ardupilot/libraries/AP_HAL_ChibiOS/EventSource.cpp
Tom Pittenger f764bd6547 AP_HAL_ChibiOS: disable EventSource only when CH_CFG_USE_EVENTS is false
(cherry picked from commit 6e7542a70ca2343ab8d18470deaf5fc2d27390af) from bugobliterator
2021-06-09 18:36:18 +10:00

34 lines
855 B
C++

#include "EventSource.h"
using namespace ChibiOS;
#if CH_CFG_USE_EVENTS == TRUE
bool EventSource::wait(uint64_t duration, AP_HAL::EventHandle *evt_handle)
{
chibios_rt::EventListener evt_listener;
eventmask_t evt_mask = evt_handle->get_evt_mask();
msg_t ret = msg_t();
ch_evt_src_.registerMask(&evt_listener, evt_mask);
if (duration == 0) {
ret = chEvtWaitAnyTimeout(evt_mask, TIME_IMMEDIATE);
} else {
ret = chEvtWaitAnyTimeout(evt_mask, chTimeUS2I(duration));
}
ch_evt_src_.unregister(&evt_listener);
return ret == MSG_OK;
}
void EventSource::signal(uint32_t evt_mask)
{
ch_evt_src_.broadcastFlags(evt_mask);
}
void EventSource::signalI(uint32_t evt_mask)
{
chSysLockFromISR();
ch_evt_src_.broadcastFlagsI(evt_mask);
chSysUnlockFromISR();
}
#endif //#if CH_CFG_USE_EVENTS == TRUE