66 if ((tp->
state == state) && (tp->u1.
p == p)) {
72 "pointer out of range");
91 while (cnt < (cnt_t)0) {
94 "pointer out of range");
115 #if (CH_DBG_SYSTEM_STATE_CHECK == TRUE) || defined(__DOXYGEN__) 211 port_lock_from_isr();
216 port_unlock_from_isr();
226 port_lock_from_isr();
231 port_unlock_from_isr();
280 #if CH_DBG_SYSTEM_STATE_CHECK == TRUE 290 tcp = nil_thd_configs;
292 #if CH_DBG_ENABLE_STACK_CHECK 306 #if CH_DBG_ENABLE_STACK_CHECK 315 #if CH_DBG_SYSTEM_STATE_CHECK == TRUE 320 #if CH_CFG_USE_MEMCORE == TRUE 325 #if CH_CFG_USE_HEAP == TRUE 330 #if CH_CFG_USE_FACTORY == TRUE 386 #if CH_CFG_ST_TIMEDELTA == 0 400 if (NIL_THD_IS_WTQUEUE(tp)) {
403 else if (NIL_THD_IS_SUSP(tp)) {
439 if (NIL_THD_IS_WTQUEUE(tp)) {
443 if (NIL_THD_IS_SUSP(tp)) {
470 port_timer_stop_alarm();
484 if (port_irq_enabled(port_get_irq_status())) {
498 if (!port_irq_enabled(port_get_irq_status())) {
518 syssts_t sts = port_get_irq_status();
519 if (port_irq_enabled(sts)) {
520 if (port_is_isr_context()) {
541 if (port_irq_enabled(sts)) {
542 if (port_is_isr_context()) {
552 #if (PORT_SUPPORTS_RT == TRUE) || defined(__DOXYGEN__) 573 return (
bool)((cnt - start) < (end - start));
589 rtcnt_t end = start + cycles;
608 chDbgAssert(!NIL_THD_IS_READY(tp),
"already ready");
652 port_switch(nil.
next, otp);
692 "idle cannot sleep");
695 otp->
state = newstate;
697 #if CH_CFG_ST_TIMEDELTA > 0 712 port_timer_start_alarm(abstime);
719 port_timer_set_alarm(abstime);
737 if (NIL_THD_IS_READY(ntp)) {
742 port_switch(ntp, otp);
749 "pointer out of range");
926 if (tqp->
cnt < (cnt_t)0) {
947 #if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__) 1003 cnt_t cnt = sp->
cnt;
1004 if (cnt <= (cnt_t)0) {
1009 sp->
cnt = cnt - (cnt_t)1;
1014 sp->
cnt = cnt - (cnt_t)1;
1050 if (++sp->
cnt <= (cnt_t)0) {
1106 #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__) 1141 if (NIL_THD_IS_WTOREVT(tp) &&
1170 if ((m = (ctp->
epmask & mask)) == (eventmask_t)0) {
1174 return (eventmask_t)0;
1180 return (eventmask_t)0;
tfunc_t funcp
Thread function.
stkalign_t * wbase
Thread working area base.
Structure representing a thread.
void chSchRescheduleS(void)
Reschedules if needed.
#define CH_CFG_IDLE_ENTER_HOOK()
Idle thread enter hook.
#define chSysLock()
Enters the kernel lock state.
systime_t nexttime
Time of the next scheduled tick event.
eventmask_t ewmask
Enabled events mask.
#define NIL_STATE_READY
Thread ready or executing.
void chEvtSignal(thread_t *tp, eventmask_t mask)
Adds a set of event flags directly to the specified thread_t.
msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout)
Puts the current thread to sleep into the specified state with timeout specification.
void chSysHalt(const char *reason)
Halts the system.
volatile cnt_t cnt
Threads Queue counter.
thread_reference_t * trp
Pointer to thread reference.
void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the threads queue object.
void chSemSignal(semaphore_t *sp)
Performs a signal operation on a semaphore.
tstate_t state
Thread state.
msg_t chThdSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
Sends the current thread sleeping and sets a reference variable.
void chThdResume(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
void chEvtSignalI(thread_t *tp, eventmask_t mask)
Adds a set of event flags directly to the specified thread_t.
eventmask_t epmask
Pending events mask.
#define chTimeAddX(systime, interval)
Adds an interval to a system time returning a system time.
void _factory_init(void)
Initializes the objects factory.
#define CH_CFG_SYSTEM_INIT_HOOK()
System initialization hook.
cnt_t lock_cnt
Lock nesting level.
static cnt_t nil_ready_all(void *p, cnt_t cnt, msg_t msg)
Puts in ready state all thread matching the specified status and associated object.
volatile systime_t systime
System time.
#define chTimeDiffX(start, end)
Subtracts two system times returning an interval.
#define TIME_IMMEDIATE
Zero time specification for some functions with a timeout specification.
#define TIME_INFINITE
Infinite time specification for all functions with a timeout specification.
void _core_init(void)
Low level memory manager initialization.
void chThdResumeI(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
stkalign_t * wabase
Thread stack boundary.
#define chSysGetRealtimeCounterX()
Returns the current value of the system real time counter.
void chSemSignalI(semaphore_t *sp)
Performs a signal operation on a semaphore.
#define NIL_STATE_WTOREVT
Waiting for events.
void chThdDoDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the threads queue object.
Structure representing a thread static configuration.
#define chSchIsRescRequiredI()
Evaluates if a reschedule is required.
void chSysRestoreStatusX(syssts_t sts)
Restores the specified execution status and leaves a critical zone.
eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, sysinterval_t timeout)
Waits for any of the specified events.
thread_t threads[CH_CFG_NUM_THREADS+1]
Thread structures for all the defined threads.
void chDbgCheckClassS(void)
S-class functions context check.
void chSemReset(semaphore_t *sp, cnt_t n)
Performs a reset operation on the semaphore.
#define CH_CFG_SYSTEM_HALT_HOOK(reason)
System halt hook.
void chSemResetI(semaphore_t *sp, cnt_t n)
Performs a reset operation on the semaphore.
#define CH_CFG_ST_TIMEDELTA
Time delta constant for the tick-less mode.
void _dbg_check_suspend(void)
Guard code for chSysSuspend().
void chThdSleepUntil(systime_t abstime)
Suspends the invoking thread until the system time arrives to the specified value.
void chDbgCheckClassI(void)
I-class functions context check.
#define MSG_TIMEOUT
Wake-up caused by a timeout condition.
#define chSysUnlock()
Leaves the kernel lock state.
#define chThdSleepS(timeout)
Suspends the invoking thread for the specified time.
thread_t * current
Pointer to the running thread.
thread_t * next
Pointer to the next thread to be executed.
#define chSysSuspend()
Raises the system interrupt priority mask to system level.
stkalign_t * wend
Thread working area end.
#define chDbgAssert(c, r)
Condition assertion.
uint32_t sysinterval_t
Type of time interval.
#define chSysUnlockFromISR()
Leaves the kernel lock state from within an interrupt handler.
void chThdSleep(sysinterval_t timeout)
Suspends the invoking thread for the specified time.
void chSysUnconditionalLock(void)
Unconditionally enters the kernel lock state.
msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread on a threads queue object.
#define CH_CFG_IDLE_LEAVE_HOOK()
Idle thread leave hook.
#define CH_CFG_THREAD_EXT_INIT_HOOK(tr)
Threads initialization hook.
void chSysPolledDelayX(rtcnt_t cycles)
Polled delay.
void _dbg_check_lock(void)
Guard code for chSysLock().
#define NIL_STATE_WTQUEUE
On queue or semaph.
msg_t msg
Wake-up message.
#define CH_CFG_NUM_THREADS
Number of user threads in the application.
void chSysInit(void)
Initializes the kernel.
#define NIL_STATE_SUSP
Thread suspended.
uint32_t systime_t
Type of system time.
#define MSG_OK
OK wakeup message.
#define chSysLockFromISR()
Enters the kernel lock state from within an interrupt handler.
void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the threads queue object, if any.
cnt_t isr_cnt
ISR nesting level.
#define MSG_RESET
Wake-up caused by a reset condition.
bool chSchIsPreemptionRequired(void)
Evaluates if preemption is required.
volatile sysinterval_t timeout
Timeout counter, zero if disabled.
void chSysTimerHandlerI(void)
Time management handler.
void _dbg_check_lock_from_isr(void)
Guard code for chSysLockFromIsr().
const char *volatile dbg_panic_msg
Panic message.
void _dbg_check_unlock_from_isr(void)
Guard code for chSysUnlockFromIsr().
void _dbg_check_enable(void)
Guard code for chSysEnable().
#define chDbgCheck(c)
Function parameters check.
bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end)
Realtime window test.
#define chThdSleepUntilS(abstime)
Suspends the invoking thread until the system time arrives to the specified value.
static thread_t * nil_find_thread(tstate_t state, void *p)
Retrieves the highest priority thread in the specified state and associated to the specified object...
void chSysUnconditionalUnlock(void)
Unconditionally leaves the kernel lock state.
Structure representing a queue of threads.
thread_t * chSchReadyI(thread_t *tp, msg_t msg)
Makes the specified thread ready for execution.
void _dbg_check_leave_isr(void)
Guard code for CH_IRQ_EPILOGUE().
threads_queue_t * tqp
Pointer to thread queue.
syssts_t chSysGetStatusAndLockX(void)
Returns the execution status and enters a critical zone.
void * arg
Thread function argument.
void _dbg_check_enter_isr(void)
Guard code for CH_IRQ_PROLOGUE().
Nil RTOS main header file.
void chSchDoReschedule(void)
Switches to the first thread on the runnable queue.
msg_t chSemWaitTimeout(semaphore_t *sp, sysinterval_t timeout)
Performs a wait operation on a semaphore with timeout specification.
semaphore_t * semp
Pointer to semaphore.
nil_system_t nil
System data structures.
systime_t lasttime
System time of the last tick event.
msg_t chSemWaitTimeoutS(semaphore_t *sp, sysinterval_t timeout)
Performs a wait operation on a semaphore with timeout specification.
void _dbg_check_unlock(void)
Guard code for chSysUnlock().
void _dbg_check_disable(void)
Guard code for chSysDisable().
#define chTimeIsInRangeX(time, start, end)
Checks if the specified time is within the specified time range.
#define chVTGetSystemTimeX()
Current system time.
void _heap_init(void)
Initializes the default heap.