Get Current Time with kernel Timer

Hello,

I like to get the current time with a kernel_timer. So I use the function k_uptime_get().

However,with each call the timer starts again from the beginning (from 0).Is there a method how i can bypass that it starts again from 0.

Parents
  • Hello,

    k_uptime_get() does not reset when you use it. Is it saying "0" every time? I'm guessing youre looking at it with a printk or LOG_XXX function. If so it's probably just not printing the 64 bit number correctly. For instance,

    while(1)
    {
        printk("%d\n", k_uptime_get());
        k_msleep(1000);
    }

    Would print "0" every time because the %d is not expecting a 64 bit number. It's only printing the upper 32 bits which is 0 until 4,294,967,295 milliseconds have elapsed.

    If you do this instead:

    while(1)
    {
        printk("%"PRIu64"\n", k_uptime_get());
        k_msleep(1000);
    }

    Then it will print the correct values. Or you could use this if you dont need all 64 bits:

    while(1)
    {
        printk("%d\n", k_uptime_get_32());
        k_msleep(1000);
    }

  • thank you for your answer. 

    enclosed you can see my output. As you can see I have output currenttime. However, with both the system restarts, so that the same number is printed out. After "Tasks_sleep_mode" my system ist entering the IDLE Thread and is waking up with an interrupt. In my Interrupt i am printing the current time. Does the timer starts again after getting out of the IDLE Thread?

  • It should not restart because of exiting the idle thread. That is interesting. Are you able to post your code? Are you using any power savings modes or something?

Reply Children
Related