git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@536 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
a4d1195979
commit
dae3de6609
|
@ -139,7 +139,7 @@ int main(int argc, char **argv) {
|
|||
chEvtRegister(&evt.et_es, &el0, 0); // Registers a listener on the source.
|
||||
|
||||
/*
|
||||
* Starts serveral instances of the SequencerThread class, each one operating
|
||||
* Starts several instances of the SequencerThread class, each one operating
|
||||
* on a different LED.
|
||||
*/
|
||||
SequencerThread blinker1(LED1_sequence);
|
||||
|
@ -150,7 +150,7 @@ int main(int argc, char **argv) {
|
|||
* Serves timer events.
|
||||
*/
|
||||
while (true)
|
||||
Event::Wait(ALL_EVENTS, evhndl);
|
||||
Event::Dispatch(evhndl, Event::WaitOne(ALL_EVENTS));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#---------------------------------------------------------------------------
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = ChibiOS/RT
|
||||
PROJECT_NUMBER = "0.8.2 beta"
|
||||
PROJECT_NUMBER = "0.8.3 beta"
|
||||
OUTPUT_DIRECTORY = .
|
||||
CREATE_SUBDIRS = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td style="text-align: center; vertical-align: top; width: 150px;">Current
|
||||
Version 0.8.2<br>
|
||||
Version 0.8.3<br>
|
||||
-<br>
|
||||
<a href="http://sourceforge.net/projects/chibios/" rel="me" target="_top">Project on SourceForge</a><br>
|
||||
<a href="html/index.html" target="_top" rel="me">Documentation</a><br>
|
||||
|
|
|
@ -73,6 +73,10 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
|
|||
*** Releases ***
|
||||
*****************************************************************************
|
||||
|
||||
*** 0.8.3 ***
|
||||
- Updated the C++ wrapper with the latest APIs changes and fixed some bugs.
|
||||
- Small fixes to the documentation.
|
||||
|
||||
*** 0.8.2 ***
|
||||
- FIX: Included the files that were missing from version 0.8.1 distribution.
|
||||
- FIX: Duplicated sections in the documentation removed.
|
||||
|
|
|
@ -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) {
|
||||
|
||||
chEvtSend(&event);
|
||||
chEvtBroadcast(&event);
|
||||
}
|
||||
|
||||
void Event::Clear(eventmask_t mask) {
|
||||
eventmask_t Event::Clear(eventmask_t mask) {
|
||||
|
||||
chEvtClear(mask);
|
||||
return chEvtClear(mask);
|
||||
}
|
||||
|
||||
eventid_t Event::Wait(eventmask_t ewmask, const evhandler_t handlers[]) {
|
||||
eventmask_t Event::Pend(eventmask_t mask) {
|
||||
|
||||
return chEvtWait(ewmask, handlers);
|
||||
return chEvtPend(mask);
|
||||
}
|
||||
|
||||
void Event::Dispatch(const evhandler_t handlers[], eventmask_t mask) {
|
||||
|
||||
chEvtDispatch(handlers, mask);
|
||||
}
|
||||
|
||||
eventmask_t Event::WaitOne(eventmask_t ewmask) {
|
||||
|
||||
return chEvtWaitOne(ewmask);
|
||||
}
|
||||
|
||||
eventmask_t Event::WaitAny(eventmask_t ewmask) {
|
||||
|
||||
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 chEvtWaitTimeout(ewmask, handlers, 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 chEvtWaitAllTimeout(ewmask, time);
|
||||
}
|
||||
#endif /* CH_USE_EVENTS_TIMEOUT */
|
||||
#endif /* CH_USE_EVENTS */
|
||||
|
|
141
src/lib/ch.hpp
141
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[]);
|
||||
|
||||
/**
|
||||
* 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 eventmask_t WaitAll(eventmask_t ewmask);
|
||||
|
||||
#ifdef CH_USE_EVENTS_TIMEOUT
|
||||
/**
|
||||
* Waits and dispatchs events with timeout specification.
|
||||
* 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 eventid_t WaitTimeout(eventmask_t ewmask,
|
||||
const evhandler_t handlers[],
|
||||
systime_t time);
|
||||
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 */
|
||||
|
|
Loading…
Reference in New Issue