static msg_t PollIMUThread(void *arg){ (void)arg; chRegSetThreadName("PollIMU"); struct EventListener self_el; chEvtRegister(&imu_event, &self_el, 2); while (TRUE) { chEvtWaitAll(EVENT_MASK(0) && EVENT_MASK(4)); mpu_i2c_read_data(0x3B, 14); // Read accelerometer, temperature and gyro data chEvtBroadcastFlags(&imu_event, EVENT_MASK(2)); } return 0; }
static void evt2_execute(void) { eventmask_t m; event_listener_t el1, el2; systime_t target_time; /* * Test on chEvtWaitOne() without wait. */ chEvtAddEvents(5); m = chEvtWaitOne(ALL_EVENTS); test_assert(1, m == 1, "single event error"); m = chEvtWaitOne(ALL_EVENTS); test_assert(2, m == 4, "single event error"); m = chEvtGetAndClearEvents(ALL_EVENTS); test_assert(3, m == 0, "stuck event"); /* * Test on chEvtWaitOne() with wait. */ test_wait_tick(); target_time = chVTGetSystemTime() + MS2ST(50); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX() - 1, thread1, chThdGetSelfX()); m = chEvtWaitOne(ALL_EVENTS); test_assert_time_window(4, target_time, target_time + ALLOWED_DELAY); test_assert(5, m == 1, "single event error"); m = chEvtGetAndClearEvents(ALL_EVENTS); test_assert(6, m == 0, "stuck event"); test_wait_threads(); /* * Test on chEvtWaitAny() without wait. */ chEvtAddEvents(5); m = chEvtWaitAny(ALL_EVENTS); test_assert(7, m == 5, "unexpected pending bit"); m = chEvtGetAndClearEvents(ALL_EVENTS); test_assert(8, m == 0, "stuck event"); /* * Test on chEvtWaitAny() with wait. */ test_wait_tick(); target_time = chVTGetSystemTime() + MS2ST(50); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX() - 1, thread1, chThdGetSelfX()); m = chEvtWaitAny(ALL_EVENTS); test_assert_time_window(9, target_time, target_time + ALLOWED_DELAY); test_assert(10, m == 1, "single event error"); m = chEvtGetAndClearEvents(ALL_EVENTS); test_assert(11, m == 0, "stuck event"); test_wait_threads(); /* * Test on chEvtWaitAll(). */ chEvtObjectInit(&es1); chEvtObjectInit(&es2); chEvtRegisterMask(&es1, &el1, 1); chEvtRegisterMask(&es2, &el2, 4); test_wait_tick(); target_time = chVTGetSystemTime() + MS2ST(50); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX() - 1, thread2, "A"); m = chEvtWaitAll(5); test_assert_time_window(12, target_time, target_time + ALLOWED_DELAY); m = chEvtGetAndClearEvents(ALL_EVENTS); test_assert(13, m == 0, "stuck event"); test_wait_threads(); chEvtUnregister(&es1, &el1); chEvtUnregister(&es2, &el2); test_assert(14, !chEvtIsListeningI(&es1), "stuck listener"); test_assert(15, !chEvtIsListeningI(&es2), "stuck listener"); }
eventmask_t BaseThread::waitAllEvents(eventmask_t ewmask) { return chEvtWaitAll(ewmask); }
eventmask_t Event::WaitAll(eventmask_t ewmask) { return chEvtWaitAll(ewmask); }