Dear All
Could you point me a timer example, can be used to time the interval in ms between something? like read the system time when something happens and then read again when it happens again?
Thank you!
Ping
Dear All
Could you point me a timer example, can be used to time the interval in ms between something? like read the system time when something happens and then read again when it happens again?
Thank you!
Ping
Hi Ping
You should be able to use the k_uptime_get() or k_uptime_get_32() functions for this. They will return the number of milliseconds that have passed since the system booted, either as a 64-bit or 32-bit value, and if you call this twice and compare the two values you can see how much time has passed.
Best regards
Torbjørn
Thanks, Torbjorn
That works fine.
I also need to create a timer to do a periodic task like blink a LED, I don't want to use k_sleep() , what is the best way to do it please?
I am sorry keep asking you the small questions like this, but I am new to Zephyr.
Thanks
Ping
void my_work_handler(struct k_work *work) { /* do the processing that needs to be done periodically */ gpio_pin_set(dev, PIN, (int)led_is_on); led_is_on = !led_is_on; } K_WORK_DEFINE(my_work, my_work_handler); void my_timer_handler(struct k_timer *dummy) { k_work_submit(&my_work); } K_TIMER_DEFINE(my_timer, my_timer_handler, NULL);
K_THREAD_DEFINE(uart_write_thread_id, STACKSIZE, uart_write_thread, NULL, NULL, NULL, PRIORITY, 0, 0);
void my_work_handler(struct k_work *work) { /* do the processing that needs to be done periodically */ gpio_pin_set(dev, PIN, (int)led_is_on); led_is_on = !led_is_on; } K_WORK_DEFINE(my_work, my_work_handler); void my_timer_handler(struct k_timer *dummy) { k_work_submit(&my_work); } K_TIMER_DEFINE(my_timer, my_timer_handler, NULL);
K_THREAD_DEFINE(uart_write_thread_id, STACKSIZE, uart_write_thread, NULL, NULL, NULL, PRIORITY, 0, 0);
Hi Ping
It is very odd that running the timer would cause your thread to stop functioning.
Does it matter if you start the timer or not, or if you submit the work item or not?
Would you be able to share your main file with me, so I can see what your thread is doing?
I can make this case private if you don't want to share your code in a public case.
Best regards
Torbjørn