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__)
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);
335 nil.dbg_panic_msg = reason;
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)) {
396 chDbgAssert(
nil.nexttime == port_timer_get_alarm(),
"time mismatch");
410 tp->timeout = timeout;
415 if (NIL_THD_IS_WTQUEUE(tp)) {
419 if (NIL_THD_IS_SUSPENDED(tp)) {
439 nil.lasttime =
nil.nexttime;
442 port_timer_set_alarm(
nil.nexttime);
446 port_timer_stop_alarm();
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
687 if (
nil.lasttime ==
nil.nexttime) {
689 port_timer_start_alarm(abstime);
690 nil.nexttime = abstime;
696 port_timer_set_alarm(abstime);
697 nil.nexttime = abstime;
702 otp->timeout = abstime -
nil.lasttime;
707 otp->timeout = timeout;
714 if (NIL_THD_IS_READY(ntp)) {
715 nil.current =
nil.next = ntp;
720 return nil.current->u1.msg;
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
857 nil.current->u1.msg = msg;
877 if (NIL_THD_IS_FINAL(tp)) {
881 nil.current->u1.tp = tp;
913 nil.current->u1.trp = trp;
932 chDbgAssert(NIL_THD_IS_SUSPENDED(tr),
"not suspended");
1017 nil.current->u1.tqp = tqp;
1059 if (tqp->cnt < (
cnt_t)0) {
thread_t * chSchReadyI(thread_t *tp, msg_t msg)
Makes the specified thread ready for execution.
#define CH_CFG_IDLE_LEAVE_HOOK()
Idle thread leave hook.
void chThdResume(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
#define chVTGetSystemTimeX()
Current system time.
static bool port_irq_enabled(syssts_t sts)
Checks the interrupt status.
void __dbg_check_unlock_from_isr(void)
Guard code for chSysUnlockFromIsr().
#define chTimeDiffX(start, end)
Subtracts two system times returning an interval.
port_stkalign_t stkalign_t
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.
void chDbgCheckClassS(void)
S-class functions context check.
#define CH_CFG_SYSTEM_HALT_HOOK(reason)
System halt hook.
#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().
void chThdSleep(sysinterval_t timeout)
Suspends the invoking thread for the specified time.
uint64_t systime_t
Type of system 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 chDbgAssert(c, r)
Condition assertion.
#define NIL_STATE_WTQUEUE
On queue or semaph.
#define CH_CFG_IDLE_ENTER_HOOK()
Idle thread enter hook.
stkalign_t * wend
Pointer to the working area end.
#define chSysLockFromISR()
Enters the kernel lock state from within an interrupt handler.
#define NIL_STATE_SUSPENDED
Thread suspended.
System instance data structure.
void __dbg_check_unlock(void)
Guard code for chSysUnlock().
void __dbg_check_enter_isr(void)
Guard code for CH_IRQ_PROLOGUE().
void chThdResumeS(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
static void port_unlock_from_isr(void)
Kernel-unlock action from an interrupt handler.
#define NIL_STATE_FINAL
Thread terminated.
void chSysPolledDelayX(rtcnt_t cycles)
Polled delay.
#define CH_CFG_THREAD_EXIT_HOOK(tp)
Threads finalization hook.
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.
static bool port_is_isr_context(void)
Determines the current execution context.
#define NIL_STATE_WTEXIT
Waiting a thread.
#define CH_CFG_SYSTEM_INIT_HOOK()
System initialization hook.
void chSysRestoreStatusX(syssts_t sts)
Restores the specified execution status and leaves a critical zone.
stkalign_t * wbase
Pointer to the working area base.
#define chSysGetRealtimeCounterX()
Returns the current value of the system real time counter.
void __dbg_check_leave_isr(void)
Guard code for CH_IRQ_EPILOGUE().
void chSysInit(void)
Initializes the kernel.
#define chDbgCheck(c)
Function parameters check.
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.
#define TIME_IMMEDIATE
Zero interval specification for some functions with a timeout specification.
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.
#define MEM_IS_ALIGNED(p, a)
Returns whatever a pointer or memory size is aligned.
tfunc_t funcp
Thread function pointer.
#define chSchIsRescRequiredI()
Evaluates if a reschedule is required.
Structure representing a thread.
#define chSysSuspend()
Raises the system interrupt priority mask to system level.
stkalign_t * wabase
Working area base address.
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.
void chSysHalt(const char *reason)
Halts the system.
#define CH_CFG_MAX_THREADS
Maximum number of user threads in the application.
void __dbg_check_lock_from_isr(void)
Guard code for chSysLockFromIsr().
static syssts_t port_get_irq_status(void)
Returns a word encoding the current interrupts status.
msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout)
Enqueues the caller thread on a threads queue object.
Type of a thread descriptor.
#define chThdSleepS(timeout)
Suspends the invoking thread for the specified time.
#define TIME_INFINITE
Infinite interval specification for all functions with a timeout specification.
void * arg
Thread argument.
thread_t * chThdCreateI(const thread_descriptor_t *tdp)
Creates a new thread into a static memory area.
void chSchDoPreemption(void)
Switches to the first thread on the runnable queue.
#define PORT_SETUP_CONTEXT(tp, wbase, wtop, pf, arg)
Platform dependent part of the chThdCreateI() API.
static void port_lock_from_isr(void)
Kernel-lock action from an interrupt handler.
#define MSG_OK
Normal wakeup message.
#define NIL_STATE_READY
Thread ready or executing.
void __dbg_check_disable(void)
Guard code for chSysDisable().
void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg)
Dequeues and wakes up all threads from the threads queue object.
thread_t * chThdCreate(const thread_descriptor_t *tdp)
Creates a new thread into a static memory area.
uint64_t sysinterval_t
Type of time interval.
static void port_disable(void)
Disables all the interrupt sources.
void __dbg_check_enable(void)
Guard code for chSysEnable().
tstate_t state
Current thread state.
#define chTimeAddX(systime, interval)
Adds an interval to a system time returning a system time.
#define PORT_WORKING_AREA_ALIGN
Working Areas alignment constant.
#define MSG_TIMEOUT
Wakeup caused by a timeout condition.
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 port_switch(ntp, otp)
Performs a context switch between two threads.
bool chTimeIsInRangeX(systime_t time, systime_t start, systime_t end)
Checks if the specified time is within the specified time range.
tprio_t prio
Thread priority.
#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 PORT_STACK_ALIGN
Stack alignment constant.
#define chSysLock()
Enters the kernel lock state.