#include #include #include #include #include #define N 100 #define NUM_EVENTS 3 static RT_EVENT(event); static rt_atomic_uint x = 0; void rt_irq_handler(void) { static uint32_t event_shift = 0; rt_event_set(&event, 1 << event_shift); ++event_shift; if (event_shift == NUM_EVENTS) { event_shift = 0; } } static void waiter(void) { for (;;) { rt_event_wait(&event, ((1 << NUM_EVENTS) - 1) | RT_EVENT_WAIT_ALL); rt_atomic_fetch_add(&x, 1, RT_ATOMIC_RELEASE); } } static void interrupter(void) { for (int i = 0; i < N * NUM_EVENTS; ++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);