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

master
gdisirio 2013-09-03 13:50:15 +00:00
parent 6db8c459a5
commit 1292b0230c
4 changed files with 151 additions and 151 deletions

View File

@ -29,9 +29,9 @@ THD_FUNCTION(Thread1, arg) {
while (true) { while (true) {
// gpioSetPad(GPIOC, GPIOC_LED4); // gpioSetPad(GPIOC, GPIOC_LED4);
nilThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
// gpioClearPad(GPIOC, GPIOC_LED4); // gpioClearPad(GPIOC, GPIOC_LED4);
nilThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
} }
} }
@ -45,9 +45,9 @@ THD_FUNCTION(Thread2, arg) {
while (true) { while (true) {
// gpioSetPad(GPIOC, GPIOC_LED3); // gpioSetPad(GPIOC, GPIOC_LED3);
nilThdSleepMilliseconds(250); chThdSleepMilliseconds(250);
// gpioClearPad(GPIOC, GPIOC_LED3); // gpioClearPad(GPIOC, GPIOC_LED3);
nilThdSleepMilliseconds(250); chThdSleepMilliseconds(250);
} }
} }
@ -71,7 +71,7 @@ int main(void) {
* - Nil RTOS initialization. * - Nil RTOS initialization.
*/ */
// hwInit(); // hwInit();
nilSysInit(); chSysInit();
/* This is now the idle thread loop, you may perform here a low priority /* This is now the idle thread loop, you may perform here a low priority
task but you must never try to sleep or wait in this loop.*/ task but you must never try to sleep or wait in this loop.*/

View File

@ -43,11 +43,11 @@
*/ */
#define _NIL_ /**< @brief Nil RTOS identification.*/ #define _NIL_ /**< @brief Nil RTOS identification.*/
#define NIL_KERNEL_VERSION "0.1.0alpha" #define CH_KERNEL_VERSION "0.1.0alpha"
#define NIL_KERNEL_MAJOR 0 #define CH_KERNEL_MAJOR 0
#define NIL_KERNEL_MINOR 1 #define CH_KERNEL_MINOR 1
#define NIL_KERNEL_PATCH 0 #define CH_KERNEL_PATCH 0
/** @} */ /** @} */
/** /**
@ -84,14 +84,14 @@
* @name Thread state related macros * @name Thread state related macros
* @{ * @{
*/ */
#define NIL_THD_READY 0 /**< @brief Thread ready or executing. */ #define NIL_STATE_READY 0 /**< @brief Thread ready or executing. */
#define NIL_THD_SLEEPING 1 /**< @brief Thread sleeping. */ #define NIL_STATE_SLEEPING 1 /**< @brief Thread sleeping. */
#define NIL_THD_SUSP 2 /**< @brief Thread suspended. */ #define NIL_STATE_SUSP 2 /**< @brief Thread suspended. */
#define NIL_THD_WTSEM 3 /**< @brief Thread waiting on semaphore.*/ #define NIL_STATE_WTSEM 3 /**< @brief Thread waiting on semaphore.*/
#define NIL_THD_IS_READY(tr) ((tr)->state == NIL_THD_READY) #define NIL_THD_IS_READY(tr) ((tr)->state == NIL_STATE_READY)
#define NIL_THD_IS_SLEEPING(tr) ((tr)->state == NIL_THD_SLEEPING) #define NIL_THD_IS_SLEEPING(tr) ((tr)->state == NIL_STATE_SLEEPING)
#define NIL_THD_IS_SUSP(tr) ((tr)->state == NIL_THD_SUSP) #define NIL_THD_IS_SUSP(tr) ((tr)->state == NIL_STATE_SUSP)
#define NIL_THD_IS_WTSEM(tr) ((tr)->state == NIL_THD_WTSEM) #define NIL_THD_IS_WTSEM(tr) ((tr)->state == NIL_STATE_WTSEM)
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/
@ -163,9 +163,9 @@
#endif #endif
#if NIL_CFG_ENABLE_ASSERTS #if NIL_CFG_ENABLE_ASSERTS
#define NIL_DBG_ENABLED TRUE #define CH_DBG_ENABLED TRUE
#else #else
#define NIL_DBG_ENABLED FALSE #define CH_DBG_ENABLED FALSE
#endif #endif
/*===========================================================================*/ /*===========================================================================*/
@ -222,7 +222,7 @@ struct nil_thread {
intctx_t *ctxp; /**< @brief Pointer to internal context. */ intctx_t *ctxp; /**< @brief Pointer to internal context. */
tstate_t state; /**< @brief Thread state. */ tstate_t state; /**< @brief Thread state. */
/* Note, the following union contains a pointer while the thread is in a /* Note, the following union contains a pointer while the thread is in a
sleeping state (!NIL_THD_IS_READY()) else contains the wake-up message.*/ sleeping state (!CH_THD_IS_READY()) else contains the wake-up message.*/
union { union {
msg_t msg; /**< @brief Wake-up message. */ msg_t msg; /**< @brief Wake-up message. */
void *p; /**< @brief Generic pointer. */ void *p; /**< @brief Generic pointer. */
@ -271,7 +271,7 @@ typedef struct {
* @brief Thread structures for all the defined threads. * @brief Thread structures for all the defined threads.
*/ */
thread_t threads[NIL_CFG_NUM_THREADS + 1]; thread_t threads[NIL_CFG_NUM_THREADS + 1];
#if NIL_DBG_ENABLED || defined(__DOXYGEN__) #if CH_DBG_ENABLED || defined(__DOXYGEN__)
/** /**
* @brief Panic message. * @brief Panic message.
* @note This field is only present if some debug options have been * @note This field is only present if some debug options have been
@ -288,7 +288,7 @@ typedef struct {
/** /**
* @brief String quotation macro. * @brief String quotation macro.
*/ */
#define __NIL_QUOTE(p) #p #define __CH_QUOTE(p) #p
/** /**
* @name Threads tables definition macros * @name Threads tables definition macros
@ -375,7 +375,7 @@ typedef struct {
* *
* @special * @special
*/ */
#define NIL_IRQ_PROLOGUE() PORT_IRQ_PROLOGUE() #define CH_IRQ_PROLOGUE() PORT_IRQ_PROLOGUE()
/** /**
* @brief IRQ handler exit code. * @brief IRQ handler exit code.
@ -383,7 +383,7 @@ typedef struct {
* *
* @special * @special
*/ */
#define NIL_IRQ_EPILOGUE() PORT_IRQ_EPILOGUE() #define CH_IRQ_EPILOGUE() PORT_IRQ_EPILOGUE()
/** /**
* @brief Standard normal IRQ handler declaration. * @brief Standard normal IRQ handler declaration.
@ -392,7 +392,7 @@ typedef struct {
* *
* @special * @special
*/ */
#define NIL_IRQ_HANDLER(id) PORT_IRQ_HANDLER(id) #define CH_IRQ_HANDLER(id) PORT_IRQ_HANDLER(id)
/** @} */ /** @} */
/** /**
@ -406,7 +406,7 @@ typedef struct {
* *
* @special * @special
*/ */
#define NIL_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id) #define CH_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id)
/** @} */ /** @} */
/** /**
@ -464,28 +464,28 @@ typedef struct {
* *
* @special * @special
*/ */
#define nilSysDisable() port_disable() #define chSysDisable() port_disable()
/** /**
* @brief Enters the kernel lock mode. * @brief Enters the kernel lock mode.
* *
* @special * @special
*/ */
#define nilSysEnable() port_enable() #define chSysEnable() port_enable()
/** /**
* @brief Enters the kernel lock mode. * @brief Enters the kernel lock mode.
* *
* @special * @special
*/ */
#define nilSysLock() port_lock() #define chSysLock() port_lock()
/** /**
* @brief Leaves the kernel lock mode. * @brief Leaves the kernel lock mode.
* *
* @special * @special
*/ */
#define nilSysUnlock() port_unlock() #define chSysUnlock() port_unlock()
/** /**
* @brief Enters the kernel lock mode from within an interrupt handler. * @brief Enters the kernel lock mode from within an interrupt handler.
@ -499,7 +499,7 @@ typedef struct {
* *
* @special * @special
*/ */
#define nilSysLockFromISR() port_lock_from_isr() #define chSysLockFromISR() port_lock_from_isr()
/** /**
* @brief Leaves the kernel lock mode from within an interrupt handler. * @brief Leaves the kernel lock mode from within an interrupt handler.
@ -514,7 +514,7 @@ typedef struct {
* *
* @special * @special
*/ */
#define nilSysUnlockFromISR() port_unlock_from_isr() #define chSysUnlockFromISR() port_unlock_from_isr()
/** /**
* @brief Delays the invoking thread for the specified number of seconds. * @brief Delays the invoking thread for the specified number of seconds.
@ -526,7 +526,7 @@ typedef struct {
* *
* @api * @api
*/ */
#define nilThdSleepSeconds(sec) nilThdSleep(S2ST(sec)) #define chThdSleepSeconds(sec) chThdSleep(S2ST(sec))
/** /**
* @brief Delays the invoking thread for the specified number of * @brief Delays the invoking thread for the specified number of
@ -539,7 +539,7 @@ typedef struct {
* *
* @api * @api
*/ */
#define nilThdSleepMilliseconds(msec) nilThdSleep(MS2ST(msec)) #define chThdSleepMilliseconds(msec) chThdSleep(MS2ST(msec))
/** /**
* @brief Delays the invoking thread for the specified number of * @brief Delays the invoking thread for the specified number of
@ -552,7 +552,7 @@ typedef struct {
* *
* @api * @api
*/ */
#define nilThdSleepMicroseconds(usec) nilThdSleep(US2ST(usec)) #define chThdSleepMicroseconds(usec) chThdSleep(US2ST(usec))
/** /**
* @brief Suspends the invoking thread for the specified time. * @brief Suspends the invoking thread for the specified time.
@ -561,7 +561,7 @@ typedef struct {
* *
* @sclass * @sclass
*/ */
#define nilThdSleepS(timeout) nilSchGoSleepTimeoutS(NIL_THD_SLEEPING, timeout) #define chThdSleepS(timeout) chSchGoSleepTimeoutS(NIL_STATE_SLEEPING, timeout)
/** /**
* @brief Suspends the invoking thread until the system time arrives to the * @brief Suspends the invoking thread until the system time arrives to the
@ -571,8 +571,8 @@ typedef struct {
* *
* @sclass * @sclass
*/ */
#define nilThdSleepUntilS(time) \ #define chThdSleepUntilS(time) \
nilSchGoSleepTimeoutS(NIL_THD_SLEEPING, (time) - nilTimeNow()) chSchGoSleepTimeoutS(NIL_STATE_SLEEPING, (time) - chTimeNow())
/** /**
* @brief Initializes a semaphore with the specified counter value. * @brief Initializes a semaphore with the specified counter value.
@ -583,7 +583,7 @@ typedef struct {
* *
* @init * @init
*/ */
#define nilSemInit(sp, n) ((sp)->cnt = n) #define chSemInit(sp, n) ((sp)->cnt = n)
/** /**
* @brief Performs a wait operation on a semaphore. * @brief Performs a wait operation on a semaphore.
@ -591,13 +591,13 @@ typedef struct {
* @param[in] sp pointer to a @p semaphore_t structure * @param[in] sp pointer to a @p semaphore_t structure
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the semaphore. * released from the semaphore.
* @retval NIL_MSG_OK if the thread has not stopped on the semaphore or the * @retval CH_MSG_OK if the thread has not stopped on the semaphore or the
* semaphore has been signaled. * semaphore has been signaled.
* @retval NIL_MSG_RST if the semaphore has been reset using @p nilSemReset(). * @retval CH_MSG_RST if the semaphore has been reset using @p chSemReset().
* *
* @api * @api
*/ */
#define nilSemWait(sp) nilSemWaitTimeout(sp, TIME_INFINITE) #define chSemWait(sp) chSemWaitTimeout(sp, TIME_INFINITE)
/** /**
* @brief Performs a wait operation on a semaphore. * @brief Performs a wait operation on a semaphore.
@ -605,29 +605,29 @@ typedef struct {
* @param[in] sp pointer to a @p semaphore_t structure * @param[in] sp pointer to a @p semaphore_t structure
* @return A message specifying how the invoking thread has been * @return A message specifying how the invoking thread has been
* released from the semaphore. * released from the semaphore.
* @retval NIL_MSG_OK if the thread has not stopped on the semaphore or the * @retval CH_MSG_OK if the thread has not stopped on the semaphore or the
* semaphore has been signaled. * semaphore has been signaled.
* @retval NIL_MSG_RST if the semaphore has been reset using @p nilSemReset(). * @retval CH_MSG_RST if the semaphore has been reset using @p chSemReset().
* *
* @sclass * @sclass
*/ */
#define nilSemWaitS(sp) nilSemWaitTimeoutS(sp, TIME_INFINITE) #define chSemWaitS(sp) chSemWaitTimeoutS(sp, TIME_INFINITE)
/** /**
* @brief Current system time. * @brief Current system time.
* @details Returns the number of system ticks since the @p nilSysInit() * @details Returns the number of system ticks since the @p chSysInit()
* invocation. * invocation.
* @note The counter can reach its maximum and then restart from zero. * @note The counter can reach its maximum and then restart from zero.
* @note This function is designed to work with the @p nilThdSleepUntil(). * @note This function is designed to work with the @p chThdSleepUntil().
* *
* @return The system time in ticks. * @return The system time in ticks.
* *
* @iclass * @iclass
*/ */
#if NIL_CFG_TIMEDELTA == 0 || defined(__DOXYGEN__) #if NIL_CFG_TIMEDELTA == 0 || defined(__DOXYGEN__)
#define nilTimeNowI() (nil.systime) #define chTimeNowI() (nil.systime)
#else #else
#define nilTimeNowI() port_timer_get_time() #define chTimeNowI() port_timer_get_time()
#endif #endif
/** /**
@ -644,7 +644,7 @@ typedef struct {
* *
* @api * @api
*/ */
#define nilTimeIsWithin(time, start, end) \ #define chTimeIsWithin(time, start, end) \
((end) > (start) ? ((time) >= (start)) && ((time) < (end)) : \ ((end) > (start) ? ((time) >= (start)) && ((time) < (end)) : \
((time) >= (start)) || ((time) < (end))) ((time) >= (start)) || ((time) < (end)))
@ -663,14 +663,14 @@ typedef struct {
* *
* @api * @api
*/ */
#if !defined(nilDbgAssert) #if !defined(chDbgAssert)
#define nilDbgAssert(c, r) { \ #define chDbgAssert(c, r) { \
if (!(c)) \ if (!(c)) \
nilSysHalt("A:"__NIL_QUOTE(__FUNCTION__)":"__NIL_QUOTE(__LINE__)); \ chSysHalt("A:"__CH_QUOTE(__FUNCTION__)":"__CH_QUOTE(__LINE__)); \
} }
#endif /* !defined(nilDbgAssert) */ #endif /* !defined(chDbgAssert) */
#else /* !NIL_CFG_ENABLE_ASSERTS */ #else /* !NIL_CFG_ENABLE_ASSERTS */
#define nilDbgAssert(c, r) /*{(void)(c);}*/ #define chDbgAssert(c, r) /*{(void)(c);}*/
#endif /* !NIL_CFG_ENABLE_ASSERTS */ #endif /* !NIL_CFG_ENABLE_ASSERTS */
/** @} */ /** @} */
@ -686,24 +686,24 @@ extern const thread_config_t nil_thd_configs[NIL_CFG_NUM_THREADS + 1];
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void nilSysInit(void); void chSysInit(void);
void nilSysHalt(const char *reason); void chSysHalt(const char *reason);
void nilSysTimerHandlerI(void); void chSysTimerHandlerI(void);
thread_ref_t nilSchReadyI(thread_ref_t trp, msg_t msg); thread_ref_t chSchReadyI(thread_ref_t trp, msg_t msg);
msg_t nilSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout); msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout);
void nilSchRescheduleS(void); void chSchRescheduleS(void);
msg_t nilThdSuspendTimeoutS(thread_ref_t *trp, systime_t timeout); msg_t chThdSuspendTimeoutS(thread_ref_t *trp, systime_t timeout);
void nilThdResumeI(thread_ref_t *trp, msg_t msg); void chThdResumeI(thread_ref_t *trp, msg_t msg);
void nilThdSleep(systime_t time); void chThdSleep(systime_t time);
void nilThdSleepUntil(systime_t time); void chThdSleepUntil(systime_t time);
systime_t nilTimeNow(void); systime_t chTimeNow(void);
bool nilTimeNowIsWithin(systime_t start, systime_t end); bool chTimeNowIsWithin(systime_t start, systime_t end);
msg_t nilSemWaitTimeout(semaphore_t *sp, systime_t time); msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time);
msg_t nilSemWaitTimeoutS(semaphore_t *sp, systime_t time); msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time);
void nilSemSignal(semaphore_t *sp); void chSemSignal(semaphore_t *sp);
void nilSemSignalI(semaphore_t *sp); void chSemSignalI(semaphore_t *sp);
void nilSemReset(semaphore_t *sp, cnt_t n); void chSemReset(semaphore_t *sp, cnt_t n);
void nilSemResetI(semaphore_t *sp, cnt_t n); void chSemResetI(semaphore_t *sp, cnt_t n);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -89,7 +89,7 @@ _port_thread_start:
mov r0, r5 mov r0, r5
blx r4 blx r4
mov r3, #0 mov r3, #0
bl nilSysHalt bl chSysHalt
/*--------------------------------------------------------------------------* /*--------------------------------------------------------------------------*
* Post-IRQ switch code. * Post-IRQ switch code.
@ -99,7 +99,7 @@ _port_thread_start:
.thumb_func .thumb_func
.globl _port_switch_from_isr .globl _port_switch_from_isr
_port_switch_from_isr: _port_switch_from_isr:
bl nilSchRescheduleS bl chSchRescheduleS
.globl _port_exit_from_isr .globl _port_exit_from_isr
_port_exit_from_isr: _port_exit_from_isr:
ldr r2, .L2 ldr r2, .L2

View File

@ -65,7 +65,7 @@ nil_system_t nil;
* *
* @special * @special
*/ */
void nilSysInit(void) { void chSysInit(void) {
thread_ref_t tr; thread_ref_t tr;
const thread_config_t *tcp; const thread_config_t *tcp;
@ -76,7 +76,7 @@ void nilSysInit(void) {
for (tr = &nil.threads[0], tcp = nil_thd_configs; for (tr = &nil.threads[0], tcp = nil_thd_configs;
tr < &nil.threads[NIL_CFG_NUM_THREADS]; tr < &nil.threads[NIL_CFG_NUM_THREADS];
tr++, tcp++) { tr++, tcp++) {
tr->state = NIL_THD_READY; tr->state = NIL_STATE_READY;
tr->timeout = 0; tr->timeout = 0;
/* Port dependent thread initialization.*/ /* Port dependent thread initialization.*/
@ -94,7 +94,7 @@ void nilSysInit(void) {
port_switch(nil.threads, &nil.threads[NIL_CFG_NUM_THREADS]); port_switch(nil.threads, &nil.threads[NIL_CFG_NUM_THREADS]);
/* Interrupts enabled for the idle thread.*/ /* Interrupts enabled for the idle thread.*/
nilSysEnable(); chSysEnable();
} }
/** /**
@ -107,7 +107,7 @@ void nilSysInit(void) {
* *
* @special * @special
*/ */
void nilSysHalt(const char *reason) { void chSysHalt(const char *reason) {
port_disable(); port_disable();
@ -133,7 +133,7 @@ void nilSysHalt(const char *reason) {
* *
* @iclass * @iclass
*/ */
void nilSysTimerHandlerI(void) { void chSysTimerHandlerI(void) {
#if NIL_CFG_TIMEDELTA == 0 #if NIL_CFG_TIMEDELTA == 0
thread_ref_t tr = &nil.threads[0]; thread_ref_t tr = &nil.threads[0];
@ -142,7 +142,7 @@ void nilSysTimerHandlerI(void) {
/* Is the thread in a wait state with timeout?.*/ /* Is the thread in a wait state with timeout?.*/
if (tr->timeout > 0) { if (tr->timeout > 0) {
nilDbgAssert(!NIL_THD_IS_READY(tr), "is ready"); chDbgAssert(!NIL_THD_IS_READY(tr), "is ready");
/* Did the timer reach zero?*/ /* Did the timer reach zero?*/
if (--tr->timeout == 0) { if (--tr->timeout == 0) {
@ -152,30 +152,30 @@ void nilSysTimerHandlerI(void) {
tr->u1.semp->cnt++; tr->u1.semp->cnt++;
else if (NIL_THD_IS_SUSP(tr)) else if (NIL_THD_IS_SUSP(tr))
tr->u1.trp = NULL; tr->u1.trp = NULL;
nilSchReadyI(tr, MSG_TIMEOUT); chSchReadyI(tr, MSG_TIMEOUT);
} }
} }
/* Lock released in order to give a preemption chance on those /* Lock released in order to give a preemption chance on those
architectures supporting IRQ preemption.*/ architectures supporting IRQ preemption.*/
nilSysUnlockFromISR(); chSysUnlockFromISR();
tr++; tr++;
nilSysLockFromISR(); chSysLockFromISR();
} while (tr < &nil.threads[NIL_CFG_NUM_THREADS]); } while (tr < &nil.threads[NIL_CFG_NUM_THREADS]);
#else #else
thread_ref_t tr = &nil.threads[0]; thread_ref_t tr = &nil.threads[0];
systime_t next = 0; systime_t next = 0;
nilDbgAssert(nil.nexttime == port_timer_get_alarm(), chDbgAssert(nil.nexttime == port_timer_get_alarm(),
"nilSysTimerHandlerI(), #1", "time mismatch"); "chSysTimerHandlerI(), #1", "time mismatch");
do { do {
/* Is the thread in a wait state with timeout?.*/ /* Is the thread in a wait state with timeout?.*/
if (tr->timeout > 0) { if (tr->timeout > 0) {
nilDbgAssert(!NIL_THD_IS_READY(tr), chDbgAssert(!NIL_THD_IS_READY(tr),
"nilSysTimerHandlerI(), #2", "is ready"); "chSysTimerHandlerI(), #2", "is ready");
nilDbgAssert(tr->timeout >= nil.nexttime - nil.lasttime, chDbgAssert(tr->timeout >= nil.nexttime - nil.lasttime,
"nilSysTimerHandlerI(), #3", "skipped one"); "chSysTimerHandlerI(), #3", "skipped one");
tr->timeout -= nil.nexttime - nil.lasttime; tr->timeout -= nil.nexttime - nil.lasttime;
if (tr->timeout == 0) { if (tr->timeout == 0) {
@ -185,7 +185,7 @@ void nilSysTimerHandlerI(void) {
tr->u1.semp->cnt++; tr->u1.semp->cnt++;
else if (NIL_THD_IS_SUSP(tr)) else if (NIL_THD_IS_SUSP(tr))
tr->u1.trp = NULL; tr->u1.trp = NULL;
nilSchReadyI(tr, NIL_MSG_TMO); chSchReadyI(tr, NIL_MSG_TMO);
} }
else { else {
if (tr->timeout <= next - 1) if (tr->timeout <= next - 1)
@ -194,9 +194,9 @@ void nilSysTimerHandlerI(void) {
} }
/* Lock released in order to give a preemption chance on those /* Lock released in order to give a preemption chance on those
architectures supporting IRQ preemption.*/ architectures supporting IRQ preemption.*/
nilSysUnlockFromISR(); chSysUnlockFromISR();
tr++; tr++;
nilSysLockFromISR(); chSysLockFromISR();
} while (tr < &nil.threads[NIL_CFG_NUM_THREADS]); } while (tr < &nil.threads[NIL_CFG_NUM_THREADS]);
nil.lasttime = nil.nexttime; nil.lasttime = nil.nexttime;
if (next > 0) { if (next > 0) {
@ -218,16 +218,16 @@ void nilSysTimerHandlerI(void) {
* *
* @return The same reference passed as parameter. * @return The same reference passed as parameter.
*/ */
thread_ref_t nilSchReadyI(thread_ref_t tr, msg_t msg) { thread_ref_t chSchReadyI(thread_ref_t tr, msg_t msg) {
nilDbgAssert((tr >= nil.threads) && chDbgAssert((tr >= nil.threads) &&
(tr < &nil.threads[NIL_CFG_NUM_THREADS]), (tr < &nil.threads[NIL_CFG_NUM_THREADS]),
"pointer out of range"); "pointer out of range");
nilDbgAssert(!NIL_THD_IS_READY(tr), "already ready"); chDbgAssert(!NIL_THD_IS_READY(tr), "already ready");
nilDbgAssert(nil.next <= nil.current, "priority ordering"); chDbgAssert(nil.next <= nil.current, "priority ordering");
tr->u1.msg = msg; tr->u1.msg = msg;
tr->state = NIL_THD_READY; tr->state = NIL_STATE_READY;
tr->timeout = 0; tr->timeout = 0;
if (tr < nil.next) if (tr < nil.next)
nil.next = tr; nil.next = tr;
@ -239,7 +239,7 @@ thread_ref_t nilSchReadyI(thread_ref_t tr, msg_t msg) {
* *
* @sclass * @sclass
*/ */
void nilSchRescheduleS() { void chSchRescheduleS() {
thread_ref_t otr = nil.current; thread_ref_t otr = nil.current;
thread_ref_t ntr = nil.next; thread_ref_t ntr = nil.next;
@ -271,10 +271,10 @@ void nilSchRescheduleS() {
* *
* @sclass * @sclass
*/ */
msg_t nilSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout) { msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout) {
thread_ref_t ntr, otr = nil.current; thread_ref_t ntr, otr = nil.current;
nilDbgAssert(otr != &nil.threads[NIL_CFG_NUM_THREADS], chDbgAssert(otr != &nil.threads[NIL_CFG_NUM_THREADS],
"idle cannot sleep"); "idle cannot sleep");
/* Storing the wait object for the current thread.*/ /* Storing the wait object for the current thread.*/
@ -282,7 +282,7 @@ msg_t nilSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout) {
#if NIL_CFG_TIMEDELTA > 0 #if NIL_CFG_TIMEDELTA > 0
if (timeout != TIME_INFINITE) { if (timeout != TIME_INFINITE) {
systime_t time = nilTimeNowI() + timeout; systime_t time = chTimeNowI() + timeout;
/* TIMEDELTA makes sure to have enough time to reprogram the timer /* TIMEDELTA makes sure to have enough time to reprogram the timer
before the free-running timer counter reaches the selected timeout.*/ before the free-running timer counter reaches the selected timeout.*/
@ -297,7 +297,7 @@ msg_t nilSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout) {
else { else {
/* Special case, there are already other threads with a timeout /* Special case, there are already other threads with a timeout
activated, evaluating the order.*/ activated, evaluating the order.*/
if (nilTimeIsWithin(time, nil.lasttime, nil.nexttime)) { if (chTimeIsWithin(time, nil.lasttime, nil.nexttime)) {
port_timer_set_alarm(time); port_timer_set_alarm(time);
nil.nexttime = time; nil.nexttime = time;
} }
@ -329,7 +329,7 @@ msg_t nilSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout) {
/* Points to the next thread in lowering priority order.*/ /* Points to the next thread in lowering priority order.*/
ntr++; ntr++;
nilDbgAssert(ntr <= &nil.threads[NIL_CFG_NUM_THREADS], chDbgAssert(ntr <= &nil.threads[NIL_CFG_NUM_THREADS],
"pointer out of range"); "pointer out of range");
} }
} }
@ -348,13 +348,13 @@ msg_t nilSchGoSleepTimeoutS(tstate_t newstate, systime_t timeout) {
* *
* @sclass * @sclass
*/ */
msg_t nilThdSuspendTimeoutS(thread_ref_t *trp, systime_t timeout) { msg_t chThdSuspendTimeoutS(thread_ref_t *trp, systime_t timeout) {
nilDbgAssert(*trp == NULL, "not NULL"); chDbgAssert(*trp == NULL, "not NULL");
*trp = nil.current; *trp = nil.current;
nil.current->u1.trp = trp; nil.current->u1.trp = trp;
return nilSchGoSleepTimeoutS(NIL_THD_SUSP, timeout); return chSchGoSleepTimeoutS(NIL_STATE_SUSP, timeout);
} }
/** /**
@ -367,15 +367,15 @@ msg_t nilThdSuspendTimeoutS(thread_ref_t *trp, systime_t timeout) {
* *
* @iclass * @iclass
*/ */
void nilThdResumeI(thread_ref_t *trp, msg_t msg) { void chThdResumeI(thread_ref_t *trp, msg_t msg) {
if (*trp != NULL) { if (*trp != NULL) {
thread_ref_t tr = *trp; thread_ref_t tr = *trp;
nilDbgAssert(NIL_THD_IS_SUSP(tr), "not suspended"); chDbgAssert(NIL_THD_IS_SUSP(tr), "not suspended");
*trp = NULL; *trp = NULL;
nilSchReadyI(tr, msg); chSchReadyI(tr, msg);
} }
} }
@ -386,11 +386,11 @@ void nilThdResumeI(thread_ref_t *trp, msg_t msg) {
* *
* @api * @api
*/ */
void nilThdSleep(systime_t time) { void chThdSleep(systime_t time) {
nilSysLock(); chSysLock();
nilThdSleepS(time); chThdSleepS(time);
nilSysUnlock(); chSysUnlock();
} }
/** /**
@ -401,30 +401,30 @@ void nilThdSleep(systime_t time) {
* *
* @api * @api
*/ */
void nilThdSleepUntil(systime_t time) { void chThdSleepUntil(systime_t time) {
nilSysLock(); chSysLock();
nilThdSleepUntilS(time); chThdSleepUntilS(time);
nilSysUnlock(); chSysUnlock();
} }
/** /**
* @brief Current system time. * @brief Current system time.
* @details Returns the number of system ticks since the @p nilSysInit() * @details Returns the number of system ticks since the @p chSysInit()
* invocation. * invocation.
* @note The counter can reach its maximum and then restart from zero. * @note The counter can reach its maximum and then restart from zero.
* @note This function is designed to work with the @p nilThdSleepUntil(). * @note This function is designed to work with the @p chThdSleepUntil().
* *
* @return The system time in ticks. * @return The system time in ticks.
* *
* @api * @api
*/ */
systime_t nilTimeNow(void) { systime_t chTimeNow(void) {
systime_t time; systime_t time;
nilSysLock(); chSysLock();
time = nilTimeNowI(); time = chTimeNowI();
nilSysUnlock(); chSysUnlock();
return time; return time;
} }
@ -442,10 +442,10 @@ systime_t nilTimeNow(void) {
* *
* @api * @api
*/ */
bool nilTimeNowIsWithin(systime_t start, systime_t end) { bool chTimeNowIsWithin(systime_t start, systime_t end) {
systime_t time = nilTimeNow(); systime_t time = chTimeNow();
return nilTimeIsWithin(time, start, end); return chTimeIsWithin(time, start, end);
} }
/** /**
@ -461,18 +461,18 @@ bool nilTimeNowIsWithin(systime_t start, systime_t end) {
* released from the semaphore. * released from the semaphore.
* @retval NIL_MSG_OK if the thread has not stopped on the semaphore or the * @retval NIL_MSG_OK if the thread has not stopped on the semaphore or the
* semaphore has been signaled. * semaphore has been signaled.
* @retval NIL_MSG_RST if the semaphore has been reset using @p nilSemReset(). * @retval NIL_MSG_RST if the semaphore has been reset using @p chSemReset().
* @retval NIL_MSG_TMO if the semaphore has not been signaled or reset within * @retval NIL_MSG_TMO if the semaphore has not been signaled or reset within
* the specified timeout. * the specified timeout.
* *
* @api * @api
*/ */
msg_t nilSemWaitTimeout(semaphore_t *sp, systime_t timeout) { msg_t chSemWaitTimeout(semaphore_t *sp, systime_t timeout) {
msg_t msg; msg_t msg;
nilSysLock(); chSysLock();
msg = nilSemWaitTimeoutS(sp, timeout); msg = chSemWaitTimeoutS(sp, timeout);
nilSysUnlock(); chSysUnlock();
return msg; return msg;
} }
@ -489,13 +489,13 @@ msg_t nilSemWaitTimeout(semaphore_t *sp, systime_t timeout) {
* released from the semaphore. * released from the semaphore.
* @retval NIL_MSG_OK if the thread has not stopped on the semaphore or the * @retval NIL_MSG_OK if the thread has not stopped on the semaphore or the
* semaphore has been signaled. * semaphore has been signaled.
* @retval NIL_MSG_RST if the semaphore has been reset using @p nilSemReset(). * @retval NIL_MSG_RST if the semaphore has been reset using @p chSemReset().
* @retval NIL_MSG_TMO if the semaphore has not been signaled or reset within * @retval NIL_MSG_TMO if the semaphore has not been signaled or reset within
* the specified timeout. * the specified timeout.
* *
* @sclass * @sclass
*/ */
msg_t nilSemWaitTimeoutS(semaphore_t *sp, systime_t timeout) { msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t timeout) {
/* Note, the semaphore counter is a volatile variable so accesses are /* Note, the semaphore counter is a volatile variable so accesses are
manually optimized.*/ manually optimized.*/
@ -505,7 +505,7 @@ msg_t nilSemWaitTimeoutS(semaphore_t *sp, systime_t timeout) {
return MSG_TIMEOUT; return MSG_TIMEOUT;
sp->cnt = cnt - 1; sp->cnt = cnt - 1;
nil.current->u1.semp = sp; nil.current->u1.semp = sp;
return nilSchGoSleepTimeoutS(NIL_THD_WTSEM, timeout); return chSchGoSleepTimeoutS(NIL_STATE_WTSEM, timeout);
} }
sp->cnt = cnt - 1; sp->cnt = cnt - 1;
return MSG_OK; return MSG_OK;
@ -522,12 +522,12 @@ msg_t nilSemWaitTimeoutS(semaphore_t *sp, systime_t timeout) {
* *
* @api * @api
*/ */
void nilSemSignal(semaphore_t *sp) { void chSemSignal(semaphore_t *sp) {
nilSysLock(); chSysLock();
nilSemSignalI(sp); chSemSignalI(sp);
nilSchRescheduleS(); chSchRescheduleS();
nilSysUnlock(); chSysUnlock();
} }
/** /**
@ -541,7 +541,7 @@ void nilSemSignal(semaphore_t *sp) {
* *
* @iclass * @iclass
*/ */
void nilSemSignalI(semaphore_t *sp) { void chSemSignalI(semaphore_t *sp) {
if (++sp->cnt <= 0) { if (++sp->cnt <= 0) {
thread_ref_t tr = nil.threads; thread_ref_t tr = nil.threads;
@ -549,9 +549,9 @@ void nilSemSignalI(semaphore_t *sp) {
/* Is this thread waiting on this semaphore?*/ /* Is this thread waiting on this semaphore?*/
if (tr->u1.semp == sp) { if (tr->u1.semp == sp) {
nilDbgAssert(NIL_THD_IS_WTSEM(tr), "not waiting"); chDbgAssert(NIL_THD_IS_WTSEM(tr), "not waiting");
nilSchReadyI(tr, MSG_OK); chSchReadyI(tr, MSG_OK);
return; return;
} }
tr++; tr++;
@ -575,12 +575,12 @@ void nilSemSignalI(semaphore_t *sp) {
* *
* @api * @api
*/ */
void nilSemReset(semaphore_t *sp, cnt_t n) { void chSemReset(semaphore_t *sp, cnt_t n) {
nilSysLock(); chSysLock();
nilSemResetI(sp, n); chSemResetI(sp, n);
nilSchRescheduleS(); chSchRescheduleS();
nilSysUnlock(); chSysUnlock();
} }
/** /**
@ -599,7 +599,7 @@ void nilSemReset(semaphore_t *sp, cnt_t n) {
* *
* @iclass * @iclass
*/ */
void nilSemResetI(semaphore_t *sp, cnt_t n) { void chSemResetI(semaphore_t *sp, cnt_t n) {
thread_ref_t tr; thread_ref_t tr;
cnt_t cnt; cnt_t cnt;
@ -610,10 +610,10 @@ void nilSemResetI(semaphore_t *sp, cnt_t n) {
/* Is this thread waiting on this semaphore?*/ /* Is this thread waiting on this semaphore?*/
if (tr->u1.semp == sp) { if (tr->u1.semp == sp) {
nilDbgAssert(NIL_THD_IS_WTSEM(tr), "not waiting"); chDbgAssert(NIL_THD_IS_WTSEM(tr), "not waiting");
cnt++; cnt++;
nilSchReadyI(tr, MSG_RESET); chSchReadyI(tr, MSG_RESET);
} }
tr++; tr++;
} }