Added strong type checks to the code rules.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7746 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2015-03-10 10:24:19 +00:00
parent e801a6adb4
commit 014976ee10
17 changed files with 138 additions and 115 deletions

View File

@ -267,7 +267,7 @@ static inline void chBSemSignalI(binary_semaphore_t *bsp) {
chDbgCheckClassI(); chDbgCheckClassI();
if (bsp->bs_sem.s_cnt < 1) { if (bsp->bs_sem.s_cnt < (cnt_t)1) {
chSemSignalI(&bsp->bs_sem); chSemSignalI(&bsp->bs_sem);
} }
} }
@ -301,7 +301,7 @@ static inline bool chBSemGetStateI(binary_semaphore_t *bsp) {
chDbgCheckClassI(); chDbgCheckClassI();
return (bsp->bs_sem.s_cnt > 0) ? false : true; return (bsp->bs_sem.s_cnt > (cnt_t)0) ? false : true;
} }
#endif /* CH_CFG_USE_SEMAPHORES == TRUE */ #endif /* CH_CFG_USE_SEMAPHORES == TRUE */

View File

@ -188,7 +188,7 @@ static inline void chEvtObjectInit(event_source_t *esp) {
*/ */
static inline void chEvtRegisterMask(event_source_t *esp, static inline void chEvtRegisterMask(event_source_t *esp,
event_listener_t *elp, event_listener_t *elp,
eventflags_t events) { eventmask_t events) {
chEvtRegisterMaskWithFlags(esp, elp, events, (eventflags_t)-1); chEvtRegisterMaskWithFlags(esp, elp, events, (eventflags_t)-1);
} }
@ -236,7 +236,7 @@ static inline bool chEvtIsListeningI(event_source_t *esp) {
*/ */
static inline void chEvtBroadcast(event_source_t *esp) { static inline void chEvtBroadcast(event_source_t *esp) {
chEvtBroadcastFlags(esp, 0); chEvtBroadcastFlags(esp, (eventflags_t)0);
} }
/** /**
@ -253,7 +253,7 @@ static inline void chEvtBroadcast(event_source_t *esp) {
*/ */
static inline void chEvtBroadcastI(event_source_t *esp) { static inline void chEvtBroadcastI(event_source_t *esp) {
chEvtBroadcastFlagsI(esp, 0); chEvtBroadcastFlagsI(esp, (eventflags_t)0);
} }
#endif /* CH_CFG_USE_EVENTS == TRUE */ #endif /* CH_CFG_USE_EVENTS == TRUE */

View File

@ -41,8 +41,8 @@
#define Q_OK MSG_OK /**< @brief Operation successful. */ #define Q_OK MSG_OK /**< @brief Operation successful. */
#define Q_TIMEOUT MSG_TIMEOUT /**< @brief Timeout condition. */ #define Q_TIMEOUT MSG_TIMEOUT /**< @brief Timeout condition. */
#define Q_RESET MSG_RESET /**< @brief Queue has been reset. */ #define Q_RESET MSG_RESET /**< @brief Queue has been reset. */
#define Q_EMPTY -3 /**< @brief Queue empty. */ #define Q_EMPTY (msg_t)-3 /**< @brief Queue empty. */
#define Q_FULL -4 /**< @brief Queue full, */ #define Q_FULL (msg_t)-4 /**< @brief Queue full, */
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -36,48 +36,50 @@
* @name Wakeup status codes * @name Wakeup status codes
* @{ * @{
*/ */
#define MSG_OK 0 /**< @brief Normal wakeup message. */ #define MSG_OK (msg_t)0 /**< @brief Normal wakeup message. */
#define MSG_TIMEOUT -1 /**< @brief Wakeup caused by a timeout #define MSG_TIMEOUT (msg_t)-1 /**< @brief Wakeup caused by a timeout
condition. */ condition. */
#define MSG_RESET -2 /**< @brief Wakeup caused by a reset #define MSG_RESET (msg_t)-2 /**< @brief Wakeup caused by a reset
condition. */ condition. */
/** @} */ /** @} */
/** /**
* @name Priority constants * @name Priority constants
* @{ * @{
*/ */
#define NOPRIO 0U /**< @brief Ready list header priority. */ #define NOPRIO (tprio_t)0 /**< @brief Ready list header
#define IDLEPRIO 1U /**< @brief Idle thread priority. */ priority. */
#define LOWPRIO 2U /**< @brief Lowest user priority. */ #define IDLEPRIO (tprio_t)1 /**< @brief Idle priority. */
#define NORMALPRIO 64U /**< @brief Normal user priority. */ #define LOWPRIO (tprio_t)2 /**< @brief Lowest priority. */
#define HIGHPRIO 127U /**< @brief Highest user priority. */ #define NORMALPRIO (tprio_t)64 /**< @brief Normal priority. */
#define ABSPRIO 255U /**< @brief Greatest possible priority. */ #define HIGHPRIO (tprio_t)127 /**< @brief Highest priority. */
#define ABSPRIO (tprio_t)255 /**< @brief Greatest priority. */
/** @} */ /** @} */
/** /**
* @name Thread states * @name Thread states
* @{ * @{
*/ */
#define CH_STATE_READY 0U /**< @brief Waiting on the ready list. */ #define CH_STATE_READY (tstate_t)0 /**< @brief Waiting on the
#define CH_STATE_CURRENT 1U /**< @brief Currently running. */ ready list. */
#define CH_STATE_WTSTART 2U /**< @brief Created but not started. */ #define CH_STATE_CURRENT (tstate_t)1 /**< @brief Currently running. */
#define CH_STATE_SUSPENDED 3U /**< @brief Suspended state. */ #define CH_STATE_WTSTART (tstate_t)2 /**< @brief Just created. */
#define CH_STATE_QUEUED 4U /**< @brief Waiting on an I/O queue. */ #define CH_STATE_SUSPENDED (tstate_t)3 /**< @brief Suspended state. */
#define CH_STATE_WTSEM 5U /**< @brief Waiting on a semaphore. */ #define CH_STATE_QUEUED (tstate_t)4 /**< @brief On an I/O queue. */
#define CH_STATE_WTMTX 6U /**< @brief Waiting on a mutex. */ #define CH_STATE_WTSEM (tstate_t)5 /**< @brief On a semaphore. */
#define CH_STATE_WTCOND 7U /**< @brief Waiting on a condition #define CH_STATE_WTMTX (tstate_t)6 /**< @brief On a mutex. */
variable. */ #define CH_STATE_WTCOND (tstate_t)7 /**< @brief On a cond.variable.*/
#define CH_STATE_SLEEPING 8U /**< @brief Waiting in @p chThdSleep() #define CH_STATE_SLEEPING (tstate_t)8 /**< @brief Sleeping. */
or @p chThdSleepUntil(). */ #define CH_STATE_WTEXIT (tstate_t)9 /**< @brief Waiting a thread. */
#define CH_STATE_WTEXIT 9U /**< @brief Waiting in @p chThdWait(). */ #define CH_STATE_WTOREVT (tstate_t)10 /**< @brief One event. */
#define CH_STATE_WTOREVT 10U /**< @brief Waiting for an event. */ #define CH_STATE_WTANDEVT (tstate_t)11 /**< @brief Several events. */
#define CH_STATE_WTANDEVT 11U /**< @brief Waiting for several events. */ #define CH_STATE_SNDMSGQ (tstate_t)12 /**< @brief Sending a message,
#define CH_STATE_SNDMSGQ 12U /**< @brief Sending a message, in queue.*/ in queue. */
#define CH_STATE_SNDMSG 13U /**< @brief Sent a message, waiting #define CH_STATE_SNDMSG (tstate_t)13 /**< @brief Sent a message,
answer. */ waiting answer. */
#define CH_STATE_WTMSG 14U /**< @brief Waiting for a message. */ #define CH_STATE_WTMSG (tstate_t)14 /**< @brief Waiting for a
#define CH_STATE_FINAL 15U /**< @brief Thread terminated. */ message. */
#define CH_STATE_FINAL (tstate_t)15 /**< @brief Thread terminated. */
/** /**
* @brief Thread states as array of strings. * @brief Thread states as array of strings.
@ -94,13 +96,15 @@
* @name Thread flags and attributes * @name Thread flags and attributes
* @{ * @{
*/ */
#define CH_FLAG_MODE_MASK 3U /**< @brief Thread memory mode mask. */ #define CH_FLAG_MODE_MASK (tmode_t)3U /**< @brief Thread memory mode
#define CH_FLAG_MODE_STATIC 0U /**< @brief Static thread. */ mask. */
#define CH_FLAG_MODE_HEAP 1U /**< @brief Thread allocated from a #define CH_FLAG_MODE_STATIC (tmode_t)0U /**< @brief Static thread. */
Memory Heap. */ #define CH_FLAG_MODE_HEAP (tmode_t)1U /**< @brief Thread allocated
#define CH_FLAG_MODE_MEMPOOL 2U /**< @brief Thread allocated from a from a Memory Heap. */
Memory Pool. */ #define CH_FLAG_MODE_MPOOL (tmode_t)2U /**< @brief Thread allocated
#define CH_FLAG_TERMINATE 4U /**< @brief Termination requested flag. */ from a Memory Pool. */
#define CH_FLAG_TERMINATE (tmode_t)4U /**< @brief Termination requested
flag. */
/** @} */ /** @} */
/** /**
@ -755,7 +759,7 @@ static inline void chSchPreemption(void) {
tprio_t p2 = currp->p_prio; tprio_t p2 = currp->p_prio;
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
if (currp->p_preempt > 0U) { if (currp->p_preempt > (tslices_t)0) {
if (p1 > p2) { if (p1 > p2) {
chSchDoRescheduleAhead(); chSchDoRescheduleAhead();
} }

View File

@ -230,7 +230,7 @@ static inline bool chThdTerminatedX(thread_t *tp) {
*/ */
static inline bool chThdShouldTerminateX(void) { static inline bool chThdShouldTerminateX(void) {
return (bool)((chThdGetSelfX()->p_flags & CH_FLAG_TERMINATE) != 0U); return (bool)((chThdGetSelfX()->p_flags & CH_FLAG_TERMINATE) != (tmode_t)0);
} }
/** /**

View File

@ -451,7 +451,7 @@ static inline void chVTDoTickI(void) {
virtual_timer_t *vtp; virtual_timer_t *vtp;
--ch.vtlist.vt_next->vt_delta; --ch.vtlist.vt_next->vt_delta;
while (ch.vtlist.vt_next->vt_delta == 0U) { while (ch.vtlist.vt_next->vt_delta == (systime_t)0) {
vtfunc_t fn; vtfunc_t fn;
vtp = ch.vtlist.vt_next; vtp = ch.vtlist.vt_next;

View File

@ -276,7 +276,7 @@ static inline syssts_t port_get_irq_status(void) {
*/ */
static inline bool port_irq_enabled(syssts_t sts) { static inline bool port_irq_enabled(syssts_t sts) {
return (sts & 1U) == 0U; return (sts & (syssts_t)1) == (syssts_t)0;
} }
/** /**

View File

@ -68,7 +68,7 @@
thread_t *chThdAddRef(thread_t *tp) { thread_t *chThdAddRef(thread_t *tp) {
chSysLock(); chSysLock();
chDbgAssert(tp->p_refs < 255U, "too many references"); chDbgAssert(tp->p_refs < (trefs_t)255, "too many references");
tp->p_refs++; tp->p_refs++;
chSysUnlock(); chSysUnlock();
@ -92,7 +92,7 @@ void chThdRelease(thread_t *tp) {
trefs_t refs; trefs_t refs;
chSysLock(); chSysLock();
chDbgAssert(tp->p_refs > 0U, "not referenced"); chDbgAssert(tp->p_refs > (trefs_t)0, "not referenced");
tp->p_refs--; tp->p_refs--;
refs = tp->p_refs; refs = tp->p_refs;
chSysUnlock(); chSysUnlock();
@ -100,7 +100,7 @@ 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 == 0U) && (tp->p_state == CH_STATE_FINAL)) { if ((refs == (trefs_t)0) && (tp->p_state == CH_STATE_FINAL)) {
switch (tp->p_flags & CH_FLAG_MODE_MASK) { switch (tp->p_flags & CH_FLAG_MODE_MASK) {
#if CH_CFG_USE_HEAP == TRUE #if CH_CFG_USE_HEAP == TRUE
case CH_FLAG_MODE_HEAP: case CH_FLAG_MODE_HEAP:
@ -111,7 +111,7 @@ void chThdRelease(thread_t *tp) {
break; break;
#endif #endif
#if CH_CFG_USE_MEMPOOLS == TRUE #if CH_CFG_USE_MEMPOOLS == TRUE
case CH_FLAG_MODE_MEMPOOL: case CH_FLAG_MODE_MPOOL:
#if CH_CFG_USE_REGISTRY == TRUE #if CH_CFG_USE_REGISTRY == TRUE
REG_REMOVE(tp); REG_REMOVE(tp);
#endif #endif
@ -224,7 +224,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 = CH_FLAG_MODE_MEMPOOL; tp->p_flags = CH_FLAG_MODE_MPOOL;
tp->p_mpool = mp; tp->p_mpool = mp;
chSchWakeupS(tp, MSG_OK); chSchWakeupS(tp, MSG_OK);
chSysUnlock(); chSysUnlock();

View File

@ -112,7 +112,7 @@ void chEvtRegisterMaskWithFlags(event_source_t *esp,
esp->es_next = elp; esp->es_next = elp;
elp->el_listener = currp; elp->el_listener = currp;
elp->el_events = events; elp->el_events = events;
elp->el_flags = 0; elp->el_flags = (eventflags_t)0;
elp->el_wflags = wflags; elp->el_wflags = wflags;
chSysUnlock(); chSysUnlock();
} }
@ -219,7 +219,8 @@ void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) {
elp->el_flags |= flags; elp->el_flags |= flags;
/* When flags == 0 the thread will always be signaled because the /* When flags == 0 the thread will always be signaled because the
source does not emit any flag.*/ source does not emit any flag.*/
if ((flags == 0U) || ((elp->el_flags & elp->el_wflags) != 0U)) { if ((flags == (eventflags_t)0) ||
((elp->el_flags & elp->el_wflags) != (eventflags_t)0)) {
chEvtSignalI(elp->el_listener, elp->el_events); chEvtSignalI(elp->el_listener, elp->el_events);
} }
elp = elp->el_next; elp = elp->el_next;
@ -242,7 +243,7 @@ eventflags_t chEvtGetAndClearFlags(event_listener_t *elp) {
chSysLock(); chSysLock();
flags = elp->el_flags; flags = elp->el_flags;
elp->el_flags = 0; elp->el_flags = (eventflags_t)0;
chSysUnlock(); chSysUnlock();
return flags; return flags;
@ -286,7 +287,7 @@ void chEvtSignalI(thread_t *tp, eventmask_t events) {
tp->p_epending |= events; tp->p_epending |= events;
/* Test on the AND/OR conditions wait states.*/ /* Test on the AND/OR conditions wait states.*/
if (((tp->p_state == CH_STATE_WTOREVT) && if (((tp->p_state == CH_STATE_WTOREVT) &&
((tp->p_epending & tp->p_u.ewmask) != 0U)) || ((tp->p_epending & tp->p_u.ewmask) != (eventmask_t)0)) ||
((tp->p_state == CH_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))) {
tp->p_u.rdymsg = MSG_OK; tp->p_u.rdymsg = MSG_OK;
@ -330,7 +331,7 @@ eventflags_t chEvtGetAndClearFlagsI(event_listener_t *elp) {
eventflags_t flags; eventflags_t flags;
flags = elp->el_flags; flags = elp->el_flags;
elp->el_flags = 0; elp->el_flags = (eventflags_t)0;
return flags; return flags;
} }
@ -349,9 +350,9 @@ void chEvtDispatch(const evhandler_t *handlers, eventmask_t events) {
chDbgCheck(handlers != NULL); chDbgCheck(handlers != NULL);
eid = 0; eid = (eventid_t)0;
while (events != 0U) { while (events != (eventmask_t)0) {
if ((events & EVENT_MASK(eid)) != 0U) { if ((events & EVENT_MASK(eid)) != (eventmask_t)0) {
chDbgAssert(handlers[eid] != NULL, "null handler"); chDbgAssert(handlers[eid] != NULL, "null handler");
events &= ~EVENT_MASK(eid); events &= ~EVENT_MASK(eid);
handlers[eid](eid); handlers[eid](eid);
@ -385,12 +386,12 @@ eventmask_t chEvtWaitOne(eventmask_t events) {
chSysLock(); chSysLock();
m = ctp->p_epending & events; m = ctp->p_epending & events;
if (m == 0U) { if (m == (eventmask_t)0) {
ctp->p_u.ewmask = events; ctp->p_u.ewmask = events;
chSchGoSleepS(CH_STATE_WTOREVT); chSchGoSleepS(CH_STATE_WTOREVT);
m = ctp->p_epending & events; m = ctp->p_epending & events;
} }
m ^= m & (m - 1U); m ^= m & (m - (eventmask_t)1);
ctp->p_epending &= ~m; ctp->p_epending &= ~m;
chSysUnlock(); chSysUnlock();
@ -415,7 +416,7 @@ eventmask_t chEvtWaitAny(eventmask_t events) {
chSysLock(); chSysLock();
m = ctp->p_epending & events; m = ctp->p_epending & events;
if (m == 0U) { if (m == (eventmask_t)0) {
ctp->p_u.ewmask = events; ctp->p_u.ewmask = events;
chSchGoSleepS(CH_STATE_WTOREVT); chSchGoSleepS(CH_STATE_WTOREVT);
m = ctp->p_epending & events; m = ctp->p_epending & events;
@ -481,7 +482,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) {
chSysLock(); chSysLock();
m = ctp->p_epending & events; m = ctp->p_epending & events;
if (m == 0U) { if (m == (eventmask_t)0) {
if (TIME_IMMEDIATE == time) { if (TIME_IMMEDIATE == time) {
chSysUnlock(); chSysUnlock();
return (eventmask_t)0; return (eventmask_t)0;
@ -493,7 +494,7 @@ eventmask_t chEvtWaitOneTimeout(eventmask_t events, systime_t time) {
} }
m = ctp->p_epending & events; m = ctp->p_epending & events;
} }
m ^= m & (m - 1U); m ^= m & (m - (eventmask_t)1);
ctp->p_epending &= ~m; ctp->p_epending &= ~m;
chSysUnlock(); chSysUnlock();
@ -524,7 +525,7 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t events, systime_t time) {
chSysLock(); chSysLock();
m = ctp->p_epending & events; m = ctp->p_epending & events;
if (m == 0U) { if (m == (eventmask_t)0) {
if (TIME_IMMEDIATE == time) { if (TIME_IMMEDIATE == time) {
chSysUnlock(); chSysUnlock();
return (eventmask_t)0; return (eventmask_t)0;

View File

@ -85,14 +85,14 @@
*/ */
void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) {
chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0)); chDbgCheck((mbp != NULL) && (buf != NULL) && (n > (cnt_t)0));
mbp->mb_buffer = buf; mbp->mb_buffer = buf;
mbp->mb_rdptr = buf; mbp->mb_rdptr = buf;
mbp->mb_wrptr = buf; mbp->mb_wrptr = buf;
mbp->mb_top = &buf[n]; mbp->mb_top = &buf[n];
chSemObjectInit(&mbp->mb_emptysem, n); chSemObjectInit(&mbp->mb_emptysem, n);
chSemObjectInit(&mbp->mb_fullsem, 0); chSemObjectInit(&mbp->mb_fullsem, (cnt_t)0);
} }
/** /**
@ -129,7 +129,7 @@ void chMBResetI(mailbox_t *mbp) {
mbp->mb_wrptr = mbp->mb_buffer; mbp->mb_wrptr = mbp->mb_buffer;
mbp->mb_rdptr = mbp->mb_buffer; mbp->mb_rdptr = mbp->mb_buffer;
chSemResetI(&mbp->mb_emptysem, (cnt_t)(mbp->mb_top - mbp->mb_buffer)); chSemResetI(&mbp->mb_emptysem, (cnt_t)(mbp->mb_top - mbp->mb_buffer));
chSemResetI(&mbp->mb_fullsem, 0); chSemResetI(&mbp->mb_fullsem, (cnt_t)0);
} }
/** /**
@ -218,7 +218,7 @@ msg_t chMBPostI(mailbox_t *mbp, msg_t msg) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck(mbp != NULL); chDbgCheck(mbp != NULL);
if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) { if (chSemGetCounterI(&mbp->mb_emptysem) <= (cnt_t)0) {
return MSG_TIMEOUT; return MSG_TIMEOUT;
} }
@ -318,7 +318,7 @@ msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck(mbp != NULL); chDbgCheck(mbp != NULL);
if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) { if (chSemGetCounterI(&mbp->mb_emptysem) <= (cnt_t)0) {
return MSG_TIMEOUT; return MSG_TIMEOUT;
} }
chSemFastWaitI(&mbp->mb_emptysem); chSemFastWaitI(&mbp->mb_emptysem);
@ -417,7 +417,7 @@ msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck((mbp != NULL) && (msgp != NULL)); chDbgCheck((mbp != NULL) && (msgp != NULL));
if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) { if (chSemGetCounterI(&mbp->mb_fullsem) <= (cnt_t)0) {
return MSG_TIMEOUT; return MSG_TIMEOUT;
} }
chSemFastWaitI(&mbp->mb_fullsem); chSemFastWaitI(&mbp->mb_fullsem);

View File

@ -164,7 +164,7 @@ thread_t *chRegNextThread(thread_t *tp) {
} }
#if CH_CFG_USE_DYNAMIC == TRUE #if CH_CFG_USE_DYNAMIC == TRUE
else { else {
chDbgAssert(ntp->p_refs < 255U, "too many references"); chDbgAssert(ntp->p_refs < (trefs_t)255, "too many references");
ntp->p_refs++; ntp->p_refs++;
} }
#endif #endif

View File

@ -257,7 +257,7 @@ void chSchGoSleepS(tstate_t newstate) {
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
/* The thread is renouncing its remaining time slices so it will have a new /* The thread is renouncing its remaining time slices so it will have a new
time quantum when it will wakeup.*/ time quantum when it will wakeup.*/
otp->p_preempt = CH_CFG_TIME_QUANTUM; otp->p_preempt = (tslices_t)CH_CFG_TIME_QUANTUM;
#endif #endif
setcurrp(queue_fifo_remove(&ch.rlist.r_queue)); setcurrp(queue_fifo_remove(&ch.rlist.r_queue));
#if defined(CH_CFG_IDLE_ENTER_HOOK) #if defined(CH_CFG_IDLE_ENTER_HOOK)
@ -430,7 +430,7 @@ bool chSchIsPreemptionRequired(void) {
if the first thread on the ready queue has a higher priority. if the first thread on the ready queue has a higher priority.
Otherwise, if the running thread has used up its time quantum, reschedule 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.*/ if the first thread on the ready queue has equal or higher priority.*/
return (currp->p_preempt > 0U) ? (p1 > p2) : (p1 >= p2); return (currp->p_preempt > (tslices_t)0) ? (p1 > p2) : (p1 >= p2);
#else #else
/* If the round robin preemption feature is not enabled then performs a /* If the round robin preemption feature is not enabled then performs a
simpler comparison.*/ simpler comparison.*/
@ -461,7 +461,7 @@ void chSchDoRescheduleBehind(void) {
#endif #endif
currp->p_state = CH_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 = (tslices_t)CH_CFG_TIME_QUANTUM;
#endif #endif
(void) chSchReadyI(otp); (void) chSchReadyI(otp);
chSysSwitch(currp, otp); chSysSwitch(currp, otp);
@ -518,7 +518,7 @@ void chSchDoReschedule(void) {
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
/* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios /* If CH_CFG_TIME_QUANTUM is enabled then there are two different scenarios
to handle on preemption: time quantum elapsed or not.*/ to handle on preemption: time quantum elapsed or not.*/
if (currp->p_preempt == 0U) { if (currp->p_preempt == (tslices_t)0) {
/* The thread consumed its time quantum so it is enqueued behind threads /* The thread consumed its time quantum so it is enqueued behind threads
with same priority level, however, it acquires a new time quantum.*/ with same priority level, however, it acquires a new time quantum.*/
chSchDoRescheduleBehind(); chSchDoRescheduleBehind();

View File

@ -96,7 +96,7 @@
*/ */
void chSemObjectInit(semaphore_t *sp, cnt_t n) { void chSemObjectInit(semaphore_t *sp, cnt_t n) {
chDbgCheck((sp != NULL) && (n >= 0)); chDbgCheck((sp != NULL) && (n >= (cnt_t)0));
queue_init(&sp->s_queue); queue_init(&sp->s_queue);
sp->s_cnt = n; sp->s_cnt = n;
@ -148,14 +148,14 @@ void chSemResetI(semaphore_t *sp, cnt_t n) {
cnt_t cnt; cnt_t cnt;
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck((sp != NULL) && (n >= 0)); chDbgCheck((sp != NULL) && (n >= (cnt_t)0));
chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
"inconsistent semaphore"); "inconsistent semaphore");
cnt = sp->s_cnt; cnt = sp->s_cnt;
sp->s_cnt = n; sp->s_cnt = n;
while (++cnt <= 0) { while (++cnt <= (cnt_t)0) {
chSchReadyI(queue_lifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_RESET; chSchReadyI(queue_lifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_RESET;
} }
} }
@ -198,11 +198,11 @@ msg_t chSemWaitS(semaphore_t *sp) {
chDbgCheckClassS(); chDbgCheckClassS();
chDbgCheck(sp != NULL); chDbgCheck(sp != NULL);
chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
"inconsistent semaphore"); "inconsistent semaphore");
if (--sp->s_cnt < 0) { if (--sp->s_cnt < (cnt_t)0) {
currp->p_u.wtsemp = sp; currp->p_u.wtsemp = sp;
sem_insert(currp, &sp->s_queue); sem_insert(currp, &sp->s_queue);
chSchGoSleepS(CH_STATE_WTSEM); chSchGoSleepS(CH_STATE_WTSEM);
@ -265,11 +265,11 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) {
chDbgCheckClassS(); chDbgCheckClassS();
chDbgCheck(sp != NULL); chDbgCheck(sp != NULL);
chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
"inconsistent semaphore"); "inconsistent semaphore");
if (--sp->s_cnt < 0) { if (--sp->s_cnt < (cnt_t)0) {
if (TIME_IMMEDIATE == time) { if (TIME_IMMEDIATE == time) {
sp->s_cnt++; sp->s_cnt++;
@ -294,12 +294,12 @@ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time) {
void chSemSignal(semaphore_t *sp) { void chSemSignal(semaphore_t *sp) {
chDbgCheck(sp != NULL); chDbgCheck(sp != NULL);
chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
"inconsistent semaphore"); "inconsistent semaphore");
chSysLock(); chSysLock();
if (++sp->s_cnt <= 0) { if (++sp->s_cnt <= (cnt_t)0) {
chSchWakeupS(queue_fifo_remove(&sp->s_queue), MSG_OK); chSchWakeupS(queue_fifo_remove(&sp->s_queue), MSG_OK);
} }
chSysUnlock(); chSysUnlock();
@ -320,11 +320,11 @@ void chSemSignalI(semaphore_t *sp) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck(sp != NULL); chDbgCheck(sp != NULL);
chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
"inconsistent semaphore"); "inconsistent semaphore");
if (++sp->s_cnt <= 0) { if (++sp->s_cnt <= (cnt_t)0) {
/* Note, it is done this way in order to allow a tail call on /* Note, it is done this way in order to allow a tail call on
chSchReadyI().*/ chSchReadyI().*/
thread_t *tp = queue_fifo_remove(&sp->s_queue); thread_t *tp = queue_fifo_remove(&sp->s_queue);
@ -349,13 +349,13 @@ void chSemSignalI(semaphore_t *sp) {
void chSemAddCounterI(semaphore_t *sp, cnt_t n) { void chSemAddCounterI(semaphore_t *sp, cnt_t n) {
chDbgCheckClassI(); chDbgCheckClassI();
chDbgCheck((sp != NULL) && (n > 0)); chDbgCheck((sp != NULL) && (n > (cnt_t)0));
chDbgAssert(((sp->s_cnt >= 0) && queue_isempty(&sp->s_queue)) || chDbgAssert(((sp->s_cnt >= (cnt_t)0) && queue_isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && queue_notempty(&sp->s_queue)), ((sp->s_cnt < (cnt_t)0) && queue_notempty(&sp->s_queue)),
"inconsistent semaphore"); "inconsistent semaphore");
while (n > 0) { while (n > (cnt_t)0) {
if (++sp->s_cnt <= 0) { if (++sp->s_cnt <= (cnt_t)0) {
chSchReadyI(queue_fifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_OK; chSchReadyI(queue_fifo_remove(&sp->s_queue))->p_u.rdymsg = MSG_OK;
} }
n--; n--;
@ -379,18 +379,18 @@ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw) {
msg_t msg; msg_t msg;
chDbgCheck((sps != NULL) && (spw != NULL)); chDbgCheck((sps != NULL) && (spw != NULL));
chDbgAssert(((sps->s_cnt >= 0) && queue_isempty(&sps->s_queue)) || chDbgAssert(((sps->s_cnt >= (cnt_t)0) && queue_isempty(&sps->s_queue)) ||
((sps->s_cnt < 0) && queue_notempty(&sps->s_queue)), ((sps->s_cnt < (cnt_t)0) && queue_notempty(&sps->s_queue)),
"inconsistent semaphore"); "inconsistent semaphore");
chDbgAssert(((spw->s_cnt >= 0) && queue_isempty(&spw->s_queue)) || chDbgAssert(((spw->s_cnt >= (cnt_t)0) && queue_isempty(&spw->s_queue)) ||
((spw->s_cnt < 0) && queue_notempty(&spw->s_queue)), ((spw->s_cnt < (cnt_t)0) && queue_notempty(&spw->s_queue)),
"inconsistent semaphore"); "inconsistent semaphore");
chSysLock(); chSysLock();
if (++sps->s_cnt <= 0) { if (++sps->s_cnt <= (cnt_t)0) {
chSchReadyI(queue_fifo_remove(&sps->s_queue))->p_u.rdymsg = MSG_OK; chSchReadyI(queue_fifo_remove(&sps->s_queue))->p_u.rdymsg = MSG_OK;
} }
if (--spw->s_cnt < 0) { if (--spw->s_cnt < (cnt_t)0) {
thread_t *ctp = currp; thread_t *ctp = currp;
sem_insert(ctp, &spw->s_queue); sem_insert(ctp, &spw->s_queue);
ctp->p_u.wtsemp = spw; ctp->p_u.wtsemp = spw;

View File

@ -188,7 +188,7 @@ void chSysTimerHandlerI(void) {
#if CH_CFG_TIME_QUANTUM > 0 #if CH_CFG_TIME_QUANTUM > 0
/* Running thread has not used up quantum yet? */ /* Running thread has not used up quantum yet? */
if (currp->p_preempt > 0U) { if (currp->p_preempt > (tslices_t)0) {
/* Decrement remaining quantum.*/ /* Decrement remaining quantum.*/
currp->p_preempt--; currp->p_preempt--;
} }

View File

@ -94,20 +94,20 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) {
tp->p_state = CH_STATE_WTSTART; tp->p_state = CH_STATE_WTSTART;
tp->p_flags = CH_FLAG_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 = (tslices_t)CH_CFG_TIME_QUANTUM;
#endif #endif
#if CH_CFG_USE_MUTEXES == TRUE #if CH_CFG_USE_MUTEXES == TRUE
tp->p_realprio = prio; tp->p_realprio = prio;
tp->p_mtxlist = NULL; tp->p_mtxlist = NULL;
#endif #endif
#if CH_CFG_USE_EVENTS == TRUE #if CH_CFG_USE_EVENTS == TRUE
tp->p_epending = 0; tp->p_epending = (eventmask_t)0;
#endif #endif
#if CH_DBG_THREADS_PROFILING == TRUE #if CH_DBG_THREADS_PROFILING == TRUE
tp->p_time = 0; tp->p_time = (systime_t)0;
#endif #endif
#if CH_CFG_USE_DYNAMIC == TRUE #if CH_CFG_USE_DYNAMIC == TRUE
tp->p_refs = 1; tp->p_refs = (trefs_t)1;
#endif #endif
#if CH_CFG_USE_REGISTRY == TRUE #if CH_CFG_USE_REGISTRY == TRUE
tp->p_name = NULL; tp->p_name = NULL;
@ -333,7 +333,7 @@ void chThdSleepUntil(systime_t time) {
chSysLock(); chSysLock();
time -= chVTGetSystemTimeX(); time -= chVTGetSystemTimeX();
if (time > 0U) { if (time > (systime_t)0) {
chThdSleepS(time); chThdSleepS(time);
} }
chSysUnlock(); chSysUnlock();
@ -480,7 +480,7 @@ msg_t chThdWait(thread_t *tp) {
chSysLock(); chSysLock();
chDbgAssert(tp != currp, "waiting self"); chDbgAssert(tp != currp, "waiting self");
#if CH_CFG_USE_DYNAMIC == TRUE #if CH_CFG_USE_DYNAMIC == TRUE
chDbgAssert(tp->p_refs > 0U, "not referenced"); chDbgAssert(tp->p_refs > (trefs_t)0, "not referenced");
#endif #endif
if (tp->p_state != CH_STATE_FINAL) { if (tp->p_state != CH_STATE_FINAL) {
list_insert(currp, &tp->p_waiting); list_insert(currp, &tp->p_waiting);

View File

@ -64,9 +64,9 @@ void _vt_init(void) {
ch.vtlist.vt_prev = (virtual_timer_t *)&ch.vtlist; ch.vtlist.vt_prev = (virtual_timer_t *)&ch.vtlist;
ch.vtlist.vt_delta = (systime_t)-1; ch.vtlist.vt_delta = (systime_t)-1;
#if CH_CFG_ST_TIMEDELTA == 0 #if CH_CFG_ST_TIMEDELTA == 0
ch.vtlist.vt_systime = 0; ch.vtlist.vt_systime = (systime_t)0;
#else /* CH_CFG_ST_TIMEDELTA > 0 */ #else /* CH_CFG_ST_TIMEDELTA > 0 */
ch.vtlist.vt_lasttime = 0; ch.vtlist.vt_lasttime = (systime_t)0;
#endif /* CH_CFG_ST_TIMEDELTA > 0 */ #endif /* CH_CFG_ST_TIMEDELTA > 0 */
} }

View File

@ -7,6 +7,24 @@
+libh(stm32f4xx.h) +libh(stm32f4xx.h)
+libh(*_lld.h) +libh(*_lld.h)
/* Reinforcing type checking for some critical types even if not required by
MISRA.*/
-strong(AJX, systime_t)
-strong(AJX, rtcnt_t)
-strong(AJX, rttime_t)
-strong(AJX, syssts_t)
-strong(AJX, msg_t)
-strong(AJX, tmode_t)
-strong(AJX, tstate_t)
-strong(AJX, trefs_t)
-strong(AJX, tslices_t)
-strong(AJX, tprio_t)
-strong(AJX, cnt_t)
-strong(AJX, ucnt_t)
-strong(AJX, eventid_t)
-strong(AJX, eventmask_t)
-strong(AJX, eventflags_t)
/* Permitting anonymous unions.*/ /* Permitting anonymous unions.*/
+fan +fan