#include #include #include #include static RT_MUTEX(mutex); static volatile uint64_t x, y; void rt_irq_handler(void) { if (rt_mutex_trylock(&mutex)) { ++x; ++y; rt_mutex_unlock(&mutex); } } static void incrementer(void) { for (;;) { rt_mutex_lock(&mutex); uint64_t tmp = x; rt_irq_pend(); x = tmp + 1; ++y; rt_assert(x == y, "x and y don't match"); rt_mutex_unlock(&mutex); rt_irq_pend(); } } static void timeout(void) { rt_task_sleep(100); rt_trap(); } RT_TASK(incrementer, RT_STACK_MIN, 1); RT_TASK(timeout, RT_STACK_MIN, 0);