mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_HAL: add common Event interface
This commit is contained in:
parent
0690b7bd68
commit
697e4141cb
@ -16,6 +16,7 @@
|
||||
#include "RCOutput.h"
|
||||
#include "Scheduler.h"
|
||||
#include "Semaphores.h"
|
||||
#include "EventHandle.h"
|
||||
#include "Util.h"
|
||||
#include "OpticalFlow.h"
|
||||
#include "Flash.h"
|
||||
|
@ -26,6 +26,8 @@ namespace AP_HAL {
|
||||
class RCInput;
|
||||
class RCOutput;
|
||||
class Scheduler;
|
||||
class EventHandle;
|
||||
class EventSource;
|
||||
class Semaphore;
|
||||
class OpticalFlow;
|
||||
class DSP;
|
||||
|
33
libraries/AP_HAL/EventHandle.cpp
Normal file
33
libraries/AP_HAL/EventHandle.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "EventHandle.h"
|
||||
#include <AP_HAL/AP_HAL.h>
|
||||
|
||||
|
||||
bool AP_HAL::EventHandle::register_event(uint32_t evt_mask)
|
||||
{
|
||||
WITH_SEMAPHORE(sem);
|
||||
evt_mask_ |= evt_mask;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AP_HAL::EventHandle::unregister_event(uint32_t evt_mask)
|
||||
{
|
||||
WITH_SEMAPHORE(sem);
|
||||
evt_mask_ &= ~evt_mask;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AP_HAL::EventHandle::wait(uint64_t duration)
|
||||
{
|
||||
if (evt_src_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return evt_src_->wait(duration, this);
|
||||
}
|
||||
|
||||
bool AP_HAL::EventHandle::set_source(AP_HAL::EventSource* src)
|
||||
{
|
||||
WITH_SEMAPHORE(sem);
|
||||
evt_src_ = src;
|
||||
evt_mask_ = 0;
|
||||
return true;
|
||||
}
|
44
libraries/AP_HAL/EventHandle.h
Normal file
44
libraries/AP_HAL/EventHandle.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "AP_HAL_Namespace.h"
|
||||
#include <stdint.h>
|
||||
#include "AP_HAL_Boards.h"
|
||||
|
||||
class AP_HAL::EventSource {
|
||||
public:
|
||||
// generate event from thread context
|
||||
virtual void signal(uint32_t evt_mask) = 0;
|
||||
|
||||
// generate event from interrupt context
|
||||
virtual void signalI(uint32_t evt_mask) { signal(evt_mask); }
|
||||
|
||||
|
||||
// Wait on an Event handle, method for internal use by EventHandle
|
||||
virtual bool wait(uint64_t duration, AP_HAL::EventHandle* evt_handle) = 0;
|
||||
};
|
||||
|
||||
class AP_HAL::EventHandle {
|
||||
public:
|
||||
//Set event source
|
||||
virtual bool set_source(AP_HAL::EventSource* src);
|
||||
|
||||
AP_HAL::EventSource* get_source() { return evt_src_; }
|
||||
|
||||
// return true if event type was successfully registered
|
||||
virtual bool register_event(uint32_t evt_mask);
|
||||
|
||||
// return true if event type was successfully unregistered
|
||||
virtual bool unregister_event(uint32_t evt_mask);
|
||||
|
||||
// return true if event was triggered within the duration
|
||||
virtual bool wait(uint64_t duration);
|
||||
|
||||
virtual uint32_t get_evt_mask() const { return evt_mask_; }
|
||||
|
||||
private:
|
||||
// Mask of events to be handeled,
|
||||
// Max 32 events can be handled per event handle
|
||||
uint32_t evt_mask_;
|
||||
AP_HAL::EventSource *evt_src_;
|
||||
HAL_Semaphore sem;
|
||||
};
|
@ -60,6 +60,9 @@
|
||||
#include <AP_HAL_ChibiOS/Semaphores.h>
|
||||
#define HAL_Semaphore ChibiOS::Semaphore
|
||||
|
||||
#include <AP_HAL/EventHandle.h>
|
||||
#define HAL_EventHandle AP_HAL::EventHandle
|
||||
|
||||
/* string names for well known SPI devices */
|
||||
#define HAL_BARO_MS5611_NAME "ms5611"
|
||||
#ifndef HAL_BARO_MS5611_SPI_INT_NAME
|
||||
|
@ -347,4 +347,5 @@
|
||||
|
||||
#include <AP_HAL_Linux/Semaphores.h>
|
||||
#define HAL_Semaphore Linux::Semaphore
|
||||
|
||||
#include <AP_HAL/EventHandle.h>
|
||||
#define HAL_EventHandle AP_HAL::EventHandle
|
||||
|
@ -58,6 +58,11 @@
|
||||
#include <AP_HAL_SITL/Semaphores.h>
|
||||
#define HAL_Semaphore HALSITL::Semaphore
|
||||
|
||||
#include <AP_HAL/EventHandle.h>
|
||||
#define HAL_EventHandle AP_HAL::EventHandle
|
||||
|
||||
#define HAL_NUM_CAN_IFACES 2
|
||||
|
||||
#ifndef HAL_BOARD_STORAGE_DIRECTORY
|
||||
#define HAL_BOARD_STORAGE_DIRECTORY "."
|
||||
#endif
|
||||
|
@ -14,6 +14,7 @@ namespace ChibiOS {
|
||||
class RCOutput;
|
||||
class Scheduler;
|
||||
class Semaphore;
|
||||
class EventSource;
|
||||
class SPIBus;
|
||||
class SPIDesc;
|
||||
class SPIDevice;
|
||||
|
Loading…
Reference in New Issue
Block a user