diff options
Diffstat (limited to 'os/rt/src')
-rw-r--r-- | os/rt/src/chcond.c | 30 | ||||
-rw-r--r-- | os/rt/src/chdebug.c | 214 | ||||
-rw-r--r-- | os/rt/src/chdynamic.c | 238 | ||||
-rw-r--r-- | os/rt/src/chevents.c | 102 | ||||
-rw-r--r-- | os/rt/src/chheap.c | 294 | ||||
-rw-r--r-- | os/rt/src/chmboxes.c | 434 | ||||
-rw-r--r-- | os/rt/src/chmemcore.c | 163 | ||||
-rw-r--r-- | os/rt/src/chmempools.c | 202 | ||||
-rw-r--r-- | os/rt/src/chmsg.c | 14 | ||||
-rw-r--r-- | os/rt/src/chmtx.c | 164 | ||||
-rw-r--r-- | os/rt/src/chqueues.c | 120 | ||||
-rw-r--r-- | os/rt/src/chregistry.c | 42 | ||||
-rw-r--r-- | os/rt/src/chschd.c | 248 | ||||
-rw-r--r-- | os/rt/src/chsem.c | 84 | ||||
-rw-r--r-- | os/rt/src/chstats.c | 2 | ||||
-rw-r--r-- | os/rt/src/chsys.c | 90 | ||||
-rw-r--r-- | os/rt/src/chthreads.c | 280 | ||||
-rw-r--r-- | os/rt/src/chvt.c | 102 |
18 files changed, 888 insertions, 1935 deletions
diff --git a/os/rt/src/chcond.c b/os/rt/src/chcond.c index 20b0cd47e..906f1dbc7 100644 --- a/os/rt/src/chcond.c +++ b/os/rt/src/chcond.c @@ -76,7 +76,7 @@ void chCondObjectInit(condition_variable_t *cp) { chDbgCheck(cp != NULL);
- queue_init(&cp->c_queue);
+ queue_init(&cp->queue);
}
/**
@@ -91,8 +91,8 @@ void chCondSignal(condition_variable_t *cp) { chDbgCheck(cp != NULL);
chSysLock();
- if (queue_notempty(&cp->c_queue)) {
- chSchWakeupS(queue_fifo_remove(&cp->c_queue), MSG_OK);
+ if (queue_notempty(&cp->queue)) {
+ chSchWakeupS(queue_fifo_remove(&cp->queue), MSG_OK);
}
chSysUnlock();
}
@@ -113,9 +113,9 @@ void chCondSignalI(condition_variable_t *cp) { chDbgCheckClassI();
chDbgCheck(cp != NULL);
- if (queue_notempty(&cp->c_queue)) {
- thread_t *tp = queue_fifo_remove(&cp->c_queue);
- tp->p_u.rdymsg = MSG_OK;
+ if (queue_notempty(&cp->queue)) {
+ thread_t *tp = queue_fifo_remove(&cp->queue);
+ tp->u.rdymsg = MSG_OK;
(void) chSchReadyI(tp);
}
}
@@ -154,8 +154,8 @@ void chCondBroadcastI(condition_variable_t *cp) { /* Empties the condition variable queue and inserts all the threads into the
ready list in FIFO order. The wakeup message is set to @p MSG_RESET in
order to make a chCondBroadcast() detectable from a chCondSignal().*/
- while (queue_notempty(&cp->c_queue)) {
- chSchReadyI(queue_fifo_remove(&cp->c_queue))->p_u.rdymsg = MSG_RESET;
+ while (queue_notempty(&cp->queue)) {
+ chSchReadyI(queue_fifo_remove(&cp->queue))->u.rdymsg = MSG_RESET;
}
}
@@ -209,7 +209,7 @@ msg_t chCondWaitS(condition_variable_t *cp) { chDbgCheckClassS();
chDbgCheck(cp != NULL);
- chDbgAssert(ctp->p_mtxlist != NULL, "not owning a mutex");
+ chDbgAssert(ctp->mtxlist != NULL, "not owning a mutex");
/* Getting "current" mutex and releasing it.*/
mp = chMtxGetNextMutexS();
@@ -217,10 +217,10 @@ msg_t chCondWaitS(condition_variable_t *cp) { /* Start waiting on the condition variable, on exit the mutex is taken
again.*/
- ctp->p_u.wtobjp = cp;
- queue_prio_insert(ctp, &cp->c_queue);
+ ctp->u.wtobjp = cp;
+ queue_prio_insert(ctp, &cp->queue);
chSchGoSleepS(CH_STATE_WTCOND);
- msg = ctp->p_u.rdymsg;
+ msg = ctp->u.rdymsg;
chMtxLockS(mp);
return msg;
@@ -299,7 +299,7 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { chDbgCheckClassS();
chDbgCheck((cp != NULL) && (time != TIME_IMMEDIATE));
- chDbgAssert(currp->p_mtxlist != NULL, "not owning a mutex");
+ chDbgAssert(currp->mtxlist != NULL, "not owning a mutex");
/* Getting "current" mutex and releasing it.*/
mp = chMtxGetNextMutexS();
@@ -307,8 +307,8 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) { /* Start waiting on the condition variable, on exit the mutex is taken
again.*/
- currp->p_u.wtobjp = cp;
- queue_prio_insert(currp, &cp->c_queue);
+ currp->u.wtobjp = cp;
+ queue_prio_insert(currp, &cp->queue);
msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, time);
if (msg != MSG_TIMEOUT) {
chMtxLockS(mp);
diff --git a/os/rt/src/chdebug.c b/os/rt/src/chdebug.c index bba6b4fa4..611cb39d2 100644 --- a/os/rt/src/chdebug.c +++ b/os/rt/src/chdebug.c @@ -101,6 +101,31 @@ /* Module local functions. */
/*===========================================================================*/
+#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE) || defined(__DOXYGEN__)
+/**
+ * @brief Writes a time stamp and increases the trace buffer pointer.
+ *
+ * @notapi
+ */
+NOINLINE static void trace_next(void) {
+
+ ch.dbg.trace_buffer.ptr->time = chVTGetSystemTimeX();
+#if PORT_SUPPORTS_RT == TRUE
+ ch.dbg.trace_buffer.ptr->rtstamp = chSysGetRealtimeCounterX();
+#else
+ ch.dbg.trace_buffer.ptr->rtstamp = (rtcnt_t)0;
+#endif
+
+ /* Trace hook, useful in order to interface debug tools.*/
+ CH_CFG_TRACE_HOOK(ch.dbg.trace_buffer.ptr);
+
+ if (++ch.dbg.trace_buffer.ptr >=
+ &ch.dbg.trace_buffer.buffer[CH_DBG_TRACE_BUFFER_SIZE]) {
+ ch.dbg.trace_buffer.ptr = &ch.dbg.trace_buffer.buffer[0];
+ }
+}
+#endif
+
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
@@ -256,17 +281,24 @@ void chDbgCheckClassS(void) { #endif /* CH_DBG_SYSTEM_STATE_CHECK == TRUE */
-#if (CH_DBG_ENABLE_TRACE == TRUE) || defined(__DOXYGEN__)
+#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE) || defined(__DOXYGEN__)
/**
* @brief Trace circular buffer subsystem initialization.
* @note Internal use only.
*/
void _dbg_trace_init(void) {
+ unsigned i;
- ch.dbg.trace_buffer.tb_size = CH_DBG_TRACE_BUFFER_SIZE;
- ch.dbg.trace_buffer.tb_ptr = &ch.dbg.trace_buffer.tb_buffer[0];
+ ch.dbg.trace_buffer.suspended = 0U;
+ ch.dbg.trace_buffer.size = CH_DBG_TRACE_BUFFER_SIZE;
+ ch.dbg.trace_buffer.ptr = &ch.dbg.trace_buffer.buffer[0];
+ for (i = 0U; i < CH_DBG_TRACE_BUFFER_SIZE; i++) {
+ ch.dbg.trace_buffer.buffer[i].type = CH_TRACE_TYPE_UNUSED;
+ }
}
+#if ((CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_SWITCH) != 0) || \
+ defined(__DOXYGEN__)
/**
* @brief Inserts in the circular debug trace buffer a context switch record.
*
@@ -274,17 +306,173 @@ void _dbg_trace_init(void) { *
* @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];
+void _dbg_trace_switch(thread_t *otp) {
+
+ if ((ch.dbg.trace_buffer.suspended & CH_TRACE_SUSPEND_SWITCH) == 0U) {
+ ch.dbg.trace_buffer.ptr->type = CH_TRACE_TYPE_SWITCH;
+ ch.dbg.trace_buffer.ptr->state = (uint8_t)otp->state;
+ ch.dbg.trace_buffer.ptr->u.sw.ntp = currp;
+ ch.dbg.trace_buffer.ptr->u.sw.wtobjp = otp->u.wtobjp;
+ trace_next();
}
}
-#endif /* CH_DBG_ENABLE_TRACE */
+#endif /* (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_SWITCH) != 0 */
+
+#if ((CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_ISR) != 0) || \
+ defined(__DOXYGEN__)
+/**
+ * @brief Inserts in the circular debug trace buffer an ISR-enter record.
+ *
+ * @param[in] isr name of the isr
+ *
+ * @notapi
+ */
+void _dbg_trace_isr_enter(const char *isr) {
+
+ if ((ch.dbg.trace_buffer.suspended & CH_TRACE_SUSPEND_ISR_ENTER) == 0U) {
+ port_lock_from_isr();
+ ch.dbg.trace_buffer.ptr->type = CH_TRACE_TYPE_ISR_ENTER;
+ ch.dbg.trace_buffer.ptr->state = 0U;
+ ch.dbg.trace_buffer.ptr->u.isr.name = isr;
+ trace_next();
+ port_unlock_from_isr();
+ }
+}
+
+/**
+ * @brief Inserts in the circular debug trace buffer an ISR-leave record.
+ *
+ * @param[in] isr name of the isr
+ *
+ * @notapi
+ */
+void _dbg_trace_isr_leave(const char *isr) {
+
+ if ((ch.dbg.trace_buffer.suspended & CH_TRACE_SUSPEND_ISR_LEAVE) == 0U) {
+ port_lock_from_isr();
+ ch.dbg.trace_buffer.ptr->type = CH_TRACE_TYPE_ISR_LEAVE;
+ ch.dbg.trace_buffer.ptr->state = 0U;
+ ch.dbg.trace_buffer.ptr->u.isr.name = isr;
+ trace_next();
+ port_unlock_from_isr();
+ }
+}
+#endif /* (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_ISR) != 0 */
+
+#if ((CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_HALT) != 0) || \
+ defined(__DOXYGEN__)
+/**
+ * @brief Inserts in the circular debug trace buffer an halt record.
+ *
+ * @param[in] reason the halt error string
+ *
+ * @notapi
+ */
+void _dbg_trace_halt(const char *reason) {
+
+ if ((ch.dbg.trace_buffer.suspended & CH_TRACE_SUSPEND_HALT) == 0U) {
+ ch.dbg.trace_buffer.ptr->type = CH_TRACE_TYPE_HALT;
+ ch.dbg.trace_buffer.ptr->state = 0;
+ ch.dbg.trace_buffer.ptr->u.halt.reason = reason;
+ trace_next();
+ }
+}
+#endif /* (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_HALT) != 0 */
+
+#if ((CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_USER) != 0) || \
+ defined(__DOXYGEN__)
+/**
+ * @brief Adds an user trace record to the trace buffer.
+ *
+ * @param[in] up1 user parameter 1
+ * @param[in] up2 user parameter 2
+ *
+ * @iclass
+ */
+void chDbgWriteTraceI(void *up1, void *up2) {
+
+ chDbgCheckClassI();
+
+ if ((ch.dbg.trace_buffer.suspended & CH_TRACE_SUSPEND_SWITCH) == 0U) {
+ ch.dbg.trace_buffer.ptr->type = CH_TRACE_TYPE_USER;
+ ch.dbg.trace_buffer.ptr->state = 0;
+ ch.dbg.trace_buffer.ptr->u.user.up1 = up1;
+ ch.dbg.trace_buffer.ptr->u.user.up2 = up2;
+ trace_next();
+ }
+}
+
+/**
+ * @brief Adds an user trace record to the trace buffer.
+ *
+ * @param[in] up1 user parameter 1
+ * @param[in] up2 user parameter 2
+ *
+ * @api
+ */
+void chDbgWriteTrace(void *up1, void *up2) {
+
+ chSysLock();
+ chDbgWriteTraceI(up1, up2);
+ chSysUnlock();
+}
+#endif /* (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_USER) != 0 */
+
+/**
+ * @brief Suspends one or more trace events.
+ *
+ * @paramin mask mask of the trace events to be suspended
+ *
+ * @iclass
+ */
+void chDbgSuspendTraceI(uint16_t mask) {
+
+ chDbgCheckClassI();
+
+ ch.dbg.trace_buffer.suspended |= mask;
+}
+
+/**
+ * @brief Suspends one or more trace events.
+ *
+ * @paramin mask mask of the trace events to be suspended
+ *
+ * @api
+ */
+void chDbgSuspendTrace(uint16_t mask) {
+
+ chSysLock();
+ chDbgSuspendTraceI(mask);
+ chSysUnlock();
+}
+
+/**
+ * @brief Resumes one or more trace events.
+ *
+ * @paramin mask mask of the trace events to be resumed
+ *
+ * @iclass
+ */
+void chDbgResumeTraceI(uint16_t mask) {
+
+ chDbgCheckClassI();
+
+ ch.dbg.trace_buffer.suspended &= ~mask;
+}
+
+/**
+ * @brief Resumes one or more trace events.
+ *
+ * @paramin mask mask of the trace events to be resumed
+ *
+ * @api
+ */
+void chDbgResumeTrace(uint16_t mask) {
+
+ chSysLock();
+ chDbgResumeTraceI(mask);
+ chSysUnlock();
+}
+#endif /* CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE */
/** @} */
diff --git a/os/rt/src/chdynamic.c b/os/rt/src/chdynamic.c deleted file mode 100644 index 01bfbeb25..000000000 --- a/os/rt/src/chdynamic.c +++ /dev/null @@ -1,238 +0,0 @@ -/*
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio.
-
- This file is part of ChibiOS.
-
- ChibiOS 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 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @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 == TRUE) || 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 < (trefs_t)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 <b>and</b> 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 > (trefs_t)0, "not referenced");
- tp->p_refs--;
- 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 == (trefs_t)0) && (tp->p_state == CH_STATE_FINAL)) {
- switch (tp->p_flags & CH_FLAG_MODE_MASK) {
-#if CH_CFG_USE_HEAP == TRUE
- case CH_FLAG_MODE_HEAP:
-#if CH_CFG_USE_REGISTRY == TRUE
- REG_REMOVE(tp);
-#endif
- chHeapFree(tp);
- break;
-#endif
-#if CH_CFG_USE_MEMPOOLS == TRUE
- case CH_FLAG_MODE_MPOOL:
-#if CH_CFG_USE_REGISTRY == TRUE
- REG_REMOVE(tp);
-#endif
- chPoolFree(tp->p_mpool, tp);
- break;
-#endif
- default:
- /* Nothing to do for static threads, those are removed from the
- registry on exit.*/
- break;
- }
- }
-}
-
-#if (CH_CFG_USE_HEAP == TRUE) || 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 == TRUE
- _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, MSG_OK);
- chSysUnlock();
-
- return tp;
-}
-#endif /* CH_CFG_USE_HEAP == TRUE */
-
-#if (CH_CFG_USE_MEMPOOLS == TRUE) || 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 == TRUE
- _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_MPOOL;
- tp->p_mpool = mp;
- chSchWakeupS(tp, MSG_OK);
- chSysUnlock();
-
- return tp;
-}
-#endif /* CH_CFG_USE_MEMPOOLS == TRUE */
-
-#endif /* CH_CFG_USE_DYNAMIC == TRUE */
-
-/** @} */
diff --git a/os/rt/src/chevents.c b/os/rt/src/chevents.c index 96c1594d8..87e9ba90e 100644 --- a/os/rt/src/chevents.c +++ b/os/rt/src/chevents.c @@ -108,12 +108,12 @@ void chEvtRegisterMaskWithFlags(event_source_t *esp, chDbgCheck((esp != NULL) && (elp != NULL));
chSysLock();
- elp->el_next = esp->es_next;
- esp->es_next = elp;
- elp->el_listener = currp;
- elp->el_events = events;
- elp->el_flags = (eventflags_t)0;
- elp->el_wflags = wflags;
+ elp->next = esp->next;
+ esp->next = elp;
+ elp->listener = currp;
+ elp->events = events;
+ elp->flags = (eventflags_t)0;
+ elp->wflags = wflags;
chSysUnlock();
}
@@ -140,13 +140,13 @@ void chEvtUnregister(event_source_t *esp, event_listener_t *elp) { /*lint -restore*/
chSysLock();
/*lint -save -e9087 -e740 [11.3, 1.3] Cast required by list handling.*/
- while (p->el_next != (event_listener_t *)esp) {
+ while (p->next != (event_listener_t *)esp) {
/*lint -restore*/
- if (p->el_next == elp) {
- p->el_next = elp->el_next;
+ if (p->next == elp) {
+ p->next = elp->next;
break;
}
- p = p->el_next;
+ p = p->next;
}
chSysUnlock();
}
@@ -163,8 +163,8 @@ eventmask_t chEvtGetAndClearEvents(eventmask_t events) { eventmask_t m;
chSysLock();
- m = currp->p_epending & events;
- currp->p_epending &= ~events;
+ m = currp->epending & events;
+ currp->epending &= ~events;
chSysUnlock();
return m;
@@ -182,8 +182,8 @@ eventmask_t chEvtGetAndClearEvents(eventmask_t events) { eventmask_t chEvtAddEvents(eventmask_t events) {
chSysLock();
- currp->p_epending |= events;
- events = currp->p_epending;
+ currp->epending |= events;
+ events = currp->epending;
chSysUnlock();
return events;
@@ -212,18 +212,18 @@ void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) { chDbgCheckClassI();
chDbgCheck(esp != NULL);
- elp = esp->es_next;
+ elp = esp->next;
/*lint -save -e9087 -e740 [11.3, 1.3] Cast required by list handling.*/
while (elp != (event_listener_t *)esp) {
/*lint -restore*/
- elp->el_flags |= flags;
+ elp->flags |= flags;
/* When flags == 0 the thread will always be signaled because the
source does not emit any flag.*/
if ((flags == (eventflags_t)0) ||
- ((elp->el_flags & elp->el_wflags) != (eventflags_t)0)) {
- chEvtSignalI(elp->el_listener, elp->el_events);
+ ((elp->flags & elp->wflags) != (eventflags_t)0)) {
+ chEvtSignalI(elp->listener, elp->events);
}
- elp = elp->el_next;
+ elp = elp->next;
}
}
@@ -242,8 +242,8 @@ eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) { eventflags_t flags;
chSysLock();
- flags = elp->el_flags;
- elp->el_flags = (eventflags_t)0;
+ flags = elp->flags;
+ elp->flags = (eventflags_t)0;
chSysUnlock();
return flags;
@@ -284,13 +284,13 @@ void chEvtSignalI(thread_t *tp, eventmask_t events) { chDbgCheckClassI();
chDbgCheck(tp != NULL);
- tp->p_epending |= events;
+ tp->epending |= events;
/* Test on the AND/OR conditions wait states.*/
- if (((tp->p_state == CH_STATE_WTOREVT) &&
- ((tp->p_epending & tp->p_u.ewmask) != (eventmask_t)0)) ||
- ((tp->p_state == CH_STATE_WTANDEVT) &&
- ((tp->p_epending & tp->p_u.ewmask) == tp->p_u.ewmask))) {
- tp->p_u.rdymsg = MSG_OK;
+ if (((tp->state == CH_STATE_WTOREVT) &&
+ ((tp->epending & tp->u.ewmask) != (eventmask_t)0)) ||
+ ((tp->state == CH_STATE_WTANDEVT) &&
+ ((tp->epending & tp->u.ewmask) == tp->u.ewmask))) {
+ tp->u.rdymsg = MSG_OK;
(void) chSchReadyI(tp);
}
}
@@ -330,8 +330,8 @@ void chEvtBroadcastFlags(event_source_t *esp, eventflags_t flags) { eventflags_t chEvtGetAndClearFlagsI(event_listener_t *elp) {
eventflags_t flags;
- flags = elp->el_flags;
- elp->el_flags = (eventflags_t)0;
+ flags = elp->flags;
+ elp->flags = (eventflags_t)0;
return flags;
}
@@ -385,14 +385,14 @@ eventmask_t chEvtWaitOne(eventmask_t events) { eventmask_t m;
chSysLock();
- m = ctp->p_epending & events;
+ m = ctp->epending & events;
if (m == (eventmask_t)0) {
- ctp->p_u.ewmask = events;
+ ctp->u.ewmask = events;
chSchGoSleepS(CH_STATE_WTOREVT);
- m = ctp->p_epending & events;
+ m = ctp->epending & events;
}
m ^= m & (m - (eventmask_t)1);
- ctp->p_epending &= ~m;
+ ctp->epending &= ~m;
chSysUnlock();
return m;
@@ -415,13 +415,13 @@ eventmask_t chEvtWaitAny(eventmask_t events) { eventmask_t m;
chSysLock();
- m = ctp->p_epending & events;
+ m = ctp->epending & events;
if (m == (eventmask_t)0) {
- ctp->p_u.ewmask = events;
+ ctp->u.ewmask = events;
chSchGoSleepS(CH_STATE_WTOREVT);
- m = ctp->p_epending & events;
+ m = ctp->epending & events;
}
- ctp->p_epending &= ~m;
+ ctp->epending &= ~m;
chSysUnlock();
return m;
@@ -442,11 +442,11 @@ eventmask_t chEvtWaitAll(eventmask_t events) { thread_t *ctp = currp;
chSysLock();
- if ((ctp->p_epending & events) != events) {
- ctp->p_u.ewmask = events;
+ if ((ctp->epending & events) != events) {
+ ctp->u.ewmask = events;
chSchGoSleepS(CH_STATE_WTANDEVT);
}
- ctp->p_epending &= ~events;
+ ctp->epending &= ~events;
chSysUnlock();
return events;
@@ -481,21 +481,21 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) { eventmask_t m;
chSysLock();
- m = ctp->p_epending & events;
+ m = ctp->epending & events;
if (m == (eventmask_t)0) {
if (TIME_IMMEDIATE == time) {
chSysUnlock();
return (eventmask_t)0;
}
- ctp->p_u.ewmask = events;
+ ctp->u.ewmask = events;
if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < MSG_OK) {
chSysUnlock();
return (eventmask_t)0;
}
- m = ctp->p_epending & events;
+ m = ctp->epending & events;
}
m ^= m & (m - (eventmask_t)1);
- ctp->p_epending &= ~m;
+ ctp->epending &= ~m;
chSysUnlock();
return m;
@@ -524,20 +524,20 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time) { eventmask_t m;
chSysLock();
- m = ctp->p_epending & events;
+ m = ctp->epending & events;
if (m == (eventmask_t)0) {
if (TIME_IMMEDIATE == time) {
chSysUnlock();
return (eventmask_t)0;
}
- ctp->p_u.ewmask = events;
+ ctp->u.ewmask = events;
if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < MSG_OK) {
chSysUnlock();
return (eventmask_t)0;
}
- m = ctp->p_epending & events;
+ m = ctp->epending & events;
}
- ctp->p_epending &= ~m;
+ ctp->epending &= ~m;
chSysUnlock();
return m;
@@ -564,18 +564,18 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t events, systime_t time) { thread_t *ctp = currp;
chSysLock();
- if ((ctp->p_epending & events) != events) {
+ if ((ctp->epending & events) != events) {
if (TIME_IMMEDIATE == time) {
chSysUnlock();
return (eventmask_t)0;
}
- ctp->p_u.ewmask = events;
+ ctp->u.ewmask = events;
if (chSchGoSleepTimeoutS(CH_STATE_WTANDEVT, time) < MSG_OK) {
chSysUnlock();
return (eventmask_t)0;
}
}
- ctp->p_epending &= ~events;
+ ctp->epending &= ~events;
chSysUnlock();
return events;
diff --git a/os/rt/src/chheap.c b/os/rt/src/chheap.c deleted file mode 100644 index 6f9cff77f..000000000 --- a/os/rt/src/chheap.c +++ /dev/null @@ -1,294 +0,0 @@ -/*
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio.
-
- This file is part of ChibiOS.
-
- ChibiOS 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 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file chheap.c
- * @brief Heaps code.
- *
- * @addtogroup heaps
- * @details Heap Allocator related APIs.
- * <h2>Operation mode</h2>
- * 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.<br>
- * @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 == TRUE) || defined(__DOXYGEN__)
-
-/*===========================================================================*/
-/* Module local definitions. */
-/*===========================================================================*/
-
-/*
- * Defaults on the best synchronization mechanism available.
- */
-#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
-#define H_LOCK(h) chMtxLock(&(h)->h_mtx)
-#define H_UNLOCK(h) chMtxUnlock(&(h)->h_mtx)
-#else
-#define H_LOCK(h) (void) chSemWait(&(h)->h_sem)
-#define H_UNLOCK(h) chSemSignal(&(h)->h_sem)
-#endif
-
-#define LIMIT(p) \
- /*lint -save -e9087 [11.3] Safe cast.*/ \
- (union heap_header *)((uint8_t *)(p) + \
- sizeof(union heap_header) + (p)->h.size) \
- /*lint -restore*/
-
-/*===========================================================================*/
-/* 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 = NULL;
- default_heap.h_free.h.size = 0;
-#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
- chMtxObjectInit(&default_heap.h_mtx);
-#else
- chSemObjectInit(&default_heap.h_sem, (cnt_t)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 = buf;
-
- chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size));
-
- heapp->h_provider = NULL;
- heapp->h_free.h.u.next = hp;
- heapp->h_free.h.size = 0;
- hp->h.u.next = NULL;
- hp->h.size = size - sizeof(union heap_header);
-#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
- chMtxObjectInit(&heapp->h_mtx);
-#else
- chSemObjectInit(&heapp->h_sem, (cnt_t)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.*/
- /*lint -save -e9087 [11.3] Safe cast.*/
- fp = (void *)((uint8_t *)(hp) + sizeof(union heap_header) + size);
- /*lint -restore*/
- 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);
-
- /*lint -save -e9087 [11.3] Safe cast.*/
- return (void *)(hp + 1);
- /*lint -restore*/
- }
- qp = hp;
- }
- H_UNLOCK(heapp);
-
- /* More memory is required, tries to get it from the associated provider
- else fails.*/
- if (heapp->h_provider != NULL) {
- hp = heapp->h_provider(size + sizeof(union heap_header));
- if (hp != NULL) {
- hp->h.u.heap = heapp;
- hp->h.size = size;
- hp++;
-
- /*lint -save -e9087 [11.3] Safe cast.*/
- return (void *)hp;
- /*lint -restore*/
- }
- }
-
- return NULL;
-}
-
-/**
- * @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);
-
- /*lint -save -e9087 [11.3] Safe cast.*/
- hp = (union heap_header *)p - 1;
- /*lint -restore*/
- 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;
- n = 0;
- qp = &heapp->h_free;
- while (qp->h.u.next != NULL) {
- sz += qp->h.u.next->h.size;
- n++;
- qp = qp->h.u.next;
- }
- if (sizep != NULL) {
- *sizep = sz;
- }
- H_UNLOCK(heapp);
-
- return n;
-}
-
-#endif /* CH_CFG_USE_HEAP == TRUE */
-
-/** @} */
diff --git a/os/rt/src/chmboxes.c b/os/rt/src/chmboxes.c deleted file mode 100644 index 21f8ce55e..000000000 --- a/os/rt/src/chmboxes.c +++ /dev/null @@ -1,434 +0,0 @@ -/*
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio.
-
- This file is part of ChibiOS.
-
- ChibiOS 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 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file chmboxes.c
- * @brief Mailboxes code.
- *
- * @addtogroup mailboxes
- * @details Asynchronous messages.
- * <h2>Operation mode</h2>
- * A mailbox is an asynchronous communication mechanism.<br>
- * Operations defined for mailboxes:
- * - <b>Post</b>: Posts a message on the mailbox in FIFO order.
- * - <b>Post Ahead</b>: Posts a message on the mailbox with urgent
- * priority.
- * - <b>Fetch</b>: A message is fetched from the mailbox and removed
- * from the queue.
- * - <b>Reset</b>: 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 == TRUE) || 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 > (cnt_t)0));
-
- mbp->mb_buffer = buf;
- mbp->mb_rdptr = buf;
- mbp->mb_wrptr = buf;
- mbp->mb_top = &buf[n];
- chSemObjectInit(&mbp->mb_emptysem, n);
- chSemObjectInit(&mbp->mb_fullsem, (cnt_t)0);
-}
-
-/**
- * @brief Resets a @p mailbox_t object.
- * @details All the waiting threads are resumed with status @p MSG_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) {
-
- chSysLock();
- chMBResetI(mbp);
- chSchRescheduleS();
- chSysUnlock();
-}
-
-/**
- * @brief Resets a @p mailbox_t object.
- * @details All the waiting threads are resumed with status @p MSG_RESET and
- * the queued messages are lost.
- *
- * @param[in] mbp the pointer to an initialized @p mailbox_t object
- *
- * @api
- */
-void chMBResetI(mailbox_t *mbp) {
-
- chDbgCheckClassI();
- chDbgCheck(mbp != NULL);
-
- mbp->mb_wrptr = mbp->mb_buffer;
- mbp->mb_rdptr = mbp->mb_buffer;
- chSemResetI(&mbp->mb_emptysem, (cnt_t)(mbp->mb_top - mbp->mb_buffer));
- chSemResetI(&mbp->mb_fullsem, (cnt_t)0);
-}
-
-/**
- * @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] timeout 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 MSG_OK if a message has been correctly posted.
- * @retval MSG_RESET if the mailbox has been reset while waiting.
- * @retval MSG_TIMEOUT if the operation has timed out.
- *
- * @api
- */
-msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t timeout) {
- msg_t rdymsg;
-
- chSysLock();
- rdymsg = chMBPostS(mbp, msg, timeout);
- 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] timeout 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 MSG_OK if a message has been correctly posted.
- * @retval MSG_RESET if the mailbox has been reset while waiting.
- * @retval MSG_TIMEOUT if the operation has timed out.
- *
- * @sclass
- */
-msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t timeout) {
- msg_t rdymsg;
-
- chDbgCheckClassS();
- chDbgCheck(mbp != NULL);
-
- rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, timeout);
- if (rdymsg == MSG_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 MSG_OK if a message has been correctly posted.
- * @retval MSG_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) <= (cnt_t)0) {
- return MSG_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 MSG_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] timeout 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 MSG_OK if a message has been correctly posted.
- * @retval MSG_RESET if the mailbox has been reset while waiting.
- * @retval MSG_TIMEOUT if the operation has timed out.
- *
- * @api
- */
-msg_t chMBPostAhead(mailbox_t *mbp, msg_t msg, systime_t timeout) {
- msg_t rdymsg;
-
- chSysLock();
- rdymsg = chMBPostAheadS(mbp, msg, timeout);
- 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] timeout 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 MSG_OK if a message has been correctly posted.
- * @retval MSG_RESET if the mailbox has been reset while waiting.
- * @retval MSG_TIMEOUT if the operation has timed out.
- *
- * @sclass
- */
-msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t timeout) {
- msg_t rdymsg;
-
- chDbgCheckClassS();
- chDbgCheck(mbp != NULL);
-
- rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, timeout);
- if (rdymsg == MSG_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 MSG_OK if a message has been correctly posted.
- * @retval MSG_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) <= (cnt_t)0) {
- return MSG_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 MSG_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] timeout 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 MSG_OK if a message has been correctly fetched.
- * @retval MSG_RESET if the mailbox has been reset while waiting.
- * @retval MSG_TIMEOUT if the operation has timed out.
- *
- * @api
- */
-msg_t chMBFetch(mailbox_t *mbp, msg_t *msgp, systime_t timeout) {
- msg_t rdymsg;
-
- chSysLock();
- rdymsg = chMBFetchS(mbp, msgp, timeout);
- 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] timeout 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 MSG_OK if a message has been correctly fetched.
- * @retval MSG_RESET if the mailbox has been reset while waiting.
- * @retval MSG_TIMEOUT if the operation has timed out.
- *
- * @sclass
- */
-msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t timeout) {
- msg_t rdymsg;
-
- chDbgCheckClassS();
- chDbgCheck((mbp != NULL) && (msgp != NULL));
-
- rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, timeout);
- if (rdymsg == MSG_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 MSG_OK if a message has been correctly fetched.
- * @retval MSG_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) <= (cnt_t)0) {
- return MSG_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 MSG_OK;
-}
-#endif /* CH_CFG_USE_MAILBOXES == TRUE */
-
-/** @} */
diff --git a/os/rt/src/chmemcore.c b/os/rt/src/chmemcore.c deleted file mode 100644 index 64f82aa84..000000000 --- a/os/rt/src/chmemcore.c +++ /dev/null @@ -1,163 +0,0 @@ -/*
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio.
-
- This file is part of ChibiOS.
-
- ChibiOS 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 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file chmemcore.c
- * @brief Core memory manager code.
- *
- * @addtogroup memcore
- * @details Core Memory Manager related APIs and services.
- * <h2>Operation mode</h2>
- * The core memory manager is a simplified allocator that only
- * allows to allocate memory blocks without the possibility to
- * free them.<br>
- * 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.<br>
- * 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 == TRUE) || 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__[];
-
- /*lint -save -e9033 [10.8] Required cast operations.*/
- nextmem = (uint8_t *)MEM_ALIGN_NEXT(__heap_base__);
- endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__);
- /*lint restore*/
-#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 <code>MEM_ALIGN_SIZE</code>.
- *
- * @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
- * <code>MEM_ALIGN_SIZE</code>.
- *
- * @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);
- /*lint -save -e9033 [10.8] The cast is safe.*/
- if ((size_t)(endmem - nextmem) < size) {
- /*lint -restore*/
- return NULL;
- }
- p = nextmem;
- nextmem += size;
-
- return p;
-}
-
-/**
- * @brief Core memory status.
- *
- * @return The size, in bytes, of the free core memory.
- *
- * @xclass
- */
-size_t chCoreGetStatusX(void) {
-
- /*lint -save -e9033 [10.8] The cast is safe.*/
- return (size_t)(endmem - nextmem);
- /*lint -restore*/
-}
-#endif /* CH_CFG_USE_MEMCORE == TRUE */
-
-/** @} */
diff --git a/os/rt/src/chmempools.c b/os/rt/src/chmempools.c deleted file mode 100644 index bdacedc0d..000000000 --- a/os/rt/src/chmempools.c +++ /dev/null @@ -1,202 +0,0 @@ -/*
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio.
-
- This file is part of ChibiOS.
-
- ChibiOS 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 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file chmempools.c
- * @brief Memory Pools code.
- *
- * @addtogroup pools
- * @details Memory Pools related APIs and services.
- * <h2>Operation mode</h2>
- * The Memory Pools APIs allow to allocate/free fixed size objects in
- * <b>constant time</b> and reliably without memory fragmentation
- * problems.<br>
- * 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 == TRUE) || 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 != 0U));
-
- while (n != 0U) {
- chPoolAdd(mp, p);
- /*lint -save -e9087 [11.3] Safe cast.*/
- p = (void *)(((uint8_t *)p) + mp->mp_object_size);
- /*lint -restore*/
- 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);
-
- objp = mp->mp_next;
- /*lint -save -e9013 [15.7] There is no else because it is not needed.*/
- if (objp != NULL) {
- mp->mp_next = mp->mp_next->ph_next;
- }
- else if (mp->mp_provider != NULL) {
- objp = mp->mp_provider(mp->mp_object_size);
- }
- /*lint -restore*/
-
- 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 == TRUE */
-
-/** @} */
diff --git a/os/rt/src/chmsg.c b/os/rt/src/chmsg.c index a4a646722..173473955 100644 --- a/os/rt/src/chmsg.c +++ b/os/rt/src/chmsg.c @@ -90,13 +90,13 @@ msg_t chMsgSend(thread_t *tp, msg_t msg) { chDbgCheck(tp != NULL);
chSysLock();
- ctp->p_u.sentmsg = msg;
- msg_insert(ctp, &tp->p_msgqueue);
- if (tp->p_state == CH_STATE_WTMSG) {
+ ctp->u.sentmsg = msg;
+ msg_insert(ctp, &tp->msgqueue);
+ if (tp->state == CH_STATE_WTMSG) {
(void) chSchReadyI(tp);
}
chSchGoSleepS(CH_STATE_SNDMSGQ);
- msg = ctp->p_u.rdymsg;
+ msg = ctp->u.rdymsg;
chSysUnlock();
return msg;
@@ -123,8 +123,8 @@ thread_t *chMsgWait(void) { if (!chMsgIsPendingI(currp)) {
chSchGoSleepS(CH_STATE_WTMSG);
}
- tp = queue_fifo_remove(&currp->p_msgqueue);
- tp->p_state = CH_STATE_SNDMSG;
+ tp = queue_fifo_remove(&currp->msgqueue);
+ tp->state = CH_STATE_SNDMSG;
chSysUnlock();
return tp;
@@ -143,7 +143,7 @@ thread_t *chMsgWait(void) { void chMsgRelease(thread_t *tp, msg_t msg) {
chSysLock();
- chDbgAssert(tp->p_state == CH_STATE_SNDMSG, "invalid state");
+ chDbgAssert(tp->state == CH_STATE_SNDMSG, "invalid state");
chMsgReleaseS(tp, msg);
chSysUnlock();
}
diff --git a/os/rt/src/chmtx.c b/os/rt/src/chmtx.c index 42c2836ae..e8f315ed3 100644 --- a/os/rt/src/chmtx.c +++ b/os/rt/src/chmtx.c @@ -104,10 +104,10 @@ void chMtxObjectInit(mutex_t *mp) { chDbgCheck(mp != NULL);
- queue_init(&mp->m_queue);
- mp->m_owner = NULL;
+ queue_init(&mp->queue);
+ mp->owner = NULL;
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- mp->m_cnt = (cnt_t)0;
+ mp->cnt = (cnt_t)0;
#endif
}
@@ -143,35 +143,35 @@ void chMtxLockS(mutex_t *mp) { chDbgCheck(mp != NULL);
/* Is the mutex already locked? */
- if (mp->m_owner != NULL) {
+ if (mp->owner != NULL) {
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- chDbgAssert(mp->m_cnt >= (cnt_t)1, "counter is not positive");
+ chDbgAssert(mp->cnt >= (cnt_t)1, "counter is not positive");
/* If the mutex is already owned by this thread, the counter is increased
and there is no need of more actions.*/
- if (mp->m_owner == ctp) {
- mp->m_cnt++;
+ if (mp->owner == ctp) {
+ mp->cnt++;
}
else {
#endif
/* 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;
+ thread_t *tp = mp->owner;
/* Does the running thread have higher priority than the mutex
owning thread? */
- while (tp->p_prio < ctp->p_prio) {
+ while (tp->prio < ctp->prio) {
/* Make priority of thread tp match the running thread's priority.*/
- tp->p_prio = ctp->p_prio;
+ tp->prio = ctp->prio;
/* The following states need priority queues reordering.*/
- switch (tp->p_state) {
+ switch (tp->state) {
case CH_STATE_WTMTX:
/* Re-enqueues the mutex owner with its new priority.*/
- queue_prio_insert(queue_dequeue(tp), &tp->p_u.wtmtxp->m_queue);
- tp = tp->p_u.wtmtxp->m_owner;
+ queue_prio_insert(queue_dequeue(tp), &tp->u.wtmtxp->queue);
+ tp = tp->u.wtmtxp->owner;
/*lint -e{9042} [16.1] Continues the while.*/
continue;
#if (CH_CFG_USE_CONDVARS == TRUE) || \
@@ -190,13 +190,13 @@ void chMtxLockS(mutex_t *mp) { case CH_STATE_SNDMSGQ:
#endif
/* Re-enqueues tp with its new priority on the queue.*/
- queue_prio_insert(queue_dequeue(tp), &tp->p_u.wtmtxp->m_queue);
+ queue_prio_insert(queue_dequeue(tp), &tp->u.wtmtxp->queue);
break;
#endif
case CH_STATE_READY:
#if CH_DBG_ENABLE_ASSERTS == TRUE
/* Prevents an assertion in chSchReadyI().*/
- tp->p_state = CH_STATE_CURRENT;
+ tp->state = CH_STATE_CURRENT;
#endif
/* Re-enqueues tp with its new priority on the ready list.*/
(void) chSchReadyI(queue_dequeue(tp));
@@ -209,29 +209,29 @@ void chMtxLockS(mutex_t *mp) { }
/* Sleep on the mutex.*/
- queue_prio_insert(ctp, &mp->m_queue);
- ctp->p_u.wtmtxp = mp;
+ queue_prio_insert(ctp, &mp->queue);
+ ctp->u.wtmtxp = 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");
+ chDbgAssert(mp->owner == ctp, "not owner");
+ chDbgAssert(ctp->mtxlist == mp, "not owned");
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- chDbgAssert(mp->m_cnt == (cnt_t)1, "counter is not one");
+ chDbgAssert(mp->cnt == (cnt_t)1, "counter is not one");
}
#endif
}
else {
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- chDbgAssert(mp->m_cnt == (cnt_t)0, "counter is not zero");
+ chDbgAssert(mp->cnt == (cnt_t)0, "counter is not zero");
- mp->m_cnt++;
+ mp->cnt++;
#endif
/* It was not owned, inserted in the owned mutexes list.*/
- mp->m_owner = ctp;
- mp->m_next = ctp->p_mtxlist;
- ctp->p_mtxlist = mp;
+ mp->owner = ctp;
+ mp->next = ctp->mtxlist;
+ ctp->mtxlist = mp;
}
}
@@ -284,13 +284,13 @@ bool chMtxTryLockS(mutex_t *mp) { chDbgCheckClassS();
chDbgCheck(mp != NULL);
- if (mp->m_owner != NULL) {
+ if (mp->owner != NULL) {
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- chDbgAssert(mp->m_cnt >= (cnt_t)1, "counter is not positive");
+ chDbgAssert(mp->cnt >= (cnt_t)1, "counter is not positive");
- if (mp->m_owner == currp) {
- mp->m_cnt++;
+ if (mp->owner == currp) {
+ mp->cnt++;
return true;
}
#endif
@@ -298,13 +298,13 @@ bool chMtxTryLockS(mutex_t *mp) { }
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- chDbgAssert(mp->m_cnt == (cnt_t)0, "counter is not zero");
+ chDbgAssert(mp->cnt == (cnt_t)0, "counter is not zero");
- mp->m_cnt++;
+ mp->cnt++;
#endif
- mp->m_owner = currp;
- mp->m_next = currp->p_mtxlist;
- currp->p_mtxlist = mp;
+ mp->owner = currp;
+ mp->next = currp->mtxlist;
+ currp->mtxlist = mp;
return true;
}
@@ -328,20 +328,20 @@ void chMtxUnlock(mutex_t *mp) { chSysLock();
- chDbgAssert(ctp->p_mtxlist != NULL, "owned mutexes list empty");
- chDbgAssert(ctp->p_mtxlist->m_owner == ctp, "ownership failure");
+ chDbgAssert(ctp->mtxlist != NULL, "owned mutexes list empty");
+ chDbgAssert(ctp->mtxlist->owner == ctp, "ownership failure");
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- chDbgAssert(mp->m_cnt >= (cnt_t)1, "counter is not positive");
+ chDbgAssert(mp->cnt >= (cnt_t)1, "counter is not positive");
- if (--mp->m_cnt == (cnt_t)0) {
+ if (--mp->cnt == (cnt_t)0) {
#endif
- chDbgAssert(ctp->p_mtxlist == mp, "not next in list");
+ chDbgAssert(ctp->mtxlist == mp, "not next in list");
/* Removes the top mutex from the thread's owned mutexes list and marks
it as not owned. Note, it is assumed to be the same mutex passed as
parameter of this function.*/
- ctp->p_mtxlist = mp->m_next;
+ ctp->mtxlist = mp->next;
/* If a thread is waiting on the mutex then the fun part begins.*/
if (chMtxQueueNotEmptyS(mp)) {
@@ -349,32 +349,32 @@ void chMtxUnlock(mutex_t *mp) { /* Recalculates the optimal thread priority by scanning the owned
mutexes list.*/
- tprio_t newprio = ctp->p_realprio;
- lmp = ctp->p_mtxlist;
+ tprio_t newprio = ctp->realprio;
+ lmp = ctp->mtxlist;
while (lmp != 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(lmp) &&
- (lmp->m_queue.p_next->p_prio > newprio)) {
- newprio = lmp->m_queue.p_next->p_prio;
+ (lmp->queue.next->prio > newprio)) {
+ newprio = lmp->queue.next->prio;
}
- lmp = lmp->m_next;
+ lmp = lmp->next;
}
/* Assigns to the current thread the highest priority among all the
waiting threads.*/
- ctp->p_prio = newprio;
+ ctp->prio = newprio;
/* Awakens the highest priority thread waiting for the unlocked mutex and
assigns the mutex to it.*/
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- mp->m_cnt = (cnt_t)1;
+ mp->cnt = (cnt_t)1;
#endif
- tp = queue_fifo_remove(&mp->m_queue);
- mp->m_owner = tp;
- mp->m_next = tp->p_mtxlist;
- tp->p_mtxlist = mp;
+ tp = queue_fifo_remove(&mp->queue);
+ mp->owner = tp;
+ mp->next = tp->mtxlist;
+ tp->mtxlist = mp;
/* Note, not using chSchWakeupS() becuase that function expects the
current thread to have the higher or equal priority than the ones
@@ -384,7 +384,7 @@ void chMtxUnlock(mutex_t *mp) { chSchRescheduleS();
}
else {
- mp->m_owner = NULL;
+ mp->owner = NULL;
}
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
}
@@ -414,20 +414,20 @@ void chMtxUnlockS(mutex_t *mp) { chDbgCheckClassS();
chDbgCheck(mp != NULL);
- chDbgAssert(ctp->p_mtxlist != NULL, "owned mutexes list empty");
- chDbgAssert(ctp->p_mtxlist->m_owner == ctp, "ownership failure");
+ chDbgAssert(ctp->mtxlist != NULL, "owned mutexes list empty");
+ chDbgAssert(ctp->mtxlist->owner == ctp, "ownership failure");
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- chDbgAssert(mp->m_cnt >= (cnt_t)1, "counter is not positive");
+ chDbgAssert(mp->cnt >= (cnt_t)1, "counter is not positive");
- if (--mp->m_cnt == (cnt_t)0) {
+ if (--mp->cnt == (cnt_t)0) {
#endif
- chDbgAssert(ctp->p_mtxlist == mp, "not next in list");
+ chDbgAssert(ctp->mtxlist == mp, "not next in list");
/* Removes the top mutex from the thread's owned mutexes list and marks
it as not owned. Note, it is assumed to be the same mutex passed as
parameter of this function.*/
- ctp->p_mtxlist = mp->m_next;
+ ctp->mtxlist = mp->next;
/* If a thread is waiting on the mutex then the fun part begins.*/
if (chMtxQueueNotEmptyS(mp)) {
@@ -435,36 +435,36 @@ void chMtxUnlockS(mutex_t *mp) { /* Recalculates the optimal thread priority by scanning the owned
mutexes list.*/
- tprio_t newprio = ctp->p_realprio;
- lmp = ctp->p_mtxlist;
+ tprio_t newprio = ctp->realprio;
+ lmp = ctp->mtxlist;
while (lmp != 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(lmp) &&
- (lmp->m_queue.p_next->p_prio > newprio)) {
- newprio = lmp->m_queue.p_next->p_prio;
+ (lmp->queue.next->prio > newprio)) {
+ newprio = lmp->queue.next->prio;
}
- lmp = lmp->m_next;
+ lmp = lmp->next;
}
/* Assigns to the current thread the highest priority among all the
waiting threads.*/
- ctp->p_prio = newprio;
+ ctp->prio = newprio;
/* Awakens the highest priority thread waiting for the unlocked mutex and
assigns the mutex to it.*/
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- mp->m_cnt = (cnt_t)1;
+ mp->cnt = (cnt_t)1;
#endif
- tp = queue_fifo_remove(&mp->m_queue);
- mp->m_owner = tp;
- mp->m_next = tp->p_mtxlist;
- tp->p_mtxlist = mp;
+ tp = queue_fifo_remove(&mp->queue);
+ mp->owner = tp;
+ mp->next = tp->mtxlist;
+ tp->mtxlist = mp;
(void) chSchReadyI(tp);
}
else {
- mp->m_owner = NULL;
+ mp->owner = NULL;
}
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
}
@@ -486,28 +486,28 @@ void chMtxUnlockAll(void) { thread_t *ctp = currp;
chSysLock();
- if (ctp->p_mtxlist != NULL) {
+ if (ctp->mtxlist != NULL) {
do {
- mutex_t *mp = ctp->p_mtxlist;
- ctp->p_mtxlist = mp->m_next;
+ mutex_t *mp = ctp->mtxlist;
+ ctp->mtxlist = mp->next;
if (chMtxQueueNotEmptyS(mp)) {
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- mp->m_cnt = (cnt_t)1;
+ mp->cnt = (cnt_t)1;
#endif
- thread_t *tp = queue_fifo_remove(&mp->m_queue);
- mp->m_owner = tp;
- mp->m_next = tp->p_mtxlist;
- tp->p_mtxlist = mp;
+ thread_t *tp = queue_fifo_remove(&mp->queue);
+ mp->owner = tp;
+ mp->next = tp->mtxlist;
+ tp->mtxlist = mp;
(void) chSchReadyI(tp);
}
else {
#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE
- mp->m_cnt = (cnt_t)0;
+ mp->cnt = (cnt_t)0;
#endif
- mp->m_owner = NULL;
+ mp->owner = NULL;
}
- } while (ctp->p_mtxlist != NULL);
- ctp->p_prio = ctp->p_realprio;
+ } while (ctp->mtxlist != NULL);
+ ctp->prio = ctp->realprio;
chSchRescheduleS();
}
chSysUnlock();
diff --git a/os/rt/src/chqueues.c b/os/rt/src/chqueues.c index c7340289e..0eeaa3c0e 100644 --- a/os/rt/src/chqueues.c +++ b/os/rt/src/chqueues.c @@ -87,14 +87,14 @@ void chIQObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size,
qnotify_t infy, void *link) {
- chThdQueueObjectInit(&iqp->q_waiting);
- iqp->q_counter = 0;
- iqp->q_buffer = bp;
- iqp->q_rdptr = bp;
- iqp->q_wrptr = bp;
- iqp->q_top = bp + size;
- iqp->q_notify = infy;
- iqp->q_link = link;
+ chThdQueueObjectInit(&iqp->waiting);
+ iqp->counter = 0;
+ iqp->buffer = bp;
+ iqp->rdptr = bp;
+ iqp->wrptr = bp;
+ iqp->top = bp + size;
+ iqp->notify = infy;
+ iqp->link = link;
}
/**
@@ -112,10 +112,10 @@ void chIQResetI(input_queue_t *iqp) { chDbgCheckClassI();
- iqp->q_rdptr = iqp->q_buffer;
- iqp->q_wrptr = iqp->q_buffer;
- iqp->q_counter = 0;
- chThdDequeueAllI(&iqp->q_waiting, Q_RESET);
+ iqp->rdptr = iqp->buffer;
+ iqp->wrptr = iqp->buffer;
+ iqp->counter = 0;
+ chThdDequeueAllI(&iqp->waiting, Q_RESET);
}
/**
@@ -139,13 +139,13 @@ msg_t chIQPutI(input_queue_t *iqp, uint8_t b) { return Q_FULL;
}
- iqp->q_counter++;
- *iqp->q_wrptr++ = b;
- if (iqp->q_wrptr >= iqp->q_top) {
- iqp->q_wrptr = iqp->q_buffer;
+ iqp->counter++;
+ *iqp->wrptr++ = b;
+ if (iqp->wrptr >= iqp->top) {
+ iqp->wrptr = iqp->buffer;
}
- chThdDequeueNextI(&iqp->q_waiting, Q_OK);
+ chThdDequeueNextI(&iqp->waiting, Q_OK);
return Q_OK;
}
@@ -174,22 +174,22 @@ msg_t chIQGetTimeout(input_queue_t *iqp, systime_t timeout) { uint8_t b;
chSysLock();
- if (iqp->q_notify != NULL) {
- iqp->q_notify(iqp);
+ if (iqp->notify != NULL) {
+ iqp->notify(iqp);
}
while (chIQIsEmptyI(iqp)) {
- msg_t msg = chThdEnqueueTimeoutS(&iqp->q_waiting, timeout);
+ msg_t msg = chThdEnqueueTimeoutS(&iqp->waiting, timeout);
if (msg < 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;
+ iqp->counter--;
+ b = *iqp->rdptr++;
+ if (iqp->rdptr >= iqp->top) {
+ iqp->rdptr = iqp->buffer;
}
chSysUnlock();
@@ -222,7 +222,7 @@ msg_t chIQGetTimeout(input_queue_t *iqp, systime_t timeout) { */
size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp,
size_t n, systime_t timeout) {
- qnotify_t nfy = iqp->q_notify;
+ qnotify_t nfy = iqp->notify;
size_t r = 0;
chDbgCheck(n > 0U);
@@ -234,16 +234,16 @@ size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp, }
while (chIQIsEmptyI(iqp)) {
- if (chThdEnqueueTimeoutS(&iqp->q_waiting, timeout) != Q_OK) {
+ if (chThdEnqueueTimeoutS(&iqp->waiting, timeout) != 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;
+ iqp->counter--;
+ *bp++ = *iqp->rdptr++;
+ if (iqp->rdptr >= iqp->top) {
+ iqp->rdptr = iqp->buffer;
}
chSysUnlock(); /* Gives a preemption chance in a controlled point.*/
@@ -275,14 +275,14 @@ size_t chIQReadTimeout(input_queue_t *iqp, uint8_t *bp, void chOQObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size,
qnotify_t onfy, void *link) {
- chThdQueueObjectInit(&oqp->q_waiting);
- oqp->q_counter = size;
- oqp->q_buffer = bp;
- oqp->q_rdptr = bp;
- oqp->q_wrptr = bp;
- oqp->q_top = bp + size;
- oqp->q_notify = onfy;
- oqp->q_link = link;
+ chThdQueueObjectInit(&oqp->waiting);
+ oqp->counter = size;
+ oqp->buffer = bp;
+ oqp->rdptr = bp;
+ oqp->wrptr = bp;
+ oqp->top = bp + size;
+ oqp->notify = onfy;
+ oqp->link = link;
}
/**
@@ -300,10 +300,10 @@ void chOQResetI(output_queue_t *oqp) { chDbgCheckClassI();
- oqp->q_rdptr = oqp->q_buffer;
- oqp->q_wrptr = oqp->q_buffer;
- oqp->q_counter = chQSizeX(oqp);
- chThdDequeueAllI(&oqp->q_waiting, Q_RESET);
+ oqp->rdptr = oqp->buffer;
+ oqp->wrptr = oqp->buffer;
+ oqp->counter = chQSizeX(oqp);
+ chThdDequeueAllI(&oqp->waiting, Q_RESET);
}
/**
@@ -332,21 +332,21 @@ msg_t chOQPutTimeout(output_queue_t *oqp, uint8_t b, systime_t timeout) { chSysLock();
while (chOQIsFullI(oqp)) {
- msg_t msg = chThdEnqueueTimeoutS(&oqp->q_waiting, timeout);
+ msg_t msg = chThdEnqueueTimeoutS(&oqp->waiting, timeout);
if (msg < 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;
+ oqp->counter--;
+ *oqp->wrptr++ = b;
+ if (oqp->wrptr >= oqp->top) {
+ oqp->wrptr = oqp->buffer;
}
- if (oqp->q_notify != NULL) {
- oqp->q_notify(oqp);
+ if (oqp->notify != NULL) {
+ oqp->notify(oqp);
}
chSysUnlock();
@@ -372,13 +372,13 @@ msg_t chOQGetI(output_queue_t *oqp) { return Q_EMPTY;
}
- oqp->q_counter++;
- b = *oqp->q_rdptr++;
- if (oqp->q_rdptr >= oqp->q_top) {
- oqp->q_rdptr = oqp->q_buffer;
+ oqp->counter++;
+ b = *oqp->rdptr++;
+ if (oqp->rdptr >= oqp->top) {
+ oqp->rdptr = oqp->buffer;
}
- chThdDequeueNextI(&oqp->q_waiting, Q_OK);
+ chThdDequeueNextI(&oqp->waiting, Q_OK);
return (msg_t)b;
}
@@ -409,7 +409,7 @@ msg_t chOQGetI(output_queue_t *oqp) { */
size_t chOQWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
size_t n, systime_t timeout) {
- qnotify_t nfy = oqp->q_notify;
+ qnotify_t nfy = oqp->notify;
size_t w = 0;
chDbgCheck(n > 0U);
@@ -417,16 +417,16 @@ size_t chOQWriteTimeout(output_queue_t *oqp, const uint8_t *bp, chSysLock();
while (true) {
while (chOQIsFullI(oqp)) {
- if (chThdEnqueueTimeoutS(&oqp->q_waiting, timeout) != Q_OK) {
+ if (chThdEnqueueTimeoutS(&oqp->waiting, timeout) != 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;
+ oqp->counter--;
+ *oqp->wrptr++ = *bp++;
+ if (oqp->wrptr >= oqp->top) {
+ oqp->wrptr = oqp->buffer;
}
if (nfy != NULL) {
diff --git a/os/rt/src/chregistry.c b/os/rt/src/chregistry.c index aacadf22c..07185d331 100644 --- a/os/rt/src/chregistry.c +++ b/os/rt/src/chregistry.c @@ -87,30 +87,26 @@ ROMCONST chdebug_t ch_debug = { (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),
+ (uint8_t)_offsetof(thread_t, prio),
+ (uint8_t)_offsetof(thread_t, ctx),
+ (uint8_t)_offsetof(thread_t, newer),
+ (uint8_t)_offsetof(thread_t, older),
+ (uint8_t)_offsetof(thread_t, name),
#if CH_DBG_ENABLE_STACK_CHECK == TRUE
- (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 == TRUE
- (uint8_t)_offsetof(thread_t, p_refs),
+ (uint8_t)_offsetof(thread_t, stklimit),
#else
(uint8_t)0,
#endif
+ (uint8_t)_offsetof(thread_t, state),
+ (uint8_t)0, /* Flags no more part of the structure. */
+ (uint8_t)0, /* Refs no more part of the structure. */
#if CH_CFG_TIME_QUANTUM > 0
- (uint8_t)_offsetof(thread_t, p_preempt),
+ (uint8_t)_offsetof(thread_t, preempt),
#else
(uint8_t)0,
#endif
#if CH_DBG_THREADS_PROFILING == TRUE
- (uint8_t)_offsetof(thread_t, p_time)
+ (uint8_t)_offsetof(thread_t, time)
#else
(uint8_t)0
#endif
@@ -132,10 +128,7 @@ thread_t *chRegFirstThread(void) { thread_t *tp;
chSysLock();
- tp = ch.rlist.r_newer;
-#if CH_CFG_USE_DYNAMIC == TRUE
- tp->p_refs++;
-#endif
+ tp = ch.rlist.newer;
chSysUnlock();
return tp;
@@ -156,22 +149,13 @@ thread_t *chRegNextThread(thread_t *tp) { thread_t *ntp;
chSysLock();
- ntp = tp->p_newer;
+ ntp = tp->newer;
/*lint -save -e9087 -e740 [11.3, 1.3] Cast required by list handling.*/
if (ntp == (thread_t *)&ch.rlist) {
/*lint -restore*/
ntp = NULL;
}
-#if CH_CFG_USE_DYNAMIC == TRUE
- else {
- chDbgAssert(ntp->p_refs < (trefs_t)255, "too many references");
- ntp->p_refs++;
- }
-#endif
chSysUnlock();
-#if CH_CFG_USE_DYNAMIC == TRUE
- chThdRelease(tp);
-#endif
return ntp;
}
diff --git a/os/rt/src/chschd.c b/os/rt/src/chschd.c index ba73d3562..a1b533ea5 100644 --- a/os/rt/src/chschd.c +++ b/os/rt/src/chschd.c @@ -64,11 +64,11 @@ ch_system_t ch; */
void _scheduler_init(void) {
- queue_init(&ch.rlist.r_queue);
- ch.rlist.r_prio = NOPRIO;
+ queue_init(&ch.rlist.queue);
+ ch.rlist.prio = NOPRIO;
#if CH_CFG_USE_REGISTRY == TRUE
- ch.rlist.r_newer = (thread_t *)&ch.rlist;
- ch.rlist.r_older = (thread_t *)&ch.rlist;
+ ch.rlist.newer = (thread_t *)&ch.rlist;
+ ch.rlist.older = (thread_t *)&ch.rlist;
#endif
}
@@ -87,12 +87,12 @@ void queue_prio_insert(thread_t *tp, threads_queue_t *tqp) { thread_t *cp = (thread_t *)tqp;
do {
- cp = cp->p_next;
- } while ((cp != (thread_t *)tqp) && (cp->p_prio >= tp->p_prio));
- tp->p_next = cp;
- tp->p_prev = cp->p_prev;
- tp->p_prev->p_next = tp;
- cp->p_prev = tp;
+ cp = cp->next;
+ } while ((cp != (thread_t *)tqp) && (cp->prio >= tp->prio));
+ tp->next = cp;
+ tp->prev = cp->prev;
+ tp->prev->next = tp;
+ cp->prev = tp;
}
/**
@@ -105,10 +105,10 @@ void queue_prio_insert(thread_t *tp, threads_queue_t *tqp) { */
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 = tp;
- tqp->p_prev = tp;
+ tp->next = (thread_t *)tqp;
+ tp->prev = tqp->prev;
+ tp->prev->next = tp;
+ tqp->prev = tp;
}
/**
@@ -122,10 +122,10 @@ void queue_insert(thread_t *tp, threads_queue_t *tqp) { * @notapi
*/
thread_t *queue_fifo_remove(threads_queue_t *tqp) {
- thread_t *tp = tqp->p_next;
+ thread_t *tp = tqp->next;
- tqp->p_next = tp->p_next;
- tqp->p_next->p_prev = (thread_t *)tqp;
+ tqp->next = tp->next;
+ tqp->next->prev = (thread_t *)tqp;
return tp;
}
@@ -141,10 +141,10 @@ thread_t *queue_fifo_remove(threads_queue_t *tqp) { * @notapi
*/
thread_t *queue_lifo_remove(threads_queue_t *tqp) {
- thread_t *tp = tqp->p_prev;
+ thread_t *tp = tqp->prev;
- tqp->p_prev = tp->p_prev;
- tqp->p_prev->p_next = (thread_t *)tqp;
+ tqp->prev = tp->prev;
+ tqp->prev->next = (thread_t *)tqp;
return tp;
}
@@ -161,8 +161,8 @@ thread_t *queue_lifo_remove(threads_queue_t *tqp) { */
thread_t *queue_dequeue(thread_t *tp) {
- tp->p_prev->p_next = tp->p_next;
- tp->p_next->p_prev = tp->p_prev;
+ tp->prev->next = tp->next;
+ tp->next->prev = tp->prev;
return tp;
}
@@ -177,8 +177,8 @@ thread_t *queue_dequeue(thread_t *tp) { */
void list_insert(thread_t *tp, threads_list_t *tlp) {
- tp->p_next = tlp->p_next;
- tlp->p_next = tp;
+ tp->next = tlp->next;
+ tlp->next = tp;
}
/**
@@ -192,19 +192,19 @@ void list_insert(thread_t *tp, threads_list_t *tlp) { */
thread_t *list_remove(threads_list_t *tlp) {
- thread_t *tp = tlp->p_next;
- tlp->p_next = tp->p_next;
+ thread_t *tp = tlp->next;
+ tlp->next = tp->next;
return tp;
}
#endif /* CH_CFG_OPTIMIZE_SPEED */
/**
- * @brief Inserts a thread in the Ready List.
+ * @brief Inserts a thread in the Ready List placing it behind its peers.
* @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.
+ * @p next and @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
@@ -220,20 +220,59 @@ thread_t *chSchReadyI(thread_t *tp) { chDbgCheckClassI();
chDbgCheck(tp != NULL);
- chDbgAssert((tp->p_state != CH_STATE_READY) &&
- (tp->p_state != CH_STATE_FINAL),
+ chDbgAssert((tp->state != CH_STATE_READY) &&
+ (tp->state != CH_STATE_FINAL),
"invalid state");
- tp->p_state = CH_STATE_READY;
- cp = (thread_t *)&ch.rlist.r_queue;
+ tp->state = CH_STATE_READY;
+ cp = (thread_t *)&ch.rlist.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 = tp;
- cp->p_prev = tp;
+ cp = cp->next;
+ } while (cp->prio >= tp->prio);
+ /* Insertion on prev.*/
+ tp->next = cp;
+ tp->prev = cp->prev;
+ tp->prev->next = tp;
+ cp->prev = tp;
+
+ return tp;
+}
+
+/**
+ * @brief Inserts a thread in the Ready List placing it ahead its peers.
+ * @details The thread is positioned ahead all threads with higher or equal
+ * priority.
+ * @pre The thread must not be already inserted in any list through its
+ * @p next and @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 *chSchReadyAheadI(thread_t *tp) {
+ thread_t *cp;
+
+ chDbgCheckClassI();
+ chDbgCheck(tp != NULL);
+ chDbgAssert((tp->state != CH_STATE_READY) &&
+ (tp->state != CH_STATE_FINAL),
+ "invalid state");
+
+ tp->state = CH_STATE_READY;
+ cp = (thread_t *)&ch.rlist.queue;
+ do {
+ cp = cp->next;
+ } while (cp->prio > tp->prio);
+ /* Insertion on prev.*/
+ tp->next = cp;
+ tp->prev = cp->prev;
+ tp->prev->next = tp;
+ cp->prev = tp;
return tp;
}
@@ -253,19 +292,21 @@ void chSchGoSleepS(tstate_t newstate) { chDbgCheckClassS();
otp = currp;
- otp->p_state = newstate;
+ otp->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 = (tslices_t)CH_CFG_TIME_QUANTUM;
+ otp->preempt = (tslices_t)CH_CFG_TIME_QUANTUM;
#endif
- setcurrp(queue_fifo_remove(&ch.rlist.r_queue));
-#if defined(CH_CFG_IDLE_ENTER_HOOK)
- if (currp->p_prio == IDLEPRIO) {
+ currp = queue_fifo_remove(&ch.rlist.queue);
+ if (currp->prio == IDLEPRIO) {
CH_CFG_IDLE_ENTER_HOOK();
}
-#endif
- currp->p_state = CH_STATE_CURRENT;
+
+ /* The extracted thread is marked as current.*/
+ currp->state = CH_STATE_CURRENT;
+
+ /* Swap operation as tail call.*/
chSysSwitch(currp, otp);
}
@@ -276,18 +317,18 @@ static void wakeup(void *p) { thread_t *tp = (thread_t *)p;
chSysLockFromISR();
- switch (tp->p_state) {
+ switch (tp->state) {
case CH_STATE_READY:
/* Handling the special case where the thread has been made ready by
another thread with higher priority.*/
chSysUnlockFromISR();
return;
case CH_STATE_SUSPENDED:
- *tp->p_u.wttrp = NULL;
+ *tp->u.wttrp = NULL;
break;
#if CH_CFG_USE_SEMAPHORES == TRUE
case CH_STATE_WTSEM:
- chSemFastSignalI(tp->p_u.wtsemp);
+ chSemFastSignalI(tp->u.wtsemp);
/* Falls into, intentional. */
#endif
#if (CH_CFG_USE_CONDVARS == TRUE) && (CH_CFG_USE_CONDVARS_TIMEOUT == TRUE)
@@ -301,7 +342,7 @@ static void wakeup(void *p) { /* Any other state, nothing to do.*/
break;
}
- tp->p_u.rdymsg = MSG_TIMEOUT;
+ tp->u.rdymsg = MSG_TIMEOUT;
(void) chSchReadyI(tp);
chSysUnlockFromISR();
}
@@ -344,7 +385,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { chSchGoSleepS(newstate);
}
- return currp->p_u.rdymsg;
+ return currp->u.rdymsg;
}
/**
@@ -353,7 +394,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { * 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.
+ * @p next and @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
@@ -368,30 +409,32 @@ void chSchWakeupS(thread_t *ntp, msg_t msg) { chDbgCheckClassS();
- chDbgAssert((ch.rlist.r_queue.p_next == (thread_t *)&ch.rlist.r_queue) ||
- (ch.rlist.r_current->p_prio >= ch.rlist.r_queue.p_next->p_prio),
+ chDbgAssert((ch.rlist.queue.next == (thread_t *)&ch.rlist.queue) ||
+ (ch.rlist.current->prio >= ch.rlist.queue.next->prio),
"priority order violation");
/* Storing the message to be retrieved by the target thread when it will
restart execution.*/
- ntp->p_u.rdymsg = msg;
+ ntp->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) {
+ if (ntp->prio <= currp->prio) {
(void) chSchReadyI(ntp);
}
else {
thread_t *otp = chSchReadyI(currp);
- setcurrp(ntp);
-#if defined(CH_CFG_IDLE_LEAVE_HOOK)
- if (otp->p_prio == IDLEPRIO) {
+ currp = ntp;
+ if (otp->prio == IDLEPRIO) {
CH_CFG_IDLE_LEAVE_HOOK();
}
-#endif
- ntp->p_state = CH_STATE_CURRENT;
+
+ /* The extracted thread is marked as current.*/
+ ntp->state = CH_STATE_CURRENT;
+
+ /* Swap operation as tail call.*/
chSysSwitch(ntp, otp);
}
}
@@ -426,15 +469,15 @@ void chSchRescheduleS(void) { * @special
*/
bool chSchIsPreemptionRequired(void) {
- tprio_t p1 = firstprio(&ch.rlist.r_queue);
- tprio_t p2 = currp->p_prio;
+ tprio_t p1 = firstprio(&ch.rlist.queue);
+ tprio_t p2 = currp->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 > (tslices_t)0) ? (p1 > p2) : (p1 >= p2);
+ return (currp->preempt > (tslices_t)0) ? (p1 > p2) : (p1 >= p2);
#else
/* If the round robin preemption feature is not enabled then performs a
simpler comparison.*/
@@ -448,26 +491,30 @@ bool chSchIsPreemptionRequired(void) { * 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.
+ * itself.
*
* @special
*/
void chSchDoRescheduleBehind(void) {
- thread_t *otp;
+ thread_t *otp = currp;
- otp = currp;
/* Picks the first thread from the ready queue and makes it current.*/
- setcurrp(queue_fifo_remove(&ch.rlist.r_queue));
-#if defined(CH_CFG_IDLE_LEAVE_HOOK)
- if (otp->p_prio == IDLEPRIO) {
+ currp = queue_fifo_remove(&ch.rlist.queue);
+ if (otp->prio == IDLEPRIO) {
CH_CFG_IDLE_LEAVE_HOOK();
}
-#endif
- currp->p_state = CH_STATE_CURRENT;
+
+ /* The extracted thread is marked as current.*/
+ currp->state = CH_STATE_CURRENT;
+
#if CH_CFG_TIME_QUANTUM > 0
- otp->p_preempt = (tslices_t)CH_CFG_TIME_QUANTUM;
+ otp->preempt = (tslices_t)CH_CFG_TIME_QUANTUM;
#endif
- (void) chSchReadyI(otp);
+
+ /* Placing in ready list behind peers.*/
+ otp = chSchReadyI(otp);
+
+ /* Swap operation as tail call.*/
chSysSwitch(currp, otp);
}
@@ -476,34 +523,26 @@ void chSchDoRescheduleBehind(void) { * @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.
+ * itself.
*
* @special
*/
void chSchDoRescheduleAhead(void) {
- thread_t *otp, *cp;
+ thread_t *otp = currp;
- otp = currp;
/* Picks the first thread from the ready queue and makes it current.*/
- setcurrp(queue_fifo_remove(&ch.rlist.r_queue));
-#if defined(CH_CFG_IDLE_LEAVE_HOOK)
- if (otp->p_prio == IDLEPRIO) {
+ currp = queue_fifo_remove(&ch.rlist.queue);
+ if (otp->prio == IDLEPRIO) {
CH_CFG_IDLE_LEAVE_HOOK();
}
-#endif
- 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 = otp;
- cp->p_prev = otp;
+ /* The extracted thread is marked as current.*/
+ currp->state = CH_STATE_CURRENT;
+ /* Placing in ready list ahead of peers.*/
+ otp = chSchReadyAheadI(otp);
+
+ /* Swap operation as tail call.*/
chSysSwitch(currp, otp);
}
@@ -518,25 +557,42 @@ void chSchDoRescheduleAhead(void) { * @special
*/
void chSchDoReschedule(void) {
+ thread_t *otp = currp;
+
+ /* Picks the first thread from the ready queue and makes it current.*/
+ currp = queue_fifo_remove(&ch.rlist.queue);
+ if (otp->prio == IDLEPRIO) {
+ CH_CFG_IDLE_LEAVE_HOOK();
+ }
+
+ /* The extracted thread is marked as current.*/
+ currp->state = CH_STATE_CURRENT;
#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 == (tslices_t)0) {
+ if (currp->preempt == (tslices_t)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();
+ otp = chSchReadyI(otp);
+
+ /* The thread being swapped out receives a new time quantum.*/
+ otp->preempt = (tslices_t)CH_CFG_TIME_QUANTUM;
}
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();
+ otp = chSchReadyAheadI(otp);
}
#else /* !(CH_CFG_TIME_QUANTUM > 0) */
/* If the round-robin mechanism is disabled then the thread goes always
ahead of its peers.*/
- chSchDoRescheduleAhead();
+ otp = chSchReadyAheadI(otp);
#endif /* !(CH_CFG_TIME_QUANTUM > 0) */
+
+ /* Swap operation as tail call.*/
+ chSysSwitch(currp, otp);
}
/** @} */
diff --git a/os/rt/src/chsem.c b/os/rt/src/chsem.c index 4a891b521..7f88a480c 100644 --- a/os/rt/src/chsem.c +++ b/os/rt/src/chsem.c @@ -98,8 +98,8 @@ void chSemObjectInit(semaphore_t *sp, cnt_t n) { chDbgCheck((sp != NULL) && (n >= (cnt_t)0));
- queue_init(&sp->s_queue);
- sp->s_cnt = n;
+ queue_init(&sp->queue);
+ sp->cnt = n;
}
/**
@@ -149,14 +149,14 @@ void chSemResetI(semaphore_t *sp, cnt_t n) { chDbgCheckClassI();
chDbgCheck((sp != NULL) && (n >= (cnt_t)0));
- chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
- ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
+ chDbgAssert(((sp->cnt >= (cnt_t)0) && queue_isempty(&sp->queue)) ||
+ ((sp->cnt < (cnt_t)0) && queue_notempty(&sp->queue)),
"inconsistent semaphore");
- cnt = sp->s_cnt;
- sp->s_cnt = n;
+ cnt = sp->cnt;
+ sp->cnt = n;
while (++cnt <= (cnt_t)0) {
- chSchReadyI(queue_lifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_RESET;
+ chSchReadyI(queue_lifo_remove(&sp->queue))->u.rdymsg = MSG_RESET;
}
}
@@ -198,16 +198,16 @@ msg_t chSemWaitS(semaphore_t *sp) { chDbgCheckClassS();
chDbgCheck(sp != NULL);
- chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
- ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
+ chDbgAssert(((sp->cnt >= (cnt_t)0) && queue_isempty(&sp->queue)) ||
+ ((sp->cnt < (cnt_t)0) && queue_notempty(&sp->queue)),
"inconsistent semaphore");
- if (--sp->s_cnt < (cnt_t)0) {
- currp->p_u.wtsemp = sp;
- sem_insert(currp, &sp->s_queue);
+ if (--sp->cnt < (cnt_t)0) {
+ currp->u.wtsemp = sp;
+ sem_insert(currp, &sp->queue);
chSchGoSleepS(CH_STATE_WTSEM);
- return currp->p_u.rdymsg;
+ return currp->u.rdymsg;
}
return MSG_OK;
@@ -265,18 +265,18 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { chDbgCheckClassS();
chDbgCheck(sp != NULL);
- chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
- ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
+ chDbgAssert(((sp->cnt >= (cnt_t)0) && queue_isempty(&sp->queue)) ||
+ ((sp->cnt < (cnt_t)0) && queue_notempty(&sp->queue)),
"inconsistent semaphore");
- if (--sp->s_cnt < (cnt_t)0) {
+ if (--sp->cnt < (cnt_t)0) {
if (TIME_IMMEDIATE == time) {
- sp->s_cnt++;
+ sp->cnt++;
return MSG_TIMEOUT;
}
- currp->p_u.wtsemp = sp;
- sem_insert(currp, &sp->s_queue);
+ currp->u.wtsemp = sp;
+ sem_insert(currp, &sp->queue);
return chSchGoSleepTimeoutS(CH_STATE_WTSEM, time);
}
@@ -294,13 +294,13 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) { void chSemSignal(semaphore_t *sp) {
chDbgCheck(sp != NULL);
- chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
- ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
+ chDbgAssert(((sp->cnt >= (cnt_t)0) && queue_isempty(&sp->queue)) ||
+ ((sp->cnt < (cnt_t)0) && queue_notempty(&sp->queue)),
"inconsistent semaphore");
chSysLock();
- if (++sp->s_cnt <= (cnt_t)0) {
- chSchWakeupS(queue_fifo_remove(&sp->s_queue), MSG_OK);
+ if (++sp->cnt <= (cnt_t)0) {
+ chSchWakeupS(queue_fifo_remove(&sp->queue), MSG_OK);
}
chSysUnlock();
}
@@ -320,15 +320,15 @@ void chSemSignalI(semaphore_t *sp) { chDbgCheckClassI();
chDbgCheck(sp != NULL);
- chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
- ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
+ chDbgAssert(((sp->cnt >= (cnt_t)0) && queue_isempty(&sp->queue)) ||
+ ((sp->cnt < (cnt_t)0) && queue_notempty(&sp->queue)),
"inconsistent semaphore");
- if (++sp->s_cnt <= (cnt_t)0) {
+ if (++sp->cnt <= (cnt_t)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 = MSG_OK;
+ thread_t *tp = queue_fifo_remove(&sp->queue);
+ tp->u.rdymsg = MSG_OK;
(void) chSchReadyI(tp);
}
}
@@ -350,13 +350,13 @@ void chSemAddCounterI(semaphore_t *sp, cnt_t n) { chDbgCheckClassI();
chDbgCheck((sp != NULL) && (n > (cnt_t)0));
- chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
- ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
+ chDbgAssert(((sp->cnt >= (cnt_t)0) && queue_isempty(&sp->queue)) ||
+ ((sp->cnt < (cnt_t)0) && queue_notempty(&sp->queue)),
"inconsistent semaphore");
while (n > (cnt_t)0) {
- if (++sp->s_cnt <= (cnt_t)0) {
- chSchReadyI(queue_fifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_OK;
+ if (++sp->cnt <= (cnt_t)0) {
+ chSchReadyI(queue_fifo_remove(&sp->queue))->u.rdymsg = MSG_OK;
}
n--;
}
@@ -379,23 +379,23 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) { msg_t msg;
chDbgCheck((sps != NULL) && (spw != NULL));
- chDbgAssert(((sps->s_cnt >= (cnt_t)0) && queue_isempty(&sps->s_queue)) ||
- ((sps->s_cnt < (cnt_t)0) && queue_notempty(&sps->s_queue)),
+ chDbgAssert(((sps->cnt >= (cnt_t)0) && queue_isempty(&sps->queue)) ||
+ ((sps->cnt < (cnt_t)0) && queue_notempty(&sps->queue)),
"inconsistent semaphore");
- chDbgAssert(((spw->s_cnt >= (cnt_t)0) && queue_isempty(&spw->s_queue)) ||
- ((spw->s_cnt < (cnt_t)0) && queue_notempty(&spw->s_queue)),
+ chDbgAssert(((spw->cnt >= (cnt_t)0) && queue_isempty(&spw->queue)) ||
+ ((spw->cnt < (cnt_t)0) && queue_notempty(&spw->queue)),
"inconsistent semaphore");
chSysLock();
- if (++sps->s_cnt <= (cnt_t)0) {
- chSchReadyI(queue_fifo_remove(&sps->s_queue))->p_u.rdymsg = MSG_OK;
+ if (++sps->cnt <= (cnt_t)0) {
+ chSchReadyI(queue_fifo_remove(&sps->queue))->u.rdymsg = MSG_OK;
}
- if (--spw->s_cnt < (cnt_t)0) {
+ if (--spw->cnt < (cnt_t)0) {
thread_t *ctp = currp;
- sem_insert(ctp, &spw->s_queue);
- ctp->p_u.wtsemp = spw;
+ sem_insert(ctp, &spw->queue);
+ ctp->u.wtsemp = spw;
chSchGoSleepS(CH_STATE_WTSEM);
- msg = ctp->p_u.rdymsg;
+ msg = ctp->u.rdymsg;
}
else {
chSchRescheduleS();
diff --git a/os/rt/src/chstats.c b/os/rt/src/chstats.c index 82d2a67a1..f4a82086b 100644 --- a/os/rt/src/chstats.c +++ b/os/rt/src/chstats.c @@ -86,7 +86,7 @@ void _stats_increase_irq(void) { void _stats_ctxswc(thread_t *ntp, thread_t *otp) {
ch.kernel_stats.n_ctxswc++;
- chTMChainMeasurementToX(&otp->p_stats, &ntp->p_stats);
+ chTMChainMeasurementToX(&otp->stats, &ntp->stats);
}
/**
diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c index a22a66482..d9ca6d81a 100644 --- a/os/rt/src/chsys.c +++ b/os/rt/src/chsys.c @@ -91,13 +91,11 @@ static void _idle_thread(void *p) { * @special
*/
void chSysInit(void) {
-#if CH_DBG_ENABLE_STACK_CHECK == TRUE
extern stkalign_t __main_thread_stack_base__;
-#endif
- port_init();
_scheduler_init();
_vt_init();
+
#if CH_DBG_SYSTEM_STATE_CHECK == TRUE
ch.dbg.isr_cnt = (cnt_t)0;
ch.dbg.lock_cnt = (cnt_t)0;
@@ -114,30 +112,34 @@ void chSysInit(void) { #if CH_DBG_STATISTICS == TRUE
_stats_init();
#endif
-#if CH_DBG_ENABLE_TRACE == TRUE
+#if CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE
_dbg_trace_init();
#endif
#if CH_CFG_NO_IDLE_THREAD == FALSE
/* Now this instructions flow becomes the main thread.*/
- setcurrp(_thread_init(&ch.mainthread, NORMALPRIO));
+ currp = _thread_init(&ch.mainthread, "main", NORMALPRIO);
#else
/* Now this instructions flow becomes the idle thread.*/
- setcurrp(_thread_init(&ch.mainthread, IDLEPRIO));
+ currp = _thread_init(&ch.mainthread, "idle", IDLEPRIO));
#endif
- currp->p_state = CH_STATE_CURRENT;
-#if CH_DBG_ENABLE_STACK_CHECK == TRUE
- /* 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
+ /* Setting up the base address of the static main thread stack.*/
+ currp->stklimit = &__main_thread_stack_base__;
+
+ /* Setting up the caller as current thread.*/
+ currp->state = CH_STATE_CURRENT;
+
+ /* Port layer initialization last because it depend on some of the
+ initializations performed before.*/
+ port_init();
#if CH_DBG_STATISTICS == TRUE
/* Starting measurement for this thread.*/
chTMStartMeasurementX(&currp->p_stats);
#endif
+ /* It is alive now.*/
chSysEnable();
#if CH_CFG_USE_REGISTRY == TRUE
@@ -148,15 +150,19 @@ void chSysInit(void) { #if CH_CFG_NO_IDLE_THREAD == FALSE
{
- /* 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.*/
- thread_t *tp = chThdCreateStatic(ch.idle_thread_wa,
- sizeof(ch.idle_thread_wa),
- IDLEPRIO,
- (tfunc_t)_idle_thread,
- NULL);
- chRegSetThreadNameX(tp, "idle");
+ static const thread_descriptor_t idle_descriptor = {
+ "idle",
+ THD_WORKING_AREA_BASE(ch.idle_thread_wa),
+ THD_WORKING_AREA_END(ch.idle_thread_wa),
+ IDLEPRIO,
+ _idle_thread,
+ NULL
+ };
+
+ /* 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.*/
+ (void) chThdCreate(&idle_descriptor);
}
#endif
}
@@ -177,9 +183,11 @@ void chSysHalt(const char *reason) { port_disable();
-#if defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__)
+ /* Halt hook code, usually empty.*/
CH_CFG_SYSTEM_HALT_HOOK(reason);
-#endif
+
+ /* Logging the event.*/
+ _dbg_trace_halt(reason);
/* Pointing to the passed message.*/
ch.dbg.panic_msg = reason;
@@ -224,17 +232,17 @@ bool chSysIntegrityCheckI(unsigned testmask) { /* Scanning the ready list forward.*/
n = (cnt_t)0;
- tp = ch.rlist.r_queue.p_next;
- while (tp != (thread_t *)&ch.rlist.r_queue) {
+ tp = ch.rlist.queue.next;
+ while (tp != (thread_t *)&ch.rlist.queue) {
n++;
- tp = tp->p_next;
+ tp = tp->next;
}
/* Scanning the ready list backward.*/
- tp = ch.rlist.r_queue.p_prev;
- while (tp != (thread_t *)&ch.rlist.r_queue) {
+ tp = ch.rlist.queue.prev;
+ while (tp != (thread_t *)&ch.rlist.queue) {
n--;
- tp = tp->p_prev;
+ tp = tp->prev;
}
/* The number of elements must match.*/
@@ -249,17 +257,17 @@ bool chSysIntegrityCheckI(unsigned testmask) { /* Scanning the timers list forward.*/
n = (cnt_t)0;
- vtp = ch.vtlist.vt_next;
+ vtp = ch.vtlist.next;
while (vtp != (virtual_timer_t *)&ch.vtlist) {
n++;
- vtp = vtp->vt_next;
+ vtp = vtp->next;
}
/* Scanning the timers list backward.*/
- vtp = ch.vtlist.vt_prev;
+ vtp = ch.vtlist.prev;
while (vtp != (virtual_timer_t *)&ch.vtlist) {
n--;
- vtp = vtp->vt_prev;
+ vtp = vtp->prev;
}
/* The number of elements must match.*/
@@ -274,17 +282,17 @@ bool chSysIntegrityCheckI(unsigned testmask) { /* Scanning the ready list forward.*/
n = (cnt_t)0;
- tp = ch.rlist.r_newer;
+ tp = ch.rlist.newer;
while (tp != (thread_t *)&ch.rlist) {
n++;
- tp = tp->p_newer;
+ tp = tp->newer;
}
/* Scanning the ready list backward.*/
- tp = ch.rlist.r_older;
+ tp = ch.rlist.older;
while (tp != (thread_t *)&ch.rlist) {
n--;
- tp = tp->p_older;
+ tp = tp->older;
}
/* The number of elements must match.*/
@@ -320,18 +328,16 @@ void chSysTimerHandlerI(void) { #if CH_CFG_TIME_QUANTUM > 0
/* Running thread has not used up quantum yet? */
- if (currp->p_preempt > (tslices_t)0) {
+ if (currp->preempt > (tslices_t)0) {
/* Decrement remaining quantum.*/
- currp->p_preempt--;
+ currp->preempt--;
}
#endif
#if CH_DBG_THREADS_PROFILING == TRUE
- currp->p_time++;
+ currp->time++;
#endif
chVTDoTickI();
-#if defined(CH_CFG_SYSTEM_TICK_HOOK)
CH_CFG_SYSTEM_TICK_HOOK();
-#endif
}
/**
diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index b616ffd92..e706c0d77 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -45,10 +45,6 @@ * - <b>SetPriority</b>, a thread changes its own priority level.
* - <b>Yield</b>, 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.
* @{
*/
@@ -83,51 +79,42 @@ * @note This is an internal functions, do not use it in application code.
*
* @param[in] tp pointer to the thread
+ * @param[in] name thread name
* @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) {
+thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio) {
- tp->p_prio = prio;
- tp->p_state = CH_STATE_WTSTART;
- tp->p_flags = CH_FLAG_MODE_STATIC;
+ tp->prio = prio;
#if CH_CFG_TIME_QUANTUM > 0
- tp->p_preempt = (tslices_t)CH_CFG_TIME_QUANTUM;
+ tp->preempt = (tslices_t)CH_CFG_TIME_QUANTUM;
#endif
#if CH_CFG_USE_MUTEXES == TRUE
- tp->p_realprio = prio;
- tp->p_mtxlist = NULL;
+ tp->realprio = prio;
+ tp->mtxlist = NULL;
#endif
#if CH_CFG_USE_EVENTS == TRUE
- tp->p_epending = (eventmask_t)0;
+ tp->epending = (eventmask_t)0;
#endif
#if CH_DBG_THREADS_PROFILING == TRUE
- tp->p_time = (systime_t)0;
-#endif
-#if CH_CFG_USE_DYNAMIC == TRUE
- tp->p_refs = (trefs_t)1;
+ tp->time = (systime_t)0;
#endif
#if CH_CFG_USE_REGISTRY == TRUE
- tp->p_name = NULL;
+ tp->name = name;
REG_INSERT(tp);
#endif
#if CH_CFG_USE_WAITEXIT == TRUE
- list_init(&tp->p_waiting);
+ list_init(&tp->waiting);
#endif
#if CH_CFG_USE_MESSAGES == TRUE
- queue_init(&tp->p_msgqueue);
-#endif
-#if CH_DBG_ENABLE_STACK_CHECK == TRUE
- tp->p_stklimit = (stkalign_t *)(tp + 1);
+ queue_init(&tp->msgqueue);
#endif
#if CH_DBG_STATISTICS == TRUE
- chTMObjectInit(&tp->p_stats);
+ chTMObjectInit(&tp->stats);
#endif
-#if defined(CH_CFG_THREAD_INIT_HOOK)
CH_CFG_THREAD_INIT_HOOK(tp);
-#endif
return tp;
}
@@ -162,30 +149,126 @@ void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { * @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.
+ * @param[out] tdp pointer to the thread descriptor
* @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;
+thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) {
+ thread_t *tp;
chDbgCheckClassI();
- chDbgCheck((wsp != NULL) && (size >= THD_WORKING_AREA_SIZE(0)) &&
- (prio <= HIGHPRIO) && (pf != NULL));
+ chDbgCheck(tdp != NULL);
+ chDbgCheck(MEM_IS_ALIGNED(tdp->wbase, PORT_WORKING_AREA_ALIGN) &&
+ MEM_IS_ALIGNED(tdp->wend, PORT_STACK_ALIGN) &&
+ (tdp->wend > tdp->wbase) &&
+ ((size_t)((tdp->wend - tdp->wbase) *
+ sizeof (stkalign_t)) >= THD_WORKING_AREA_SIZE(0)));
+ chDbgCheck((tdp->prio <= HIGHPRIO) && (tdp->funcp != NULL));
+
+ /* The thread structure is laid out in the upper part of the thread
+ workspace. The thread position structure is aligned to the required
+ stack alignment because it represents the stack top.*/
+ tp = (thread_t *)((uint8_t *)tdp->wend -
+ MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN));
+
+ /* Initial state.*/
+ tp->state = CH_STATE_WTSTART;
+
+ /* Stack boundary.*/
+ tp->stklimit = tdp->wbase;
+
+ /* Setting up the port-dependent part of the working area.*/
+ PORT_SETUP_CONTEXT(tp, tdp->wbase, tp, tdp->funcp, tdp->arg);
+
+ /* The driver object is initialized but not started.*/
+ return _thread_init(tp, tdp->name, tdp->prio);
+}
+
+
+/**
+ * @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_WTSTART.
+ * @post The initialized thread can be subsequently started by invoking
+ * @p chThdStart(), @p chThdStartI() 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.
+ *
+ * @param[out] tdp pointer to the thread descriptor
+ * @return The pointer to the @p thread_t structure allocated for
+ * the thread into the working space area.
+ *
+ * @api
+ */
+thread_t *chThdCreateSuspended(const thread_descriptor_t *tdp) {
+ thread_t *tp;
+
+#if CH_DBG_FILL_THREADS == TRUE
+ _thread_memfill((uint8_t *)tdp->wbase,
+ (uint8_t *)tdp->wend,
+ CH_DBG_STACK_FILL_VALUE);
+#endif
+
+ chSysLock();
+ tp = chThdCreateSuspendedI(tdp);
+ chSysUnlock();
+
+ return tp;
+}
+
+/**
+ * @brief Creates a new thread into a static memory area.
+ * @details The new thread is initialized and make ready to execute.
+ * @post The initialized thread can be subsequently started by invoking
+ * @p chThdStart(), @p chThdStartI() 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] tdp pointer to the thread descriptor
+ * @return The pointer to the @p thread_t structure allocated for
+ * the thread into the working space area.
+ *
+ * @iclass
+ */
+thread_t *chThdCreateI(const thread_descriptor_t *tdp) {
+
+ return chSchReadyI(chThdCreateSuspendedI(tdp));
+}
+
+/**
+ * @brief Creates a new thread into a static memory area.
+ * @details The new thread is initialized and make ready to execute.
+ * @note A thread can terminate by calling @p chThdExit() or by simply
+ * returning from its main function.
+ *
+ * @param[out] tdp pointer to the thread descriptor
+ * @return The pointer to the @p thread_t structure allocated for
+ * the thread into the working space area.
+ *
+ * @iclass
+ */
+thread_t *chThdCreate(const thread_descriptor_t *tdp) {
+ thread_t *tp;
- PORT_SETUP_CONTEXT(tp, wsp, size, pf, arg);
+#if CH_DBG_FILL_THREADS == TRUE
+ _thread_memfill((uint8_t *)tdp->wbase,
+ (uint8_t *)tdp->wend,
+ CH_DBG_STACK_FILL_VALUE);
+#endif
+
+ chSysLock();
+ tp = chThdCreateSuspendedI(tdp);
+ chSchWakeupS(tp, MSG_OK);
+ chSysUnlock();
- return _thread_init(tp, prio);
+ return tp;
}
/**
@@ -207,18 +290,36 @@ thread_t *chThdCreateI(void *wsp, size_t size, thread_t *chThdCreateStatic(void *wsp, size_t size,
tprio_t prio, tfunc_t pf, void *arg) {
thread_t *tp;
-
+
+ chDbgCheck((wsp != NULL) &&
+ MEM_IS_ALIGNED(wsp, PORT_WORKING_AREA_ALIGN) &&
+ (size >= THD_WORKING_AREA_SIZE(0)) &&
+ MEM_IS_ALIGNED(size, PORT_STACK_ALIGN) &&
+ (prio <= HIGHPRIO) && (pf != NULL));
+
#if CH_DBG_FILL_THREADS == TRUE
_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);
+
+ /* The thread structure is laid out in the upper part of the thread
+ workspace. The thread position structure is aligned to the required
+ stack alignment because it represents the stack top.*/
+ tp = (thread_t *)((uint8_t *)wsp + size -
+ MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN));
+
+ /* Stack boundary.*/
+ tp->stklimit = (stkalign_t *)wsp;
+
+ /* Setting up the port-dependent part of the working area.*/
+ PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg);
+
+ tp = _thread_init(tp, "noname", prio);
+
+ /* Starting the thread immediately.*/
chSchWakeupS(tp, MSG_OK);
chSysUnlock();
@@ -262,14 +363,14 @@ tprio_t chThdSetPriority(tprio_t newprio) { chSysLock();
#if CH_CFG_USE_MUTEXES == TRUE
- oldprio = currp->p_realprio;
- if ((currp->p_prio == currp->p_realprio) || (newprio > currp->p_prio)) {
- currp->p_prio = newprio;
+ oldprio = currp->realprio;
+ if ((currp->prio == currp->realprio) || (newprio > currp->prio)) {
+ currp->prio = newprio;
}
- currp->p_realprio = newprio;
+ currp->realprio = newprio;
#else
- oldprio = currp->p_prio;
- currp->p_prio = newprio;
+ oldprio = currp->prio;
+ currp->prio = newprio;
#endif
chSchRescheduleS();
chSysUnlock();
@@ -278,25 +379,6 @@ tprio_t chThdSetPriority(tprio_t newprio) { }
/**
- * @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
@@ -417,21 +499,15 @@ void chThdExit(msg_t msg) { void chThdExitS(msg_t msg) {
thread_t *tp = currp;
- tp->p_u.exitcode = msg;
-#if defined(CH_CFG_THREAD_EXIT_HOOK)
+ tp->u.exitcode = msg;
CH_CFG_THREAD_EXIT_HOOK(tp);
-#endif
#if CH_CFG_USE_WAITEXIT == TRUE
- while (list_notempty(&tp->p_waiting)) {
- (void) chSchReadyI(list_remove(&tp->p_waiting));
+ while (list_notempty(&tp->waiting)) {
+ (void) chSchReadyI(list_remove(&tp->waiting));
}
#endif
#if CH_CFG_USE_REGISTRY == TRUE
- /* 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);
- }
+ REG_REMOVE(tp);
#endif
chSchGoSleepS(CH_STATE_FINAL);
@@ -443,28 +519,12 @@ void chThdExitS(msg_t msg) { /**
* @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.<br>
- * 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.
@@ -478,21 +538,13 @@ msg_t chThdWait(thread_t *tp) { chSysLock();
chDbgAssert(tp != currp, "waiting self");
-#if CH_CFG_USE_DYNAMIC == TRUE
- chDbgAssert(tp->p_refs > (trefs_t)0, "not referenced");
-#endif
- if (tp->p_state != CH_STATE_FINAL) {
- list_insert(currp, &tp->p_waiting);
+ if (tp->state != CH_STATE_FINAL) {
+ list_insert(currp, &tp->waiting);
chSchGoSleepS(CH_STATE_WTEXIT);
}
- msg = tp->p_u.exitcode;
+ msg = tp->u.exitcode;
chSysUnlock();
-#if CH_CFG_USE_DYNAMIC == TRUE
- /* Releasing a lock if it is a dynamic thread.*/
- chThdRelease(tp);
-#endif
-
return msg;
}
#endif /* CH_CFG_USE_WAITEXIT */
@@ -513,10 +565,10 @@ msg_t chThdSuspendS(thread_reference_t *trp) { chDbgAssert(*trp == NULL, "not NULL");
*trp = tp;
- tp->p_u.wttrp = trp;
+ tp->u.wttrp = trp;
chSchGoSleepS(CH_STATE_SUSPENDED);
- return chThdGetSelfX()->p_u.rdymsg;
+ return chThdGetSelfX()->u.rdymsg;
}
/**
@@ -548,7 +600,7 @@ msg_t chThdSuspendTimeoutS(thread_reference_t *trp, systime_t timeout) { }
*trp = tp;
- tp->p_u.wttrp = trp;
+ tp->u.wttrp = trp;
return chSchGoSleepTimeoutS(CH_STATE_SUSPENDED, timeout);
}
@@ -568,11 +620,10 @@ void chThdResumeI(thread_reference_t *trp, msg_t msg) { if (*trp != NULL) {
thread_t *tp = *trp;
- chDbgAssert(tp->p_state == CH_STATE_SUSPENDED,
- "not THD_STATE_SUSPENDED");
+ chDbgAssert(tp->state == CH_STATE_SUSPENDED, "not CH_STATE_SUSPENDED");
*trp = NULL;
- tp->p_u.rdymsg = msg;
+ tp->u.rdymsg = msg;
(void) chSchReadyI(tp);
}
}
@@ -592,8 +643,7 @@ void chThdResumeS(thread_reference_t *trp, msg_t msg) { if (*trp != NULL) {
thread_t *tp = *trp;
- chDbgAssert(tp->p_state == CH_STATE_SUSPENDED,
- "not THD_STATE_SUSPENDED");
+ chDbgAssert(tp->state == CH_STATE_SUSPENDED, "not CH_STATE_SUSPENDED");
*trp = NULL;
chSchWakeupS(tp, msg);
diff --git a/os/rt/src/chvt.c b/os/rt/src/chvt.c index 214e8a7b6..2231e002b 100644 --- a/os/rt/src/chvt.c +++ b/os/rt/src/chvt.c @@ -60,13 +60,13 @@ */
void _vt_init(void) {
- ch.vtlist.vt_next = (virtual_timer_t *)&ch.vtlist;
- ch.vtlist.vt_prev = (virtual_timer_t *)&ch.vtlist;
- ch.vtlist.vt_delta = (systime_t)-1;
+ ch.vtlist.next = (virtual_timer_t *)&ch.vtlist;
+ ch.vtlist.prev = (virtual_timer_t *)&ch.vtlist;
+ ch.vtlist.delta = (systime_t)-1;
#if CH_CFG_ST_TIMEDELTA == 0
- ch.vtlist.vt_systime = (systime_t)0;
+ ch.vtlist.systime = (systime_t)0;
#else /* CH_CFG_ST_TIMEDELTA > 0 */
- ch.vtlist.vt_lasttime = (systime_t)0;
+ ch.vtlist.lasttime = (systime_t)0;
#endif /* CH_CFG_ST_TIMEDELTA > 0 */
}
@@ -100,8 +100,8 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, chDbgCheckClassI();
chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (delay != TIME_IMMEDIATE));
- vtp->vt_par = par;
- vtp->vt_func = vtfunc;
+ vtp->par = par;
+ vtp->func = vtfunc;
#if CH_CFG_ST_TIMEDELTA > 0
{
@@ -114,30 +114,30 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, }
/* Special case where the timers list is empty.*/
- if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.vt_next) {
+ if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.next) {
/* The delta list is empty, the current time becomes the new
delta list base time, the timer is inserted.*/
- ch.vtlist.vt_lasttime = now;
- ch.vtlist.vt_next = vtp;
- ch.vtlist.vt_prev = vtp;
- vtp->vt_next = (virtual_timer_t *)&ch.vtlist;
- vtp->vt_prev = (virtual_timer_t *)&ch.vtlist;
- vtp->vt_delta = delay;
+ ch.vtlist.lasttime = now;
+ ch.vtlist.next = vtp;
+ ch.vtlist.prev = vtp;
+ vtp->next = (virtual_timer_t *)&ch.vtlist;
+ vtp->prev = (virtual_timer_t *)&ch.vtlist;
+ vtp->delta = delay;
/* Being the first element in the list the alarm timer is started.*/
- port_timer_start_alarm(ch.vtlist.vt_lasttime + delay);
+ port_timer_start_alarm(ch.vtlist.lasttime + delay);
return;
}
/* Special case where the timer will be placed as first element in a
non-empty list, the alarm needs to be recalculated.*/
- delta = now + delay - ch.vtlist.vt_lasttime;
- if (delta < ch.vtlist.vt_next->vt_delta) {
+ delta = now + delay - ch.vtlist.lasttime;
+ if (delta < ch.vtlist.next->delta) {
/* New alarm deadline.*/
- port_timer_set_alarm(ch.vtlist.vt_lasttime + delta);
+ port_timer_set_alarm(ch.vtlist.lasttime + delta);
}
}
#else /* CH_CFG_ST_TIMEDELTA == 0 */
@@ -147,23 +147,23 @@ void chVTDoSetI(virtual_timer_t *vtp, systime_t delay, /* The delta list is scanned in order to find the correct position for
this timer. */
- p = ch.vtlist.vt_next;
- while (p->vt_delta < delta) {
- delta -= p->vt_delta;
- p = p->vt_next;
+ p = ch.vtlist.next;
+ while (p->delta < delta) {
+ delta -= p->delta;
+ p = p->next;
}
/* The timer is inserted in the delta list.*/
- vtp->vt_next = p;
- vtp->vt_prev = vtp->vt_next->vt_prev;
- vtp->vt_prev->vt_next = vtp;
- p->vt_prev = vtp;
- vtp->vt_delta = delta
+ vtp->next = p;
+ vtp->prev = vtp->next->prev;
+ vtp->prev->next = vtp;
+ p->prev = vtp;
+ vtp->delta = delta
/* Special case when the timer is in last position in the list, the
value in the header must be restored.*/;
- p->vt_delta -= delta;
- ch.vtlist.vt_delta = (systime_t)-1;
+ p->delta -= delta;
+ ch.vtlist.delta = (systime_t)-1;
}
/**
@@ -178,71 +178,71 @@ void chVTDoResetI(virtual_timer_t *vtp) { chDbgCheckClassI();
chDbgCheck(vtp != NULL);
- chDbgAssert(vtp->vt_func != NULL, "timer not set or already triggered");
+ chDbgAssert(vtp->func != NULL, "timer not set or already triggered");
#if CH_CFG_ST_TIMEDELTA == 0
/* The delta of the timer is added to the next timer.*/
- vtp->vt_next->vt_delta += vtp->vt_delta;
+ vtp->next->delta += vtp->delta;
/* Removing the element from the delta list.*/
- vtp->vt_prev->vt_next = vtp->vt_next;
- vtp->vt_next->vt_prev = vtp->vt_prev;
- vtp->vt_func = NULL;
+ vtp->prev->next = vtp->next;
+ vtp->next->prev = vtp->prev;
+ vtp->func = 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;
+ ch.vtlist.delta = (systime_t)-1;
#else /* CH_CFG_ST_TIMEDELTA > 0 */
systime_t nowdelta, delta;
/* If the timer is not the first of the list then it is simply unlinked
else the operation is more complex.*/
- if (ch.vtlist.vt_next != vtp) {
+ if (ch.vtlist.next != vtp) {
/* Removing the element from the delta list.*/
- vtp->vt_prev->vt_next = vtp->vt_next;
- vtp->vt_next->vt_prev = vtp->vt_prev;
- vtp->vt_func = NULL;
+ vtp->prev->next = vtp->next;
+ vtp->next->prev = vtp->prev;
+ vtp->func = NULL;
/* Adding delta to the next element, if it is not the last one.*/
- if (&ch.vtlist != (virtual_timers_list_t *)vtp->vt_next)
- vtp->vt_next->vt_delta += vtp->vt_delta;
+ if (&ch.vtlist != (virtual_timers_list_t *)vtp->next)
+ vtp->next->delta += vtp->delta;
return;
}
/* Removing the first timer from the list.*/
- ch.vtlist.vt_next = vtp->vt_next;
- ch.vtlist.vt_next->vt_prev = (virtual_timer_t *)&ch.vtlist;
- vtp->vt_func = NULL;
+ ch.vtlist.next = vtp->next;
+ ch.vtlist.next->prev = (virtual_timer_t *)&ch.vtlist;
+ vtp->func = NULL;
/* If the list become empty then the alarm timer is stopped and done.*/
- if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.vt_next) {
+ if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.next) {
port_timer_stop_alarm();
return;
}
/* The delta of the removed timer is added to the new first timer.*/
- ch.vtlist.vt_next->vt_delta += vtp->vt_delta;
+ ch.vtlist.next->delta += vtp->delta;
/* If the new first timer has a delta of zero then the alarm is not
modified, the already programmed alarm will serve it.*/
-/* if (ch.vtlist.vt_next->vt_delta == 0) {
+/* if (ch.vtlist.next->delta == 0) {
return;
}*/
/* Distance in ticks between the last alarm event and current time.*/
- nowdelta = chVTGetSystemTimeX() - ch.vtlist.vt_lasttime;
+ nowdelta = chVTGetSystemTimeX() - ch.vtlist.lasttime;
/* If the current time surpassed the time of the next element in list
then the event interrupt is already pending, just return.*/
- if (nowdelta >= ch.vtlist.vt_next->vt_delta) {
+ if (nowdelta >= ch.vtlist.next->delta) {
return;
}
/* Distance from the next scheduled event and now.*/
- delta = ch.vtlist.vt_next->vt_delta - nowdelta;
+ delta = ch.vtlist.next->delta - nowdelta;
/* Making sure to not schedule an event closer than CH_CFG_ST_TIMEDELTA
ticks from now.*/
@@ -250,7 +250,7 @@ void chVTDoResetI(virtual_timer_t *vtp) { delta = (systime_t)CH_CFG_ST_TIMEDELTA;
}
- port_timer_set_alarm(ch.vtlist.vt_lasttime + nowdelta + delta);
+ port_timer_set_alarm(ch.vtlist.lasttime + nowdelta + delta);
#endif /* CH_CFG_ST_TIMEDELTA > 0 */
}
|