Skip to main content
sonerb
Associate
December 22, 2022
Question

SPC5 Studio osalThreadGetMicroseconds overflow

  • December 22, 2022
  • 1 reply
  • 831 views

Hi,

In the osal.c line 389 "osalThreadGetMicroseconds" function uses "osalSysTime_ST2US" macro to convert ticks to microseconds.

The macro uses osalsystime_t variable type that is 32-bit length.

 return ((uint32_t)((((osalsystime_t)ticks) * 1000000UL) / osal_ticks_per_sec));

After 4294 microseconds, the value of the calculation overflows 32-bit and gives a wrong time. (4295 x 1000000 = 0x100007FC0 )

I change to type to uint64_t and it's working now.

 return ((uint32_t)((((uint64_t)ticks) * 1000000UL) / osal_ticks_per_sec));

This topic has been closed for replies.

1 reply

ODOUV.1
ST Employee
January 3, 2023

Hello,

thank you for your remark.

We will fix in next release.

Best regards.