#include #include #include #include #include #define N 100 static RT_SEM_BINARY(sem); static rt_atomic_uint x = 0; void rt_irq_handler(void) { rt_sem_post(&sem); } static void waiter(void) { for (;;) { rt_sem_wait(&sem); rt_atomic_fetch_add(&x, 1, RT_ATOMIC_RELEASE); } } static void interrupter(void) { for (int i = 0; i < N; ++i) { rt_irq_pend(); } rt_assert(rt_atomic_load(&x, RT_ATOMIC_ACQUIRE) == N, "x has an unexpected value"); rt_trap(); } static void timeout(void) { rt_task_sleep(100); rt_panic("timed out"); } RT_TASK(interrupter, RT_STACK_MIN, 2); RT_TASK(waiter, RT_STACK_MIN, 1); RT_TASK(timeout, RT_STACK_MIN, 0);