diff options
Diffstat (limited to 'src/lib/ch.hpp')
-rw-r--r-- | src/lib/ch.hpp | 143 |
1 files changed, 128 insertions, 15 deletions
diff --git a/src/lib/ch.hpp b/src/lib/ch.hpp index e65e4fdbd..fe368a0f2 100644 --- a/src/lib/ch.hpp +++ b/src/lib/ch.hpp @@ -53,15 +53,12 @@ namespace chibios_rt { */
static void Unlock(void);
-#ifdef CH_USE_SYSTEMTIME
/**
* Returns the system time as system ticks.
*/
static systime_t GetTime(void);
-#endif /* CH_USE_SYSTEMTIME */
};
-#ifdef CH_USE_VIRTUAL_TIMERS
/**
* Timer class.
*/
@@ -88,7 +85,6 @@ namespace chibios_rt { */
bool IsArmed(void);
};
-#endif /* CH_USE_VIRTUAL_TIMER */
/**
* Base class for a ChibiOS/RT thread, the thread body is the virtual
@@ -135,12 +131,10 @@ namespace chibios_rt { */
static void Sleep(systime_t n);
-#ifdef CH_USE_SYSTEMTIME
/**
* Suspends the thread execution until the specified time arrives.
*/
static void SleepUntil(systime_t time);
-#endif /* CH_USE_SYSTEMTIME */
#ifdef CH_USE_MESSAGES
/**
@@ -253,7 +247,7 @@ namespace chibios_rt { /**
* Atomic signal and wait operations.
*/
- msg_t SignalWait(Semaphore *ssem, Semaphore *wsem);
+ static msg_t SignalWait(Semaphore *ssem, Semaphore *wsem);
#endif /* CH_USE_SEMSW */
};
#endif /* CH_USE_SEMAPHORES */
@@ -291,6 +285,28 @@ namespace chibios_rt { */
static void UnlockAll(void);
};
+
+#ifdef CH_USE_CONDVARS
+ class CondVar {
+ public:
+ ::CondVar condvar;
+
+ /**
+ * CondVar constructor.
+ */
+ CondVar(void);
+
+ void Signal(void);
+
+ void Broadcast(void);
+
+ msg_t Wait(void);
+
+#ifdef CH_USE_CONDVARS_TIMEOUT
+ msg_t WaitTimeout(systime_t time);
+#endif /* CH_USE_CONDVARS_TIMEOUT */
+ };
+#endif /* CH_USE_CONDVARS */
#endif /* CH_USE_MUTEXES */
#ifdef CH_USE_EVENTS
@@ -308,36 +324,133 @@ namespace chibios_rt { /**
* Registers a listener on the event source.
+ * @param elp pointer to the \p EventListener structure
+ * @param eid numeric identifier assigned to the Event Listener
*/
void Register(EventListener *elp, eventid_t eid);
/**
+ * Registers an Event Listener on an Event Source.
+ * @param elp pointer to the \p EventListener structure
+ * @param emask the mask of event flags to be pended to the thread when the
+ * event source is broadcasted
+ * @note Multiple Event Listeners can specify the same bits to be pended.
+ */
+ void RegisterMask(EventListener *elp, eventmask_t emask);
+
+ /**
* Unregisters a listener from the event source.
*/
void Unregister(EventListener *elp);
/**
- * Sends an event.
+ * Broadcasts an event.
*/
- void Send(void);
+ void Broadcast(void);
/**
* Clears specified events from the pending events mask.
+ * @param mask the events to be cleared
+ * @return The pending events that were cleared.
*/
- static void Clear(eventmask_t mask);
+ static eventmask_t Clear(eventmask_t mask);
+
+ /**
+ * Makes an events mask pending in the current thread, this is \b much
+ * faster than using \p Broadcast().
+ * @param mask the events to be pended
+ * @return The current pending events mask.
+ */
+ static eventmask_t Pend(eventmask_t mask);
+
+ /**
+ * Invokes the event handlers associated with a mask.
+ * @param mask mask of the events to be dispatched
+ * @param handlers an array of \p evhandler_t. The array must be
+ * have indexes from zero up the higher registered event
+ * identifier.
+ */
+ static void Dispatch(const evhandler_t handlers[], eventmask_t mask);
/**
* Waits and dispatchs events.
*/
static eventid_t Wait(eventmask_t ewmask, const evhandler_t handlers[]);
-#ifdef CH_USE_EVENTS_TIMEOUT
/**
- * Waits and dispatchs events with timeout specification.
+ * A pending event among those specified in \p ewmask is selected, cleared and
+ * its mask returned.
+ * @param ewmask mask of the events that the function should wait for,
+ * \p ALL_EVENTS enables all the events
+ * @return The mask of the lowest id served and cleared event.
+ * @note One and only one event is served in the function, the one with the
+ * lowest event id. The function is meant to be invoked into a loop in
+ * order to serve all the pending events.<br>
+ * This means that Event Listeners with a lower event identifier have
+ * an higher priority.
+ */
+ static eventmask_t WaitOne(eventmask_t ewmask);
+
+ /**
+ * Waits for any of the specified events.
+ * The function waits for any event among those specified in \p ewmask to
+ * become pending then the events are cleared and returned.
+ * @param ewmask mask of the events that the function should wait for,
+ * \p ALL_EVENTS enables all the events
+ * @return The mask of the served and cleared events.
+ */
+ static eventmask_t WaitAny(eventmask_t ewmask);
+
+ /**
+ * Waits for all the specified event flags then clears them.
+ * The function waits for all the events specified in \p ewmask to become
+ * pending then the events are cleared and returned.
+ * @param ewmask mask of the event ids that the function should wait for
+ * @return The mask of the served and cleared events.
*/
- static eventid_t WaitTimeout(eventmask_t ewmask,
- const evhandler_t handlers[],
- systime_t time);
+ static eventmask_t WaitAll(eventmask_t ewmask);
+
+#ifdef CH_USE_EVENTS_TIMEOUT
+ /**
+ * Waits for a single event.
+ * A pending event among those specified in \p ewmask is selected, cleared
+ * and its mask returned.
+ * @param ewmask mask of the events that the function should wait for,
+ * \p ALL_EVENTS enables all the events
+ * @param time the number of ticks before the operation timouts
+ * @return The mask of the lowest id served and cleared event.
+ * @retval 0 if the specified timeout expired.
+ * @note One and only one event is served in the function, the one with the
+ * lowest event id. The function is meant to be invoked into a loop in
+ * order to serve all the pending events.<br>
+ * This means that Event Listeners with a lower event identifier have
+ * an higher priority.
+ */
+ static eventmask_t WaitOneTimeout(eventmask_t ewmask, systime_t time);
+
+ /**
+ * Waits for any of the specified events.
+ * The function waits for any event among those specified in \p ewmask to
+ * become pending then the events are cleared and returned.
+ * @param ewmask mask of the events that the function should wait for,
+ * \p ALL_EVENTS enables all the events
+ * @param time the number of ticks before the operation timouts
+ * @return The mask of the served and cleared events.
+ * @retval 0 if the specified timeout expired.
+ */
+ static eventmask_t WaitAnyTimeout(eventmask_t ewmask, systime_t time);
+
+ /**
+ * Waits for all the specified event flags then clears them.
+ * The function waits for all the events specified in \p ewmask to become
+ * pending then the events are cleared and returned.
+ * @param ewmask mask of the event ids that the function should wait for
+ * @param time the number of ticks before the operation timouts
+ * @return The mask of the served and cleared events.
+ * @retval 0 if the specified timeout expired.
+ */
+ static eventmask_t WaitAllTimeout(eventmask_t ewmask, systime_t time);
+
#endif /* CH_USE_EVENTS_TIMEOUT */
};
#endif /* CH_USE_EVENTS */
|