ChibiOS/RT
2.5.1
System Management
Collaboration diagram for System Management:

Detailed Description

System related APIs and services:

Functions

void chSysInit (void)
 ChibiOS/RT initialization.
void chSysTimerHandlerI (void)
 Handles time ticks for round robin preemption and timer increments.
 WORKING_AREA (_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE)
 Idle thread working area.
void _idle_thread (void *p)
 This function implements the idle thread infinite loop.

Macro Functions

#define chSysGetIdleThread()   (rlist.r_queue.p_prev)
 Returns a pointer to the idle thread.
#define chSysHalt()   port_halt()
 Halts the system.
#define chSysSwitch(ntp, otp)
 Performs a context switch.
#define chSysDisable()
 Raises the system interrupt priority mask to the maximum level.
#define chSysSuspend()
 Raises the system interrupt priority mask to system level.
#define chSysEnable()
 Lowers the system interrupt priority mask to user level.
#define chSysLock()
 Enters the kernel lock mode.
#define chSysUnlock()
 Leaves the kernel lock mode.
#define chSysLockFromIsr()
 Enters the kernel lock mode from within an interrupt handler.
#define chSysUnlockFromIsr()
 Leaves the kernel lock mode from within an interrupt handler.

ISRs abstraction macros

#define CH_IRQ_PROLOGUE()
 IRQ handler enter code.
#define CH_IRQ_EPILOGUE()
 IRQ handler exit code.
#define CH_IRQ_HANDLER(id)   PORT_IRQ_HANDLER(id)
 Standard normal IRQ handler declaration.

Fast ISRs abstraction macros

#define CH_FAST_IRQ_HANDLER(id)   PORT_FAST_IRQ_HANDLER(id)
 Standard fast IRQ handler declaration.

Function Documentation

void chSysInit ( void  )

ChibiOS/RT initialization.

After executing this function the current instructions stream becomes the main thread.

Precondition:
Interrupts must be still disabled when chSysInit() is invoked and are internally enabled.
Postcondition:
The main thread is created with priority NORMALPRIO.
Note:
This function has special, architecture-dependent, requirements, see the notes into the various port reference manuals.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 77 of file chsys.c.

References _core_init(), _heap_init(), _idle_thread(), _scheduler_init(), _thread_init(), _trace_init(), _vt_init(), chRegSetThreadName, chSysEnable, chThdCreateStatic(), currp, IDLEPRIO, NORMALPRIO, port_init, setcurrp, and THD_STATE_CURRENT.

Here is the call graph for this function:

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.

Note:
The frequency of the timer determines the system tick granularity and, together with the CH_TIME_QUANTUM macro, the round robin interval.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 130 of file chsys.c.

References chDbgCheckClassI(), chVTDoTickI, currp, and SYSTEM_TICK_EVENT_HOOK.

Here is the call graph for this function:

WORKING_AREA ( _idle_thread_wa  ,
PORT_IDLE_THREAD_STACK_SIZE   
)

Idle thread working area.

void _idle_thread ( void *  p)

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.

Parameters:
[in]pthe thread parameter, unused in this scenario

Definition at line 54 of file chsys.c.

References chRegSetThreadName, IDLE_LOOP_HOOK, port_wait_for_interrupt, and TRUE.

Referenced by chSysInit().


Define Documentation

#define chSysGetIdleThread ( )    (rlist.r_queue.p_prev)

Returns a pointer to the idle thread.

Precondition:
In order to use this function the option CH_NO_IDLE_THREAD must be disabled.
Note:
The reference counter of the idle thread is not incremented but it is not strictly required being the idle thread a static object.
Returns:
Pointer to the idle thread.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 49 of file chsys.h.

#define chSysHalt ( )    port_halt()

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.

Note:
Can be invoked from any system state.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 63 of file chsys.h.

Referenced by chDbgPanic().

#define chSysSwitch (   ntp,
  otp 
)
Value:
{                                             \
  dbg_trace(otp);                                                           \
  THREAD_CONTEXT_SWITCH_HOOK(ntp, otp);                                     \
  port_switch(ntp, otp);                                                    \
}

Performs a context switch.

Note:
Not a user function, it is meant to be invoked by the scheduler itself or from within the port layer.
Parameters:
[in]ntpthe thread to be switched in
[in]otpthe thread to be switched out
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 81 of file chsys.h.

Referenced by chSchDoRescheduleBehind(), chSchGoSleepS(), and chSchWakeupS().

#define chSysDisable ( )
Value:

Raises the system interrupt priority mask to the maximum level.

All the maskable interrupt sources are disabled regardless their hardware priority.

Note:
Do not invoke this API from within a kernel lock.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 95 of file chsys.h.

#define chSysSuspend ( )
Value:

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.

Note:
Do not invoke this API from within a kernel lock.
This API is no replacement for chSysLock(), the chSysLock() could do more than just disable the interrupts.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 111 of file chsys.h.

#define chSysEnable ( )
Value:
{                                                     \
  dbg_check_enable();                                                       \
  port_enable();                                                            \
}

Lowers the system interrupt priority mask to user level.

All the interrupt sources are enabled.

Note:
Do not invoke this API from within a kernel lock.
This API is no replacement for chSysUnlock(), the chSysUnlock() could do more than just enable the interrupts.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 125 of file chsys.h.

Referenced by chSysInit().

#define chSysLockFromIsr ( )
Value:

Enters the kernel lock mode from within an interrupt handler.

Note:
This API may do nothing on some architectures, it is required because on ports that support preemptable interrupt handlers it is required to raise the interrupt mask to the same level of the system mutual exclusion zone.
It is good practice to invoke this API before invoking any I-class syscall from an interrupt handler.
This API must be invoked exclusively from interrupt handlers.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 162 of file chsys.h.

#define chSysUnlockFromIsr ( )
Value:

Leaves the kernel lock mode from within an interrupt handler.

Note:
This API may do nothing on some architectures, it is required because on ports that support preemptable interrupt handlers it is required to raise the interrupt mask to the same level of the system mutual exclusion zone.
It is good practice to invoke this API after invoking any I-class syscall from an interrupt handler.
This API must be invoked exclusively from interrupt handlers.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 180 of file chsys.h.

#define CH_IRQ_PROLOGUE ( )
Value:

IRQ handler enter code.

Note:
Usually IRQ handlers functions are also declared naked.
On some architectures this macro can be empty.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 196 of file chsys.h.

#define CH_IRQ_EPILOGUE ( )
Value:

IRQ handler exit code.

Note:
Usually IRQ handlers function are also declared naked.
This macro usually performs the final reschedule by using chSchIsPreemptionRequired() and chSchDoReschedule().
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 208 of file chsys.h.

#define CH_IRQ_HANDLER (   id)    PORT_IRQ_HANDLER(id)

Standard normal IRQ handler declaration.

Note:
id can be a function name or a vector number depending on the port implementation.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 219 of file chsys.h.

#define CH_FAST_IRQ_HANDLER (   id)    PORT_FAST_IRQ_HANDLER(id)

Standard fast IRQ handler declaration.

Note:
id can be a function name or a vector number depending on the port implementation.
Not all architectures support fast interrupts.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 233 of file chsys.h.