git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6025 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2013-07-24 14:54:26 +00:00
parent fa64f08fc1
commit 40f413d3c9
18 changed files with 157 additions and 134 deletions

View File

@ -134,9 +134,9 @@ static void set_error(SerialDriver *sdp, uint32_t isr) {
sts |= SD_FRAMING_ERROR; sts |= SD_FRAMING_ERROR;
if (isr & USART_ISR_NE) if (isr & USART_ISR_NE)
sts |= SD_NOISE_ERROR; sts |= SD_NOISE_ERROR;
chSysLockFromIsr(); chSysLockFromISR();
chnAddFlagsI(sdp, sts); chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr(); chSysUnlockFromISR();
} }
/** /**
@ -158,20 +158,20 @@ static void serve_interrupt(SerialDriver *sdp) {
set_error(sdp, isr); set_error(sdp, isr);
/* Special case, LIN break detection.*/ /* Special case, LIN break detection.*/
if (isr & USART_ISR_LBD) { if (isr & USART_ISR_LBD) {
chSysLockFromIsr(); chSysLockFromISR();
chnAddFlagsI(sdp, SD_BREAK_DETECTED); chnAddFlagsI(sdp, SD_BREAK_DETECTED);
chSysUnlockFromIsr(); chSysUnlockFromISR();
} }
/* Data available.*/ /* Data available.*/
if (isr & USART_ISR_RXNE) { if (isr & USART_ISR_RXNE) {
chSysLockFromIsr(); chSysLockFromISR();
sdIncomingDataI(sdp, (uint8_t)u->RDR); sdIncomingDataI(sdp, (uint8_t)u->RDR);
chSysUnlockFromIsr(); chSysUnlockFromISR();
} }
/* Transmission buffer empty.*/ /* Transmission buffer empty.*/
if ((cr1 & USART_CR1_TXEIE) && (isr & USART_ISR_TXE)) { if ((cr1 & USART_CR1_TXEIE) && (isr & USART_ISR_TXE)) {
msg_t b; msg_t b;
chSysLockFromIsr(); chSysLockFromISR();
b = chOQGetI(&sdp->oqueue); b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) { if (b < Q_OK) {
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY); chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
@ -179,13 +179,13 @@ static void serve_interrupt(SerialDriver *sdp) {
} }
else else
u->TDR = b; u->TDR = b;
chSysUnlockFromIsr(); chSysUnlockFromISR();
} }
/* Physical transmission end.*/ /* Physical transmission end.*/
if (isr & USART_ISR_TC) { if (isr & USART_ISR_TC) {
chSysLockFromIsr(); chSysLockFromISR();
chnAddFlagsI(sdp, CHN_TRANSMISSION_END); chnAddFlagsI(sdp, CHN_TRANSMISSION_END);
chSysUnlockFromIsr(); chSysUnlockFromISR();
u->CR1 = cr1 & ~USART_CR1_TCIE; u->CR1 = cr1 & ~USART_CR1_TCIE;
} }
} }

View File

