| 18 | } |
| 19 | |
| 20 | struct Timer* timer_alloc(enum TimerType type, TickType_t ticks, timer_callback_t callback, void* context) { |
| 21 | check(xPortInIsrContext() == pdFALSE); |
| 22 | check(callback != NULL); |
| 23 | |
| 24 | struct Timer* timer = (struct Timer*)malloc(sizeof(struct Timer)); |
| 25 | if (timer == NULL) { |
| 26 | return NULL; |
| 27 | } |
| 28 | |
| 29 | timer->callback = callback; |
| 30 | timer->context = context; |
| 31 | |
| 32 | BaseType_t auto_reload = (type == TIMER_TYPE_ONCE) ? pdFALSE : pdTRUE; |
| 33 | timer->handle = xTimerCreate(NULL, ticks, auto_reload, timer, timer_callback_internal); |
| 34 | |
| 35 | if (timer->handle == NULL) { |
| 36 | free(timer); |
| 37 | return NULL; |
| 38 | } |
| 39 | |
| 40 | return timer; |
| 41 | } |
| 42 | |
| 43 | void timer_free(struct Timer* timer) { |
| 44 | check(xPortInIsrContext() == pdFALSE); |