2020-05-31 09:20:46 -03:00
|
|
|
#include "EventSource.h"
|
2022-04-03 20:54:20 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2020-07-30 14:50:57 -03:00
|
|
|
|
2020-05-31 09:20:46 -03:00
|
|
|
using namespace ChibiOS;
|
|
|
|
|
|
|
|
#if CH_CFG_USE_EVENTS == TRUE
|
|
|
|
|
2023-04-17 01:12:25 -03:00
|
|
|
bool EventSource::wait(uint16_t duration_us, AP_HAL::EventHandle *evt_handle)
|
2020-05-31 09:20:46 -03:00
|
|
|
{
|
|
|
|
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);
|
2023-04-17 01:12:25 -03:00
|
|
|
if (duration_us == 0) {
|
2020-05-31 09:20:46 -03:00
|
|
|
ret = chEvtWaitAnyTimeout(evt_mask, TIME_IMMEDIATE);
|
|
|
|
} else {
|
2023-04-17 01:12:25 -03:00
|
|
|
const sysinterval_t wait_us = MIN(TIME_MAX_INTERVAL, MAX(CH_CFG_ST_TIMEDELTA, chTimeUS2I(duration_us)));
|
|
|
|
ret = chEvtWaitAnyTimeout(evt_mask, wait_us);
|
2020-05-31 09:20:46 -03:00
|
|
|
}
|
|
|
|
ch_evt_src_.unregister(&evt_listener);
|
|
|
|
return ret == MSG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventSource::signal(uint32_t evt_mask)
|
|
|
|
{
|
|
|
|
ch_evt_src_.broadcastFlags(evt_mask);
|
|
|
|
}
|
|
|
|
|
2021-09-04 08:59:15 -03:00
|
|
|
__RAMFUNC__ void EventSource::signalI(uint32_t evt_mask)
|
2020-05-31 09:20:46 -03:00
|
|
|
{
|
|
|
|
chSysLockFromISR();
|
|
|
|
ch_evt_src_.broadcastFlagsI(evt_mask);
|
|
|
|
chSysUnlockFromISR();
|
|
|
|
}
|
2020-07-30 14:50:57 -03:00
|
|
|
#endif //#if CH_CFG_USE_EVENTS == TRUE
|