@ -109,6 +109,8 @@ extern "C" {
void chSysInit(void); void chSysInit(void);
void chSysHalt(void); void chSysHalt(void);
void chSysTimerHandlerI(void); void chSysTimerHandlerI(void);
syssts_t chSysGetAndLockX(void);
void chSysRestoreLockX(syssts_t sts);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@ -214,7 +216,7 @@ static inline void chSysUnlock(void) {
* *
* @special * @special
*/ */
static inline void chSysLockFromIsr(void) { static inline void chSysLockFromISR(void) {
port_lock_from_isr(); port_lock_from_isr();
dbg_check_lock_from_isr(); dbg_check_lock_from_isr();
@ -233,7 +235,7 @@ static inline void chSysLockFromIsr(void) {
* *
* @special * @special
*/ */
static inline void chSysUnlockFromIsr(void) { static inline void chSysUnlockFromISR(void) {
dbg_check_unlock_from_isr(); dbg_check_unlock_from_isr();
port_unlock_from_isr(); port_unlock_from_isr();

View File

@ -37,31 +37,31 @@
* @name Thread states * @name Thread states
* @{ * @{
*/ */
#define THD_STATE_READY 0 /**< @brief Waiting on the ready list. */ #define CH_STATE_READY 0 /**< @brief Waiting on the ready list. */
#define THD_STATE_CURRENT 1 /**< @brief Currently running. */ #define CH_STATE_CURRENT 1 /**< @brief Currently running. */
#define THD_STATE_SUSPENDED 2 /**< @brief Created in suspended state. */ #define CH_STATE_SUSPENDED 2 /**< @brief Created in suspended state. */
#define THD_STATE_WTSEM 3 /**< @brief Waiting on a semaphore. */ #define CH_STATE_WTSEM 3 /**< @brief Waiting on a semaphore. */
#define THD_STATE_WTMTX 4 /**< @brief Waiting on a mutex. */ #define CH_STATE_WTMTX 4 /**< @brief Waiting on a mutex. */
#define THD_STATE_WTCOND 5 /**< @brief Waiting on a condition #define CH_STATE_WTCOND 5 /**< @brief Waiting on a condition
variable. */ variable. */
#define THD_STATE_SLEEPING 6 /**< @brief Waiting in @p chThdSleep() #define CH_STATE_SLEEPING 6 /**< @brief Waiting in @p chThdSleep()
or @p chThdSleepUntil(). */ or @p chThdSleepUntil(). */
#define THD_STATE_WTEXIT 7 /**< @brief Waiting in @p chThdWait(). */ #define CH_STATE_WTEXIT 7 /**< @brief Waiting in @p chThdWait(). */
#define THD_STATE_WTOREVT 8 /**< @brief Waiting for an event. */ #define CH_STATE_WTOREVT 8 /**< @brief Waiting for an event. */
#define THD_STATE_WTANDEVT 9 /**< @brief Waiting for several events. */ #define CH_STATE_WTANDEVT 9 /**< @brief Waiting for several events. */
#define THD_STATE_SNDMSGQ 10 /**< @brief Sending a message, in queue.*/ #define CH_STATE_SNDMSGQ 10 /**< @brief Sending a message, in queue.*/
#define THD_STATE_SNDMSG 11 /**< @brief Sent a message, waiting #define CH_STATE_SNDMSG 11 /**< @brief Sent a message, waiting
answer. */ answer. */
#define THD_STATE_WTMSG 12 /**< @brief Waiting for a message. */ #define CH_STATE_WTMSG 12 /**< @brief Waiting for a message. */
#define THD_STATE_WTQUEUE 13 /**< @brief Waiting on an I/O queue. */ #define CH_STATE_WTQUEUE 13 /**< @brief Waiting on an I/O queue. */
#define THD_STATE_FINAL 14 /**< @brief Thread terminated. */ #define CH_STATE_FINAL 14 /**< @brief Thread terminated. */
/** /**
* @brief Thread states as array of strings. * @brief Thread states as array of strings.
* @details Each element in an array initialized with this macro can be * @details Each element in an array initialized with this macro can be
* indexed using the numeric thread state values. * indexed using the numeric thread state values.
*/ */
#define THD_STATE_NAMES \ #define CH_STATE_NAMES \
"READY", "CURRENT", "SUSPENDED", "WTSEM", "WTMTX", "WTCOND", "SLEEPING", \ "READY", "CURRENT", "SUSPENDED", "WTSEM", "WTMTX", "WTCOND", "SLEEPING", \
"WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", "SNDMSG", "WTMSG", "WTQUEUE", \ "WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", "SNDMSG", "WTMSG", "WTQUEUE", \
"FINAL" "FINAL"
@ -71,13 +71,13 @@
* @name Thread flags and attributes * @name Thread flags and attributes
* @{ * @{
*/ */
#define THD_MEM_MODE_MASK 3 /**< @brief Thread memory mode mask. */ #define CH_FLAG_MODE_MASK 3 /**< @brief Thread memory mode mask. */
#define THD_MEM_MODE_STATIC 0 /**< @brief Static thread. */ #define CH_FLAG_MODE_STATIC 0 /**< @brief Static thread. */
#define THD_MEM_MODE_HEAP 1 /**< @brief Thread allocated from a #define CH_FLAG_MODE_HEAP 1 /**< @brief Thread allocated from a
Memory Heap. */ 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. */ 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. * @brief Enabled events mask.
* @note This field is only valid while the thread is in the * @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; eventmask_t ewmask;
#endif #endif
@ -298,7 +298,7 @@ typedef msg_t (*tfunc_t)(void *);
#define chThdGetTicks(tp) ((tp)->p_time) #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. * @note Can be invoked in any context.
* *
* @param[in] tp pointer to the thread * @param[in] tp pointer to the thread
@ -307,7 +307,7 @@ typedef msg_t (*tfunc_t)(void *);
* *
* @special * @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. * @brief Verifies if the current thread has a termination request pending.
@ -318,7 +318,7 @@ typedef msg_t (*tfunc_t)(void *);
* *
* @special * @special
*/ */
#define chThdShouldTerminate() (currp->p_flags & THD_TERMINATE) #define chThdShouldTerminate() (currp->p_flags & CH_FLAG_TERMINATE)
/** /**
* @brief Resumes a thread created with @p chThdCreateI(). * @brief Resumes a thread created with @p chThdCreateI().
@ -341,7 +341,7 @@ typedef msg_t (*tfunc_t)(void *);
* *
* @sclass * @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. * @brief Delays the invoking thread for the specified number of seconds.

View File

@ -384,9 +384,9 @@ static inline void chVTDoTickI(void) {
vtp->vt_func = (vtfunc_t)NULL; vtp->vt_func = (vtfunc_t)NULL;
vtp->vt_next->vt_prev = (void *)&vtlist; vtp->vt_next->vt_prev = (void *)&vtlist;
vtlist.vt_next = vtp->vt_next; vtlist.vt_next = vtp->vt_next;
chSysUnlockFromIsr(); chSysUnlockFromISR();
fn(vtp->vt_par); fn(vtp->vt_par);
chSysLockFromIsr(); chSysLockFromISR();
} }
} }
#else /* CH_CFG_TIMEDELTA > 0 */ #else /* CH_CFG_TIMEDELTA > 0 */
@ -401,9 +401,9 @@ static inline void chVTDoTickI(void) {
vtp->vt_func = (vtfunc_t)NULL; vtp->vt_func = (vtfunc_t)NULL;
vtp->vt_next->vt_prev = (void *)&vtlist; vtp->vt_next->vt_prev = (void *)&vtlist;
vtlist.vt_next = vtp->vt_next; vtlist.vt_next = vtp->vt_next;
chSysUnlockFromIsr(); chSysUnlockFromISR();
fn(vtp->vt_par); fn(vtp->vt_par);
chSysLockFromIsr(); chSysLockFromISR();
} }
if (&vtlist == (virtual_timers_list_t *)vtlist.vt_next) { if (&vtlist == (virtual_timers_list_t *)vtlist.vt_next) {
/* The list is empty, no tick event needed so the alarm timer /* The list is empty, no tick event needed so the alarm timer

View File

@ -212,7 +212,7 @@ msg_t chCondWaitS(condition_variable_t *cp) {
mp = chMtxUnlockS(); mp = chMtxUnlockS();
ctp->p_u.wtobjp = cp; ctp->p_u.wtobjp = cp;
queue_prio_insert(ctp, &cp->c_queue); queue_prio_insert(ctp, &cp->c_queue);
chSchGoSleepS(THD_STATE_WTCOND); chSchGoSleepS(CH_STATE_WTCOND);
msg = ctp->p_u.rdymsg; msg = ctp->p_u.rdymsg;
chMtxLockS(mp); chMtxLockS(mp);
return msg; return msg;
@ -297,7 +297,7 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) {
mp = chMtxUnlockS(); mp = chMtxUnlockS();
currp->p_u.wtobjp = cp; currp->p_u.wtobjp = cp;
queue_prio_insert(currp, &cp->c_queue); queue_prio_insert(currp, &cp->c_queue);
msg = chSchGoSleepTimeoutS(THD_STATE_WTCOND, time); msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, time);
if (msg != RDY_TIMEOUT) if (msg != RDY_TIMEOUT)
chMtxLockS(mp); chMtxLockS(mp);
return msg; return msg;

View File

@ -78,7 +78,7 @@ thread_t *chThdAddRef(thread_t *tp) {
/** /**
* @brief Releases a reference to a thread object. * @brief Releases a reference to a thread object.
* @details If the references counter reaches zero <b>and</b> the thread * @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. * returned to the proper allocator.
* @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in order * @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in order
* to use this function. * 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 /* If the references counter reaches zero and the thread is in its
terminated state then the memory can be returned to the proper terminated state then the memory can be returned to the proper
allocator. Of course static threads are not affected.*/ allocator. Of course static threads are not affected.*/
if ((refs == 0) && (tp->p_state == THD_STATE_FINAL)) { if ((refs == 0) && (tp->p_state == CH_STATE_FINAL)) {
switch (tp->p_flags & THD_MEM_MODE_MASK) { switch (tp->p_flags & CH_FLAG_MODE_MASK) {
#if CH_CFG_USE_HEAP #if CH_CFG_USE_HEAP
case THD_MEM_MODE_HEAP: case CH_FLAG_MODE_HEAP:
#if CH_CFG_USE_REGISTRY #if CH_CFG_USE_REGISTRY
REG_REMOVE(tp); REG_REMOVE(tp);
#endif #endif
@ -110,7 +110,7 @@ void chThdRelease(thread_t *tp) {
break; break;
#endif #endif
#if CH_CFG_USE_MEMPOOLS #if CH_CFG_USE_MEMPOOLS
case THD_MEM_MODE_MEMPOOL: case CH_FLAG_MODE_MEMPOOL:
#if CH_CFG_USE_REGISTRY #if CH_CFG_USE_REGISTRY
REG_REMOVE(tp); REG_REMOVE(tp);
#endif #endif
@ -164,7 +164,7 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size,
chSysLock(); chSysLock();
tp = chThdCreateI(wsp, size, prio, pf, arg); 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); chSchWakeupS(tp, RDY_OK);
chSysUnlock(); chSysUnlock();
return tp; return tp;
@ -215,7 +215,7 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio,
chSysLock(); chSysLock();
tp = chThdCreateI(wsp, mp->mp_object_size, prio, pf, arg); 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; tp->p_mpool = mp;
chSchWakeupS(tp, RDY_OK); chSchWakeupS(tp, RDY_OK);
chSysUnlock(); chSysUnlock();

View File

@ -275,9 +275,9 @@ void chEvtSignalI(thread_t *tp, eventmask_t mask) {
tp->p_epending |= mask; tp->p_epending |= mask;
/* Test on the AND/OR conditions wait states.*/ /* 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_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))) ((tp->p_epending & tp->p_u.ewmask) == tp->p_u.ewmask)))
chSchReadyI(tp)->p_u.rdymsg = RDY_OK; chSchReadyI(tp)->p_u.rdymsg = RDY_OK;
} }
@ -375,7 +375,7 @@ eventmask_t chEvtWaitOne(eventmask_t mask) {
if ((m = (ctp->p_epending & mask)) == 0) { if ((m = (ctp->p_epending & mask)) == 0) {
ctp->p_u.ewmask = mask; ctp->p_u.ewmask = mask;
chSchGoSleepS(THD_STATE_WTOREVT); chSchGoSleepS(CH_STATE_WTOREVT);
m = ctp->p_epending & mask; m = ctp->p_epending & mask;
} }
m &= -m; m &= -m;
@ -404,7 +404,7 @@ eventmask_t chEvtWaitAny(eventmask_t mask) {
if ((m = (ctp->p_epending & mask)) == 0) { if ((m = (ctp->p_epending & mask)) == 0) {
ctp->p_u.ewmask = mask; ctp->p_u.ewmask = mask;
chSchGoSleepS(THD_STATE_WTOREVT); chSchGoSleepS(CH_STATE_WTOREVT);
m = ctp->p_epending & mask; m = ctp->p_epending & mask;
} }
ctp->p_epending &= ~m; ctp->p_epending &= ~m;
@ -431,7 +431,7 @@ eventmask_t chEvtWaitAll(eventmask_t mask) {
if ((ctp->p_epending & mask) != mask) { if ((ctp->p_epending & mask) != mask) {
ctp->p_u.ewmask = mask; ctp->p_u.ewmask = mask;
chSchGoSleepS(THD_STATE_WTANDEVT); chSchGoSleepS(CH_STATE_WTANDEVT);
} }
ctp->p_epending &= ~mask; ctp->p_epending &= ~mask;
@ -475,7 +475,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time) {
return (eventmask_t)0; return (eventmask_t)0;
} }
ctp->p_u.ewmask = mask; ctp->p_u.ewmask = mask;
if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) { if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < RDY_OK) {
chSysUnlock(); chSysUnlock();
return (eventmask_t)0; return (eventmask_t)0;
} }
@ -518,7 +518,7 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time) {
return (eventmask_t)0; return (eventmask_t)0;
} }
ctp->p_u.ewmask = mask; ctp->p_u.ewmask = mask;
if (chSchGoSleepTimeoutS(THD_STATE_WTOREVT, time) < RDY_OK) { if (chSchGoSleepTimeoutS(CH_STATE_WTOREVT, time) < RDY_OK) {
chSysUnlock(); chSysUnlock();
return (eventmask_t)0; return (eventmask_t)0;
} }
@ -558,7 +558,7 @@ eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time) {
return (eventmask_t)0; return (eventmask_t)0;
} }
ctp->p_u.ewmask = mask; ctp->p_u.ewmask = mask;
if (chSchGoSleepTimeoutS(THD_STATE_WTANDEVT, time) < RDY_OK) { if (chSchGoSleepTimeoutS(CH_STATE_WTANDEVT, time) < RDY_OK) {
chSysUnlock(); chSysUnlock();
return (eventmask_t)0; return (eventmask_t)0;
} }

View File

@ -94,9 +94,9 @@ msg_t chMsgSend(thread_t *tp, msg_t msg) {
ctp->p_msg = msg; ctp->p_msg = msg;
ctp->p_u.wtobjp = &tp->p_msgqueue; ctp->p_u.wtobjp = &tp->p_msgqueue;
msg_insert(ctp, &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); chSchReadyI(tp);
chSchGoSleepS(THD_STATE_SNDMSGQ); chSchGoSleepS(CH_STATE_SNDMSGQ);
msg = ctp->p_u.rdymsg; msg = ctp->p_u.rdymsg;
chSysUnlock(); chSysUnlock();
return msg; return msg;
@ -121,9 +121,9 @@ thread_t *chMsgWait(void) {
chSysLock(); chSysLock();
if (!chMsgIsPendingI(currp)) if (!chMsgIsPendingI(currp))
chSchGoSleepS(THD_STATE_WTMSG); chSchGoSleepS(CH_STATE_WTMSG);
tp = queue_fifo_remove(&currp->p_msgqueue); tp = queue_fifo_remove(&currp->p_msgqueue);
tp->p_state = THD_STATE_SNDMSG; tp->p_state = CH_STATE_SNDMSG;
chSysUnlock(); chSysUnlock();
return tp; return tp;
} }
@ -141,7 +141,7 @@ thread_t *chMsgWait(void) {
void chMsgRelease(thread_t *tp, msg_t msg) { void chMsgRelease(thread_t *tp, msg_t msg) {
chSysLock(); chSysLock();
chDbgAssert(tp->p_state == THD_STATE_SNDMSG, chDbgAssert(tp->p_state == CH_STATE_SNDMSG,
"chMsgRelease(), #1", "invalid state"); "chMsgRelease(), #1", "invalid state");
chMsgReleaseS(tp, msg); chMsgReleaseS(tp, msg);
chSysUnlock(); chSysUnlock();

View File

@ -152,7 +152,7 @@ void chMtxLockS(mutex_t *mp) {
/* The following states need priority queues reordering.*/ /* The following states need priority queues reordering.*/
switch (tp->p_state) { switch (tp->p_state) {
case THD_STATE_WTMTX: case CH_STATE_WTMTX:
/* Re-enqueues the mutex owner with its new priority.*/ /* Re-enqueues the mutex owner with its new priority.*/
queue_prio_insert(queue_dequeue(tp), queue_prio_insert(queue_dequeue(tp),
(threads_queue_t *)tp->p_u.wtobjp); (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_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY) | \
(CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY) (CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY)
#if CH_CFG_USE_CONDVARS #if CH_CFG_USE_CONDVARS
case THD_STATE_WTCOND: case CH_STATE_WTCOND:
#endif #endif
#if CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY #if CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY
case THD_STATE_WTSEM: case CH_STATE_WTSEM:
#endif #endif
#if CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY #if CH_CFG_USE_MESSAGES && CH_CFG_USE_MESSAGES_PRIORITY
case THD_STATE_SNDMSGQ: case CH_STATE_SNDMSGQ:
#endif #endif
/* Re-enqueues tp with its new priority on the queue.*/ /* Re-enqueues tp with its new priority on the queue.*/
queue_prio_insert(queue_dequeue(tp), queue_prio_insert(queue_dequeue(tp),
(threads_queue_t *)tp->p_u.wtobjp); (threads_queue_t *)tp->p_u.wtobjp);
break; break;
#endif #endif
case THD_STATE_READY: case CH_STATE_READY:
#if CH_DBG_ENABLE_ASSERTS #if CH_DBG_ENABLE_ASSERTS
/* Prevents an assertion in chSchReadyI().*/ /* Prevents an assertion in chSchReadyI().*/
tp->p_state = THD_STATE_CURRENT; tp->p_state = CH_STATE_CURRENT;
#endif #endif
/* Re-enqueues tp with its new priority on the ready list.*/ /* Re-enqueues tp with its new priority on the ready list.*/
chSchReadyI(queue_dequeue(tp)); chSchReadyI(queue_dequeue(tp));
@ -190,7 +190,7 @@ void chMtxLockS(mutex_t *mp) {
/* Sleep on the mutex.*/ /* Sleep on the mutex.*/
queue_prio_insert(ctp, &mp->m_queue); queue_prio_insert(ctp, &mp->m_queue);
ctp->p_u.wtobjp = mp; ctp->p_u.wtobjp = mp;
chSchGoSleepS(THD_STATE_WTMTX); chSchGoSleepS(CH_STATE_WTMTX);
/* It is assumed that the thread performing the unlock operation assigns /* It is assumed that the thread performing the unlock operation assigns
the mutex to this thread.*/ the mutex to this thread.*/

View File

@ -66,7 +66,7 @@ static msg_t qwait(GenericQueue *qp, systime_t time) {
return Q_TIMEOUT; return Q_TIMEOUT;
currp->p_u.wtobjp = qp; currp->p_u.wtobjp = qp;
queue_insert(currp, &qp->q_waiting); 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 * is empty then the calling thread is suspended until a byte arrives
* in the queue or a timeout occurs. * in the queue or a timeout occurs.
* @note The callback is invoked before reading the character from the * @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] iqp pointer to an @p InputQueue structure
* @param[in] time the number of ticks before the operation timeouts, * @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 * @note The function is not atomic, if you need atomicity it is suggested
* to use a semaphore or a mutex for mutual exclusion. * to use a semaphore or a mutex for mutual exclusion.
* @note The callback is invoked before reading each character from the * @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[in] iqp pointer to an @p InputQueue structure
* @param[out] bp pointer to the data buffer * @param[out] bp pointer to the data buffer

View File

@ -94,12 +94,12 @@ thread_t *chSchReadyI(thread_t *tp) {
chDbgCheckClassI(); chDbgCheckClassI();
/* Integrity checks.*/ /* Integrity checks.*/
chDbgAssert((tp->p_state != THD_STATE_READY) && chDbgAssert((tp->p_state != CH_STATE_READY) &&
(tp->p_state != THD_STATE_FINAL), (tp->p_state != CH_STATE_FINAL),
"chSchReadyI(), #1", "chSchReadyI(), #1",
"invalid state"); "invalid state");
tp->p_state = THD_STATE_READY; tp->p_state = CH_STATE_READY;
cp = (thread_t *)&rlist.r_queue; cp = (thread_t *)&rlist.r_queue;
do { do {
cp = cp->p_next; cp = cp->p_next;
@ -132,7 +132,7 @@ void chSchGoSleepS(tstate_t newstate) {
otp->p_preempt = CH_CFG_TIME_QUANTUM; otp->p_preempt = CH_CFG_TIME_QUANTUM;
#endif #endif
setcurrp(queue_fifo_remove(&rlist.r_queue)); setcurrp(queue_fifo_remove(&rlist.r_queue));
currp->p_state = THD_STATE_CURRENT; currp->p_state = CH_STATE_CURRENT;
chSysSwitch(currp, otp); chSysSwitch(currp, otp);
} }
@ -142,25 +142,25 @@ void chSchGoSleepS(tstate_t newstate) {
static void wakeup(void *p) { static void wakeup(void *p) {
thread_t *tp = (thread_t *)p; thread_t *tp = (thread_t *)p;
chSysLockFromIsr(); chSysLockFromISR();
switch (tp->p_state) { switch (tp->p_state) {
case THD_STATE_READY: case CH_STATE_READY:
/* Handling the special case where the thread has been made ready by /* Handling the special case where the thread has been made ready by
another thread with higher priority.*/ another thread with higher priority.*/
chSysUnlockFromIsr(); chSysUnlockFromISR();
return; return;
#if CH_CFG_USE_SEMAPHORES || CH_CFG_USE_QUEUES || \ #if CH_CFG_USE_SEMAPHORES || CH_CFG_USE_QUEUES || \
(CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT) (CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT)
#if CH_CFG_USE_SEMAPHORES #if CH_CFG_USE_SEMAPHORES
case THD_STATE_WTSEM: case CH_STATE_WTSEM:
chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp); chSemFastSignalI((semaphore_t *)tp->p_u.wtobjp);
/* Falls into, intentional. */ /* Falls into, intentional. */
#endif #endif
#if CH_CFG_USE_QUEUES #if CH_CFG_USE_QUEUES
case THD_STATE_WTQUEUE: case CH_STATE_WTQUEUE:
#endif #endif
#if CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT #if CH_CFG_USE_CONDVARS && CH_CFG_USE_CONDVARS_TIMEOUT
case THD_STATE_WTCOND: case CH_STATE_WTCOND:
#endif #endif
/* States requiring dequeuing.*/ /* States requiring dequeuing.*/
queue_dequeue(tp); queue_dequeue(tp);
@ -168,7 +168,7 @@ static void wakeup(void *p) {
} }
tp->p_u.rdymsg = RDY_TIMEOUT; tp->p_u.rdymsg = RDY_TIMEOUT;
chSchReadyI(tp); chSchReadyI(tp);
chSysUnlockFromIsr(); chSysUnlockFromISR();
} }
/** /**
@ -240,7 +240,7 @@ void chSchWakeupS(thread_t *ntp, msg_t msg) {
else { else {
thread_t *otp = chSchReadyI(currp); thread_t *otp = chSchReadyI(currp);
setcurrp(ntp); setcurrp(ntp);
ntp->p_state = THD_STATE_CURRENT; ntp->p_state = CH_STATE_CURRENT;
chSysSwitch(ntp, otp); chSysSwitch(ntp, otp);
} }
} }
@ -305,7 +305,7 @@ void chSchDoRescheduleBehind(void) {
otp = currp; otp = currp;
/* Picks the first thread from the ready queue and makes it current.*/ /* Picks the first thread from the ready queue and makes it current.*/
setcurrp(queue_fifo_remove(&rlist.r_queue)); 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 #if CH_CFG_TIME_QUANTUM > 0
otp->p_preempt = CH_CFG_TIME_QUANTUM; otp->p_preempt = CH_CFG_TIME_QUANTUM;
#endif #endif
@ -328,9 +328,9 @@ void chSchDoRescheduleAhead(void) {
otp = currp; otp = currp;
/* Picks the first thread from the ready queue and makes it current.*/ /* Picks the first thread from the ready queue and makes it current.*/
setcurrp(queue_fifo_remove(&rlist.r_queue)); 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; cp = (thread_t *)&rlist.r_queue;
do { do {
cp = cp->p_next; cp = cp->p_next;

View File

@ -207,7 +207,7 @@ msg_t chSemWaitS(semaphore_t *sp) {
if (--sp->s_cnt < 0) { if (--sp->s_cnt < 0) {
currp->p_u.wtobjp = sp; currp->p_u.wtobjp = sp;
sem_insert(currp, &sp->s_queue); sem_insert(currp, &sp->s_queue);
chSchGoSleepS(THD_STATE_WTSEM); chSchGoSleepS(CH_STATE_WTSEM);
return currp->p_u.rdymsg; return currp->p_u.rdymsg;
} }
return RDY_OK; return RDY_OK;
@ -276,7 +276,7 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) {
} }
currp->p_u.wtobjp = sp; currp->p_u.wtobjp = sp;
sem_insert(currp, &sp->s_queue); sem_insert(currp, &sp->s_queue);
return chSchGoSleepTimeoutS(THD_STATE_WTSEM, time); return chSchGoSleepTimeoutS(CH_STATE_WTSEM, time);
} }
return RDY_OK; return RDY_OK;
} }
@ -393,7 +393,7 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) {
thread_t *ctp = currp; thread_t *ctp = currp;
sem_insert(ctp, &spw->s_queue); sem_insert(ctp, &spw->s_queue);
ctp->p_u.wtobjp = spw; ctp->p_u.wtobjp = spw;
chSchGoSleepS(THD_STATE_WTSEM); chSchGoSleepS(CH_STATE_WTSEM);
msg = ctp->p_u.rdymsg; msg = ctp->p_u.rdymsg;
} }
else { else {

View File

@ -117,7 +117,7 @@ void chSysInit(void) {
/* Now this instructions flow becomes the main thread.*/ /* Now this instructions flow becomes the main thread.*/
setcurrp(_thread_init(&mainthread, NORMALPRIO)); setcurrp(_thread_init(&mainthread, NORMALPRIO));
currp->p_state = THD_STATE_CURRENT; currp->p_state = CH_STATE_CURRENT;
#if CH_DBG_ENABLE_STACK_CHECK #if CH_DBG_ENABLE_STACK_CHECK
/* This is a special case because the main thread thread_t structure is not /* This is a special case because the main thread thread_t structure is not
adjacent to its stack area.*/ adjacent to its stack area.*/
@ -191,4 +191,47 @@ void chSysTimerHandlerI(void) {
#endif #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();
}
}
/** @} */ /** @} */

View File

@ -93,8 +93,8 @@
thread_t *_thread_init(thread_t *tp, tprio_t prio) { thread_t *_thread_init(thread_t *tp, tprio_t prio) {
tp->p_prio = prio; tp->p_prio = prio;
tp->p_state = THD_STATE_SUSPENDED; tp->p_state = CH_STATE_SUSPENDED;
tp->p_flags = THD_MEM_MODE_STATIC; tp->p_flags = CH_FLAG_MODE_STATIC;
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
tp->p_preempt = CH_CFG_TIME_QUANTUM; tp->p_preempt = CH_CFG_TIME_QUANTUM;
#endif #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. * @brief Creates a new thread into a static memory area.
* @details The new thread is initialized but not inserted in the ready list, * @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 * @post The initialized thread can be subsequently started by invoking
* @p chThdResume(), @p chThdResumeI() or @p chSchWakeupS() * @p chThdResume(), @p chThdResumeI() or @p chSchWakeupS()
* depending on the execution context. * depending on the execution context.
@ -255,7 +255,7 @@ tprio_t chThdSetPriority(tprio_t newprio) {
/** /**
* @brief Resumes a suspended thread. * @brief Resumes a suspended thread.
* @pre The specified thread pointer must refer to an initialized 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 * @post The specified thread is immediately started or put in the ready
* list depending on the relative priority levels. * list depending on the relative priority levels.
* @note Use this function to start threads created with @p chThdCreateI(). * @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) { thread_t *chThdResume(thread_t *tp) {
chSysLock(); chSysLock();
chDbgAssert(tp->p_state == THD_STATE_SUSPENDED, chDbgAssert(tp->p_state == CH_STATE_SUSPENDED,
"chThdResume(), #1", "chThdResume(), #1",
"thread not in THD_STATE_SUSPENDED state"); "thread not in CH_STATE_SUSPENDED state");
chSchWakeupS(tp, RDY_OK); chSchWakeupS(tp, RDY_OK);
chSysUnlock(); chSysUnlock();
return tp; return tp;
@ -291,7 +291,7 @@ thread_t *chThdResume(thread_t *tp) {
void chThdTerminate(thread_t *tp) { void chThdTerminate(thread_t *tp) {
chSysLock(); chSysLock();
tp->p_flags |= THD_TERMINATE; tp->p_flags |= CH_FLAG_TERMINATE;
chSysUnlock(); chSysUnlock();
} }
@ -348,7 +348,7 @@ void chThdYield(void) {
/** /**
* @brief Terminates the current thread. * @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 * specified exit status code, other threads can retrieve the
* exit status code by invoking the function @p chThdWait(). * exit status code by invoking the function @p chThdWait().
* @post Eventual code after this function will never be executed, * @post Eventual code after this function will never be executed,
@ -369,7 +369,7 @@ void chThdExit(msg_t msg) {
/** /**
* @brief Terminates the current thread. * @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 * specified exit status code, other threads can retrieve the
* exit status code by invoking the function @p chThdWait(). * exit status code by invoking the function @p chThdWait().
* @post Eventual code after this function will never be executed, * @post Eventual code after this function will never be executed,
@ -395,10 +395,10 @@ void chThdExitS(msg_t msg) {
#if CH_CFG_USE_REGISTRY #if CH_CFG_USE_REGISTRY
/* Static threads are immediately removed from the registry because /* Static threads are immediately removed from the registry because
there is no memory to recover.*/ 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); REG_REMOVE(tp);
#endif #endif
chSchGoSleepS(THD_STATE_FINAL); chSchGoSleepS(CH_STATE_FINAL);
/* The thread never returns here.*/ /* The thread never returns here.*/
chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse");
} }
@ -445,9 +445,9 @@ msg_t chThdWait(thread_t *tp) {
#if CH_CFG_USE_DYNAMIC #if CH_CFG_USE_DYNAMIC
chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced"); chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced");
#endif #endif
if (tp->p_state != THD_STATE_FINAL) { if (tp->p_state != CH_STATE_FINAL) {
list_insert(currp, &tp->p_waiting); list_insert(currp, &tp->p_waiting);
chSchGoSleepS(THD_STATE_WTEXIT); chSchGoSleepS(CH_STATE_WTEXIT);
} }
msg = tp->p_u.exitcode; msg = tp->p_u.exitcode;
chSysUnlock(); chSysUnlock();

View File

@ -59,9 +59,9 @@ CH_IRQ_HANDLER(VectorB0) {
STM32F3_TIM2->SR = 0; STM32F3_TIM2->SR = 0;
chSysLockFromIsr(); chSysLockFromISR();
chSysTimerHandlerI(); chSysTimerHandlerI();
chSysUnlockFromIsr(); chSysUnlockFromISR();
CH_IRQ_EPILOGUE(); CH_IRQ_EPILOGUE();
} }

View File

@ -34,6 +34,7 @@
#include <stdbool.h> #include <stdbool.h>
typedef bool bool_t; /**< Fast boolean type. */ 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 tmode_t; /**< Thread flags. */
typedef uint8_t tstate_t; /**< Thread state. */ typedef uint8_t tstate_t; /**< Thread state. */
typedef uint8_t trefs_t; /**< Thread references counter. */ typedef uint8_t trefs_t; /**< Thread references counter. */
@ -46,35 +47,12 @@ typedef uint32_t eventflags_t; /**< Mask of event flags. */
typedef uint32_t systime_t; /**< System time. */ typedef uint32_t systime_t; /**< System time. */
typedef int32_t cnt_t; /**< Resources counter. */ typedef int32_t cnt_t; /**< Resources counter. */
/**
* @brief Inline function modifier.
*/
#define INLINE inline
/** /**
* @brief ROM constant modifier. * @brief ROM constant modifier.
* @note It is set to use the "const" keyword in this port. * @note It is set to use the "const" keyword in this port.
*/ */
#define ROMCONST const #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_ */ #endif /* _CHTYPES_H_ */
/** @} */ /** @} */

View File

@ -207,7 +207,7 @@ msg_t thread4(void *p) {
(void)p; (void)p;
chSysLock(); chSysLock();
do { do {
chSchGoSleepS(THD_STATE_SUSPENDED); chSchGoSleepS(CH_STATE_SUSPENDED);
msg = self->p_u.rdymsg; msg = self->p_u.rdymsg;
} while (msg == RDY_OK); } while (msg == RDY_OK);
chSysUnlock(); chSysUnlock();

View File

@ -224,11 +224,11 @@ static void dyn3_execute(void) {
/* Detach and let the thread execute and terminate.*/ /* Detach and let the thread execute and terminate.*/
chThdRelease(tp); chThdRelease(tp);
test_assert(6, tp->p_refs == 0, "detach failure"); 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(8, regfind(tp), "thread disappeared");
test_assert(9, regfind(tp), "thread disappeared"); test_assert(9, regfind(tp), "thread disappeared");
chThdSleepMilliseconds(50); /* The thread just terminates. */ 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.*/ /* Clearing the zombie by scanning the registry.*/
test_assert(11, regfind(tp), "thread disappeared"); test_assert(11, regfind(tp), "thread disappeared");