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);
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)) {
410 tp->timeout = timeout;
415 if (NIL_THD_IS_WTQUEUE(tp)) {
419 if (NIL_THD_IS_SUSPENDED(tp)) {
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
689 port_timer_start_alarm(abstime);
696 port_timer_set_alarm(abstime);
707 otp->timeout = timeout;
714 if (NIL_THD_IS_READY(ntp)) {
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");
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.
const char *volatile dbg_panic_msg
Panic message.
#define chVTGetSystemTimeX()
Current system time.
thread_t * next
Pointer to the next thread to be executed.
static bool port_irq_enabled(syssts_t sts)
Checks the interrupt status.
#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.
void _dbg_check_unlock(void)
Guard code for chSysUnlock().
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.
volatile systime_t systime
System time.
cnt_t lock_cnt
Lock nesting level.
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
End of the working area.
#define chSysLockFromISR()
Enters the kernel lock state from within an interrupt handler.
#define NIL_STATE_SUSPENDED
Thread suspended.
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.
void _dbg_check_enable(void)
Guard code for chSysEnable().
#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_lock(void)
Guard code for chSysLock().
void _dbg_check_unlock_from_isr(void)
Guard code for chSysUnlockFromIsr().
void chSysInit(void)
Initializes the kernel.
nil_system_t nil
System data structures.
uint64_t stkalign_t
Type of stack and memory alignment enforcement.
#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.
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.
void chSchDoReschedule(void)
Switches to the first thread on the runnable queue.
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 _dbg_check_disable(void)
Guard code for chSysDisable().
void chSysHalt(const char *reason)
Halts the system.
void _dbg_check_enter_isr(void)
Guard code for CH_IRQ_PROLOGUE().
void _dbg_check_leave_isr(void)
Guard code for CH_IRQ_EPILOGUE().
#define CH_CFG_MAX_THREADS
Maximum number of user threads in the application.
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.
thread_t threads[CH_CFG_MAX_THREADS+1]
Thread structures for all the defined threads.
#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.
static void _oslib_init(void)
Initialization of all library modules.
cnt_t isr_cnt
ISR nesting level.
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.
tstate_t state
Current thread state.
thread_t * current
Pointer to the running thread.
void _dbg_check_lock_from_isr(void)
Guard code for chSysLockFromIsr().
#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 ...
systime_t lasttime
System time of the last tick event.
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.
#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.
systime_t nexttime
Time of the next scheduled tick event.
tprio_t prio
Thread priority.
#define chSysUnlock()
Leaves the kernel lock state.
#define CH_CFG_THREAD_EXT_INIT_HOOK(tr)
Threads initialization hook.
#define PORT_STACK_ALIGN
Stack alignment constant.
void _dbg_check_suspend(void)
Guard code for chSysSuspend().
#define chSysLock()
Enters the kernel lock state.