HAL_ChibiOS: add EventSource HAL
This commit is contained in:
parent
265e9b8cc6
commit
7929efec0d
34
libraries/AP_HAL_ChibiOS/EventSource.cpp
Normal file
34
libraries/AP_HAL_ChibiOS/EventSource.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "EventSource.h"
|
||||||
|
#include <AP_HAL/AP_HAL.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
|
25
libraries/AP_HAL_ChibiOS/EventSource.h
Normal file
25
libraries/AP_HAL_ChibiOS/EventSource.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <AP_HAL/AP_HAL_Boards.h>
|
||||||
|
#include <AP_HAL/AP_HAL_Macros.h>
|
||||||
|
#include <AP_HAL/EventHandle.h>
|
||||||
|
#include "AP_HAL_ChibiOS_Namespace.h"
|
||||||
|
#include <ch.hpp>
|
||||||
|
|
||||||
|
#if CH_CFG_USE_EVENTS == TRUE
|
||||||
|
class ChibiOS::EventSource : public AP_HAL::EventSource {
|
||||||
|
// Single event source to be shared across multiple users
|
||||||
|
chibios_rt::EventSource ch_evt_src_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// generate event from thread context
|
||||||
|
void signal(uint32_t evt_mask) override;
|
||||||
|
|
||||||
|
// generate event from interrupt context
|
||||||
|
void signalI(uint32_t evt_mask) override;
|
||||||
|
|
||||||
|
// Wait on an Event handle, method for internal use by EventHandle
|
||||||
|
bool wait(uint64_t duration, AP_HAL::EventHandle* evt_handle) override;
|
||||||
|
};
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user