2009-08-16 13:07:24 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2012-01-21 14:29:42 +00:00
|
|
|
2011,2012 Giovanni Di Sirio.
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @file ch.cpp
|
|
|
|
* @brief C++ wrapper code.
|
|
|
|
*
|
2009-08-30 07:17:22 +00:00
|
|
|
* @addtogroup cpp_library
|
2009-08-16 13:07:24 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-12-08 17:37:49 +00:00
|
|
|
#include "ch.hpp"
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
namespace chibios_rt {
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::System *
|
|
|
|
*------------------------------------------------------------------------*/
|
2013-01-01 15:42:44 +00:00
|
|
|
void System::init(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
chSysInit();
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void System::lock(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
chSysLock();
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void System::unlock(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
chSysUnlock();
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
systime_t System::getTime(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
return chTimeNow();
|
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
bool isTimeWithin(systime_t start, systime_t end) {
|
|
|
|
|
|
|
|
return (bool)chTimeIsWithin(start, end);
|
|
|
|
}
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::Timer *
|
|
|
|
*------------------------------------------------------------------------*/
|
2013-01-01 15:42:44 +00:00
|
|
|
void Timer::setI(systime_t time, vtfunc_t vtfunc, void *par) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
chVTSetI(&timer_ref, time, vtfunc, par);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void Timer::resetI() {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
if (chVTIsArmedI(&timer_ref))
|
|
|
|
chVTResetI(&timer_ref);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
bool Timer::isArmedI(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
return (bool)chVTIsArmedI(&timer_ref);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-01 15:42:44 +00:00
|
|
|
* chibios_rt::ThreadReference *
|
2009-08-16 13:07:24 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t ThreadReference::suspend(void) {
|
|
|
|
msg_t msg;
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
chSysLock();
|
|
|
|
|
|
|
|
chDbgAssert(thread_ref != NULL,
|
|
|
|
"ThreadReference, #1",
|
|
|
|
"already referenced");
|
|
|
|
|
|
|
|
thread_ref = chThdSelf();
|
|
|
|
chSchGoSleepS(THD_STATE_SUSPENDED);
|
|
|
|
msg = thread_ref->p_u.rdymsg;
|
|
|
|
|
|
|
|
chSysUnlock();
|
|
|
|
return msg;
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t ThreadReference::suspendS(void) {
|
|
|
|
|
|
|
|
chDbgAssert(thread_ref == NULL,
|
|
|
|
"ThreadReference, #2",
|
|
|
|
"already referenced");
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
thread_ref = chThdSelf();
|
|
|
|
chSchGoSleepS(THD_STATE_SUSPENDED);
|
|
|
|
return thread_ref->p_u.rdymsg;
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void ThreadReference::resume(msg_t msg) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
chSysLock()
|
|
|
|
|
|
|
|
chDbgAssert(thread_ref != NULL,
|
|
|
|
"ThreadReference, #3",
|
|
|
|
"not referenced");
|
|
|
|
|
|
|
|
if (thread_ref) {
|
|
|
|
Thread *tp = thread_ref;
|
|
|
|
thread_ref = NULL;
|
|
|
|
chSchWakeupS(tp, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
chSysUnlock();
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void ThreadReference::resumeI(msg_t msg) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
chDbgAssert(thread_ref != NULL,
|
|
|
|
"ThreadReference, #4",
|
|
|
|
"not referenced");
|
|
|
|
|
|
|
|
if (thread_ref) {
|
|
|
|
Thread *tp = thread_ref;
|
|
|
|
thread_ref = NULL;
|
|
|
|
tp->p_msg = msg;
|
|
|
|
chSchReadyI(tp);
|
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void ThreadReference::requestTerminate(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
chThdTerminate(thread_ref);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
#if CH_USE_WAITEXIT || defined(__DOXYGEN__)
|
|
|
|
msg_t ThreadReference::wait(void) {
|
|
|
|
|
|
|
|
chDbgAssert(thread_ref != NULL,
|
|
|
|
"ThreadReference, #5",
|
|
|
|
"not referenced");
|
|
|
|
|
|
|
|
msg_t msg = chThdWait(thread_ref);
|
|
|
|
thread_ref = NULL;
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_WAITEXIT */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
#if CH_USE_MESSAGES || defined(__DOXYGEN__)
|
|
|
|
msg_t ThreadReference::sendMessage(msg_t msg) {
|
|
|
|
|
|
|
|
chDbgAssert(thread_ref != NULL,
|
|
|
|
"ThreadReference, #6",
|
|
|
|
"not referenced");
|
|
|
|
|
|
|
|
return chMsgSend(thread_ref, msg);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
bool ThreadReference::isPendingMessage(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
return (bool)chMsgIsPendingI(thread_ref);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
2013-01-01 15:42:44 +00:00
|
|
|
#endif /* CH_USE_MESSAGES */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
#if CH_USE_EVENTS
|
|
|
|
void ThreadReference::signalEvents(eventmask_t mask) {
|
|
|
|
|
|
|
|
chEvtSignal(thread_ref, mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadReference::signalEventsI(eventmask_t mask) {
|
|
|
|
|
|
|
|
chEvtSignalI(thread_ref, mask);
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_EVENTS */
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
#if CH_USE_DYNAMIC
|
|
|
|
#endif /* CH_USE_DYNAMIC */
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::BaseThread *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
BaseThread::BaseThread() : ThreadReference(NULL) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t _thd_start(void *arg) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
return ((BaseThread *)arg)->Main();
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
void BaseThread::setName(const char *tname) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
chRegSetThreadName(tname);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
tprio_t BaseThread::setPriority(tprio_t newprio) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
return chThdSetPriority(newprio);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
void BaseThread::exit(msg_t msg) {
|
|
|
|
|
|
|
|
chThdExit(msg);
|
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
void BaseThread::exitS(msg_t msg) {
|
|
|
|
|
|
|
|
chThdExitS(msg);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
bool BaseThread::shouldTerminate(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
return (bool)chThdShouldTerminate();
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void BaseThread::sleep(systime_t interval){
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
chThdSleep(interval);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void BaseThread::sleepUntil(systime_t time) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
chThdSleepUntil(time);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
void BaseThread::yield(void) {
|
|
|
|
|
|
|
|
chThdYield();
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
#if CH_USE_MESSAGES
|
|
|
|
msg_t BaseThread::getMessage(ThreadReference* trp) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
return chMsgGet(trp->thread_ref);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void BaseThread::releaseMessage(ThreadReference* trp, msg_t msg) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
chMsgRelease(trp->thread_ref, msg);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
2013-01-01 15:42:44 +00:00
|
|
|
#endif /* CH_USE_MESSAGES */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
#if CH_USE_EVENTS
|
|
|
|
eventmask_t BaseThread::getAndClearEvents(eventmask_t mask) {
|
|
|
|
|
|
|
|
return chEvtGetAndClearEvents(mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
eventmask_t BaseThread::addEvents(eventmask_t mask) {
|
|
|
|
|
|
|
|
return chEvtAddEvents(mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
eventmask_t BaseThread::waitOneEvent(eventmask_t ewmask) {
|
|
|
|
|
|
|
|
return chEvtWaitOne(ewmask);
|
|
|
|
}
|
|
|
|
|
|
|
|
eventmask_t BaseThread::waitAnyEvent(eventmask_t ewmask) {
|
|
|
|
|
|
|
|
return chEvtWaitAny(ewmask);
|
|
|
|
}
|
|
|
|
|
|
|
|
eventmask_t BaseThread::waitAllEvents(eventmask_t ewmask) {
|
|
|
|
|
|
|
|
return chEvtWaitAll(ewmask);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CH_USE_EVENTS_TIMEOUT
|
|
|
|
eventmask_t BaseThread::waitOneEventTimeout(eventmask_t ewmask,
|
|
|
|
systime_t time) {
|
|
|
|
|
|
|
|
return chEvtWaitOneTimeout(ewmask, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
eventmask_t BaseThread::waitAnyEventTimeout(eventmask_t ewmask,
|
|
|
|
systime_t time) {
|
|
|
|
|
|
|
|
return chEvtWaitAnyTimeout(ewmask, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
eventmask_t BaseThread::waitAllEventsTimeout(eventmask_t ewmask,
|
|
|
|
systime_t time) {
|
|
|
|
|
|
|
|
return chEvtWaitAllTimeout(ewmask, time);
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_EVENTS_TIMEOUT */
|
2013-01-02 10:47:01 +00:00
|
|
|
|
|
|
|
void BaseThread::dispatchEvents(const evhandler_t handlers[],
|
|
|
|
eventmask_t mask) {
|
|
|
|
|
|
|
|
chEvtDispatch(handlers, mask);
|
|
|
|
}
|
2013-01-02 10:11:02 +00:00
|
|
|
#endif /* CH_USE_EVENTS */
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
#if CH_USE_MUTEXES
|
|
|
|
void BaseThread::unlockMutex(void) {
|
|
|
|
|
|
|
|
chMtxUnlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseThread::unlockMutexS(void) {
|
|
|
|
|
|
|
|
chMtxUnlockS();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseThread::unlockAllMutexes(void) {
|
|
|
|
|
|
|
|
chMtxUnlockAll();
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_MUTEXES */
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
#if CH_USE_SEMAPHORES
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::Semaphore *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
Semaphore::Semaphore(cnt_t n) {
|
|
|
|
|
|
|
|
chSemInit(&sem, n);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void Semaphore::reset(cnt_t n) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
chSemReset(&sem, n);
|
|
|
|
}
|
|
|
|
|
2013-01-02 13:30:07 +00:00
|
|
|
void Semaphore::resetI(cnt_t n) {
|
|
|
|
|
|
|
|
chSemResetI(&sem, n);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t Semaphore::wait(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
return chSemWait(&sem);
|
|
|
|
}
|
|
|
|
|
2013-01-02 13:30:07 +00:00
|
|
|
msg_t Semaphore::waitS(void) {
|
|
|
|
|
|
|
|
return chSemWaitS(&sem);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t Semaphore::waitTimeout(systime_t time) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
return chSemWaitTimeout(&sem, time);
|
|
|
|
}
|
|
|
|
|
2013-01-02 13:30:07 +00:00
|
|
|
msg_t Semaphore::waitTimeoutS(systime_t time) {
|
|
|
|
|
|
|
|
return chSemWaitTimeoutS(&sem, time);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void Semaphore::signal(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
chSemSignal(&sem);
|
|
|
|
}
|
|
|
|
|
2013-01-02 13:30:07 +00:00
|
|
|
void Semaphore::signalI(void) {
|
|
|
|
|
|
|
|
chSemSignalI(&sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Semaphore::addCounterI(cnt_t n) {
|
|
|
|
|
|
|
|
chSemAddCounterI(&sem, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt_t Semaphore::getCounterI(void) {
|
|
|
|
|
|
|
|
return chSemGetCounterI(&sem);
|
|
|
|
}
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
#if CH_USE_SEMSW
|
2013-01-02 14:01:11 +00:00
|
|
|
msg_t Semaphore::signalWait(chibios_rt::Semaphore *ssem,
|
|
|
|
chibios_rt::Semaphore *wsem) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
return chSemSignalWait(&ssem->sem, &wsem->sem);
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_SEMSW */
|
|
|
|
#endif /* CH_USE_SEMAPHORES */
|
|
|
|
|
|
|
|
#if CH_USE_MUTEXES
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::Mutex *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
Mutex::Mutex(void) {
|
|
|
|
|
|
|
|
chMtxInit(&mutex);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
bool Mutex::tryLock(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
return chMtxTryLock(&mutex);
|
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
bool Mutex::tryLockS(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
return chMtxTryLockS(&mutex);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
void Mutex::lock(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
chMtxLock(&mutex);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
void Mutex::lockS(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
chMtxLockS(&mutex);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if CH_USE_CONDVARS
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::CondVar *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
CondVar::CondVar(void) {
|
|
|
|
|
|
|
|
chCondInit(&condvar);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void CondVar::signal(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
chCondSignal(&condvar);
|
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
void CondVar::signalI(void) {
|
|
|
|
|
|
|
|
chCondSignalI(&condvar);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
void CondVar::broadcast(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
chCondBroadcast(&condvar);
|
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
void CondVar::broadcastI(void) {
|
|
|
|
|
|
|
|
chCondBroadcastI(&condvar);
|
|
|
|
}
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t CondVar::wait(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
return chCondWait(&condvar);
|
|
|
|
}
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
msg_t CondVar::waitS(void) {
|
|
|
|
|
|
|
|
return chCondWaitS(&condvar);
|
|
|
|
}
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
#if CH_USE_CONDVARS_TIMEOUT
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t CondVar::waitTimeout(systime_t time) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
return chCondWaitTimeout(&condvar, time);
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_CONDVARS_TIMEOUT */
|
|
|
|
#endif /* CH_USE_CONDVARS */
|
|
|
|
#endif /* CH_USE_MUTEXES */
|
|
|
|
|
|
|
|
#if CH_USE_EVENTS
|
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-02 10:47:01 +00:00
|
|
|
* chibios_rt::EvtListener *
|
2009-08-16 13:07:24 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
2013-01-02 10:47:01 +00:00
|
|
|
flagsmask_t EvtListener::getAndClearFlags(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
return chEvtGetAndClearFlags(&ev_listener);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-02 10:47:01 +00:00
|
|
|
* chibios_rt::EvtSource *
|
2013-01-02 10:11:02 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
2013-01-02 10:47:01 +00:00
|
|
|
EvtSource::EvtSource(void) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 10:47:01 +00:00
|
|
|
chEvtInit(&ev_source);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 10:47:01 +00:00
|
|
|
void EvtSource::registerOne(chibios_rt::EvtListener *elp,
|
2013-01-02 10:11:02 +00:00
|
|
|
eventid_t eid) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
chEvtRegister(&ev_source, &elp->ev_listener, eid);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 10:47:01 +00:00
|
|
|
void EvtSource::registerMask(chibios_rt::EvtListener *elp,
|
2013-01-02 10:11:02 +00:00
|
|
|
eventmask_t emask) {
|
2013-01-02 08:32:03 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
chEvtRegisterMask(&ev_source, &elp->ev_listener, emask);
|
2013-01-02 08:32:03 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 10:47:01 +00:00
|
|
|
void EvtSource::unregister(chibios_rt::EvtListener *elp) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
chEvtUnregister(&ev_source, &elp->ev_listener);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 10:47:01 +00:00
|
|
|
void EvtSource::broadcastFlags(flagsmask_t flags) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
chEvtBroadcastFlags(&ev_source, flags);
|
2013-01-01 09:37:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 10:47:01 +00:00
|
|
|
void EvtSource::broadcastFlagsI(flagsmask_t flags) {
|
2013-01-01 09:37:24 +00:00
|
|
|
|
2013-01-02 10:11:02 +00:00
|
|
|
chEvtBroadcastFlagsI(&ev_source, flags);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
#endif /* CH_USE_EVENTS */
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|