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