ChibiOS/RT
5.1.0
|
System related APIs and services:
Macros | |
#define | chSysGetRealtimeCounterX() (rtcnt_t)port_rt_get_counter_value() |
Returns the current value of the system real time counter. More... | |
#define | chSysSwitch(ntp, otp) |
Performs a context switch. More... | |
Masks of executable integrity checks. | |
#define | CH_INTEGRITY_RLIST 1U |
#define | CH_INTEGRITY_VTLIST 2U |
#define | CH_INTEGRITY_REGISTRY 4U |
#define | CH_INTEGRITY_PORT 8U |
ISRs abstraction macros | |
#define | CH_IRQ_IS_VALID_PRIORITY(prio) PORT_IRQ_IS_VALID_PRIORITY(prio) |
Priority level validation macro. More... | |
#define | CH_IRQ_IS_VALID_KERNEL_PRIORITY(prio) PORT_IRQ_IS_VALID_KERNEL_PRIORITY(prio) |
Priority level validation macro. More... | |
#define | CH_IRQ_PROLOGUE() |
IRQ handler enter code. More... | |
#define | CH_IRQ_EPILOGUE() |
IRQ handler exit code. More... | |
#define | CH_IRQ_HANDLER(id) PORT_IRQ_HANDLER(id) |
Standard normal IRQ handler declaration. More... | |
Fast ISRs abstraction macros | |
#define | CH_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id) |
Standard fast IRQ handler declaration. More... | |
Time conversion utilities for the realtime counter | |
#define | S2RTC(freq, sec) ((freq) * (sec)) |
Seconds to realtime counter. More... | |
#define | MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec)) |
Milliseconds to realtime counter. More... | |
#define | US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec)) |
Microseconds to realtime counter. More... | |
#define | RTC2S(freq, n) ((((n) - 1UL) / (freq)) + 1UL) |
Realtime counter cycles to seconds. More... | |
#define | RTC2MS(freq, n) ((((n) - 1UL) / ((freq) / 1000UL)) + 1UL) |
Realtime counter cycles to milliseconds. More... | |
#define | RTC2US(freq, n) ((((n) - 1UL) / ((freq) / 1000000UL)) + 1UL) |
Realtime counter cycles to microseconds. More... | |
Functions | |
THD_WORKING_AREA (ch_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE) | |
Idle thread working area. More... | |
static void | _idle_thread (void *p) |
This function implements the idle thread infinite loop. More... | |
void | chSysInit (void) |
ChibiOS/RT initialization. More... | |
void | chSysHalt (const char *reason) |
Halts the system. More... | |
bool | chSysIntegrityCheckI (unsigned testmask) |
System integrity check. More... | |
void | chSysTimerHandlerI (void) |
Handles time ticks for round robin preemption and timer increments. More... | |
syssts_t | chSysGetStatusAndLockX (void) |
Returns the execution status and enters a critical zone. More... | |
void | chSysRestoreStatusX (syssts_t sts) |
Restores the specified execution status and leaves a critical zone. More... | |
bool | chSysIsCounterWithinX (rtcnt_t cnt, rtcnt_t start, rtcnt_t end) |
Realtime window test. More... | |
void | chSysPolledDelayX (rtcnt_t cycles) |
Polled delay. More... | |
static void | chSysDisable (void) |
Raises the system interrupt priority mask to the maximum level. More... | |
static void | chSysSuspend (void) |
Raises the system interrupt priority mask to system level. More... | |
static void | chSysEnable (void) |
Lowers the system interrupt priority mask to user level. More... | |
static void | chSysLock (void) |
Enters the kernel lock state. More... | |
static void | chSysUnlock (void) |
Leaves the kernel lock state. More... | |
static void | chSysLockFromISR (void) |
Enters the kernel lock state from within an interrupt handler. More... | |
static void | chSysUnlockFromISR (void) |
Leaves the kernel lock state from within an interrupt handler. More... | |
static void | chSysUnconditionalLock (void) |
Unconditionally enters the kernel lock state. More... | |
static void | chSysUnconditionalUnlock (void) |
Unconditionally leaves the kernel lock state. More... | |
static thread_t * | chSysGetIdleThreadX (void) |
Returns a pointer to the idle thread. More... | |
#define CH_IRQ_IS_VALID_PRIORITY | ( | prio | ) | PORT_IRQ_IS_VALID_PRIORITY(prio) |
Priority level validation macro.
This macro determines if the passed value is a valid priority level for the underlying architecture.
[in] | prio | the priority level |
false | if the priority is invalid or if the architecture does not support priorities. |
true | if the priority is valid. |
#define CH_IRQ_IS_VALID_KERNEL_PRIORITY | ( | prio | ) | PORT_IRQ_IS_VALID_KERNEL_PRIORITY(prio) |
Priority level validation macro.
This macro determines if the passed value is a valid priority level that cannot preempt the kernel critical zone.
[in] | prio | the priority level |
false | if the priority is invalid or if the architecture does not support priorities. |
true | if the priority is valid. |
#define CH_IRQ_PROLOGUE | ( | ) |
IRQ handler enter code.
#define CH_IRQ_EPILOGUE | ( | ) |
IRQ handler exit code.
chSchIsPreemptionRequired()
and chSchDoReschedule()
.#define CH_IRQ_HANDLER | ( | id | ) | PORT_IRQ_HANDLER(id) |
#define CH_FAST_IRQ_HANDLER | ( | id | ) | PORT_FAST_IRQ_HANDLER(id) |
#define S2RTC | ( | freq, | |
sec | |||
) | ((freq) * (sec)) |
Seconds to realtime counter.
Converts from seconds to realtime counter cycles.
freq
>= 1
.[in] | freq | clock frequency, in Hz, of the realtime counter |
[in] | sec | number of seconds |
#define MS2RTC | ( | freq, | |
msec | |||
) | (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec)) |
Milliseconds to realtime counter.
Converts from milliseconds to realtime counter cycles.
freq
>= 1000
.[in] | freq | clock frequency, in Hz, of the realtime counter |
[in] | msec | number of milliseconds |
#define US2RTC | ( | freq, | |
usec | |||
) | (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec)) |
Microseconds to realtime counter.
Converts from microseconds to realtime counter cycles.
freq
>= 1000000
.[in] | freq | clock frequency, in Hz, of the realtime counter |
[in] | usec | number of microseconds |
#define RTC2S | ( | freq, | |
n | |||
) | ((((n) - 1UL) / (freq)) + 1UL) |
Realtime counter cycles to seconds.
Converts from realtime counter cycles number to seconds.
freq
>= 1
.[in] | freq | clock frequency, in Hz, of the realtime counter |
[in] | n | number of cycles |
#define RTC2MS | ( | freq, | |
n | |||
) | ((((n) - 1UL) / ((freq) / 1000UL)) + 1UL) |
Realtime counter cycles to milliseconds.
Converts from realtime counter cycles number to milliseconds.
freq
>= 1000
.[in] | freq | clock frequency, in Hz, of the realtime counter |
[in] | n | number of cycles |
#define RTC2US | ( | freq, | |
n | |||
) | ((((n) - 1UL) / ((freq) / 1000000UL)) + 1UL) |
Realtime counter cycles to microseconds.
Converts from realtime counter cycles number to microseconds.
freq
>= 1000000
.[in] | freq | clock frequency, in Hz, of the realtime counter |
[in] | n | number of cycles |
#define chSysGetRealtimeCounterX | ( | ) | (rtcnt_t)port_rt_get_counter_value() |
Returns the current value of the system real time counter.
PORT_SUPPORTS_RT
.Definition at line 253 of file chsys.h.
Referenced by chSysPolledDelayX(), chTMChainMeasurementToX(), chTMStartMeasurementX(), chTMStopMeasurementX(), and trace_next().
#define chSysSwitch | ( | ntp, | |
otp | |||
) |
Performs a context switch.
[in] | ntp | the thread to be switched in |
[in] | otp | the thread to be switched out |
Definition at line 266 of file chsys.h.
Referenced by chSchDoReschedule(), chSchDoRescheduleAhead(), chSchDoRescheduleBehind(), chSchGoSleepS(), and chSchWakeupS().
THD_WORKING_AREA | ( | ch_idle_thread_wa | , |
PORT_IDLE_THREAD_STACK_SIZE | |||
) |
Idle thread working area.
|
static |
This function implements the idle thread infinite loop.
The function puts the processor in the lowest power mode capable to serve interrupts.
The priority is internally set to the minimum system value so that this thread is executed only if there are no other ready threads in the system.
[in] | p | the thread parameter, unused in this scenario |
Definition at line 72 of file chsys.c.
References CH_CFG_IDLE_LOOP_HOOK.
Referenced by chSysInit().
void chSysInit | ( | void | ) |
ChibiOS/RT initialization.
After executing this function the current instructions stream becomes the main thread.
NORMALPRIO
and interrupts are enabled.Definition at line 100 of file chsys.c.
References _core_init(), _factory_init(), _heap_init(), _idle_thread(), _scheduler_init(), _stats_init(), _thread_init(), _tm_init(), _trace_init(), _vt_init(), ch, CH_CFG_SYSTEM_INIT_HOOK, CH_STATE_CURRENT, chSysEnable(), chThdCreate(), chTMStartMeasurementX(), currp, ch_system::dbg, IDLEPRIO, ch_system_debug::isr_cnt, ch_system_debug::lock_cnt, ch_system::mainthread, NORMALPRIO, THD_WORKING_AREA_BASE, and THD_WORKING_AREA_END.
void chSysHalt | ( | const char * | reason | ) |
Halts the system.
This function is invoked by the operating system when an unrecoverable error is detected, for example because a programming error in the application code that triggers an assertion while in debug mode.
[in] | reason | pointer to an error string |
Definition at line 198 of file chsys.c.
References _trace_halt(), ch, CH_CFG_SYSTEM_HALT_HOOK, ch_system::dbg, and ch_system_debug::panic_msg.
Referenced by _dbg_check_disable(), _dbg_check_enable(), _dbg_check_enter_isr(), _dbg_check_leave_isr(), _dbg_check_lock(), _dbg_check_lock_from_isr(), _dbg_check_suspend(), _dbg_check_unlock(), _dbg_check_unlock_from_isr(), chDbgCheckClassI(), and chDbgCheckClassS().
bool chSysIntegrityCheckI | ( | unsigned | testmask | ) |
System integrity check.
Performs an integrity check of the important ChibiOS/RT data structures.
NULL
or corrupted pointers in list elements. Exception vectors must be monitored as well. [in] | testmask | Each bit in this mask is associated to a test to be performed. |
false | The test succeeded. |
true | Test failed. |
Definition at line 240 of file chsys.c.
References ch, chDbgCheckClassI(), ch_thread::newer, ch_threads_queue::next, ch_virtual_timer::next, ch_virtual_timers_list::next, ch_thread::older, ch_threads_queue::prev, ch_virtual_timer::prev, ch_virtual_timers_list::prev, ch_thread::queue, ch_system::rlist, and ch_system::vtlist.
void chSysTimerHandlerI | ( | void | ) |
Handles time ticks for round robin preemption and timer increments.
Decrements the remaining time quantum of the running thread and preempts it when the quantum is used up. Increments system time and manages the timers.
CH_CFG_TIME_QUANTUM
macro, the round robin interval.Definition at line 341 of file chsys.c.
References CH_CFG_SYSTEM_TICK_HOOK, chDbgCheckClassI(), chVTDoTickI(), and currp.
syssts_t chSysGetStatusAndLockX | ( | void | ) |
Returns the execution status and enters a critical zone.
This functions enters into a critical zone and can be called from any context. Because its flexibility it is less efficient than chSysLock()
which is preferable when the calling context is known.
Definition at line 372 of file chsys.c.
References chSysLock(), and chSysLockFromISR().
void chSysRestoreStatusX | ( | syssts_t | sts | ) |
Restores the specified execution status and leaves a critical zone.
chSchRescheduleS()
is automatically performed if exiting the critical zone and if not in ISR context.[in] | sts | the system status to be restored. |
Definition at line 395 of file chsys.c.
References chSchRescheduleS(), chSysUnlock(), and chSysUnlockFromISR().
bool chSysIsCounterWithinX | ( | rtcnt_t | cnt, |
rtcnt_t | start, | ||
rtcnt_t | end | ||
) |
Realtime window test.
This function verifies if the current realtime counter value lies within the specified range or not. The test takes care of the realtime counter wrapping to zero on overflow.
PORT_SUPPORTS_RT
.[in] | cnt | the counter value to be tested |
[in] | start | the start of the time window (inclusive) |
[in] | end | the end of the time window (non inclusive) |
true | current time within the specified time window. |
false | current time not within the specified time window. |
Definition at line 427 of file chsys.c.
Referenced by chSysPolledDelayX().
void chSysPolledDelayX | ( | rtcnt_t | cycles | ) |
Polled delay.
PORT_SUPPORTS_RT
.[in] | cycles | number of cycles |
Definition at line 443 of file chsys.c.
References chSysGetRealtimeCounterX, and chSysIsCounterWithinX().
|
inlinestatic |
Raises the system interrupt priority mask to the maximum level.
All the maskable interrupt sources are disabled regardless their hardware priority.
Definition at line 310 of file chsys.h.
References _dbg_check_disable().
|
inlinestatic |
Raises the system interrupt priority mask to system level.
The interrupt sources that should not be able to preempt the kernel are disabled, interrupt sources with higher priority are still enabled.
chSysLock()
, the chSysLock()
could do more than just disable the interrupts.Definition at line 327 of file chsys.h.
References _dbg_check_suspend().
|
inlinestatic |
Lowers the system interrupt priority mask to user level.
All the interrupt sources are enabled.
chSysUnlock()
, the chSysUnlock()
could do more than just enable the interrupts.Definition at line 342 of file chsys.h.
References _dbg_check_enable().
Referenced by chSysInit().
|
inlinestatic |
Enters the kernel lock state.
Definition at line 353 of file chsys.h.
References _dbg_check_lock(), and _stats_start_measure_crit_thd().
Referenced by chBSemSignal(), chCondBroadcast(), chCondSignal(), chCondWait(), chCondWaitTimeout(), chCoreAllocAligned(), chCoreAllocAlignedWithOffset(), chDbgResumeTrace(), chDbgSuspendTrace(), chDbgWriteTrace(), chEvtAddEvents(), chEvtBroadcastFlags(), chEvtGetAndClearEvents(), chEvtGetAndClearFlags(), chEvtRegisterMaskWithFlags(), chEvtSignal(), chEvtUnregister(), chEvtWaitAll(), chEvtWaitAllTimeout(), chEvtWaitAny(), chEvtWaitAnyTimeout(), chEvtWaitOne(), chEvtWaitOneTimeout(), chGuardedPoolAllocTimeout(), chGuardedPoolFree(), chMBFetchTimeout(), chMBPostAheadTimeout(), chMBPostTimeout(), chMBReset(), chMsgRelease(), chMsgSend(), chMsgWait(), chMtxLock(), chMtxTryLock(), chMtxUnlock(), chMtxUnlockAll(), chPoolAlloc(), chPoolFree(), chRegFirstThread(), chRegNextThread(), chSemReset(), chSemSignal(), chSemSignalWait(), chSemWait(), chSemWaitTimeout(), chSysGetStatusAndLockX(), chSysUnconditionalLock(), chThdAddRef(), chThdCreate(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), chThdCreateSuspended(), chThdExit(), chThdRelease(), chThdResume(), chThdSetPriority(), chThdSleep(), chThdSleepUntil(), chThdSleepUntilWindowed(), chThdStart(), chThdTerminate(), chThdWait(), chThdYield(), chVTGetSystemTime(), chVTIsArmed(), chVTReset(), and chVTSet().
|
inlinestatic |
Leaves the kernel lock state.
Definition at line 365 of file chsys.h.
References _dbg_check_unlock(), _stats_stop_measure_crit_thd(), ch, chDbgAssert, and ch_system::rlist.
Referenced by chBSemSignal(), chCondBroadcast(), chCondSignal(), chCondWait(), chCondWaitTimeout(), chCoreAllocAligned(), chCoreAllocAlignedWithOffset(), chDbgResumeTrace(), chDbgSuspendTrace(), chDbgWriteTrace(), chEvtAddEvents(), chEvtBroadcastFlags(), chEvtGetAndClearEvents(), chEvtGetAndClearFlags(), chEvtRegisterMaskWithFlags(), chEvtSignal(), chEvtUnregister(), chEvtWaitAll(), chEvtWaitAllTimeout(), chEvtWaitAny(), chEvtWaitAnyTimeout(), chEvtWaitOne(), chEvtWaitOneTimeout(), chGuardedPoolAllocTimeout(), chGuardedPoolFree(), chMBFetchTimeout(), chMBPostAheadTimeout(), chMBPostTimeout(), chMBReset(), chMsgRelease(), chMsgSend(), chMsgWait(), chMtxLock(), chMtxTryLock(), chMtxUnlock(), chMtxUnlockAll(), chPoolAlloc(), chPoolFree(), chRegFirstThread(), chRegNextThread(), chSemReset(), chSemSignal(), chSemSignalWait(), chSemWait(), chSemWaitTimeout(), chSysRestoreStatusX(), chSysUnconditionalUnlock(), chThdAddRef(), chThdCreate(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), chThdCreateSuspended(), chThdRelease(), chThdResume(), chThdSetPriority(), chThdSleep(), chThdSleepUntil(), chThdSleepUntilWindowed(), chThdStart(), chThdTerminate(), chThdWait(), chThdYield(), chVTGetSystemTime(), chVTIsArmed(), chVTReset(), and chVTSet().
|
inlinestatic |
Enters the kernel lock state from within an interrupt handler.
Definition at line 393 of file chsys.h.
References _dbg_check_lock_from_isr(), and _stats_start_measure_crit_isr().
Referenced by chSchGoSleepS(), chSysGetStatusAndLockX(), and chVTDoTickI().
|
inlinestatic |
Leaves the kernel lock state from within an interrupt handler.
Definition at line 413 of file chsys.h.
References _dbg_check_unlock_from_isr(), and _stats_stop_measure_crit_isr().
Referenced by chSchGoSleepS(), chSysRestoreStatusX(), and chVTDoTickI().
|
inlinestatic |
Unconditionally enters the kernel lock state.
Definition at line 427 of file chsys.h.
References chSysLock().
|
inlinestatic |
Unconditionally leaves the kernel lock state.
Definition at line 441 of file chsys.h.
References chSysUnlock().
|
inlinestatic |
Returns a pointer to the idle thread.
CH_CFG_NO_IDLE_THREAD
must be disabled. Definition at line 461 of file chsys.h.
References ch, and ch_system::rlist.