Skip to content

Commit 308ae12

Browse files
committed
Add timer APIs to cover cancellation paths
Add timer cancellation APIs to validate timer behavior across different cancellation scenarios, including task destruction, explicit timer cancellation, and one-shot timers. These APIs help ensure cancelled or destroyed timers never fire and that one-shot timers handle tick expiration correctly.
1 parent 0f0c3f8 commit 308ae12

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/timer.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,22 @@ int32_t app_main(void)
5454
mo_timer_create(timer_callback, 1000, (void *) 1);
5555
mo_timer_create(timer_callback, 3000, (void *) 2);
5656
mo_timer_create(timer_callback, 500, (void *) 3);
57+
mo_timer_create(timer_callback, 100, (void *) 4);
5758

5859
/* Start all created timers in auto-reload mode.
5960
* Note: In this simple case, the IDs will be 0x6000, 0x6001, and 0x6002.
6061
*/
6162
mo_timer_start(0x6000, TIMER_AUTORELOAD);
62-
mo_timer_start(0x6001, TIMER_AUTORELOAD);
63+
mo_timer_start(0x6001, TIMER_ONESHOT);
6364
mo_timer_start(0x6002, TIMER_AUTORELOAD);
65+
mo_timer_start(0x6003, TIMER_AUTORELOAD);
66+
67+
/* Timer destroy to confirm functions workable; now only timer 3 will run
68+
* and timer 2 only one shot */
69+
mo_timer_destroy(0x6000);
70+
mo_timer_cancel(0x6003);
71+
/* Destroyed timer can't be resumed */
72+
mo_timer_start(0x6000, TIMER_AUTORELOAD);
6473

6574
/* Spawn a single idle task to keep the kernel running. */
6675
mo_task_spawn(idle_task, DEFAULT_STACK_SIZE);

0 commit comments

Comments
 (0)