aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/platforms/STM32/USARTv2/serial_lld.c20
-rw-r--r--os/kernel/include/chsys.h6
-rw-r--r--os/kernel/include/chthreads.h52
-rw-r--r--os/kernel/include/chvt.h8
-rw-r--r--os/kernel/src/chcond.c4
-rw-r--r--os/kernel/src/chdynamic.c14
-rw-r--r--os/kernel/src/chevents.c16
-rw-r--r--os/kernel/src/chmsg.c10
-rw-r--r--os/kernel/src/chmtx.c14
-rw-r--r--os/kernel/src/chqueues.c6
-rw-r--r--os/kernel/src/chschd.c30
-rw-r--r--os/kernel/src/chsem.c6
-rw-r--r--os/kernel/src/chsys.c45
-rw-r--r--os/kernel/src/chthreads.c26
-rw-r--r--os/ports/GCC/ARMCMx/STM32F3xx/chtimer.c4
-rw-r--r--os/ports/GCC/ARMCMx/chtypes.h24
-rw-r--r--test/testbmk.c2
-rw-r--r--test/testdyn.c4
18 files changed, 157 insertions, 134 deletions
diff --git a/os/hal/platforms/STM32/USARTv2/serial_lld.c b/os/hal/platforms/STM32/USARTv2/serial_lld.c
index 85f6b059c..f57d0ce1b 100644
--- a/os/hal/platforms/STM32/USARTv2/serial_lld.c
+++ b/os/hal/platforms/STM32/USARTv2/serial_lld.c
@@ -134,9 +134,9 @@ static void set_error(SerialDriver *sdp, uint32_t isr) {
sts |= SD_FRAMING_ERROR;
if (isr & USART_ISR_NE)
sts |= SD_NOISE_ERROR;
- chSysLockFromIsr();
+ chSysLockFromISR();
chnAddFlagsI(sdp, sts);
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
}
/**
@@ -158,20 +158,20 @@ static void serve_interrupt(SerialDriver *sdp) {
set_error(sdp, isr);
/* Special case, LIN break detection.*/
if (isr & USART_ISR_LBD) {
- chSysLockFromIsr();
+ chSysLockFromISR();
chnAddFlagsI(sdp, SD_BREAK_DETECTED);
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
}
/* Data available.*/
if (isr & USART_ISR_RXNE) {
- chSysLockFromIsr();
+ chSysLockFromISR();
sdIncomingDataI(sdp, (uint8_t)u->RDR);
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
}
/* Transmission buffer empty.*/
if ((cr1 & USART_CR1_TXEIE) && (isr & USART_ISR_TXE)) {
msg_t b;
- chSysLockFromIsr();
+ chSysLockFromISR();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
@@ -179,13 +179,13 @@ static void serve_interrupt(SerialDriver *sdp) {
}
else
u->TDR = b;
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
}
/* Physical transmission end.*/
if (isr & USART_ISR_TC) {
- chSysLockFromIsr();
+ chSysLockFromISR();
chnAddFlagsI(sdp, CHN_TRANSMISSION_END);
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
u->CR1 = cr1 & ~USART_CR1_TCIE;
}
}
diff --git a/os/kernel/include/chsys.h b/os/kernel/include/chsys.h
index e87d0c6c1..5086e0b7f 100644
--- a/os/kernel/include/chsys.h
+++ b/os/kernel/include/chsys.h
@@ -109,6 +109,8 @@ extern "C" {
void chSysInit(void);
void chSysHalt(void);
void chSysTimerHandlerI(void);
+ syssts_t chSysGetAndLockX(void);
+ void chSysRestoreLockX(syssts_t sts);
#ifdef __cplusplus
}
#endif
@@ -214,7 +216,7 @@ static inline void chSysUnlock(void) {
*
* @special
*/
-static inline void chSysLockFromIsr(void) {
+static inline void chSysLockFromISR(void) {
port_lock_from_isr();
dbg_check_lock_from_isr();
@@ -233,7 +235,7 @@ static inline void chSysLockFromIsr(void) {
*
* @special
*/
-static inline void chSysUnlockFromIsr(void) {
+static inline void chSysUnlockFromISR(void) {
dbg_check_unlock_from_isr();
port_unlock_from_isr();
diff --git a/os/kernel/include/chthreads.h b/os/kernel/include/chthreads.h
index f4785a268..a945f8d7d 100644
--- a/os/kernel/include/chthreads.h
+++ b/os/kernel/include/chthreads.h
@@ -37,31 +37,31 @@
* @name Thread states
* @{
*/
-#define THD_STATE_READY 0 /**< @brief Waiting on the ready list. */
-#define THD_STATE_CURRENT 1 /**< @brief Currently running. */
-#define THD_STATE_SUSPENDED 2 /**< @brief Created in suspended state. */
-#define THD_STATE_WTSEM 3 /**< @brief Waiting on a semaphore. */
-#define THD_STATE_WTMTX 4 /**< @brief Waiting on a mutex. */
-#define THD_STATE_WTCOND 5 /**< @brief Waiting on a condition
+#define CH_STATE_READY 0 /**< @brief Waiting on the ready list. */
+#define CH_STATE_CURRENT 1 /**< @brief Currently running. */
+#define CH_STATE_SUSPENDED 2 /**< @brief Created in suspended state. */
+#define CH_STATE_WTSEM 3 /**< @brief Waiting on a semaphore. */
+#define CH_STATE_WTMTX 4 /**< @brief Waiting on a mutex. */
+#define CH_STATE_WTCOND 5 /**< @brief Waiting on a condition
variable. */
-#define THD_STATE_SLEEPING 6 /**< @brief Waiting in @p chThdSleep()
+#define CH_STATE_SLEEPING 6 /**< @brief Waiting in @p chThdSleep()
or @p chThdSleepUntil(). */
-#define THD_STATE_WTEXIT 7 /**< @brief Waiting in @p chThdWait(). */
-#define THD_STATE_WTOREVT 8 /**< @brief Waiting for an event. */
-#define THD_STATE_WTANDEVT 9 /**< @brief Waiting for several events. */
-#define THD_STATE_SNDMSGQ 10 /**< @brief Sending a message, in queue.*/
-#define THD_STATE_SNDMSG 11 /**< @brief Sent a message, waiting
+#define CH_STATE_WTEXIT 7 /**< @brief Waiting in @p chThdWait(). */
+#define CH_STATE_WTOREVT 8 /**< @brief Waiting for an event. */
+#define CH_STATE_WTANDEVT 9 /**< @brief Waiting for several events. */
+#define CH_STATE_SNDMSGQ 10 /**< @brief Sending a message, in queue.*/
+#define CH_STATE_SNDMSG 11 /**< @brief Sent a message, waiting
answer. */
-#define THD_STATE_WTMSG 12 /**< @brief Waiting for a message. */
-#define THD_STATE_WTQUEUE 13 /**< @brief Waiting on an I/O queue. */
-#define THD_STATE_FINAL 14 /**< @brief Thread terminated. */
+#define CH_STATE_WTMSG 12 /**< @brief Waiting for a message. */
+#define CH_STATE_WTQUEUE 13 /**< @brief Waiting on an I/O queue. */
+#define CH_STATE_FINAL 14 /**< @brief Thread terminated. */
/**
* @brief Thread states as array of strings.
* @details Each element in an array initialized with this macro can be
* indexed using the numeric thread state values.
*/
-#define THD_STATE_NAMES \
+#define CH_STATE_NAMES \
"READY", "CURRENT", "SUSPENDED", "WTSEM", "WTMTX", "WTCOND", "SLEEPING", \
"WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", "SNDMSG", "WTMSG", "WTQUEUE", \
"FINAL"
@@ -71,13 +71,13 @@
* @name Thread flags and attributes
* @{
*/
-#define THD_MEM_MODE_MASK 3 /**< @brief Thread memory mode mask. */
-#define THD_MEM_MODE_STATIC 0 /**< @brief Static thread. */
-#define THD_MEM_MODE_HEAP 1 /**< @brief Thread allocated from a
+#define CH_FLAG_MODE_MASK 3 /**< @brief Thread memory mode mask. */
+#define CH_FLAG_MODE_STATIC 0 /**< @brief Static thread. */
+#define CH_FLAG_MODE_HEAP 1 /**< @brief Thread allocated from a
Memory Heap. */
-#define THD_MEM_MODE_MEMPOOL 2 /**< @brief Thread allocated from a
+#define CH_FLAG_MODE_MEMPOOL 2 /**< @brief Thread allocated from a
Memory Pool. */
-#define THD_TERMINATE 4 /**< @brief Termination requested flag. */
+#define CH_FLAG_TERMINATE 4 /**< @brief Termination requested flag. */
/** @} */
/*===========================================================================*/
@@ -206,7 +206,7 @@ typedef struct thread {
/**
* @brief Enabled events mask.
* @note This field is only valid while the thread is in the
- * @p THD_STATE_WTOREVT or @p THD_STATE_WTANDEVT states.
+ * @p CH_STATE_WTOREVT or @p CH_STATE_WTANDEVT states.
*/
eventmask_t ewmask;
#endif
@@ -298,7 +298,7 @@ typedef msg_t (*tfunc_t)(void *);
#define chThdGetTicks(tp) ((tp)->p_time)
/**
- * @brief Verifies if the specified thread is in the @p THD_STATE_FINAL state.
+ * @brief Verifies if the specified thread is in the @p CH_STATE_FINAL state.
* @note Can be invoked in any context.
*
* @param[in] tp pointer to the thread
@@ -307,7 +307,7 @@ typedef msg_t (*tfunc_t)(void *);
*
* @special
*/
-#define chThdTerminated(tp) ((tp)->p_state == THD_STATE_FINAL)
+#define chThdTerminated(tp) ((tp)->p_state == CH_STATE_FINAL)
/**
* @brief Verifies if the current thread has a termination request pending.
@@ -318,7 +318,7 @@ typedef msg_t (*tfunc_t)(void *);
*
* @special
*/
-#define chThdShouldTerminate() (currp->p_flags & THD_TERMINATE)
+#define chThdShouldTerminate() (currp->p_flags & CH_FLAG_TERMINATE)
/**
* @brief Resumes a thread created with @p chThdCreateI().
@@ -341,7 +341,7 @@ typedef msg_t (*tfunc_t)(void *);
*
* @sclass
*/
-#define chThdSleepS(time) chSchGoSleepTimeoutS(THD_STATE_SLEEPING, time)
+#define chThdSleepS(time) chSchGoSleepTimeoutS(CH_STATE_SLEEPING, time)
/**
* @brief Delays the invoking thread for the specified number of seconds.
diff --git a/os/kernel/include/chvt.h b/os/kernel/include/chvt.h
index d1659d286..a499db690 100644
--- a/os/kernel/include/chvt.h
+++ b/os/kernel/include/chvt.h
@@ -384,9 +384,9 @@ static inline void chVTDoTickI(void) {
vtp->vt_func = (vtfunc_t)NULL;
vtp->vt_next->vt_prev = (void *)&vtlist;
vtlist.vt_next = vtp->vt_next;
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
fn(vtp->vt_par);
- chSysLockFromIsr();
+ chSysLockFromISR();
}
}
#else /* CH_CFG_TIMEDELTA > 0 */
@@ -401,9 +401,9 @@ static inline void chVTDoTickI(void) {
vtp->vt_func = (vtfunc_t)NULL;
vtp->vt_next->vt_prev = (void *)&vtlist;
vtlist.vt_next = vtp->vt_next;
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
fn(vtp->vt_par);
- chSysLockFromIsr();
+ chSysLockFromISR();
}
if (&vtlist == (virtual_timers_list_t *)vtlist.vt_next) {
/* The list is empty, no tick event needed so the alarm timer
diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c
index 8486705e6..49e1f891e 100644
--- a/os/kernel/src/chcond.c
+++ b/os/kernel/src/chcond.c
@@ -212,7 +212,7 @@ msg_t chCondWaitS(condition_variable_t *cp) {
mp = chMtxUnlockS();
ctp->p_u.wtobjp = cp;
queue_prio_insert(ctp, &cp->c_queue);
- chSchGoSleepS(THD_STATE_WTCOND);
+ chSchGoSleepS(CH_STATE_WTCOND);
msg = ctp->p_u.rdymsg;
chMtxLockS(mp);
return msg;
@@ -297,7 +297,7 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) {
mp = chMtxUnlockS();
currp->p_u.wtobjp = cp;
queue_prio_insert(currp, &cp->c_queue);
- msg = chSchGoSleepTimeoutS(THD_STATE_WTCOND, time);
+ msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, time);
if (msg != RDY_TIMEOUT)
chMtxLockS(mp);
return msg;
diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c
index cab5556f3..2b12e698f 100644
--- a/os/kernel/src/chdynamic.c
+++ b/os/kernel/src/chdynamic.c
@@ -78,7 +78,7 @@ thread_t *chThdAddRef(thread_t *tp) {
/**
* @brief Releases a reference to a thread object.
* @details If the references counter reaches zero <b>and</b> the thread
- * is in the @p THD_STATE_FINAL state then the thread's memory is
+ * is in the @p CH_STATE_FINAL state then the thread's memory is
* returned to the proper allocator.
* @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in order
* to use this function.
@@ -99,10 +99,10 @@ void chThdRelease(thread_t *tp) {
/* If the references counter reaches zero and the thread is in its
terminated state then the memory can be returned to the proper
allocator. Of course static threads are not affected.*/
- if ((refs == 0) && (tp->p_state == THD_STATE_FINAL)) {
- switch (tp->p_flags & THD_MEM_MODE_MASK) {
+ if ((refs == 0) && (tp->p_state == CH_STATE_FINAL)) {
+ switch (tp->p_flags & CH_FLAG_MODE_MASK) {
#if CH_CFG_USE_HEAP
- case THD_MEM_MODE_HEAP:
+ case CH_FLAG_MODE_HEAP:
#if CH_CFG_USE_REGISTRY
REG_REMOVE(tp);
#endif
@@ -110,7 +110,7 @@ void chThdRelease(thread_t *tp) {
break;
#endif
#if CH_CFG_USE_MEMPOOLS
- case THD_MEM_MODE_MEMPOOL:
+ case CH_FLAG_MODE_MEMPOOL:
#if CH_CFG_USE_REGISTRY
REG_REMOVE(tp);
#endif
@@ -164,7 +164,7 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size,
chSysLock();
tp = chThdCreateI(wsp, size, prio, pf, arg);
- tp->p_flags = THD_MEM_MODE_HEAP;
+ tp->p_flags = CH_FLAG_MODE_HEAP;
chSchWakeupS(tp, RDY_OK);
chSysUnlock();
return tp;
@@ -215,7 +215,7 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio,
chSysLock();
tp = chThdCreateI(wsp, mp->mp_object_size, prio, pf, arg);
- tp->p_flags = THD_MEM_MODE_MEMPOOL;
+ tp->p_flags = CH_FLAG_MODE_MEMPOOL;
tp->p_mpool = mp;
chSchWakeupS(tp, RDY_OK);
chSysUnlock();
diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c
index f48a3ec9a..d95730f7c 100644
--- a/os/kernel/src/chevents.c
+++ b/os/kernel/src/chevents.c
@@ -275,9 +275,9 @@ void chEvtSignalI(thread_t *tp, eventmask_t mask) {
tp->p_epending |= mask;
/* Test on the AND/OR conditions wait states.*/
- if (((tp->p_state == THD_STATE_WTOREVT) &&
+ if (((tp->p_state == CH_STATE_WTOREVT) &&
((tp->p_epending & tp->p_u.ewmask) != 0)) ||
- ((tp->p_state == THD_STATE_WTANDEVT) &&
+ ((tp->p_state == CH_STATE_WTANDEVT) &&
((tp->p_epending & tp->p_u.ewmask) == tp->p_u.ewmask)))
chSchReadyI(tp)->p_u.rdymsg = RDY_OK;
}
@@ -375,7 +375,7 @@ eventmask_t chEvtWaitOne(eventmask_t mask) {
if ((m = (ctp->p_epending & mask)) == 0) {
ctp->p_u.ewmask = mask;
- chSchGoSleepS(THD_STATE_WTOREVT);
+ chSchGoSleepS(CH_STATE_WTOREVT);
m = ctp->p_epending & mask;
}
m &= -m;
@@ -404,7 +404,7 @@ eventmask_t chEvtWaitAny(eventmask_t mask) {
if ((m = (ctp->p_epending & mask)) == 0) {
ctp->p_u.ewmask = mask;
- chSchGoSleepS(THD_STATE_WTOREVT);
+ chSchGoSleepS(CH_STATE_WTOREVT);
m = ctp->p_epending & mask;
}
ctp->p_epending &= ~m;
@@ -431,7 +431,7 @@ eventmask_t chEvtWaitAll(eventmask_t mask) {
if ((ctp->p_epending & mask) != mask) {
ctp->p_u.ewmask = mask;
- chSchGoSleepS(THD_STATE_WTANDEVT);
+ chSchGoSleepS(CH_STATE_WTANDEVT);
}
ctp->p_epending &= ~mask;
@@ -475,7 +475,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time) {
return (eventmask_t)0;
}
ctp->p_u.ewmask = mask;
- if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) {
+ if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < RDY_OK) {
chSysUnlock();
return (eventmask_t)0;
}
@@ -518,7 +518,7 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time) {
return (eventmask_t)0;
}
ctp->p_u.ewmask = mask;
- if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) {
+ if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < RDY_OK) {
chSysUnlock();
return (eventmask_t)0;
}
@@ -558,7 +558,7 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time) {
return (eventmask_t)0;
}
ctp->p_u.ewmask = mask;
- if (chSchGoSleepTimeoutS(THD_STATE_WTANDEVT, time) < RDY_OK) {
+ if (chSchGoSleepTimeoutS(CH_STATE_WTANDEVT, time) < RDY_OK) {
chSysUnlock();
return (eventmask_t)0;
}
diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c
index 535143b7c..1e99cce3f 100644
--- a/os/kernel/src/chmsg.c
+++ b/os/kernel/src/chmsg.c
@@ -94,9 +94,9 @@ msg_t chMsgSend(thread_t *tp, msg_t msg) {
ctp->p_msg = msg;
ctp->p_u.wtobjp = &tp->p_msgqueue;
msg_insert(ctp, &tp->p_msgqueue);
- if (tp->p_state == THD_STATE_WTMSG)
+ if (tp->p_state == CH_STATE_WTMSG)
chSchReadyI(tp);
- chSchGoSleepS(THD_STATE_SNDMSGQ);
+ chSchGoSleepS(CH_STATE_SNDMSGQ);
msg = ctp->p_u.rdymsg;
chSysUnlock();
return msg;
@@ -121,9 +121,9 @@ thread_t *chMsgWait(void) {
chSysLock();
if (!chMsgIsPendingI(currp))
- chSchGoSleepS(THD_STATE_WTMSG);
+ chSchGoSleepS(CH_STATE_WTMSG);
tp = queue_fifo_remove(&currp->p_msgqueue);
- tp->p_state = THD_STATE_SNDMSG;
+ tp->p_state = CH_STATE_SNDMSG;
chSysUnlock();
return tp;
}
@@ -141,7 +141,7 @@ thread_t *chMsgWait(void) {
void chMsgRelease(thread_t *tp, msg_t msg) {
chSysLock();
- chDbgAssert(tp->p_state == THD_STATE_SNDMSG,
+ chDbgAssert(tp->p_state == CH_STATE_SNDMSG,
"chMsgRelease(), #1", "invalid state");
chMsgReleaseS(tp, msg);
chSysUnlock();
diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c
index be9c6dd78..5f7bdfb8d 100644
--- a/os/kernel/src/chmtx.c
+++ b/os/kernel/src/chmtx.c
@@ -152,7 +152,7 @@ void chMtxLockS(mutex_t *mp) {
/* The following states need priority queues reordering.*/
switch (tp->p_state) {
- case THD_STATE_WTMTX:
+ case CH_STATE_WTMTX:
/* Re-enqueues the mutex owner with its new priority.*/
queue_prio_insert(queue_dequeue(tp),
(threads_queue_t *)tp->p_u.wtobjp);
@@ -162,23 +162,23 @@ void chMtxLockS(mutex_t *mp) {
(CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY) | \
(CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY)
#if CH_CFG_USE_CONDVARS
- case THD_STATE_WTCOND:
+ case CH_STATE_WTCOND:
#endif
#if CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY
- case THD_STATE_WTSEM:
+ case CH_STATE_WTSEM:
#endif
#if CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY
- case THD_STATE_SNDMSGQ:
+ case CH_STATE_SNDMSGQ:
#endif
/* Re-enqueues tp with its new priority on the queue.*/
queue_prio_insert(queue_dequeue(tp),
(threads_queue_t *)tp->p_u.wtobjp);
break;
#endif
- case THD_STATE_READY:
+ case CH_STATE_READY:
#if CH_DBG_ENABLE_ASSERTS
/* Prevents an assertion in chSchReadyI().*/
- tp->p_state = THD_STATE_CURRENT;
+ tp->p_state = CH_STATE_CURRENT;
#endif
/* Re-enqueues tp with its new priority on the ready list.*/
chSchReadyI(queue_dequeue(tp));
@@ -190,7 +190,7 @@ void chMtxLockS(mutex_t *mp) {
/* Sleep on the mutex.*/
queue_prio_insert(ctp, &mp->m_queue);
ctp->p_u.wtobjp = mp;
- chSchGoSleepS(THD_STATE_WTMTX);
+ chSchGoSleepS(CH_STATE_WTMTX);
/* It is assumed that the thread performing the unlock operation assigns
the mutex to this thread.*/
diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c
index fcaa2895f..f7e587228 100644
--- a/os/kernel/src/chqueues.c
+++ b/os/kernel/src/chqueues.c
@@ -66,7 +66,7 @@ static msg_t qwait(GenericQueue *qp, systime_t time) {
return Q_TIMEOUT;
currp->p_u.wtobjp = qp;
queue_insert(currp, &qp->q_waiting);
- return chSchGoSleepTimeoutS(THD_STATE_WTQUEUE, time);
+ return chSchGoSleepTimeoutS(CH_STATE_WTQUEUE, time);
}
/**
@@ -154,7 +154,7 @@ msg_t chIQPutI(InputQueue *iqp, uint8_t b) {
* is empty then the calling thread is suspended until a byte arrives
* in the queue or a timeout occurs.
* @note The callback is invoked before reading the character from the
- * buffer or before entering the state @p THD_STATE_WTQUEUE.
+ * buffer or before entering the state @p CH_STATE_WTQUEUE.
*
* @param[in] iqp pointer to an @p InputQueue structure
* @param[in] time the number of ticks before the operation timeouts,
@@ -201,7 +201,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) {
* @note The function is not atomic, if you need atomicity it is suggested
* to use a semaphore or a mutex for mutual exclusion.
* @note The callback is invoked before reading each character from the
- * buffer or before entering the state @p THD_STATE_WTQUEUE.
+ * buffer or before entering the state @p CH_STATE_WTQUEUE.
*
* @param[in] iqp pointer to an @p InputQueue structure
* @param[out] bp pointer to the data buffer
diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c
index c360777ef..db0097108 100644
--- a/os/kernel/src/chschd.c
+++ b/os/kernel/src/chschd.c
@@ -94,12 +94,12 @@ thread_t *chSchReadyI(thread_t *tp) {
chDbgCheckClassI();
/* Integrity checks.*/
- chDbgAssert((tp->p_state != THD_STATE_READY) &&
- (tp->p_state != THD_STATE_FINAL),
+ chDbgAssert((tp->p_state != CH_STATE_READY) &&
+ (tp->p_state != CH_STATE_FINAL),
"chSchReadyI(), #1",
"invalid state");
- tp->p_state = THD_STATE_READY;
+ tp->p_state = CH_STATE_READY;
cp = (thread_t *)&rlist.r_queue;
do {
cp = cp->p_next;
@@ -132,7 +132,7 @@ void chSchGoSleepS(tstate_t newstate) {
otp->p_preempt = CH_CFG_TIME_QUANTUM;
#endif
setcurrp(queue_fifo_remove(&rlist.r_queue));
- currp->p_state = THD_STATE_CURRENT;
+ currp->p_state = CH_STATE_CURRENT;
chSysSwitch(currp, otp);
}
@@ -142,25 +142,25 @@ void chSchGoSleepS(tstate_t newstate) {
static void wakeup(void *p) {
thread_t *tp = (thread_t *)p;
- chSysLockFromIsr();
+ chSysLockFromISR();
switch (tp->p_state) {
- case THD_STATE_READY:
+ case CH_STATE_READY:
/* Handling the special case where the thread has been made ready by
another thread with higher priority.*/
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
return;
#if CH_CFG_USE_SEMAPHORES || CH_CFG_USE_QUEUES || \
(CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT)
#if CH_CFG_USE_SEMAPHORES
- case THD_STATE_WTSEM:
+ case CH_STATE_WTSEM:
chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp);
/* Falls into, intentional. */
#endif
#if CH_CFG_USE_QUEUES
- case THD_STATE_WTQUEUE:
+ case CH_STATE_WTQUEUE:
#endif
#if CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT
- case THD_STATE_WTCOND:
+ case CH_STATE_WTCOND:
#endif
/* States requiring dequeuing.*/
queue_dequeue(tp);
@@ -168,7 +168,7 @@ static void wakeup(void *p) {
}
tp->p_u.rdymsg = RDY_TIMEOUT;
chSchReadyI(tp);
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
}
/**
@@ -240,7 +240,7 @@ void chSchWakeupS(thread_t *ntp, msg_t msg) {
else {
thread_t *otp = chSchReadyI(currp);
setcurrp(ntp);
- ntp->p_state = THD_STATE_CURRENT;
+ ntp->p_state = CH_STATE_CURRENT;
chSysSwitch(ntp, otp);
}
}
@@ -305,7 +305,7 @@ void chSchDoRescheduleBehind(void) {
otp = currp;
/* Picks the first thread from the ready queue and makes it current.*/
setcurrp(queue_fifo_remove(&rlist.r_queue));
- currp->p_state = THD_STATE_CURRENT;
+ currp->p_state = CH_STATE_CURRENT;
#if CH_CFG_TIME_QUANTUM > 0
otp->p_preempt = CH_CFG_TIME_QUANTUM;
#endif
@@ -328,9 +328,9 @@ void chSchDoRescheduleAhead(void) {
otp = currp;
/* Picks the first thread from the ready queue and makes it current.*/
setcurrp(queue_fifo_remove(&rlist.r_queue));
- currp->p_state = THD_STATE_CURRENT;
+ currp->p_state = CH_STATE_CURRENT;
- otp->p_state = THD_STATE_READY;
+ otp->p_state = CH_STATE_READY;
cp = (thread_t *)&rlist.r_queue;
do {
cp = cp->p_next;
diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c
index bcf222230..d25b93822 100644
--- a/os/kernel/src/chsem.c
+++ b/os/kernel/src/chsem.c
@@ -207,7 +207,7 @@ msg_t chSemWaitS(semaphore_t *sp) {
if (--sp->s_cnt < 0) {
currp->p_u.wtobjp = sp;
sem_insert(currp, &sp->s_queue);
- chSchGoSleepS(THD_STATE_WTSEM);
+ chSchGoSleepS(CH_STATE_WTSEM);
return currp->p_u.rdymsg;
}
return RDY_OK;
@@ -276,7 +276,7 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) {
}
currp->p_u.wtobjp = sp;
sem_insert(currp, &sp->s_queue);
- return chSchGoSleepTimeoutS(THD_STATE_WTSEM, time);
+ return chSchGoSleepTimeoutS(CH_STATE_WTSEM, time);
}
return RDY_OK;
}
@@ -393,7 +393,7 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) {
thread_t *ctp = currp;
sem_insert(ctp, &spw->s_queue);
ctp->p_u.wtobjp = spw;
- chSchGoSleepS(THD_STATE_WTSEM);
+ chSchGoSleepS(CH_STATE_WTSEM);
msg = ctp->p_u.rdymsg;
}
else {
diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c
index 97f01f933..61157b1b9 100644
--- a/os/kernel/src/chsys.c
+++ b/os/kernel/src/chsys.c
@@ -117,7 +117,7 @@ void chSysInit(void) {
/* Now this instructions flow becomes the main thread.*/
setcurrp(_thread_init(&mainthread, NORMALPRIO));
- currp->p_state = THD_STATE_CURRENT;
+ currp->p_state = CH_STATE_CURRENT;
#if CH_DBG_ENABLE_STACK_CHECK
/* This is a special case because the main thread thread_t structure is not
adjacent to its stack area.*/
@@ -191,4 +191,47 @@ void chSysTimerHandlerI(void) {
#endif
}
+
+/**
+ * @brief Returns the execution context and enters the kernel lock mode.
+ * @details This functions enters into a critical zone and can be called
+ * from any context. Because its flexibility it is less efficient
+ * than @p chSysLock() which is preferable when the calling context
+ * is known.
+ *
+ * @return The previous system status, the encoding of this
+ * status word is architecture-dependent but zero is
+ * assumed to mean not-locked.
+ *
+ * @special
+ */
+syssts_t chSysGetAndLockX(void) {
+
+ syssts_t sts = port_get_status();
+ if (!sts) {
+ if (port_get_context())
+ chSysLockFromISR();
+ else
+ chSysLock();
+ }
+ return sts;
+}
+
+/**
+ * @brief Restores the specified execution status.
+ *
+ * @param[in] sts the system status to be restored.
+ *
+ * @special
+ */
+void chSysRestoreLockX(syssts_t sts) {
+
+ if (!sts) {
+ if (port_get_context())
+ chSysUnlockFromISR();
+ else
+ chSysUnlock();
+ }
+}
+
/** @} */
diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c
index 17eeb763b..9017a59b7 100644
--- a/os/kernel/src/chthreads.c
+++ b/os/kernel/src/chthreads.c
@@ -93,8 +93,8 @@
thread_t *_thread_init(thread_t *tp, tprio_t prio) {
tp->p_prio = prio;
- tp->p_state = THD_STATE_SUSPENDED;
- tp->p_flags = THD_MEM_MODE_STATIC;
+ tp->p_state = CH_STATE_SUSPENDED;
+ tp->p_flags = CH_FLAG_MODE_STATIC;
#if CH_CFG_TIME_QUANTUM > 0
tp->p_preempt = CH_CFG_TIME_QUANTUM;
#endif
@@ -150,7 +150,7 @@ void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) {
/**
* @brief Creates a new thread into a static memory area.
* @details The new thread is initialized but not inserted in the ready list,
- * the initial state is @p THD_STATE_SUSPENDED.
+ * the initial state is @p CH_STATE_SUSPENDED.
* @post The initialized thread can be subsequently started by invoking
* @p chThdResume(), @p chThdResumeI() or @p chSchWakeupS()
* depending on the execution context.
@@ -255,7 +255,7 @@ tprio_t chThdSetPriority(tprio_t newprio) {
/**
* @brief Resumes a suspended thread.
* @pre The specified thread pointer must refer to an initialized thread
- * in the @p THD_STATE_SUSPENDED state.
+ * in the @p CH_STATE_SUSPENDED state.
* @post The specified thread is immediately started or put in the ready
* list depending on the relative priority levels.
* @note Use this function to start threads created with @p chThdCreateI().
@@ -268,9 +268,9 @@ tprio_t chThdSetPriority(tprio_t newprio) {
thread_t *chThdResume(thread_t *tp) {
chSysLock();
- chDbgAssert(tp->p_state == THD_STATE_SUSPENDED,
+ chDbgAssert(tp->p_state == CH_STATE_SUSPENDED,
"chThdResume(), #1",
- "thread not in THD_STATE_SUSPENDED state");
+ "thread not in CH_STATE_SUSPENDED state");
chSchWakeupS(tp, RDY_OK);
chSysUnlock();
return tp;
@@ -291,7 +291,7 @@ thread_t *chThdResume(thread_t *tp) {
void chThdTerminate(thread_t *tp) {
chSysLock();
- tp->p_flags |= THD_TERMINATE;
+ tp->p_flags |= CH_FLAG_TERMINATE;
chSysUnlock();
}
@@ -348,7 +348,7 @@ void chThdYield(void) {
/**
* @brief Terminates the current thread.
- * @details The thread goes in the @p THD_STATE_FINAL state holding the
+ * @details The thread goes in the @p CH_STATE_FINAL state holding the
* specified exit status code, other threads can retrieve the
* exit status code by invoking the function @p chThdWait().
* @post Eventual code after this function will never be executed,
@@ -369,7 +369,7 @@ void chThdExit(msg_t msg) {
/**
* @brief Terminates the current thread.
- * @details The thread goes in the @p THD_STATE_FINAL state holding the
+ * @details The thread goes in the @p CH_STATE_FINAL state holding the
* specified exit status code, other threads can retrieve the
* exit status code by invoking the function @p chThdWait().
* @post Eventual code after this function will never be executed,
@@ -395,10 +395,10 @@ void chThdExitS(msg_t msg) {
#if CH_CFG_USE_REGISTRY
/* Static threads are immediately removed from the registry because
there is no memory to recover.*/
- if ((tp->p_flags & THD_MEM_MODE_MASK) == THD_MEM_MODE_STATIC)
+ if ((tp->p_flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC)
REG_REMOVE(tp);
#endif
- chSchGoSleepS(THD_STATE_FINAL);
+ chSchGoSleepS(CH_STATE_FINAL);
/* The thread never returns here.*/
chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse");
}
@@ -445,9 +445,9 @@ msg_t chThdWait(thread_t *tp) {
#if CH_CFG_USE_DYNAMIC
chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced");
#endif
- if (tp->p_state != THD_STATE_FINAL) {
+ if (tp->p_state != CH_STATE_FINAL) {
list_insert(currp, &tp->p_waiting);
- chSchGoSleepS(THD_STATE_WTEXIT);
+ chSchGoSleepS(CH_STATE_WTEXIT);
}
msg = tp->p_u.exitcode;
chSysUnlock();
diff --git a/os/ports/GCC/ARMCMx/STM32F3xx/chtimer.c b/os/ports/GCC/ARMCMx/STM32F3xx/chtimer.c
index 78d2aaf06..9eba072c5 100644
--- a/os/ports/GCC/ARMCMx/STM32F3xx/chtimer.c
+++ b/os/ports/GCC/ARMCMx/STM32F3xx/chtimer.c
@@ -59,9 +59,9 @@ CH_IRQ_HANDLER(VectorB0) {
STM32F3_TIM2->SR = 0;
- chSysLockFromIsr();
+ chSysLockFromISR();
chSysTimerHandlerI();
- chSysUnlockFromIsr();
+ chSysUnlockFromISR();
CH_IRQ_EPILOGUE();
}
diff --git a/os/ports/GCC/ARMCMx/chtypes.h b/os/ports/GCC/ARMCMx/chtypes.h
index 2d61d0250..689b8c64d 100644
--- a/os/ports/GCC/ARMCMx/chtypes.h
+++ b/os/ports/GCC/ARMCMx/chtypes.h
@@ -34,6 +34,7 @@
#include <stdbool.h>
typedef bool bool_t; /**< Fast boolean type. */
+typedef uint32_t syssts_t; /**< System status word. */
typedef uint8_t tmode_t; /**< Thread flags. */
typedef uint8_t tstate_t; /**< Thread state. */
typedef uint8_t trefs_t; /**< Thread references counter. */
@@ -47,34 +48,11 @@ typedef uint32_t systime_t; /**< System time. */
typedef int32_t cnt_t; /**< Resources counter. */
/**
- * @brief Inline function modifier.
- */
-#define INLINE inline
-
-/**
* @brief ROM constant modifier.
* @note It is set to use the "const" keyword in this port.
*/
#define ROMCONST const
-/**
- * @brief Packed structure modifier (within).
- * @note It uses the "packed" GCC attribute.
- */
-#define PACK_STRUCT_STRUCT __attribute__((packed))
-
-/**
- * @brief Packed structure modifier (before).
- * @note Empty in this port.
- */
-#define PACK_STRUCT_BEGIN
-
-/**
- * @brief Packed structure modifier (after).
- * @note Empty in this port.
- */
-#define PACK_STRUCT_END
-
#endif /* _CHTYPES_H_ */
/** @} */
diff --git a/test/testbmk.c b/test/testbmk.c
index ce8b8d51e..293dbd607 100644
--- a/test/testbmk.c
+++ b/test/testbmk.c
@@ -207,7 +207,7 @@ msg_t thread4(void *p) {
(void)p;
chSysLock();
do {
- chSchGoSleepS(THD_STATE_SUSPENDED);
+ chSchGoSleepS(CH_STATE_SUSPENDED);
msg = self->p_u.rdymsg;
} while (msg == RDY_OK);
chSysUnlock();
diff --git a/test/testdyn.c b/test/testdyn.c
index 31fd0c005..7ba281e31 100644
--- a/test/testdyn.c
+++ b/test/testdyn.c
@@ -224,11 +224,11 @@ static void dyn3_execute(void) {
/* Detach and let the thread execute and terminate.*/
chThdRelease(tp);
test_assert(6, tp->p_refs == 0, "detach failure");
- test_assert(7, tp->p_state == THD_STATE_READY, "invalid state");
+ test_assert(7, tp->p_state == CH_STATE_READY, "invalid state");
test_assert(8, regfind(tp), "thread disappeared");
test_assert(9, regfind(tp), "thread disappeared");
chThdSleepMilliseconds(50); /* The thread just terminates. */
- test_assert(10, tp->p_state == THD_STATE_FINAL, "invalid state");
+ test_assert(10, tp->p_state == CH_STATE_FINAL, "invalid state");
/* Clearing the zombie by scanning the registry.*/
test_assert(11, regfind(tp), "thread disappeared");