littlekernel / lk

LK embedded kernel
MIT License
3.11k stars 613 forks source link

How to use timer #332

Open Inchul-Lee opened 2 years ago

Inchul-Lee commented 2 years ago

I am merging IAR source cdoe to LK. In the IAR it is possible to use SysTick_Handler(void). But I have conformed that _systick(void) is used by LK kernel. I need to use systick or timer for system. I fount out that LK has the timer function like as platform_set_oneshot_timer() or platform_set_periodic_timer. How can I use it? Please give me the example or information.

cleverca22 commented 1 year ago

https://github.com/librerpi/lk-overlay/blob/master/platform/bcm28xx/temp/temp.c#L98-L116

static enum handler_return poller_entry(struct timer *t, lk_time_t now, void *arg) {
...
  return INT_NO_RESCHEDULE;
}

static void temp_init(const struct app_descriptor *app) {
  timer_initialize(&poller);
  timer_set_periodic(&poller, 1000, poller_entry, NULL);
}

APP_START(temp)
  .init = temp_init,
APP_END

this code creates a timer that will run the set function every second