Go to the documentation of this file.
75 if ((tp->
state == state) && (tp->u1.
p == p)) {
98 while (cnt < (
cnt_t)0) {
101 "pointer out of range");
114 #if (CH_DBG_SYSTEM_STATE_CHECK == TRUE) || defined(__DOXYGEN__)
210 port_lock_from_isr();
215 port_unlock_from_isr();
225 port_lock_from_isr();
230 port_unlock_from_isr();
291 #if CH_DBG_ENABLE_STACK_CHECK == TRUE
300 #if CH_DBG_SYSTEM_STATE_CHECK == TRUE
304 #if CH_CFG_AUTOSTART_THREADS == TRUE
306 tdp = nil_thd_configs;
310 }
while (tdp->
funcp != NULL);
359 #if CH_CFG_ST_TIMEDELTA == 0
373 #if CH_CFG_USE_SEMAPHORES == TRUE
374 if (NIL_THD_IS_WTQUEUE(tp)) {
379 if (NIL_THD_IS_SUSPENDED(tp)) {
415 if (NIL_THD_IS_WTQUEUE(tp)) {
419 if (NIL_THD_IS_SUSPENDED(tp)) {
446 port_timer_stop_alarm();
460 if (port_irq_enabled(port_get_irq_status())) {
474 if (!port_irq_enabled(port_get_irq_status())) {
494 syssts_t sts = port_get_irq_status();
495 if (port_irq_enabled(sts)) {
496 if (port_is_isr_context()) {
517 if (port_irq_enabled(sts)) {
518 if (port_is_isr_context()) {
528 #if (PORT_SUPPORTS_RT == TRUE) || defined(__DOXYGEN__)
585 chDbgAssert(!NIL_THD_IS_READY(tp),
"already ready");
669 "idle cannot sleep");
672 otp->
state = newstate;
674 #if CH_CFG_ST_TIMEDELTA > 0
689 port_timer_start_alarm(abstime);
696 port_timer_set_alarm(abstime);
714 if (NIL_THD_IS_READY(ntp)) {
719 port_switch(ntp, otp);
726 "pointer out of range");
765 (tdp->
wbase != NULL) &&
769 (tdp->
funcp != NULL));
775 chDbgAssert(NIL_THD_IS_WTSTART(tp) || NIL_THD_IS_FINAL(tp),
776 "priority slot taken");
778 #if CH_CFG_USE_EVENTS == TRUE
781 #if CH_DBG_ENABLE_STACK_CHECK == TRUE
842 #if CH_CFG_USE_WAITEXIT == TRUE
877 if (NIL_THD_IS_FINAL(tp)) {
932 chDbgAssert(NIL_THD_IS_SUSPENDED(tr),
"not suspended");
thread_t * chSchReadyI(thread_t *tp, msg_t msg)
Makes the specified thread ready for execution.
threads_queue_t * tqp
Pointer to thread queue.
void chThdResume(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
#define chVTGetSystemTimeX()
Current system time.
void __dbg_check_unlock_from_isr(void)
Guard code for chSysUnlockFromIsr().
#define chTimeDiffX(start, end)
Subtracts two system times returning an interval.
msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout)
Puts the current thread to sleep into the specified state with timeout specification.
void chSysUnconditionalUnlock(void)
Unconditionally leaves the kernel lock state.
bool chSchIsPreemptionRequired(void)
Evaluates if preemption is required.
msg_t msg
Wake-up/exit message.
void chDbgCheckClassS(void)
S-class functions context check.
#define chSysUnlockFromISR()
Leaves the kernel lock state from within an interrupt handler.
syssts_t chSysGetStatusAndLockX(void)
Returns the execution status and enters a critical zone.
void __dbg_check_lock(void)
Guard code for chSysLock().
Structure representing a thread descriptor.
volatile cnt_t cnt
Threads Queue counter.
void chThdSleep(sysinterval_t timeout)
Suspends the invoking thread for the specified time.
void chThdResumeI(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
void chSysTimerHandlerI(void)
Time management handler.
#define NIL_STATE_WTQUEUE
On queue or semaph.
#define chSysLockFromISR()
Enters the kernel lock state from within an interrupt handler.
#define NIL_STATE_SUSPENDED
Thread suspended.
#define MSG_TIMEOUT
Wake-up caused by a timeout condition.
#define MEM_IS_ALIGNED(p, a)
Returns whatever a pointer or memory size is aligned.
const char *volatile dbg_panic_msg
Panic message.
port_stkalign_t stkalign_t
void __dbg_check_unlock(void)
Guard code for chSysUnlock().
#define TIME_INFINITE
Infinite time specification for all functions with a timeout specification.
thread_t * tp
Pointer to thread.
#define MSG_OK
OK wakeup message.
thread_t * chThdCreate(const thread_descriptor_t *tdp)
Creates a new thread into a static memory area.
systime_t nexttime
Time of the next scheduled tick event.
void __dbg_check_enter_isr(void)
Guard code for CH_IRQ_PROLOGUE().
semaphore_t * semp
Pointer to semaphore.
#define NIL_STATE_FINAL
Thread terminated.
void chSysPolledDelayX(rtcnt_t cycles)
Polled delay.
void * arg
Thread function argument.
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.
#define NIL_STATE_WTEXIT
Waiting a thread.
void chSysRestoreStatusX(syssts_t sts)
Restores the specified execution status and leaves a critical zone.
void __dbg_check_leave_isr(void)
Guard code for CH_IRQ_EPILOGUE().
void chSysInit(void)
Initializes the kernel.
#define chDbgCheck(c)
Function parameters check.
cnt_t isr_cnt
ISR nesting level.
void chDbgCheckClassI(void)
I-class functions context check.
bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end)
Realtime window test.
void chThdSleepUntil(systime_t abstime)
Suspends the invoking thread until the system time arrives to the specified value.
uint32_t systime_t
Type of system time.
os_instance_t nil
System data structures.
void chThdDoDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the threads queue object.
void chSysUnconditionalLock(void)
Unconditionally enters the kernel lock state.
#define chThdSleepUntilS(abstime)
Suspends the invoking thread until the system time arrives to the specified value.
stkalign_t * wabase
Thread stack boundary.
tfunc_t funcp
Thread function.
stkalign_t * wbase
Thread working area base.
#define chSchIsRescRequiredI()
Evaluates if a reschedule is required.
#define CH_CFG_IDLE_LEAVE_HOOK()
Idle thread leave hook.
#define chSysSuspend()
Raises the system interrupt priority mask to system level.
void chThdExit(msg_t msg)
Terminates the current thread.
void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up one thread from the threads queue object, if any.
thread_reference_t * trp
Pointer to thread reference.
void chSysHalt(const char *reason)
Halts the system.
stkalign_t * wend
Thread working area end.
Structure representing a queue of threads.
eventmask_t epmask
Pending events mask.
#define CH_CFG_MAX_THREADS
Maximum number of user threads in the application.
systime_t lasttime
System time of the last tick event.
void __dbg_check_lock_from_isr(void)
Guard code for chSysLockFromIsr().
Structure representing a thread.
msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread on a threads queue object.
#define chThdSleepS(timeout)
Suspends the invoking thread for the specified time.
#define chDbgAssert(c, r)
Condition assertion.
void chSchDoPreemption(void)
Switches to the first thread on the runnable queue.
#define CH_CFG_THREAD_EXIT_HOOK(tp)
Threads finalization hook.
#define CH_CFG_SYSTEM_HALT_HOOK(reason)
System halt hook.
volatile systime_t systime
System time.
#define CH_CFG_IDLE_ENTER_HOOK()
Idle thread enter hook.
#define NIL_STATE_READY
Thread ready or executing.
void __dbg_check_disable(void)
Guard code for chSysDisable().
thread_t * chThdCreateI(const thread_descriptor_t *tdp)
Creates a new thread into a static memory area.
tstate_t state
Thread state.
thread_t * next
Pointer to the next thread to be executed.
void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the threads queue object.
thread_t * current
Pointer to the running thread.
volatile sysinterval_t timeout
Timeout counter, zero if disabled.
void __dbg_check_enable(void)
Guard code for chSysEnable().
#define CH_CFG_SYSTEM_INIT_HOOK()
System initialization hook.
#define TIME_IMMEDIATE
Zero time specification for some functions with a timeout specification.
#define chTimeAddX(systime, interval)
Adds an interval to a system time returning a system time.
uint32_t sysinterval_t
Type of time interval.
tprio_t prio
Thread priority slot.
Nil RTOS main header file.
msg_t chThdSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
Sends the current thread sleeping and sets a reference variable.
void chSchRescheduleS(void)
Reschedules if needed.
msg_t chThdWait(thread_t *tp)
Blocks the execution of the invoking thread until the specified thread terminates then the exit code ...
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.
static void __oslib_init(void)
Initialization of all library modules.
#define CH_CFG_ST_TIMEDELTA
Time delta constant for the tick-less mode.
cnt_t lock_cnt
Lock nesting level.
bool chTimeIsInRangeX(systime_t time, systime_t start, systime_t end)
Checks if the specified time is within the specified time range.
#define chSysGetRealtimeCounterX()
Returns the current value of the system real time counter.
#define chSysUnlock()
Leaves the kernel lock state.
#define CH_CFG_THREAD_EXT_INIT_HOOK(tr)
Threads initialization hook.
void __dbg_check_suspend(void)
Guard code for chSysSuspend().
#define chThdResumeS(trp, msg)
Wakes up a thread waiting on a thread reference object.
thread_t threads[CH_CFG_MAX_THREADS+1]
Thread structures for all the defined threads.
#define chSysLock()
Enters the kernel lock state.