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-03 09:52:04 +00:00
|
|
|
bool System::isTimeWithin(systime_t start, systime_t end) {
|
2013-01-02 14:01:11 +00:00
|
|
|
|
|
|
|
return (bool)chTimeIsWithin(start, end);
|
|
|
|
}
|
|
|
|
|
2013-01-03 09:52:04 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::Core *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
void *Core::alloc(size_t size) {
|
|
|
|
|
|
|
|
return chCoreAlloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Core::allocI(size_t size) {
|
|
|
|
|
|
|
|
return chCoreAllocI(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Core::getStatus(void) {
|
|
|
|
|
|
|
|
return chCoreStatus();
|
|
|
|
}
|
|
|
|
|
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-03 09:52:04 +00:00
|
|
|
#if CH_USE_WAITEXIT
|
2013-01-01 15:42:44 +00:00
|
|
|
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-03 09:52:04 +00:00
|
|
|
#if CH_USE_MESSAGES
|
2013-01-01 15:42:44 +00:00
|
|
|
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-03 16:17:42 +00:00
|
|
|
|
|
|
|
msg_t ThreadReference::getMessage(void) {
|
|
|
|
|
|
|
|
return chMsgGet(thread_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadReference::releaseMessage(msg_t msg) {
|
|
|
|
|
|
|
|
chMsgRelease(thread_ref, msg);
|
|
|
|
}
|
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-03 16:17:42 +00:00
|
|
|
msg_t BaseThread::main(void) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadReference BaseThread::start(tprio_t prio) {
|
|
|
|
|
|
|
|
(void)prio;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
};
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t _thd_start(void *arg) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-03 16:17:42 +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-04 09:38:41 +00:00
|
|
|
#if CH_USE_MESSAGES
|
|
|
|
ThreadReference BaseThread::waitMessage(void) {
|
|
|
|
|
|
|
|
ThreadReference tr(chMsgWait());
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_MESSAGES */
|
|
|
|
|
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 */
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::BinarySemaphore *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
BinarySemaphore::BinarySemaphore(bool taken) {
|
|
|
|
|
|
|
|
chBSemInit(&bsem, (bool_t)taken);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t BinarySemaphore::wait(void) {
|
|
|
|
|
|
|
|
return chBSemWait(&bsem);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t BinarySemaphore::waitS(void) {
|
|
|
|
|
|
|
|
return chBSemWaitS(&bsem);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t BinarySemaphore::waitTimeout(systime_t time) {
|
|
|
|
|
|
|
|
return chBSemWaitTimeout(&bsem, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t BinarySemaphore::waitTimeoutS(systime_t time) {
|
|
|
|
|
|
|
|
return chBSemWaitTimeoutS(&bsem, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinarySemaphore::reset(bool taken) {
|
|
|
|
|
|
|
|
chBSemReset(&bsem, (bool_t)taken);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinarySemaphore::resetI(bool taken) {
|
|
|
|
|
|
|
|
chBSemResetI(&bsem, (bool_t)taken);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinarySemaphore::signal(void) {
|
|
|
|
|
|
|
|
chBSemSignal(&bsem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinarySemaphore::signalI(void) {
|
|
|
|
|
|
|
|
chBSemSignalI(&bsem);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BinarySemaphore::getStateI(void) {
|
|
|
|
|
|
|
|
return (bool)chBSemGetStateI(&bsem);
|
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
#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-03 18:28:21 +00:00
|
|
|
flagsmask_t EvtListener::getAndClearFlagsI(void) {
|
|
|
|
|
|
|
|
return chEvtGetAndClearFlagsI(&ev_listener);
|
|
|
|
}
|
|
|
|
|
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 */
|
2013-01-02 15:00:20 +00:00
|
|
|
|
2013-01-03 09:52:04 +00:00
|
|
|
#if CH_USE_QUEUES
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::InputQueue *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
InputQueue::InputQueue(uint8_t *bp, size_t size,
|
|
|
|
qnotify_t infy, void *link) {
|
|
|
|
|
|
|
|
chIQInit(&iq, bp, size, infy, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t InputQueue::getFullI(void) {
|
|
|
|
|
|
|
|
return chIQGetFullI(&iq);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t InputQueue::getEmptyI(void) {
|
|
|
|
|
|
|
|
return chIQGetEmptyI(&iq);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputQueue::isEmptyI(void) {
|
|
|
|
|
|
|
|
return (bool)chIQIsEmptyI(&iq);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputQueue::isFullI(void) {
|
|
|
|
|
|
|
|
return (bool)chIQIsFullI(&iq);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputQueue::resetI(void) {
|
|
|
|
|
|
|
|
chIQResetI(&iq);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t InputQueue::putI(uint8_t b) {
|
|
|
|
|
|
|
|
return chIQPutI(&iq, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t InputQueue::get() {
|
|
|
|
|
|
|
|
return chIQGet(&iq);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t InputQueue::getTimeout(systime_t time) {
|
|
|
|
|
|
|
|
return chIQGetTimeout(&iq, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t InputQueue::readTimeout(uint8_t *bp, size_t n, systime_t time) {
|
|
|
|
|
|
|
|
return chIQReadTimeout(&iq, bp, n, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::OutputQueue *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
OutputQueue::OutputQueue(uint8_t *bp, size_t size,
|
|
|
|
qnotify_t onfy, void *link) {
|
|
|
|
|
|
|
|
chOQInit(&oq, bp, size, onfy, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t OutputQueue::getFullI(void) {
|
|
|
|
|
|
|
|
return chOQGetFullI(&oq);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t OutputQueue::getEmptyI(void) {
|
|
|
|
|
|
|
|
return chOQGetEmptyI(&oq);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OutputQueue::isEmptyI(void) {
|
|
|
|
|
|
|
|
return (bool)chOQIsEmptyI(&oq);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OutputQueue::isFullI(void) {
|
|
|
|
|
|
|
|
return (bool)chOQIsFullI(&oq);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputQueue::resetI(void) {
|
|
|
|
|
|
|
|
chOQResetI(&oq);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t OutputQueue::put(uint8_t b) {
|
|
|
|
|
|
|
|
return chOQPut(&oq, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t OutputQueue::putTimeout(uint8_t b, systime_t time) {
|
|
|
|
|
|
|
|
return chOQPutTimeout(&oq, b, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t OutputQueue::getI(void) {
|
|
|
|
|
|
|
|
return chOQGetI(&oq);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t OutputQueue::writeTimeout(const uint8_t *bp, size_t n,
|
|
|
|
systime_t time) {
|
|
|
|
|
|
|
|
return chOQWriteTimeout(&oq, bp, n, time);
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_QUEUES */
|
|
|
|
|
|
|
|
#if CH_USE_MAILBOXES
|
2013-01-02 15:00:20 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::Mailbox *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
Mailbox::Mailbox(msg_t *buf, cnt_t n) {
|
|
|
|
|
|
|
|
chMBInit(&mb, buf, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mailbox::reset(void) {
|
|
|
|
|
|
|
|
chMBReset(&mb);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::post(msg_t msg, systime_t time) {
|
|
|
|
|
|
|
|
return chMBPost(&mb, msg, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::postS(msg_t msg, systime_t time) {
|
|
|
|
|
|
|
|
return chMBPostS(&mb, msg, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::postI(msg_t msg) {
|
|
|
|
|
|
|
|
return chMBPostI(&mb, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::postAhead(msg_t msg, systime_t time) {
|
|
|
|
|
|
|
|
return chMBPostAhead(&mb, msg, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::postAheadS(msg_t msg, systime_t time) {
|
|
|
|
|
|
|
|
return chMBPostAheadS(&mb, msg, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::postAheadI(msg_t msg) {
|
|
|
|
|
|
|
|
return chMBPostAheadI(&mb, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::fetch(msg_t *msgp, systime_t time) {
|
|
|
|
|
|
|
|
return chMBFetch(&mb, msgp, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::fetchS(msg_t *msgp, systime_t time) {
|
|
|
|
|
|
|
|
return chMBFetchS(&mb, msgp, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t Mailbox::fetchI(msg_t *msgp) {
|
|
|
|
|
|
|
|
return chMBFetchI(&mb, msgp);
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_MAILBOXES */
|
2013-01-02 18:42:39 +00:00
|
|
|
|
|
|
|
#if CH_USE_MEMPOOLS
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::MemoryPool *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
MemoryPool::MemoryPool(size_t size, memgetfunc_t provider) {
|
|
|
|
|
|
|
|
chPoolInit(&pool, size, provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryPool::loadArray(void *p, size_t n) {
|
|
|
|
|
|
|
|
chPoolLoadArray(&pool, p, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *MemoryPool::allocI(void) {
|
|
|
|
|
|
|
|
return chPoolAlloc(&pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *MemoryPool::alloc(void) {
|
|
|
|
|
|
|
|
return chPoolAllocI(&pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryPool::free(void *objp) {
|
|
|
|
|
|
|
|
chPoolFree(&pool, objp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryPool::freeI(void *objp) {
|
|
|
|
|
|
|
|
chPoolFreeI(&pool, objp);
|
|
|
|
}
|
|
|
|
#endif /* CH_USE_MEMPOOLS */
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|