This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

k_uptime_get return a signed value

Hello,

I would like to use k_uptime_get, however this is returning an int64_t where I would expect an uint64_t.

While looking in the function, I see that k_uptime_get calls k_ticks_to_ms_floor64(k_uptime_ticks()); which should be returning an uint64_t.

What is the reason for this cast?

How is this counter computed? Is it reading a hardware register? Can this counter return to 0 in some cases (apart from a reboot)?

Thanks!

Parents Reply
  • Hi Florian,

    Depraz said:

    Once started (without the tickless option), can I safely assume that this counter won't restart to 0 unless the program runs for years and years (i.e. until 2^64 milliseconds) ?

    I see that the driver is returning 32bit values. Once we reach 2^32 milliseconds, will we restart to 0 even if we are using k_uptime_get which should return an 64bit?

    If we look deeper into how the ticks are handled, its a diff based on the last time the counter was updated:

    https://github.com/nrfconnect/sdk-zephyr/blob/master/include/drivers/timer/system_timer.h#L124-L132

     

    This is the call from k_uptime_ticks -> sys_clock_tick_get:

    curr_tick + delta

     

    The "curr_tick" is updated when function "sys_clock_announce()" is called.

     

    As long as the sys_clock_announce() updates the curr_tick every 2^24 -1 ticks, (RTC max CC value), it should be able to run as expected.

     

    Kind regards,

    Håkon 

Children
Related