aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-12-07 10:21:40 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-12-07 10:21:40 +0000
commitdae3de6609b9251dbaaa280c1ce886a350c3c0c5 (patch)
tree77880097c174ba635a50d9086cce447d8bd53c81 /src
parenta4d1195979a0ee8dddb05e5b8dc29521e190d28f (diff)
downloadChibiOS-dae3de6609b9251dbaaa280c1ce886a350c3c0c5.tar.gz
ChibiOS-dae3de6609b9251dbaaa280c1ce886a350c3c0c5.tar.bz2
ChibiOS-dae3de6609b9251dbaaa280c1ce886a350c3c0c5.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@536 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
-rw-r--r--src/lib/ch.cpp91
-rw-r--r--src/lib/ch.hpp143
2 files changed, 203 insertions, 31 deletions
diff --git a/src/lib/ch.cpp b/src/lib/ch.cpp
index 1d63cefd5..61a5633d4 100644
--- a/src/lib/ch.cpp
+++ b/src/lib/ch.cpp
@@ -39,14 +39,11 @@ namespace chibios_rt {
chSysUnlock();
}
-#ifdef CH_USE_SYSTEMTIME
systime_t System::GetTime(void) {
return chSysGetTime();
}
-#endif /* CH_USE_SYSTEMTIME */
-#ifdef CH_USE_VIRTUAL_TIMERS
/*------------------------------------------------------------------------*
* chibios_rt::Timer *
*------------------------------------------------------------------------*/
@@ -64,7 +61,6 @@ namespace chibios_rt {
return chVTIsArmedI(&timer);
}
-#endif /* CH_USE_VIRTUAL_TIMER */
/*------------------------------------------------------------------------*
* chibios_rt::BaseThread *
@@ -113,12 +109,10 @@ namespace chibios_rt {
chThdSleep(n);
}
-#ifdef CH_USE_SYSTEMTIME
void BaseThread::SleepUntil(systime_t time) {
chThdSleepUntil(time);
}
-#endif /* CH_USE_SYSTEMTIME */
#ifdef CH_USE_MESSAGES
msg_t BaseThread::SendMessage(::Thread* tp, msg_t msg) {
@@ -224,6 +218,38 @@ namespace chibios_rt {
chMtxUnlockAll();
}
+
+#ifdef CH_USE_CONDVARS
+ /*------------------------------------------------------------------------*
+ * chibios_rt::CondVar *
+ *------------------------------------------------------------------------*/
+ CondVar::CondVar(void) {
+
+ chCondInit(&condvar);
+ }
+
+ void CondVar::Signal(void) {
+
+ chCondSignal(&condvar);
+ }
+
+ void CondVar::Broadcast(void) {
+
+ chCondBroadcast(&condvar);
+ }
+
+ msg_t CondVar::Wait(void) {
+
+ return chCondWait(&condvar);
+ }
+
+#ifdef CH_USE_CONDVARS_TIMEOUT
+ msg_t CondVar::WaitTimeout(systime_t time) {
+
+ return chCondWaitTimeout(&condvar, time);
+ }
+#endif /* CH_USE_CONDVARS_TIMEOUT */
+#endif /* CH_USE_CONDVARS */
#endif /* CH_USE_MUTEXES */
#ifdef CH_USE_EVENTS
@@ -240,32 +266,65 @@ namespace chibios_rt {
chEvtRegister(&event,elp, eid);
}
+ void Event::RegisterMask(EventListener *elp, eventmask_t emask) {
+
+ chEvtRegisterMask(&event,elp, emask);
+ }
+
void Event::Unregister(EventListener *elp) {
chEvtUnregister(&event, elp);
}
- void Event::Send(void) {
+ void Event::Broadcast(void) {
+
+ chEvtBroadcast(&event);
+ }
+
+ eventmask_t Event::Clear(eventmask_t mask) {
+
+ return chEvtClear(mask);
+ }
+
+ eventmask_t Event::Pend(eventmask_t mask) {
+
+ return chEvtPend(mask);
+ }
+
+ void Event::Dispatch(const evhandler_t handlers[], eventmask_t mask) {
- chEvtSend(&event);
+ chEvtDispatch(handlers, mask);
}
- void Event::Clear(eventmask_t mask) {
+ eventmask_t Event::WaitOne(eventmask_t ewmask) {
- chEvtClear(mask);
+ return chEvtWaitOne(ewmask);
}
- eventid_t Event::Wait(eventmask_t ewmask, const evhandler_t handlers[]) {
+ eventmask_t Event::WaitAny(eventmask_t ewmask) {
- return chEvtWait(ewmask, handlers);
+ return chEvtWaitAny(ewmask);
+ }
+
+ eventmask_t Event::WaitAll(eventmask_t ewmask) {
+
+ return chEvtWaitAll(ewmask);
}
#ifdef CH_USE_EVENTS_TIMEOUT
- eventid_t Event::WaitTimeout(eventmask_t ewmask,
- const evhandler_t handlers[],
- systime_t time) {
+ eventmask_t Event::WaitOneTimeout(eventmask_t ewmask, systime_t time) {
+
+ return chEvtWaitOneTimeout(ewmask, time);
+ }
+
+ eventmask_t Event::WaitAnyTimeout(eventmask_t ewmask, systime_t time) {
+
+ return chEvtWaitAnyTimeout(ewmask, time);
+ }
+
+ eventmask_t Event::WaitAllTimeout(eventmask_t ewmask, systime_t time) {
- return chEvtWaitTimeout(ewmask, handlers, time);
+ return chEvtWaitAllTimeout(ewmask, time);
}
#endif /* CH_USE_EVENTS_TIMEOUT */
#endif /* CH_USE_EVENTS */
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 */