From 0d96f5c78e54d267ef1ca230fe20af1ca090e1d6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Jun 2013 12:21:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5859 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 +- os/kernel/src/chthreads.c | 2 +- os/kernel/src/chvt.c | 124 +++++++++++++++++++++++++++------------------- 3 files changed, 75 insertions(+), 53 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 1106cf03f..285c36ba3 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -189,7 +189,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { chVTSetI(&vt, time, wakeup, currp); chSchGoSleepS(newstate); if (chVTIsArmedI(&vt)) - chVTResetI(&vt); + chVTDoResetI(&vt); } else chSchGoSleepS(newstate); diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 9f6973c90..7652cbfb1 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -302,7 +302,7 @@ void chThdSleep(systime_t time) { void chThdSleepUntil(systime_t time) { chSysLock(); - if ((time -= chTimeNow()) > 0) + if ((time -= chVTGetSystemTimeI()) > 0) chThdSleepS(time); chSysUnlock(); } diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index a8e3ce499..d27f3170c 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -20,7 +20,7 @@ /** * @file chvt.c - * @brief Time and Virtual Timers related code. + * @brief Time and Virtual Timers module code. * * @addtogroup time * @details Time and Virtual Timers related APIs and services. @@ -29,11 +29,35 @@ #include "ch.h" +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + /** * @brief Virtual timers delta list header. */ VTList vtlist; +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Virtual Timers initialization. * @note Internal use only. @@ -43,21 +67,37 @@ VTList vtlist; void _vt_init(void) { vtlist.vt_next = vtlist.vt_prev = (void *)&vtlist; - vtlist.vt_time = (systime_t)-1; - vtlist.vt_systime = 0; + vtlist.vt_time = 0; +} + +/** + * @brief Checks if the current system time is within the specified time + * window. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval TRUE current time within the specified time window. + * @retval FALSE current time not within the specified time window. + * + * @api + */ +bool_t chVTIsSystemTimeWithin(systime_t start, systime_t end) { + + systime_t time = chVTGetSystemTime(); + return end > start ? (time >= start) && (time < end) : + (time >= start) || (time < end); } /** * @brief Enables a virtual timer. + * @details The timer is enabled and programmed to trigger at the absolute + * system time specified as parameter. * @note The associated function is invoked from interrupt context. * * @param[out] vtp the @p VirtualTimer structure pointer - * @param[in] time the number of ticks before the operation timeouts, the - * special values are handled as follow: - * - @a TIME_INFINITE is allowed but interpreted as a - * normal time specification. - * - @a TIME_IMMEDIATE this value is not allowed. - * . + * @param[in] time absolute system time * @param[in] vtfunc the timer callback function. After invoking the * callback the timer is disabled and the structure can * be disposed or reused. @@ -66,31 +106,36 @@ void _vt_init(void) { * * @iclass */ -void chVTSetI(VirtualTimer *vtp, systime_t time, vtfunc_t vtfunc, void *par) { +void chVTSetAbsoluteI(VirtualTimer *vtp, systime_t time, + vtfunc_t vtfunc, void *par) { VirtualTimer *p; + systime_t systime = vtlist.vt_time; chDbgCheckClassI(); - chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (time != TIME_IMMEDIATE), - "chVTSetI"); + chDbgCheck((vtp != NULL) && (vtfunc != NULL), "chVTSetI"); vtp->vt_par = par; vtp->vt_func = vtfunc; - p = vtlist.vt_next; - while (p->vt_time < time) { - time -= p->vt_time; - p = p->vt_next; - } - - vtp->vt_prev = (vtp->vt_next = p)->vt_prev; - vtp->vt_prev->vt_next = p->vt_prev = vtp; vtp->vt_time = time; - if (p != (void *)&vtlist) - p->vt_time -= time; + if (time <= systime) { + p = vtlist.vt_prev; + while ((p->vt_time <= systime) && (p->vt_time > time)) + p = p->vt_prev; + vtp->vt_next = (vtp->vt_prev = p)->vt_next; + vtp->vt_next->vt_prev = p->vt_next = vtp; + } + else { + p = vtlist.vt_next; + while ((p->vt_time > systime) && (p->vt_time < time)) + p = p->vt_next; + vtp->vt_prev = (vtp->vt_next = p)->vt_prev; + vtp->vt_prev->vt_next = p->vt_prev = vtp; + } } /** * @brief Disables a Virtual Timer. - * @note The timer MUST be active when this function is invoked. + * @note The timer is first checked and disabled only if armed. * * @param[in] vtp the @p VirtualTimer structure pointer * @@ -100,35 +145,12 @@ void chVTResetI(VirtualTimer *vtp) { chDbgCheckClassI(); chDbgCheck(vtp != NULL, "chVTResetI"); - chDbgAssert(vtp->vt_func != NULL, - "chVTResetI(), #1", - "timer not set or already triggered"); - - if (vtp->vt_next != (void *)&vtlist) - vtp->vt_next->vt_time += vtp->vt_time; - vtp->vt_prev->vt_next = vtp->vt_next; - vtp->vt_next->vt_prev = vtp->vt_prev; - vtp->vt_func = (vtfunc_t)NULL; -} -/** - * @brief Checks if the current system time is within the specified time - * window. - * @note When start==end then the function returns always true because the - * whole time range is specified. - * - * @param[in] start the start of the time window (inclusive) - * @param[in] end the end of the time window (non inclusive) - * @retval TRUE current time within the specified time window. - * @retval FALSE current time not within the specified time window. - * - * @api - */ -bool_t chTimeIsWithin(systime_t start, systime_t end) { - - systime_t time = chTimeNow(); - return end > start ? (time >= start) && (time < end) : - (time >= start) || (time < end); + if (chVTIsArmedI(vtp)) { + vtp->vt_prev->vt_next = vtp->vt_next; + vtp->vt_next->vt_prev = vtp->vt_prev; + vtp->vt_func = (vtfunc_t)NULL; + } } /** @} */ -- cgit v1.2.3 From 2e4ba09bb54f415e7f8fd66f4ccddbf421612820 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Jun 2013 16:12:33 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5860 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 4 ++-- os/kernel/src/chqueues.c | 8 ++++---- os/kernel/src/chsem.c | 32 ++++++++++++++++---------------- os/kernel/src/chthreads.c | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index c217bf6fd..0e404808f 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -68,7 +68,7 @@ void chCondSignal(CondVar *cp) { chDbgCheck(cp != NULL, "chCondSignal"); chSysLock(); - if (notempty(&cp->c_queue)) + if (queue_notempty(&cp->c_queue)) chSchWakeupS(fifo_remove(&cp->c_queue), RDY_OK); chSysUnlock(); } @@ -89,7 +89,7 @@ void chCondSignalI(CondVar *cp) { chDbgCheckClassI(); chDbgCheck(cp != NULL, "chCondSignalI"); - if (notempty(&cp->c_queue)) + if (queue_notempty(&cp->c_queue)) chSchReadyI(fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_OK; } diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index 871e499a0..fa2bd527b 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -113,7 +113,7 @@ void chIQResetI(InputQueue *iqp) { iqp->q_rdptr = iqp->q_wrptr = iqp->q_buffer; iqp->q_counter = 0; - while (notempty(&iqp->q_waiting)) + while (queue_notempty(&iqp->q_waiting)) chSchReadyI(fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_RESET; } @@ -142,7 +142,7 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) { if (iqp->q_wrptr >= iqp->q_top) iqp->q_wrptr = iqp->q_buffer; - if (notempty(&iqp->q_waiting)) + if (queue_notempty(&iqp->q_waiting)) chSchReadyI(fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_OK; return Q_OK; @@ -293,7 +293,7 @@ void chOQResetI(OutputQueue *oqp) { oqp->q_rdptr = oqp->q_wrptr = oqp->q_buffer; oqp->q_counter = chQSizeI(oqp); - while (notempty(&oqp->q_waiting)) + while (queue_notempty(&oqp->q_waiting)) chSchReadyI(fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_RESET; } @@ -366,7 +366,7 @@ msg_t chOQGetI(OutputQueue *oqp) { if (oqp->q_rdptr >= oqp->q_top) oqp->q_rdptr = oqp->q_buffer; - if (notempty(&oqp->q_waiting)) + if (queue_notempty(&oqp->q_waiting)) chSchReadyI(fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_OK; return b; diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index 2dc7ee354..7ea365291 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -131,8 +131,8 @@ void chSemResetI(Semaphore *sp, cnt_t n) { chDbgCheckClassI(); chDbgCheck((sp != NULL) && (n >= 0), "chSemResetI"); - chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), "chSemResetI(), #1", "inconsistent semaphore"); @@ -179,8 +179,8 @@ msg_t chSemWaitS(Semaphore *sp) { chDbgCheckClassS(); chDbgCheck(sp != NULL, "chSemWaitS"); - chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), "chSemWaitS(), #1", "inconsistent semaphore"); @@ -244,8 +244,8 @@ msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) { chDbgCheckClassS(); chDbgCheck(sp != NULL, "chSemWaitTimeoutS"); - chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), "chSemWaitTimeoutS(), #1", "inconsistent semaphore"); @@ -271,8 +271,8 @@ msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) { void chSemSignal(Semaphore *sp) { chDbgCheck(sp != NULL, "chSemSignal"); - chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), "chSemSignal(), #1", "inconsistent semaphore"); @@ -297,8 +297,8 @@ void chSemSignalI(Semaphore *sp) { chDbgCheckClassI(); chDbgCheck(sp != NULL, "chSemSignalI"); - chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), "chSemSignalI(), #1", "inconsistent semaphore"); @@ -328,8 +328,8 @@ void chSemAddCounterI(Semaphore *sp, cnt_t n) { chDbgCheckClassI(); chDbgCheck((sp != NULL) && (n > 0), "chSemAddCounterI"); - chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && notempty(&sp->s_queue)), + chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || + ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), "chSemAddCounterI(), #1", "inconsistent semaphore"); @@ -360,12 +360,12 @@ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) { msg_t msg; chDbgCheck((sps != NULL) && (spw != NULL), "chSemSignalWait"); - chDbgAssert(((sps->s_cnt >= 0) && isempty(&sps->s_queue)) || - ((sps->s_cnt < 0) && notempty(&sps->s_queue)), + chDbgAssert(((sps->s_cnt >= 0) && queue_isempty(&sps->s_queue)) || + ((sps->s_cnt < 0) && queue_notempty(&sps->s_queue)), "chSemSignalWait(), #1", "inconsistent semaphore"); - chDbgAssert(((spw->s_cnt >= 0) && isempty(&spw->s_queue)) || - ((spw->s_cnt < 0) && notempty(&spw->s_queue)), + chDbgAssert(((spw->s_cnt >= 0) && queue_isempty(&spw->s_queue)) || + ((spw->s_cnt < 0) && queue_notempty(&spw->s_queue)), "chSemSignalWait(), #2", "inconsistent semaphore"); diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 7652cbfb1..37d25eb7b 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -364,7 +364,7 @@ void chThdExitS(msg_t msg) { THREAD_EXT_EXIT_HOOK(tp); #endif #if CH_USE_WAITEXIT - while (notempty(&tp->p_waiting)) + while (list_notempty(&tp->p_waiting)) chSchReadyI(list_remove(&tp->p_waiting)); #endif #if CH_USE_REGISTRY -- cgit v1.2.3 From 745d8c15044781f1215f2188edcc402fafadd059 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Jun 2013 16:30:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5861 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 10 +++++----- os/kernel/src/chlists.c | 8 ++++---- os/kernel/src/chmsg.c | 2 +- os/kernel/src/chmtx.c | 14 +++++++------- os/kernel/src/chqueues.c | 8 ++++---- os/kernel/src/chschd.c | 8 ++++---- os/kernel/src/chsem.c | 10 +++++----- 7 files changed, 30 insertions(+), 30 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index 0e404808f..e6bf51652 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -69,7 +69,7 @@ void chCondSignal(CondVar *cp) { chSysLock(); if (queue_notempty(&cp->c_queue)) - chSchWakeupS(fifo_remove(&cp->c_queue), RDY_OK); + chSchWakeupS(queue_fifo_remove(&cp->c_queue), RDY_OK); chSysUnlock(); } @@ -90,7 +90,7 @@ void chCondSignalI(CondVar *cp) { chDbgCheck(cp != NULL, "chCondSignalI"); if (queue_notempty(&cp->c_queue)) - chSchReadyI(fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_OK; + chSchReadyI(queue_fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_OK; } /** @@ -128,7 +128,7 @@ void chCondBroadcastI(CondVar *cp) { ready list in FIFO order. The wakeup message is set to @p RDY_RESET in order to make a chCondBroadcast() detectable from a chCondSignal().*/ while (cp->c_queue.p_next != (void *)&cp->c_queue) - chSchReadyI(fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_RESET; + chSchReadyI(queue_fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_RESET; } /** @@ -187,7 +187,7 @@ msg_t chCondWaitS(CondVar *cp) { mp = chMtxUnlockS(); ctp->p_u.wtobjp = cp; - prio_insert(ctp, &cp->c_queue); + queue_prio_insert(ctp, &cp->c_queue); chSchGoSleepS(THD_STATE_WTCOND); msg = ctp->p_u.rdymsg; chMtxLockS(mp); @@ -272,7 +272,7 @@ msg_t chCondWaitTimeoutS(CondVar *cp, systime_t time) { mp = chMtxUnlockS(); currp->p_u.wtobjp = cp; - prio_insert(currp, &cp->c_queue); + queue_prio_insert(currp, &cp->c_queue); msg = chSchGoSleepTimeoutS(THD_STATE_WTCOND, time); if (msg != RDY_TIMEOUT) chMtxLockS(mp); diff --git a/os/kernel/src/chlists.c b/os/kernel/src/chlists.c index 8ee309200..2183171a7 100644 --- a/os/kernel/src/chlists.c +++ b/os/kernel/src/chlists.c @@ -41,7 +41,7 @@ * * @notapi */ -void prio_insert(Thread *tp, ThreadsQueue *tqp) { +void queue_prio_insert(Thread *tp, ThreadsQueue *tqp) { /* cp iterates over the queue.*/ Thread *cp = (Thread *)tqp; @@ -81,7 +81,7 @@ void queue_insert(Thread *tp, ThreadsQueue *tqp) { * * @notapi */ -Thread *fifo_remove(ThreadsQueue *tqp) { +Thread *queue_fifo_remove(ThreadsQueue *tqp) { Thread *tp = tqp->p_next; (tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp; @@ -98,7 +98,7 @@ Thread *fifo_remove(ThreadsQueue *tqp) { * * @notapi */ -Thread *lifo_remove(ThreadsQueue *tqp) { +Thread *queue_lifo_remove(ThreadsQueue *tqp) { Thread *tp = tqp->p_prev; (tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp; @@ -115,7 +115,7 @@ Thread *lifo_remove(ThreadsQueue *tqp) { * * @notapi */ -Thread *dequeue(Thread *tp) { +Thread *queue_dequeue(Thread *tp) { tp->p_prev->p_next = tp->p_next; tp->p_next->p_prev = tp->p_prev; diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index ad97da79c..d27713ef0 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -102,7 +102,7 @@ Thread *chMsgWait(void) { chSysLock(); if (!chMsgIsPendingI(currp)) chSchGoSleepS(THD_STATE_WTMSG); - tp = fifo_remove(&currp->p_msgqueue); + tp = queue_fifo_remove(&currp->p_msgqueue); tp->p_state = THD_STATE_SNDMSG; chSysUnlock(); return tp; diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index 84d7e53a6..adeb0dd52 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -132,7 +132,7 @@ void chMtxLockS(Mutex *mp) { switch (tp->p_state) { case THD_STATE_WTMTX: /* Re-enqueues the mutex owner with its new priority.*/ - prio_insert(dequeue(tp), (ThreadsQueue *)tp->p_u.wtobjp); + queue_prio_insert(queue_dequeue(tp), (ThreadsQueue *)tp->p_u.wtobjp); tp = ((Mutex *)tp->p_u.wtobjp)->m_owner; continue; #if CH_USE_CONDVARS | \ @@ -148,7 +148,7 @@ void chMtxLockS(Mutex *mp) { case THD_STATE_SNDMSGQ: #endif /* Re-enqueues tp with its new priority on the queue.*/ - prio_insert(dequeue(tp), (ThreadsQueue *)tp->p_u.wtobjp); + queue_prio_insert(queue_dequeue(tp), (ThreadsQueue *)tp->p_u.wtobjp); break; #endif case THD_STATE_READY: @@ -157,13 +157,13 @@ void chMtxLockS(Mutex *mp) { tp->p_state = THD_STATE_CURRENT; #endif /* Re-enqueues tp with its new priority on the ready list.*/ - chSchReadyI(dequeue(tp)); + chSchReadyI(queue_dequeue(tp)); break; } break; } /* Sleep on the mutex.*/ - prio_insert(ctp, &mp->m_queue); + queue_prio_insert(ctp, &mp->m_queue); ctp->p_u.wtobjp = mp; chSchGoSleepS(THD_STATE_WTMTX); /* It is assumed that the thread performing the unlock operation assigns @@ -283,7 +283,7 @@ Mutex *chMtxUnlock(void) { ctp->p_prio = newprio; /* Awakens the highest priority thread waiting for the unlocked mutex and assigns the mutex to it.*/ - tp = fifo_remove(&ump->m_queue); + tp = queue_fifo_remove(&ump->m_queue); ump->m_owner = tp; ump->m_next = tp->p_mtxlist; tp->p_mtxlist = ump; @@ -342,7 +342,7 @@ Mutex *chMtxUnlockS(void) { ctp->p_prio = newprio; /* Awakens the highest priority thread waiting for the unlocked mutex and assigns the mutex to it.*/ - tp = fifo_remove(&ump->m_queue); + tp = queue_fifo_remove(&ump->m_queue); ump->m_owner = tp; ump->m_next = tp->p_mtxlist; tp->p_mtxlist = ump; @@ -373,7 +373,7 @@ void chMtxUnlockAll(void) { Mutex *ump = ctp->p_mtxlist; ctp->p_mtxlist = ump->m_next; if (chMtxQueueNotEmptyS(ump)) { - Thread *tp = fifo_remove(&ump->m_queue); + Thread *tp = queue_fifo_remove(&ump->m_queue); ump->m_owner = tp; ump->m_next = tp->p_mtxlist; tp->p_mtxlist = ump; diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index fa2bd527b..a4b0aa416 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -114,7 +114,7 @@ void chIQResetI(InputQueue *iqp) { iqp->q_rdptr = iqp->q_wrptr = iqp->q_buffer; iqp->q_counter = 0; while (queue_notempty(&iqp->q_waiting)) - chSchReadyI(fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_RESET; + chSchReadyI(queue_fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_RESET; } /** @@ -143,7 +143,7 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) { iqp->q_wrptr = iqp->q_buffer; if (queue_notempty(&iqp->q_waiting)) - chSchReadyI(fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_OK; + chSchReadyI(queue_fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_OK; return Q_OK; } @@ -294,7 +294,7 @@ void chOQResetI(OutputQueue *oqp) { oqp->q_rdptr = oqp->q_wrptr = oqp->q_buffer; oqp->q_counter = chQSizeI(oqp); while (queue_notempty(&oqp->q_waiting)) - chSchReadyI(fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_RESET; + chSchReadyI(queue_fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_RESET; } /** @@ -367,7 +367,7 @@ msg_t chOQGetI(OutputQueue *oqp) { oqp->q_rdptr = oqp->q_buffer; if (queue_notempty(&oqp->q_waiting)) - chSchReadyI(fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_OK; + chSchReadyI(queue_fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_OK; return b; } diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 285c36ba3..ab9b88040 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -116,7 +116,7 @@ void chSchGoSleepS(tstate_t newstate) { time quantum when it will wakeup.*/ otp->p_preempt = CH_TIME_QUANTUM; #endif - setcurrp(fifo_remove(&rlist.r_queue)); + setcurrp(queue_fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; chSysSwitch(currp, otp); } @@ -150,7 +150,7 @@ static void wakeup(void *p) { case THD_STATE_WTCOND: #endif /* States requiring dequeuing.*/ - dequeue(tp); + queue_dequeue(tp); #endif } tp->p_u.rdymsg = RDY_TIMEOUT; @@ -299,7 +299,7 @@ void chSchDoRescheduleBehind(void) { otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ - setcurrp(fifo_remove(&rlist.r_queue)); + setcurrp(queue_fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; #if CH_TIME_QUANTUM > 0 otp->p_preempt = CH_TIME_QUANTUM; @@ -324,7 +324,7 @@ void chSchDoRescheduleAhead(void) { otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ - setcurrp(fifo_remove(&rlist.r_queue)); + setcurrp(queue_fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; otp->p_state = THD_STATE_READY; diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index 7ea365291..c91264b9d 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -139,7 +139,7 @@ void chSemResetI(Semaphore *sp, cnt_t n) { cnt = sp->s_cnt; sp->s_cnt = n; while (++cnt <= 0) - chSchReadyI(lifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_RESET; + chSchReadyI(queue_lifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_RESET; } /** @@ -278,7 +278,7 @@ void chSemSignal(Semaphore *sp) { chSysLock(); if (++sp->s_cnt <= 0) - chSchWakeupS(fifo_remove(&sp->s_queue), RDY_OK); + chSchWakeupS(queue_fifo_remove(&sp->s_queue), RDY_OK); chSysUnlock(); } @@ -305,7 +305,7 @@ void chSemSignalI(Semaphore *sp) { if (++sp->s_cnt <= 0) { /* Note, it is done this way in order to allow a tail call on chSchReadyI().*/ - Thread *tp = fifo_remove(&sp->s_queue); + Thread *tp = queue_fifo_remove(&sp->s_queue); tp->p_u.rdymsg = RDY_OK; chSchReadyI(tp); } @@ -335,7 +335,7 @@ void chSemAddCounterI(Semaphore *sp, cnt_t n) { while (n > 0) { if (++sp->s_cnt <= 0) - chSchReadyI(fifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_OK; + chSchReadyI(queue_fifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_OK; n--; } } @@ -371,7 +371,7 @@ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) { chSysLock(); if (++sps->s_cnt <= 0) - chSchReadyI(fifo_remove(&sps->s_queue))->p_u.rdymsg = RDY_OK; + chSchReadyI(queue_fifo_remove(&sps->s_queue))->p_u.rdymsg = RDY_OK; if (--spw->s_cnt < 0) { Thread *ctp = currp; sem_insert(ctp, &spw->s_queue); -- cgit v1.2.3 From 43a7a0820fa1873dba8e77d7890b614fb5dd93dd Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Jun 2013 16:48:40 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5862 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chlists.c | 24 ++++++++++++++++++++++++ os/kernel/src/chthreads.c | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chlists.c b/os/kernel/src/chlists.c index 2183171a7..c0961a5c9 100644 --- a/os/kernel/src/chlists.c +++ b/os/kernel/src/chlists.c @@ -30,6 +30,30 @@ */ #include "ch.h" +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + #if !CH_OPTIMIZE_SPEED || defined(__DOXYGEN__) /** * @brief Inserts a thread into a priority ordered queue. diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 37d25eb7b..9f176c6a0 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -56,6 +56,30 @@ #include "ch.h" +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Initializes a thread structure. * @note This is an internal functions, do not use it in application code. -- cgit v1.2.3 From 3739568d8918ee183f432c55ff753867737f1f07 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 16 Jul 2013 17:13:32 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5978 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chvt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index d27f3170c..8864bce0c 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -75,17 +75,18 @@ void _vt_init(void) { * window. * @note When start==end then the function returns always true because the * whole time range is specified. + * @note This function can be called from any context. * + * @param[in] time the time to be verified * @param[in] start the start of the time window (inclusive) * @param[in] end the end of the time window (non inclusive) - * @retval TRUE current time within the specified time window. - * @retval FALSE current time not within the specified time window. + * @retval true current time within the specified time window. + * @retval false current time not within the specified time window. * - * @api + * @special */ -bool_t chVTIsSystemTimeWithin(systime_t start, systime_t end) { +bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) { - systime_t time = chVTGetSystemTime(); return end > start ? (time >= start) && (time < end) : (time >= start) || (time < end); } -- cgit v1.2.3 From 3b6423187e643f8d1005d5fca2617a5485bc16b8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 09:43:11 +0000 Subject: Started renaming the types to follow the _t convention. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5988 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chlists.c | 12 ++++----- os/kernel/src/chmtx.c | 6 +++-- os/kernel/src/chschd.c | 2 +- os/kernel/src/chvt.c | 70 +++++++++++++++++++++++++++---------------------- 4 files changed, 49 insertions(+), 41 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chlists.c b/os/kernel/src/chlists.c index c0961a5c9..9e9b276e6 100644 --- a/os/kernel/src/chlists.c +++ b/os/kernel/src/chlists.c @@ -65,7 +65,7 @@ * * @notapi */ -void queue_prio_insert(Thread *tp, ThreadsQueue *tqp) { +void queue_prio_insert(Thread *tp, threads_queue_t *tqp) { /* cp iterates over the queue.*/ Thread *cp = (Thread *)tqp; @@ -88,7 +88,7 @@ void queue_prio_insert(Thread *tp, ThreadsQueue *tqp) { * * @notapi */ -void queue_insert(Thread *tp, ThreadsQueue *tqp) { +void queue_insert(Thread *tp, threads_queue_t *tqp) { tp->p_next = (Thread *)tqp; tp->p_prev = tqp->p_prev; @@ -105,7 +105,7 @@ void queue_insert(Thread *tp, ThreadsQueue *tqp) { * * @notapi */ -Thread *queue_fifo_remove(ThreadsQueue *tqp) { +Thread *queue_fifo_remove(threads_queue_t *tqp) { Thread *tp = tqp->p_next; (tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp; @@ -122,7 +122,7 @@ Thread *queue_fifo_remove(ThreadsQueue *tqp) { * * @notapi */ -Thread *queue_lifo_remove(ThreadsQueue *tqp) { +Thread *queue_lifo_remove(threads_queue_t *tqp) { Thread *tp = tqp->p_prev; (tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp; @@ -154,7 +154,7 @@ Thread *queue_dequeue(Thread *tp) { * * @notapi */ -void list_insert(Thread *tp, ThreadsList *tlp) { +void list_insert(Thread *tp, threads_list_t *tlp) { tp->p_next = tlp->p_next; tlp->p_next = tp; @@ -169,7 +169,7 @@ void list_insert(Thread *tp, ThreadsList *tlp) { * * @notapi */ -Thread *list_remove(ThreadsList *tlp) { +Thread *list_remove(threads_list_t *tlp) { Thread *tp = tlp->p_next; tlp->p_next = tp->p_next; diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index adeb0dd52..38ecbed74 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -132,7 +132,8 @@ void chMtxLockS(Mutex *mp) { switch (tp->p_state) { case THD_STATE_WTMTX: /* Re-enqueues the mutex owner with its new priority.*/ - queue_prio_insert(queue_dequeue(tp), (ThreadsQueue *)tp->p_u.wtobjp); + queue_prio_insert(queue_dequeue(tp), + (threads_queue_t *)tp->p_u.wtobjp); tp = ((Mutex *)tp->p_u.wtobjp)->m_owner; continue; #if CH_USE_CONDVARS | \ @@ -148,7 +149,8 @@ void chMtxLockS(Mutex *mp) { case THD_STATE_SNDMSGQ: #endif /* Re-enqueues tp with its new priority on the queue.*/ - queue_prio_insert(queue_dequeue(tp), (ThreadsQueue *)tp->p_u.wtobjp); + queue_prio_insert(queue_dequeue(tp), + (threads_queue_t *)tp->p_u.wtobjp); break; #endif case THD_STATE_READY: diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index ab9b88040..4f0fa839d 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -186,7 +186,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { if (TIME_INFINITE != time) { VirtualTimer vt; - chVTSetI(&vt, time, wakeup, currp); + chVTDoSetI(&vt, time, wakeup, currp); chSchGoSleepS(newstate); if (chVTIsArmedI(&vt)) chVTDoResetI(&vt); diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index 8864bce0c..e93b2244c 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -67,7 +67,8 @@ VTList vtlist; void _vt_init(void) { vtlist.vt_next = vtlist.vt_prev = (void *)&vtlist; - vtlist.vt_time = 0; + vtlist.vt_time = (systime_t)-1; + vtlist.vt_systime = 0; } /** @@ -93,12 +94,18 @@ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) { /** * @brief Enables a virtual timer. - * @details The timer is enabled and programmed to trigger at the absolute - * system time specified as parameter. - * @note The associated function is invoked from interrupt context. + * @details The timer is enabled and programmed to trigger after the delay + * specified as parameter. + * @pre The timer must not be already armed before calling this function. + * @note The callback function is invoked from interrupt context. * * @param[out] vtp the @p VirtualTimer structure pointer - * @param[in] time absolute system time + * @param[in] delay the number of ticks before the operation timeouts, the + * special values are handled as follow: + * - @a TIME_INFINITE is allowed but interpreted as a + * normal time specification. + * - @a TIME_IMMEDIATE this value is not allowed. + * . * @param[in] vtfunc the timer callback function. After invoking the * callback the timer is disabled and the structure can * be disposed or reused. @@ -107,51 +114,50 @@ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) { * * @iclass */ -void chVTSetAbsoluteI(VirtualTimer *vtp, systime_t time, - vtfunc_t vtfunc, void *par) { +void chVTDoSetI(VirtualTimer *vtp, systime_t delay, + vtfunc_t vtfunc, void *par) { VirtualTimer *p; - systime_t systime = vtlist.vt_time; chDbgCheckClassI(); - chDbgCheck((vtp != NULL) && (vtfunc != NULL), "chVTSetI"); + chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE), + "chVTDoSetI"); vtp->vt_par = par; vtp->vt_func = vtfunc; - vtp->vt_time = time; - if (time <= systime) { - p = vtlist.vt_prev; - while ((p->vt_time <= systime) && (p->vt_time > time)) - p = p->vt_prev; - vtp->vt_next = (vtp->vt_prev = p)->vt_next; - vtp->vt_next->vt_prev = p->vt_next = vtp; - } - else { - p = vtlist.vt_next; - while ((p->vt_time > systime) && (p->vt_time < time)) - p = p->vt_next; - vtp->vt_prev = (vtp->vt_next = p)->vt_prev; - vtp->vt_prev->vt_next = p->vt_prev = vtp; + p = vtlist.vt_next; + while (p->vt_time < delay) { + delay -= p->vt_time; + p = p->vt_next; } + + vtp->vt_prev = (vtp->vt_next = p)->vt_prev; + vtp->vt_prev->vt_next = p->vt_prev = vtp; + vtp->vt_time = delay; + if (p != (void *)&vtlist) + p->vt_time -= delay; } /** * @brief Disables a Virtual Timer. - * @note The timer is first checked and disabled only if armed. + * @pre The timer must be in armed state before calling this function. * * @param[in] vtp the @p VirtualTimer structure pointer * * @iclass */ -void chVTResetI(VirtualTimer *vtp) { +void chVTDoResetI(VirtualTimer *vtp) { chDbgCheckClassI(); - chDbgCheck(vtp != NULL, "chVTResetI"); - - if (chVTIsArmedI(vtp)) { - vtp->vt_prev->vt_next = vtp->vt_next; - vtp->vt_next->vt_prev = vtp->vt_prev; - vtp->vt_func = (vtfunc_t)NULL; - } + chDbgCheck(vtp != NULL, "chVTDoResetI"); + chDbgAssert(vtp->vt_func != NULL, + "chVTDoResetI(), #1", + "timer not set or already triggered"); + + if (vtp->vt_next != (void *)&vtlist) + vtp->vt_next->vt_time += vtp->vt_time; + vtp->vt_prev->vt_next = vtp->vt_next; + vtp->vt_next->vt_prev = vtp->vt_prev; + vtp->vt_func = (vtfunc_t)NULL; } /** @} */ -- cgit v1.2.3 From 4245ba7659ecdaadd47b0cdd61f3255b83f87d4f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 11:48:43 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5994 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 4f0fa839d..1333fc400 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -23,22 +23,40 @@ * @brief Scheduler code. * * @addtogroup scheduler - * @details This module provides the default portable scheduler code, - * scheduler functions can be individually captured by the port - * layer in order to provide architecture optimized equivalents. - * When a function is captured its default code is not built into - * the OS image, the optimized version is included instead. + * @details This module provides the default portable scheduler code. * @{ */ #include "ch.h" +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + /** * @brief Ready list header. */ -#if !defined(PORT_OPTIMIZED_RLIST_VAR) || defined(__DOXYGEN__) -ReadyList rlist; -#endif /* !defined(PORT_OPTIMIZED_RLIST_VAR) */ +ready_list_t rlist; + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ /** * @brief Scheduler initialization. @@ -70,7 +88,6 @@ void _scheduler_init(void) { * * @iclass */ -#if !defined(PORT_OPTIMIZED_READYI) || defined(__DOXYGEN__) Thread *chSchReadyI(Thread *tp) { Thread *cp; @@ -93,7 +110,6 @@ Thread *chSchReadyI(Thread *tp) { tp->p_prev->p_next = cp->p_prev = tp; return tp; } -#endif /* !defined(PORT_OPTIMIZED_READYI) */ /** * @brief Puts the current thread to sleep into the specified state. @@ -104,7 +120,6 @@ Thread *chSchReadyI(Thread *tp) { * * @sclass */ -#if !defined(PORT_OPTIMIZED_GOSLEEPS) || defined(__DOXYGEN__) void chSchGoSleepS(tstate_t newstate) { Thread *otp; @@ -120,9 +135,7 @@ void chSchGoSleepS(tstate_t newstate) { currp->p_state = THD_STATE_CURRENT; chSysSwitch(currp, otp); } -#endif /* !defined(PORT_OPTIMIZED_GOSLEEPS) */ -#if !defined(PORT_OPTIMIZED_GOSLEEPTIMEOUTS) || defined(__DOXYGEN__) /* * Timeout wakeup callback. */ @@ -195,7 +208,6 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { chSchGoSleepS(newstate); return currp->p_u.rdymsg; } -#endif /* !defined(PORT_OPTIMIZED_GOSLEEPTIMEOUTS) */ /** * @brief Wakes up a thread. @@ -214,7 +226,6 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { * * @sclass */ -#if !defined(PORT_OPTIMIZED_WAKEUPS) || defined(__DOXYGEN__) void chSchWakeupS(Thread *ntp, msg_t msg) { chDbgCheckClassS(); @@ -233,7 +244,6 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { chSysSwitch(ntp, otp); } } -#endif /* !defined(PORT_OPTIMIZED_WAKEUPS) */ /** * @brief Performs a reschedule if a higher priority thread is runnable. @@ -242,7 +252,6 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { * * @sclass */ -#if !defined(PORT_OPTIMIZED_RESCHEDULES) || defined(__DOXYGEN__) void chSchRescheduleS(void) { chDbgCheckClassS(); @@ -250,7 +259,6 @@ void chSchRescheduleS(void) { if (chSchIsRescRequiredI()) chSchDoRescheduleAhead(); } -#endif /* !defined(PORT_OPTIMIZED_RESCHEDULES) */ /** * @brief Evaluates if preemption is required. @@ -265,8 +273,7 @@ void chSchRescheduleS(void) { * * @special */ -#if !defined(PORT_OPTIMIZED_ISPREEMPTIONREQUIRED) || defined(__DOXYGEN__) -bool_t chSchIsPreemptionRequired(void) { +bool chSchIsPreemptionRequired(void) { tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; #if CH_TIME_QUANTUM > 0 @@ -281,7 +288,6 @@ bool_t chSchIsPreemptionRequired(void) { return p1 > p2; #endif } -#endif /* !defined(PORT_OPTIMIZED_ISPREEMPTIONREQUIRED) */ /** * @brief Switches to the first thread on the runnable queue. @@ -293,7 +299,6 @@ bool_t chSchIsPreemptionRequired(void) { * * @special */ -#if !defined(PORT_OPTIMIZED_DORESCHEDULEBEHIND) || defined(__DOXYGEN__) void chSchDoRescheduleBehind(void) { Thread *otp; @@ -307,7 +312,6 @@ void chSchDoRescheduleBehind(void) { chSchReadyI(otp); chSysSwitch(currp, otp); } -#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEBEHIND) */ /** * @brief Switches to the first thread on the runnable queue. @@ -318,7 +322,6 @@ void chSchDoRescheduleBehind(void) { * * @special */ -#if !defined(PORT_OPTIMIZED_DORESCHEDULEAHEAD) || defined(__DOXYGEN__) void chSchDoRescheduleAhead(void) { Thread *otp, *cp; @@ -339,7 +342,6 @@ void chSchDoRescheduleAhead(void) { chSysSwitch(currp, otp); } -#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEAHEAD) */ /** * @brief Switches to the first thread on the runnable queue. @@ -351,7 +353,6 @@ void chSchDoRescheduleAhead(void) { * * @special */ -#if !defined(PORT_OPTIMIZED_DORESCHEDULE) || defined(__DOXYGEN__) void chSchDoReschedule(void) { #if CH_TIME_QUANTUM > 0 @@ -373,6 +374,5 @@ void chSchDoReschedule(void) { chSchDoRescheduleAhead(); #endif /* !(CH_TIME_QUANTUM > 0) */ } -#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULE) */ /** @} */ -- cgit v1.2.3 From 84e044f176cee7c6946b24c36c90f63534b5b369 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 12:22:31 +0000 Subject: Renamed Thread to thread_t. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5995 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 4 ++-- os/kernel/src/chdebug.c | 2 +- os/kernel/src/chdynamic.c | 28 ++++++++++++++-------------- os/kernel/src/chevents.c | 26 +++++++++++++------------- os/kernel/src/chlists.c | 42 +++++++++++++++++++++--------------------- os/kernel/src/chmsg.c | 12 ++++++------ os/kernel/src/chmtx.c | 20 ++++++++++---------- os/kernel/src/chregistry.c | 34 +++++++++++++++++----------------- os/kernel/src/chschd.c | 24 ++++++++++++------------ os/kernel/src/chsem.c | 4 ++-- os/kernel/src/chsys.c | 4 ++-- os/kernel/src/chthreads.c | 33 +++++++++++++++++---------------- 12 files changed, 117 insertions(+), 116 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index e6bf51652..99a641122 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -124,7 +124,7 @@ void chCondBroadcastI(CondVar *cp) { chDbgCheckClassI(); chDbgCheck(cp != NULL, "chCondBroadcastI"); - /* Empties the condition variable queue and inserts all the Threads into the + /* Empties the condition variable queue and inserts all the threads into the ready list in FIFO order. The wakeup message is set to @p RDY_RESET in order to make a chCondBroadcast() detectable from a chCondSignal().*/ while (cp->c_queue.p_next != (void *)&cp->c_queue) @@ -175,7 +175,7 @@ msg_t chCondWait(CondVar *cp) { * @sclass */ msg_t chCondWaitS(CondVar *cp) { - Thread *ctp = currp; + thread_t *ctp = currp; Mutex *mp; msg_t msg; diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index c69ce8f3f..44058dff8 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -232,7 +232,7 @@ void _trace_init(void) { * * @notapi */ -void dbg_trace(Thread *otp) { +void dbg_trace(thread_t *otp) { dbg_trace_buffer.tb_ptr->se_time = chTimeNow(); dbg_trace_buffer.tb_ptr->se_tp = currp; diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c index 632367ca1..3d856a526 100644 --- a/os/kernel/src/chdynamic.c +++ b/os/kernel/src/chdynamic.c @@ -42,7 +42,7 @@ * * @api */ -Thread *chThdAddRef(Thread *tp) { +thread_t *chThdAddRef(thread_t *tp) { chSysLock(); chDbgAssert(tp->p_refs < 255, "chThdAddRef(), #1", "too many references"); @@ -64,7 +64,7 @@ Thread *chThdAddRef(Thread *tp) { * * @api */ -void chThdRelease(Thread *tp) { +void chThdRelease(thread_t *tp) { trefs_t refs; chSysLock(); @@ -114,16 +114,16 @@ void chThdRelease(Thread *tp) { * @param[in] pf the thread function * @param[in] arg an argument passed to the thread function. It can be * @p NULL. - * @return The pointer to the @p Thread structure allocated for + * @return The pointer to the @p thread_t structure allocated for * the thread into the working space area. * @retval NULL if the memory cannot be allocated. * * @api */ -Thread *chThdCreateFromHeap(MemoryHeap *heapp, size_t size, - tprio_t prio, tfunc_t pf, void *arg) { +thread_t *chThdCreateFromHeap(MemoryHeap *heapp, size_t size, + tprio_t prio, tfunc_t pf, void *arg) { void *wsp; - Thread *tp; + thread_t *tp; wsp = chHeapAlloc(heapp, size); if (wsp == NULL) @@ -131,9 +131,9 @@ Thread *chThdCreateFromHeap(MemoryHeap *heapp, size_t size, #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(Thread), + (uint8_t *)wsp + sizeof(thread_t), CH_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(Thread), + _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + size, CH_STACK_FILL_VALUE); #endif @@ -163,16 +163,16 @@ Thread *chThdCreateFromHeap(MemoryHeap *heapp, size_t size, * @param[in] pf the thread function * @param[in] arg an argument passed to the thread function. It can be * @p NULL. - * @return The pointer to the @p Thread structure allocated for + * @return The pointer to the @p thread_t structure allocated for * the thread into the working space area. * @retval NULL if the memory pool is empty. * * @api */ -Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio, - tfunc_t pf, void *arg) { +thread_t *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio, + tfunc_t pf, void *arg) { void *wsp; - Thread *tp; + thread_t *tp; chDbgCheck(mp != NULL, "chThdCreateFromMemoryPool"); @@ -182,9 +182,9 @@ Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio, #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(Thread), + (uint8_t *)wsp + sizeof(thread_t), CH_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(Thread), + _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + mp->mp_object_size, CH_STACK_FILL_VALUE); #endif diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index 1a2285779..0ff5bef73 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -28,8 +28,8 @@ * @addtogroup events * @details Event Flags, Event Sources and Event Listeners. *

Operation mode

- * Each thread has a mask of pending event flags inside its @p Thread - * structure. + * Each thread has a mask of pending event flags inside its + * @p thread_t structure. * Operations defined for event flags: * - Wait, the invoking thread goes to sleep until a certain * AND/OR combination of event flags becomes pending. @@ -54,7 +54,7 @@ * @pre In order to use the Events APIs the @p CH_USE_EVENTS option must be * enabled in @p chconf.h. * @post Enabling events requires 1-4 (depending on the architecture) - * extra bytes in the @p Thread structure. + * extra bytes in the @p thread_t structure. * @{ */ @@ -212,14 +212,14 @@ flagsmask_t chEvtGetAndClearFlags(EventListener *elp) { } /** - * @brief Adds a set of event flags directly to specified @p Thread. + * @brief Adds a set of event flags directly to the specified @p thread_t. * * @param[in] tp the thread to be signaled * @param[in] mask the event flags set to be ORed * * @api */ -void chEvtSignal(Thread *tp, eventmask_t mask) { +void chEvtSignal(thread_t *tp, eventmask_t mask) { chDbgCheck(tp != NULL, "chEvtSignal"); @@ -230,7 +230,7 @@ void chEvtSignal(Thread *tp, eventmask_t mask) { } /** - * @brief Adds a set of event flags directly to specified @p Thread. + * @brief Adds a set of event flags directly to the specified @p thread_t. * @post This function does not reschedule so a call to a rescheduling * function must be performed before unlocking the kernel. Note that * interrupt handlers always reschedule on exit so an explicit @@ -241,7 +241,7 @@ void chEvtSignal(Thread *tp, eventmask_t mask) { * * @iclass */ -void chEvtSignalI(Thread *tp, eventmask_t mask) { +void chEvtSignalI(thread_t *tp, eventmask_t mask) { chDbgCheckClassI(); chDbgCheck(tp != NULL, "chEvtSignalI"); @@ -341,7 +341,7 @@ void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask) { * @api */ eventmask_t chEvtWaitOne(eventmask_t mask) { - Thread *ctp = currp; + thread_t *ctp = currp; eventmask_t m; chSysLock(); @@ -370,7 +370,7 @@ eventmask_t chEvtWaitOne(eventmask_t mask) { * @api */ eventmask_t chEvtWaitAny(eventmask_t mask) { - Thread *ctp = currp; + thread_t *ctp = currp; eventmask_t m; chSysLock(); @@ -398,7 +398,7 @@ eventmask_t chEvtWaitAny(eventmask_t mask) { * @api */ eventmask_t chEvtWaitAll(eventmask_t mask) { - Thread *ctp = currp; + thread_t *ctp = currp; chSysLock(); @@ -437,7 +437,7 @@ eventmask_t chEvtWaitAll(eventmask_t mask) { * @api */ eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time) { - Thread *ctp = currp; + thread_t *ctp = currp; eventmask_t m; chSysLock(); @@ -480,7 +480,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time) { * @api */ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time) { - Thread *ctp = currp; + thread_t *ctp = currp; eventmask_t m; chSysLock(); @@ -521,7 +521,7 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time) { * @api */ eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time) { - Thread *ctp = currp; + thread_t *ctp = currp; chSysLock(); diff --git a/os/kernel/src/chlists.c b/os/kernel/src/chlists.c index 9e9b276e6..241067ab4 100644 --- a/os/kernel/src/chlists.c +++ b/os/kernel/src/chlists.c @@ -65,15 +65,15 @@ * * @notapi */ -void queue_prio_insert(Thread *tp, threads_queue_t *tqp) { +void queue_prio_insert(thread_t *tp, threads_queue_t *tqp) { /* cp iterates over the queue.*/ - Thread *cp = (Thread *)tqp; + thread_t *cp = (thread_t *)tqp; do { /* Iterate to next thread in queue.*/ cp = cp->p_next; /* Not end of queue? and cp has equal or higher priority than tp?.*/ - } while ((cp != (Thread *)tqp) && (cp->p_prio >= tp->p_prio)); + } while ((cp != (thread_t *)tqp) && (cp->p_prio >= tp->p_prio)); /* Insertion on p_prev.*/ tp->p_next = cp; tp->p_prev = cp->p_prev; @@ -81,22 +81,22 @@ void queue_prio_insert(Thread *tp, threads_queue_t *tqp) { } /** - * @brief Inserts a Thread into a queue. + * @brief Inserts a thread into a queue. * * @param[in] tp the pointer to the thread to be inserted in the list * @param[in] tqp the pointer to the threads list header * * @notapi */ -void queue_insert(Thread *tp, threads_queue_t *tqp) { +void queue_insert(thread_t *tp, threads_queue_t *tqp) { - tp->p_next = (Thread *)tqp; + tp->p_next = (thread_t *)tqp; tp->p_prev = tqp->p_prev; tp->p_prev->p_next = tqp->p_prev = tp; } /** - * @brief Removes the first-out Thread from a queue and returns it. + * @brief Removes the first-out thread from a queue and returns it. * @note If the queue is priority ordered then this function returns the * thread with the highest priority. * @@ -105,15 +105,15 @@ void queue_insert(Thread *tp, threads_queue_t *tqp) { * * @notapi */ -Thread *queue_fifo_remove(threads_queue_t *tqp) { - Thread *tp = tqp->p_next; +thread_t *queue_fifo_remove(threads_queue_t *tqp) { + thread_t *tp = tqp->p_next; - (tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp; + (tqp->p_next = tp->p_next)->p_prev = (thread_t *)tqp; return tp; } /** - * @brief Removes the last-out Thread from a queue and returns it. + * @brief Removes the last-out thread from a queue and returns it. * @note If the queue is priority ordered then this function returns the * thread with the lowest priority. * @@ -122,15 +122,15 @@ Thread *queue_fifo_remove(threads_queue_t *tqp) { * * @notapi */ -Thread *queue_lifo_remove(threads_queue_t *tqp) { - Thread *tp = tqp->p_prev; +thread_t *queue_lifo_remove(threads_queue_t *tqp) { + thread_t *tp = tqp->p_prev; - (tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp; + (tqp->p_prev = tp->p_prev)->p_next = (thread_t *)tqp; return tp; } /** - * @brief Removes a Thread from a queue and returns it. + * @brief Removes a thread from a queue and returns it. * @details The thread is removed from the queue regardless of its relative * position and regardless the used insertion method. * @@ -139,7 +139,7 @@ Thread *queue_lifo_remove(threads_queue_t *tqp) { * * @notapi */ -Thread *queue_dequeue(Thread *tp) { +thread_t *queue_dequeue(thread_t *tp) { tp->p_prev->p_next = tp->p_next; tp->p_next->p_prev = tp->p_prev; @@ -147,21 +147,21 @@ Thread *queue_dequeue(Thread *tp) { } /** - * @brief Pushes a Thread on top of a stack list. + * @brief Pushes a thread_t on top of a stack list. * * @param[in] tp the pointer to the thread to be inserted in the list * @param[in] tlp the pointer to the threads list header * * @notapi */ -void list_insert(Thread *tp, threads_list_t *tlp) { +void list_insert(thread_t *tp, threads_list_t *tlp) { tp->p_next = tlp->p_next; tlp->p_next = tp; } /** - * @brief Pops a Thread from the top of a stack list and returns it. + * @brief Pops a thread from the top of a stack list and returns it. * @pre The list must be non-empty before calling this function. * * @param[in] tlp the pointer to the threads list header @@ -169,9 +169,9 @@ void list_insert(Thread *tp, threads_list_t *tlp) { * * @notapi */ -Thread *list_remove(threads_list_t *tlp) { +thread_t *list_remove(threads_list_t *tlp) { - Thread *tp = tlp->p_next; + thread_t *tp = tlp->p_next; tlp->p_next = tp->p_next; return tp; } diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index d27713ef0..50e489915 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -40,7 +40,7 @@ * @pre In order to use the message APIs the @p CH_USE_MESSAGES option * must be enabled in @p chconf.h. * @post Enabling messages requires 6-12 (depending on the architecture) - * extra bytes in the @p Thread structure. + * extra bytes in the @p thread_t structure. * @{ */ @@ -65,8 +65,8 @@ * * @api */ -msg_t chMsgSend(Thread *tp, msg_t msg) { - Thread *ctp = currp; +msg_t chMsgSend(thread_t *tp, msg_t msg) { + thread_t *ctp = currp; chDbgCheck(tp != NULL, "chMsgSend"); @@ -96,8 +96,8 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { * * @api */ -Thread *chMsgWait(void) { - Thread *tp; +thread_t *chMsgWait(void) { + thread_t *tp; chSysLock(); if (!chMsgIsPendingI(currp)) @@ -118,7 +118,7 @@ Thread *chMsgWait(void) { * * @api */ -void chMsgRelease(Thread *tp, msg_t msg) { +void chMsgRelease(thread_t *tp, msg_t msg) { chSysLock(); chDbgAssert(tp->p_state == THD_STATE_SNDMSG, diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index 38ecbed74..f70dd9b20 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -61,7 +61,7 @@ * @pre In order to use the mutex APIs the @p CH_USE_MUTEXES option * must be enabled in @p chconf.h. * @post Enabling mutexes requires 5-12 (depending on the architecture) - * extra bytes in the @p Thread structure. + * extra bytes in the @p thread_t structure. * @{ */ @@ -112,7 +112,7 @@ void chMtxLock(Mutex *mp) { * @sclass */ void chMtxLockS(Mutex *mp) { - Thread *ctp = currp; + thread_t *ctp = currp; chDbgCheckClassS(); chDbgCheck(mp != NULL, "chMtxLockS"); @@ -122,7 +122,7 @@ void chMtxLockS(Mutex *mp) { /* Priority inheritance protocol; explores the thread-mutex dependencies boosting the priority of all the affected threads to equal the priority of the running thread requesting the mutex.*/ - Thread *tp = mp->m_owner; + thread_t *tp = mp->m_owner; /* Does the running thread have higher priority than the mutex owning thread? */ while (tp->p_prio < ctp->p_prio) { @@ -250,7 +250,7 @@ bool_t chMtxTryLockS(Mutex *mp) { * @api */ Mutex *chMtxUnlock(void) { - Thread *ctp = currp; + thread_t *ctp = currp; Mutex *ump, *mp; chSysLock(); @@ -260,13 +260,13 @@ Mutex *chMtxUnlock(void) { chDbgAssert(ctp->p_mtxlist->m_owner == ctp, "chMtxUnlock(), #2", "ownership failure"); - /* Removes the top Mutex from the Thread's owned mutexes list and marks it + /* Removes the top Mutex from the thread's owned mutexes list and marks it as not owned.*/ ump = ctp->p_mtxlist; ctp->p_mtxlist = ump->m_next; /* If a thread is waiting on the mutex then the fun part begins.*/ if (chMtxQueueNotEmptyS(ump)) { - Thread *tp; + thread_t *tp; /* Recalculates the optimal thread priority by scanning the owned mutexes list.*/ @@ -310,7 +310,7 @@ Mutex *chMtxUnlock(void) { * @sclass */ Mutex *chMtxUnlockS(void) { - Thread *ctp = currp; + thread_t *ctp = currp; Mutex *ump, *mp; chDbgCheckClassS(); @@ -327,7 +327,7 @@ Mutex *chMtxUnlockS(void) { ctp->p_mtxlist = ump->m_next; /* If a thread is waiting on the mutex then the fun part begins.*/ if (chMtxQueueNotEmptyS(ump)) { - Thread *tp; + thread_t *tp; /* Recalculates the optimal thread priority by scanning the owned mutexes list.*/ @@ -367,7 +367,7 @@ Mutex *chMtxUnlockS(void) { * @api */ void chMtxUnlockAll(void) { - Thread *ctp = currp; + thread_t *ctp = currp; chSysLock(); if (ctp->p_mtxlist != NULL) { @@ -375,7 +375,7 @@ void chMtxUnlockAll(void) { Mutex *ump = ctp->p_mtxlist; ctp->p_mtxlist = ump->m_next; if (chMtxQueueNotEmptyS(ump)) { - Thread *tp = queue_fifo_remove(&ump->m_queue); + thread_t *tp = queue_fifo_remove(&ump->m_queue); ump->m_owner = tp; ump->m_next = tp->p_mtxlist; tp->p_mtxlist = ump; diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c index 645172833..d567393c1 100644 --- a/os/kernel/src/chregistry.c +++ b/os/kernel/src/chregistry.c @@ -65,31 +65,31 @@ ROMCONST chdebug_t ch_debug = { (CH_KERNEL_PATCH) << 0), (uint8_t)sizeof (void *), (uint8_t)sizeof (systime_t), - (uint8_t)sizeof (Thread), - (uint8_t)_offsetof(Thread, p_prio), - (uint8_t)_offsetof(Thread, p_ctx), - (uint8_t)_offsetof(Thread, p_newer), - (uint8_t)_offsetof(Thread, p_older), - (uint8_t)_offsetof(Thread, p_name), + (uint8_t)sizeof (thread_t), + (uint8_t)_offsetof(thread_t, p_prio), + (uint8_t)_offsetof(thread_t, p_ctx), + (uint8_t)_offsetof(thread_t, p_newer), + (uint8_t)_offsetof(thread_t, p_older), + (uint8_t)_offsetof(thread_t, p_name), #if CH_DBG_ENABLE_STACK_CHECK - (uint8_t)_offsetof(Thread, p_stklimit), + (uint8_t)_offsetof(thread_t, p_stklimit), #else (uint8_t)0, #endif - (uint8_t)_offsetof(Thread, p_state), - (uint8_t)_offsetof(Thread, p_flags), + (uint8_t)_offsetof(thread_t, p_state), + (uint8_t)_offsetof(thread_t, p_flags), #if CH_USE_DYNAMIC - (uint8_t)_offsetof(Thread, p_refs), + (uint8_t)_offsetof(thread_t, p_refs), #else (uint8_t)0, #endif #if CH_TIME_QUANTUM > 0 - (uint8_t)_offsetof(Thread, p_preempt), + (uint8_t)_offsetof(thread_t, p_preempt), #else (uint8_t)0, #endif #if CH_DBG_THREADS_PROFILING - (uint8_t)_offsetof(Thread, p_time) + (uint8_t)_offsetof(thread_t, p_time) #else (uint8_t)0 #endif @@ -107,8 +107,8 @@ ROMCONST chdebug_t ch_debug = { * * @api */ -Thread *chRegFirstThread(void) { - Thread *tp; +thread_t *chRegFirstThread(void) { + thread_t *tp; chSysLock(); tp = rlist.r_newer; @@ -130,12 +130,12 @@ Thread *chRegFirstThread(void) { * * @api */ -Thread *chRegNextThread(Thread *tp) { - Thread *ntp; +thread_t *chRegNextThread(thread_t *tp) { + thread_t *ntp; chSysLock(); ntp = tp->p_newer; - if (ntp == (Thread *)&rlist) + if (ntp == (thread_t *)&rlist) ntp = NULL; #if CH_USE_DYNAMIC else { diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 1333fc400..b957a8152 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -68,7 +68,7 @@ void _scheduler_init(void) { queue_init(&rlist.r_queue); rlist.r_prio = NOPRIO; #if CH_USE_REGISTRY - rlist.r_newer = rlist.r_older = (Thread *)&rlist; + rlist.r_newer = rlist.r_older = (thread_t *)&rlist; #endif } @@ -88,8 +88,8 @@ void _scheduler_init(void) { * * @iclass */ -Thread *chSchReadyI(Thread *tp) { - Thread *cp; +thread_t *chSchReadyI(thread_t *tp) { + thread_t *cp; chDbgCheckClassI(); @@ -100,7 +100,7 @@ Thread *chSchReadyI(Thread *tp) { "invalid state"); tp->p_state = THD_STATE_READY; - cp = (Thread *)&rlist.r_queue; + cp = (thread_t *)&rlist.r_queue; do { cp = cp->p_next; } while (cp->p_prio >= tp->p_prio); @@ -121,7 +121,7 @@ Thread *chSchReadyI(Thread *tp) { * @sclass */ void chSchGoSleepS(tstate_t newstate) { - Thread *otp; + thread_t *otp; chDbgCheckClassS(); @@ -140,7 +140,7 @@ void chSchGoSleepS(tstate_t newstate) { * Timeout wakeup callback. */ static void wakeup(void *p) { - Thread *tp = (Thread *)p; + thread_t *tp = (thread_t *)p; chSysLockFromIsr(); switch (tp->p_state) { @@ -221,12 +221,12 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { * @note The function assumes that the current thread has the highest * priority. * - * @param[in] ntp the Thread to be made ready + * @param[in] ntp the thread to be made ready * @param[in] msg message to the awakened thread * * @sclass */ -void chSchWakeupS(Thread *ntp, msg_t msg) { +void chSchWakeupS(thread_t *ntp, msg_t msg) { chDbgCheckClassS(); @@ -238,7 +238,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { if (ntp->p_prio <= currp->p_prio) chSchReadyI(ntp); else { - Thread *otp = chSchReadyI(currp); + thread_t *otp = chSchReadyI(currp); setcurrp(ntp); ntp->p_state = THD_STATE_CURRENT; chSysSwitch(ntp, otp); @@ -300,7 +300,7 @@ bool chSchIsPreemptionRequired(void) { * @special */ void chSchDoRescheduleBehind(void) { - Thread *otp; + thread_t *otp; otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ @@ -323,7 +323,7 @@ void chSchDoRescheduleBehind(void) { * @special */ void chSchDoRescheduleAhead(void) { - Thread *otp, *cp; + thread_t *otp, *cp; otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ @@ -331,7 +331,7 @@ void chSchDoRescheduleAhead(void) { currp->p_state = THD_STATE_CURRENT; otp->p_state = THD_STATE_READY; - cp = (Thread *)&rlist.r_queue; + cp = (thread_t *)&rlist.r_queue; do { cp = cp->p_next; } while (cp->p_prio > otp->p_prio); diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index c91264b9d..04e208e58 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -305,7 +305,7 @@ void chSemSignalI(Semaphore *sp) { if (++sp->s_cnt <= 0) { /* Note, it is done this way in order to allow a tail call on chSchReadyI().*/ - Thread *tp = queue_fifo_remove(&sp->s_queue); + thread_t *tp = queue_fifo_remove(&sp->s_queue); tp->p_u.rdymsg = RDY_OK; chSchReadyI(tp); } @@ -373,7 +373,7 @@ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) { if (++sps->s_cnt <= 0) chSchReadyI(queue_fifo_remove(&sps->s_queue))->p_u.rdymsg = RDY_OK; if (--spw->s_cnt < 0) { - Thread *ctp = currp; + thread_t *ctp = currp; sem_insert(ctp, &spw->s_queue); ctp->p_u.wtobjp = spw; chSchGoSleepS(THD_STATE_WTSEM); diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index a6f1d15ba..f960d9b79 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -75,7 +75,7 @@ void _idle_thread(void *p) { * @special */ void chSysInit(void) { - static Thread mainthread; + static thread_t mainthread; #if CH_DBG_ENABLE_STACK_CHECK extern stkalign_t __main_thread_stack_base__; #endif @@ -97,7 +97,7 @@ void chSysInit(void) { setcurrp(_thread_init(&mainthread, NORMALPRIO)); currp->p_state = THD_STATE_CURRENT; #if CH_DBG_ENABLE_STACK_CHECK - /* This is a special case because the main thread Thread structure is not + /* This is a special case because the main thread thread_t structure is not adjacent to its stack area.*/ currp->p_stklimit = &__main_thread_stack_base__; #endif diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 9f176c6a0..bc161ba52 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -90,7 +90,7 @@ * * @notapi */ -Thread *_thread_init(Thread *tp, tprio_t prio) { +thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_prio = prio; tp->p_state = THD_STATE_SUSPENDED; @@ -166,15 +166,16 @@ void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { * @param[in] pf the thread function * @param[in] arg an argument passed to the thread function. It can be * @p NULL. - * @return The pointer to the @p Thread structure allocated for + * @return The pointer to the @p thread_t structure allocated for * the thread into the working space area. * * @iclass */ -Thread *chThdCreateI(void *wsp, size_t size, +thread_t *chThdCreateI(void *wsp, size_t size, tprio_t prio, tfunc_t pf, void *arg) { - /* Thread structure is laid out in the lower part of the thread workspace.*/ - Thread *tp = wsp; + /* The thread structure is laid out in the lower part of the thread + workspace.*/ + thread_t *tp = wsp; chDbgCheckClassI(); @@ -196,20 +197,20 @@ Thread *chThdCreateI(void *wsp, size_t size, * @param[in] pf the thread function * @param[in] arg an argument passed to the thread function. It can be * @p NULL. - * @return The pointer to the @p Thread structure allocated for + * @return The pointer to the @p thread_t structure allocated for * the thread into the working space area. * * @api */ -Thread *chThdCreateStatic(void *wsp, size_t size, - tprio_t prio, tfunc_t pf, void *arg) { - Thread *tp; +thread_t *chThdCreateStatic(void *wsp, size_t size, + tprio_t prio, tfunc_t pf, void *arg) { + thread_t *tp; #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(Thread), + (uint8_t *)wsp + sizeof(thread_t), CH_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(Thread), + _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + size, CH_STACK_FILL_VALUE); #endif @@ -264,7 +265,7 @@ tprio_t chThdSetPriority(tprio_t newprio) { * * @api */ -Thread *chThdResume(Thread *tp) { +thread_t *chThdResume(thread_t *tp) { chSysLock(); chDbgAssert(tp->p_state == THD_STATE_SUSPENDED, @@ -287,7 +288,7 @@ Thread *chThdResume(Thread *tp) { * * @api */ -void chThdTerminate(Thread *tp) { +void chThdTerminate(thread_t *tp) { chSysLock(); tp->p_flags |= THD_TERMINATE; @@ -381,7 +382,7 @@ void chThdExit(msg_t msg) { * @sclass */ void chThdExitS(msg_t msg) { - Thread *tp = currp; + thread_t *tp = currp; tp->p_u.exitcode = msg; #if defined(THREAD_EXT_EXIT_HOOK) @@ -423,7 +424,7 @@ void chThdExitS(msg_t msg) { * @pre The configuration option @p CH_USE_WAITEXIT must be enabled in * order to use this function. * @post Enabling @p chThdWait() requires 2-4 (depending on the - * architecture) extra bytes in the @p Thread structure. + * architecture) extra bytes in the @p thread_t structure. * @post After invoking @p chThdWait() the thread pointer becomes invalid * and must not be used as parameter for further system calls. * @note If @p CH_USE_DYNAMIC is not specified this function just waits for @@ -434,7 +435,7 @@ void chThdExitS(msg_t msg) { * * @api */ -msg_t chThdWait(Thread *tp) { +msg_t chThdWait(thread_t *tp) { msg_t msg; chDbgCheck(tp != NULL, "chThdWait"); -- cgit v1.2.3 From d58064a533743df77e52f9d76385a9e0ea1d0227 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 13:17:42 +0000 Subject: Still work in progress. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5996 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 98 +++++++++++++++++++++++++++++------------------ os/kernel/src/chdynamic.c | 24 ++++++++++++ os/kernel/src/chevents.c | 25 ++++++++++++ os/kernel/src/chschd.c | 4 +- os/kernel/src/chsem.c | 46 +++++++++++----------- os/kernel/src/chvt.c | 12 +++--- 6 files changed, 141 insertions(+), 68 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index 99a641122..5903e062f 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -25,14 +25,14 @@ * @file chcond.c * @brief Condition Variables code. * - * @addtogroup condvars Condition Variables + * @addtogroup condition variables Condition Variables * @details This module implements the Condition Variables mechanism. Condition - * variables are an extensions to the Mutex subsystem and cannot + * variables are an extensions to the mutex subsystem and cannot * work alone. *

Operation mode

* The condition variable is a synchronization object meant to be - * used inside a zone protected by a @p Mutex. Mutexes and CondVars - * together can implement a Monitor construct. + * used inside a zone protected by a mutex. Mutexes and condition + * variables together can implement a Monitor construct. * @pre In order to use the condition variable APIs the @p CH_USE_CONDVARS * option must be enabled in @p chconf.h. * @{ @@ -40,16 +40,40 @@ #include "ch.h" -#if (CH_USE_CONDVARS && CH_USE_MUTEXES) || defined(__DOXYGEN__) +#if CH_USE_CONDVARS || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ /** - * @brief Initializes s @p CondVar structure. + * @brief Initializes s @p condition_variable_t structure. * - * @param[out] cp pointer to a @p CondVar structure + * @param[out] cp pointer to a @p condition_variable_t structure * * @init */ -void chCondInit(CondVar *cp) { +void chCondInit(condition_variable_t *cp) { chDbgCheck(cp != NULL, "chCondInit"); @@ -59,11 +83,11 @@ void chCondInit(CondVar *cp) { /** * @brief Signals one thread that is waiting on the condition variable. * - * @param[in] cp pointer to the @p CondVar structure + * @param[in] cp pointer to the @p condition_variable_t structure * * @api */ -void chCondSignal(CondVar *cp) { +void chCondSignal(condition_variable_t *cp) { chDbgCheck(cp != NULL, "chCondSignal"); @@ -80,11 +104,11 @@ void chCondSignal(CondVar *cp) { * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * - * @param[in] cp pointer to the @p CondVar structure + * @param[in] cp pointer to the @p condition_variable_t structure * * @iclass */ -void chCondSignalI(CondVar *cp) { +void chCondSignalI(condition_variable_t *cp) { chDbgCheckClassI(); chDbgCheck(cp != NULL, "chCondSignalI"); @@ -96,11 +120,11 @@ void chCondSignalI(CondVar *cp) { /** * @brief Signals all threads that are waiting on the condition variable. * - * @param[in] cp pointer to the @p CondVar structure + * @param[in] cp pointer to the @p condition_variable_t structure * * @api */ -void chCondBroadcast(CondVar *cp) { +void chCondBroadcast(condition_variable_t *cp) { chSysLock(); chCondBroadcastI(cp); @@ -115,11 +139,11 @@ void chCondBroadcast(CondVar *cp) { * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * - * @param[in] cp pointer to the @p CondVar structure + * @param[in] cp pointer to the @p condition_variable_t structure * * @iclass */ -void chCondBroadcastI(CondVar *cp) { +void chCondBroadcastI(condition_variable_t *cp) { chDbgCheckClassI(); chDbgCheck(cp != NULL, "chCondBroadcastI"); @@ -138,17 +162,17 @@ void chCondBroadcastI(CondVar *cp) { * is performed atomically. * @pre The invoking thread must have at least one owned mutex. * - * @param[in] cp pointer to the @p CondVar structure + * @param[in] cp pointer to the @p condition_variable_t structure * @return A message specifying how the invoking thread has been * released from the condition variable. - * @retval RDY_OK if the condvar has been signaled using + * @retval RDY_OK if the condition variable has been signaled using * @p chCondSignal(). - * @retval RDY_RESET if the condvar has been signaled using + * @retval RDY_RESET if the condition variable has been signaled using * @p chCondBroadcast(). * * @api */ -msg_t chCondWait(CondVar *cp) { +msg_t chCondWait(condition_variable_t *cp) { msg_t msg; chSysLock(); @@ -164,17 +188,17 @@ msg_t chCondWait(CondVar *cp) { * is performed atomically. * @pre The invoking thread must have at least one owned mutex. * - * @param[in] cp pointer to the @p CondVar structure + * @param[in] cp pointer to the @p condition_variable_t structure * @return A message specifying how the invoking thread has been * released from the condition variable. - * @retval RDY_OK if the condvar has been signaled using + * @retval RDY_OK if the condition variable has been signaled using * @p chCondSignal(). - * @retval RDY_RESET if the condvar has been signaled using + * @retval RDY_RESET if the condition variable has been signaled using * @p chCondBroadcast(). * * @sclass */ -msg_t chCondWaitS(CondVar *cp) { +msg_t chCondWaitS(condition_variable_t *cp) { thread_t *ctp = currp; Mutex *mp; msg_t msg; @@ -206,7 +230,7 @@ msg_t chCondWaitS(CondVar *cp) { * @post Exiting the function because a timeout does not re-acquire the * mutex, the mutex ownership is lost. * - * @param[in] cp pointer to the @p CondVar structure + * @param[in] cp pointer to the @p condition_variable_t structure * @param[in] time the number of ticks before the operation timeouts, the * special values are handled as follow: * - @a TIME_INFINITE no timeout. @@ -214,16 +238,16 @@ msg_t chCondWaitS(CondVar *cp) { * . * @return A message specifying how the invoking thread has been * released from the condition variable. - * @retval RDY_OK if the condvar has been signaled using + * @retval RDY_OK if the condition variable has been signaled using * @p chCondSignal(). - * @retval RDY_RESET if the condvar has been signaled using + * @retval RDY_RESET if the condition variable has been signaled using * @p chCondBroadcast(). - * @retval RDY_TIMEOUT if the condvar has not been signaled within the - * specified timeout. + * @retval RDY_TIMEOUT if the condition variable has not been signaled within + * the specified timeout. * * @api */ -msg_t chCondWaitTimeout(CondVar *cp, systime_t time) { +msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) { msg_t msg; chSysLock(); @@ -243,7 +267,7 @@ msg_t chCondWaitTimeout(CondVar *cp, systime_t time) { * @post Exiting the function because a timeout does not re-acquire the * mutex, the mutex ownership is lost. * - * @param[in] cp pointer to the @p CondVar structure + * @param[in] cp pointer to the @p condition_variable_t structure * @param[in] time the number of ticks before the operation timeouts, the * special values are handled as follow: * - @a TIME_INFINITE no timeout. @@ -251,16 +275,16 @@ msg_t chCondWaitTimeout(CondVar *cp, systime_t time) { * . * @return A message specifying how the invoking thread has been * released from the condition variable. - * @retval RDY_OK if the condvar has been signaled using + * @retval RDY_OK if the condition variable has been signaled using * @p chCondSignal(). - * @retval RDY_RESET if the condvar has been signaled using + * @retval RDY_RESET if the condition variable has been signaled using * @p chCondBroadcast(). - * @retval RDY_TIMEOUT if the condvar has not been signaled within the - * specified timeout. + * @retval RDY_TIMEOUT if the condition variable has not been signaled within + * the specified timeout. * * @sclass */ -msg_t chCondWaitTimeoutS(CondVar *cp, systime_t time) { +msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { Mutex *mp; msg_t msg; @@ -280,6 +304,6 @@ msg_t chCondWaitTimeoutS(CondVar *cp, systime_t time) { } #endif /* CH_USE_CONDVARS_TIMEOUT */ -#endif /* CH_USE_CONDVARS && CH_USE_MUTEXES */ +#endif /* CH_USE_CONDVARS */ /** @} */ diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c index 3d856a526..76d4ba561 100644 --- a/os/kernel/src/chdynamic.c +++ b/os/kernel/src/chdynamic.c @@ -31,6 +31,30 @@ #if CH_USE_DYNAMIC || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Adds a reference to a thread object. * @pre The configuration option @p CH_USE_DYNAMIC must be enabled in order diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index 0ff5bef73..5685f285f 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -61,6 +61,31 @@ #include "ch.h" #if CH_USE_EVENTS || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Registers an Event Listener on an Event Source. * @details Once a thread has registered as listener on an event source it diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index b957a8152..b99afbbb9 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -153,7 +153,7 @@ static void wakeup(void *p) { (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) #if CH_USE_SEMAPHORES case THD_STATE_WTSEM: - chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); + chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp); /* Falls into, intentional. */ #endif #if CH_USE_QUEUES @@ -197,7 +197,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { chDbgCheckClassS(); if (TIME_INFINITE != time) { - VirtualTimer vt; + virtual_timer_t vt; chVTDoSetI(&vt, time, wakeup, currp); chSchGoSleepS(newstate); diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index 04e208e58..73d156c02 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -70,13 +70,13 @@ /** * @brief Initializes a semaphore with the specified counter value. * - * @param[out] sp pointer to a @p Semaphore structure + * @param[out] sp pointer to a @p semaphore_t structure * @param[in] n initial value of the semaphore counter. Must be * non-negative. * * @init */ -void chSemInit(Semaphore *sp, cnt_t n) { +void chSemInit(semaphore_t *sp, cnt_t n) { chDbgCheck((sp != NULL) && (n >= 0), "chSemInit"); @@ -93,13 +93,13 @@ void chSemInit(Semaphore *sp, cnt_t n) { * rather than a signal because the @p chSemWait() will return * @p RDY_RESET instead of @p RDY_OK. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * @param[in] n the new value of the semaphore counter. The value must * be non-negative. * * @api */ -void chSemReset(Semaphore *sp, cnt_t n) { +void chSemReset(semaphore_t *sp, cnt_t n) { chSysLock(); chSemResetI(sp, n); @@ -120,13 +120,13 @@ void chSemReset(Semaphore *sp, cnt_t n) { * rather than a signal because the @p chSemWait() will return * @p RDY_RESET instead of @p RDY_OK. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * @param[in] n the new value of the semaphore counter. The value must * be non-negative. * * @iclass */ -void chSemResetI(Semaphore *sp, cnt_t n) { +void chSemResetI(semaphore_t *sp, cnt_t n) { cnt_t cnt; chDbgCheckClassI(); @@ -145,7 +145,7 @@ void chSemResetI(Semaphore *sp, cnt_t n) { /** * @brief Performs a wait operation on a semaphore. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * @return A message specifying how the invoking thread has been * released from the semaphore. * @retval RDY_OK if the thread has not stopped on the semaphore or the @@ -154,7 +154,7 @@ void chSemResetI(Semaphore *sp, cnt_t n) { * * @api */ -msg_t chSemWait(Semaphore *sp) { +msg_t chSemWait(semaphore_t *sp) { msg_t msg; chSysLock(); @@ -166,7 +166,7 @@ msg_t chSemWait(Semaphore *sp) { /** * @brief Performs a wait operation on a semaphore. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * @return A message specifying how the invoking thread has been * released from the semaphore. * @retval RDY_OK if the thread has not stopped on the semaphore or the @@ -175,7 +175,7 @@ msg_t chSemWait(Semaphore *sp) { * * @sclass */ -msg_t chSemWaitS(Semaphore *sp) { +msg_t chSemWaitS(semaphore_t *sp) { chDbgCheckClassS(); chDbgCheck(sp != NULL, "chSemWaitS"); @@ -196,7 +196,7 @@ msg_t chSemWaitS(Semaphore *sp) { /** * @brief Performs a wait operation on a semaphore with timeout specification. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. @@ -212,7 +212,7 @@ msg_t chSemWaitS(Semaphore *sp) { * * @api */ -msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) { +msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time) { msg_t msg; chSysLock(); @@ -224,7 +224,7 @@ msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) { /** * @brief Performs a wait operation on a semaphore with timeout specification. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. @@ -240,7 +240,7 @@ msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) { * * @sclass */ -msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) { +msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { chDbgCheckClassS(); chDbgCheck(sp != NULL, "chSemWaitTimeoutS"); @@ -264,11 +264,11 @@ msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) { /** * @brief Performs a signal operation on a semaphore. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * * @api */ -void chSemSignal(Semaphore *sp) { +void chSemSignal(semaphore_t *sp) { chDbgCheck(sp != NULL, "chSemSignal"); chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || @@ -289,11 +289,11 @@ void chSemSignal(Semaphore *sp) { * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * * @iclass */ -void chSemSignalI(Semaphore *sp) { +void chSemSignalI(semaphore_t *sp) { chDbgCheckClassI(); chDbgCheck(sp != NULL, "chSemSignalI"); @@ -318,13 +318,13 @@ void chSemSignalI(Semaphore *sp) { * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * - * @param[in] sp pointer to a @p Semaphore structure + * @param[in] sp pointer to a @p semaphore_t structure * @param[in] n value to be added to the semaphore counter. The value * must be positive. * * @iclass */ -void chSemAddCounterI(Semaphore *sp, cnt_t n) { +void chSemAddCounterI(semaphore_t *sp, cnt_t n) { chDbgCheckClassI(); chDbgCheck((sp != NULL) && (n > 0), "chSemAddCounterI"); @@ -346,8 +346,8 @@ void chSemAddCounterI(Semaphore *sp, cnt_t n) { * @pre The configuration option @p CH_USE_SEMSW must be enabled in order * to use this function. * - * @param[in] sps pointer to a @p Semaphore structure to be signaled - * @param[in] spw pointer to a @p Semaphore structure to wait on + * @param[in] sps pointer to a @p semaphore_t structure to be signaled + * @param[in] spw pointer to a @p semaphore_t structure to wait on * @return A message specifying how the invoking thread has been * released from the semaphore. * @retval RDY_OK if the thread has not stopped on the semaphore or the @@ -356,7 +356,7 @@ void chSemAddCounterI(Semaphore *sp, cnt_t n) { * * @api */ -msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) { +msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { msg_t msg; chDbgCheck((sps != NULL) && (spw != NULL), "chSemSignalWait"); diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index e93b2244c..3bccd1ac8 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -40,7 +40,7 @@ /** * @brief Virtual timers delta list header. */ -VTList vtlist; +virtual_timers_list_t vtlist; /*===========================================================================*/ /* Module local types. */ @@ -99,7 +99,7 @@ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) { * @pre The timer must not be already armed before calling this function. * @note The callback function is invoked from interrupt context. * - * @param[out] vtp the @p VirtualTimer structure pointer + * @param[out] vtp the @p virtual_timer_t structure pointer * @param[in] delay the number of ticks before the operation timeouts, the * special values are handled as follow: * - @a TIME_INFINITE is allowed but interpreted as a @@ -114,9 +114,9 @@ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) { * * @iclass */ -void chVTDoSetI(VirtualTimer *vtp, systime_t delay, +void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, vtfunc_t vtfunc, void *par) { - VirtualTimer *p; + virtual_timer_t *p; chDbgCheckClassI(); chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE), @@ -141,11 +141,11 @@ void chVTDoSetI(VirtualTimer *vtp, systime_t delay, * @brief Disables a Virtual Timer. * @pre The timer must be in armed state before calling this function. * - * @param[in] vtp the @p VirtualTimer structure pointer + * @param[in] vtp the @p virtual_timer_t structure pointer * * @iclass */ -void chVTDoResetI(VirtualTimer *vtp) { +void chVTDoResetI(virtual_timer_t *vtp) { chDbgCheckClassI(); chDbgCheck(vtp != NULL, "chVTDoResetI"); -- cgit v1.2.3 From 25ddb1c801f06a3be7171e20dcfd46d11a75f112 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 14:51:35 +0000 Subject: First cleanup pass finished, queues and streams not yet removed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5999 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 4 +- os/kernel/src/chdynamic.c | 4 +- os/kernel/src/chevents.c | 68 ++++++++++++++++---------------- os/kernel/src/chheap.c | 96 ++++++++++++++-------------------------------- os/kernel/src/chmboxes.c | 70 +++++++++++++++++++++------------ os/kernel/src/chmemcore.c | 22 +++++++++++ os/kernel/src/chmempools.c | 45 ++++++++++++++++------ os/kernel/src/chmsg.c | 20 ++++++++++ os/kernel/src/chmtx.c | 71 +++++++++++++++++++++++++--------- os/kernel/src/chregistry.c | 20 ++++++++++ os/kernel/src/chsem.c | 20 ++++++++++ os/kernel/src/chsys.c | 49 ++++++++++++++++++++++- 12 files changed, 327 insertions(+), 162 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index 5903e062f..6b718c7f9 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -200,7 +200,7 @@ msg_t chCondWait(condition_variable_t *cp) { */ msg_t chCondWaitS(condition_variable_t *cp) { thread_t *ctp = currp; - Mutex *mp; + mutex_t *mp; msg_t msg; chDbgCheckClassS(); @@ -285,7 +285,7 @@ msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) { * @sclass */ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { - Mutex *mp; + mutex_t *mp; msg_t msg; chDbgCheckClassS(); diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c index 76d4ba561..21c81fc24 100644 --- a/os/kernel/src/chdynamic.c +++ b/os/kernel/src/chdynamic.c @@ -144,7 +144,7 @@ void chThdRelease(thread_t *tp) { * * @api */ -thread_t *chThdCreateFromHeap(MemoryHeap *heapp, size_t size, +thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, tprio_t prio, tfunc_t pf, void *arg) { void *wsp; thread_t *tp; @@ -193,7 +193,7 @@ thread_t *chThdCreateFromHeap(MemoryHeap *heapp, size_t size, * * @api */ -thread_t *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio, +thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, tfunc_t pf, void *arg) { void *wsp; thread_t *tp; diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index 5685f285f..1206b61fe 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -93,14 +93,16 @@ * @note Multiple Event Listeners can specify the same bits to be ORed to * different threads. * - * @param[in] esp pointer to the @p EventSource structure - * @param[in] elp pointer to the @p EventListener structure + * @param[in] esp pointer to the @p event_source_t structure + * @param[in] elp pointer to the @p event_listener_t structure * @param[in] mask the mask of event flags to be ORed to the thread when * the event source is broadcasted * * @api */ -void chEvtRegisterMask(EventSource *esp, EventListener *elp, eventmask_t mask) { +void chEvtRegisterMask(event_source_t *esp, + event_listener_t *elp, + eventmask_t mask) { chDbgCheck((esp != NULL) && (elp != NULL), "chEvtRegisterMask"); @@ -121,19 +123,19 @@ void chEvtRegisterMask(EventSource *esp, EventListener *elp, eventmask_t mask) { * operations in inverse order of the register operations (elements * are found on top of the list). * - * @param[in] esp pointer to the @p EventSource structure - * @param[in] elp pointer to the @p EventListener structure + * @param[in] esp pointer to the @p event_source_t structure + * @param[in] elp pointer to the @p event_listener_t structure * * @api */ -void chEvtUnregister(EventSource *esp, EventListener *elp) { - EventListener *p; +void chEvtUnregister(event_source_t *esp, event_listener_t *elp) { + event_listener_t *p; chDbgCheck((esp != NULL) && (elp != NULL), "chEvtUnregister"); - p = (EventListener *)esp; + p = (event_listener_t *)esp; chSysLock(); - while (p->el_next != (EventListener *)esp) { + while (p->el_next != (event_listener_t *)esp) { if (p->el_next == elp) { p->el_next = elp->el_next; break; @@ -186,27 +188,27 @@ eventmask_t chEvtAddEvents(eventmask_t mask) { * @brief Signals all the Event Listeners registered on the specified Event * Source. * @details This function variants ORs the specified event flags to all the - * threads registered on the @p EventSource in addition to the event - * flags specified by the threads themselves in the - * @p EventListener objects. + * threads registered on the @p event_source_t in addition to the + * event flags specified by the threads themselves in the + * @p event_listener_t objects. * @post This function does not reschedule so a call to a rescheduling * function must be performed before unlocking the kernel. Note that * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * - * @param[in] esp pointer to the @p EventSource structure + * @param[in] esp pointer to the @p event_source_t structure * @param[in] flags the flags set to be added to the listener flags mask * * @iclass */ -void chEvtBroadcastFlagsI(EventSource *esp, flagsmask_t flags) { - EventListener *elp; +void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) { + event_listener_t *elp; chDbgCheckClassI(); chDbgCheck(esp != NULL, "chEvtBroadcastMaskI"); elp = esp->es_next; - while (elp != (EventListener *)esp) { + while (elp != (event_listener_t *)esp) { elp->el_flags |= flags; chEvtSignalI(elp->el_listener, elp->el_mask); elp = elp->el_next; @@ -214,18 +216,18 @@ void chEvtBroadcastFlagsI(EventSource *esp, flagsmask_t flags) { } /** - * @brief Returns the flags associated to an @p EventListener. - * @details The flags are returned and the @p EventListener flags mask is + * @brief Returns the flags associated to an @p event_listener_t. + * @details The flags are returned and the @p event_listener_t flags mask is * cleared. * - * @param[in] elp pointer to the @p EventListener structure + * @param[in] elp pointer to the @p event_listener_t structure * @return The flags added to the listener by the associated * event source. * * @iclass */ -flagsmask_t chEvtGetAndClearFlags(EventListener *elp) { - flagsmask_t flags; +eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) { + eventflags_t flags; chSysLock(); @@ -284,16 +286,16 @@ void chEvtSignalI(thread_t *tp, eventmask_t mask) { * @brief Signals all the Event Listeners registered on the specified Event * Source. * @details This function variants ORs the specified event flags to all the - * threads registered on the @p EventSource in addition to the event - * flags specified by the threads themselves in the - * @p EventListener objects. + * threads registered on the @p event_source_t in addition to the + * event flags specified by the threads themselves in the + * @p event_listener_t objects. * - * @param[in] esp pointer to the @p EventSource structure + * @param[in] esp pointer to the @p event_source_t structure * @param[in] flags the flags set to be added to the listener flags mask * * @api */ -void chEvtBroadcastFlags(EventSource *esp, flagsmask_t flags) { +void chEvtBroadcastFlags(event_source_t *esp, eventflags_t flags) { chSysLock(); chEvtBroadcastFlagsI(esp, flags); @@ -302,18 +304,18 @@ void chEvtBroadcastFlags(EventSource *esp, flagsmask_t flags) { } /** - * @brief Returns the flags associated to an @p EventListener. - * @details The flags are returned and the @p EventListener flags mask is + * @brief Returns the flags associated to an @p event_listener_t. + * @details The flags are returned and the @p event_listener_t flags mask is * cleared. * - * @param[in] elp pointer to the @p EventListener structure + * @param[in] elp pointer to the @p event_listener_t structure * @return The flags added to the listener by the associated * event source. * * @iclass */ -flagsmask_t chEvtGetAndClearFlagsI(EventListener *elp) { - flagsmask_t flags; +eventflags_t chEvtGetAndClearFlagsI(event_listener_t *elp) { + eventflags_t flags; flags = elp->el_flags; elp->el_flags = 0; @@ -444,8 +446,8 @@ eventmask_t chEvtWaitAll(eventmask_t mask) { * @details The function waits for one event among those specified in * @p mask to become pending then the event is cleared and returned. * @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.
+ * lowest event id. The function is meant to be invoked into a loop + * in order to serve all the pending events.
* This means that Event Listeners with a lower event identifier have * an higher priority. * diff --git a/os/kernel/src/chheap.c b/os/kernel/src/chheap.c index 23bcff6b4..4f20d3920 100644 --- a/os/kernel/src/chheap.c +++ b/os/kernel/src/chheap.c @@ -29,10 +29,6 @@ * are functionally equivalent to the usual @p malloc() and @p free() * library functions. The main difference is that the OS heap APIs * are guaranteed to be thread safe.
- * By enabling the @p CH_USE_MALLOC_HEAP option the heap manager - * will use the runtime-provided @p malloc() and @p free() as - * back end for the heap APIs instead of the system provided - * allocator. * @pre In order to use the heap APIs the @p CH_USE_HEAP option must * be enabled in @p chconf.h. * @{ @@ -42,7 +38,9 @@ #if CH_USE_HEAP || defined(__DOXYGEN__) -#if !CH_USE_MALLOC_HEAP || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ /* * Defaults on the best synchronization mechanism available. @@ -55,10 +53,30 @@ #define H_UNLOCK(h) chSemSignal(&(h)->h_sem) #endif +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + /** * @brief Default heap descriptor. */ -static MemoryHeap default_heap; +static memory_heap_t default_heap; + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ /** * @brief Initializes the default heap. @@ -80,8 +98,6 @@ void _heap_init(void) { * @brief Initializes a memory heap from a static memory area. * @pre Both the heap buffer base and the heap size must be aligned to * the @p stkalign_t type size. - * @pre In order to use this function the option @p CH_USE_MALLOC_HEAP - * must be disabled. * * @param[out] heapp pointer to the memory heap descriptor to be initialized * @param[in] buf heap buffer base @@ -89,7 +105,7 @@ void _heap_init(void) { * * @init */ -void chHeapInit(MemoryHeap *heapp, void *buf, size_t size) { +void chHeapInit(memory_heap_t *heapp, void *buf, size_t size) { union heap_header *hp; chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size), "chHeapInit"); @@ -122,7 +138,7 @@ void chHeapInit(MemoryHeap *heapp, void *buf, size_t size) { * * @api */ -void *chHeapAlloc(MemoryHeap *heapp, size_t size) { +void *chHeapAlloc(memory_heap_t *heapp, size_t size) { union heap_header *qp, *hp, *fp; if (heapp == NULL) @@ -186,7 +202,7 @@ void *chHeapAlloc(MemoryHeap *heapp, size_t size) { */ void chHeapFree(void *p) { union heap_header *qp, *hp; - MemoryHeap *heapp; + memory_heap_t *heapp; chDbgCheck(p != NULL, "chHeapFree"); @@ -229,8 +245,6 @@ void chHeapFree(void *p) { * @brief Reports the heap status. * @note This function is meant to be used in the test suite, it should * not be really useful for the application code. - * @note This function is not implemented when the @p CH_USE_MALLOC_HEAP - * configuration option is used (it always returns zero). * * @param[in] heapp pointer to a heap descriptor or @p NULL in order to * access the default heap. @@ -240,7 +254,7 @@ void chHeapFree(void *p) { * * @api */ -size_t chHeapStatus(MemoryHeap *heapp, size_t *sizep) { +size_t chHeapStatus(memory_heap_t *heapp, size_t *sizep) { union heap_header *qp; size_t n, sz; @@ -259,60 +273,6 @@ size_t chHeapStatus(MemoryHeap *heapp, size_t *sizep) { return n; } -#else /* CH_USE_MALLOC_HEAP */ - -#include - -#if CH_USE_MUTEXES -#define H_LOCK() chMtxLock(&hmtx) -#define H_UNLOCK() chMtxUnlock() -static Mutex hmtx; -#elif CH_USE_SEMAPHORES -#define H_LOCK() chSemWait(&hsem) -#define H_UNLOCK() chSemSignal(&hsem) -static Semaphore hsem; -#endif - -void _heap_init(void) { - -#if CH_USE_MUTEXES - chMtxInit(&hmtx); -#else - chSemInit(&hsem, 1); -#endif -} - -void *chHeapAlloc(MemoryHeap *heapp, size_t size) { - void *p; - - chDbgCheck(heapp == NULL, "chHeapAlloc"); - - H_LOCK(); - p = malloc(size); - H_UNLOCK(); - return p; -} - -void chHeapFree(void *p) { - - chDbgCheck(p != NULL, "chHeapFree"); - - H_LOCK(); - free(p); - H_UNLOCK(); -} - -size_t chHeapStatus(MemoryHeap *heapp, size_t *sizep) { - - chDbgCheck(heapp == NULL, "chHeapStatus"); - - if (sizep) - *sizep = 0; - return 0; -} - -#endif /* CH_USE_MALLOC_HEAP */ - #endif /* CH_USE_HEAP */ /** @} */ diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index 6f09a8d26..16f303daf 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -53,16 +53,38 @@ #include "ch.h" #if CH_USE_MAILBOXES || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** - * @brief Initializes a Mailbox object. + * @brief Initializes a @p mailbox_t object. * - * @param[out] mbp the pointer to the Mailbox structure to be initialized + * @param[out] mbp the pointer to the @p mailbox_t structure to be + * initialized * @param[in] buf pointer to the messages buffer as an array of @p msg_t * @param[in] n number of elements in the buffer array * * @init */ -void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n) { +void chMBInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0), "chMBInit"); @@ -73,15 +95,15 @@ void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n) { } /** - * @brief Resets a Mailbox object. + * @brief Resets a @p mailbox_t object. * @details All the waiting threads are resumed with status @p RDY_RESET and * the queued messages are lost. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * * @api */ -void chMBReset(Mailbox *mbp) { +void chMBReset(mailbox_t *mbp) { chDbgCheck(mbp != NULL, "chMBReset"); @@ -98,7 +120,7 @@ void chMBReset(Mailbox *mbp) { * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -112,7 +134,7 @@ void chMBReset(Mailbox *mbp) { * * @api */ -msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time) { +msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chSysLock(); @@ -126,7 +148,7 @@ msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time) { * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -140,7 +162,7 @@ msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time) { * * @sclass */ -msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { +msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); @@ -162,7 +184,7 @@ msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @return The operation status. * @retval RDY_OK if a message has been correctly posted. @@ -171,7 +193,7 @@ msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { * * @iclass */ -msg_t chMBPostI(Mailbox *mbp, msg_t msg) { +msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL, "chMBPostI"); @@ -191,7 +213,7 @@ msg_t chMBPostI(Mailbox *mbp, msg_t msg) { * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -205,7 +227,7 @@ msg_t chMBPostI(Mailbox *mbp, msg_t msg) { * * @api */ -msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t time) { +msg_t chMBPostAhead(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chSysLock(); @@ -219,7 +241,7 @@ msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t time) { * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -233,7 +255,7 @@ msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t time) { * * @sclass */ -msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { +msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); @@ -255,7 +277,7 @@ msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @return The operation status. * @retval RDY_OK if a message has been correctly posted. @@ -264,7 +286,7 @@ msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { * * @iclass */ -msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) { +msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL, "chMBPostAheadI"); @@ -284,7 +306,7 @@ msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) { * @details The invoking thread waits until a message is posted in the mailbox * or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[out] msgp pointer to a message variable for the received message * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -298,7 +320,7 @@ msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) { * * @api */ -msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t time) { +msg_t chMBFetch(mailbox_t *mbp, msg_t *msgp, systime_t time) { msg_t rdymsg; chSysLock(); @@ -312,7 +334,7 @@ msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t time) { * @details The invoking thread waits until a message is posted in the mailbox * or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[out] msgp pointer to a message variable for the received message * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -326,7 +348,7 @@ msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t time) { * * @sclass */ -msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { +msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); @@ -348,7 +370,7 @@ msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { * @details This variant is non-blocking, the function returns a timeout * condition if the queue is empty. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[out] msgp pointer to a message variable for the received message * @return The operation status. * @retval RDY_OK if a message has been correctly fetched. @@ -357,7 +379,7 @@ msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { * * @iclass */ -msg_t chMBFetchI(Mailbox *mbp, msg_t *msgp) { +msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { chDbgCheckClassI(); chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchI"); diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 0ff26bc76..76f415743 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -48,9 +48,29 @@ #if CH_USE_MEMCORE || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + static uint8_t *nextmem; static uint8_t *endmem; +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Low level memory manager initialization. * @@ -60,10 +80,12 @@ void _core_init(void) { #if CH_MEMCORE_SIZE == 0 extern uint8_t __heap_base__[]; extern uint8_t __heap_end__[]; + nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__); endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__); #else static stkalign_t buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; + nextmem = (uint8_t *)&buffer[0]; endmem = (uint8_t *)&buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; #endif diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c index 44faa057a..b52f0b6d9 100644 --- a/os/kernel/src/chmempools.c +++ b/os/kernel/src/chmempools.c @@ -39,10 +39,31 @@ #include "ch.h" #if CH_USE_MEMPOOLS || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Initializes an empty memory pool. * - * @param[out] mp pointer to a @p MemoryPool structure + * @param[out] mp pointer to a @p memory_pool_t structure * @param[in] size the size of the objects contained in this memory pool, * the minimum accepted size is the size of a pointer to * void. @@ -52,7 +73,7 @@ * * @init */ -void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) { +void chPoolInit(memory_pool_t *mp, size_t size, memgetfunc_t provider) { chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit"); @@ -68,13 +89,13 @@ void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) { * memory pool. * @post The memory pool contains the elements of the input array. * - * @param[in] mp pointer to a @p MemoryPool structure + * @param[in] mp pointer to a @p memory_pool_t structure * @param[in] p pointer to the array first element * @param[in] n number of elements in the array * * @api */ -void chPoolLoadArray(MemoryPool *mp, void *p, size_t n) { +void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n) { chDbgCheck((mp != NULL) && (n != 0), "chPoolLoadArray"); @@ -89,13 +110,13 @@ void chPoolLoadArray(MemoryPool *mp, void *p, size_t n) { * @brief Allocates an object from a memory pool. * @pre The memory pool must be already been initialized. * - * @param[in] mp pointer to a @p MemoryPool structure + * @param[in] mp pointer to a @p memory_pool_t structure * @return The pointer to the allocated object. * @retval NULL if pool is empty. * * @iclass */ -void *chPoolAllocI(MemoryPool *mp) { +void *chPoolAllocI(memory_pool_t *mp) { void *objp; chDbgCheckClassI(); @@ -112,13 +133,13 @@ void *chPoolAllocI(MemoryPool *mp) { * @brief Allocates an object from a memory pool. * @pre The memory pool must be already been initialized. * - * @param[in] mp pointer to a @p MemoryPool structure + * @param[in] mp pointer to a @p memory_pool_t structure * @return The pointer to the allocated object. * @retval NULL if pool is empty. * * @api */ -void *chPoolAlloc(MemoryPool *mp) { +void *chPoolAlloc(memory_pool_t *mp) { void *objp; chSysLock(); @@ -134,12 +155,12 @@ void *chPoolAlloc(MemoryPool *mp) { * memory pool. * @pre The object must be properly aligned to contain a pointer to void. * - * @param[in] mp pointer to a @p MemoryPool structure + * @param[in] mp pointer to a @p memory_pool_t structure * @param[in] objp the pointer to the object to be released * * @iclass */ -void chPoolFreeI(MemoryPool *mp, void *objp) { +void chPoolFreeI(memory_pool_t *mp, void *objp) { struct pool_header *php = objp; chDbgCheckClassI(); @@ -156,12 +177,12 @@ void chPoolFreeI(MemoryPool *mp, void *objp) { * memory pool. * @pre The object must be properly aligned to contain a pointer to void. * - * @param[in] mp pointer to a @p MemoryPool structure + * @param[in] mp pointer to a @p memory_pool_t structure * @param[in] objp the pointer to the object to be released * * @api */ -void chPoolFree(MemoryPool *mp, void *objp) { +void chPoolFree(memory_pool_t *mp, void *objp) { chSysLock(); chPoolFreeI(mp, objp); diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 50e489915..b53f91979 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -48,12 +48,32 @@ #if CH_USE_MESSAGES || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + #if CH_USE_MESSAGES_PRIORITY #define msg_insert(tp, qp) prio_insert(tp, qp) #else #define msg_insert(tp, qp) queue_insert(tp, qp) #endif +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Sends a message to the specified thread. * @details The sender is stopped until the receiver executes a diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index f70dd9b20..84e868a3f 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -69,14 +69,34 @@ #if CH_USE_MUTEXES || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** - * @brief Initializes s @p Mutex structure. + * @brief Initializes s @p mutex_t structure. * - * @param[out] mp pointer to a @p Mutex structure + * @param[out] mp pointer to a @p mutex_t structure * * @init */ -void chMtxInit(Mutex *mp) { +void chMtxInit(mutex_t *mp) { chDbgCheck(mp != NULL, "chMtxInit"); @@ -89,11 +109,11 @@ void chMtxInit(Mutex *mp) { * @post The mutex is locked and inserted in the per-thread stack of owned * mutexes. * - * @param[in] mp pointer to the @p Mutex structure + * @param[in] mp pointer to the @p mutex_t structure * * @api */ -void chMtxLock(Mutex *mp) { +void chMtxLock(mutex_t *mp) { chSysLock(); @@ -107,11 +127,11 @@ void chMtxLock(Mutex *mp) { * @post The mutex is locked and inserted in the per-thread stack of owned * mutexes. * - * @param[in] mp pointer to the @p Mutex structure + * @param[in] mp pointer to the @p mutex_t structure * * @sclass */ -void chMtxLockS(Mutex *mp) { +void chMtxLockS(mutex_t *mp) { thread_t *ctp = currp; chDbgCheckClassS(); @@ -123,18 +143,20 @@ void chMtxLockS(Mutex *mp) { boosting the priority of all the affected threads to equal the priority of the running thread requesting the mutex.*/ thread_t *tp = mp->m_owner; + /* Does the running thread have higher priority than the mutex owning thread? */ while (tp->p_prio < ctp->p_prio) { /* Make priority of thread tp match the running thread's priority.*/ tp->p_prio = ctp->p_prio; + /* The following states need priority queues reordering.*/ switch (tp->p_state) { case THD_STATE_WTMTX: /* Re-enqueues the mutex owner with its new priority.*/ queue_prio_insert(queue_dequeue(tp), (threads_queue_t *)tp->p_u.wtobjp); - tp = ((Mutex *)tp->p_u.wtobjp)->m_owner; + tp = ((mutex_t *)tp->p_u.wtobjp)->m_owner; continue; #if CH_USE_CONDVARS | \ (CH_USE_SEMAPHORES && CH_USE_SEMAPHORES_PRIORITY) | \ @@ -164,10 +186,12 @@ void chMtxLockS(Mutex *mp) { } break; } + /* Sleep on the mutex.*/ queue_prio_insert(ctp, &mp->m_queue); ctp->p_u.wtobjp = mp; chSchGoSleepS(THD_STATE_WTMTX); + /* It is assumed that the thread performing the unlock operation assigns the mutex to this thread.*/ chDbgAssert(mp->m_owner == ctp, "chMtxLockS(), #1", "not owner"); @@ -191,14 +215,14 @@ void chMtxLockS(Mutex *mp) { * priority inheritance mechanism because it does not try to * enter a sleep state. * - * @param[in] mp pointer to the @p Mutex structure + * @param[in] mp pointer to the @p mutex_t structure * @return The operation status. * @retval TRUE if the mutex has been successfully acquired * @retval FALSE if the lock attempt failed. * * @api */ -bool_t chMtxTryLock(Mutex *mp) { +bool_t chMtxTryLock(mutex_t *mp) { bool_t b; chSysLock(); @@ -219,20 +243,21 @@ bool_t chMtxTryLock(Mutex *mp) { * priority inheritance mechanism because it does not try to * enter a sleep state. * - * @param[in] mp pointer to the @p Mutex structure + * @param[in] mp pointer to the @p mutex_t structure * @return The operation status. * @retval TRUE if the mutex has been successfully acquired * @retval FALSE if the lock attempt failed. * * @sclass */ -bool_t chMtxTryLockS(Mutex *mp) { +bool_t chMtxTryLockS(mutex_t *mp) { chDbgCheckClassS(); chDbgCheck(mp != NULL, "chMtxTryLockS"); if (mp->m_owner != NULL) return FALSE; + mp->m_owner = currp; mp->m_next = currp->p_mtxlist; currp->p_mtxlist = mp; @@ -249,21 +274,24 @@ bool_t chMtxTryLockS(Mutex *mp) { * * @api */ -Mutex *chMtxUnlock(void) { +mutex_t *chMtxUnlock(void) { thread_t *ctp = currp; - Mutex *ump, *mp; + mutex_t *ump, *mp; chSysLock(); + chDbgAssert(ctp->p_mtxlist != NULL, "chMtxUnlock(), #1", "owned mutexes list empty"); chDbgAssert(ctp->p_mtxlist->m_owner == ctp, "chMtxUnlock(), #2", "ownership failure"); - /* Removes the top Mutex from the thread's owned mutexes list and marks it + + /* Removes the top mutex from the thread's owned mutexes list and marks it as not owned.*/ ump = ctp->p_mtxlist; ctp->p_mtxlist = ump->m_next; + /* If a thread is waiting on the mutex then the fun part begins.*/ if (chMtxQueueNotEmptyS(ump)) { thread_t *tp; @@ -280,9 +308,11 @@ Mutex *chMtxUnlock(void) { newprio = mp->m_queue.p_next->p_prio; mp = mp->m_next; } + /* Assigns to the current thread the highest priority among all the waiting threads.*/ ctp->p_prio = newprio; + /* Awakens the highest priority thread waiting for the unlocked mutex and assigns the mutex to it.*/ tp = queue_fifo_remove(&ump->m_queue); @@ -309,9 +339,9 @@ Mutex *chMtxUnlock(void) { * * @sclass */ -Mutex *chMtxUnlockS(void) { +mutex_t *chMtxUnlockS(void) { thread_t *ctp = currp; - Mutex *ump, *mp; + mutex_t *ump, *mp; chDbgCheckClassS(); chDbgAssert(ctp->p_mtxlist != NULL, @@ -321,10 +351,11 @@ Mutex *chMtxUnlockS(void) { "chMtxUnlockS(), #2", "ownership failure"); - /* Removes the top Mutex from the owned mutexes list and marks it as not + /* Removes the top mutex from the owned mutexes list and marks it as not owned.*/ ump = ctp->p_mtxlist; ctp->p_mtxlist = ump->m_next; + /* If a thread is waiting on the mutex then the fun part begins.*/ if (chMtxQueueNotEmptyS(ump)) { thread_t *tp; @@ -339,9 +370,11 @@ Mutex *chMtxUnlockS(void) { priority will have at least that priority.*/ if (chMtxQueueNotEmptyS(mp) && (mp->m_queue.p_next->p_prio > newprio)) newprio = mp->m_queue.p_next->p_prio; + mp = mp->m_next; } ctp->p_prio = newprio; + /* Awakens the highest priority thread waiting for the unlocked mutex and assigns the mutex to it.*/ tp = queue_fifo_remove(&ump->m_queue); @@ -372,7 +405,7 @@ void chMtxUnlockAll(void) { chSysLock(); if (ctp->p_mtxlist != NULL) { do { - Mutex *ump = ctp->p_mtxlist; + mutex_t *ump = ctp->p_mtxlist; ctp->p_mtxlist = ump->m_next; if (chMtxQueueNotEmptyS(ump)) { thread_t *tp = queue_fifo_remove(&ump->m_queue); diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c index d567393c1..832ef0ce9 100644 --- a/os/kernel/src/chregistry.c +++ b/os/kernel/src/chregistry.c @@ -50,9 +50,29 @@ #if CH_USE_REGISTRY || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + #define _offsetof(st, m) \ ((size_t)((char *)&((st *)0)->m - (char *)0)) +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /* * OS signature in ROM plus debug-related information. */ diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index 73d156c02..8ddba8523 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -61,12 +61,32 @@ #if CH_USE_SEMAPHORES || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + #if CH_USE_SEMAPHORES_PRIORITY #define sem_insert(tp, qp) prio_insert(tp, qp) #else #define sem_insert(tp, qp) queue_insert(tp, qp) #endif +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Initializes a semaphore with the specified counter value. * diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index f960d9b79..578de3ccf 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -35,12 +35,30 @@ #include "ch.h" +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + #if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief Idle thread working area. */ -WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); +static WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); +#endif /* CH_NO_IDLE_THREAD */ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ +#if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief This function implements the idle thread infinite loop. * @details The function puts the processor in the lowest power mode capable @@ -51,7 +69,7 @@ WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); * * @param[in] p the thread parameter, unused in this scenario */ -void _idle_thread(void *p) { +static void _idle_thread(void *p) { (void)p; chRegSetThreadName("idle"); @@ -62,6 +80,10 @@ void _idle_thread(void *p) { } #endif /* CH_NO_IDLE_THREAD */ +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief ChibiOS/RT initialization. * @details After executing this function the current instructions stream @@ -116,6 +138,29 @@ void chSysInit(void) { #endif } +/** + * @brief Halts the system. + * @details This function is invoked by the operating system when an + * unrecoverable error is detected, for example because a programming + * error in the application code that triggers an assertion while + * in debug mode. + * @note Can be invoked from any system state. + * + * @special + */ +void chSysHalt(void) { + + chSysDisable(); + +#if defined(SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) + SYSTEM_HALT_HOOK(); +#endif + + /* Harmless infinite loop.*/ + while (true) + ; +} + /** * @brief Handles time ticks for round robin preemption and timer increments. * @details Decrements the remaining time quantum of the running thread -- cgit v1.2.3 From 390ed322cb8f40cb9250021cde5f48acb928d291 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Jul 2013 07:24:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6001 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 2 +- os/kernel/src/chheap.c | 12 ++++++------ os/kernel/src/chmboxes.c | 6 +++--- os/kernel/src/chmempools.c | 2 +- os/kernel/src/chmtx.c | 20 ++++++++++---------- os/kernel/src/chqueues.c | 4 ++-- os/kernel/src/chschd.c | 4 ++-- os/kernel/src/chsem.c | 2 +- os/kernel/src/chsys.c | 2 +- os/kernel/src/chthreads.c | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index 6b718c7f9..d4d845512 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -73,7 +73,7 @@ * * @init */ -void chCondInit(condition_variable_t *cp) { +void chCondObjectInit(condition_variable_t *cp) { chDbgCheck(cp != NULL, "chCondInit"); diff --git a/os/kernel/src/chheap.c b/os/kernel/src/chheap.c index 4f20d3920..b41817123 100644 --- a/os/kernel/src/chheap.c +++ b/os/kernel/src/chheap.c @@ -88,9 +88,9 @@ void _heap_init(void) { default_heap.h_free.h.u.next = (union heap_header *)NULL; default_heap.h_free.h.size = 0; #if CH_USE_MUTEXES || defined(__DOXYGEN__) - chMtxInit(&default_heap.h_mtx); + chMtxObjectInit(&default_heap.h_mtx); #else - chSemInit(&default_heap.h_sem, 1); + chSemObjectInit(&default_heap.h_sem, 1); #endif } @@ -105,7 +105,7 @@ void _heap_init(void) { * * @init */ -void chHeapInit(memory_heap_t *heapp, void *buf, size_t size) { +void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) { union heap_header *hp; chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size), "chHeapInit"); @@ -116,9 +116,9 @@ void chHeapInit(memory_heap_t *heapp, void *buf, size_t size) { hp->h.u.next = NULL; hp->h.size = size - sizeof(union heap_header); #if CH_USE_MUTEXES || defined(__DOXYGEN__) - chMtxInit(&heapp->h_mtx); + chMtxObjectInit(&heapp->h_mtx); #else - chSemInit(&heapp->h_sem, 1); + chSemObjectInit(&heapp->h_sem, 1); #endif } @@ -211,7 +211,7 @@ void chHeapFree(void *p) { qp = &heapp->h_free; H_LOCK(heapp); - while (TRUE) { + while (true) { chDbgAssert((hp < qp) || (hp >= LIMIT(qp)), "chHeapFree(), #1", "within free block"); diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index 16f303daf..b1a4fb963 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -84,14 +84,14 @@ * * @init */ -void chMBInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { +void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0), "chMBInit"); mbp->mb_buffer = mbp->mb_wrptr = mbp->mb_rdptr = buf; mbp->mb_top = &buf[n]; - chSemInit(&mbp->mb_emptysem, n); - chSemInit(&mbp->mb_fullsem, 0); + chSemObjectInit(&mbp->mb_emptysem, n); + chSemObjectInit(&mbp->mb_fullsem, 0); } /** diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c index b52f0b6d9..44557235b 100644 --- a/os/kernel/src/chmempools.c +++ b/os/kernel/src/chmempools.c @@ -73,7 +73,7 @@ * * @init */ -void chPoolInit(memory_pool_t *mp, size_t size, memgetfunc_t provider) { +void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider) { chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit"); diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index 84e868a3f..ec191b53d 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -96,7 +96,7 @@ * * @init */ -void chMtxInit(mutex_t *mp) { +void chMtxObjectInit(mutex_t *mp) { chDbgCheck(mp != NULL, "chMtxInit"); @@ -217,13 +217,13 @@ void chMtxLockS(mutex_t *mp) { * * @param[in] mp pointer to the @p mutex_t structure * @return The operation status. - * @retval TRUE if the mutex has been successfully acquired - * @retval FALSE if the lock attempt failed. + * @retval true if the mutex has been successfully acquired + * @retval false if the lock attempt failed. * * @api */ -bool_t chMtxTryLock(mutex_t *mp) { - bool_t b; +bool chMtxTryLock(mutex_t *mp) { + bool b; chSysLock(); @@ -245,23 +245,23 @@ bool_t chMtxTryLock(mutex_t *mp) { * * @param[in] mp pointer to the @p mutex_t structure * @return The operation status. - * @retval TRUE if the mutex has been successfully acquired - * @retval FALSE if the lock attempt failed. + * @retval true if the mutex has been successfully acquired + * @retval false if the lock attempt failed. * * @sclass */ -bool_t chMtxTryLockS(mutex_t *mp) { +bool chMtxTryLockS(mutex_t *mp) { chDbgCheckClassS(); chDbgCheck(mp != NULL, "chMtxTryLockS"); if (mp->m_owner != NULL) - return FALSE; + return false; mp->m_owner = currp; mp->m_next = currp->p_mtxlist; currp->p_mtxlist = mp; - return TRUE; + return true; } /** diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index a4b0aa416..7115d77b6 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -224,7 +224,7 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp, chDbgCheck(n > 0, "chIQReadTimeout"); chSysLock(); - while (TRUE) { + while (true) { if (nfy) nfy(iqp); @@ -404,7 +404,7 @@ size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp, chDbgCheck(n > 0, "chOQWriteTimeout"); chSysLock(); - while (TRUE) { + while (true) { while (chOQIsFullI(oqp)) { if (qwait((GenericQueue *)oqp, time) != Q_OK) { chSysUnlock(); diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index b99afbbb9..4592f4806 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -267,9 +267,9 @@ void chSchRescheduleS(void) { * @note Not a user function, it is meant to be invoked by the scheduler * itself or from within the port layer. * - * @retval TRUE if there is a thread that must go in running state + * @retval true if there is a thread that must go in running state * immediately. - * @retval FALSE if preemption is not required. + * @retval false if preemption is not required. * * @special */ diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index 8ddba8523..554c02246 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -96,7 +96,7 @@ * * @init */ -void chSemInit(semaphore_t *sp, cnt_t n) { +void chSemObjectInit(semaphore_t *sp, cnt_t n) { chDbgCheck((sp != NULL) && (n >= 0), "chSemInit"); diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 578de3ccf..b3d99a7d9 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -73,7 +73,7 @@ static void _idle_thread(void *p) { (void)p; chRegSetThreadName("idle"); - while (TRUE) { + while (true) { port_wait_for_interrupt(); IDLE_LOOP_HOOK(); } diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index bc161ba52..47f53e10d 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -280,7 +280,7 @@ thread_t *chThdResume(thread_t *tp) { * @brief Requests a thread termination. * @pre The target thread must be written to invoke periodically * @p chThdShouldTerminate() and terminate cleanly if it returns - * @p TRUE. + * @p true. * @post The specified thread will terminate after detecting the termination * condition. * @@ -400,7 +400,7 @@ void chThdExitS(msg_t msg) { #endif chSchGoSleepS(THD_STATE_FINAL); /* The thread never returns here.*/ - chDbgAssert(FALSE, "chThdExitS(), #1", "zombies apocalypse"); + chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); } #if CH_USE_WAITEXIT || defined(__DOXYGEN__) -- cgit v1.2.3 From 49d71a01abeefa000a4cd7a556052d826b096d49 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Jul 2013 10:12:44 +0000 Subject: Renamed or added prefix to all hernel configuration options. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6010 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 14 +++++++------- os/kernel/src/chdynamic.c | 28 ++++++++++++++-------------- os/kernel/src/chevents.c | 14 +++++++------- os/kernel/src/chheap.c | 12 ++++++------ os/kernel/src/chlists.c | 4 ++-- os/kernel/src/chmboxes.c | 6 +++--- os/kernel/src/chmemcore.c | 12 ++++++------ os/kernel/src/chmempools.c | 6 +++--- os/kernel/src/chmsg.c | 10 +++++----- os/kernel/src/chmtx.c | 18 +++++++++--------- os/kernel/src/chqueues.c | 6 +++--- os/kernel/src/chregistry.c | 16 ++++++++-------- os/kernel/src/chschd.c | 30 +++++++++++++++--------------- os/kernel/src/chsem.c | 14 +++++--------- os/kernel/src/chsys.c | 28 ++++++++++++++-------------- os/kernel/src/chthreads.c | 44 ++++++++++++++++++++++---------------------- 16 files changed, 129 insertions(+), 133 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index d4d845512..8486705e6 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -33,14 +33,14 @@ * The condition variable is a synchronization object meant to be * used inside a zone protected by a mutex. Mutexes and condition * variables together can implement a Monitor construct. - * @pre In order to use the condition variable APIs the @p CH_USE_CONDVARS + * @pre In order to use the condition variable APIs the @p CH_CFG_USE_CONDVARS * option must be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_CONDVARS || defined(__DOXYGEN__) +#if CH_CFG_USE_CONDVARS || defined(__DOXYGEN__) /*===========================================================================*/ /* Module local definitions. */ @@ -218,14 +218,14 @@ msg_t chCondWaitS(condition_variable_t *cp) { return msg; } -#if CH_USE_CONDVARS_TIMEOUT || defined(__DOXYGEN__) +#if CH_CFG_USE_CONDVARS_TIMEOUT || defined(__DOXYGEN__) /** * @brief Waits on the condition variable releasing the mutex lock. * @details Releases the currently owned mutex, waits on the condition * variable, and finally acquires the mutex again. All the sequence * is performed atomically. * @pre The invoking thread must have at least one owned mutex. - * @pre The configuration option @p CH_USE_CONDVARS_TIMEOUT must be enabled + * @pre The configuration option @p CH_CFG_USE_CONDVARS_TIMEOUT must be enabled * in order to use this function. * @post Exiting the function because a timeout does not re-acquire the * mutex, the mutex ownership is lost. @@ -262,7 +262,7 @@ msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) { * variable, and finally acquires the mutex again. All the sequence * is performed atomically. * @pre The invoking thread must have at least one owned mutex. - * @pre The configuration option @p CH_USE_CONDVARS_TIMEOUT must be enabled + * @pre The configuration option @p CH_CFG_USE_CONDVARS_TIMEOUT must be enabled * in order to use this function. * @post Exiting the function because a timeout does not re-acquire the * mutex, the mutex ownership is lost. @@ -302,8 +302,8 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { chMtxLockS(mp); return msg; } -#endif /* CH_USE_CONDVARS_TIMEOUT */ +#endif /* CH_CFG_USE_CONDVARS_TIMEOUT */ -#endif /* CH_USE_CONDVARS */ +#endif /* CH_CFG_USE_CONDVARS */ /** @} */ diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c index 21c81fc24..cab5556f3 100644 --- a/os/kernel/src/chdynamic.c +++ b/os/kernel/src/chdynamic.c @@ -29,7 +29,7 @@ #include "ch.h" -#if CH_USE_DYNAMIC || defined(__DOXYGEN__) +#if CH_CFG_USE_DYNAMIC || defined(__DOXYGEN__) /*===========================================================================*/ /* Module local definitions. */ @@ -57,7 +57,7 @@ /** * @brief Adds a reference to a thread object. - * @pre The configuration option @p CH_USE_DYNAMIC must be enabled in order + * @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in order * to use this function. * * @param[in] tp pointer to the thread @@ -80,7 +80,7 @@ thread_t *chThdAddRef(thread_t *tp) { * @details If the references counter reaches zero and the thread * is in the @p THD_STATE_FINAL state then the thread's memory is * returned to the proper allocator. - * @pre The configuration option @p CH_USE_DYNAMIC must be enabled in order + * @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in order * to use this function. * @note Static threads are not affected. * @@ -101,17 +101,17 @@ void chThdRelease(thread_t *tp) { allocator. Of course static threads are not affected.*/ if ((refs == 0) && (tp->p_state == THD_STATE_FINAL)) { switch (tp->p_flags & THD_MEM_MODE_MASK) { -#if CH_USE_HEAP +#if CH_CFG_USE_HEAP case THD_MEM_MODE_HEAP: -#if CH_USE_REGISTRY +#if CH_CFG_USE_REGISTRY REG_REMOVE(tp); #endif chHeapFree(tp); break; #endif -#if CH_USE_MEMPOOLS +#if CH_CFG_USE_MEMPOOLS case THD_MEM_MODE_MEMPOOL: -#if CH_USE_REGISTRY +#if CH_CFG_USE_REGISTRY REG_REMOVE(tp); #endif chPoolFree(tp->p_mpool, tp); @@ -121,10 +121,10 @@ void chThdRelease(thread_t *tp) { } } -#if CH_USE_HEAP || defined(__DOXYGEN__) +#if CH_CFG_USE_HEAP || defined(__DOXYGEN__) /** * @brief Creates a new thread allocating the memory from the heap. - * @pre The configuration options @p CH_USE_DYNAMIC and @p CH_USE_HEAP + * @pre The configuration options @p CH_CFG_USE_DYNAMIC and @p CH_CFG_USE_HEAP * must be enabled in order to use this function. * @note A thread can terminate by calling @p chThdExit() or by simply * returning from its main function. @@ -169,13 +169,13 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, chSysUnlock(); return tp; } -#endif /* CH_USE_HEAP */ +#endif /* CH_CFG_USE_HEAP */ -#if CH_USE_MEMPOOLS || defined(__DOXYGEN__) +#if CH_CFG_USE_MEMPOOLS || defined(__DOXYGEN__) /** * @brief Creates a new thread allocating the memory from the specified * memory pool. - * @pre The configuration options @p CH_USE_DYNAMIC and @p CH_USE_MEMPOOLS + * @pre The configuration options @p CH_CFG_USE_DYNAMIC and @p CH_CFG_USE_MEMPOOLS * must be enabled in order to use this function. * @note A thread can terminate by calling @p chThdExit() or by simply * returning from its main function. @@ -221,8 +221,8 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, chSysUnlock(); return tp; } -#endif /* CH_USE_MEMPOOLS */ +#endif /* CH_CFG_USE_MEMPOOLS */ -#endif /* CH_USE_DYNAMIC */ +#endif /* CH_CFG_USE_DYNAMIC */ /** @} */ diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index 1206b61fe..f48a3ec9a 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -51,7 +51,7 @@ * An unlimited number of Event Sources can exists in a system and * each thread can be listening on an unlimited number of * them. - * @pre In order to use the Events APIs the @p CH_USE_EVENTS option must be + * @pre In order to use the Events APIs the @p CH_CFG_USE_EVENTS option must be * enabled in @p chconf.h. * @post Enabling events requires 1-4 (depending on the architecture) * extra bytes in the @p thread_t structure. @@ -60,7 +60,7 @@ #include "ch.h" -#if CH_USE_EVENTS || defined(__DOXYGEN__) +#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__) /*===========================================================================*/ /* Module local definitions. */ @@ -350,7 +350,7 @@ void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask) { } } -#if CH_OPTIMIZE_SPEED || !CH_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__) +#if CH_CFG_OPTIMIZE_SPEED || !CH_CFG_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__) /** * @brief Waits for exactly one of the specified events. * @details The function waits for one event among those specified in @@ -438,9 +438,9 @@ eventmask_t chEvtWaitAll(eventmask_t mask) { chSysUnlock(); return mask; } -#endif /* CH_OPTIMIZE_SPEED || !CH_USE_EVENTS_TIMEOUT */ +#endif /* CH_CFG_OPTIMIZE_SPEED || !CH_CFG_USE_EVENTS_TIMEOUT */ -#if CH_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__) +#if CH_CFG_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__) /** * @brief Waits for exactly one of the specified events. * @details The function waits for one event among those specified in @@ -568,8 +568,8 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time) { chSysUnlock(); return mask; } -#endif /* CH_USE_EVENTS_TIMEOUT */ +#endif /* CH_CFG_USE_EVENTS_TIMEOUT */ -#endif /* CH_USE_EVENTS */ +#endif /* CH_CFG_USE_EVENTS */ /** @} */ diff --git a/os/kernel/src/chheap.c b/os/kernel/src/chheap.c index b41817123..c2732376e 100644 --- a/os/kernel/src/chheap.c +++ b/os/kernel/src/chheap.c @@ -29,14 +29,14 @@ * are functionally equivalent to the usual @p malloc() and @p free() * library functions. The main difference is that the OS heap APIs * are guaranteed to be thread safe.
- * @pre In order to use the heap APIs the @p CH_USE_HEAP option must + * @pre In order to use the heap APIs the @p CH_CFG_USE_HEAP option must * be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_HEAP || defined(__DOXYGEN__) +#if CH_CFG_USE_HEAP || defined(__DOXYGEN__) /*===========================================================================*/ /* Module local definitions. */ @@ -45,7 +45,7 @@ /* * Defaults on the best synchronization mechanism available. */ -#if CH_USE_MUTEXES || defined(__DOXYGEN__) +#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) #define H_LOCK(h) chMtxLock(&(h)->h_mtx) #define H_UNLOCK(h) chMtxUnlock() #else @@ -87,7 +87,7 @@ void _heap_init(void) { default_heap.h_provider = chCoreAlloc; default_heap.h_free.h.u.next = (union heap_header *)NULL; default_heap.h_free.h.size = 0; -#if CH_USE_MUTEXES || defined(__DOXYGEN__) +#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) chMtxObjectInit(&default_heap.h_mtx); #else chSemObjectInit(&default_heap.h_sem, 1); @@ -115,7 +115,7 @@ void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) { heapp->h_free.h.size = 0; hp->h.u.next = NULL; hp->h.size = size - sizeof(union heap_header); -#if CH_USE_MUTEXES || defined(__DOXYGEN__) +#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) chMtxObjectInit(&heapp->h_mtx); #else chSemObjectInit(&heapp->h_sem, 1); @@ -273,6 +273,6 @@ size_t chHeapStatus(memory_heap_t *heapp, size_t *sizep) { return n; } -#endif /* CH_USE_HEAP */ +#endif /* CH_CFG_USE_HEAP */ /** @} */ diff --git a/os/kernel/src/chlists.c b/os/kernel/src/chlists.c index 241067ab4..0f492db5f 100644 --- a/os/kernel/src/chlists.c +++ b/os/kernel/src/chlists.c @@ -54,7 +54,7 @@ /* Module exported functions. */ /*===========================================================================*/ -#if !CH_OPTIMIZE_SPEED || defined(__DOXYGEN__) +#if !CH_CFG_OPTIMIZE_SPEED || defined(__DOXYGEN__) /** * @brief Inserts a thread into a priority ordered queue. * @note The insertion is done by scanning the list from the highest @@ -175,6 +175,6 @@ thread_t *list_remove(threads_list_t *tlp) { tlp->p_next = tp->p_next; return tp; } -#endif /* CH_OPTIMIZE_SPEED */ +#endif /* CH_CFG_OPTIMIZE_SPEED */ /** @} */ diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index b1a4fb963..2a6e6fae8 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -45,14 +45,14 @@ * example) from the posting side and free it on the fetching side. * Another approach is to set a "done" flag into the structure pointed * by the message. - * @pre In order to use the mailboxes APIs the @p CH_USE_MAILBOXES option + * @pre In order to use the mailboxes APIs the @p CH_CFG_USE_MAILBOXES option * must be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_MAILBOXES || defined(__DOXYGEN__) +#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -393,6 +393,6 @@ msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { chSemSignalI(&mbp->mb_emptysem); return RDY_OK; } -#endif /* CH_USE_MAILBOXES */ +#endif /* CH_CFG_USE_MAILBOXES */ /** @} */ diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 76f415743..d5e7ed79c 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -39,14 +39,14 @@ * This allocator, alone, is also useful for very simple * applications that just require a simple way to get memory * blocks. - * @pre In order to use the core memory manager APIs the @p CH_USE_MEMCORE + * @pre In order to use the core memory manager APIs the @p CH_CFG_USE_MEMCORE * option must be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_MEMCORE || defined(__DOXYGEN__) +#if CH_CFG_USE_MEMCORE || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -77,17 +77,17 @@ static uint8_t *endmem; * @notapi */ void _core_init(void) { -#if CH_MEMCORE_SIZE == 0 +#if CH_CFG_MEMCORE_SIZE == 0 extern uint8_t __heap_base__[]; extern uint8_t __heap_end__[]; nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__); endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__); #else - static stkalign_t buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; + static stkalign_t buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; nextmem = (uint8_t *)&buffer[0]; - endmem = (uint8_t *)&buffer[MEM_ALIGN_NEXT(CH_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; + endmem = (uint8_t *)&buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; #endif } @@ -148,6 +148,6 @@ size_t chCoreStatus(void) { return (size_t)(endmem - nextmem); } -#endif /* CH_USE_MEMCORE */ +#endif /* CH_CFG_USE_MEMCORE */ /** @} */ diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c index 44557235b..6d84b557e 100644 --- a/os/kernel/src/chmempools.c +++ b/os/kernel/src/chmempools.c @@ -31,14 +31,14 @@ * Memory Pools do not enforce any alignment constraint on the * contained object however the objects must be properly aligned * to contain a pointer to void. - * @pre In order to use the memory pools APIs the @p CH_USE_MEMPOOLS option + * @pre In order to use the memory pools APIs the @p CH_CFG_USE_MEMPOOLS option * must be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_MEMPOOLS || defined(__DOXYGEN__) +#if CH_CFG_USE_MEMPOOLS || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -189,6 +189,6 @@ void chPoolFree(memory_pool_t *mp, void *objp) { chSysUnlock(); } -#endif /* CH_USE_MEMPOOLS */ +#endif /* CH_CFG_USE_MEMPOOLS */ /** @} */ diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index b53f91979..535143b7c 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -36,8 +36,8 @@ * architectures function pointers can be larger that @p msg_t.
* Messages are usually processed in FIFO order but it is possible to * process them in priority order by enabling the - * @p CH_USE_MESSAGES_PRIORITY option in @p chconf.h.
- * @pre In order to use the message APIs the @p CH_USE_MESSAGES option + * @p CH_CFG_USE_MESSAGES_PRIORITY option in @p chconf.h.
+ * @pre In order to use the message APIs the @p CH_CFG_USE_MESSAGES option * must be enabled in @p chconf.h. * @post Enabling messages requires 6-12 (depending on the architecture) * extra bytes in the @p thread_t structure. @@ -46,7 +46,7 @@ #include "ch.h" -#if CH_USE_MESSAGES || defined(__DOXYGEN__) +#if CH_CFG_USE_MESSAGES || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -64,7 +64,7 @@ /* Module local functions. */ /*===========================================================================*/ -#if CH_USE_MESSAGES_PRIORITY +#if CH_CFG_USE_MESSAGES_PRIORITY #define msg_insert(tp, qp) prio_insert(tp, qp) #else #define msg_insert(tp, qp) queue_insert(tp, qp) @@ -147,6 +147,6 @@ void chMsgRelease(thread_t *tp, msg_t msg) { chSysUnlock(); } -#endif /* CH_USE_MESSAGES */ +#endif /* CH_CFG_USE_MESSAGES */ /** @} */ diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index ec191b53d..be9c6dd78 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -58,7 +58,7 @@ * The mechanism works with any number of nested mutexes and any * number of involved threads. The algorithm complexity (worst case) * is N with N equal to the number of nested mutexes. - * @pre In order to use the mutex APIs the @p CH_USE_MUTEXES option + * @pre In order to use the mutex APIs the @p CH_CFG_USE_MUTEXES option * must be enabled in @p chconf.h. * @post Enabling mutexes requires 5-12 (depending on the architecture) * extra bytes in the @p thread_t structure. @@ -67,7 +67,7 @@ #include "ch.h" -#if CH_USE_MUTEXES || defined(__DOXYGEN__) +#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -158,16 +158,16 @@ void chMtxLockS(mutex_t *mp) { (threads_queue_t *)tp->p_u.wtobjp); tp = ((mutex_t *)tp->p_u.wtobjp)->m_owner; continue; -#if CH_USE_CONDVARS | \ - (CH_USE_SEMAPHORES && CH_USE_SEMAPHORES_PRIORITY) | \ - (CH_USE_MESSAGES && CH_USE_MESSAGES_PRIORITY) -#if CH_USE_CONDVARS +#if CH_CFG_USE_CONDVARS | \ + (CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY) | \ + (CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY) +#if CH_CFG_USE_CONDVARS case THD_STATE_WTCOND: #endif -#if CH_USE_SEMAPHORES && CH_USE_SEMAPHORES_PRIORITY +#if CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY case THD_STATE_WTSEM: #endif -#if CH_USE_MESSAGES && CH_USE_MESSAGES_PRIORITY +#if CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY case THD_STATE_SNDMSGQ: #endif /* Re-enqueues tp with its new priority on the queue.*/ @@ -423,6 +423,6 @@ void chMtxUnlockAll(void) { chSysUnlock(); } -#endif /* CH_USE_MUTEXES */ +#endif /* CH_CFG_USE_MUTEXES */ /** @} */ diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index 7115d77b6..fcaa2895f 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -36,14 +36,14 @@ * are implemented by pairing an input queue and an output queue * together. * . - * @pre In order to use the I/O queues the @p CH_USE_QUEUES option must + * @pre In order to use the I/O queues the @p CH_CFG_USE_QUEUES option must * be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_QUEUES || defined(__DOXYGEN__) +#if CH_CFG_USE_QUEUES || defined(__DOXYGEN__) /** * @brief Puts the invoking thread into the queue's threads queue. @@ -426,6 +426,6 @@ size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp, chSysLock(); } } -#endif /* CH_USE_QUEUES */ +#endif /* CH_CFG_USE_QUEUES */ /** @} */ diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c index 832ef0ce9..b43341edd 100644 --- a/os/kernel/src/chregistry.c +++ b/os/kernel/src/chregistry.c @@ -42,13 +42,13 @@ * terminating threads can pulse an event source and an event handler * can perform a scansion of the registry in order to recover the * memory. - * @pre In order to use the threads registry the @p CH_USE_REGISTRY option + * @pre In order to use the threads registry the @p CH_CFG_USE_REGISTRY option * must be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_REGISTRY || defined(__DOXYGEN__) +#if CH_CFG_USE_REGISTRY || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -98,12 +98,12 @@ ROMCONST chdebug_t ch_debug = { #endif (uint8_t)_offsetof(thread_t, p_state), (uint8_t)_offsetof(thread_t, p_flags), -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC (uint8_t)_offsetof(thread_t, p_refs), #else (uint8_t)0, #endif -#if CH_TIME_QUANTUM > 0 +#if CH_CFG_TIME_QUANTUM > 0 (uint8_t)_offsetof(thread_t, p_preempt), #else (uint8_t)0, @@ -132,7 +132,7 @@ thread_t *chRegFirstThread(void) { chSysLock(); tp = rlist.r_newer; -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC tp->p_refs++; #endif chSysUnlock(); @@ -157,7 +157,7 @@ thread_t *chRegNextThread(thread_t *tp) { ntp = tp->p_newer; if (ntp == (thread_t *)&rlist) ntp = NULL; -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC else { chDbgAssert(ntp->p_refs < 255, "chRegNextThread(), #1", "too many references"); @@ -165,12 +165,12 @@ thread_t *chRegNextThread(thread_t *tp) { } #endif chSysUnlock(); -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC chThdRelease(tp); #endif return ntp; } -#endif /* CH_USE_REGISTRY */ +#endif /* CH_CFG_USE_REGISTRY */ /** @} */ diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 4592f4806..c360777ef 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -67,7 +67,7 @@ void _scheduler_init(void) { queue_init(&rlist.r_queue); rlist.r_prio = NOPRIO; -#if CH_USE_REGISTRY +#if CH_CFG_USE_REGISTRY rlist.r_newer = rlist.r_older = (thread_t *)&rlist; #endif } @@ -126,10 +126,10 @@ void chSchGoSleepS(tstate_t newstate) { chDbgCheckClassS(); (otp = currp)->p_state = newstate; -#if CH_TIME_QUANTUM > 0 +#if CH_CFG_TIME_QUANTUM > 0 /* The thread is renouncing its remaining time slices so it will have a new time quantum when it will wakeup.*/ - otp->p_preempt = CH_TIME_QUANTUM; + otp->p_preempt = CH_CFG_TIME_QUANTUM; #endif setcurrp(queue_fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; @@ -149,17 +149,17 @@ static void wakeup(void *p) { another thread with higher priority.*/ chSysUnlockFromIsr(); return; -#if CH_USE_SEMAPHORES || CH_USE_QUEUES || \ - (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) -#if CH_USE_SEMAPHORES +#if CH_CFG_USE_SEMAPHORES || CH_CFG_USE_QUEUES || \ + (CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT) +#if CH_CFG_USE_SEMAPHORES case THD_STATE_WTSEM: chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp); /* Falls into, intentional. */ #endif -#if CH_USE_QUEUES +#if CH_CFG_USE_QUEUES case THD_STATE_WTQUEUE: #endif -#if CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT +#if CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT case THD_STATE_WTCOND: #endif /* States requiring dequeuing.*/ @@ -276,7 +276,7 @@ void chSchRescheduleS(void) { bool chSchIsPreemptionRequired(void) { tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; -#if CH_TIME_QUANTUM > 0 +#if CH_CFG_TIME_QUANTUM > 0 /* If the running thread has not reached its time quantum, reschedule only if the first thread on the ready queue has a higher priority. Otherwise, if the running thread has used up its time quantum, reschedule @@ -306,8 +306,8 @@ void chSchDoRescheduleBehind(void) { /* Picks the first thread from the ready queue and makes it current.*/ setcurrp(queue_fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; -#if CH_TIME_QUANTUM > 0 - otp->p_preempt = CH_TIME_QUANTUM; +#if CH_CFG_TIME_QUANTUM > 0 + otp->p_preempt = CH_CFG_TIME_QUANTUM; #endif chSchReadyI(otp); chSysSwitch(currp, otp); @@ -355,8 +355,8 @@ void chSchDoRescheduleAhead(void) { */ void chSchDoReschedule(void) { -#if CH_TIME_QUANTUM > 0 - /* If CH_TIME_QUANTUM is enabled then there are two different scenarios to +#if CH_CFG_TIME_QUANTUM > 0 + /* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios to handle on preemption: time quantum elapsed or not.*/ if (currp->p_preempt == 0) { /* The thread consumed its time quantum so it is enqueued behind threads @@ -368,11 +368,11 @@ void chSchDoReschedule(void) { threads with equal priority and does not acquire a new time quantum.*/ chSchDoRescheduleAhead(); } -#else /* !(CH_TIME_QUANTUM > 0) */ +#else /* !(CH_CFG_TIME_QUANTUM > 0) */ /* If the round-robin mechanism is disabled then the thread goes always ahead of its peers.*/ chSchDoRescheduleAhead(); -#endif /* !(CH_TIME_QUANTUM > 0) */ +#endif /* !(CH_CFG_TIME_QUANTUM > 0) */ } /** @} */ diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index 554c02246..bcf222230 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -51,15 +51,15 @@ * also have other uses, queues guards and counters for example.
* Semaphores usually use a FIFO queuing strategy but it is possible * to make them order threads by priority by enabling - * @p CH_USE_SEMAPHORES_PRIORITY in @p chconf.h. - * @pre In order to use the semaphore APIs the @p CH_USE_SEMAPHORES + * @p CH_CFG_USE_SEMAPHORES_PRIORITY in @p chconf.h. + * @pre In order to use the semaphore APIs the @p CH_CFG_USE_SEMAPHORES * option must be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_SEMAPHORES || defined(__DOXYGEN__) +#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -77,7 +77,7 @@ /* Module local functions. */ /*===========================================================================*/ -#if CH_USE_SEMAPHORES_PRIORITY +#if CH_CFG_USE_SEMAPHORES_PRIORITY #define sem_insert(tp, qp) prio_insert(tp, qp) #else #define sem_insert(tp, qp) queue_insert(tp, qp) @@ -360,11 +360,8 @@ void chSemAddCounterI(semaphore_t *sp, cnt_t n) { } } -#if CH_USE_SEMSW /** * @brief Performs atomic signal and wait operations on two semaphores. - * @pre The configuration option @p CH_USE_SEMSW must be enabled in order - * to use this function. * * @param[in] sps pointer to a @p semaphore_t structure to be signaled * @param[in] spw pointer to a @p semaphore_t structure to wait on @@ -406,8 +403,7 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { chSysUnlock(); return msg; } -#endif /* CH_USE_SEMSW */ -#endif /* CH_USE_SEMAPHORES */ +#endif /* CH_CFG_USE_SEMAPHORES */ /** @} */ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index b3d99a7d9..97f01f933 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -47,18 +47,18 @@ /* Module local variables. */ /*===========================================================================*/ -#if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) +#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief Idle thread working area. */ static WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); -#endif /* CH_NO_IDLE_THREAD */ +#endif /* CH_CFG_NO_IDLE_THREAD */ /*===========================================================================*/ /* Module local functions. */ /*===========================================================================*/ -#if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) +#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief This function implements the idle thread infinite loop. * @details The function puts the processor in the lowest power mode capable @@ -75,10 +75,10 @@ static void _idle_thread(void *p) { chRegSetThreadName("idle"); while (true) { port_wait_for_interrupt(); - IDLE_LOOP_HOOK(); + CH_CFG_IDLE_LOOP_HOOK(); } } -#endif /* CH_NO_IDLE_THREAD */ +#endif /* CH_CFG_NO_IDLE_THREAD */ /*===========================================================================*/ /* Module exported functions. */ @@ -105,10 +105,10 @@ void chSysInit(void) { port_init(); _scheduler_init(); _vt_init(); -#if CH_USE_MEMCORE +#if CH_CFG_USE_MEMCORE _core_init(); #endif -#if CH_USE_HEAP +#if CH_CFG_USE_HEAP _heap_init(); #endif #if CH_DBG_ENABLE_TRACE @@ -129,7 +129,7 @@ void chSysInit(void) { active, else the parameter is ignored.*/ chRegSetThreadName((const char *)&ch_debug); -#if !CH_NO_IDLE_THREAD +#if !CH_CFG_NO_IDLE_THREAD /* This thread has the lowest priority in the system, its role is just to serve interrupts in its context while keeping the lowest energy saving mode compatible with the system status.*/ @@ -152,8 +152,8 @@ void chSysHalt(void) { chSysDisable(); -#if defined(SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) - SYSTEM_HALT_HOOK(); +#if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) + CH_CFG_SYSTEM_HALT_HOOK(); #endif /* Harmless infinite loop.*/ @@ -167,7 +167,7 @@ void chSysHalt(void) { * and preempts it when the quantum is used up. Increments system * time and manages the timers. * @note The frequency of the timer determines the system tick granularity - * and, together with the @p CH_TIME_QUANTUM macro, the round robin + * and, together with the @p CH_CFG_TIME_QUANTUM macro, the round robin * interval. * * @iclass @@ -176,7 +176,7 @@ void chSysTimerHandlerI(void) { chDbgCheckClassI(); -#if CH_TIME_QUANTUM > 0 +#if CH_CFG_TIME_QUANTUM > 0 /* Running thread has not used up quantum yet? */ if (currp->p_preempt > 0) /* Decrement remaining quantum.*/ @@ -186,8 +186,8 @@ void chSysTimerHandlerI(void) { currp->p_time++; #endif chVTDoTickI(); -#if defined(SYSTEM_TICK_EVENT_HOOK) - SYSTEM_TICK_EVENT_HOOK(); +#if defined(CH_CFG_SYSTEM_TICK_HOOK) + CH_CFG_SYSTEM_TICK_HOOK(); #endif } diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 47f53e10d..17eeb763b 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -49,7 +49,7 @@ * . * The threads subsystem is implicitly included in kernel however * some of its part may be excluded by disabling them in @p chconf.h, - * see the @p CH_USE_WAITEXIT and @p CH_USE_DYNAMIC configuration + * see the @p CH_CFG_USE_WAITEXIT and @p CH_CFG_USE_DYNAMIC configuration * options. * @{ */ @@ -95,37 +95,37 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_prio = prio; tp->p_state = THD_STATE_SUSPENDED; tp->p_flags = THD_MEM_MODE_STATIC; -#if CH_TIME_QUANTUM > 0 - tp->p_preempt = CH_TIME_QUANTUM; +#if CH_CFG_TIME_QUANTUM > 0 + tp->p_preempt = CH_CFG_TIME_QUANTUM; #endif -#if CH_USE_MUTEXES +#if CH_CFG_USE_MUTEXES tp->p_realprio = prio; tp->p_mtxlist = NULL; #endif -#if CH_USE_EVENTS +#if CH_CFG_USE_EVENTS tp->p_epending = 0; #endif #if CH_DBG_THREADS_PROFILING tp->p_time = 0; #endif -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC tp->p_refs = 1; #endif -#if CH_USE_REGISTRY +#if CH_CFG_USE_REGISTRY tp->p_name = NULL; REG_INSERT(tp); #endif -#if CH_USE_WAITEXIT +#if CH_CFG_USE_WAITEXIT list_init(&tp->p_waiting); #endif -#if CH_USE_MESSAGES +#if CH_CFG_USE_MESSAGES queue_init(&tp->p_msgqueue); #endif #if CH_DBG_ENABLE_STACK_CHECK tp->p_stklimit = (stkalign_t *)(tp + 1); #endif -#if defined(THREAD_EXT_INIT_HOOK) - THREAD_EXT_INIT_HOOK(tp); +#if defined(CH_CFG_THREAD_INIT_HOOK) + CH_CFG_THREAD_INIT_HOOK(tp); #endif return tp; } @@ -238,7 +238,7 @@ tprio_t chThdSetPriority(tprio_t newprio) { chDbgCheck(newprio <= HIGHPRIO, "chThdSetPriority"); chSysLock(); -#if CH_USE_MUTEXES +#if CH_CFG_USE_MUTEXES oldprio = currp->p_realprio; if ((currp->p_prio == currp->p_realprio) || (newprio > currp->p_prio)) currp->p_prio = newprio; @@ -385,14 +385,14 @@ void chThdExitS(msg_t msg) { thread_t *tp = currp; tp->p_u.exitcode = msg; -#if defined(THREAD_EXT_EXIT_HOOK) - THREAD_EXT_EXIT_HOOK(tp); +#if defined(CH_CFG_THREAD_EXIT_HOOK) + CH_CFG_THREAD_EXIT_HOOK(tp); #endif -#if CH_USE_WAITEXIT +#if CH_CFG_USE_WAITEXIT while (list_notempty(&tp->p_waiting)) chSchReadyI(list_remove(&tp->p_waiting)); #endif -#if CH_USE_REGISTRY +#if CH_CFG_USE_REGISTRY /* Static threads are immediately removed from the registry because there is no memory to recover.*/ if ((tp->p_flags & THD_MEM_MODE_MASK) == THD_MEM_MODE_STATIC) @@ -403,7 +403,7 @@ void chThdExitS(msg_t msg) { chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); } -#if CH_USE_WAITEXIT || defined(__DOXYGEN__) +#if CH_CFG_USE_WAITEXIT || defined(__DOXYGEN__) /** * @brief Blocks the execution of the invoking thread until the specified * thread terminates then the exit code is returned. @@ -421,13 +421,13 @@ void chThdExitS(msg_t msg) { * - If the thread was spawned by @p chThdCreateFromMemoryPool() * then the working area is returned to the owning memory pool. * . - * @pre The configuration option @p CH_USE_WAITEXIT must be enabled in + * @pre The configuration option @p CH_CFG_USE_WAITEXIT must be enabled in * order to use this function. * @post Enabling @p chThdWait() requires 2-4 (depending on the * architecture) extra bytes in the @p thread_t structure. * @post After invoking @p chThdWait() the thread pointer becomes invalid * and must not be used as parameter for further system calls. - * @note If @p CH_USE_DYNAMIC is not specified this function just waits for + * @note If @p CH_CFG_USE_DYNAMIC is not specified this function just waits for * the thread termination, no memory allocators are involved. * * @param[in] tp pointer to the thread @@ -442,7 +442,7 @@ msg_t chThdWait(thread_t *tp) { chSysLock(); chDbgAssert(tp != currp, "chThdWait(), #1", "waiting self"); -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced"); #endif if (tp->p_state != THD_STATE_FINAL) { @@ -451,11 +451,11 @@ msg_t chThdWait(thread_t *tp) { } msg = tp->p_u.exitcode; chSysUnlock(); -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC chThdRelease(tp); #endif return msg; } -#endif /* CH_USE_WAITEXIT */ +#endif /* CH_CFG_USE_WAITEXIT */ /** @} */ -- cgit v1.2.3 From 6a24f95f53578a4605480de03e5c68106611eefc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Jul 2013 13:33:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6021 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chvt.c | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 9 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index 3bccd1ac8..c03d442fc 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -67,8 +67,12 @@ virtual_timers_list_t vtlist; void _vt_init(void) { vtlist.vt_next = vtlist.vt_prev = (void *)&vtlist; - vtlist.vt_time = (systime_t)-1; + vtlist.vt_delta = (systime_t)-1; +#if CH_CFG_TIMEDELTA == 0 vtlist.vt_systime = 0; +#else /* CH_CFG_TIMEDELTA > 0 */ + vtlist.vt_lasttime = 0; +#endif /* CH_CFG_TIMEDELTA > 0 */ } /** @@ -125,16 +129,42 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, vtp->vt_par = par; vtp->vt_func = vtfunc; p = vtlist.vt_next; - while (p->vt_time < delay) { - delay -= p->vt_time; - p = p->vt_next; + +#if CH_CFG_TIMEDELTA > 0 || defined(__DOXYGEN__) + { + systime_t now = port_timer_get_time(); + + /* If the requested delay is lower than the minimum safe delta then it + is raised to the minimum safe value.*/ + if (delay < CH_CFG_TIMEDELTA) + delay = CH_CFG_TIMEDELTA; + + /* Now the delay is calculated as delta from the last tick interrupt + time.*/ + delay += now - vtlist.vt_lasttime; + + if (&vtlist != (virtual_timers_list_t *)p) + port_timer_start_alarm(vtlist.vt_lasttime + delay); + else if (delay < p->vt_delta) + port_timer_set_alarm(vtlist.vt_lasttime + delay); } +#endif /* CH_CFG_TIMEDELTA > 0 */ + /* The delta list is scanned in order to find the correct position for + this timer. */ + while (p->vt_delta < delay) { + delay -= p->vt_delta; + p = p->vt_next; + } + /* The timer is inserted in the delta list.*/ vtp->vt_prev = (vtp->vt_next = p)->vt_prev; vtp->vt_prev->vt_next = p->vt_prev = vtp; - vtp->vt_time = delay; - if (p != (void *)&vtlist) - p->vt_time -= delay; + vtp->vt_delta = delay + + /* Special case when the timer is in last position in the list, the + value in the header must be restored.*/; + p->vt_delta -= delay; + vtlist.vt_delta = (systime_t)-1; } /** @@ -153,11 +183,28 @@ void chVTDoResetI(virtual_timer_t *vtp) { "chVTDoResetI(), #1", "timer not set or already triggered"); - if (vtp->vt_next != (void *)&vtlist) - vtp->vt_next->vt_time += vtp->vt_time; + /* Removing the element from the delta list.*/ + vtp->vt_next->vt_delta += vtp->vt_delta; vtp->vt_prev->vt_next = vtp->vt_next; vtp->vt_next->vt_prev = vtp->vt_prev; vtp->vt_func = (vtfunc_t)NULL; + + /* The above code changes the value in the header when the removed element + is the last of the list, restoring it.*/ + vtlist.vt_delta = (systime_t)-1; + +#if CH_CFG_TIMEDELTA > 0 || defined(__DOXYGEN__) + { + if (&vtlist == (virtual_timers_list_t *)vtlist.vt_next) { + /* Just removed the last element in the list, alarm timer stopped.*/ + port_timer_stop_alarm(); + } + else { + /* The alarm is set to the next element in the delta list.*/ + port_timer_set_alarm(vtlist.vt_lasttime + vtlist.vt_next->vt_delta); + } + } +#endif /* CH_CFG_TIMEDELTA > 0 */ } /** @} */ -- cgit v1.2.3 From dbdf30d29078011cc71c746e7e3c1fbea90f56fa Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 22 Jul 2013 14:19:09 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6022 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chvt.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index c03d442fc..e5d6d1aa3 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -139,14 +139,22 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, if (delay < CH_CFG_TIMEDELTA) delay = CH_CFG_TIMEDELTA; - /* Now the delay is calculated as delta from the last tick interrupt - time.*/ - delay += now - vtlist.vt_lasttime; - - if (&vtlist != (virtual_timers_list_t *)p) + if (&vtlist == (virtual_timers_list_t *)p) { + /* The delta list is empty, the current time becomes the new + delta list base time.*/ + vtlist.vt_lasttime = now; port_timer_start_alarm(vtlist.vt_lasttime + delay); - else if (delay < p->vt_delta) - port_timer_set_alarm(vtlist.vt_lasttime + delay); + } + else { + /* Now the delay is calculated as delta from the last tick interrupt + time.*/ + delay += now - vtlist.vt_lasttime; + + /* If the specified delay is closer in time than the first element + in the delta list then it becomes the next alarm event in time.*/ + if (delay < p->vt_delta) + port_timer_set_alarm(vtlist.vt_lasttime + delay); + } } #endif /* CH_CFG_TIMEDELTA > 0 */ -- cgit v1.2.3 From 40f413d3c97a7694703938cd031ce15912b29ff7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 24 Jul 2013 14:54:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6025 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 4 ++-- os/kernel/src/chdynamic.c | 14 +++++++------- os/kernel/src/chevents.c | 16 ++++++++-------- os/kernel/src/chmsg.c | 10 +++++----- os/kernel/src/chmtx.c | 14 +++++++------- os/kernel/src/chqueues.c | 6 +++--- os/kernel/src/chschd.c | 30 +++++++++++++++--------------- os/kernel/src/chsem.c | 6 +++--- os/kernel/src/chsys.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- os/kernel/src/chthreads.c | 26 +++++++++++++------------- 10 files changed, 107 insertions(+), 64 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index 8486705e6..49e1f891e 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -212,7 +212,7 @@ msg_t chCondWaitS(condition_variable_t *cp) { mp = chMtxUnlockS(); ctp->p_u.wtobjp = cp; queue_prio_insert(ctp, &cp->c_queue); - chSchGoSleepS(THD_STATE_WTCOND); + chSchGoSleepS(CH_STATE_WTCOND); msg = ctp->p_u.rdymsg; chMtxLockS(mp); return msg; @@ -297,7 +297,7 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { mp = chMtxUnlockS(); currp->p_u.wtobjp = cp; queue_prio_insert(currp, &cp->c_queue); - msg = chSchGoSleepTimeoutS(THD_STATE_WTCOND, time); + msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, time); if (msg != RDY_TIMEOUT) chMtxLockS(mp); return msg; diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c index cab5556f3..2b12e698f 100644 --- a/os/kernel/src/chdynamic.c +++ b/os/kernel/src/chdynamic.c @@ -78,7 +78,7 @@ thread_t *chThdAddRef(thread_t *tp) { /** * @brief Releases a reference to a thread object. * @details If the references counter reaches zero and the thread - * is in the @p THD_STATE_FINAL state then the thread's memory is + * is in the @p CH_STATE_FINAL state then the thread's memory is * returned to the proper allocator. * @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in order * to use this function. @@ -99,10 +99,10 @@ void chThdRelease(thread_t *tp) { /* If the references counter reaches zero and the thread is in its terminated state then the memory can be returned to the proper allocator. Of course static threads are not affected.*/ - if ((refs == 0) && (tp->p_state == THD_STATE_FINAL)) { - switch (tp->p_flags & THD_MEM_MODE_MASK) { + if ((refs == 0) && (tp->p_state == CH_STATE_FINAL)) { + switch (tp->p_flags & CH_FLAG_MODE_MASK) { #if CH_CFG_USE_HEAP - case THD_MEM_MODE_HEAP: + case CH_FLAG_MODE_HEAP: #if CH_CFG_USE_REGISTRY REG_REMOVE(tp); #endif @@ -110,7 +110,7 @@ void chThdRelease(thread_t *tp) { break; #endif #if CH_CFG_USE_MEMPOOLS - case THD_MEM_MODE_MEMPOOL: + case CH_FLAG_MODE_MEMPOOL: #if CH_CFG_USE_REGISTRY REG_REMOVE(tp); #endif @@ -164,7 +164,7 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, chSysLock(); tp = chThdCreateI(wsp, size, prio, pf, arg); - tp->p_flags = THD_MEM_MODE_HEAP; + tp->p_flags = CH_FLAG_MODE_HEAP; chSchWakeupS(tp, RDY_OK); chSysUnlock(); return tp; @@ -215,7 +215,7 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, chSysLock(); tp = chThdCreateI(wsp, mp->mp_object_size, prio, pf, arg); - tp->p_flags = THD_MEM_MODE_MEMPOOL; + tp->p_flags = CH_FLAG_MODE_MEMPOOL; tp->p_mpool = mp; chSchWakeupS(tp, RDY_OK); chSysUnlock(); diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index f48a3ec9a..d95730f7c 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -275,9 +275,9 @@ void chEvtSignalI(thread_t *tp, eventmask_t mask) { tp->p_epending |= mask; /* Test on the AND/OR conditions wait states.*/ - if (((tp->p_state == THD_STATE_WTOREVT) && + if (((tp->p_state == CH_STATE_WTOREVT) && ((tp->p_epending & tp->p_u.ewmask) != 0)) || - ((tp->p_state == THD_STATE_WTANDEVT) && + ((tp->p_state == CH_STATE_WTANDEVT) && ((tp->p_epending & tp->p_u.ewmask) == tp->p_u.ewmask))) chSchReadyI(tp)->p_u.rdymsg = RDY_OK; } @@ -375,7 +375,7 @@ eventmask_t chEvtWaitOne(eventmask_t mask) { if ((m = (ctp->p_epending & mask)) == 0) { ctp->p_u.ewmask = mask; - chSchGoSleepS(THD_STATE_WTOREVT); + chSchGoSleepS(CH_STATE_WTOREVT); m = ctp->p_epending & mask; } m &= -m; @@ -404,7 +404,7 @@ eventmask_t chEvtWaitAny(eventmask_t mask) { if ((m = (ctp->p_epending & mask)) == 0) { ctp->p_u.ewmask = mask; - chSchGoSleepS(THD_STATE_WTOREVT); + chSchGoSleepS(CH_STATE_WTOREVT); m = ctp->p_epending & mask; } ctp->p_epending &= ~m; @@ -431,7 +431,7 @@ eventmask_t chEvtWaitAll(eventmask_t mask) { if ((ctp->p_epending & mask) != mask) { ctp->p_u.ewmask = mask; - chSchGoSleepS(THD_STATE_WTANDEVT); + chSchGoSleepS(CH_STATE_WTANDEVT); } ctp->p_epending &= ~mask; @@ -475,7 +475,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time) { return (eventmask_t)0; } ctp->p_u.ewmask = mask; - if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) { + if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < RDY_OK) { chSysUnlock(); return (eventmask_t)0; } @@ -518,7 +518,7 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time) { return (eventmask_t)0; } ctp->p_u.ewmask = mask; - if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) { + if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < RDY_OK) { chSysUnlock(); return (eventmask_t)0; } @@ -558,7 +558,7 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time) { return (eventmask_t)0; } ctp->p_u.ewmask = mask; - if (chSchGoSleepTimeoutS(THD_STATE_WTANDEVT, time) < RDY_OK) { + if (chSchGoSleepTimeoutS(CH_STATE_WTANDEVT, time) < RDY_OK) { chSysUnlock(); return (eventmask_t)0; } diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 535143b7c..1e99cce3f 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -94,9 +94,9 @@ msg_t chMsgSend(thread_t *tp, msg_t msg) { ctp->p_msg = msg; ctp->p_u.wtobjp = &tp->p_msgqueue; msg_insert(ctp, &tp->p_msgqueue); - if (tp->p_state == THD_STATE_WTMSG) + if (tp->p_state == CH_STATE_WTMSG) chSchReadyI(tp); - chSchGoSleepS(THD_STATE_SNDMSGQ); + chSchGoSleepS(CH_STATE_SNDMSGQ); msg = ctp->p_u.rdymsg; chSysUnlock(); return msg; @@ -121,9 +121,9 @@ thread_t *chMsgWait(void) { chSysLock(); if (!chMsgIsPendingI(currp)) - chSchGoSleepS(THD_STATE_WTMSG); + chSchGoSleepS(CH_STATE_WTMSG); tp = queue_fifo_remove(&currp->p_msgqueue); - tp->p_state = THD_STATE_SNDMSG; + tp->p_state = CH_STATE_SNDMSG; chSysUnlock(); return tp; } @@ -141,7 +141,7 @@ thread_t *chMsgWait(void) { void chMsgRelease(thread_t *tp, msg_t msg) { chSysLock(); - chDbgAssert(tp->p_state == THD_STATE_SNDMSG, + chDbgAssert(tp->p_state == CH_STATE_SNDMSG, "chMsgRelease(), #1", "invalid state"); chMsgReleaseS(tp, msg); chSysUnlock(); diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index be9c6dd78..5f7bdfb8d 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -152,7 +152,7 @@ void chMtxLockS(mutex_t *mp) { /* The following states need priority queues reordering.*/ switch (tp->p_state) { - case THD_STATE_WTMTX: + case CH_STATE_WTMTX: /* Re-enqueues the mutex owner with its new priority.*/ queue_prio_insert(queue_dequeue(tp), (threads_queue_t *)tp->p_u.wtobjp); @@ -162,23 +162,23 @@ void chMtxLockS(mutex_t *mp) { (CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY) | \ (CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY) #if CH_CFG_USE_CONDVARS - case THD_STATE_WTCOND: + case CH_STATE_WTCOND: #endif #if CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY - case THD_STATE_WTSEM: + case CH_STATE_WTSEM: #endif #if CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY - case THD_STATE_SNDMSGQ: + case CH_STATE_SNDMSGQ: #endif /* Re-enqueues tp with its new priority on the queue.*/ queue_prio_insert(queue_dequeue(tp), (threads_queue_t *)tp->p_u.wtobjp); break; #endif - case THD_STATE_READY: + case CH_STATE_READY: #if CH_DBG_ENABLE_ASSERTS /* Prevents an assertion in chSchReadyI().*/ - tp->p_state = THD_STATE_CURRENT; + tp->p_state = CH_STATE_CURRENT; #endif /* Re-enqueues tp with its new priority on the ready list.*/ chSchReadyI(queue_dequeue(tp)); @@ -190,7 +190,7 @@ void chMtxLockS(mutex_t *mp) { /* Sleep on the mutex.*/ queue_prio_insert(ctp, &mp->m_queue); ctp->p_u.wtobjp = mp; - chSchGoSleepS(THD_STATE_WTMTX); + chSchGoSleepS(CH_STATE_WTMTX); /* It is assumed that the thread performing the unlock operation assigns the mutex to this thread.*/ diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index fcaa2895f..f7e587228 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -66,7 +66,7 @@ static msg_t qwait(GenericQueue *qp, systime_t time) { return Q_TIMEOUT; currp->p_u.wtobjp = qp; queue_insert(currp, &qp->q_waiting); - return chSchGoSleepTimeoutS(THD_STATE_WTQUEUE, time); + return chSchGoSleepTimeoutS(CH_STATE_WTQUEUE, time); } /** @@ -154,7 +154,7 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) { * is empty then the calling thread is suspended until a byte arrives * in the queue or a timeout occurs. * @note The callback is invoked before reading the character from the - * buffer or before entering the state @p THD_STATE_WTQUEUE. + * buffer or before entering the state @p CH_STATE_WTQUEUE. * * @param[in] iqp pointer to an @p InputQueue structure * @param[in] time the number of ticks before the operation timeouts, @@ -201,7 +201,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) { * @note The function is not atomic, if you need atomicity it is suggested * to use a semaphore or a mutex for mutual exclusion. * @note The callback is invoked before reading each character from the - * buffer or before entering the state @p THD_STATE_WTQUEUE. + * buffer or before entering the state @p CH_STATE_WTQUEUE. * * @param[in] iqp pointer to an @p InputQueue structure * @param[out] bp pointer to the data buffer diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index c360777ef..db0097108 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -94,12 +94,12 @@ thread_t *chSchReadyI(thread_t *tp) { chDbgCheckClassI(); /* Integrity checks.*/ - chDbgAssert((tp->p_state != THD_STATE_READY) && - (tp->p_state != THD_STATE_FINAL), + chDbgAssert((tp->p_state != CH_STATE_READY) && + (tp->p_state != CH_STATE_FINAL), "chSchReadyI(), #1", "invalid state"); - tp->p_state = THD_STATE_READY; + tp->p_state = CH_STATE_READY; cp = (thread_t *)&rlist.r_queue; do { cp = cp->p_next; @@ -132,7 +132,7 @@ void chSchGoSleepS(tstate_t newstate) { otp->p_preempt = CH_CFG_TIME_QUANTUM; #endif setcurrp(queue_fifo_remove(&rlist.r_queue)); - currp->p_state = THD_STATE_CURRENT; + currp->p_state = CH_STATE_CURRENT; chSysSwitch(currp, otp); } @@ -142,25 +142,25 @@ void chSchGoSleepS(tstate_t newstate) { static void wakeup(void *p) { thread_t *tp = (thread_t *)p; - chSysLockFromIsr(); + chSysLockFromISR(); switch (tp->p_state) { - case THD_STATE_READY: + case CH_STATE_READY: /* Handling the special case where the thread has been made ready by another thread with higher priority.*/ - chSysUnlockFromIsr(); + chSysUnlockFromISR(); return; #if CH_CFG_USE_SEMAPHORES || CH_CFG_USE_QUEUES || \ (CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT) #if CH_CFG_USE_SEMAPHORES - case THD_STATE_WTSEM: + case CH_STATE_WTSEM: chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp); /* Falls into, intentional. */ #endif #if CH_CFG_USE_QUEUES - case THD_STATE_WTQUEUE: + case CH_STATE_WTQUEUE: #endif #if CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT - case THD_STATE_WTCOND: + case CH_STATE_WTCOND: #endif /* States requiring dequeuing.*/ queue_dequeue(tp); @@ -168,7 +168,7 @@ static void wakeup(void *p) { } tp->p_u.rdymsg = RDY_TIMEOUT; chSchReadyI(tp); - chSysUnlockFromIsr(); + chSysUnlockFromISR(); } /** @@ -240,7 +240,7 @@ void chSchWakeupS(thread_t *ntp, msg_t msg) { else { thread_t *otp = chSchReadyI(currp); setcurrp(ntp); - ntp->p_state = THD_STATE_CURRENT; + ntp->p_state = CH_STATE_CURRENT; chSysSwitch(ntp, otp); } } @@ -305,7 +305,7 @@ void chSchDoRescheduleBehind(void) { otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ setcurrp(queue_fifo_remove(&rlist.r_queue)); - currp->p_state = THD_STATE_CURRENT; + currp->p_state = CH_STATE_CURRENT; #if CH_CFG_TIME_QUANTUM > 0 otp->p_preempt = CH_CFG_TIME_QUANTUM; #endif @@ -328,9 +328,9 @@ void chSchDoRescheduleAhead(void) { otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ setcurrp(queue_fifo_remove(&rlist.r_queue)); - currp->p_state = THD_STATE_CURRENT; + currp->p_state = CH_STATE_CURRENT; - otp->p_state = THD_STATE_READY; + otp->p_state = CH_STATE_READY; cp = (thread_t *)&rlist.r_queue; do { cp = cp->p_next; diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index bcf222230..d25b93822 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -207,7 +207,7 @@ msg_t chSemWaitS(semaphore_t *sp) { if (--sp->s_cnt < 0) { currp->p_u.wtobjp = sp; sem_insert(currp, &sp->s_queue); - chSchGoSleepS(THD_STATE_WTSEM); + chSchGoSleepS(CH_STATE_WTSEM); return currp->p_u.rdymsg; } return RDY_OK; @@ -276,7 +276,7 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { } currp->p_u.wtobjp = sp; sem_insert(currp, &sp->s_queue); - return chSchGoSleepTimeoutS(THD_STATE_WTSEM, time); + return chSchGoSleepTimeoutS(CH_STATE_WTSEM, time); } return RDY_OK; } @@ -393,7 +393,7 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { thread_t *ctp = currp; sem_insert(ctp, &spw->s_queue); ctp->p_u.wtobjp = spw; - chSchGoSleepS(THD_STATE_WTSEM); + chSchGoSleepS(CH_STATE_WTSEM); msg = ctp->p_u.rdymsg; } else { diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 97f01f933..61157b1b9 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -117,7 +117,7 @@ void chSysInit(void) { /* Now this instructions flow becomes the main thread.*/ setcurrp(_thread_init(&mainthread, NORMALPRIO)); - currp->p_state = THD_STATE_CURRENT; + currp->p_state = CH_STATE_CURRENT; #if CH_DBG_ENABLE_STACK_CHECK /* This is a special case because the main thread thread_t structure is not adjacent to its stack area.*/ @@ -191,4 +191,47 @@ void chSysTimerHandlerI(void) { #endif } + +/** + * @brief Returns the execution context and enters the kernel lock mode. + * @details This functions enters into a critical zone and can be called + * from any context. Because its flexibility it is less efficient + * than @p chSysLock() which is preferable when the calling context + * is known. + * + * @return The previous system status, the encoding of this + * status word is architecture-dependent but zero is + * assumed to mean not-locked. + * + * @special + */ +syssts_t chSysGetAndLockX(void) { + + syssts_t sts = port_get_status(); + if (!sts) { + if (port_get_context()) + chSysLockFromISR(); + else + chSysLock(); + } + return sts; +} + +/** + * @brief Restores the specified execution status. + * + * @param[in] sts the system status to be restored. + * + * @special + */ +void chSysRestoreLockX(syssts_t sts) { + + if (!sts) { + if (port_get_context()) + chSysUnlockFromISR(); + else + chSysUnlock(); + } +} + /** @} */ diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 17eeb763b..9017a59b7 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -93,8 +93,8 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_prio = prio; - tp->p_state = THD_STATE_SUSPENDED; - tp->p_flags = THD_MEM_MODE_STATIC; + tp->p_state = CH_STATE_SUSPENDED; + tp->p_flags = CH_FLAG_MODE_STATIC; #if CH_CFG_TIME_QUANTUM > 0 tp->p_preempt = CH_CFG_TIME_QUANTUM; #endif @@ -150,7 +150,7 @@ void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { /** * @brief Creates a new thread into a static memory area. * @details The new thread is initialized but not inserted in the ready list, - * the initial state is @p THD_STATE_SUSPENDED. + * the initial state is @p CH_STATE_SUSPENDED. * @post The initialized thread can be subsequently started by invoking * @p chThdResume(), @p chThdResumeI() or @p chSchWakeupS() * depending on the execution context. @@ -255,7 +255,7 @@ tprio_t chThdSetPriority(tprio_t newprio) { /** * @brief Resumes a suspended thread. * @pre The specified thread pointer must refer to an initialized thread - * in the @p THD_STATE_SUSPENDED state. + * in the @p CH_STATE_SUSPENDED state. * @post The specified thread is immediately started or put in the ready * list depending on the relative priority levels. * @note Use this function to start threads created with @p chThdCreateI(). @@ -268,9 +268,9 @@ tprio_t chThdSetPriority(tprio_t newprio) { thread_t *chThdResume(thread_t *tp) { chSysLock(); - chDbgAssert(tp->p_state == THD_STATE_SUSPENDED, + chDbgAssert(tp->p_state == CH_STATE_SUSPENDED, "chThdResume(), #1", - "thread not in THD_STATE_SUSPENDED state"); + "thread not in CH_STATE_SUSPENDED state"); chSchWakeupS(tp, RDY_OK); chSysUnlock(); return tp; @@ -291,7 +291,7 @@ thread_t *chThdResume(thread_t *tp) { void chThdTerminate(thread_t *tp) { chSysLock(); - tp->p_flags |= THD_TERMINATE; + tp->p_flags |= CH_FLAG_TERMINATE; chSysUnlock(); } @@ -348,7 +348,7 @@ void chThdYield(void) { /** * @brief Terminates the current thread. - * @details The thread goes in the @p THD_STATE_FINAL state holding the + * @details The thread goes in the @p CH_STATE_FINAL state holding the * specified exit status code, other threads can retrieve the * exit status code by invoking the function @p chThdWait(). * @post Eventual code after this function will never be executed, @@ -369,7 +369,7 @@ void chThdExit(msg_t msg) { /** * @brief Terminates the current thread. - * @details The thread goes in the @p THD_STATE_FINAL state holding the + * @details The thread goes in the @p CH_STATE_FINAL state holding the * specified exit status code, other threads can retrieve the * exit status code by invoking the function @p chThdWait(). * @post Eventual code after this function will never be executed, @@ -395,10 +395,10 @@ void chThdExitS(msg_t msg) { #if CH_CFG_USE_REGISTRY /* Static threads are immediately removed from the registry because there is no memory to recover.*/ - if ((tp->p_flags & THD_MEM_MODE_MASK) == THD_MEM_MODE_STATIC) + if ((tp->p_flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) REG_REMOVE(tp); #endif - chSchGoSleepS(THD_STATE_FINAL); + chSchGoSleepS(CH_STATE_FINAL); /* The thread never returns here.*/ chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); } @@ -445,9 +445,9 @@ msg_t chThdWait(thread_t *tp) { #if CH_CFG_USE_DYNAMIC chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced"); #endif - if (tp->p_state != THD_STATE_FINAL) { + if (tp->p_state != CH_STATE_FINAL) { list_insert(currp, &tp->p_waiting); - chSchGoSleepS(THD_STATE_WTEXIT); + chSchGoSleepS(CH_STATE_WTEXIT); } msg = tp->p_u.exitcode; chSysUnlock(); -- cgit v1.2.3 From b21e9a01e5590dd3fe015aeffbe2a15e985af865 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 24 Jul 2013 15:38:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6027 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 61157b1b9..7a6d3ea20 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -115,8 +115,14 @@ void chSysInit(void) { _trace_init(); #endif +#if !CH_CFG_NO_IDLE_THREAD /* Now this instructions flow becomes the main thread.*/ setcurrp(_thread_init(&mainthread, NORMALPRIO)); +#else + /* Now this instructions flow becomes the main thread.*/ + setcurrp(_thread_init(&mainthread, IDLEPRIO)); +#endif + currp->p_state = CH_STATE_CURRENT; #if CH_DBG_ENABLE_STACK_CHECK /* This is a special case because the main thread thread_t structure is not -- cgit v1.2.3 From 0ca0bc18f97a40b9637f225a114f740b30db5cc1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 25 Jul 2013 12:40:58 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6028 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 7a6d3ea20..4a67c7042 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -206,16 +206,15 @@ void chSysTimerHandlerI(void) { * is known. * * @return The previous system status, the encoding of this - * status word is architecture-dependent but zero is - * assumed to mean not-locked. + * status word is architecture-dependent and opaque. * * @special */ syssts_t chSysGetAndLockX(void) { - syssts_t sts = port_get_status(); - if (!sts) { - if (port_get_context()) + syssts_t sts = port_get_irq_status(); + if (port_irq_enabled(sts)) { + if (port_is_isr_context()) chSysLockFromISR(); else chSysLock(); @@ -232,8 +231,8 @@ syssts_t chSysGetAndLockX(void) { */ void chSysRestoreLockX(syssts_t sts) { - if (!sts) { - if (port_get_context()) + if (port_irq_enabled(sts)) { + if (port_is_isr_context()) chSysUnlockFromISR(); else chSysUnlock(); -- cgit v1.2.3 From 0cb6bc9b9d260beb05fcc9e2ec4d72f0ba621b71 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 28 Jul 2013 12:15:57 +0000 Subject: RT measurements unit added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6036 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chrt.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++ os/kernel/src/chsys.c | 3 + os/kernel/src/chthreads.c | 2 +- 3 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 os/kernel/src/chrt.c (limited to 'os/kernel/src') diff --git a/os/kernel/src/chrt.c b/os/kernel/src/chrt.c new file mode 100644 index 000000000..a63ce9e32 --- /dev/null +++ b/os/kernel/src/chrt.c @@ -0,0 +1,206 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012,2013 Giovanni Di Sirio. + + 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 . +*/ + +/** + * @file chvt.c + * @brief Real Time Counter and Measurement module code. + * + * @addtogroup realtime_counter + * @details Realtime Counter APIs and services. + * + *

Operation mode

+ * The realtime counter is a fast HW counter that counts upward at + * regular intervals. This counted can be used for small and accurate + * delays, time stamp and time measurement. + * + *

Notes

+ * On those architectures where such a counter is not implemented + * the system time counter is used instead. Of course the system + * time counter usually has a much lower resolution than a real + * HW counter. + * @{ + */ + +#include "ch.h" + +#if CH_CFG_USE_RT || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/** + * @brief Subsystem calibration value. + */ +static rtcnt_t measurement_offset; + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +/** + * @brief Initializes the realtime counter unit. + * + * @init + */ +void _rt_init(void) { + time_measurement_t tm; + + /* Time Measurement subsystem calibration, it does a null measurement + and calculates the call overhead which is subtracted to real + measurements.*/ + measurement_offset = 0; + chRTTimeMeasurementObjectInit(&tm); + chRTTimeMeasurementStartX(&tm); + chRTTimeMeasurementStopX(&tm); + measurement_offset = tm.last; +} + +/** + * @brief Realtime window test. + * @details This function verifies if the current realtime counter value + * lies within the specified range or not. The test takes care + * of the realtime counter wrapping to zero on overflow. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * @note This function can be called from any context. + * + * @par Example 1 + * Example of a guarded loop using the realtime counter. The loop implements + * a timeout after one second. + * @code + * rtcnt_t start = chRTGetCounterValue(); + * rtcnt_t timeout = start + S2RTC(RTCCLK, 1); + * while (my_condition) { + * if (!chRTIsCounterWithin(start, timeout) + * return TIMEOUT; + * // Do something. + * } + * // Continue. + * @endcode + * + * @par Example 2 + * Example of a loop that lasts exactly 50 microseconds. + * @code + * rtcnt_t start = chRTGetCounterValue(); + * rtcnt_t timeout = start + US2RTC(RTCCLK, 50); + * while (chRTIsCounterWithin(start, timeout)) { + * // Do something. + * } + * // Continue. + * @endcode + * + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval true current time within the specified time window. + * @retval false current time not within the specified time window. + * + * @special + */ +bool chRTIsCounterWithin(rtcnt_t start, rtcnt_t end) { + rtcnt_t now = chRTGetCounterValueX(); + + return end > start ? (now >= start) && (now < end) : + (now >= start) || (now < end); +} + +/** + * @brief Polled delay. + * @note The real delay is always few cycles in excess of the specified + * value. + * @note This function can be called from any context. + * + * @param[in] cycles number of cycles + * + * @special + */ +void chRTPolledDelay(rtcnt_t cycles) { + rtcnt_t start = chRTGetCounterValueX(); + rtcnt_t end = start + cycles; + while (chRTIsCounterWithin(start, end)) + ; +} + +/** + * @brief Initializes a @p TimeMeasurement object. + * + * @param[out] tmp pointer to a @p TimeMeasurement structure + * + * @init + */ +void chRTTimeMeasurementObjectInit(time_measurement_t *tmp) { + + tmp->last = (rtcnt_t)0; + tmp->worst = (rtcnt_t)0; + tmp->best = (rtcnt_t)-1; +} + +/** + * @brief Starts a measurement. + * @pre The @p time_measurement_t structure must be initialized. + * @note This function can be invoked from any context. + * + * @param[in,out] tmp pointer to a @p TimeMeasurement structure + * + * @special + */ +NOINLINE void chRTTimeMeasurementStartX(time_measurement_t *tmp) { + + tmp->last = chRTGetCounterValueX(); +} + +/** + * @brief Stops a measurement. + * @pre The @p time_measurement_t structure must be initialized. + * @note This function can be invoked from any context. + * + * @param[in,out] tmp pointer to a @p time_measurement_t structure + * + * @special + */ +NOINLINE void chRTTimeMeasurementStopX(time_measurement_t *tmp) { + + rtcnt_t now = chRTGetCounterValueX(); + tmp->last = now - tmp->last - measurement_offset; + if (tmp->last > tmp->worst) + tmp->worst = tmp->last; + else if (tmp->last < tmp->best) + tmp->best = tmp->last; +} + +#endif /* CH_CFG_USE_RT */ + +/** @} */ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 4a67c7042..91277dc60 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -105,6 +105,9 @@ void chSysInit(void) { port_init(); _scheduler_init(); _vt_init(); +#if CH_CFG_USE_RT + _rt_init(); +#endif #if CH_CFG_USE_MEMCORE _core_init(); #endif diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 9017a59b7..b707b4562 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -327,7 +327,7 @@ void chThdSleep(systime_t time) { void chThdSleepUntil(systime_t time) { chSysLock(); - if ((time -= chVTGetSystemTimeI()) > 0) + if ((time -= chVTGetSystemTimeX()) > 0) chThdSleepS(time); chSysUnlock(); } -- cgit v1.2.3 From 61f841306aaa11b1471db1deb00470ea48f646fd Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 29 Jul 2013 13:28:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6037 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chrt.c | 16 +++++++++------- os/kernel/src/chsys.c | 4 ++-- os/kernel/src/chvt.c | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chrt.c b/os/kernel/src/chrt.c index a63ce9e32..0a477de39 100644 --- a/os/kernel/src/chrt.c +++ b/os/kernel/src/chrt.c @@ -131,7 +131,7 @@ void _rt_init(void) { * @special */ bool chRTIsCounterWithin(rtcnt_t start, rtcnt_t end) { - rtcnt_t now = chRTGetCounterValueX(); + rtcnt_t now = chSysGetRealtimeCounterX(); return end > start ? (now >= start) && (now < end) : (now >= start) || (now < end); @@ -148,7 +148,7 @@ bool chRTIsCounterWithin(rtcnt_t start, rtcnt_t end) { * @special */ void chRTPolledDelay(rtcnt_t cycles) { - rtcnt_t start = chRTGetCounterValueX(); + rtcnt_t start = chSysGetRealtimeCounterX(); rtcnt_t end = start + cycles; while (chRTIsCounterWithin(start, end)) ; @@ -163,9 +163,10 @@ void chRTPolledDelay(rtcnt_t cycles) { */ void chRTTimeMeasurementObjectInit(time_measurement_t *tmp) { - tmp->last = (rtcnt_t)0; - tmp->worst = (rtcnt_t)0; - tmp->best = (rtcnt_t)-1; + tmp->best = (rtcnt_t)-1; + tmp->worst = (rtcnt_t)0; + tmp->cumulative = (rtcnt_t)0; + tmp->last = (rtcnt_t)0; } /** @@ -179,7 +180,7 @@ void chRTTimeMeasurementObjectInit(time_measurement_t *tmp) { */ NOINLINE void chRTTimeMeasurementStartX(time_measurement_t *tmp) { - tmp->last = chRTGetCounterValueX(); + tmp->last = chSysGetRealtimeCounterX(); } /** @@ -193,8 +194,9 @@ NOINLINE void chRTTimeMeasurementStartX(time_measurement_t *tmp) { */ NOINLINE void chRTTimeMeasurementStopX(time_measurement_t *tmp) { - rtcnt_t now = chRTGetCounterValueX(); + rtcnt_t now = chSysGetRealtimeCounterX(); tmp->last = now - tmp->last - measurement_offset; + tmp->cumulative += tmp->last; if (tmp->last > tmp->worst) tmp->worst = tmp->last; else if (tmp->last < tmp->best) diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 91277dc60..91761b66b 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -211,7 +211,7 @@ void chSysTimerHandlerI(void) { * @return The previous system status, the encoding of this * status word is architecture-dependent and opaque. * - * @special + * @xclass */ syssts_t chSysGetAndLockX(void) { @@ -230,7 +230,7 @@ syssts_t chSysGetAndLockX(void) { * * @param[in] sts the system status to be restored. * - * @special + * @xclass */ void chSysRestoreLockX(syssts_t sts) { diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index e5d6d1aa3..3e6028f9c 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -88,9 +88,9 @@ void _vt_init(void) { * @retval true current time within the specified time window. * @retval false current time not within the specified time window. * - * @special + * @xclass */ -bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) { +bool chVTIsTimeWithinX(systime_t time, systime_t start, systime_t end) { return end > start ? (time >= start) && (time < end) : (time >= start) || (time < end); -- cgit v1.2.3 From 1ae1099ef072fd5fa5d1fde1e73c8c1df8d8d2f4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 29 Jul 2013 13:36:19 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6038 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chrt.c | 208 ------------------------------------------------ os/kernel/src/chstats.c | 65 +++++++++++++++ os/kernel/src/chtm.c | 197 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+), 208 deletions(-) delete mode 100644 os/kernel/src/chrt.c create mode 100644 os/kernel/src/chstats.c create mode 100644 os/kernel/src/chtm.c (limited to 'os/kernel/src') diff --git a/os/kernel/src/chrt.c b/os/kernel/src/chrt.c deleted file mode 100644 index 0a477de39..000000000 --- a/os/kernel/src/chrt.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chvt.c - * @brief Real Time Counter and Measurement module code. - * - * @addtogroup realtime_counter - * @details Realtime Counter APIs and services. - * - *

Operation mode

- * The realtime counter is a fast HW counter that counts upward at - * regular intervals. This counted can be used for small and accurate - * delays, time stamp and time measurement. - * - *

Notes

- * On those architectures where such a counter is not implemented - * the system time counter is used instead. Of course the system - * time counter usually has a much lower resolution than a real - * HW counter. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_RT || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/** - * @brief Subsystem calibration value. - */ -static rtcnt_t measurement_offset; - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes the realtime counter unit. - * - * @init - */ -void _rt_init(void) { - time_measurement_t tm; - - /* Time Measurement subsystem calibration, it does a null measurement - and calculates the call overhead which is subtracted to real - measurements.*/ - measurement_offset = 0; - chRTTimeMeasurementObjectInit(&tm); - chRTTimeMeasurementStartX(&tm); - chRTTimeMeasurementStopX(&tm); - measurement_offset = tm.last; -} - -/** - * @brief Realtime window test. - * @details This function verifies if the current realtime counter value - * lies within the specified range or not. The test takes care - * of the realtime counter wrapping to zero on overflow. - * @note When start==end then the function returns always true because the - * whole time range is specified. - * @note This function can be called from any context. - * - * @par Example 1 - * Example of a guarded loop using the realtime counter. The loop implements - * a timeout after one second. - * @code - * rtcnt_t start = chRTGetCounterValue(); - * rtcnt_t timeout = start + S2RTC(RTCCLK, 1); - * while (my_condition) { - * if (!chRTIsCounterWithin(start, timeout) - * return TIMEOUT; - * // Do something. - * } - * // Continue. - * @endcode - * - * @par Example 2 - * Example of a loop that lasts exactly 50 microseconds. - * @code - * rtcnt_t start = chRTGetCounterValue(); - * rtcnt_t timeout = start + US2RTC(RTCCLK, 50); - * while (chRTIsCounterWithin(start, timeout)) { - * // Do something. - * } - * // Continue. - * @endcode - * - * @param[in] start the start of the time window (inclusive) - * @param[in] end the end of the time window (non inclusive) - * @retval true current time within the specified time window. - * @retval false current time not within the specified time window. - * - * @special - */ -bool chRTIsCounterWithin(rtcnt_t start, rtcnt_t end) { - rtcnt_t now = chSysGetRealtimeCounterX(); - - return end > start ? (now >= start) && (now < end) : - (now >= start) || (now < end); -} - -/** - * @brief Polled delay. - * @note The real delay is always few cycles in excess of the specified - * value. - * @note This function can be called from any context. - * - * @param[in] cycles number of cycles - * - * @special - */ -void chRTPolledDelay(rtcnt_t cycles) { - rtcnt_t start = chSysGetRealtimeCounterX(); - rtcnt_t end = start + cycles; - while (chRTIsCounterWithin(start, end)) - ; -} - -/** - * @brief Initializes a @p TimeMeasurement object. - * - * @param[out] tmp pointer to a @p TimeMeasurement structure - * - * @init - */ -void chRTTimeMeasurementObjectInit(time_measurement_t *tmp) { - - tmp->best = (rtcnt_t)-1; - tmp->worst = (rtcnt_t)0; - tmp->cumulative = (rtcnt_t)0; - tmp->last = (rtcnt_t)0; -} - -/** - * @brief Starts a measurement. - * @pre The @p time_measurement_t structure must be initialized. - * @note This function can be invoked from any context. - * - * @param[in,out] tmp pointer to a @p TimeMeasurement structure - * - * @special - */ -NOINLINE void chRTTimeMeasurementStartX(time_measurement_t *tmp) { - - tmp->last = chSysGetRealtimeCounterX(); -} - -/** - * @brief Stops a measurement. - * @pre The @p time_measurement_t structure must be initialized. - * @note This function can be invoked from any context. - * - * @param[in,out] tmp pointer to a @p time_measurement_t structure - * - * @special - */ -NOINLINE void chRTTimeMeasurementStopX(time_measurement_t *tmp) { - - rtcnt_t now = chSysGetRealtimeCounterX(); - tmp->last = now - tmp->last - measurement_offset; - tmp->cumulative += tmp->last; - if (tmp->last > tmp->worst) - tmp->worst = tmp->last; - else if (tmp->last < tmp->best) - tmp->best = tmp->last; -} - -#endif /* CH_CFG_USE_RT */ - -/** @} */ diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c new file mode 100644 index 000000000..1decf8f16 --- /dev/null +++ b/os/kernel/src/chstats.c @@ -0,0 +1,65 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012,2013 Giovanni Di Sirio. + + 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 . +*/ + +/** + * @file chstats.c + * @brief Real Time Counter and Measurement module code. + * + * @addtogroup realtime_counter + * @details Statistics services. + * @{ + */ + +#include "ch.h" + +#if CH_DBG_STATISTICS || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/** + * @brief Global kernel statistics. + */ +kernel_stats_t kernel_stats; + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +#endif /* CH_DBG_STATISTICS */ + +/** @} */ diff --git a/os/kernel/src/chtm.c b/os/kernel/src/chtm.c new file mode 100644 index 000000000..a42223da3 --- /dev/null +++ b/os/kernel/src/chtm.c @@ -0,0 +1,197 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011,2012,2013 Giovanni Di Sirio. + + 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 . +*/ + +/** + * @file chtm.c + * @brief Time Measurement module code. + * + * @addtogroup time_measurement + * @details Time Measurement APIs and services. + * @{ + */ + +#include "ch.h" + +#if CH_CFG_USE_TM || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/** + * @brief Subsystem calibration value. + */ +static rtcnt_t measurement_offset; + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +/** + * @brief Initializes the realtime counter unit. + * + * @init + */ +void _rt_init(void) { + time_measurement_t tm; + + /* Time Measurement subsystem calibration, it does a null measurement + and calculates the call overhead which is subtracted to real + measurements.*/ + measurement_offset = 0; + chRTTimeMeasurementObjectInit(&tm); + chRTTimeMeasurementStartX(&tm); + chRTTimeMeasurementStopX(&tm); + measurement_offset = tm.last; +} + +/** + * @brief Realtime window test. + * @details This function verifies if the current realtime counter value + * lies within the specified range or not. The test takes care + * of the realtime counter wrapping to zero on overflow. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * @note This function can be called from any context. + * + * @par Example 1 + * Example of a guarded loop using the realtime counter. The loop implements + * a timeout after one second. + * @code + * rtcnt_t start = chSysGetRealtimeCounterX(); + * rtcnt_t timeout = start + S2RTC(RTCCLK, 1); + * while (my_condition) { + * if (!chTMIsCounterWithin(start, timeout) + * return TIMEOUT; + * // Do something. + * } + * // Continue. + * @endcode + * + * @par Example 2 + * Example of a loop that lasts exactly 50 microseconds. + * @code + * rtcnt_t start = chSysGetRealtimeCounterX(); + * rtcnt_t timeout = start + US2RTC(RTCCLK, 50); + * while (chTMIsCounterWithin(start, timeout)) { + * // Do something. + * } + * // Continue. + * @endcode + * + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval true current time within the specified time window. + * @retval false current time not within the specified time window. + * + * @special + */ +bool chTMIsCounterWithin(rtcnt_t start, rtcnt_t end) { + rtcnt_t now = chSysGetRealtimeCounterX(); + + return end > start ? (now >= start) && (now < end) : + (now >= start) || (now < end); +} + +/** + * @brief Polled delay. + * @note The real delay is always few cycles in excess of the specified + * value. + * @note This function can be called from any context. + * + * @param[in] cycles number of cycles + * + * @special + */ +void chTMPolledDelay(rtcnt_t cycles) { + rtcnt_t start = chSysGetRealtimeCounterX(); + rtcnt_t end = start + cycles; + while (chRTIsCounterWithin(start, end)) + ; +} + +/** + * @brief Initializes a @p TimeMeasurement object. + * + * @param[out] tmp pointer to a @p TimeMeasurement structure + * + * @init + */ +void chTMObjectInit(time_measurement_t *tmp) { + + tmp->best = (rtcnt_t)-1; + tmp->worst = (rtcnt_t)0; + tmp->cumulative = (rtcnt_t)0; + tmp->last = (rtcnt_t)0; +} + +/** + * @brief Starts a measurement. + * @pre The @p time_measurement_t structure must be initialized. + * @note This function can be invoked from any context. + * + * @param[in,out] tmp pointer to a @p TimeMeasurement structure + * + * @special + */ +NOINLINE void chTMStartX(time_measurement_t *tmp) { + + tmp->last = chSysGetRealtimeCounterX(); +} + +/** + * @brief Stops a measurement. + * @pre The @p time_measurement_t structure must be initialized. + * @note This function can be invoked from any context. + * + * @param[in,out] tmp pointer to a @p time_measurement_t structure + * + * @special + */ +NOINLINE void chTMStopX(time_measurement_t *tmp) { + + rtcnt_t now = chSysGetRealtimeCounterX(); + tmp->last = now - tmp->last - measurement_offset; + tmp->cumulative += tmp->last; + if (tmp->last > tmp->worst) + tmp->worst = tmp->last; + else if (tmp->last < tmp->best) + tmp->best = tmp->last; +} + +#endif /* CH_CFG_USE_TM */ + +/** @} */ -- cgit v1.2.3 From ca4b2f91b7a24abeb6ea7fa43c1816397fb966c4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 29 Jul 2013 14:31:13 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6039 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chstats.c | 17 +++++++- os/kernel/src/chsys.c | 7 +++- os/kernel/src/chtm.c | 101 +++++++++++++++++++++++------------------------- 3 files changed, 69 insertions(+), 56 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c index 1decf8f16..9d69e0023 100644 --- a/os/kernel/src/chstats.c +++ b/os/kernel/src/chstats.c @@ -20,9 +20,9 @@ /** * @file chstats.c - * @brief Real Time Counter and Measurement module code. + * @brief Statistics module code. * - * @addtogroup realtime_counter + * @addtogroup statistics * @details Statistics services. * @{ */ @@ -60,6 +60,19 @@ kernel_stats_t kernel_stats; /* Module exported functions. */ /*===========================================================================*/ +/** + * @brief Initializes the statistics module. + * + * @init + */ +void _stats_init(void) { + + kernel_stats.nirq = 0; + kernel_stats.nctxswc = 0; + chTMObjectInit(&kernel_stats.isr); + chTMObjectInit(&kernel_stats.critical); +} + #endif /* CH_DBG_STATISTICS */ /** @} */ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 91761b66b..0727532ee 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -105,8 +105,8 @@ void chSysInit(void) { port_init(); _scheduler_init(); _vt_init(); -#if CH_CFG_USE_RT - _rt_init(); +#if CH_CFG_USE_TM + _tm_init(); #endif #if CH_CFG_USE_MEMCORE _core_init(); @@ -114,6 +114,9 @@ void chSysInit(void) { #if CH_CFG_USE_HEAP _heap_init(); #endif +#if CH_DBG_STATISTICS + _stats_init(); +#endif #if CH_DBG_ENABLE_TRACE _trace_init(); #endif diff --git a/os/kernel/src/chtm.c b/os/kernel/src/chtm.c index a42223da3..0ae2dfeda 100644 --- a/os/kernel/src/chtm.c +++ b/os/kernel/src/chtm.c @@ -48,7 +48,7 @@ /*===========================================================================*/ /** - * @brief Subsystem calibration value. + * @brief Measurement calibration value. */ static rtcnt_t measurement_offset; @@ -56,25 +56,35 @@ static rtcnt_t measurement_offset; /* Module local functions. */ /*===========================================================================*/ +static inline void tm_stop(time_measurement_t *tmp, rtcnt_t now) { + + tmp->last = now - tmp->last - measurement_offset; + tmp->cumulative += tmp->last; + if (tmp->last > tmp->worst) + tmp->worst = tmp->last; + else if (tmp->last < tmp->best) + tmp->best = tmp->last; +} + /*===========================================================================*/ /* Module exported functions. */ /*===========================================================================*/ /** - * @brief Initializes the realtime counter unit. + * @brief Initializes the time measurement unit. * * @init */ -void _rt_init(void) { +void _tm_init(void) { time_measurement_t tm; /* Time Measurement subsystem calibration, it does a null measurement and calculates the call overhead which is subtracted to real measurements.*/ measurement_offset = 0; - chRTTimeMeasurementObjectInit(&tm); - chRTTimeMeasurementStartX(&tm); - chRTTimeMeasurementStopX(&tm); + chTMObjectInit(&tm); + chTMStartX(&tm); + chTMStopX(&tm); measurement_offset = tm.last; } @@ -85,61 +95,34 @@ void _rt_init(void) { * of the realtime counter wrapping to zero on overflow. * @note When start==end then the function returns always true because the * whole time range is specified. - * @note This function can be called from any context. - * - * @par Example 1 - * Example of a guarded loop using the realtime counter. The loop implements - * a timeout after one second. - * @code - * rtcnt_t start = chSysGetRealtimeCounterX(); - * rtcnt_t timeout = start + S2RTC(RTCCLK, 1); - * while (my_condition) { - * if (!chTMIsCounterWithin(start, timeout) - * return TIMEOUT; - * // Do something. - * } - * // Continue. - * @endcode - * - * @par Example 2 - * Example of a loop that lasts exactly 50 microseconds. - * @code - * rtcnt_t start = chSysGetRealtimeCounterX(); - * rtcnt_t timeout = start + US2RTC(RTCCLK, 50); - * while (chTMIsCounterWithin(start, timeout)) { - * // Do something. - * } - * // Continue. - * @endcode * + * @param[in] cnt the counter value to be tested * @param[in] start the start of the time window (inclusive) * @param[in] end the end of the time window (non inclusive) * @retval true current time within the specified time window. * @retval false current time not within the specified time window. * - * @special + * @xclass */ -bool chTMIsCounterWithin(rtcnt_t start, rtcnt_t end) { - rtcnt_t now = chSysGetRealtimeCounterX(); +bool chTMIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) { - return end > start ? (now >= start) && (now < end) : - (now >= start) || (now < end); + return end > start ? (cnt >= start) && (cnt < end) : + (cnt >= start) || (cnt < end); } /** * @brief Polled delay. * @note The real delay is always few cycles in excess of the specified * value. - * @note This function can be called from any context. * * @param[in] cycles number of cycles * - * @special + * @xclass */ -void chTMPolledDelay(rtcnt_t cycles) { +void chTMPolledDelayX(rtcnt_t cycles) { rtcnt_t start = chSysGetRealtimeCounterX(); rtcnt_t end = start + cycles; - while (chRTIsCounterWithin(start, end)) + while (chTMIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) ; } @@ -161,11 +144,10 @@ void chTMObjectInit(time_measurement_t *tmp) { /** * @brief Starts a measurement. * @pre The @p time_measurement_t structure must be initialized. - * @note This function can be invoked from any context. * * @param[in,out] tmp pointer to a @p TimeMeasurement structure * - * @special + * @xclass */ NOINLINE void chTMStartX(time_measurement_t *tmp) { @@ -175,23 +157,38 @@ NOINLINE void chTMStartX(time_measurement_t *tmp) { /** * @brief Stops a measurement. * @pre The @p time_measurement_t structure must be initialized. - * @note This function can be invoked from any context. * * @param[in,out] tmp pointer to a @p time_measurement_t structure * - * @special + * @xclass */ NOINLINE void chTMStopX(time_measurement_t *tmp) { - rtcnt_t now = chSysGetRealtimeCounterX(); - tmp->last = now - tmp->last - measurement_offset; - tmp->cumulative += tmp->last; - if (tmp->last > tmp->worst) - tmp->worst = tmp->last; - else if (tmp->last < tmp->best) - tmp->best = tmp->last; + tm_stop(tmp, chSysGetRealtimeCounterX()); } #endif /* CH_CFG_USE_TM */ +/** + * @brief Stops a measurement and chains to the next one using the same time + * stamp. + * + * @param[in,out] tmp1 pointer to the @p time_measurement_t structure to be + * stopped + * @param[in,out] tmp2 pointer to the @p time_measurement_t structure to be + * started + * + * + * @xclass + */ +NOINLINE void chTMChainToX(time_measurement_t *tmp1, + time_measurement_t *tmp2) { + + /* Starts new measurement.*/ + tmp2->last = chSysGetRealtimeCounterX(); + + /* Stops previous measurement using the same time stamp.*/ + tm_stop(tmp1, tmp2->last); +} + /** @} */ -- cgit v1.2.3 From f569bcec23452c190248aab184a125f3a52e2eb8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 29 Jul 2013 15:13:52 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6040 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chstats.c | 9 +++++---- os/kernel/src/chsys.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ os/kernel/src/chtm.c | 50 ++++++------------------------------------------- 3 files changed, 57 insertions(+), 48 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c index 9d69e0023..eb2023c93 100644 --- a/os/kernel/src/chstats.c +++ b/os/kernel/src/chstats.c @@ -67,10 +67,11 @@ kernel_stats_t kernel_stats; */ void _stats_init(void) { - kernel_stats.nirq = 0; - kernel_stats.nctxswc = 0; - chTMObjectInit(&kernel_stats.isr); - chTMObjectInit(&kernel_stats.critical); + kernel_stats.n_irq = 0; + kernel_stats.n_ctxswc = 0; + chTMObjectInit(&kernel_stats.m_isr); + chTMObjectInit(&kernel_stats.m_crit_thd); + chTMObjectInit(&kernel_stats.m_crit_isr); } #endif /* CH_DBG_STATISTICS */ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 0727532ee..168bd1376 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -29,6 +29,7 @@ * - Interrupt Handling. * - Power Management. * - Abnormal Termination. + * - Realtime counter. * . * @{ */ @@ -245,4 +246,49 @@ void chSysRestoreLockX(syssts_t sts) { } } + +#if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__) +/** + * @brief Realtime window test. + * @details This function verifies if the current realtime counter value + * lies within the specified range or not. The test takes care + * of the realtime counter wrapping to zero on overflow. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * @note This function is only available if the port layer supports the + * option @p CH_PORT_SUPPORTS_RT. + * + * @param[in] cnt the counter value to be tested + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval true current time within the specified time window. + * @retval false current time not within the specified time window. + * + * @xclass + */ +bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) { + + return end > start ? (cnt >= start) && (cnt < end) : + (cnt >= start) || (cnt < end); +} + +/** + * @brief Polled delay. + * @note The real delay is always few cycles in excess of the specified + * value. + * @note This function is only available if the port layer supports the + * option @p CH_PORT_SUPPORTS_RT. + * + * @param[in] cycles number of cycles + * + * @xclass + */ +void chSysPolledDelayX(rtcnt_t cycles) { + rtcnt_t start = chSysGetRealtimeCounterX(); + rtcnt_t end = start + cycles; + while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) + ; +} +#endif /* CH_PORT_SUPPORTS_RT */ + /** @} */ diff --git a/os/kernel/src/chtm.c b/os/kernel/src/chtm.c index 0ae2dfeda..474177093 100644 --- a/os/kernel/src/chtm.c +++ b/os/kernel/src/chtm.c @@ -83,49 +83,11 @@ void _tm_init(void) { measurements.*/ measurement_offset = 0; chTMObjectInit(&tm); - chTMStartX(&tm); - chTMStopX(&tm); + chTMStartMeasurementX(&tm); + chTMStopMeasurementX(&tm); measurement_offset = tm.last; } -/** - * @brief Realtime window test. - * @details This function verifies if the current realtime counter value - * lies within the specified range or not. The test takes care - * of the realtime counter wrapping to zero on overflow. - * @note When start==end then the function returns always true because the - * whole time range is specified. - * - * @param[in] cnt the counter value to be tested - * @param[in] start the start of the time window (inclusive) - * @param[in] end the end of the time window (non inclusive) - * @retval true current time within the specified time window. - * @retval false current time not within the specified time window. - * - * @xclass - */ -bool chTMIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) { - - return end > start ? (cnt >= start) && (cnt < end) : - (cnt >= start) || (cnt < end); -} - -/** - * @brief Polled delay. - * @note The real delay is always few cycles in excess of the specified - * value. - * - * @param[in] cycles number of cycles - * - * @xclass - */ -void chTMPolledDelayX(rtcnt_t cycles) { - rtcnt_t start = chSysGetRealtimeCounterX(); - rtcnt_t end = start + cycles; - while (chTMIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) - ; -} - /** * @brief Initializes a @p TimeMeasurement object. * @@ -149,7 +111,7 @@ void chTMObjectInit(time_measurement_t *tmp) { * * @xclass */ -NOINLINE void chTMStartX(time_measurement_t *tmp) { +NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp) { tmp->last = chSysGetRealtimeCounterX(); } @@ -162,7 +124,7 @@ NOINLINE void chTMStartX(time_measurement_t *tmp) { * * @xclass */ -NOINLINE void chTMStopX(time_measurement_t *tmp) { +NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp) { tm_stop(tmp, chSysGetRealtimeCounterX()); } @@ -181,8 +143,8 @@ NOINLINE void chTMStopX(time_measurement_t *tmp) { * * @xclass */ -NOINLINE void chTMChainToX(time_measurement_t *tmp1, - time_measurement_t *tmp2) { +NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1, + time_measurement_t *tmp2) { /* Starts new measurement.*/ tmp2->last = chSysGetRealtimeCounterX(); -- cgit v1.2.3 From 9cd24294b8b5c32af4f64762eb99868b1a5c7b75 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 30 Jul 2013 09:19:07 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6045 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chtm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chtm.c b/os/kernel/src/chtm.c index 474177093..2bec0cc1c 100644 --- a/os/kernel/src/chtm.c +++ b/os/kernel/src/chtm.c @@ -56,9 +56,11 @@ static rtcnt_t measurement_offset; /* Module local functions. */ /*===========================================================================*/ -static inline void tm_stop(time_measurement_t *tmp, rtcnt_t now) { +static inline void tm_stop(time_measurement_t *tmp, + rtcnt_t now, + rtcnt_t offset) { - tmp->last = now - tmp->last - measurement_offset; + tmp->last = now - tmp->last - offset; tmp->cumulative += tmp->last; if (tmp->last > tmp->worst) tmp->worst = tmp->last; @@ -126,7 +128,7 @@ NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp) { */ NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp) { - tm_stop(tmp, chSysGetRealtimeCounterX()); + tm_stop(tmp, chSysGetRealtimeCounterX(), measurement_offset); } #endif /* CH_CFG_USE_TM */ @@ -150,7 +152,7 @@ NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1, tmp2->last = chSysGetRealtimeCounterX(); /* Stops previous measurement using the same time stamp.*/ - tm_stop(tmp1, tmp2->last); + tm_stop(tmp1, tmp2->last, 0); } /** @} */ -- cgit v1.2.3 From 64403d8f188725bc5814813371382bc148956a83 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 30 Jul 2013 14:23:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6048 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 2 +- os/kernel/src/chstats.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- os/kernel/src/chsys.c | 2 +- 3 files changed, 51 insertions(+), 3 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 44058dff8..ba9c469b9 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -234,7 +234,7 @@ void _trace_init(void) { */ void dbg_trace(thread_t *otp) { - dbg_trace_buffer.tb_ptr->se_time = chTimeNow(); + dbg_trace_buffer.tb_ptr->se_time = chVTGetSystemTimeX(); dbg_trace_buffer.tb_ptr->se_tp = currp; dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c index eb2023c93..93739da17 100644 --- a/os/kernel/src/chstats.c +++ b/os/kernel/src/chstats.c @@ -69,11 +69,59 @@ void _stats_init(void) { kernel_stats.n_irq = 0; kernel_stats.n_ctxswc = 0; - chTMObjectInit(&kernel_stats.m_isr); chTMObjectInit(&kernel_stats.m_crit_thd); chTMObjectInit(&kernel_stats.m_crit_isr); } + +/** + * @brief Increases the IRQ counter. + */ +void _stats_increase_irq(void) { + + kernel_stats.n_irq++; +} + +/** + * @brief Increases the context switch counter. + */ +void _stats_increase_ctxswc(void) { + + kernel_stats.n_ctxswc++; +} + +/** + * @brief Starts the measurement of a thread critical zone. + */ +void _stats_start_measure_crit_thd(void) { + + chTMStartMeasurementX(&kernel_stats.m_crit_thd); +} + +/** + * @brief Stops the measurement of a thread critical zone. + */ +void _stats_stop_measure_crit_thd(void) { + + chTMStopMeasurementX(&kernel_stats.m_crit_thd); +} + +/** + * @brief Starts the measurement of an ISR critical zone. + */ +void _stats_start_measure_crit_isr(void) { + + chTMStartMeasurementX(&kernel_stats.m_crit_isr); +} + +/** + * @brief Stops the measurement of an ISR critical zone. + */ +void _stats_stop_measure_crit_isr(void) { + + chTMStopMeasurementX(&kernel_stats.m_crit_isr); +} + #endif /* CH_DBG_STATISTICS */ /** @} */ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 168bd1376..7057a7e01 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -163,7 +163,7 @@ void chSysInit(void) { */ void chSysHalt(void) { - chSysDisable(); + port_disable(); #if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) CH_CFG_SYSTEM_HALT_HOOK(); -- cgit v1.2.3 From 16044c7aeac671a4914749a387a6c526f0b2fdce Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 31 Jul 2013 10:26:40 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6053 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chtm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chtm.c b/os/kernel/src/chtm.c index 2bec0cc1c..e54bacbbf 100644 --- a/os/kernel/src/chtm.c +++ b/os/kernel/src/chtm.c @@ -60,8 +60,9 @@ static inline void tm_stop(time_measurement_t *tmp, rtcnt_t now, rtcnt_t offset) { + tmp->n++; tmp->last = now - tmp->last - offset; - tmp->cumulative += tmp->last; + tmp->cumulative += (rttime_t)tmp->last; if (tmp->last > tmp->worst) tmp->worst = tmp->last; else if (tmp->last < tmp->best) @@ -101,8 +102,9 @@ void chTMObjectInit(time_measurement_t *tmp) { tmp->best = (rtcnt_t)-1; tmp->worst = (rtcnt_t)0; - tmp->cumulative = (rtcnt_t)0; tmp->last = (rtcnt_t)0; + tmp->n = (ucnt_t)0; + tmp->cumulative = (rttime_t)0; } /** -- cgit v1.2.3 From ceea042aaf3e373b598b3295c256feaef4e4236c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 31 Jul 2013 12:26:02 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6056 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chstats.c | 5 +++-- os/kernel/src/chthreads.c | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c index 93739da17..06ac21d1d 100644 --- a/os/kernel/src/chstats.c +++ b/os/kernel/src/chstats.c @@ -83,11 +83,12 @@ void _stats_increase_irq(void) { } /** - * @brief Increases the context switch counter. + * @brief Updates context switch related statistics. */ -void _stats_increase_ctxswc(void) { +void _stats_ctxswc(thread_t *ntp, thread_t *otp) { kernel_stats.n_ctxswc++; + chTMChainMeasurementToX(&otp->p_stats, &ntp->p_stats); } /** diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index b707b4562..ff6e5e597 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -124,6 +124,9 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) { #if CH_DBG_ENABLE_STACK_CHECK tp->p_stklimit = (stkalign_t *)(tp + 1); #endif +#if CH_DBG_STATISTICS || defined(__DOXYGEN__) + chTMStartMeasurementX(&tp->p_stats); +#endif #if defined(CH_CFG_THREAD_INIT_HOOK) CH_CFG_THREAD_INIT_HOOK(tp); #endif -- cgit v1.2.3 From ec7cf10fcdaf32a56624f408be5830e4d5a0eef2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 6 Aug 2013 09:24:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6085 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 7057a7e01..cd4832831 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -246,7 +246,6 @@ void chSysRestoreLockX(syssts_t sts) { } } - #if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__) /** * @brief Realtime window test. -- cgit v1.2.3 From b5349cc22d7deade864d5ceb795a33af0a2eca15 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 6 Aug 2013 09:45:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6086 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chsys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index cd4832831..2494706d7 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -52,7 +52,7 @@ /** * @brief Idle thread working area. */ -static WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); +static WORKING_AREA(_idle_thread_wa, CH_PORT_IDLE_THREAD_STACK_SIZE); #endif /* CH_CFG_NO_IDLE_THREAD */ /*===========================================================================*/ -- cgit v1.2.3 From 7b51712449ffa10f260f60e6968257230fe63f15 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 9 Aug 2013 13:43:56 +0000 Subject: Updated queues. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6112 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chqueues.c | 80 +++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 28 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index f7e587228..7cbc63f50 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -45,10 +45,30 @@ #if CH_CFG_USE_QUEUES || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + /** * @brief Puts the invoking thread into the queue's threads queue. * - * @param[out] qp pointer to an @p GenericQueue structure + * @param[out] qp pointer to an @p io_queue_t structure * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. @@ -60,7 +80,7 @@ * @retval Q_RESET if the queue has been reset. * @retval Q_TIMEOUT if the queue operation timed out. */ -static msg_t qwait(GenericQueue *qp, systime_t time) { +static msg_t qwait(io_queue_t *qp, systime_t time) { if (TIME_IMMEDIATE == time) return Q_TIMEOUT; @@ -69,6 +89,10 @@ static msg_t qwait(GenericQueue *qp, systime_t time) { return chSchGoSleepTimeoutS(CH_STATE_WTQUEUE, time); } +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Initializes an input queue. * @details A Semaphore is internally initialized and works as a counter of @@ -76,7 +100,7 @@ static msg_t qwait(GenericQueue *qp, systime_t time) { * @note The callback is invoked from within the S-Locked system state, * see @ref system_states. * - * @param[out] iqp pointer to an @p InputQueue structure + * @param[out] iqp pointer to an @p input_queue_t structure * @param[in] bp pointer to a memory area allocated as queue buffer * @param[in] size size of the queue buffer * @param[in] infy pointer to a callback function that is invoked when @@ -85,8 +109,8 @@ static msg_t qwait(GenericQueue *qp, systime_t time) { * * @init */ -void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy, - void *link) { +void chIQObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size, + qnotify_t infy, void *link) { queue_init(&iqp->q_waiting); iqp->q_counter = 0; @@ -103,11 +127,11 @@ void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy, * @note A reset operation can be used by a low level driver in order to * obtain immediate attention from the high level layers. * - * @param[in] iqp pointer to an @p InputQueue structure + * @param[in] iqp pointer to an @p input_queue_t structure * * @iclass */ -void chIQResetI(InputQueue *iqp) { +void chIQResetI(input_queue_t *iqp) { chDbgCheckClassI(); @@ -121,7 +145,7 @@ void chIQResetI(InputQueue *iqp) { * @brief Input queue write. * @details A byte value is written into the low end of an input queue. * - * @param[in] iqp pointer to an @p InputQueue structure + * @param[in] iqp pointer to an @p input_queue_t structure * @param[in] b the byte value to be written in the queue * @return The operation status. * @retval Q_OK if the operation has been completed with success. @@ -130,7 +154,7 @@ void chIQResetI(InputQueue *iqp) { * * @iclass */ -msg_t chIQPutI(InputQueue *iqp, uint8_t b) { +msg_t chIQPutI(input_queue_t *iqp, uint8_t b) { chDbgCheckClassI(); @@ -156,7 +180,7 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) { * @note The callback is invoked before reading the character from the * buffer or before entering the state @p CH_STATE_WTQUEUE. * - * @param[in] iqp pointer to an @p InputQueue structure + * @param[in] iqp pointer to an @p input_queue_t structure * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. @@ -168,7 +192,7 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) { * * @api */ -msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) { +msg_t chIQGetTimeout(input_queue_t *iqp, systime_t time) { uint8_t b; chSysLock(); @@ -177,7 +201,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) { while (chIQIsEmptyI(iqp)) { msg_t msg; - if ((msg = qwait((GenericQueue *)iqp, time)) < Q_OK) { + if ((msg = qwait((io_queue_t *)iqp, time)) < Q_OK) { chSysUnlock(); return msg; } @@ -203,7 +227,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) { * @note The callback is invoked before reading each character from the * buffer or before entering the state @p CH_STATE_WTQUEUE. * - * @param[in] iqp pointer to an @p InputQueue structure + * @param[in] iqp pointer to an @p input_queue_t structure * @param[out] bp pointer to the data buffer * @param[in] n the maximum amount of data to be transferred, the * value 0 is reserved @@ -216,7 +240,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) { * * @api */ -size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp, +size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp, size_t n, systime_t time) { qnotify_t nfy = iqp->q_notify; size_t r = 0; @@ -229,7 +253,7 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp, nfy(iqp); while (chIQIsEmptyI(iqp)) { - if (qwait((GenericQueue *)iqp, time) != Q_OK) { + if (qwait((io_queue_t *)iqp, time) != Q_OK) { chSysUnlock(); return r; } @@ -256,7 +280,7 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp, * @note The callback is invoked from within the S-Locked system state, * see @ref system_states. * - * @param[out] oqp pointer to an @p OutputQueue structure + * @param[out] oqp pointer to an @p output_queue_t structure * @param[in] bp pointer to a memory area allocated as queue buffer * @param[in] size size of the queue buffer * @param[in] onfy pointer to a callback function that is invoked when @@ -265,8 +289,8 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp, * * @init */ -void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy, - void *link) { +void chOQObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size, + qnotify_t onfy, void *link) { queue_init(&oqp->q_waiting); oqp->q_counter = size; @@ -283,11 +307,11 @@ void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy, * @note A reset operation can be used by a low level driver in order to * obtain immediate attention from the high level layers. * - * @param[in] oqp pointer to an @p OutputQueue structure + * @param[in] oqp pointer to an @p output_queue_t structure * * @iclass */ -void chOQResetI(OutputQueue *oqp) { +void chOQResetI(output_queue_t *oqp) { chDbgCheckClassI(); @@ -305,7 +329,7 @@ void chOQResetI(OutputQueue *oqp) { * @note The callback is invoked after writing the character into the * buffer. * - * @param[in] oqp pointer to an @p OutputQueue structure + * @param[in] oqp pointer to an @p output_queue_t structure * @param[in] b the byte value to be written in the queue * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -319,13 +343,13 @@ void chOQResetI(OutputQueue *oqp) { * * @api */ -msg_t chOQPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time) { +msg_t chOQPutTimeout(output_queue_t *oqp, uint8_t b, systime_t time) { chSysLock(); while (chOQIsFullI(oqp)) { msg_t msg; - if ((msg = qwait((GenericQueue *)oqp, time)) < Q_OK) { + if ((msg = qwait((io_queue_t *)oqp, time)) < Q_OK) { chSysUnlock(); return msg; } @@ -347,13 +371,13 @@ msg_t chOQPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time) { * @brief Output queue read. * @details A byte value is read from the low end of an output queue. * - * @param[in] oqp pointer to an @p OutputQueue structure + * @param[in] oqp pointer to an @p output_queue_t structure * @return The byte value from the queue. * @retval Q_EMPTY if the queue is empty. * * @iclass */ -msg_t chOQGetI(OutputQueue *oqp) { +msg_t chOQGetI(output_queue_t *oqp) { uint8_t b; chDbgCheckClassI(); @@ -383,7 +407,7 @@ msg_t chOQGetI(OutputQueue *oqp) { * @note The callback is invoked after writing each character into the * buffer. * - * @param[in] oqp pointer to an @p OutputQueue structure + * @param[in] oqp pointer to an @p output_queue_t structure * @param[out] bp pointer to the data buffer * @param[in] n the maximum amount of data to be transferred, the * value 0 is reserved @@ -396,7 +420,7 @@ msg_t chOQGetI(OutputQueue *oqp) { * * @api */ -size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp, +size_t chOQWriteTimeout(output_queue_t *oqp, const uint8_t *bp, size_t n, systime_t time) { qnotify_t nfy = oqp->q_notify; size_t w = 0; @@ -406,7 +430,7 @@ size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp, chSysLock(); while (true) { while (chOQIsFullI(oqp)) { - if (qwait((GenericQueue *)oqp, time) != Q_OK) { + if (qwait((io_queue_t *)oqp, time) != Q_OK) { chSysUnlock(); return w; } -- cgit v1.2.3 From c3dc5598c315f4650bfcd1e595104a2ace7aa87c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 08:07:43 +0000 Subject: Global variables consolidation. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6116 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chregistry.c | 10 +++++----- os/kernel/src/chschd.c | 29 ++++++++++++----------------- os/kernel/src/chsys.c | 5 +++++ os/kernel/src/chvt.c | 34 +++++++++++++++------------------- 4 files changed, 37 insertions(+), 41 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c index b43341edd..b0d241fee 100644 --- a/os/kernel/src/chregistry.c +++ b/os/kernel/src/chregistry.c @@ -42,8 +42,8 @@ * terminating threads can pulse an event source and an event handler * can perform a scansion of the registry in order to recover the * memory. - * @pre In order to use the threads registry the @p CH_CFG_USE_REGISTRY option - * must be enabled in @p chconf.h. + * @pre In order to use the threads registry the @p CH_CFG_USE_REGISTRY + * option must be enabled in @p chconf.h. * @{ */ #include "ch.h" @@ -66,7 +66,7 @@ /* Module local functions. */ /*===========================================================================*/ -#define _offsetof(st, m) \ +#define _offsetof(st, m) \ ((size_t)((char *)&((st *)0)->m - (char *)0)) /*===========================================================================*/ @@ -131,7 +131,7 @@ thread_t *chRegFirstThread(void) { thread_t *tp; chSysLock(); - tp = rlist.r_newer; + tp = ch.rlist.r_newer; #if CH_CFG_USE_DYNAMIC tp->p_refs++; #endif @@ -155,7 +155,7 @@ thread_t *chRegNextThread(thread_t *tp) { chSysLock(); ntp = tp->p_newer; - if (ntp == (thread_t *)&rlist) + if (ntp == (thread_t *)&ch.rlist) ntp = NULL; #if CH_CFG_USE_DYNAMIC else { diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index db0097108..53a14dac7 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -37,11 +37,6 @@ /* Module exported variables. */ /*===========================================================================*/ -/** - * @brief Ready list header. - */ -ready_list_t rlist; - /*===========================================================================*/ /* Module local types. */ /*===========================================================================*/ @@ -65,10 +60,10 @@ ready_list_t rlist; */ void _scheduler_init(void) { - queue_init(&rlist.r_queue); - rlist.r_prio = NOPRIO; + queue_init(&ch.rlist.r_queue); + ch.rlist.r_prio = NOPRIO; #if CH_CFG_USE_REGISTRY - rlist.r_newer = rlist.r_older = (thread_t *)&rlist; + ch.rlist.r_newer = ch.rlist.r_older = (thread_t *)&ch.rlist; #endif } @@ -100,7 +95,7 @@ thread_t *chSchReadyI(thread_t *tp) { "invalid state"); tp->p_state = CH_STATE_READY; - cp = (thread_t *)&rlist.r_queue; + cp = (thread_t *)&ch.rlist.r_queue; do { cp = cp->p_next; } while (cp->p_prio >= tp->p_prio); @@ -131,7 +126,7 @@ void chSchGoSleepS(tstate_t newstate) { time quantum when it will wakeup.*/ otp->p_preempt = CH_CFG_TIME_QUANTUM; #endif - setcurrp(queue_fifo_remove(&rlist.r_queue)); + setcurrp(queue_fifo_remove(&ch.rlist.r_queue)); currp->p_state = CH_STATE_CURRENT; chSysSwitch(currp, otp); } @@ -149,7 +144,7 @@ static void wakeup(void *p) { another thread with higher priority.*/ chSysUnlockFromISR(); return; -#if CH_CFG_USE_SEMAPHORES || CH_CFG_USE_QUEUES || \ +#if CH_CFG_USE_SEMAPHORES || CH_CFG_USE_QUEUES || \ (CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT) #if CH_CFG_USE_SEMAPHORES case CH_STATE_WTSEM: @@ -274,7 +269,7 @@ void chSchRescheduleS(void) { * @special */ bool chSchIsPreemptionRequired(void) { - tprio_t p1 = firstprio(&rlist.r_queue); + tprio_t p1 = firstprio(&ch.rlist.r_queue); tprio_t p2 = currp->p_prio; #if CH_CFG_TIME_QUANTUM > 0 /* If the running thread has not reached its time quantum, reschedule only @@ -304,7 +299,7 @@ void chSchDoRescheduleBehind(void) { otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ - setcurrp(queue_fifo_remove(&rlist.r_queue)); + setcurrp(queue_fifo_remove(&ch.rlist.r_queue)); currp->p_state = CH_STATE_CURRENT; #if CH_CFG_TIME_QUANTUM > 0 otp->p_preempt = CH_CFG_TIME_QUANTUM; @@ -327,11 +322,11 @@ void chSchDoRescheduleAhead(void) { otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ - setcurrp(queue_fifo_remove(&rlist.r_queue)); + setcurrp(queue_fifo_remove(&ch.rlist.r_queue)); currp->p_state = CH_STATE_CURRENT; otp->p_state = CH_STATE_READY; - cp = (thread_t *)&rlist.r_queue; + cp = (thread_t *)&ch.rlist.r_queue; do { cp = cp->p_next; } while (cp->p_prio > otp->p_prio); @@ -356,8 +351,8 @@ void chSchDoRescheduleAhead(void) { void chSchDoReschedule(void) { #if CH_CFG_TIME_QUANTUM > 0 - /* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios to - handle on preemption: time quantum elapsed or not.*/ + /* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios + to handle on preemption: time quantum elapsed or not.*/ if (currp->p_preempt == 0) { /* The thread consumed its time quantum so it is enqueued behind threads with same priority level, however, it acquires a new time quantum.*/ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 2494706d7..9212cbf5f 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -48,6 +48,11 @@ /* Module local variables. */ /*===========================================================================*/ +/** + * @brief System data structures. + */ +ch_system_t ch; + #if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) /** * @brief Idle thread working area. diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index 3e6028f9c..6fa4dd582 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -37,11 +37,6 @@ /* Module exported variables. */ /*===========================================================================*/ -/** - * @brief Virtual timers delta list header. - */ -virtual_timers_list_t vtlist; - /*===========================================================================*/ /* Module local types. */ /*===========================================================================*/ @@ -66,12 +61,12 @@ virtual_timers_list_t vtlist; */ void _vt_init(void) { - vtlist.vt_next = vtlist.vt_prev = (void *)&vtlist; - vtlist.vt_delta = (systime_t)-1; + ch.vtlist.vt_next = ch.vtlist.vt_prev = (void *)&ch.vtlist; + ch.vtlist.vt_delta = (systime_t)-1; #if CH_CFG_TIMEDELTA == 0 - vtlist.vt_systime = 0; + ch.vtlist.vt_systime = 0; #else /* CH_CFG_TIMEDELTA > 0 */ - vtlist.vt_lasttime = 0; + ch.vtlist.vt_lasttime = 0; #endif /* CH_CFG_TIMEDELTA > 0 */ } @@ -128,7 +123,7 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, vtp->vt_par = par; vtp->vt_func = vtfunc; - p = vtlist.vt_next; + p = ch.vtlist.vt_next; #if CH_CFG_TIMEDELTA > 0 || defined(__DOXYGEN__) { @@ -139,21 +134,21 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, if (delay < CH_CFG_TIMEDELTA) delay = CH_CFG_TIMEDELTA; - if (&vtlist == (virtual_timers_list_t *)p) { + if (&ch.vtlist == (virtual_timers_list_t *)p) { /* The delta list is empty, the current time becomes the new delta list base time.*/ - vtlist.vt_lasttime = now; - port_timer_start_alarm(vtlist.vt_lasttime + delay); + ch.vtlist.vt_lasttime = now; + port_timer_start_alarm(ch.vtlist.vt_lasttime + delay); } else { /* Now the delay is calculated as delta from the last tick interrupt time.*/ - delay += now - vtlist.vt_lasttime; + delay += now - ch.vtlist.vt_lasttime; /* If the specified delay is closer in time than the first element in the delta list then it becomes the next alarm event in time.*/ if (delay < p->vt_delta) - port_timer_set_alarm(vtlist.vt_lasttime + delay); + port_timer_set_alarm(ch.vtlist.vt_lasttime + delay); } } #endif /* CH_CFG_TIMEDELTA > 0 */ @@ -172,7 +167,7 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, /* Special case when the timer is in last position in the list, the value in the header must be restored.*/; p->vt_delta -= delay; - vtlist.vt_delta = (systime_t)-1; + ch.vtlist.vt_delta = (systime_t)-1; } /** @@ -199,17 +194,18 @@ void chVTDoResetI(virtual_timer_t *vtp) { /* The above code changes the value in the header when the removed element is the last of the list, restoring it.*/ - vtlist.vt_delta = (systime_t)-1; + ch.vtlist.vt_delta = (systime_t)-1; #if CH_CFG_TIMEDELTA > 0 || defined(__DOXYGEN__) { - if (&vtlist == (virtual_timers_list_t *)vtlist.vt_next) { + if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.vt_next) { /* Just removed the last element in the list, alarm timer stopped.*/ port_timer_stop_alarm(); } else { /* The alarm is set to the next element in the delta list.*/ - port_timer_set_alarm(vtlist.vt_lasttime + vtlist.vt_next->vt_delta); + port_timer_set_alarm(ch.vtlist.vt_lasttime + + ch.vtlist.vt_next->vt_delta); } } #endif /* CH_CFG_TIMEDELTA > 0 */ -- cgit v1.2.3 From 649decd10516a30886d05f5afca3d425d836db0e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 10:17:45 +0000 Subject: Cleanup debug module. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6120 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chdebug.c | 125 +++++++++++++++++++++------------------------- os/kernel/src/chdynamic.c | 8 +-- os/kernel/src/chthreads.c | 4 +- 3 files changed, 63 insertions(+), 74 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index ba9c469b9..05b746357 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -51,29 +51,38 @@ #include "ch.h" /*===========================================================================*/ -/* System state checker related code and variables. */ +/* Module local definitions. */ /*===========================================================================*/ -#if CH_DBG_SYSTEM_STATE_CHECK || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ -/** - * @brief ISR nesting level. - */ -cnt_t dbg_isr_cnt; +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ -/** - * @brief Lock nesting level. - */ -cnt_t dbg_lock_cnt; +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ +#if CH_DBG_SYSTEM_STATE_CHECK || defined(__DOXYGEN__) /** * @brief Guard code for @p chSysDisable(). * * @notapi */ -void dbg_check_disable(void) { +void _dbg_check_disable(void) { - if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) + if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt != 0)) chDbgPanic("SV#1"); } @@ -82,9 +91,9 @@ void dbg_check_disable(void) { * * @notapi */ -void dbg_check_suspend(void) { +void _dbg_check_suspend(void) { - if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) + if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt != 0)) chDbgPanic("SV#2"); } @@ -93,9 +102,9 @@ void dbg_check_suspend(void) { * * @notapi */ -void dbg_check_enable(void) { +void _dbg_check_enable(void) { - if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) + if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt != 0)) chDbgPanic("SV#3"); } @@ -104,11 +113,11 @@ void dbg_check_enable(void) { * * @notapi */ -void dbg_check_lock(void) { +void _dbg_check_lock(void) { - if ((dbg_isr_cnt != 0) || (dbg_lock_cnt != 0)) + if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt != 0)) chDbgPanic("SV#4"); - dbg_enter_lock(); + _dbg_enter_lock(); } /** @@ -116,11 +125,11 @@ void dbg_check_lock(void) { * * @notapi */ -void dbg_check_unlock(void) { +void _dbg_check_unlock(void) { - if ((dbg_isr_cnt != 0) || (dbg_lock_cnt <= 0)) + if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt <= 0)) chDbgPanic("SV#5"); - dbg_leave_lock(); + _dbg_leave_lock(); } /** @@ -128,11 +137,11 @@ void dbg_check_unlock(void) { * * @notapi */ -void dbg_check_lock_from_isr(void) { +void _dbg_check_lock_from_isr(void) { - if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt != 0)) + if ((ch.dbg_isr_cnt <= 0) || (ch.dbg_lock_cnt != 0)) chDbgPanic("SV#6"); - dbg_enter_lock(); + _dbg_enter_lock(); } /** @@ -140,11 +149,11 @@ void dbg_check_lock_from_isr(void) { * * @notapi */ -void dbg_check_unlock_from_isr(void) { +void _dbg_check_unlock_from_isr(void) { - if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt <= 0)) + if ((ch.dbg_isr_cnt <= 0) || (ch.dbg_lock_cnt <= 0)) chDbgPanic("SV#7"); - dbg_leave_lock(); + _dbg_leave_lock(); } /** @@ -152,12 +161,12 @@ void dbg_check_unlock_from_isr(void) { * * @notapi */ -void dbg_check_enter_isr(void) { +void _dbg_check_enter_isr(void) { port_lock_from_isr(); - if ((dbg_isr_cnt < 0) || (dbg_lock_cnt != 0)) + if ((ch.dbg_isr_cnt < 0) || (ch.dbg_lock_cnt != 0)) chDbgPanic("SV#8"); - dbg_isr_cnt++; + ch.dbg_isr_cnt++; port_unlock_from_isr(); } @@ -166,12 +175,12 @@ void dbg_check_enter_isr(void) { * * @notapi */ -void dbg_check_leave_isr(void) { +void _dbg_check_leave_isr(void) { port_lock_from_isr(); - if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt != 0)) + if ((ch.dbg_isr_cnt <= 0) || (ch.dbg_lock_cnt != 0)) chDbgPanic("SV#9"); - dbg_isr_cnt--; + ch.dbg_isr_cnt--; port_unlock_from_isr(); } @@ -185,7 +194,7 @@ void dbg_check_leave_isr(void) { */ void chDbgCheckClassI(void) { - if ((dbg_isr_cnt < 0) || (dbg_lock_cnt <= 0)) + if ((ch.dbg_isr_cnt < 0) || (ch.dbg_lock_cnt <= 0)) chDbgPanic("SV#10"); } @@ -199,30 +208,21 @@ void chDbgCheckClassI(void) { */ void chDbgCheckClassS(void) { - if ((dbg_isr_cnt != 0) || (dbg_lock_cnt <= 0)) + if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt <= 0)) chDbgPanic("SV#11"); } #endif /* CH_DBG_SYSTEM_STATE_CHECK */ -/*===========================================================================*/ -/* Trace related code and variables. */ -/*===========================================================================*/ - #if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) -/** - * @brief Public trace buffer. - */ -ch_trace_buffer_t dbg_trace_buffer; - /** * @brief Trace circular buffer subsystem initialization. * @note Internal use only. */ void _trace_init(void) { - dbg_trace_buffer.tb_size = CH_TRACE_BUFFER_SIZE; - dbg_trace_buffer.tb_ptr = &dbg_trace_buffer.tb_buffer[0]; + ch.dbg_trace_buffer.tb_size = CH_DBG_TRACE_BUFFER_SIZE; + ch.dbg_trace_buffer.tb_ptr = &ch.dbg_trace_buffer.tb_buffer[0]; } /** @@ -232,30 +232,19 @@ void _trace_init(void) { * * @notapi */ -void dbg_trace(thread_t *otp) { - - dbg_trace_buffer.tb_ptr->se_time = chVTGetSystemTimeX(); - dbg_trace_buffer.tb_ptr->se_tp = currp; - dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; - dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; - if (++dbg_trace_buffer.tb_ptr >= - &dbg_trace_buffer.tb_buffer[CH_TRACE_BUFFER_SIZE]) - dbg_trace_buffer.tb_ptr = &dbg_trace_buffer.tb_buffer[0]; +void _dbg_trace(thread_t *otp) { + + ch.dbg_trace_buffer.tb_ptr->se_time = chVTGetSystemTimeX(); + ch.dbg_trace_buffer.tb_ptr->se_tp = currp; + ch.dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; + ch.dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; + if (++ch.dbg_trace_buffer.tb_ptr >= + &ch.dbg_trace_buffer.tb_buffer[CH_DBG_TRACE_BUFFER_SIZE]) + ch.dbg_trace_buffer.tb_ptr = &ch.dbg_trace_buffer.tb_buffer[0]; } #endif /* CH_DBG_ENABLE_TRACE */ -/*===========================================================================*/ -/* Panic related code and variables. */ -/*===========================================================================*/ - #if CH_DBG_ENABLED || defined(__DOXYGEN__) -/** - * @brief Pointer to the panic message. - * @details This pointer is meant to be accessed through the debugger, it is - * written once and then the system is halted. - */ -const char *dbg_panic_msg; - /** * @brief Prints a panic message on the console and then halts the system. * @@ -263,7 +252,7 @@ const char *dbg_panic_msg; */ void chDbgPanic(const char *msg) { - dbg_panic_msg = msg; + ch.dbg_panic_msg = msg; chSysHalt(); } #endif /* CH_DBG_ENABLED */ diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c index 2b12e698f..86e37df14 100644 --- a/os/kernel/src/chdynamic.c +++ b/os/kernel/src/chdynamic.c @@ -156,10 +156,10 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, (uint8_t *)wsp + sizeof(thread_t), - CH_THREAD_FILL_VALUE); + CH_DBG_THREAD_FILL_VALUE); _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + size, - CH_STACK_FILL_VALUE); + CH_DBG_STACK_FILL_VALUE); #endif chSysLock(); @@ -207,10 +207,10 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, (uint8_t *)wsp + sizeof(thread_t), - CH_THREAD_FILL_VALUE); + CH_DBG_THREAD_FILL_VALUE); _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + mp->mp_object_size, - CH_STACK_FILL_VALUE); + CH_DBG_STACK_FILL_VALUE); #endif chSysLock(); diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index ff6e5e597..a18e82005 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -212,10 +212,10 @@ thread_t *chThdCreateStatic(void *wsp, size_t size, #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, (uint8_t *)wsp + sizeof(thread_t), - CH_THREAD_FILL_VALUE); + CH_DBG_THREAD_FILL_VALUE); _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + size, - CH_STACK_FILL_VALUE); + CH_DBG_STACK_FILL_VALUE); #endif chSysLock(); chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK); -- cgit v1.2.3 From 10a6a01271053053c64077fee56d0cb8444123b6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 11:49:48 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6121 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chstats.c | 26 ++++++++++---------------- os/kernel/src/chtm.c | 11 +++-------- 2 files changed, 13 insertions(+), 24 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c index 06ac21d1d..653d8da77 100644 --- a/os/kernel/src/chstats.c +++ b/os/kernel/src/chstats.c @@ -39,11 +39,6 @@ /* Module exported variables. */ /*===========================================================================*/ -/** - * @brief Global kernel statistics. - */ -kernel_stats_t kernel_stats; - /*===========================================================================*/ /* Module local types. */ /*===========================================================================*/ @@ -67,19 +62,18 @@ kernel_stats_t kernel_stats; */ void _stats_init(void) { - kernel_stats.n_irq = 0; - kernel_stats.n_ctxswc = 0; - chTMObjectInit(&kernel_stats.m_crit_thd); - chTMObjectInit(&kernel_stats.m_crit_isr); + ch.kernel_stats.n_irq = 0; + ch.kernel_stats.n_ctxswc = 0; + chTMObjectInit(&ch.kernel_stats.m_crit_thd); + chTMObjectInit(&ch.kernel_stats.m_crit_isr); } - /** * @brief Increases the IRQ counter. */ void _stats_increase_irq(void) { - kernel_stats.n_irq++; + ch.kernel_stats.n_irq++; } /** @@ -87,7 +81,7 @@ void _stats_increase_irq(void) { */ void _stats_ctxswc(thread_t *ntp, thread_t *otp) { - kernel_stats.n_ctxswc++; + ch.kernel_stats.n_ctxswc++; chTMChainMeasurementToX(&otp->p_stats, &ntp->p_stats); } @@ -96,7 +90,7 @@ void _stats_ctxswc(thread_t *ntp, thread_t *otp) { */ void _stats_start_measure_crit_thd(void) { - chTMStartMeasurementX(&kernel_stats.m_crit_thd); + chTMStartMeasurementX(&ch.kernel_stats.m_crit_thd); } /** @@ -104,7 +98,7 @@ void _stats_start_measure_crit_thd(void) { */ void _stats_stop_measure_crit_thd(void) { - chTMStopMeasurementX(&kernel_stats.m_crit_thd); + chTMStopMeasurementX(&ch.kernel_stats.m_crit_thd); } /** @@ -112,7 +106,7 @@ void _stats_stop_measure_crit_thd(void) { */ void _stats_start_measure_crit_isr(void) { - chTMStartMeasurementX(&kernel_stats.m_crit_isr); + chTMStartMeasurementX(&ch.kernel_stats.m_crit_isr); } /** @@ -120,7 +114,7 @@ void _stats_start_measure_crit_isr(void) { */ void _stats_stop_measure_crit_isr(void) { - chTMStopMeasurementX(&kernel_stats.m_crit_isr); + chTMStopMeasurementX(&ch.kernel_stats.m_crit_isr); } #endif /* CH_DBG_STATISTICS */ diff --git a/os/kernel/src/chtm.c b/os/kernel/src/chtm.c index e54bacbbf..24239e0e2 100644 --- a/os/kernel/src/chtm.c +++ b/os/kernel/src/chtm.c @@ -47,11 +47,6 @@ /* Module local variables. */ /*===========================================================================*/ -/** - * @brief Measurement calibration value. - */ -static rtcnt_t measurement_offset; - /*===========================================================================*/ /* Module local functions. */ /*===========================================================================*/ @@ -84,11 +79,11 @@ void _tm_init(void) { /* Time Measurement subsystem calibration, it does a null measurement and calculates the call overhead which is subtracted to real measurements.*/ - measurement_offset = 0; + ch.measurement_offset = 0; chTMObjectInit(&tm); chTMStartMeasurementX(&tm); chTMStopMeasurementX(&tm); - measurement_offset = tm.last; + ch.measurement_offset = tm.last; } /** @@ -130,7 +125,7 @@ NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp) { */ NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp) { - tm_stop(tmp, chSysGetRealtimeCounterX(), measurement_offset); + tm_stop(tmp, chSysGetRealtimeCounterX(), ch.measurement_offset); } #endif /* CH_CFG_USE_TM */ -- cgit v1.2.3 From eb7a1a15b23341693864c6fc13ac5eab5c1d6122 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 14:50:32 +0000 Subject: Removed 2nd parameter to assertion and check macros. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6122 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 20 ++++++++------------ os/kernel/src/chdynamic.c | 6 +++--- os/kernel/src/chevents.c | 16 +++++++--------- os/kernel/src/chheap.c | 8 +++----- os/kernel/src/chmboxes.c | 16 ++++++++-------- os/kernel/src/chmempools.c | 8 ++++---- os/kernel/src/chmsg.c | 5 ++--- os/kernel/src/chmtx.c | 26 +++++++++----------------- os/kernel/src/chqueues.c | 4 ++-- os/kernel/src/chregistry.c | 3 +-- os/kernel/src/chschd.c | 1 - os/kernel/src/chsem.c | 24 ++++++++---------------- os/kernel/src/chthreads.c | 16 +++++++--------- os/kernel/src/chvt.c | 9 +++------ 14 files changed, 65 insertions(+), 97 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index 49e1f891e..94fd8e81c 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -75,7 +75,7 @@ */ void chCondObjectInit(condition_variable_t *cp) { - chDbgCheck(cp != NULL, "chCondInit"); + chDbgCheck(cp != NULL); queue_init(&cp->c_queue); } @@ -89,7 +89,7 @@ void chCondObjectInit(condition_variable_t *cp) { */ void chCondSignal(condition_variable_t *cp) { - chDbgCheck(cp != NULL, "chCondSignal"); + chDbgCheck(cp != NULL); chSysLock(); if (queue_notempty(&cp->c_queue)) @@ -111,7 +111,7 @@ void chCondSignal(condition_variable_t *cp) { void chCondSignalI(condition_variable_t *cp) { chDbgCheckClassI(); - chDbgCheck(cp != NULL, "chCondSignalI"); + chDbgCheck(cp != NULL); if (queue_notempty(&cp->c_queue)) chSchReadyI(queue_fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_OK; @@ -146,7 +146,7 @@ void chCondBroadcast(condition_variable_t *cp) { void chCondBroadcastI(condition_variable_t *cp) { chDbgCheckClassI(); - chDbgCheck(cp != NULL, "chCondBroadcastI"); + chDbgCheck(cp != NULL); /* Empties the condition variable queue and inserts all the threads into the ready list in FIFO order. The wakeup message is set to @p RDY_RESET in @@ -204,10 +204,8 @@ msg_t chCondWaitS(condition_variable_t *cp) { msg_t msg; chDbgCheckClassS(); - chDbgCheck(cp != NULL, "chCondWaitS"); - chDbgAssert(ctp->p_mtxlist != NULL, - "chCondWaitS(), #1", - "not owning a mutex"); + chDbgCheck(cp != NULL); + chDbgAssert(ctp->p_mtxlist != NULL, "not owning a mutex"); mp = chMtxUnlockS(); ctp->p_u.wtobjp = cp; @@ -289,10 +287,8 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { msg_t msg; chDbgCheckClassS(); - chDbgCheck((cp != NULL) && (time != TIME_IMMEDIATE), "chCondWaitTimeoutS"); - chDbgAssert(currp->p_mtxlist != NULL, - "chCondWaitTimeoutS(), #1", - "not owning a mutex"); + chDbgCheck((cp != NULL) && (time != TIME_IMMEDIATE)); + chDbgAssert(currp->p_mtxlist != NULL, "not owning a mutex"); mp = chMtxUnlockS(); currp->p_u.wtobjp = cp; diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c index 86e37df14..5f174eda7 100644 --- a/os/kernel/src/chdynamic.c +++ b/os/kernel/src/chdynamic.c @@ -69,7 +69,7 @@ thread_t *chThdAddRef(thread_t *tp) { chSysLock(); - chDbgAssert(tp->p_refs < 255, "chThdAddRef(), #1", "too many references"); + chDbgAssert(tp->p_refs < 255, "too many references"); tp->p_refs++; chSysUnlock(); return tp; @@ -92,7 +92,7 @@ void chThdRelease(thread_t *tp) { trefs_t refs; chSysLock(); - chDbgAssert(tp->p_refs > 0, "chThdRelease(), #1", "not referenced"); + chDbgAssert(tp->p_refs > 0, "not referenced"); refs = --tp->p_refs; chSysUnlock(); @@ -198,7 +198,7 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, void *wsp; thread_t *tp; - chDbgCheck(mp != NULL, "chThdCreateFromMemoryPool"); + chDbgCheck(mp != NULL); wsp = chPoolAlloc(mp); if (wsp == NULL) diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index d95730f7c..04b0e6fb8 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -104,7 +104,7 @@ void chEvtRegisterMask(event_source_t *esp, event_listener_t *elp, eventmask_t mask) { - chDbgCheck((esp != NULL) && (elp != NULL), "chEvtRegisterMask"); + chDbgCheck((esp != NULL) && (elp != NULL)); chSysLock(); elp->el_next = esp->es_next; @@ -131,7 +131,7 @@ void chEvtRegisterMask(event_source_t *esp, void chEvtUnregister(event_source_t *esp, event_listener_t *elp) { event_listener_t *p; - chDbgCheck((esp != NULL) && (elp != NULL), "chEvtUnregister"); + chDbgCheck((esp != NULL) && (elp != NULL)); p = (event_listener_t *)esp; chSysLock(); @@ -205,7 +205,7 @@ void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) { event_listener_t *elp; chDbgCheckClassI(); - chDbgCheck(esp != NULL, "chEvtBroadcastMaskI"); + chDbgCheck(esp != NULL); elp = esp->es_next; while (elp != (event_listener_t *)esp) { @@ -248,7 +248,7 @@ eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) { */ void chEvtSignal(thread_t *tp, eventmask_t mask) { - chDbgCheck(tp != NULL, "chEvtSignal"); + chDbgCheck(tp != NULL); chSysLock(); chEvtSignalI(tp, mask); @@ -271,7 +271,7 @@ void chEvtSignal(thread_t *tp, eventmask_t mask) { void chEvtSignalI(thread_t *tp, eventmask_t mask) { chDbgCheckClassI(); - chDbgCheck(tp != NULL, "chEvtSignalI"); + chDbgCheck(tp != NULL); tp->p_epending |= mask; /* Test on the AND/OR conditions wait states.*/ @@ -335,14 +335,12 @@ eventflags_t chEvtGetAndClearFlagsI(event_listener_t *elp) { void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask) { eventid_t eid; - chDbgCheck(handlers != NULL, "chEvtDispatch"); + chDbgCheck(handlers != NULL); eid = 0; while (mask) { if (mask & EVENT_MASK(eid)) { - chDbgAssert(handlers[eid] != NULL, - "chEvtDispatch(), #1", - "null handler"); + chDbgAssert(handlers[eid] != NULL, "null handler"); mask &= ~EVENT_MASK(eid); handlers[eid](eid); } diff --git a/os/kernel/src/chheap.c b/os/kernel/src/chheap.c index c2732376e..abda4ff10 100644 --- a/os/kernel/src/chheap.c +++ b/os/kernel/src/chheap.c @@ -108,7 +108,7 @@ void _heap_init(void) { void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) { union heap_header *hp; - chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size), "chHeapInit"); + chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size)); heapp->h_provider = (memgetfunc_t)NULL; heapp->h_free.h.u.next = hp = buf; @@ -204,7 +204,7 @@ void chHeapFree(void *p) { union heap_header *qp, *hp; memory_heap_t *heapp; - chDbgCheck(p != NULL, "chHeapFree"); + chDbgCheck(p != NULL); hp = (union heap_header *)p - 1; heapp = hp->h.u.heap; @@ -212,9 +212,7 @@ void chHeapFree(void *p) { H_LOCK(heapp); while (true) { - chDbgAssert((hp < qp) || (hp >= LIMIT(qp)), - "chHeapFree(), #1", - "within free block"); + chDbgAssert((hp < qp) || (hp >= LIMIT(qp)), "within free block"); if (((qp == &heapp->h_free) || (hp > qp)) && ((qp->h.u.next == NULL) || (hp < qp->h.u.next))) { diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index 2a6e6fae8..003c779ec 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -86,7 +86,7 @@ */ void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { - chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0), "chMBInit"); + chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0)); mbp->mb_buffer = mbp->mb_wrptr = mbp->mb_rdptr = buf; mbp->mb_top = &buf[n]; @@ -105,7 +105,7 @@ void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { */ void chMBReset(mailbox_t *mbp) { - chDbgCheck(mbp != NULL, "chMBReset"); + chDbgCheck(mbp != NULL); chSysLock(); mbp->mb_wrptr = mbp->mb_rdptr = mbp->mb_buffer; @@ -166,7 +166,7 @@ msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); - chDbgCheck(mbp != NULL, "chMBPostS"); + chDbgCheck(mbp != NULL); rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); if (rdymsg == RDY_OK) { @@ -196,7 +196,7 @@ msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); - chDbgCheck(mbp != NULL, "chMBPostI"); + chDbgCheck(mbp != NULL); if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) return RDY_TIMEOUT; @@ -259,7 +259,7 @@ msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); - chDbgCheck(mbp != NULL, "chMBPostAheadS"); + chDbgCheck(mbp != NULL); rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); if (rdymsg == RDY_OK) { @@ -289,7 +289,7 @@ msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); - chDbgCheck(mbp != NULL, "chMBPostAheadI"); + chDbgCheck(mbp != NULL); if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) return RDY_TIMEOUT; @@ -352,7 +352,7 @@ msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); - chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchS"); + chDbgCheck((mbp != NULL) && (msgp != NULL)); rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, time); if (rdymsg == RDY_OK) { @@ -382,7 +382,7 @@ msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { chDbgCheckClassI(); - chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchI"); + chDbgCheck((mbp != NULL) && (msgp != NULL)); if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) return RDY_TIMEOUT; diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c index 6d84b557e..d92ea7517 100644 --- a/os/kernel/src/chmempools.c +++ b/os/kernel/src/chmempools.c @@ -75,7 +75,7 @@ */ void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider) { - chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit"); + chDbgCheck((mp != NULL) && (size >= sizeof(void *))); mp->mp_next = NULL; mp->mp_object_size = size; @@ -97,7 +97,7 @@ void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider) { */ void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n) { - chDbgCheck((mp != NULL) && (n != 0), "chPoolLoadArray"); + chDbgCheck((mp != NULL) && (n != 0)); while (n) { chPoolAdd(mp, p); @@ -120,7 +120,7 @@ void *chPoolAllocI(memory_pool_t *mp) { void *objp; chDbgCheckClassI(); - chDbgCheck(mp != NULL, "chPoolAllocI"); + chDbgCheck(mp != NULL); if ((objp = mp->mp_next) != NULL) mp->mp_next = mp->mp_next->ph_next; @@ -164,7 +164,7 @@ void chPoolFreeI(memory_pool_t *mp, void *objp) { struct pool_header *php = objp; chDbgCheckClassI(); - chDbgCheck((mp != NULL) && (objp != NULL), "chPoolFreeI"); + chDbgCheck((mp != NULL) && (objp != NULL)); php->ph_next = mp->mp_next; mp->mp_next = php; diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 1e99cce3f..335b46c61 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -88,7 +88,7 @@ msg_t chMsgSend(thread_t *tp, msg_t msg) { thread_t *ctp = currp; - chDbgCheck(tp != NULL, "chMsgSend"); + chDbgCheck(tp != NULL); chSysLock(); ctp->p_msg = msg; @@ -141,8 +141,7 @@ thread_t *chMsgWait(void) { void chMsgRelease(thread_t *tp, msg_t msg) { chSysLock(); - chDbgAssert(tp->p_state == CH_STATE_SNDMSG, - "chMsgRelease(), #1", "invalid state"); + chDbgAssert(tp->p_state == CH_STATE_SNDMSG, "invalid state"); chMsgReleaseS(tp, msg); chSysUnlock(); } diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index 5f7bdfb8d..0eb02e2b5 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -98,7 +98,7 @@ */ void chMtxObjectInit(mutex_t *mp) { - chDbgCheck(mp != NULL, "chMtxInit"); + chDbgCheck(mp != NULL); queue_init(&mp->m_queue); mp->m_owner = NULL; @@ -135,7 +135,7 @@ void chMtxLockS(mutex_t *mp) { thread_t *ctp = currp; chDbgCheckClassS(); - chDbgCheck(mp != NULL, "chMtxLockS"); + chDbgCheck(mp != NULL); /* Is the mutex already locked? */ if (mp->m_owner != NULL) { @@ -194,8 +194,8 @@ void chMtxLockS(mutex_t *mp) { /* It is assumed that the thread performing the unlock operation assigns the mutex to this thread.*/ - chDbgAssert(mp->m_owner == ctp, "chMtxLockS(), #1", "not owner"); - chDbgAssert(ctp->p_mtxlist == mp, "chMtxLockS(), #2", "not owned"); + chDbgAssert(mp->m_owner == ctp, "not owner"); + chDbgAssert(ctp->p_mtxlist == mp, "not owned"); } else { /* It was not owned, inserted in the owned mutexes list.*/ @@ -253,7 +253,7 @@ bool chMtxTryLock(mutex_t *mp) { bool chMtxTryLockS(mutex_t *mp) { chDbgCheckClassS(); - chDbgCheck(mp != NULL, "chMtxTryLockS"); + chDbgCheck(mp != NULL); if (mp->m_owner != NULL) return false; @@ -280,12 +280,8 @@ mutex_t *chMtxUnlock(void) { chSysLock(); - chDbgAssert(ctp->p_mtxlist != NULL, - "chMtxUnlock(), #1", - "owned mutexes list empty"); - chDbgAssert(ctp->p_mtxlist->m_owner == ctp, - "chMtxUnlock(), #2", - "ownership failure"); + chDbgAssert(ctp->p_mtxlist != NULL, "owned mutexes list empty"); + chDbgAssert(ctp->p_mtxlist->m_owner == ctp, "ownership failure"); /* Removes the top mutex from the thread's owned mutexes list and marks it as not owned.*/ @@ -344,12 +340,8 @@ mutex_t *chMtxUnlockS(void) { mutex_t *ump, *mp; chDbgCheckClassS(); - chDbgAssert(ctp->p_mtxlist != NULL, - "chMtxUnlockS(), #1", - "owned mutexes list empty"); - chDbgAssert(ctp->p_mtxlist->m_owner == ctp, - "chMtxUnlockS(), #2", - "ownership failure"); + chDbgAssert(ctp->p_mtxlist != NULL, "owned mutexes list empty"); + chDbgAssert(ctp->p_mtxlist->m_owner == ctp, "ownership failure"); /* Removes the top mutex from the owned mutexes list and marks it as not owned.*/ diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index 7cbc63f50..679d69337 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -245,7 +245,7 @@ size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp, qnotify_t nfy = iqp->q_notify; size_t r = 0; - chDbgCheck(n > 0, "chIQReadTimeout"); + chDbgCheck(n > 0); chSysLock(); while (true) { @@ -425,7 +425,7 @@ size_t chOQWriteTimeout(output_queue_t *oqp, const uint8_t *bp, qnotify_t nfy = oqp->q_notify; size_t w = 0; - chDbgCheck(n > 0, "chOQWriteTimeout"); + chDbgCheck(n > 0); chSysLock(); while (true) { diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c index b0d241fee..685d0c109 100644 --- a/os/kernel/src/chregistry.c +++ b/os/kernel/src/chregistry.c @@ -159,8 +159,7 @@ thread_t *chRegNextThread(thread_t *tp) { ntp = NULL; #if CH_CFG_USE_DYNAMIC else { - chDbgAssert(ntp->p_refs < 255, "chRegNextThread(), #1", - "too many references"); + chDbgAssert(ntp->p_refs < 255, "too many references"); ntp->p_refs++; } #endif diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 53a14dac7..615008589 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -91,7 +91,6 @@ thread_t *chSchReadyI(thread_t *tp) { /* Integrity checks.*/ chDbgAssert((tp->p_state != CH_STATE_READY) && (tp->p_state != CH_STATE_FINAL), - "chSchReadyI(), #1", "invalid state"); tp->p_state = CH_STATE_READY; diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index d25b93822..388e50bc6 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -98,7 +98,7 @@ */ void chSemObjectInit(semaphore_t *sp, cnt_t n) { - chDbgCheck((sp != NULL) && (n >= 0), "chSemInit"); + chDbgCheck((sp != NULL) && (n >= 0)); queue_init(&sp->s_queue); sp->s_cnt = n; @@ -150,10 +150,9 @@ void chSemResetI(semaphore_t *sp, cnt_t n) { cnt_t cnt; chDbgCheckClassI(); - chDbgCheck((sp != NULL) && (n >= 0), "chSemResetI"); + chDbgCheck((sp != NULL) && (n >= 0)); chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "chSemResetI(), #1", "inconsistent semaphore"); cnt = sp->s_cnt; @@ -198,10 +197,9 @@ msg_t chSemWait(semaphore_t *sp) { msg_t chSemWaitS(semaphore_t *sp) { chDbgCheckClassS(); - chDbgCheck(sp != NULL, "chSemWaitS"); + chDbgCheck(sp != NULL); chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "chSemWaitS(), #1", "inconsistent semaphore"); if (--sp->s_cnt < 0) { @@ -263,10 +261,9 @@ msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time) { msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { chDbgCheckClassS(); - chDbgCheck(sp != NULL, "chSemWaitTimeoutS"); + chDbgCheck(sp != NULL); chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "chSemWaitTimeoutS(), #1", "inconsistent semaphore"); if (--sp->s_cnt < 0) { @@ -290,10 +287,9 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { */ void chSemSignal(semaphore_t *sp) { - chDbgCheck(sp != NULL, "chSemSignal"); + chDbgCheck(sp != NULL); chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "chSemSignal(), #1", "inconsistent semaphore"); chSysLock(); @@ -316,10 +312,9 @@ void chSemSignal(semaphore_t *sp) { void chSemSignalI(semaphore_t *sp) { chDbgCheckClassI(); - chDbgCheck(sp != NULL, "chSemSignalI"); + chDbgCheck(sp != NULL); chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "chSemSignalI(), #1", "inconsistent semaphore"); if (++sp->s_cnt <= 0) { @@ -347,10 +342,9 @@ void chSemSignalI(semaphore_t *sp) { void chSemAddCounterI(semaphore_t *sp, cnt_t n) { chDbgCheckClassI(); - chDbgCheck((sp != NULL) && (n > 0), "chSemAddCounterI"); + chDbgCheck((sp != NULL) && (n > 0)); chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "chSemAddCounterI(), #1", "inconsistent semaphore"); while (n > 0) { @@ -376,14 +370,12 @@ void chSemAddCounterI(semaphore_t *sp, cnt_t n) { msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { msg_t msg; - chDbgCheck((sps != NULL) && (spw != NULL), "chSemSignalWait"); + chDbgCheck((sps != NULL) && (spw != NULL)); chDbgAssert(((sps->s_cnt >= 0) && queue_isempty(&sps->s_queue)) || ((sps->s_cnt < 0) && queue_notempty(&sps->s_queue)), - "chSemSignalWait(), #1", "inconsistent semaphore"); chDbgAssert(((spw->s_cnt >= 0) && queue_isempty(&spw->s_queue)) || ((spw->s_cnt < 0) && queue_notempty(&spw->s_queue)), - "chSemSignalWait(), #2", "inconsistent semaphore"); chSysLock(); diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index a18e82005..073b6eed7 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -183,8 +183,7 @@ thread_t *chThdCreateI(void *wsp, size_t size, chDbgCheckClassI(); chDbgCheck((wsp != NULL) && (size >= THD_WA_SIZE(0)) && - (prio <= HIGHPRIO) && (pf != NULL), - "chThdCreateI"); + (prio <= HIGHPRIO) && (pf != NULL)); SETUP_CONTEXT(wsp, size, pf, arg); return _thread_init(tp, prio); } @@ -238,7 +237,7 @@ thread_t *chThdCreateStatic(void *wsp, size_t size, tprio_t chThdSetPriority(tprio_t newprio) { tprio_t oldprio; - chDbgCheck(newprio <= HIGHPRIO, "chThdSetPriority"); + chDbgCheck(newprio <= HIGHPRIO); chSysLock(); #if CH_CFG_USE_MUTEXES @@ -272,7 +271,6 @@ thread_t *chThdResume(thread_t *tp) { chSysLock(); chDbgAssert(tp->p_state == CH_STATE_SUSPENDED, - "chThdResume(), #1", "thread not in CH_STATE_SUSPENDED state"); chSchWakeupS(tp, RDY_OK); chSysUnlock(); @@ -312,7 +310,7 @@ void chThdTerminate(thread_t *tp) { */ void chThdSleep(systime_t time) { - chDbgCheck(time != TIME_IMMEDIATE, "chThdSleep"); + chDbgCheck(time != TIME_IMMEDIATE); chSysLock(); chThdSleepS(time); @@ -403,7 +401,7 @@ void chThdExitS(msg_t msg) { #endif chSchGoSleepS(CH_STATE_FINAL); /* The thread never returns here.*/ - chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); + chDbgAssert(false, "zombies apocalypse"); } #if CH_CFG_USE_WAITEXIT || defined(__DOXYGEN__) @@ -441,12 +439,12 @@ void chThdExitS(msg_t msg) { msg_t chThdWait(thread_t *tp) { msg_t msg; - chDbgCheck(tp != NULL, "chThdWait"); + chDbgCheck(tp != NULL); chSysLock(); - chDbgAssert(tp != currp, "chThdWait(), #1", "waiting self"); + chDbgAssert(tp != currp, "waiting self"); #if CH_CFG_USE_DYNAMIC - chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced"); + chDbgAssert(tp->p_refs > 0, "not referenced"); #endif if (tp->p_state != CH_STATE_FINAL) { list_insert(currp, &tp->p_waiting); diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index 6fa4dd582..3f1559ac4 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -118,8 +118,7 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, virtual_timer_t *p; chDbgCheckClassI(); - chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE), - "chVTDoSetI"); + chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE)); vtp->vt_par = par; vtp->vt_func = vtfunc; @@ -181,10 +180,8 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, void chVTDoResetI(virtual_timer_t *vtp) { chDbgCheckClassI(); - chDbgCheck(vtp != NULL, "chVTDoResetI"); - chDbgAssert(vtp->vt_func != NULL, - "chVTDoResetI(), #1", - "timer not set or already triggered"); + chDbgCheck(vtp != NULL); + chDbgAssert(vtp->vt_func != NULL, "timer not set or already triggered"); /* Removing the element from the delta list.*/ vtp->vt_next->vt_delta += vtp->vt_delta; -- cgit v1.2.3 From a1435e018bfc9919cb76b1356509ecc883767fb4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 14:51:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6123 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chcond.c | 305 ------------------------ os/kernel/src/chdebug.c | 260 -------------------- os/kernel/src/chdynamic.c | 228 ------------------ os/kernel/src/chevents.c | 573 --------------------------------------------- os/kernel/src/chheap.c | 276 ---------------------- os/kernel/src/chlists.c | 180 -------------- os/kernel/src/chmboxes.c | 398 ------------------------------- os/kernel/src/chmemcore.c | 153 ------------ os/kernel/src/chmempools.c | 194 --------------- os/kernel/src/chmsg.c | 151 ------------ os/kernel/src/chmtx.c | 420 --------------------------------- os/kernel/src/chqueues.c | 455 ----------------------------------- os/kernel/src/chregistry.c | 175 -------------- os/kernel/src/chschd.c | 372 ----------------------------- os/kernel/src/chsem.c | 401 ------------------------------- os/kernel/src/chstats.c | 122 ---------- os/kernel/src/chsys.c | 298 ----------------------- os/kernel/src/chthreads.c | 462 ------------------------------------ os/kernel/src/chtm.c | 155 ------------ os/kernel/src/chvt.c | 211 ----------------- 20 files changed, 5789 deletions(-) delete mode 100644 os/kernel/src/chcond.c delete mode 100644 os/kernel/src/chdebug.c delete mode 100644 os/kernel/src/chdynamic.c delete mode 100644 os/kernel/src/chevents.c delete mode 100644 os/kernel/src/chheap.c delete mode 100644 os/kernel/src/chlists.c delete mode 100644 os/kernel/src/chmboxes.c delete mode 100644 os/kernel/src/chmemcore.c delete mode 100644 os/kernel/src/chmempools.c delete mode 100644 os/kernel/src/chmsg.c delete mode 100644 os/kernel/src/chmtx.c delete mode 100644 os/kernel/src/chqueues.c delete mode 100644 os/kernel/src/chregistry.c delete mode 100644 os/kernel/src/chschd.c delete mode 100644 os/kernel/src/chsem.c delete mode 100644 os/kernel/src/chstats.c delete mode 100644 os/kernel/src/chsys.c delete mode 100644 os/kernel/src/chthreads.c delete mode 100644 os/kernel/src/chtm.c delete mode 100644 os/kernel/src/chvt.c (limited to 'os/kernel/src') diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c deleted file mode 100644 index 94fd8e81c..000000000 --- a/os/kernel/src/chcond.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ -/* - Concepts and parts of this file have been contributed by Leon Woestenberg. - */ - -/** - * @file chcond.c - * @brief Condition Variables code. - * - * @addtogroup condition variables Condition Variables - * @details This module implements the Condition Variables mechanism. Condition - * variables are an extensions to the mutex subsystem and cannot - * work alone. - *

Operation mode

- * The condition variable is a synchronization object meant to be - * used inside a zone protected by a mutex. Mutexes and condition - * variables together can implement a Monitor construct. - * @pre In order to use the condition variable APIs the @p CH_CFG_USE_CONDVARS - * option must be enabled in @p chconf.h. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_CONDVARS || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes s @p condition_variable_t structure. - * - * @param[out] cp pointer to a @p condition_variable_t structure - * - * @init - */ -void chCondObjectInit(condition_variable_t *cp) { - - chDbgCheck(cp != NULL); - - queue_init(&cp->c_queue); -} - -/** - * @brief Signals one thread that is waiting on the condition variable. - * - * @param[in] cp pointer to the @p condition_variable_t structure - * - * @api - */ -void chCondSignal(condition_variable_t *cp) { - - chDbgCheck(cp != NULL); - - chSysLock(); - if (queue_notempty(&cp->c_queue)) - chSchWakeupS(queue_fifo_remove(&cp->c_queue), RDY_OK); - chSysUnlock(); -} - -/** - * @brief Signals one thread that is waiting on the condition variable. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. Note that - * interrupt handlers always reschedule on exit so an explicit - * reschedule must not be performed in ISRs. - * - * @param[in] cp pointer to the @p condition_variable_t structure - * - * @iclass - */ -void chCondSignalI(condition_variable_t *cp) { - - chDbgCheckClassI(); - chDbgCheck(cp != NULL); - - if (queue_notempty(&cp->c_queue)) - chSchReadyI(queue_fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_OK; -} - -/** - * @brief Signals all threads that are waiting on the condition variable. - * - * @param[in] cp pointer to the @p condition_variable_t structure - * - * @api - */ -void chCondBroadcast(condition_variable_t *cp) { - - chSysLock(); - chCondBroadcastI(cp); - chSchRescheduleS(); - chSysUnlock(); -} - -/** - * @brief Signals all threads that are waiting on the condition variable. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. Note that - * interrupt handlers always reschedule on exit so an explicit - * reschedule must not be performed in ISRs. - * - * @param[in] cp pointer to the @p condition_variable_t structure - * - * @iclass - */ -void chCondBroadcastI(condition_variable_t *cp) { - - chDbgCheckClassI(); - chDbgCheck(cp != NULL); - - /* Empties the condition variable queue and inserts all the threads into the - ready list in FIFO order. The wakeup message is set to @p RDY_RESET in - order to make a chCondBroadcast() detectable from a chCondSignal().*/ - while (cp->c_queue.p_next != (void *)&cp->c_queue) - chSchReadyI(queue_fifo_remove(&cp->c_queue))->p_u.rdymsg = RDY_RESET; -} - -/** - * @brief Waits on the condition variable releasing the mutex lock. - * @details Releases the currently owned mutex, waits on the condition - * variable, and finally acquires the mutex again. All the sequence - * is performed atomically. - * @pre The invoking thread must have at least one owned mutex. - * - * @param[in] cp pointer to the @p condition_variable_t structure - * @return A message specifying how the invoking thread has been - * released from the condition variable. - * @retval RDY_OK if the condition variable has been signaled using - * @p chCondSignal(). - * @retval RDY_RESET if the condition variable has been signaled using - * @p chCondBroadcast(). - * - * @api - */ -msg_t chCondWait(condition_variable_t *cp) { - msg_t msg; - - chSysLock(); - msg = chCondWaitS(cp); - chSysUnlock(); - return msg; -} - -/** - * @brief Waits on the condition variable releasing the mutex lock. - * @details Releases the currently owned mutex, waits on the condition - * variable, and finally acquires the mutex again. All the sequence - * is performed atomically. - * @pre The invoking thread must have at least one owned mutex. - * - * @param[in] cp pointer to the @p condition_variable_t structure - * @return A message specifying how the invoking thread has been - * released from the condition variable. - * @retval RDY_OK if the condition variable has been signaled using - * @p chCondSignal(). - * @retval RDY_RESET if the condition variable has been signaled using - * @p chCondBroadcast(). - * - * @sclass - */ -msg_t chCondWaitS(condition_variable_t *cp) { - thread_t *ctp = currp; - mutex_t *mp; - msg_t msg; - - chDbgCheckClassS(); - chDbgCheck(cp != NULL); - chDbgAssert(ctp->p_mtxlist != NULL, "not owning a mutex"); - - mp = chMtxUnlockS(); - ctp->p_u.wtobjp = cp; - queue_prio_insert(ctp, &cp->c_queue); - chSchGoSleepS(CH_STATE_WTCOND); - msg = ctp->p_u.rdymsg; - chMtxLockS(mp); - return msg; -} - -#if CH_CFG_USE_CONDVARS_TIMEOUT || defined(__DOXYGEN__) -/** - * @brief Waits on the condition variable releasing the mutex lock. - * @details Releases the currently owned mutex, waits on the condition - * variable, and finally acquires the mutex again. All the sequence - * is performed atomically. - * @pre The invoking thread must have at least one owned mutex. - * @pre The configuration option @p CH_CFG_USE_CONDVARS_TIMEOUT must be enabled - * in order to use this function. - * @post Exiting the function because a timeout does not re-acquire the - * mutex, the mutex ownership is lost. - * - * @param[in] cp pointer to the @p condition_variable_t structure - * @param[in] time the number of ticks before the operation timeouts, the - * special values are handled as follow: - * - @a TIME_INFINITE no timeout. - * - @a TIME_IMMEDIATE this value is not allowed. - * . - * @return A message specifying how the invoking thread has been - * released from the condition variable. - * @retval RDY_OK if the condition variable has been signaled using - * @p chCondSignal(). - * @retval RDY_RESET if the condition variable has been signaled using - * @p chCondBroadcast(). - * @retval RDY_TIMEOUT if the condition variable has not been signaled within - * the specified timeout. - * - * @api - */ -msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) { - msg_t msg; - - chSysLock(); - msg = chCondWaitTimeoutS(cp, time); - chSysUnlock(); - return msg; -} - -/** - * @brief Waits on the condition variable releasing the mutex lock. - * @details Releases the currently owned mutex, waits on the condition - * variable, and finally acquires the mutex again. All the sequence - * is performed atomically. - * @pre The invoking thread must have at least one owned mutex. - * @pre The configuration option @p CH_CFG_USE_CONDVARS_TIMEOUT must be enabled - * in order to use this function. - * @post Exiting the function because a timeout does not re-acquire the - * mutex, the mutex ownership is lost. - * - * @param[in] cp pointer to the @p condition_variable_t structure - * @param[in] time the number of ticks before the operation timeouts, the - * special values are handled as follow: - * - @a TIME_INFINITE no timeout. - * - @a TIME_IMMEDIATE this value is not allowed. - * . - * @return A message specifying how the invoking thread has been - * released from the condition variable. - * @retval RDY_OK if the condition variable has been signaled using - * @p chCondSignal(). - * @retval RDY_RESET if the condition variable has been signaled using - * @p chCondBroadcast(). - * @retval RDY_TIMEOUT if the condition variable has not been signaled within - * the specified timeout. - * - * @sclass - */ -msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { - mutex_t *mp; - msg_t msg; - - chDbgCheckClassS(); - chDbgCheck((cp != NULL) && (time != TIME_IMMEDIATE)); - chDbgAssert(currp->p_mtxlist != NULL, "not owning a mutex"); - - mp = chMtxUnlockS(); - currp->p_u.wtobjp = cp; - queue_prio_insert(currp, &cp->c_queue); - msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, time); - if (msg != RDY_TIMEOUT) - chMtxLockS(mp); - return msg; -} -#endif /* CH_CFG_USE_CONDVARS_TIMEOUT */ - -#endif /* CH_CFG_USE_CONDVARS */ - -/** @} */ diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c deleted file mode 100644 index 05b746357..000000000 --- a/os/kernel/src/chdebug.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chdebug.c - * @brief ChibiOS/RT Debug code. - * - * @addtogroup debug - * @details Debug APIs and services: - * - Runtime system state and call protocol check. The following - * panic messages can be generated: - * - SV#1, misplaced @p chSysDisable(). - * - SV#2, misplaced @p chSysSuspend() - * - SV#3, misplaced @p chSysEnable(). - * - SV#4, misplaced @p chSysLock(). - * - SV#5, misplaced @p chSysUnlock(). - * - SV#6, misplaced @p chSysLockFromIsr(). - * - SV#7, misplaced @p chSysUnlockFromIsr(). - * - SV#8, misplaced @p CH_IRQ_PROLOGUE(). - * - SV#9, misplaced @p CH_IRQ_EPILOGUE(). - * - SV#10, misplaced I-class function. - * - SV#11, misplaced S-class function. - * . - * - Trace buffer. - * - Parameters check. - * - Kernel assertions. - * - Kernel panics. - * . - * @note Stack checks are not implemented in this module but in the port - * layer in an architecture-dependent way. - * @{ - */ - -#include "ch.h" - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -#if CH_DBG_SYSTEM_STATE_CHECK || defined(__DOXYGEN__) -/** - * @brief Guard code for @p chSysDisable(). - * - * @notapi - */ -void _dbg_check_disable(void) { - - if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt != 0)) - chDbgPanic("SV#1"); -} - -/** - * @brief Guard code for @p chSysSuspend(). - * - * @notapi - */ -void _dbg_check_suspend(void) { - - if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt != 0)) - chDbgPanic("SV#2"); -} - -/** - * @brief Guard code for @p chSysEnable(). - * - * @notapi - */ -void _dbg_check_enable(void) { - - if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt != 0)) - chDbgPanic("SV#3"); -} - -/** - * @brief Guard code for @p chSysLock(). - * - * @notapi - */ -void _dbg_check_lock(void) { - - if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt != 0)) - chDbgPanic("SV#4"); - _dbg_enter_lock(); -} - -/** - * @brief Guard code for @p chSysUnlock(). - * - * @notapi - */ -void _dbg_check_unlock(void) { - - if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt <= 0)) - chDbgPanic("SV#5"); - _dbg_leave_lock(); -} - -/** - * @brief Guard code for @p chSysLockFromIsr(). - * - * @notapi - */ -void _dbg_check_lock_from_isr(void) { - - if ((ch.dbg_isr_cnt <= 0) || (ch.dbg_lock_cnt != 0)) - chDbgPanic("SV#6"); - _dbg_enter_lock(); -} - -/** - * @brief Guard code for @p chSysUnlockFromIsr(). - * - * @notapi - */ -void _dbg_check_unlock_from_isr(void) { - - if ((ch.dbg_isr_cnt <= 0) || (ch.dbg_lock_cnt <= 0)) - chDbgPanic("SV#7"); - _dbg_leave_lock(); -} - -/** - * @brief Guard code for @p CH_IRQ_PROLOGUE(). - * - * @notapi - */ -void _dbg_check_enter_isr(void) { - - port_lock_from_isr(); - if ((ch.dbg_isr_cnt < 0) || (ch.dbg_lock_cnt != 0)) - chDbgPanic("SV#8"); - ch.dbg_isr_cnt++; - port_unlock_from_isr(); -} - -/** - * @brief Guard code for @p CH_IRQ_EPILOGUE(). - * - * @notapi - */ -void _dbg_check_leave_isr(void) { - - port_lock_from_isr(); - if ((ch.dbg_isr_cnt <= 0) || (ch.dbg_lock_cnt != 0)) - chDbgPanic("SV#9"); - ch.dbg_isr_cnt--; - port_unlock_from_isr(); -} - -/** - * @brief I-class functions context check. - * @details Verifies that the system is in an appropriate state for invoking - * an I-class API function. A panic is generated if the state is - * not compatible. - * - * @api - */ -void chDbgCheckClassI(void) { - - if ((ch.dbg_isr_cnt < 0) || (ch.dbg_lock_cnt <= 0)) - chDbgPanic("SV#10"); -} - -/** - * @brief S-class functions context check. - * @details Verifies that the system is in an appropriate state for invoking - * an S-class API function. A panic is generated if the state is - * not compatible. - * - * @api - */ -void chDbgCheckClassS(void) { - - if ((ch.dbg_isr_cnt != 0) || (ch.dbg_lock_cnt <= 0)) - chDbgPanic("SV#11"); -} - -#endif /* CH_DBG_SYSTEM_STATE_CHECK */ - -#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) -/** - * @brief Trace circular buffer subsystem initialization. - * @note Internal use only. - */ -void _trace_init(void) { - - ch.dbg_trace_buffer.tb_size = CH_DBG_TRACE_BUFFER_SIZE; - ch.dbg_trace_buffer.tb_ptr = &ch.dbg_trace_buffer.tb_buffer[0]; -} - -/** - * @brief Inserts in the circular debug trace buffer a context switch record. - * - * @param[in] otp the thread being switched out - * - * @notapi - */ -void _dbg_trace(thread_t *otp) { - - ch.dbg_trace_buffer.tb_ptr->se_time = chVTGetSystemTimeX(); - ch.dbg_trace_buffer.tb_ptr->se_tp = currp; - ch.dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp; - ch.dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state; - if (++ch.dbg_trace_buffer.tb_ptr >= - &ch.dbg_trace_buffer.tb_buffer[CH_DBG_TRACE_BUFFER_SIZE]) - ch.dbg_trace_buffer.tb_ptr = &ch.dbg_trace_buffer.tb_buffer[0]; -} -#endif /* CH_DBG_ENABLE_TRACE */ - -#if CH_DBG_ENABLED || defined(__DOXYGEN__) -/** - * @brief Prints a panic message on the console and then halts the system. - * - * @param[in] msg the pointer to the panic message string - */ -void chDbgPanic(const char *msg) { - - ch.dbg_panic_msg = msg; - chSysHalt(); -} -#endif /* CH_DBG_ENABLED */ - -/** @} */ diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c deleted file mode 100644 index 5f174eda7..000000000 --- a/os/kernel/src/chdynamic.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chdynamic.c - * @brief Dynamic threads code. - * - * @addtogroup dynamic_threads - * @details Dynamic threads related APIs and services. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_DYNAMIC || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Adds a reference to a thread object. - * @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in order - * to use this function. - * - * @param[in] tp pointer to the thread - * @return The same thread pointer passed as parameter - * representing the new reference. - * - * @api - */ -thread_t *chThdAddRef(thread_t *tp) { - - chSysLock(); - chDbgAssert(tp->p_refs < 255, "too many references"); - tp->p_refs++; - chSysUnlock(); - return tp; -} - -/** - * @brief Releases a reference to a thread object. - * @details If the references counter reaches zero and the thread - * is in the @p CH_STATE_FINAL state then the thread's memory is - * returned to the proper allocator. - * @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in order - * to use this function. - * @note Static threads are not affected. - * - * @param[in] tp pointer to the thread - * - * @api - */ -void chThdRelease(thread_t *tp) { - trefs_t refs; - - chSysLock(); - chDbgAssert(tp->p_refs > 0, "not referenced"); - refs = --tp->p_refs; - chSysUnlock(); - - /* If the references counter reaches zero and the thread is in its - terminated state then the memory can be returned to the proper - allocator. Of course static threads are not affected.*/ - if ((refs == 0) && (tp->p_state == CH_STATE_FINAL)) { - switch (tp->p_flags & CH_FLAG_MODE_MASK) { -#if CH_CFG_USE_HEAP - case CH_FLAG_MODE_HEAP: -#if CH_CFG_USE_REGISTRY - REG_REMOVE(tp); -#endif - chHeapFree(tp); - break; -#endif -#if CH_CFG_USE_MEMPOOLS - case CH_FLAG_MODE_MEMPOOL: -#if CH_CFG_USE_REGISTRY - REG_REMOVE(tp); -#endif - chPoolFree(tp->p_mpool, tp); - break; -#endif - } - } -} - -#if CH_CFG_USE_HEAP || defined(__DOXYGEN__) -/** - * @brief Creates a new thread allocating the memory from the heap. - * @pre The configuration options @p CH_CFG_USE_DYNAMIC and @p CH_CFG_USE_HEAP - * must be enabled in order to use this function. - * @note A thread can terminate by calling @p chThdExit() or by simply - * returning from its main function. - * @note The memory allocated for the thread is not released when the thread - * terminates but when a @p chThdWait() is performed. - * - * @param[in] heapp heap from which allocate the memory or @p NULL for the - * default heap - * @param[in] size size of the working area to be allocated - * @param[in] prio the priority level for the new thread - * @param[in] pf the thread function - * @param[in] arg an argument passed to the thread function. It can be - * @p NULL. - * @return The pointer to the @p thread_t structure allocated for - * the thread into the working space area. - * @retval NULL if the memory cannot be allocated. - * - * @api - */ -thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, - tprio_t prio, tfunc_t pf, void *arg) { - void *wsp; - thread_t *tp; - - wsp = chHeapAlloc(heapp, size); - if (wsp == NULL) - return NULL; - -#if CH_DBG_FILL_THREADS - _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(thread_t), - CH_DBG_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(thread_t), - (uint8_t *)wsp + size, - CH_DBG_STACK_FILL_VALUE); -#endif - - chSysLock(); - tp = chThdCreateI(wsp, size, prio, pf, arg); - tp->p_flags = CH_FLAG_MODE_HEAP; - chSchWakeupS(tp, RDY_OK); - chSysUnlock(); - return tp; -} -#endif /* CH_CFG_USE_HEAP */ - -#if CH_CFG_USE_MEMPOOLS || defined(__DOXYGEN__) -/** - * @brief Creates a new thread allocating the memory from the specified - * memory pool. - * @pre The configuration options @p CH_CFG_USE_DYNAMIC and @p CH_CFG_USE_MEMPOOLS - * must be enabled in order to use this function. - * @note A thread can terminate by calling @p chThdExit() or by simply - * returning from its main function. - * @note The memory allocated for the thread is not released when the thread - * terminates but when a @p chThdWait() is performed. - * - * @param[in] mp pointer to the memory pool object - * @param[in] prio the priority level for the new thread - * @param[in] pf the thread function - * @param[in] arg an argument passed to the thread function. It can be - * @p NULL. - * @return The pointer to the @p thread_t structure allocated for - * the thread into the working space area. - * @retval NULL if the memory pool is empty. - * - * @api - */ -thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, - tfunc_t pf, void *arg) { - void *wsp; - thread_t *tp; - - chDbgCheck(mp != NULL); - - wsp = chPoolAlloc(mp); - if (wsp == NULL) - return NULL; - -#if CH_DBG_FILL_THREADS - _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(thread_t), - CH_DBG_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(thread_t), - (uint8_t *)wsp + mp->mp_object_size, - CH_DBG_STACK_FILL_VALUE); -#endif - - chSysLock(); - tp = chThdCreateI(wsp, mp->mp_object_size, prio, pf, arg); - tp->p_flags = CH_FLAG_MODE_MEMPOOL; - tp->p_mpool = mp; - chSchWakeupS(tp, RDY_OK); - chSysUnlock(); - return tp; -} -#endif /* CH_CFG_USE_MEMPOOLS */ - -#endif /* CH_CFG_USE_DYNAMIC */ - -/** @} */ diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c deleted file mode 100644 index 04b0e6fb8..000000000 --- a/os/kernel/src/chevents.c +++ /dev/null @@ -1,573 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ -/* - Concepts and parts of this file have been contributed by Scott (skute). - */ - -/** - * @file chevents.c - * @brief Events code. - * - * @addtogroup events - * @details Event Flags, Event Sources and Event Listeners. - *

Operation mode

- * Each thread has a mask of pending event flags inside its - * @p thread_t structure. - * Operations defined for event flags: - * - Wait, the invoking thread goes to sleep until a certain - * AND/OR combination of event flags becomes pending. - * - Clear, a mask of event flags is cleared from the pending - * events mask, the cleared event flags mask is returned (only the - * flags that were actually pending and then cleared). - * - Signal, an event mask is directly ORed to the mask of the - * signaled thread. - * - Broadcast, each thread registered on an Event Source is - * signaled with the event flags specified in its Event Listener. - * - Dispatch, an events mask is scanned and for each bit set - * to one an associated handler function is invoked. Bit masks are - * scanned from bit zero upward. - * . - * An Event Source is a special object that can be "broadcasted" by - * a thread or an interrupt service routine. Broadcasting an Event - * Source has the effect that all the threads registered on the - * Event Source will be signaled with an events mask.
- * An unlimited number of Event Sources can exists in a system and - * each thread can be listening on an unlimited number of - * them. - * @pre In order to use the Events APIs the @p CH_CFG_USE_EVENTS option must be - * enabled in @p chconf.h. - * @post Enabling events requires 1-4 (depending on the architecture) - * extra bytes in the @p thread_t structure. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Registers an Event Listener on an Event Source. - * @details Once a thread has registered as listener on an event source it - * will be notified of all events broadcasted there. - * @note Multiple Event Listeners can specify the same bits to be ORed to - * different threads. - * - * @param[in] esp pointer to the @p event_source_t structure - * @param[in] elp pointer to the @p event_listener_t structure - * @param[in] mask the mask of event flags to be ORed to the thread when - * the event source is broadcasted - * - * @api - */ -void chEvtRegisterMask(event_source_t *esp, - event_listener_t *elp, - eventmask_t mask) { - - chDbgCheck((esp != NULL) && (elp != NULL)); - - chSysLock(); - elp->el_next = esp->es_next; - esp->es_next = elp; - elp->el_listener = currp; - elp->el_mask = mask; - elp->el_flags = 0; - chSysUnlock(); -} - -/** - * @brief Unregisters an Event Listener from its Event Source. - * @note If the event listener is not registered on the specified event - * source then the function does nothing. - * @note For optimal performance it is better to perform the unregister - * operations in inverse order of the register operations (elements - * are found on top of the list). - * - * @param[in] esp pointer to the @p event_source_t structure - * @param[in] elp pointer to the @p event_listener_t structure - * - * @api - */ -void chEvtUnregister(event_source_t *esp, event_listener_t *elp) { - event_listener_t *p; - - chDbgCheck((esp != NULL) && (elp != NULL)); - - p = (event_listener_t *)esp; - chSysLock(); - while (p->el_next != (event_listener_t *)esp) { - if (p->el_next == elp) { - p->el_next = elp->el_next; - break; - } - p = p->el_next; - } - chSysUnlock(); -} - -/** - * @brief Clears the pending events specified in the mask. - * - * @param[in] mask the events to be cleared - * @return The pending events that were cleared. - * - * @api - */ -eventmask_t chEvtGetAndClearEvents(eventmask_t mask) { - eventmask_t m; - - chSysLock(); - - m = currp->p_epending & mask; - currp->p_epending &= ~mask; - - chSysUnlock(); - return m; -} - -/** - * @brief Adds (OR) a set of event flags on the current thread, this is - * @b much faster than using @p chEvtBroadcast() or @p chEvtSignal(). - * - * @param[in] mask the event flags to be added - * @return The current pending events mask. - * - * @api - */ -eventmask_t chEvtAddEvents(eventmask_t mask) { - - chSysLock(); - - mask = (currp->p_epending |= mask); - - chSysUnlock(); - return mask; -} - -/** - * @brief Signals all the Event Listeners registered on the specified Event - * Source. - * @details This function variants ORs the specified event flags to all the - * threads registered on the @p event_source_t in addition to the - * event flags specified by the threads themselves in the - * @p event_listener_t objects. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. Note that - * interrupt handlers always reschedule on exit so an explicit - * reschedule must not be performed in ISRs. - * - * @param[in] esp pointer to the @p event_source_t structure - * @param[in] flags the flags set to be added to the listener flags mask - * - * @iclass - */ -void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) { - event_listener_t *elp; - - chDbgCheckClassI(); - chDbgCheck(esp != NULL); - - elp = esp->es_next; - while (elp != (event_listener_t *)esp) { - elp->el_flags |= flags; - chEvtSignalI(elp->el_listener, elp->el_mask); - elp = elp->el_next; - } -} - -/** - * @brief Returns the flags associated to an @p event_listener_t. - * @details The flags are returned and the @p event_listener_t flags mask is - * cleared. - * - * @param[in] elp pointer to the @p event_listener_t structure - * @return The flags added to the listener by the associated - * event source. - * - * @iclass - */ -eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) { - eventflags_t flags; - - chSysLock(); - - flags = elp->el_flags; - elp->el_flags = 0; - - chSysUnlock(); - return flags; -} - -/** - * @brief Adds a set of event flags directly to the specified @p thread_t. - * - * @param[in] tp the thread to be signaled - * @param[in] mask the event flags set to be ORed - * - * @api - */ -void chEvtSignal(thread_t *tp, eventmask_t mask) { - - chDbgCheck(tp != NULL); - - chSysLock(); - chEvtSignalI(tp, mask); - chSchRescheduleS(); - chSysUnlock(); -} - -/** - * @brief Adds a set of event flags directly to the specified @p thread_t. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. Note that - * interrupt handlers always reschedule on exit so an explicit - * reschedule must not be performed in ISRs. - * - * @param[in] tp the thread to be signaled - * @param[in] mask the event flags set to be ORed - * - * @iclass - */ -void chEvtSignalI(thread_t *tp, eventmask_t mask) { - - chDbgCheckClassI(); - chDbgCheck(tp != NULL); - - tp->p_epending |= mask; - /* Test on the AND/OR conditions wait states.*/ - if (((tp->p_state == CH_STATE_WTOREVT) && - ((tp->p_epending & tp->p_u.ewmask) != 0)) || - ((tp->p_state == CH_STATE_WTANDEVT) && - ((tp->p_epending & tp->p_u.ewmask) == tp->p_u.ewmask))) - chSchReadyI(tp)->p_u.rdymsg = RDY_OK; -} - -/** - * @brief Signals all the Event Listeners registered on the specified Event - * Source. - * @details This function variants ORs the specified event flags to all the - * threads registered on the @p event_source_t in addition to the - * event flags specified by the threads themselves in the - * @p event_listener_t objects. - * - * @param[in] esp pointer to the @p event_source_t structure - * @param[in] flags the flags set to be added to the listener flags mask - * - * @api - */ -void chEvtBroadcastFlags(event_source_t *esp, eventflags_t flags) { - - chSysLock(); - chEvtBroadcastFlagsI(esp, flags); - chSchRescheduleS(); - chSysUnlock(); -} - -/** - * @brief Returns the flags associated to an @p event_listener_t. - * @details The flags are returned and the @p event_listener_t flags mask is - * cleared. - * - * @param[in] elp pointer to the @p event_listener_t structure - * @return The flags added to the listener by the associated - * event source. - * - * @iclass - */ -eventflags_t chEvtGetAndClearFlagsI(event_listener_t *elp) { - eventflags_t flags; - - flags = elp->el_flags; - elp->el_flags = 0; - - return flags; -} - -/** - * @brief Invokes the event handlers associated to an event flags mask. - * - * @param[in] mask mask of the event flags to be dispatched - * @param[in] handlers an array of @p evhandler_t. The array must have size - * equal to the number of bits in eventmask_t. - * - * @api - */ -void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask) { - eventid_t eid; - - chDbgCheck(handlers != NULL); - - eid = 0; - while (mask) { - if (mask & EVENT_MASK(eid)) { - chDbgAssert(handlers[eid] != NULL, "null handler"); - mask &= ~EVENT_MASK(eid); - handlers[eid](eid); - } - eid++; - } -} - -#if CH_CFG_OPTIMIZE_SPEED || !CH_CFG_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__) -/** - * @brief Waits for exactly one of the specified events. - * @details The function waits for one event among those specified in - * @p mask to become pending then the event is cleared and returned. - * @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.
- * This means that Event Listeners with a lower event identifier have - * an higher priority. - * - * @param[in] mask mask of the event flags that the function should wait - * for, @p ALL_EVENTS enables all the events - * @return The mask of the lowest id served and cleared event. - * - * @api - */ -eventmask_t chEvtWaitOne(eventmask_t mask) { - thread_t *ctp = currp; - eventmask_t m; - - chSysLock(); - - if ((m = (ctp->p_epending & mask)) == 0) { - ctp->p_u.ewmask = mask; - chSchGoSleepS(CH_STATE_WTOREVT); - m = ctp->p_epending & mask; - } - m &= -m; - ctp->p_epending &= ~m; - - chSysUnlock(); - return m; -} - -/** - * @brief Waits for any of the specified events. - * @details The function waits for any event among those specified in - * @p mask to become pending then the events are cleared and returned. - * - * @param[in] mask mask of the event flags that the function should wait - * for, @p ALL_EVENTS enables all the events - * @return The mask of the served and cleared events. - * - * @api - */ -eventmask_t chEvtWaitAny(eventmask_t mask) { - thread_t *ctp = currp; - eventmask_t m; - - chSysLock(); - - if ((m = (ctp->p_epending & mask)) == 0) { - ctp->p_u.ewmask = mask; - chSchGoSleepS(CH_STATE_WTOREVT); - m = ctp->p_epending & mask; - } - ctp->p_epending &= ~m; - - chSysUnlock(); - return m; -} - -/** - * @brief Waits for all the specified events. - * @details The function waits for all the events specified in @p mask to - * become pending then the events are cleared and returned. - * - * @param[in] mask mask of the event flags that the function should wait - * for, @p ALL_EVENTS requires all the events - * @return The mask of the served and cleared events. - * - * @api - */ -eventmask_t chEvtWaitAll(eventmask_t mask) { - thread_t *ctp = currp; - - chSysLock(); - - if ((ctp->p_epending & mask) != mask) { - ctp->p_u.ewmask = mask; - chSchGoSleepS(CH_STATE_WTANDEVT); - } - ctp->p_epending &= ~mask; - - chSysUnlock(); - return mask; -} -#endif /* CH_CFG_OPTIMIZE_SPEED || !CH_CFG_USE_EVENTS_TIMEOUT */ - -#if CH_CFG_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__) -/** - * @brief Waits for exactly one of the specified events. - * @details The function waits for one event among those specified in - * @p mask to become pending then the event is cleared and returned. - * @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.
- * This means that Event Listeners with a lower event identifier have - * an higher priority. - * - * @param[in] mask mask of the event flags that the function should wait - * for, @p ALL_EVENTS enables all the events - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The mask of the lowest id served and cleared event. - * @retval 0 if the operation has timed out. - * - * @api - */ -eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time) { - thread_t *ctp = currp; - eventmask_t m; - - chSysLock(); - - if ((m = (ctp->p_epending & mask)) == 0) { - if (TIME_IMMEDIATE == time) { - chSysUnlock(); - return (eventmask_t)0; - } - ctp->p_u.ewmask = mask; - if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < RDY_OK) { - chSysUnlock(); - return (eventmask_t)0; - } - m = ctp->p_epending & mask; - } - m &= -m; - ctp->p_epending &= ~m; - - chSysUnlock(); - return m; -} - -/** - * @brief Waits for any of the specified events. - * @details The function waits for any event among those specified in - * @p mask to become pending then the events are cleared and - * returned. - * - * @param[in] mask mask of the event flags that the function should wait - * for, @p ALL_EVENTS enables all the events - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The mask of the served and cleared events. - * @retval 0 if the operation has timed out. - * - * @api - */ -eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time) { - thread_t *ctp = currp; - eventmask_t m; - - chSysLock(); - - if ((m = (ctp->p_epending & mask)) == 0) { - if (TIME_IMMEDIATE == time) { - chSysUnlock(); - return (eventmask_t)0; - } - ctp->p_u.ewmask = mask; - if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < RDY_OK) { - chSysUnlock(); - return (eventmask_t)0; - } - m = ctp->p_epending & mask; - } - ctp->p_epending &= ~m; - - chSysUnlock(); - return m; -} - -/** - * @brief Waits for all the specified events. - * @details The function waits for all the events specified in @p mask to - * become pending then the events are cleared and returned. - * - * @param[in] mask mask of the event flags that the function should wait - * for, @p ALL_EVENTS requires all the events - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The mask of the served and cleared events. - * @retval 0 if the operation has timed out. - * - * @api - */ -eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time) { - thread_t *ctp = currp; - - chSysLock(); - - if ((ctp->p_epending & mask) != mask) { - if (TIME_IMMEDIATE == time) { - chSysUnlock(); - return (eventmask_t)0; - } - ctp->p_u.ewmask = mask; - if (chSchGoSleepTimeoutS(CH_STATE_WTANDEVT, time) < RDY_OK) { - chSysUnlock(); - return (eventmask_t)0; - } - } - ctp->p_epending &= ~mask; - - chSysUnlock(); - return mask; -} -#endif /* CH_CFG_USE_EVENTS_TIMEOUT */ - -#endif /* CH_CFG_USE_EVENTS */ - -/** @} */ diff --git a/os/kernel/src/chheap.c b/os/kernel/src/chheap.c deleted file mode 100644 index abda4ff10..000000000 --- a/os/kernel/src/chheap.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chheap.c - * @brief Heaps code. - * - * @addtogroup heaps - * @details Heap Allocator related APIs. - *

Operation mode

- * The heap allocator implements a first-fit strategy and its APIs - * are functionally equivalent to the usual @p malloc() and @p free() - * library functions. The main difference is that the OS heap APIs - * are guaranteed to be thread safe.
- * @pre In order to use the heap APIs the @p CH_CFG_USE_HEAP option must - * be enabled in @p chconf.h. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_HEAP || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/* - * Defaults on the best synchronization mechanism available. - */ -#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) -#define H_LOCK(h) chMtxLock(&(h)->h_mtx) -#define H_UNLOCK(h) chMtxUnlock() -#else -#define H_LOCK(h) chSemWait(&(h)->h_sem) -#define H_UNLOCK(h) chSemSignal(&(h)->h_sem) -#endif - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/** - * @brief Default heap descriptor. - */ -static memory_heap_t default_heap; - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes the default heap. - * - * @notapi - */ -void _heap_init(void) { - default_heap.h_provider = chCoreAlloc; - default_heap.h_free.h.u.next = (union heap_header *)NULL; - default_heap.h_free.h.size = 0; -#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) - chMtxObjectInit(&default_heap.h_mtx); -#else - chSemObjectInit(&default_heap.h_sem, 1); -#endif -} - -/** - * @brief Initializes a memory heap from a static memory area. - * @pre Both the heap buffer base and the heap size must be aligned to - * the @p stkalign_t type size. - * - * @param[out] heapp pointer to the memory heap descriptor to be initialized - * @param[in] buf heap buffer base - * @param[in] size heap size - * - * @init - */ -void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size) { - union heap_header *hp; - - chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size)); - - heapp->h_provider = (memgetfunc_t)NULL; - heapp->h_free.h.u.next = hp = buf; - heapp->h_free.h.size = 0; - hp->h.u.next = NULL; - hp->h.size = size - sizeof(union heap_header); -#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) - chMtxObjectInit(&heapp->h_mtx); -#else - chSemObjectInit(&heapp->h_sem, 1); -#endif -} - -/** - * @brief Allocates a block of memory from the heap by using the first-fit - * algorithm. - * @details The allocated block is guaranteed to be properly aligned for a - * pointer data type (@p stkalign_t). - * - * @param[in] heapp pointer to a heap descriptor or @p NULL in order to - * access the default heap. - * @param[in] size the size of the block to be allocated. Note that the - * allocated block may be a bit bigger than the requested - * size for alignment and fragmentation reasons. - * @return A pointer to the allocated block. - * @retval NULL if the block cannot be allocated. - * - * @api - */ -void *chHeapAlloc(memory_heap_t *heapp, size_t size) { - union heap_header *qp, *hp, *fp; - - if (heapp == NULL) - heapp = &default_heap; - - size = MEM_ALIGN_NEXT(size); - qp = &heapp->h_free; - H_LOCK(heapp); - - while (qp->h.u.next != NULL) { - hp = qp->h.u.next; - if (hp->h.size >= size) { - if (hp->h.size < size + sizeof(union heap_header)) { - /* Gets the whole block even if it is slightly bigger than the - requested size because the fragment would be too small to be - useful.*/ - qp->h.u.next = hp->h.u.next; - } - else { - /* Block bigger enough, must split it.*/ - fp = (void *)((uint8_t *)(hp) + sizeof(union heap_header) + size); - fp->h.u.next = hp->h.u.next; - fp->h.size = hp->h.size - sizeof(union heap_header) - size; - qp->h.u.next = fp; - hp->h.size = size; - } - hp->h.u.heap = heapp; - - H_UNLOCK(heapp); - return (void *)(hp + 1); - } - qp = hp; - } - - H_UNLOCK(heapp); - - /* More memory is required, tries to get it from the associated provider - else fails.*/ - if (heapp->h_provider) { - hp = heapp->h_provider(size + sizeof(union heap_header)); - if (hp != NULL) { - hp->h.u.heap = heapp; - hp->h.size = size; - hp++; - return (void *)hp; - } - } - return NULL; -} - -#define LIMIT(p) (union heap_header *)((uint8_t *)(p) + \ - sizeof(union heap_header) + \ - (p)->h.size) - -/** - * @brief Frees a previously allocated memory block. - * - * @param[in] p pointer to the memory block to be freed - * - * @api - */ -void chHeapFree(void *p) { - union heap_header *qp, *hp; - memory_heap_t *heapp; - - chDbgCheck(p != NULL); - - hp = (union heap_header *)p - 1; - heapp = hp->h.u.heap; - qp = &heapp->h_free; - H_LOCK(heapp); - - while (true) { - chDbgAssert((hp < qp) || (hp >= LIMIT(qp)), "within free block"); - - if (((qp == &heapp->h_free) || (hp > qp)) && - ((qp->h.u.next == NULL) || (hp < qp->h.u.next))) { - /* Insertion after qp.*/ - hp->h.u.next = qp->h.u.next; - qp->h.u.next = hp; - /* Verifies if the newly inserted block should be merged.*/ - if (LIMIT(hp) == hp->h.u.next) { - /* Merge with the next block.*/ - hp->h.size += hp->h.u.next->h.size + sizeof(union heap_header); - hp->h.u.next = hp->h.u.next->h.u.next; - } - if ((LIMIT(qp) == hp)) { - /* Merge with the previous block.*/ - qp->h.size += hp->h.size + sizeof(union heap_header); - qp->h.u.next = hp->h.u.next; - } - break; - } - qp = qp->h.u.next; - } - - H_UNLOCK(heapp); - return; -} - -/** - * @brief Reports the heap status. - * @note This function is meant to be used in the test suite, it should - * not be really useful for the application code. - * - * @param[in] heapp pointer to a heap descriptor or @p NULL in order to - * access the default heap. - * @param[in] sizep pointer to a variable that will receive the total - * fragmented free space - * @return The number of fragments in the heap. - * - * @api - */ -size_t chHeapStatus(memory_heap_t *heapp, size_t *sizep) { - union heap_header *qp; - size_t n, sz; - - if (heapp == NULL) - heapp = &default_heap; - - H_LOCK(heapp); - - sz = 0; - for (n = 0, qp = &heapp->h_free; qp->h.u.next; n++, qp = qp->h.u.next) - sz += qp->h.u.next->h.size; - if (sizep) - *sizep = sz; - - H_UNLOCK(heapp); - return n; -} - -#endif /* CH_CFG_USE_HEAP */ - -/** @} */ diff --git a/os/kernel/src/chlists.c b/os/kernel/src/chlists.c deleted file mode 100644 index 0f492db5f..000000000 --- a/os/kernel/src/chlists.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chlists.c - * @brief Thread queues/lists code. - * - * @addtogroup internals - * @details All the functions present in this module, while public, are not - * OS APIs and should not be directly used in the user applications - * code. - * @{ - */ -#include "ch.h" - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -#if !CH_CFG_OPTIMIZE_SPEED || defined(__DOXYGEN__) -/** - * @brief Inserts a thread into a priority ordered queue. - * @note The insertion is done by scanning the list from the highest - * priority toward the lowest. - * - * @param[in] tp the pointer to the thread to be inserted in the list - * @param[in] tqp the pointer to the threads list header - * - * @notapi - */ -void queue_prio_insert(thread_t *tp, threads_queue_t *tqp) { - - /* cp iterates over the queue.*/ - thread_t *cp = (thread_t *)tqp; - do { - /* Iterate to next thread in queue.*/ - cp = cp->p_next; - /* Not end of queue? and cp has equal or higher priority than tp?.*/ - } while ((cp != (thread_t *)tqp) && (cp->p_prio >= tp->p_prio)); - /* Insertion on p_prev.*/ - tp->p_next = cp; - tp->p_prev = cp->p_prev; - tp->p_prev->p_next = cp->p_prev = tp; -} - -/** - * @brief Inserts a thread into a queue. - * - * @param[in] tp the pointer to the thread to be inserted in the list - * @param[in] tqp the pointer to the threads list header - * - * @notapi - */ -void queue_insert(thread_t *tp, threads_queue_t *tqp) { - - tp->p_next = (thread_t *)tqp; - tp->p_prev = tqp->p_prev; - tp->p_prev->p_next = tqp->p_prev = tp; -} - -/** - * @brief Removes the first-out thread from a queue and returns it. - * @note If the queue is priority ordered then this function returns the - * thread with the highest priority. - * - * @param[in] tqp the pointer to the threads list header - * @return The removed thread pointer. - * - * @notapi - */ -thread_t *queue_fifo_remove(threads_queue_t *tqp) { - thread_t *tp = tqp->p_next; - - (tqp->p_next = tp->p_next)->p_prev = (thread_t *)tqp; - return tp; -} - -/** - * @brief Removes the last-out thread from a queue and returns it. - * @note If the queue is priority ordered then this function returns the - * thread with the lowest priority. - * - * @param[in] tqp the pointer to the threads list header - * @return The removed thread pointer. - * - * @notapi - */ -thread_t *queue_lifo_remove(threads_queue_t *tqp) { - thread_t *tp = tqp->p_prev; - - (tqp->p_prev = tp->p_prev)->p_next = (thread_t *)tqp; - return tp; -} - -/** - * @brief Removes a thread from a queue and returns it. - * @details The thread is removed from the queue regardless of its relative - * position and regardless the used insertion method. - * - * @param[in] tp the pointer to the thread to be removed from the queue - * @return The removed thread pointer. - * - * @notapi - */ -thread_t *queue_dequeue(thread_t *tp) { - - tp->p_prev->p_next = tp->p_next; - tp->p_next->p_prev = tp->p_prev; - return tp; -} - -/** - * @brief Pushes a thread_t on top of a stack list. - * - * @param[in] tp the pointer to the thread to be inserted in the list - * @param[in] tlp the pointer to the threads list header - * - * @notapi - */ -void list_insert(thread_t *tp, threads_list_t *tlp) { - - tp->p_next = tlp->p_next; - tlp->p_next = tp; -} - -/** - * @brief Pops a thread from the top of a stack list and returns it. - * @pre The list must be non-empty before calling this function. - * - * @param[in] tlp the pointer to the threads list header - * @return The removed thread pointer. - * - * @notapi - */ -thread_t *list_remove(threads_list_t *tlp) { - - thread_t *tp = tlp->p_next; - tlp->p_next = tp->p_next; - return tp; -} -#endif /* CH_CFG_OPTIMIZE_SPEED */ - -/** @} */ diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c deleted file mode 100644 index 003c779ec..000000000 --- a/os/kernel/src/chmboxes.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chmboxes.c - * @brief Mailboxes code. - * - * @addtogroup mailboxes - * @details Asynchronous messages. - *

Operation mode

- * A mailbox is an asynchronous communication mechanism.
- * Operations defined for mailboxes: - * - Post: Posts a message on the mailbox in FIFO order. - * - Post Ahead: Posts a message on the mailbox with urgent - * priority. - * - Fetch: A message is fetched from the mailbox and removed - * from the queue. - * - Reset: The mailbox is emptied and all the stored messages - * are lost. - * . - * A message is a variable of type msg_t that is guaranteed to have - * the same size of and be compatible with (data) pointers (anyway an - * explicit cast is needed). - * If larger messages need to be exchanged then a pointer to a - * structure can be posted in the mailbox but the posting side has - * no predefined way to know when the message has been processed. A - * possible approach is to allocate memory (from a memory pool for - * example) from the posting side and free it on the fetching side. - * Another approach is to set a "done" flag into the structure pointed - * by the message. - * @pre In order to use the mailboxes APIs the @p CH_CFG_USE_MAILBOXES option - * must be enabled in @p chconf.h. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes a @p mailbox_t object. - * - * @param[out] mbp the pointer to the @p mailbox_t structure to be - * initialized - * @param[in] buf pointer to the messages buffer as an array of @p msg_t - * @param[in] n number of elements in the buffer array - * - * @init - */ -void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { - - chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0)); - - mbp->mb_buffer = mbp->mb_wrptr = mbp->mb_rdptr = buf; - mbp->mb_top = &buf[n]; - chSemObjectInit(&mbp->mb_emptysem, n); - chSemObjectInit(&mbp->mb_fullsem, 0); -} - -/** - * @brief Resets a @p mailbox_t object. - * @details All the waiting threads are resumed with status @p RDY_RESET and - * the queued messages are lost. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * - * @api - */ -void chMBReset(mailbox_t *mbp) { - - chDbgCheck(mbp != NULL); - - chSysLock(); - mbp->mb_wrptr = mbp->mb_rdptr = mbp->mb_buffer; - chSemResetI(&mbp->mb_emptysem, mbp->mb_top - mbp->mb_buffer); - chSemResetI(&mbp->mb_fullsem, 0); - chSchRescheduleS(); - chSysUnlock(); -} - -/** - * @brief Posts a message into a mailbox. - * @details The invoking thread waits until a empty slot in the mailbox becomes - * available or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @api - */ -msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t time) { - msg_t rdymsg; - - chSysLock(); - rdymsg = chMBPostS(mbp, msg, time); - chSysUnlock(); - return rdymsg; -} - -/** - * @brief Posts a message into a mailbox. - * @details The invoking thread waits until a empty slot in the mailbox becomes - * available or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @sclass - */ -msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { - msg_t rdymsg; - - chDbgCheckClassS(); - chDbgCheck(mbp != NULL); - - rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); - if (rdymsg == RDY_OK) { - *mbp->mb_wrptr++ = msg; - if (mbp->mb_wrptr >= mbp->mb_top) - mbp->mb_wrptr = mbp->mb_buffer; - chSemSignalI(&mbp->mb_fullsem); - chSchRescheduleS(); - } - return rdymsg; -} - -/** - * @brief Posts a message into a mailbox. - * @details This variant is non-blocking, the function returns a timeout - * condition if the queue is full. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @return The operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be - * posted. - * - * @iclass - */ -msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { - - chDbgCheckClassI(); - chDbgCheck(mbp != NULL); - - if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) - return RDY_TIMEOUT; - chSemFastWaitI(&mbp->mb_emptysem); - *mbp->mb_wrptr++ = msg; - if (mbp->mb_wrptr >= mbp->mb_top) - mbp->mb_wrptr = mbp->mb_buffer; - chSemSignalI(&mbp->mb_fullsem); - return RDY_OK; -} - -/** - * @brief Posts an high priority message into a mailbox. - * @details The invoking thread waits until a empty slot in the mailbox becomes - * available or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @api - */ -msg_t chMBPostAhead(mailbox_t *mbp, msg_t msg, systime_t time) { - msg_t rdymsg; - - chSysLock(); - rdymsg = chMBPostAheadS(mbp, msg, time); - chSysUnlock(); - return rdymsg; -} - -/** - * @brief Posts an high priority message into a mailbox. - * @details The invoking thread waits until a empty slot in the mailbox becomes - * available or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @sclass - */ -msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { - msg_t rdymsg; - - chDbgCheckClassS(); - chDbgCheck(mbp != NULL); - - rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); - if (rdymsg == RDY_OK) { - if (--mbp->mb_rdptr < mbp->mb_buffer) - mbp->mb_rdptr = mbp->mb_top - 1; - *mbp->mb_rdptr = msg; - chSemSignalI(&mbp->mb_fullsem); - chSchRescheduleS(); - } - return rdymsg; -} - -/** - * @brief Posts an high priority message into a mailbox. - * @details This variant is non-blocking, the function returns a timeout - * condition if the queue is full. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @return The operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be - * posted. - * - * @iclass - */ -msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { - - chDbgCheckClassI(); - chDbgCheck(mbp != NULL); - - if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) - return RDY_TIMEOUT; - chSemFastWaitI(&mbp->mb_emptysem); - if (--mbp->mb_rdptr < mbp->mb_buffer) - mbp->mb_rdptr = mbp->mb_top - 1; - *mbp->mb_rdptr = msg; - chSemSignalI(&mbp->mb_fullsem); - return RDY_OK; -} - -/** - * @brief Retrieves a message from a mailbox. - * @details The invoking thread waits until a message is posted in the mailbox - * or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[out] msgp pointer to a message variable for the received message - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK if a message has been correctly fetched. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @api - */ -msg_t chMBFetch(mailbox_t *mbp, msg_t *msgp, systime_t time) { - msg_t rdymsg; - - chSysLock(); - rdymsg = chMBFetchS(mbp, msgp, time); - chSysUnlock(); - return rdymsg; -} - -/** - * @brief Retrieves a message from a mailbox. - * @details The invoking thread waits until a message is posted in the mailbox - * or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[out] msgp pointer to a message variable for the received message - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval RDY_OK if a message has been correctly fetched. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @sclass - */ -msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { - msg_t rdymsg; - - chDbgCheckClassS(); - chDbgCheck((mbp != NULL) && (msgp != NULL)); - - rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, time); - if (rdymsg == RDY_OK) { - *msgp = *mbp->mb_rdptr++; - if (mbp->mb_rdptr >= mbp->mb_top) - mbp->mb_rdptr = mbp->mb_buffer; - chSemSignalI(&mbp->mb_emptysem); - chSchRescheduleS(); - } - return rdymsg; -} - -/** - * @brief Retrieves a message from a mailbox. - * @details This variant is non-blocking, the function returns a timeout - * condition if the queue is empty. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[out] msgp pointer to a message variable for the received message - * @return The operation status. - * @retval RDY_OK if a message has been correctly fetched. - * @retval RDY_TIMEOUT if the mailbox is empty and a message cannot be - * fetched. - * - * @iclass - */ -msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { - - chDbgCheckClassI(); - chDbgCheck((mbp != NULL) && (msgp != NULL)); - - if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) - return RDY_TIMEOUT; - chSemFastWaitI(&mbp->mb_fullsem); - *msgp = *mbp->mb_rdptr++; - if (mbp->mb_rdptr >= mbp->mb_top) - mbp->mb_rdptr = mbp->mb_buffer; - chSemSignalI(&mbp->mb_emptysem); - return RDY_OK; -} -#endif /* CH_CFG_USE_MAILBOXES */ - -/** @} */ diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c deleted file mode 100644 index d5e7ed79c..000000000 --- a/os/kernel/src/chmemcore.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chmemcore.c - * @brief Core memory manager code. - * - * @addtogroup memcore - * @details Core Memory Manager related APIs and services. - *

Operation mode

- * The core memory manager is a simplified allocator that only - * allows to allocate memory blocks without the possibility to - * free them.
- * This allocator is meant as a memory blocks provider for the - * other allocators such as: - * - C-Runtime allocator (through a compiler specific adapter module). - * - Heap allocator (see @ref heaps). - * - Memory pools allocator (see @ref pools). - * . - * By having a centralized memory provider the various allocators - * can coexist and share the main memory.
- * This allocator, alone, is also useful for very simple - * applications that just require a simple way to get memory - * blocks. - * @pre In order to use the core memory manager APIs the @p CH_CFG_USE_MEMCORE - * option must be enabled in @p chconf.h. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_MEMCORE || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -static uint8_t *nextmem; -static uint8_t *endmem; - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Low level memory manager initialization. - * - * @notapi - */ -void _core_init(void) { -#if CH_CFG_MEMCORE_SIZE == 0 - extern uint8_t __heap_base__[]; - extern uint8_t __heap_end__[]; - - nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__); - endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__); -#else - static stkalign_t buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; - - nextmem = (uint8_t *)&buffer[0]; - endmem = (uint8_t *)&buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE)/MEM_ALIGN_SIZE]; -#endif -} - -/** - * @brief Allocates a memory block. - * @details The size of the returned block is aligned to the alignment - * type so it is not possible to allocate less - * than MEM_ALIGN_SIZE. - * - * @param[in] size the size of the block to be allocated - * @return A pointer to the allocated memory block. - * @retval NULL allocation failed, core memory exhausted. - * - * @api - */ -void *chCoreAlloc(size_t size) { - void *p; - - chSysLock(); - p = chCoreAllocI(size); - chSysUnlock(); - return p; -} - -/** - * @brief Allocates a memory block. - * @details The size of the returned block is aligned to the alignment - * type so it is not possible to allocate less than - * MEM_ALIGN_SIZE. - * - * @param[in] size the size of the block to be allocated. - * @return A pointer to the allocated memory block. - * @retval NULL allocation failed, core memory exhausted. - * - * @iclass - */ -void *chCoreAllocI(size_t size) { - void *p; - - chDbgCheckClassI(); - - size = MEM_ALIGN_NEXT(size); - if ((size_t)(endmem - nextmem) < size) - return NULL; - p = nextmem; - nextmem += size; - return p; -} - -/** - * @brief Core memory status. - * - * @return The size, in bytes, of the free core memory. - * - * @api - */ -size_t chCoreStatus(void) { - - return (size_t)(endmem - nextmem); -} -#endif /* CH_CFG_USE_MEMCORE */ - -/** @} */ diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c deleted file mode 100644 index d92ea7517..000000000 --- a/os/kernel/src/chmempools.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chmempools.c - * @brief Memory Pools code. - * - * @addtogroup pools - * @details Memory Pools related APIs and services. - *

Operation mode

- * The Memory Pools APIs allow to allocate/free fixed size objects in - * constant time and reliably without memory fragmentation - * problems.
- * Memory Pools do not enforce any alignment constraint on the - * contained object however the objects must be properly aligned - * to contain a pointer to void. - * @pre In order to use the memory pools APIs the @p CH_CFG_USE_MEMPOOLS option - * must be enabled in @p chconf.h. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_MEMPOOLS || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes an empty memory pool. - * - * @param[out] mp pointer to a @p memory_pool_t structure - * @param[in] size the size of the objects contained in this memory pool, - * the minimum accepted size is the size of a pointer to - * void. - * @param[in] provider memory provider function for the memory pool or - * @p NULL if the pool is not allowed to grow - * automatically - * - * @init - */ -void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider) { - - chDbgCheck((mp != NULL) && (size >= sizeof(void *))); - - mp->mp_next = NULL; - mp->mp_object_size = size; - mp->mp_provider = provider; -} - -/** - * @brief Loads a memory pool with an array of static objects. - * @pre The memory pool must be already been initialized. - * @pre The array elements must be of the right size for the specified - * memory pool. - * @post The memory pool contains the elements of the input array. - * - * @param[in] mp pointer to a @p memory_pool_t structure - * @param[in] p pointer to the array first element - * @param[in] n number of elements in the array - * - * @api - */ -void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n) { - - chDbgCheck((mp != NULL) && (n != 0)); - - while (n) { - chPoolAdd(mp, p); - p = (void *)(((uint8_t *)p) + mp->mp_object_size); - n--; - } -} - -/** - * @brief Allocates an object from a memory pool. - * @pre The memory pool must be already been initialized. - * - * @param[in] mp pointer to a @p memory_pool_t structure - * @return The pointer to the allocated object. - * @retval NULL if pool is empty. - * - * @iclass - */ -void *chPoolAllocI(memory_pool_t *mp) { - void *objp; - - chDbgCheckClassI(); - chDbgCheck(mp != NULL); - - if ((objp = mp->mp_next) != NULL) - mp->mp_next = mp->mp_next->ph_next; - else if (mp->mp_provider != NULL) - objp = mp->mp_provider(mp->mp_object_size); - return objp; -} - -/** - * @brief Allocates an object from a memory pool. - * @pre The memory pool must be already been initialized. - * - * @param[in] mp pointer to a @p memory_pool_t structure - * @return The pointer to the allocated object. - * @retval NULL if pool is empty. - * - * @api - */ -void *chPoolAlloc(memory_pool_t *mp) { - void *objp; - - chSysLock(); - objp = chPoolAllocI(mp); - chSysUnlock(); - return objp; -} - -/** - * @brief Releases an object into a memory pool. - * @pre The memory pool must be already been initialized. - * @pre The freed object must be of the right size for the specified - * memory pool. - * @pre The object must be properly aligned to contain a pointer to void. - * - * @param[in] mp pointer to a @p memory_pool_t structure - * @param[in] objp the pointer to the object to be released - * - * @iclass - */ -void chPoolFreeI(memory_pool_t *mp, void *objp) { - struct pool_header *php = objp; - - chDbgCheckClassI(); - chDbgCheck((mp != NULL) && (objp != NULL)); - - php->ph_next = mp->mp_next; - mp->mp_next = php; -} - -/** - * @brief Releases an object into a memory pool. - * @pre The memory pool must be already been initialized. - * @pre The freed object must be of the right size for the specified - * memory pool. - * @pre The object must be properly aligned to contain a pointer to void. - * - * @param[in] mp pointer to a @p memory_pool_t structure - * @param[in] objp the pointer to the object to be released - * - * @api - */ -void chPoolFree(memory_pool_t *mp, void *objp) { - - chSysLock(); - chPoolFreeI(mp, objp); - chSysUnlock(); -} - -#endif /* CH_CFG_USE_MEMPOOLS */ - -/** @} */ diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c deleted file mode 100644 index 335b46c61..000000000 --- a/os/kernel/src/chmsg.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chmsg.c - * @brief Messages code. - * - * @addtogroup messages - * @details Synchronous inter-thread messages APIs and services. - *

Operation Mode

- * Synchronous messages are an easy to use and fast IPC mechanism, - * threads can both act as message servers and/or message clients, - * the mechanism allows data to be carried in both directions. Note - * that messages are not copied between the client and server threads - * but just a pointer passed so the exchange is very time - * efficient.
- * Messages are scalar data types of type @p msg_t that are guaranteed - * to be size compatible with data pointers. Note that on some - * architectures function pointers can be larger that @p msg_t.
- * Messages are usually processed in FIFO order but it is possible to - * process them in priority order by enabling the - * @p CH_CFG_USE_MESSAGES_PRIORITY option in @p chconf.h.
- * @pre In order to use the message APIs the @p CH_CFG_USE_MESSAGES option - * must be enabled in @p chconf.h. - * @post Enabling messages requires 6-12 (depending on the architecture) - * extra bytes in the @p thread_t structure. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_MESSAGES || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -#if CH_CFG_USE_MESSAGES_PRIORITY -#define msg_insert(tp, qp) prio_insert(tp, qp) -#else -#define msg_insert(tp, qp) queue_insert(tp, qp) -#endif - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Sends a message to the specified thread. - * @details The sender is stopped until the receiver executes a - * @p chMsgRelease()after receiving the message. - * - * @param[in] tp the pointer to the thread - * @param[in] msg the message - * @return The answer message from @p chMsgRelease(). - * - * @api - */ -msg_t chMsgSend(thread_t *tp, msg_t msg) { - thread_t *ctp = currp; - - chDbgCheck(tp != NULL); - - chSysLock(); - ctp->p_msg = msg; - ctp->p_u.wtobjp = &tp->p_msgqueue; - msg_insert(ctp, &tp->p_msgqueue); - if (tp->p_state == CH_STATE_WTMSG) - chSchReadyI(tp); - chSchGoSleepS(CH_STATE_SNDMSGQ); - msg = ctp->p_u.rdymsg; - chSysUnlock(); - return msg; -} - -/** - * @brief Suspends the thread and waits for an incoming message. - * @post After receiving a message the function @p chMsgGet() must be - * called in order to retrieve the message and then @p chMsgRelease() - * must be invoked in order to acknowledge the reception and send - * the answer. - * @note If the message is a pointer then you can assume that the data - * pointed by the message is stable until you invoke @p chMsgRelease() - * because the sending thread is suspended until then. - * - * @return A reference to the thread carrying the message. - * - * @api - */ -thread_t *chMsgWait(void) { - thread_t *tp; - - chSysLock(); - if (!chMsgIsPendingI(currp)) - chSchGoSleepS(CH_STATE_WTMSG); - tp = queue_fifo_remove(&currp->p_msgqueue); - tp->p_state = CH_STATE_SNDMSG; - chSysUnlock(); - return tp; -} - -/** - * @brief Releases a sender thread specifying a response message. - * @pre Invoke this function only after a message has been received - * using @p chMsgWait(). - * - * @param[in] tp pointer to the thread - * @param[in] msg message to be returned to the sender - * - * @api - */ -void chMsgRelease(thread_t *tp, msg_t msg) { - - chSysLock(); - chDbgAssert(tp->p_state == CH_STATE_SNDMSG, "invalid state"); - chMsgReleaseS(tp, msg); - chSysUnlock(); -} - -#endif /* CH_CFG_USE_MESSAGES */ - -/** @} */ diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c deleted file mode 100644 index 0eb02e2b5..000000000 --- a/os/kernel/src/chmtx.c +++ /dev/null @@ -1,420 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chmtx.c - * @brief Mutexes code. - * - * @addtogroup mutexes - * @details Mutexes related APIs and services. - * - *

Operation mode

- * A mutex is a threads synchronization object that can be in two - * distinct states: - * - Not owned (unlocked). - * - Owned by a thread (locked). - * . - * Operations defined for mutexes: - * - Lock: The mutex is checked, if the mutex is not owned by - * some other thread then it is associated to the locking thread - * else the thread is queued on the mutex in a list ordered by - * priority. - * - Unlock: The mutex is released by the owner and the highest - * priority thread waiting in the queue, if any, is resumed and made - * owner of the mutex. - * . - *

Constraints

- * In ChibiOS/RT the Unlock operations are always performed in - * lock-reverse order. The unlock API does not even have a parameter, - * the mutex to unlock is selected from an internal, per-thread, stack - * of owned mutexes. This both improves the performance and is - * required for an efficient implementation of the priority - * inheritance mechanism. - * - *

The priority inversion problem

- * The mutexes in ChibiOS/RT implements the full priority - * inheritance mechanism in order handle the priority inversion - * problem.
- * When a thread is queued on a mutex, any thread, directly or - * indirectly, holding the mutex gains the same priority of the - * waiting thread (if their priority was not already equal or higher). - * The mechanism works with any number of nested mutexes and any - * number of involved threads. The algorithm complexity (worst case) - * is N with N equal to the number of nested mutexes. - * @pre In order to use the mutex APIs the @p CH_CFG_USE_MUTEXES option - * must be enabled in @p chconf.h. - * @post Enabling mutexes requires 5-12 (depending on the architecture) - * extra bytes in the @p thread_t structure. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes s @p mutex_t structure. - * - * @param[out] mp pointer to a @p mutex_t structure - * - * @init - */ -void chMtxObjectInit(mutex_t *mp) { - - chDbgCheck(mp != NULL); - - queue_init(&mp->m_queue); - mp->m_owner = NULL; -} - -/** - * @brief Locks the specified mutex. - * @post The mutex is locked and inserted in the per-thread stack of owned - * mutexes. - * - * @param[in] mp pointer to the @p mutex_t structure - * - * @api - */ -void chMtxLock(mutex_t *mp) { - - chSysLock(); - - chMtxLockS(mp); - - chSysUnlock(); -} - -/** - * @brief Locks the specified mutex. - * @post The mutex is locked and inserted in the per-thread stack of owned - * mutexes. - * - * @param[in] mp pointer to the @p mutex_t structure - * - * @sclass - */ -void chMtxLockS(mutex_t *mp) { - thread_t *ctp = currp; - - chDbgCheckClassS(); - chDbgCheck(mp != NULL); - - /* Is the mutex already locked? */ - if (mp->m_owner != NULL) { - /* Priority inheritance protocol; explores the thread-mutex dependencies - boosting the priority of all the affected threads to equal the priority - of the running thread requesting the mutex.*/ - thread_t *tp = mp->m_owner; - - /* Does the running thread have higher priority than the mutex - owning thread? */ - while (tp->p_prio < ctp->p_prio) { - /* Make priority of thread tp match the running thread's priority.*/ - tp->p_prio = ctp->p_prio; - - /* The following states need priority queues reordering.*/ - switch (tp->p_state) { - case CH_STATE_WTMTX: - /* Re-enqueues the mutex owner with its new priority.*/ - queue_prio_insert(queue_dequeue(tp), - (threads_queue_t *)tp->p_u.wtobjp); - tp = ((mutex_t *)tp->p_u.wtobjp)->m_owner; - continue; -#if CH_CFG_USE_CONDVARS | \ - (CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY) | \ - (CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY) -#if CH_CFG_USE_CONDVARS - case CH_STATE_WTCOND: -#endif -#if CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY - case CH_STATE_WTSEM: -#endif -#if CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY - case CH_STATE_SNDMSGQ: -#endif - /* Re-enqueues tp with its new priority on the queue.*/ - queue_prio_insert(queue_dequeue(tp), - (threads_queue_t *)tp->p_u.wtobjp); - break; -#endif - case CH_STATE_READY: -#if CH_DBG_ENABLE_ASSERTS - /* Prevents an assertion in chSchReadyI().*/ - tp->p_state = CH_STATE_CURRENT; -#endif - /* Re-enqueues tp with its new priority on the ready list.*/ - chSchReadyI(queue_dequeue(tp)); - break; - } - break; - } - - /* Sleep on the mutex.*/ - queue_prio_insert(ctp, &mp->m_queue); - ctp->p_u.wtobjp = mp; - chSchGoSleepS(CH_STATE_WTMTX); - - /* It is assumed that the thread performing the unlock operation assigns - the mutex to this thread.*/ - chDbgAssert(mp->m_owner == ctp, "not owner"); - chDbgAssert(ctp->p_mtxlist == mp, "not owned"); - } - else { - /* It was not owned, inserted in the owned mutexes list.*/ - mp->m_owner = ctp; - mp->m_next = ctp->p_mtxlist; - ctp->p_mtxlist = mp; - } -} - -/** - * @brief Tries to lock a mutex. - * @details This function attempts to lock a mutex, if the mutex is already - * locked by another thread then the function exits without waiting. - * @post The mutex is locked and inserted in the per-thread stack of owned - * mutexes. - * @note This function does not have any overhead related to the - * priority inheritance mechanism because it does not try to - * enter a sleep state. - * - * @param[in] mp pointer to the @p mutex_t structure - * @return The operation status. - * @retval true if the mutex has been successfully acquired - * @retval false if the lock attempt failed. - * - * @api - */ -bool chMtxTryLock(mutex_t *mp) { - bool b; - - chSysLock(); - - b = chMtxTryLockS(mp); - - chSysUnlock(); - return b; -} - -/** - * @brief Tries to lock a mutex. - * @details This function attempts to lock a mutex, if the mutex is already - * taken by another thread then the function exits without waiting. - * @post The mutex is locked and inserted in the per-thread stack of owned - * mutexes. - * @note This function does not have any overhead related to the - * priority inheritance mechanism because it does not try to - * enter a sleep state. - * - * @param[in] mp pointer to the @p mutex_t structure - * @return The operation status. - * @retval true if the mutex has been successfully acquired - * @retval false if the lock attempt failed. - * - * @sclass - */ -bool chMtxTryLockS(mutex_t *mp) { - - chDbgCheckClassS(); - chDbgCheck(mp != NULL); - - if (mp->m_owner != NULL) - return false; - - mp->m_owner = currp; - mp->m_next = currp->p_mtxlist; - currp->p_mtxlist = mp; - return true; -} - -/** - * @brief Unlocks the next owned mutex in reverse lock order. - * @pre The invoking thread must have at least one owned mutex. - * @post The mutex is unlocked and removed from the per-thread stack of - * owned mutexes. - * - * @return A pointer to the unlocked mutex. - * - * @api - */ -mutex_t *chMtxUnlock(void) { - thread_t *ctp = currp; - mutex_t *ump, *mp; - - chSysLock(); - - chDbgAssert(ctp->p_mtxlist != NULL, "owned mutexes list empty"); - chDbgAssert(ctp->p_mtxlist->m_owner == ctp, "ownership failure"); - - /* Removes the top mutex from the thread's owned mutexes list and marks it - as not owned.*/ - ump = ctp->p_mtxlist; - ctp->p_mtxlist = ump->m_next; - - /* If a thread is waiting on the mutex then the fun part begins.*/ - if (chMtxQueueNotEmptyS(ump)) { - thread_t *tp; - - /* Recalculates the optimal thread priority by scanning the owned - mutexes list.*/ - tprio_t newprio = ctp->p_realprio; - mp = ctp->p_mtxlist; - while (mp != NULL) { - /* If the highest priority thread waiting in the mutexes list has a - greater priority than the current thread base priority then the final - priority will have at least that priority.*/ - if (chMtxQueueNotEmptyS(mp) && (mp->m_queue.p_next->p_prio > newprio)) - newprio = mp->m_queue.p_next->p_prio; - mp = mp->m_next; - } - - /* Assigns to the current thread the highest priority among all the - waiting threads.*/ - ctp->p_prio = newprio; - - /* Awakens the highest priority thread waiting for the unlocked mutex and - assigns the mutex to it.*/ - tp = queue_fifo_remove(&ump->m_queue); - ump->m_owner = tp; - ump->m_next = tp->p_mtxlist; - tp->p_mtxlist = ump; - chSchWakeupS(tp, RDY_OK); - } - else - ump->m_owner = NULL; - chSysUnlock(); - return ump; -} - -/** - * @brief Unlocks the next owned mutex in reverse lock order. - * @pre The invoking thread must have at least one owned mutex. - * @post The mutex is unlocked and removed from the per-thread stack of - * owned mutexes. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. - * - * @return A pointer to the unlocked mutex. - * - * @sclass - */ -mutex_t *chMtxUnlockS(void) { - thread_t *ctp = currp; - mutex_t *ump, *mp; - - chDbgCheckClassS(); - chDbgAssert(ctp->p_mtxlist != NULL, "owned mutexes list empty"); - chDbgAssert(ctp->p_mtxlist->m_owner == ctp, "ownership failure"); - - /* Removes the top mutex from the owned mutexes list and marks it as not - owned.*/ - ump = ctp->p_mtxlist; - ctp->p_mtxlist = ump->m_next; - - /* If a thread is waiting on the mutex then the fun part begins.*/ - if (chMtxQueueNotEmptyS(ump)) { - thread_t *tp; - - /* Recalculates the optimal thread priority by scanning the owned - mutexes list.*/ - tprio_t newprio = ctp->p_realprio; - mp = ctp->p_mtxlist; - while (mp != NULL) { - /* If the highest priority thread waiting in the mutexes list has a - greater priority than the current thread base priority then the final - priority will have at least that priority.*/ - if (chMtxQueueNotEmptyS(mp) && (mp->m_queue.p_next->p_prio > newprio)) - newprio = mp->m_queue.p_next->p_prio; - - mp = mp->m_next; - } - ctp->p_prio = newprio; - - /* Awakens the highest priority thread waiting for the unlocked mutex and - assigns the mutex to it.*/ - tp = queue_fifo_remove(&ump->m_queue); - ump->m_owner = tp; - ump->m_next = tp->p_mtxlist; - tp->p_mtxlist = ump; - chSchReadyI(tp); - } - else - ump->m_owner = NULL; - return ump; -} - -/** - * @brief Unlocks all the mutexes owned by the invoking thread. - * @post The stack of owned mutexes is emptied and all the found - * mutexes are unlocked. - * @note This function is MUCH MORE efficient than releasing the - * mutexes one by one and not just because the call overhead, - * this function does not have any overhead related to the priority - * inheritance mechanism. - * - * @api - */ -void chMtxUnlockAll(void) { - thread_t *ctp = currp; - - chSysLock(); - if (ctp->p_mtxlist != NULL) { - do { - mutex_t *ump = ctp->p_mtxlist; - ctp->p_mtxlist = ump->m_next; - if (chMtxQueueNotEmptyS(ump)) { - thread_t *tp = queue_fifo_remove(&ump->m_queue); - ump->m_owner = tp; - ump->m_next = tp->p_mtxlist; - tp->p_mtxlist = ump; - chSchReadyI(tp); - } - else - ump->m_owner = NULL; - } while (ctp->p_mtxlist != NULL); - ctp->p_prio = ctp->p_realprio; - chSchRescheduleS(); - } - chSysUnlock(); -} - -#endif /* CH_CFG_USE_MUTEXES */ - -/** @} */ diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c deleted file mode 100644 index 679d69337..000000000 --- a/os/kernel/src/chqueues.c +++ /dev/null @@ -1,455 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chqueues.c - * @brief I/O Queues code. - * - * @addtogroup io_queues - * @details ChibiOS/RT queues are mostly used in serial-like device drivers. - * The device drivers are usually designed to have a lower side - * (lower driver, it is usually an interrupt service routine) and an - * upper side (upper driver, accessed by the application threads).
- * There are several kind of queues:
- * - Input queue, unidirectional queue where the writer is the - * lower side and the reader is the upper side. - * - Output queue, unidirectional queue where the writer is the - * upper side and the reader is the lower side. - * - Full duplex queue, bidirectional queue. Full duplex queues - * are implemented by pairing an input queue and an output queue - * together. - * . - * @pre In order to use the I/O queues the @p CH_CFG_USE_QUEUES option must - * be enabled in @p chconf.h. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_QUEUES || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/** - * @brief Puts the invoking thread into the queue's threads queue. - * - * @param[out] qp pointer to an @p io_queue_t structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return A message specifying how the invoking thread has been - * released from threads queue. - * @retval Q_OK is the normal exit, thread signaled. - * @retval Q_RESET if the queue has been reset. - * @retval Q_TIMEOUT if the queue operation timed out. - */ -static msg_t qwait(io_queue_t *qp, systime_t time) { - - if (TIME_IMMEDIATE == time) - return Q_TIMEOUT; - currp->p_u.wtobjp = qp; - queue_insert(currp, &qp->q_waiting); - return chSchGoSleepTimeoutS(CH_STATE_WTQUEUE, time); -} - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes an input queue. - * @details A Semaphore is internally initialized and works as a counter of - * the bytes contained in the queue. - * @note The callback is invoked from within the S-Locked system state, - * see @ref system_states. - * - * @param[out] iqp pointer to an @p input_queue_t structure - * @param[in] bp pointer to a memory area allocated as queue buffer - * @param[in] size size of the queue buffer - * @param[in] infy pointer to a callback function that is invoked when - * data is read from the queue. The value can be @p NULL. - * @param[in] link application defined pointer - * - * @init - */ -void chIQObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size, - qnotify_t infy, void *link) { - - queue_init(&iqp->q_waiting); - iqp->q_counter = 0; - iqp->q_buffer = iqp->q_rdptr = iqp->q_wrptr = bp; - iqp->q_top = bp + size; - iqp->q_notify = infy; - iqp->q_link = link; -} - -/** - * @brief Resets an input queue. - * @details All the data in the input queue is erased and lost, any waiting - * thread is resumed with status @p Q_RESET. - * @note A reset operation can be used by a low level driver in order to - * obtain immediate attention from the high level layers. - * - * @param[in] iqp pointer to an @p input_queue_t structure - * - * @iclass - */ -void chIQResetI(input_queue_t *iqp) { - - chDbgCheckClassI(); - - iqp->q_rdptr = iqp->q_wrptr = iqp->q_buffer; - iqp->q_counter = 0; - while (queue_notempty(&iqp->q_waiting)) - chSchReadyI(queue_fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_RESET; -} - -/** - * @brief Input queue write. - * @details A byte value is written into the low end of an input queue. - * - * @param[in] iqp pointer to an @p input_queue_t structure - * @param[in] b the byte value to be written in the queue - * @return The operation status. - * @retval Q_OK if the operation has been completed with success. - * @retval Q_FULL if the queue is full and the operation cannot be - * completed. - * - * @iclass - */ -msg_t chIQPutI(input_queue_t *iqp, uint8_t b) { - - chDbgCheckClassI(); - - if (chIQIsFullI(iqp)) - return Q_FULL; - - iqp->q_counter++; - *iqp->q_wrptr++ = b; - if (iqp->q_wrptr >= iqp->q_top) - iqp->q_wrptr = iqp->q_buffer; - - if (queue_notempty(&iqp->q_waiting)) - chSchReadyI(queue_fifo_remove(&iqp->q_waiting))->p_u.rdymsg = Q_OK; - - return Q_OK; -} - -/** - * @brief Input queue read with timeout. - * @details This function reads a byte value from an input queue. If the queue - * is empty then the calling thread is suspended until a byte arrives - * in the queue or a timeout occurs. - * @note The callback is invoked before reading the character from the - * buffer or before entering the state @p CH_STATE_WTQUEUE. - * - * @param[in] iqp pointer to an @p input_queue_t structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return A byte value from the queue. - * @retval Q_TIMEOUT if the specified time expired. - * @retval Q_RESET if the queue has been reset. - * - * @api - */ -msg_t chIQGetTimeout(input_queue_t *iqp, systime_t time) { - uint8_t b; - - chSysLock(); - if (iqp->q_notify) - iqp->q_notify(iqp); - - while (chIQIsEmptyI(iqp)) { - msg_t msg; - if ((msg = qwait((io_queue_t *)iqp, time)) < Q_OK) { - chSysUnlock(); - return msg; - } - } - - iqp->q_counter--; - b = *iqp->q_rdptr++; - if (iqp->q_rdptr >= iqp->q_top) - iqp->q_rdptr = iqp->q_buffer; - - chSysUnlock(); - return b; -} - -/** - * @brief Input queue read with timeout. - * @details The function reads data from an input queue into a buffer. The - * operation completes when the specified amount of data has been - * transferred or after the specified timeout or if the queue has - * been reset. - * @note The function is not atomic, if you need atomicity it is suggested - * to use a semaphore or a mutex for mutual exclusion. - * @note The callback is invoked before reading each character from the - * buffer or before entering the state @p CH_STATE_WTQUEUE. - * - * @param[in] iqp pointer to an @p input_queue_t structure - * @param[out] bp pointer to the data buffer - * @param[in] n the maximum amount of data to be transferred, the - * value 0 is reserved - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The number of bytes effectively transferred. - * - * @api - */ -size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp, - size_t n, systime_t time) { - qnotify_t nfy = iqp->q_notify; - size_t r = 0; - - chDbgCheck(n > 0); - - chSysLock(); - while (true) { - if (nfy) - nfy(iqp); - - while (chIQIsEmptyI(iqp)) { - if (qwait((io_queue_t *)iqp, time) != Q_OK) { - chSysUnlock(); - return r; - } - } - - iqp->q_counter--; - *bp++ = *iqp->q_rdptr++; - if (iqp->q_rdptr >= iqp->q_top) - iqp->q_rdptr = iqp->q_buffer; - - chSysUnlock(); /* Gives a preemption chance in a controlled point.*/ - r++; - if (--n == 0) - return r; - - chSysLock(); - } -} - -/** - * @brief Initializes an output queue. - * @details A Semaphore is internally initialized and works as a counter of - * the free bytes in the queue. - * @note The callback is invoked from within the S-Locked system state, - * see @ref system_states. - * - * @param[out] oqp pointer to an @p output_queue_t structure - * @param[in] bp pointer to a memory area allocated as queue buffer - * @param[in] size size of the queue buffer - * @param[in] onfy pointer to a callback function that is invoked when - * data is written to the queue. The value can be @p NULL. - * @param[in] link application defined pointer - * - * @init - */ -void chOQObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size, - qnotify_t onfy, void *link) { - - queue_init(&oqp->q_waiting); - oqp->q_counter = size; - oqp->q_buffer = oqp->q_rdptr = oqp->q_wrptr = bp; - oqp->q_top = bp + size; - oqp->q_notify = onfy; - oqp->q_link = link; -} - -/** - * @brief Resets an output queue. - * @details All the data in the output queue is erased and lost, any waiting - * thread is resumed with status @p Q_RESET. - * @note A reset operation can be used by a low level driver in order to - * obtain immediate attention from the high level layers. - * - * @param[in] oqp pointer to an @p output_queue_t structure - * - * @iclass - */ -void chOQResetI(output_queue_t *oqp) { - - chDbgCheckClassI(); - - oqp->q_rdptr = oqp->q_wrptr = oqp->q_buffer; - oqp->q_counter = chQSizeI(oqp); - while (queue_notempty(&oqp->q_waiting)) - chSchReadyI(queue_fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_RESET; -} - -/** - * @brief Output queue write with timeout. - * @details This function writes a byte value to an output queue. If the queue - * is full then the calling thread is suspended until there is space - * in the queue or a timeout occurs. - * @note The callback is invoked after writing the character into the - * buffer. - * - * @param[in] oqp pointer to an @p output_queue_t structure - * @param[in] b the byte value to be written in the queue - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The operation status. - * @retval Q_OK if the operation succeeded. - * @retval Q_TIMEOUT if the specified time expired. - * @retval Q_RESET if the queue has been reset. - * - * @api - */ -msg_t chOQPutTimeout(output_queue_t *oqp, uint8_t b, systime_t time) { - - chSysLock(); - while (chOQIsFullI(oqp)) { - msg_t msg; - - if ((msg = qwait((io_queue_t *)oqp, time)) < Q_OK) { - chSysUnlock(); - return msg; - } - } - - oqp->q_counter--; - *oqp->q_wrptr++ = b; - if (oqp->q_wrptr >= oqp->q_top) - oqp->q_wrptr = oqp->q_buffer; - - if (oqp->q_notify) - oqp->q_notify(oqp); - - chSysUnlock(); - return Q_OK; -} - -/** - * @brief Output queue read. - * @details A byte value is read from the low end of an output queue. - * - * @param[in] oqp pointer to an @p output_queue_t structure - * @return The byte value from the queue. - * @retval Q_EMPTY if the queue is empty. - * - * @iclass - */ -msg_t chOQGetI(output_queue_t *oqp) { - uint8_t b; - - chDbgCheckClassI(); - - if (chOQIsEmptyI(oqp)) - return Q_EMPTY; - - oqp->q_counter++; - b = *oqp->q_rdptr++; - if (oqp->q_rdptr >= oqp->q_top) - oqp->q_rdptr = oqp->q_buffer; - - if (queue_notempty(&oqp->q_waiting)) - chSchReadyI(queue_fifo_remove(&oqp->q_waiting))->p_u.rdymsg = Q_OK; - - return b; -} - -/** - * @brief Output queue write with timeout. - * @details The function writes data from a buffer to an output queue. The - * operation completes when the specified amount of data has been - * transferred or after the specified timeout or if the queue has - * been reset. - * @note The function is not atomic, if you need atomicity it is suggested - * to use a semaphore or a mutex for mutual exclusion. - * @note The callback is invoked after writing each character into the - * buffer. - * - * @param[in] oqp pointer to an @p output_queue_t structure - * @param[out] bp pointer to the data buffer - * @param[in] n the maximum amount of data to be transferred, the - * value 0 is reserved - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return The number of bytes effectively transferred. - * - * @api - */ -size_t chOQWriteTimeout(output_queue_t *oqp, const uint8_t *bp, - size_t n, systime_t time) { - qnotify_t nfy = oqp->q_notify; - size_t w = 0; - - chDbgCheck(n > 0); - - chSysLock(); - while (true) { - while (chOQIsFullI(oqp)) { - if (qwait((io_queue_t *)oqp, time) != Q_OK) { - chSysUnlock(); - return w; - } - } - oqp->q_counter--; - *oqp->q_wrptr++ = *bp++; - if (oqp->q_wrptr >= oqp->q_top) - oqp->q_wrptr = oqp->q_buffer; - - if (nfy) - nfy(oqp); - - chSysUnlock(); /* Gives a preemption chance in a controlled point.*/ - w++; - if (--n == 0) - return w; - chSysLock(); - } -} -#endif /* CH_CFG_USE_QUEUES */ - -/** @} */ diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c deleted file mode 100644 index 685d0c109..000000000 --- a/os/kernel/src/chregistry.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chregistry.c - * @brief Threads registry code. - * - * @addtogroup registry - * @details Threads Registry related APIs and services. - * - *

Operation mode

- * The Threads Registry is a double linked list that holds all the - * active threads in the system.
- * Operations defined for the registry: - * - First, returns the first, in creation order, active thread - * in the system. - * - Next, returns the next, in creation order, active thread - * in the system. - * . - * The registry is meant to be mainly a debug feature, for example, - * using the registry a debugger can enumerate the active threads - * in any given moment or the shell can print the active threads - * and their state.
- * Another possible use is for centralized threads memory management, - * terminating threads can pulse an event source and an event handler - * can perform a scansion of the registry in order to recover the - * memory. - * @pre In order to use the threads registry the @p CH_CFG_USE_REGISTRY - * option must be enabled in @p chconf.h. - * @{ - */ -#include "ch.h" - -#if CH_CFG_USE_REGISTRY || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -#define _offsetof(st, m) \ - ((size_t)((char *)&((st *)0)->m - (char *)0)) - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/* - * OS signature in ROM plus debug-related information. - */ -ROMCONST chdebug_t ch_debug = { - "main", - (uint8_t)0, - (uint8_t)sizeof (chdebug_t), - (uint16_t)((CH_KERNEL_MAJOR << 11) | - (CH_KERNEL_MINOR << 6) | - (CH_KERNEL_PATCH) << 0), - (uint8_t)sizeof (void *), - (uint8_t)sizeof (systime_t), - (uint8_t)sizeof (thread_t), - (uint8_t)_offsetof(thread_t, p_prio), - (uint8_t)_offsetof(thread_t, p_ctx), - (uint8_t)_offsetof(thread_t, p_newer), - (uint8_t)_offsetof(thread_t, p_older), - (uint8_t)_offsetof(thread_t, p_name), -#if CH_DBG_ENABLE_STACK_CHECK - (uint8_t)_offsetof(thread_t, p_stklimit), -#else - (uint8_t)0, -#endif - (uint8_t)_offsetof(thread_t, p_state), - (uint8_t)_offsetof(thread_t, p_flags), -#if CH_CFG_USE_DYNAMIC - (uint8_t)_offsetof(thread_t, p_refs), -#else - (uint8_t)0, -#endif -#if CH_CFG_TIME_QUANTUM > 0 - (uint8_t)_offsetof(thread_t, p_preempt), -#else - (uint8_t)0, -#endif -#if CH_DBG_THREADS_PROFILING - (uint8_t)_offsetof(thread_t, p_time) -#else - (uint8_t)0 -#endif -}; - -/** - * @brief Returns the first thread in the system. - * @details Returns the most ancient thread in the system, usually this is - * the main thread unless it terminated. A reference is added to the - * returned thread in order to make sure its status is not lost. - * @note This function cannot return @p NULL because there is always at - * least one thread in the system. - * - * @return A reference to the most ancient thread. - * - * @api - */ -thread_t *chRegFirstThread(void) { - thread_t *tp; - - chSysLock(); - tp = ch.rlist.r_newer; -#if CH_CFG_USE_DYNAMIC - tp->p_refs++; -#endif - chSysUnlock(); - return tp; -} - -/** - * @brief Returns the thread next to the specified one. - * @details The reference counter of the specified thread is decremented and - * the reference counter of the returned thread is incremented. - * - * @param[in] tp pointer to the thread - * @return A reference to the next thread. - * @retval NULL if there is no next thread. - * - * @api - */ -thread_t *chRegNextThread(thread_t *tp) { - thread_t *ntp; - - chSysLock(); - ntp = tp->p_newer; - if (ntp == (thread_t *)&ch.rlist) - ntp = NULL; -#if CH_CFG_USE_DYNAMIC - else { - chDbgAssert(ntp->p_refs < 255, "too many references"); - ntp->p_refs++; - } -#endif - chSysUnlock(); -#if CH_CFG_USE_DYNAMIC - chThdRelease(tp); -#endif - return ntp; -} - -#endif /* CH_CFG_USE_REGISTRY */ - -/** @} */ diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c deleted file mode 100644 index 615008589..000000000 --- a/os/kernel/src/chschd.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chschd.c - * @brief Scheduler code. - * - * @addtogroup scheduler - * @details This module provides the default portable scheduler code. - * @{ - */ - -#include "ch.h" - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Scheduler initialization. - * - * @notapi - */ -void _scheduler_init(void) { - - queue_init(&ch.rlist.r_queue); - ch.rlist.r_prio = NOPRIO; -#if CH_CFG_USE_REGISTRY - ch.rlist.r_newer = ch.rlist.r_older = (thread_t *)&ch.rlist; -#endif -} - -/** - * @brief Inserts a thread in the Ready List. - * @details The thread is positioned behind all threads with higher or equal - * priority. - * @pre The thread must not be already inserted in any list through its - * @p p_next and @p p_prev or list corruption would occur. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. Note that - * interrupt handlers always reschedule on exit so an explicit - * reschedule must not be performed in ISRs. - * - * @param[in] tp the thread to be made ready - * @return The thread pointer. - * - * @iclass - */ -thread_t *chSchReadyI(thread_t *tp) { - thread_t *cp; - - chDbgCheckClassI(); - - /* Integrity checks.*/ - chDbgAssert((tp->p_state != CH_STATE_READY) && - (tp->p_state != CH_STATE_FINAL), - "invalid state"); - - tp->p_state = CH_STATE_READY; - cp = (thread_t *)&ch.rlist.r_queue; - do { - cp = cp->p_next; - } while (cp->p_prio >= tp->p_prio); - /* Insertion on p_prev.*/ - tp->p_next = cp; - tp->p_prev = cp->p_prev; - tp->p_prev->p_next = cp->p_prev = tp; - return tp; -} - -/** - * @brief Puts the current thread to sleep into the specified state. - * @details The thread goes into a sleeping state. The possible - * @ref thread_states are defined into @p threads.h. - * - * @param[in] newstate the new thread state - * - * @sclass - */ -void chSchGoSleepS(tstate_t newstate) { - thread_t *otp; - - chDbgCheckClassS(); - - (otp = currp)->p_state = newstate; -#if CH_CFG_TIME_QUANTUM > 0 - /* The thread is renouncing its remaining time slices so it will have a new - time quantum when it will wakeup.*/ - otp->p_preempt = CH_CFG_TIME_QUANTUM; -#endif - setcurrp(queue_fifo_remove(&ch.rlist.r_queue)); - currp->p_state = CH_STATE_CURRENT; - chSysSwitch(currp, otp); -} - -/* - * Timeout wakeup callback. - */ -static void wakeup(void *p) { - thread_t *tp = (thread_t *)p; - - chSysLockFromISR(); - switch (tp->p_state) { - case CH_STATE_READY: - /* Handling the special case where the thread has been made ready by - another thread with higher priority.*/ - chSysUnlockFromISR(); - return; -#if CH_CFG_USE_SEMAPHORES || CH_CFG_USE_QUEUES || \ - (CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT) -#if CH_CFG_USE_SEMAPHORES - case CH_STATE_WTSEM: - chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp); - /* Falls into, intentional. */ -#endif -#if CH_CFG_USE_QUEUES - case CH_STATE_WTQUEUE: -#endif -#if CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT - case CH_STATE_WTCOND: -#endif - /* States requiring dequeuing.*/ - queue_dequeue(tp); -#endif - } - tp->p_u.rdymsg = RDY_TIMEOUT; - chSchReadyI(tp); - chSysUnlockFromISR(); -} - -/** - * @brief Puts the current thread to sleep into the specified state with - * timeout specification. - * @details The thread goes into a sleeping state, if it is not awakened - * explicitly within the specified timeout then it is forcibly - * awakened with a @p RDY_TIMEOUT low level message. The possible - * @ref thread_states are defined into @p threads.h. - * - * @param[in] newstate the new thread state - * @param[in] time the number of ticks before the operation timeouts, the - * special values are handled as follow: - * - @a TIME_INFINITE the thread enters an infinite sleep - * state, this is equivalent to invoking - * @p chSchGoSleepS() but, of course, less efficient. - * - @a TIME_IMMEDIATE this value is not allowed. - * . - * @return The wakeup message. - * @retval RDY_TIMEOUT if a timeout occurs. - * - * @sclass - */ -msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { - - chDbgCheckClassS(); - - if (TIME_INFINITE != time) { - virtual_timer_t vt; - - chVTDoSetI(&vt, time, wakeup, currp); - chSchGoSleepS(newstate); - if (chVTIsArmedI(&vt)) - chVTDoResetI(&vt); - } - else - chSchGoSleepS(newstate); - return currp->p_u.rdymsg; -} - -/** - * @brief Wakes up a thread. - * @details The thread is inserted into the ready list or immediately made - * running depending on its relative priority compared to the current - * thread. - * @pre The thread must not be already inserted in any list through its - * @p p_next and @p p_prev or list corruption would occur. - * @note It is equivalent to a @p chSchReadyI() followed by a - * @p chSchRescheduleS() but much more efficient. - * @note The function assumes that the current thread has the highest - * priority. - * - * @param[in] ntp the thread to be made ready - * @param[in] msg message to the awakened thread - * - * @sclass - */ -void chSchWakeupS(thread_t *ntp, msg_t msg) { - - chDbgCheckClassS(); - - ntp->p_u.rdymsg = msg; - /* If the waken thread has a not-greater priority than the current - one then it is just inserted in the ready list else it made - running immediately and the invoking thread goes in the ready - list instead.*/ - if (ntp->p_prio <= currp->p_prio) - chSchReadyI(ntp); - else { - thread_t *otp = chSchReadyI(currp); - setcurrp(ntp); - ntp->p_state = CH_STATE_CURRENT; - chSysSwitch(ntp, otp); - } -} - -/** - * @brief Performs a reschedule if a higher priority thread is runnable. - * @details If a thread with a higher priority than the current thread is in - * the ready list then make the higher priority thread running. - * - * @sclass - */ -void chSchRescheduleS(void) { - - chDbgCheckClassS(); - - if (chSchIsRescRequiredI()) - chSchDoRescheduleAhead(); -} - -/** - * @brief Evaluates if preemption is required. - * @details The decision is taken by comparing the relative priorities and - * depending on the state of the round robin timeout counter. - * @note Not a user function, it is meant to be invoked by the scheduler - * itself or from within the port layer. - * - * @retval true if there is a thread that must go in running state - * immediately. - * @retval false if preemption is not required. - * - * @special - */ -bool chSchIsPreemptionRequired(void) { - tprio_t p1 = firstprio(&ch.rlist.r_queue); - tprio_t p2 = currp->p_prio; -#if CH_CFG_TIME_QUANTUM > 0 - /* If the running thread has not reached its time quantum, reschedule only - if the first thread on the ready queue has a higher priority. - Otherwise, if the running thread has used up its time quantum, reschedule - if the first thread on the ready queue has equal or higher priority.*/ - return currp->p_preempt ? p1 > p2 : p1 >= p2; -#else - /* If the round robin preemption feature is not enabled then performs a - simpler comparison.*/ - return p1 > p2; -#endif -} - -/** - * @brief Switches to the first thread on the runnable queue. - * @details The current thread is positioned in the ready list behind all - * threads having the same priority. The thread regains its time - * quantum. - * @note Not a user function, it is meant to be invoked by the scheduler - * itself or from within the port layer. - * - * @special - */ -void chSchDoRescheduleBehind(void) { - thread_t *otp; - - otp = currp; - /* Picks the first thread from the ready queue and makes it current.*/ - setcurrp(queue_fifo_remove(&ch.rlist.r_queue)); - currp->p_state = CH_STATE_CURRENT; -#if CH_CFG_TIME_QUANTUM > 0 - otp->p_preempt = CH_CFG_TIME_QUANTUM; -#endif - chSchReadyI(otp); - chSysSwitch(currp, otp); -} - -/** - * @brief Switches to the first thread on the runnable queue. - * @details The current thread is positioned in the ready list ahead of all - * threads having the same priority. - * @note Not a user function, it is meant to be invoked by the scheduler - * itself or from within the port layer. - * - * @special - */ -void chSchDoRescheduleAhead(void) { - thread_t *otp, *cp; - - otp = currp; - /* Picks the first thread from the ready queue and makes it current.*/ - setcurrp(queue_fifo_remove(&ch.rlist.r_queue)); - currp->p_state = CH_STATE_CURRENT; - - otp->p_state = CH_STATE_READY; - cp = (thread_t *)&ch.rlist.r_queue; - do { - cp = cp->p_next; - } while (cp->p_prio > otp->p_prio); - /* Insertion on p_prev.*/ - otp->p_next = cp; - otp->p_prev = cp->p_prev; - otp->p_prev->p_next = cp->p_prev = otp; - - chSysSwitch(currp, otp); -} - -/** - * @brief Switches to the first thread on the runnable queue. - * @details The current thread is positioned in the ready list behind or - * ahead of all threads having the same priority depending on - * if it used its whole time slice. - * @note Not a user function, it is meant to be invoked by the scheduler - * itself or from within the port layer. - * - * @special - */ -void chSchDoReschedule(void) { - -#if CH_CFG_TIME_QUANTUM > 0 - /* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios - to handle on preemption: time quantum elapsed or not.*/ - if (currp->p_preempt == 0) { - /* The thread consumed its time quantum so it is enqueued behind threads - with same priority level, however, it acquires a new time quantum.*/ - chSchDoRescheduleBehind(); - } - else { - /* The thread didn't consume all its time quantum so it is put ahead of - threads with equal priority and does not acquire a new time quantum.*/ - chSchDoRescheduleAhead(); - } -#else /* !(CH_CFG_TIME_QUANTUM > 0) */ - /* If the round-robin mechanism is disabled then the thread goes always - ahead of its peers.*/ - chSchDoRescheduleAhead(); -#endif /* !(CH_CFG_TIME_QUANTUM > 0) */ -} - -/** @} */ diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c deleted file mode 100644 index 388e50bc6..000000000 --- a/os/kernel/src/chsem.c +++ /dev/null @@ -1,401 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chsem.c - * @brief Semaphores code. - * - * @addtogroup semaphores - * @details Semaphores related APIs and services. - * - *

Operation mode

- * Semaphores are a flexible synchronization primitive, ChibiOS/RT - * implements semaphores in their "counting semaphores" variant as - * defined by Edsger Dijkstra plus several enhancements like: - * - Wait operation with timeout. - * - Reset operation. - * - Atomic wait+signal operation. - * - Return message from the wait operation (OK, RESET, TIMEOUT). - * . - * The binary semaphores variant can be easily implemented using - * counting semaphores.
- * Operations defined for semaphores: - * - Signal: The semaphore counter is increased and if the - * result is non-positive then a waiting thread is removed from - * the semaphore queue and made ready for execution. - * - Wait: The semaphore counter is decreased and if the result - * becomes negative the thread is queued in the semaphore and - * suspended. - * - Reset: The semaphore counter is reset to a non-negative - * value and all the threads in the queue are released. - * . - * Semaphores can be used as guards for mutual exclusion zones - * (note that mutexes are recommended for this kind of use) but - * also have other uses, queues guards and counters for example.
- * Semaphores usually use a FIFO queuing strategy but it is possible - * to make them order threads by priority by enabling - * @p CH_CFG_USE_SEMAPHORES_PRIORITY in @p chconf.h. - * @pre In order to use the semaphore APIs the @p CH_CFG_USE_SEMAPHORES - * option must be enabled in @p chconf.h. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -#if CH_CFG_USE_SEMAPHORES_PRIORITY -#define sem_insert(tp, qp) prio_insert(tp, qp) -#else -#define sem_insert(tp, qp) queue_insert(tp, qp) -#endif - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes a semaphore with the specified counter value. - * - * @param[out] sp pointer to a @p semaphore_t structure - * @param[in] n initial value of the semaphore counter. Must be - * non-negative. - * - * @init - */ -void chSemObjectInit(semaphore_t *sp, cnt_t n) { - - chDbgCheck((sp != NULL) && (n >= 0)); - - queue_init(&sp->s_queue); - sp->s_cnt = n; -} - -/** - * @brief Performs a reset operation on the semaphore. - * @post After invoking this function all the threads waiting on the - * semaphore, if any, are released and the semaphore counter is set - * to the specified, non negative, value. - * @note The released threads can recognize they were waked up by a reset - * rather than a signal because the @p chSemWait() will return - * @p RDY_RESET instead of @p RDY_OK. - * - * @param[in] sp pointer to a @p semaphore_t structure - * @param[in] n the new value of the semaphore counter. The value must - * be non-negative. - * - * @api - */ -void chSemReset(semaphore_t *sp, cnt_t n) { - - chSysLock(); - chSemResetI(sp, n); - chSchRescheduleS(); - chSysUnlock(); -} - -/** - * @brief Performs a reset operation on the semaphore. - * @post After invoking this function all the threads waiting on the - * semaphore, if any, are released and the semaphore counter is set - * to the specified, non negative, value. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. Note that - * interrupt handlers always reschedule on exit so an explicit - * reschedule must not be performed in ISRs. - * @note The released threads can recognize they were waked up by a reset - * rather than a signal because the @p chSemWait() will return - * @p RDY_RESET instead of @p RDY_OK. - * - * @param[in] sp pointer to a @p semaphore_t structure - * @param[in] n the new value of the semaphore counter. The value must - * be non-negative. - * - * @iclass - */ -void chSemResetI(semaphore_t *sp, cnt_t n) { - cnt_t cnt; - - chDbgCheckClassI(); - chDbgCheck((sp != NULL) && (n >= 0)); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "inconsistent semaphore"); - - cnt = sp->s_cnt; - sp->s_cnt = n; - while (++cnt <= 0) - chSchReadyI(queue_lifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_RESET; -} - -/** - * @brief Performs a wait operation on a semaphore. - * - * @param[in] sp pointer to a @p semaphore_t structure - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval RDY_OK if the thread has not stopped on the semaphore or the - * semaphore has been signaled. - * @retval RDY_RESET if the semaphore has been reset using @p chSemReset(). - * - * @api - */ -msg_t chSemWait(semaphore_t *sp) { - msg_t msg; - - chSysLock(); - msg = chSemWaitS(sp); - chSysUnlock(); - return msg; -} - -/** - * @brief Performs a wait operation on a semaphore. - * - * @param[in] sp pointer to a @p semaphore_t structure - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval RDY_OK if the thread has not stopped on the semaphore or the - * semaphore has been signaled. - * @retval RDY_RESET if the semaphore has been reset using @p chSemReset(). - * - * @sclass - */ -msg_t chSemWaitS(semaphore_t *sp) { - - chDbgCheckClassS(); - chDbgCheck(sp != NULL); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "inconsistent semaphore"); - - if (--sp->s_cnt < 0) { - currp->p_u.wtobjp = sp; - sem_insert(currp, &sp->s_queue); - chSchGoSleepS(CH_STATE_WTSEM); - return currp->p_u.rdymsg; - } - return RDY_OK; -} - -/** - * @brief Performs a wait operation on a semaphore with timeout specification. - * - * @param[in] sp pointer to a @p semaphore_t structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval RDY_OK if the thread has not stopped on the semaphore or the - * semaphore has been signaled. - * @retval RDY_RESET if the semaphore has been reset using @p chSemReset(). - * @retval RDY_TIMEOUT if the semaphore has not been signaled or reset within - * the specified timeout. - * - * @api - */ -msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time) { - msg_t msg; - - chSysLock(); - msg = chSemWaitTimeoutS(sp, time); - chSysUnlock(); - return msg; -} - -/** - * @brief Performs a wait operation on a semaphore with timeout specification. - * - * @param[in] sp pointer to a @p semaphore_t structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval RDY_OK if the thread has not stopped on the semaphore or the - * semaphore has been signaled. - * @retval RDY_RESET if the semaphore has been reset using @p chSemReset(). - * @retval RDY_TIMEOUT if the semaphore has not been signaled or reset within - * the specified timeout. - * - * @sclass - */ -msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { - - chDbgCheckClassS(); - chDbgCheck(sp != NULL); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "inconsistent semaphore"); - - if (--sp->s_cnt < 0) { - if (TIME_IMMEDIATE == time) { - sp->s_cnt++; - return RDY_TIMEOUT; - } - currp->p_u.wtobjp = sp; - sem_insert(currp, &sp->s_queue); - return chSchGoSleepTimeoutS(CH_STATE_WTSEM, time); - } - return RDY_OK; -} - -/** - * @brief Performs a signal operation on a semaphore. - * - * @param[in] sp pointer to a @p semaphore_t structure - * - * @api - */ -void chSemSignal(semaphore_t *sp) { - - chDbgCheck(sp != NULL); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "inconsistent semaphore"); - - chSysLock(); - if (++sp->s_cnt <= 0) - chSchWakeupS(queue_fifo_remove(&sp->s_queue), RDY_OK); - chSysUnlock(); -} - -/** - * @brief Performs a signal operation on a semaphore. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. Note that - * interrupt handlers always reschedule on exit so an explicit - * reschedule must not be performed in ISRs. - * - * @param[in] sp pointer to a @p semaphore_t structure - * - * @iclass - */ -void chSemSignalI(semaphore_t *sp) { - - chDbgCheckClassI(); - chDbgCheck(sp != NULL); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "inconsistent semaphore"); - - if (++sp->s_cnt <= 0) { - /* Note, it is done this way in order to allow a tail call on - chSchReadyI().*/ - thread_t *tp = queue_fifo_remove(&sp->s_queue); - tp->p_u.rdymsg = RDY_OK; - chSchReadyI(tp); - } -} - -/** - * @brief Adds the specified value to the semaphore counter. - * @post This function does not reschedule so a call to a rescheduling - * function must be performed before unlocking the kernel. Note that - * interrupt handlers always reschedule on exit so an explicit - * reschedule must not be performed in ISRs. - * - * @param[in] sp pointer to a @p semaphore_t structure - * @param[in] n value to be added to the semaphore counter. The value - * must be positive. - * - * @iclass - */ -void chSemAddCounterI(semaphore_t *sp, cnt_t n) { - - chDbgCheckClassI(); - chDbgCheck((sp != NULL) && (n > 0)); - chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || - ((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), - "inconsistent semaphore"); - - while (n > 0) { - if (++sp->s_cnt <= 0) - chSchReadyI(queue_fifo_remove(&sp->s_queue))->p_u.rdymsg = RDY_OK; - n--; - } -} - -/** - * @brief Performs atomic signal and wait operations on two semaphores. - * - * @param[in] sps pointer to a @p semaphore_t structure to be signaled - * @param[in] spw pointer to a @p semaphore_t structure to wait on - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval RDY_OK if the thread has not stopped on the semaphore or the - * semaphore has been signaled. - * @retval RDY_RESET if the semaphore has been reset using @p chSemReset(). - * - * @api - */ -msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { - msg_t msg; - - chDbgCheck((sps != NULL) && (spw != NULL)); - chDbgAssert(((sps->s_cnt >= 0) && queue_isempty(&sps->s_queue)) || - ((sps->s_cnt < 0) && queue_notempty(&sps->s_queue)), - "inconsistent semaphore"); - chDbgAssert(((spw->s_cnt >= 0) && queue_isempty(&spw->s_queue)) || - ((spw->s_cnt < 0) && queue_notempty(&spw->s_queue)), - "inconsistent semaphore"); - - chSysLock(); - if (++sps->s_cnt <= 0) - chSchReadyI(queue_fifo_remove(&sps->s_queue))->p_u.rdymsg = RDY_OK; - if (--spw->s_cnt < 0) { - thread_t *ctp = currp; - sem_insert(ctp, &spw->s_queue); - ctp->p_u.wtobjp = spw; - chSchGoSleepS(CH_STATE_WTSEM); - msg = ctp->p_u.rdymsg; - } - else { - chSchRescheduleS(); - msg = RDY_OK; - } - chSysUnlock(); - return msg; -} - -#endif /* CH_CFG_USE_SEMAPHORES */ - -/** @} */ diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c deleted file mode 100644 index 653d8da77..000000000 --- a/os/kernel/src/chstats.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chstats.c - * @brief Statistics module code. - * - * @addtogroup statistics - * @details Statistics services. - * @{ - */ - -#include "ch.h" - -#if CH_DBG_STATISTICS || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes the statistics module. - * - * @init - */ -void _stats_init(void) { - - ch.kernel_stats.n_irq = 0; - ch.kernel_stats.n_ctxswc = 0; - chTMObjectInit(&ch.kernel_stats.m_crit_thd); - chTMObjectInit(&ch.kernel_stats.m_crit_isr); -} - -/** - * @brief Increases the IRQ counter. - */ -void _stats_increase_irq(void) { - - ch.kernel_stats.n_irq++; -} - -/** - * @brief Updates context switch related statistics. - */ -void _stats_ctxswc(thread_t *ntp, thread_t *otp) { - - ch.kernel_stats.n_ctxswc++; - chTMChainMeasurementToX(&otp->p_stats, &ntp->p_stats); -} - -/** - * @brief Starts the measurement of a thread critical zone. - */ -void _stats_start_measure_crit_thd(void) { - - chTMStartMeasurementX(&ch.kernel_stats.m_crit_thd); -} - -/** - * @brief Stops the measurement of a thread critical zone. - */ -void _stats_stop_measure_crit_thd(void) { - - chTMStopMeasurementX(&ch.kernel_stats.m_crit_thd); -} - -/** - * @brief Starts the measurement of an ISR critical zone. - */ -void _stats_start_measure_crit_isr(void) { - - chTMStartMeasurementX(&ch.kernel_stats.m_crit_isr); -} - -/** - * @brief Stops the measurement of an ISR critical zone. - */ -void _stats_stop_measure_crit_isr(void) { - - chTMStopMeasurementX(&ch.kernel_stats.m_crit_isr); -} - -#endif /* CH_DBG_STATISTICS */ - -/** @} */ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c deleted file mode 100644 index 9212cbf5f..000000000 --- a/os/kernel/src/chsys.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chsys.c - * @brief System related code. - * - * @addtogroup system - * @details System related APIs and services: - * - Initialization. - * - Locks. - * - Interrupt Handling. - * - Power Management. - * - Abnormal Termination. - * - Realtime counter. - * . - * @{ - */ - -#include "ch.h" - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/** - * @brief System data structures. - */ -ch_system_t ch; - -#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) -/** - * @brief Idle thread working area. - */ -static WORKING_AREA(_idle_thread_wa, CH_PORT_IDLE_THREAD_STACK_SIZE); -#endif /* CH_CFG_NO_IDLE_THREAD */ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__) -/** - * @brief This function implements the idle thread infinite loop. - * @details The function puts the processor in the lowest power mode capable - * to serve interrupts.
- * The priority is internally set to the minimum system value so - * that this thread is executed only if there are no other ready - * threads in the system. - * - * @param[in] p the thread parameter, unused in this scenario - */ -static void _idle_thread(void *p) { - - (void)p; - chRegSetThreadName("idle"); - while (true) { - port_wait_for_interrupt(); - CH_CFG_IDLE_LOOP_HOOK(); - } -} -#endif /* CH_CFG_NO_IDLE_THREAD */ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief ChibiOS/RT initialization. - * @details After executing this function the current instructions stream - * becomes the main thread. - * @pre Interrupts must be still disabled when @p chSysInit() is invoked - * and are internally enabled. - * @post The main thread is created with priority @p NORMALPRIO. - * @note This function has special, architecture-dependent, requirements, - * see the notes into the various port reference manuals. - * - * @special - */ -void chSysInit(void) { - static thread_t mainthread; -#if CH_DBG_ENABLE_STACK_CHECK - extern stkalign_t __main_thread_stack_base__; -#endif - - port_init(); - _scheduler_init(); - _vt_init(); -#if CH_CFG_USE_TM - _tm_init(); -#endif -#if CH_CFG_USE_MEMCORE - _core_init(); -#endif -#if CH_CFG_USE_HEAP - _heap_init(); -#endif -#if CH_DBG_STATISTICS - _stats_init(); -#endif -#if CH_DBG_ENABLE_TRACE - _trace_init(); -#endif - -#if !CH_CFG_NO_IDLE_THREAD - /* Now this instructions flow becomes the main thread.*/ - setcurrp(_thread_init(&mainthread, NORMALPRIO)); -#else - /* Now this instructions flow becomes the main thread.*/ - setcurrp(_thread_init(&mainthread, IDLEPRIO)); -#endif - - currp->p_state = CH_STATE_CURRENT; -#if CH_DBG_ENABLE_STACK_CHECK - /* This is a special case because the main thread thread_t structure is not - adjacent to its stack area.*/ - currp->p_stklimit = &__main_thread_stack_base__; -#endif - chSysEnable(); - - /* Note, &ch_debug points to the string "main" if the registry is - active, else the parameter is ignored.*/ - chRegSetThreadName((const char *)&ch_debug); - -#if !CH_CFG_NO_IDLE_THREAD - /* This thread has the lowest priority in the system, its role is just to - serve interrupts in its context while keeping the lowest energy saving - mode compatible with the system status.*/ - chThdCreateStatic(_idle_thread_wa, sizeof(_idle_thread_wa), IDLEPRIO, - (tfunc_t)_idle_thread, NULL); -#endif -} - -/** - * @brief Halts the system. - * @details This function is invoked by the operating system when an - * unrecoverable error is detected, for example because a programming - * error in the application code that triggers an assertion while - * in debug mode. - * @note Can be invoked from any system state. - * - * @special - */ -void chSysHalt(void) { - - port_disable(); - -#if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) - CH_CFG_SYSTEM_HALT_HOOK(); -#endif - - /* Harmless infinite loop.*/ - while (true) - ; -} - -/** - * @brief Handles time ticks for round robin preemption and timer increments. - * @details Decrements the remaining time quantum of the running thread - * and preempts it when the quantum is used up. Increments system - * time and manages the timers. - * @note The frequency of the timer determines the system tick granularity - * and, together with the @p CH_CFG_TIME_QUANTUM macro, the round robin - * interval. - * - * @iclass - */ -void chSysTimerHandlerI(void) { - - chDbgCheckClassI(); - -#if CH_CFG_TIME_QUANTUM > 0 - /* Running thread has not used up quantum yet? */ - if (currp->p_preempt > 0) - /* Decrement remaining quantum.*/ - currp->p_preempt--; -#endif -#if CH_DBG_THREADS_PROFILING - currp->p_time++; -#endif - chVTDoTickI(); -#if defined(CH_CFG_SYSTEM_TICK_HOOK) - CH_CFG_SYSTEM_TICK_HOOK(); -#endif -} - - -/** - * @brief Returns the execution context and enters the kernel lock mode. - * @details This functions enters into a critical zone and can be called - * from any context. Because its flexibility it is less efficient - * than @p chSysLock() which is preferable when the calling context - * is known. - * - * @return The previous system status, the encoding of this - * status word is architecture-dependent and opaque. - * - * @xclass - */ -syssts_t chSysGetAndLockX(void) { - - syssts_t sts = port_get_irq_status(); - if (port_irq_enabled(sts)) { - if (port_is_isr_context()) - chSysLockFromISR(); - else - chSysLock(); - } - return sts; -} - -/** - * @brief Restores the specified execution status. - * - * @param[in] sts the system status to be restored. - * - * @xclass - */ -void chSysRestoreLockX(syssts_t sts) { - - if (port_irq_enabled(sts)) { - if (port_is_isr_context()) - chSysUnlockFromISR(); - else - chSysUnlock(); - } -} - -#if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__) -/** - * @brief Realtime window test. - * @details This function verifies if the current realtime counter value - * lies within the specified range or not. The test takes care - * of the realtime counter wrapping to zero on overflow. - * @note When start==end then the function returns always true because the - * whole time range is specified. - * @note This function is only available if the port layer supports the - * option @p CH_PORT_SUPPORTS_RT. - * - * @param[in] cnt the counter value to be tested - * @param[in] start the start of the time window (inclusive) - * @param[in] end the end of the time window (non inclusive) - * @retval true current time within the specified time window. - * @retval false current time not within the specified time window. - * - * @xclass - */ -bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) { - - return end > start ? (cnt >= start) && (cnt < end) : - (cnt >= start) || (cnt < end); -} - -/** - * @brief Polled delay. - * @note The real delay is always few cycles in excess of the specified - * value. - * @note This function is only available if the port layer supports the - * option @p CH_PORT_SUPPORTS_RT. - * - * @param[in] cycles number of cycles - * - * @xclass - */ -void chSysPolledDelayX(rtcnt_t cycles) { - rtcnt_t start = chSysGetRealtimeCounterX(); - rtcnt_t end = start + cycles; - while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) - ; -} -#endif /* CH_PORT_SUPPORTS_RT */ - -/** @} */ diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c deleted file mode 100644 index 073b6eed7..000000000 --- a/os/kernel/src/chthreads.c +++ /dev/null @@ -1,462 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chthreads.c - * @brief Threads code. - * - * @addtogroup threads - * @details Threads related APIs and services. - * - *

Operation mode

- * A thread is an abstraction of an independent instructions flow. - * In ChibiOS/RT a thread is represented by a "C" function owning - * a processor context, state informations and a dedicated stack - * area. In this scenario static variables are shared among all - * threads while automatic variables are local to the thread.
- * Operations defined for threads: - * - Create, a thread is started on the specified thread - * function. This operation is available in multiple variants, - * both static and dynamic. - * - Exit, a thread terminates by returning from its top - * level function or invoking a specific API, the thread can - * return a value that can be retrieved by other threads. - * - Wait, a thread waits for the termination of another - * thread and retrieves its return value. - * - Resume, a thread created in suspended state is started. - * - Sleep, the execution of a thread is suspended for the - * specified amount of time or the specified future absolute time - * is reached. - * - SetPriority, a thread changes its own priority level. - * - Yield, a thread voluntarily renounces to its time slot. - * . - * The threads subsystem is implicitly included in kernel however - * some of its part may be excluded by disabling them in @p chconf.h, - * see the @p CH_CFG_USE_WAITEXIT and @p CH_CFG_USE_DYNAMIC configuration - * options. - * @{ - */ - -#include "ch.h" - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes a thread structure. - * @note This is an internal functions, do not use it in application code. - * - * @param[in] tp pointer to the thread - * @param[in] prio the priority level for the new thread - * @return The same thread pointer passed as parameter. - * - * @notapi - */ -thread_t *_thread_init(thread_t *tp, tprio_t prio) { - - tp->p_prio = prio; - tp->p_state = CH_STATE_SUSPENDED; - tp->p_flags = CH_FLAG_MODE_STATIC; -#if CH_CFG_TIME_QUANTUM > 0 - tp->p_preempt = CH_CFG_TIME_QUANTUM; -#endif -#if CH_CFG_USE_MUTEXES - tp->p_realprio = prio; - tp->p_mtxlist = NULL; -#endif -#if CH_CFG_USE_EVENTS - tp->p_epending = 0; -#endif -#if CH_DBG_THREADS_PROFILING - tp->p_time = 0; -#endif -#if CH_CFG_USE_DYNAMIC - tp->p_refs = 1; -#endif -#if CH_CFG_USE_REGISTRY - tp->p_name = NULL; - REG_INSERT(tp); -#endif -#if CH_CFG_USE_WAITEXIT - list_init(&tp->p_waiting); -#endif -#if CH_CFG_USE_MESSAGES - queue_init(&tp->p_msgqueue); -#endif -#if CH_DBG_ENABLE_STACK_CHECK - tp->p_stklimit = (stkalign_t *)(tp + 1); -#endif -#if CH_DBG_STATISTICS || defined(__DOXYGEN__) - chTMStartMeasurementX(&tp->p_stats); -#endif -#if defined(CH_CFG_THREAD_INIT_HOOK) - CH_CFG_THREAD_INIT_HOOK(tp); -#endif - return tp; -} - -#if CH_DBG_FILL_THREADS || defined(__DOXYGEN__) -/** - * @brief Memory fill utility. - * - * @param[in] startp first address to fill - * @param[in] endp last address to fill +1 - * @param[in] v filler value - * - * @notapi - */ -void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { - - while (startp < endp) - *startp++ = v; -} -#endif /* CH_DBG_FILL_THREADS */ - -/** - * @brief Creates a new thread into a static memory area. - * @details The new thread is initialized but not inserted in the ready list, - * the initial state is @p CH_STATE_SUSPENDED. - * @post The initialized thread can be subsequently started by invoking - * @p chThdResume(), @p chThdResumeI() or @p chSchWakeupS() - * depending on the execution context. - * @note A thread can terminate by calling @p chThdExit() or by simply - * returning from its main function. - * @note Threads created using this function do not obey to the - * @p CH_DBG_FILL_THREADS debug option because it would keep - * the kernel locked for too much time. - * - * @param[out] wsp pointer to a working area dedicated to the thread stack - * @param[in] size size of the working area - * @param[in] prio the priority level for the new thread - * @param[in] pf the thread function - * @param[in] arg an argument passed to the thread function. It can be - * @p NULL. - * @return The pointer to the @p thread_t structure allocated for - * the thread into the working space area. - * - * @iclass - */ -thread_t *chThdCreateI(void *wsp, size_t size, - tprio_t prio, tfunc_t pf, void *arg) { - /* The thread structure is laid out in the lower part of the thread - workspace.*/ - thread_t *tp = wsp; - - chDbgCheckClassI(); - - chDbgCheck((wsp != NULL) && (size >= THD_WA_SIZE(0)) && - (prio <= HIGHPRIO) && (pf != NULL)); - SETUP_CONTEXT(wsp, size, pf, arg); - return _thread_init(tp, prio); -} - -/** - * @brief Creates a new thread into a static memory area. - * @note A thread can terminate by calling @p chThdExit() or by simply - * returning from its main function. - * - * @param[out] wsp pointer to a working area dedicated to the thread stack - * @param[in] size size of the working area - * @param[in] prio the priority level for the new thread - * @param[in] pf the thread function - * @param[in] arg an argument passed to the thread function. It can be - * @p NULL. - * @return The pointer to the @p thread_t structure allocated for - * the thread into the working space area. - * - * @api - */ -thread_t *chThdCreateStatic(void *wsp, size_t size, - tprio_t prio, tfunc_t pf, void *arg) { - thread_t *tp; - -#if CH_DBG_FILL_THREADS - _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(thread_t), - CH_DBG_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(thread_t), - (uint8_t *)wsp + size, - CH_DBG_STACK_FILL_VALUE); -#endif - chSysLock(); - chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK); - chSysUnlock(); - return tp; -} - -/** - * @brief Changes the running thread priority level then reschedules if - * necessary. - * @note The function returns the real thread priority regardless of the - * current priority that could be higher than the real priority - * because the priority inheritance mechanism. - * - * @param[in] newprio the new priority level of the running thread - * @return The old priority level. - * - * @api - */ -tprio_t chThdSetPriority(tprio_t newprio) { - tprio_t oldprio; - - chDbgCheck(newprio <= HIGHPRIO); - - chSysLock(); -#if CH_CFG_USE_MUTEXES - oldprio = currp->p_realprio; - if ((currp->p_prio == currp->p_realprio) || (newprio > currp->p_prio)) - currp->p_prio = newprio; - currp->p_realprio = newprio; -#else - oldprio = currp->p_prio; - currp->p_prio = newprio; -#endif - chSchRescheduleS(); - chSysUnlock(); - return oldprio; -} - -/** - * @brief Resumes a suspended thread. - * @pre The specified thread pointer must refer to an initialized thread - * in the @p CH_STATE_SUSPENDED state. - * @post The specified thread is immediately started or put in the ready - * list depending on the relative priority levels. - * @note Use this function to start threads created with @p chThdCreateI(). - * - * @param[in] tp pointer to the thread - * @return The pointer to the thread. - * - * @api - */ -thread_t *chThdResume(thread_t *tp) { - - chSysLock(); - chDbgAssert(tp->p_state == CH_STATE_SUSPENDED, - "thread not in CH_STATE_SUSPENDED state"); - chSchWakeupS(tp, RDY_OK); - chSysUnlock(); - return tp; -} - -/** - * @brief Requests a thread termination. - * @pre The target thread must be written to invoke periodically - * @p chThdShouldTerminate() and terminate cleanly if it returns - * @p true. - * @post The specified thread will terminate after detecting the termination - * condition. - * - * @param[in] tp pointer to the thread - * - * @api - */ -void chThdTerminate(thread_t *tp) { - - chSysLock(); - tp->p_flags |= CH_FLAG_TERMINATE; - chSysUnlock(); -} - -/** - * @brief Suspends the invoking thread for the specified time. - * - * @param[in] time the delay in system ticks, the special values are - * handled as follow: - * - @a TIME_INFINITE the thread enters an infinite sleep - * state. - * - @a TIME_IMMEDIATE this value is not allowed. - * . - * - * @api - */ -void chThdSleep(systime_t time) { - - chDbgCheck(time != TIME_IMMEDIATE); - - chSysLock(); - chThdSleepS(time); - chSysUnlock(); -} - -/** - * @brief Suspends the invoking thread until the system time arrives to the - * specified value. - * - * @param[in] time absolute system time - * - * @api - */ -void chThdSleepUntil(systime_t time) { - - chSysLock(); - if ((time -= chVTGetSystemTimeX()) > 0) - chThdSleepS(time); - chSysUnlock(); -} - -/** - * @brief Yields the time slot. - * @details Yields the CPU control to the next thread in the ready list with - * equal priority, if any. - * - * @api - */ -void chThdYield(void) { - - chSysLock(); - chSchDoYieldS(); - chSysUnlock(); -} - -/** - * @brief Terminates the current thread. - * @details The thread goes in the @p CH_STATE_FINAL state holding the - * specified exit status code, other threads can retrieve the - * exit status code by invoking the function @p chThdWait(). - * @post Eventual code after this function will never be executed, - * this function never returns. The compiler has no way to - * know this so do not assume that the compiler would remove - * the dead code. - * - * @param[in] msg thread exit code - * - * @api - */ -void chThdExit(msg_t msg) { - - chSysLock(); - chThdExitS(msg); - /* The thread never returns here.*/ -} - -/** - * @brief Terminates the current thread. - * @details The thread goes in the @p CH_STATE_FINAL state holding the - * specified exit status code, other threads can retrieve the - * exit status code by invoking the function @p chThdWait(). - * @post Eventual code after this function will never be executed, - * this function never returns. The compiler has no way to - * know this so do not assume that the compiler would remove - * the dead code. - * - * @param[in] msg thread exit code - * - * @sclass - */ -void chThdExitS(msg_t msg) { - thread_t *tp = currp; - - tp->p_u.exitcode = msg; -#if defined(CH_CFG_THREAD_EXIT_HOOK) - CH_CFG_THREAD_EXIT_HOOK(tp); -#endif -#if CH_CFG_USE_WAITEXIT - while (list_notempty(&tp->p_waiting)) - chSchReadyI(list_remove(&tp->p_waiting)); -#endif -#if CH_CFG_USE_REGISTRY - /* Static threads are immediately removed from the registry because - there is no memory to recover.*/ - if ((tp->p_flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) - REG_REMOVE(tp); -#endif - chSchGoSleepS(CH_STATE_FINAL); - /* The thread never returns here.*/ - chDbgAssert(false, "zombies apocalypse"); -} - -#if CH_CFG_USE_WAITEXIT || defined(__DOXYGEN__) -/** - * @brief Blocks the execution of the invoking thread until the specified - * thread terminates then the exit code is returned. - * @details This function waits for the specified thread to terminate then - * decrements its reference counter, if the counter reaches zero then - * the thread working area is returned to the proper allocator.
- * The memory used by the exited thread is handled in different ways - * depending on the API that spawned the thread: - * - If the thread was spawned by @p chThdCreateStatic() or by - * @p chThdCreateI() then nothing happens and the thread working - * area is not released or modified in any way. This is the - * default, totally static, behavior. - * - If the thread was spawned by @p chThdCreateFromHeap() then - * the working area is returned to the system heap. - * - If the thread was spawned by @p chThdCreateFromMemoryPool() - * then the working area is returned to the owning memory pool. - * . - * @pre The configuration option @p CH_CFG_USE_WAITEXIT must be enabled in - * order to use this function. - * @post Enabling @p chThdWait() requires 2-4 (depending on the - * architecture) extra bytes in the @p thread_t structure. - * @post After invoking @p chThdWait() the thread pointer becomes invalid - * and must not be used as parameter for further system calls. - * @note If @p CH_CFG_USE_DYNAMIC is not specified this function just waits for - * the thread termination, no memory allocators are involved. - * - * @param[in] tp pointer to the thread - * @return The exit code from the terminated thread. - * - * @api - */ -msg_t chThdWait(thread_t *tp) { - msg_t msg; - - chDbgCheck(tp != NULL); - - chSysLock(); - chDbgAssert(tp != currp, "waiting self"); -#if CH_CFG_USE_DYNAMIC - chDbgAssert(tp->p_refs > 0, "not referenced"); -#endif - if (tp->p_state != CH_STATE_FINAL) { - list_insert(currp, &tp->p_waiting); - chSchGoSleepS(CH_STATE_WTEXIT); - } - msg = tp->p_u.exitcode; - chSysUnlock(); -#if CH_CFG_USE_DYNAMIC - chThdRelease(tp); -#endif - return msg; -} -#endif /* CH_CFG_USE_WAITEXIT */ - -/** @} */ diff --git a/os/kernel/src/chtm.c b/os/kernel/src/chtm.c deleted file mode 100644 index 24239e0e2..000000000 --- a/os/kernel/src/chtm.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chtm.c - * @brief Time Measurement module code. - * - * @addtogroup time_measurement - * @details Time Measurement APIs and services. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_TM || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -static inline void tm_stop(time_measurement_t *tmp, - rtcnt_t now, - rtcnt_t offset) { - - tmp->n++; - tmp->last = now - tmp->last - offset; - tmp->cumulative += (rttime_t)tmp->last; - if (tmp->last > tmp->worst) - tmp->worst = tmp->last; - else if (tmp->last < tmp->best) - tmp->best = tmp->last; -} - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes the time measurement unit. - * - * @init - */ -void _tm_init(void) { - time_measurement_t tm; - - /* Time Measurement subsystem calibration, it does a null measurement - and calculates the call overhead which is subtracted to real - measurements.*/ - ch.measurement_offset = 0; - chTMObjectInit(&tm); - chTMStartMeasurementX(&tm); - chTMStopMeasurementX(&tm); - ch.measurement_offset = tm.last; -} - -/** - * @brief Initializes a @p TimeMeasurement object. - * - * @param[out] tmp pointer to a @p TimeMeasurement structure - * - * @init - */ -void chTMObjectInit(time_measurement_t *tmp) { - - tmp->best = (rtcnt_t)-1; - tmp->worst = (rtcnt_t)0; - tmp->last = (rtcnt_t)0; - tmp->n = (ucnt_t)0; - tmp->cumulative = (rttime_t)0; -} - -/** - * @brief Starts a measurement. - * @pre The @p time_measurement_t structure must be initialized. - * - * @param[in,out] tmp pointer to a @p TimeMeasurement structure - * - * @xclass - */ -NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp) { - - tmp->last = chSysGetRealtimeCounterX(); -} - -/** - * @brief Stops a measurement. - * @pre The @p time_measurement_t structure must be initialized. - * - * @param[in,out] tmp pointer to a @p time_measurement_t structure - * - * @xclass - */ -NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp) { - - tm_stop(tmp, chSysGetRealtimeCounterX(), ch.measurement_offset); -} - -#endif /* CH_CFG_USE_TM */ - -/** - * @brief Stops a measurement and chains to the next one using the same time - * stamp. - * - * @param[in,out] tmp1 pointer to the @p time_measurement_t structure to be - * stopped - * @param[in,out] tmp2 pointer to the @p time_measurement_t structure to be - * started - * - * - * @xclass - */ -NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1, - time_measurement_t *tmp2) { - - /* Starts new measurement.*/ - tmp2->last = chSysGetRealtimeCounterX(); - - /* Stops previous measurement using the same time stamp.*/ - tm_stop(tmp1, tmp2->last, 0); -} - -/** @} */ diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c deleted file mode 100644 index 3f1559ac4..000000000 --- a/os/kernel/src/chvt.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - 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 . -*/ - -/** - * @file chvt.c - * @brief Time and Virtual Timers module code. - * - * @addtogroup time - * @details Time and Virtual Timers related APIs and services. - * @{ - */ - -#include "ch.h" - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Virtual Timers initialization. - * @note Internal use only. - * - * @notapi - */ -void _vt_init(void) { - - ch.vtlist.vt_next = ch.vtlist.vt_prev = (void *)&ch.vtlist; - ch.vtlist.vt_delta = (systime_t)-1; -#if CH_CFG_TIMEDELTA == 0 - ch.vtlist.vt_systime = 0; -#else /* CH_CFG_TIMEDELTA > 0 */ - ch.vtlist.vt_lasttime = 0; -#endif /* CH_CFG_TIMEDELTA > 0 */ -} - -/** - * @brief Checks if the current system time is within the specified time - * window. - * @note When start==end then the function returns always true because the - * whole time range is specified. - * @note This function can be called from any context. - * - * @param[in] time the time to be verified - * @param[in] start the start of the time window (inclusive) - * @param[in] end the end of the time window (non inclusive) - * @retval true current time within the specified time window. - * @retval false current time not within the specified time window. - * - * @xclass - */ -bool chVTIsTimeWithinX(systime_t time, systime_t start, systime_t end) { - - return end > start ? (time >= start) && (time < end) : - (time >= start) || (time < end); -} - -/** - * @brief Enables a virtual timer. - * @details The timer is enabled and programmed to trigger after the delay - * specified as parameter. - * @pre The timer must not be already armed before calling this function. - * @note The callback function is invoked from interrupt context. - * - * @param[out] vtp the @p virtual_timer_t structure pointer - * @param[in] delay the number of ticks before the operation timeouts, the - * special values are handled as follow: - * - @a TIME_INFINITE is allowed but interpreted as a - * normal time specification. - * - @a TIME_IMMEDIATE this value is not allowed. - * . - * @param[in] vtfunc the timer callback function. After invoking the - * callback the timer is disabled and the structure can - * be disposed or reused. - * @param[in] par a parameter that will be passed to the callback - * function - * - * @iclass - */ -void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, - vtfunc_t vtfunc, void *par) { - virtual_timer_t *p; - - chDbgCheckClassI(); - chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE)); - - vtp->vt_par = par; - vtp->vt_func = vtfunc; - p = ch.vtlist.vt_next; - -#if CH_CFG_TIMEDELTA > 0 || defined(__DOXYGEN__) - { - systime_t now = port_timer_get_time(); - - /* If the requested delay is lower than the minimum safe delta then it - is raised to the minimum safe value.*/ - if (delay < CH_CFG_TIMEDELTA) - delay = CH_CFG_TIMEDELTA; - - if (&ch.vtlist == (virtual_timers_list_t *)p) { - /* The delta list is empty, the current time becomes the new - delta list base time.*/ - ch.vtlist.vt_lasttime = now; - port_timer_start_alarm(ch.vtlist.vt_lasttime + delay); - } - else { - /* Now the delay is calculated as delta from the last tick interrupt - time.*/ - delay += now - ch.vtlist.vt_lasttime; - - /* If the specified delay is closer in time than the first element - in the delta list then it becomes the next alarm event in time.*/ - if (delay < p->vt_delta) - port_timer_set_alarm(ch.vtlist.vt_lasttime + delay); - } - } -#endif /* CH_CFG_TIMEDELTA > 0 */ - - /* The delta list is scanned in order to find the correct position for - this timer. */ - while (p->vt_delta < delay) { - delay -= p->vt_delta; - p = p->vt_next; - } - /* The timer is inserted in the delta list.*/ - vtp->vt_prev = (vtp->vt_next = p)->vt_prev; - vtp->vt_prev->vt_next = p->vt_prev = vtp; - vtp->vt_delta = delay - - /* Special case when the timer is in last position in the list, the - value in the header must be restored.*/; - p->vt_delta -= delay; - ch.vtlist.vt_delta = (systime_t)-1; -} - -/** - * @brief Disables a Virtual Timer. - * @pre The timer must be in armed state before calling this function. - * - * @param[in] vtp the @p virtual_timer_t structure pointer - * - * @iclass - */ -void chVTDoResetI(virtual_timer_t *vtp) { - - chDbgCheckClassI(); - chDbgCheck(vtp != NULL); - chDbgAssert(vtp->vt_func != NULL, "timer not set or already triggered"); - - /* Removing the element from the delta list.*/ - vtp->vt_next->vt_delta += vtp->vt_delta; - vtp->vt_prev->vt_next = vtp->vt_next; - vtp->vt_next->vt_prev = vtp->vt_prev; - vtp->vt_func = (vtfunc_t)NULL; - - /* The above code changes the value in the header when the removed element - is the last of the list, restoring it.*/ - ch.vtlist.vt_delta = (systime_t)-1; - -#if CH_CFG_TIMEDELTA > 0 || defined(__DOXYGEN__) - { - if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.vt_next) { - /* Just removed the last element in the list, alarm timer stopped.*/ - port_timer_stop_alarm(); - } - else { - /* The alarm is set to the next element in the delta list.*/ - port_timer_set_alarm(ch.vtlist.vt_lasttime + - ch.vtlist.vt_next->vt_delta); - } - } -#endif /* CH_CFG_TIMEDELTA > 0 */ -} - -/** @} */ -- cgit v1.2.3