ChibiOS/RT Logo ChibiOS/RT

Architecture - Reference Manual - Guides

Defines | Functions

System Management
[Base Kernel Services]

Collaboration diagram for System Management:


Description

System related APIs and services:

Defines

#define chSysHalt()   port_halt()
 Halts the system.
#define chSysSwitchI(ntp, otp)   port_switch(ntp, otp)
 Performs a context switch.
#define chSysDisable()   port_disable()
 Raises the system interrupt priority mask to the maximum level.
#define chSysSuspend()   port_suspend()
 Raises the system interrupt priority mask to system level.
#define chSysEnable()   port_enable()
 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()   port_lock_from_isr()
 Enters the kernel lock mode from within an interrupt handler.
#define chSysUnlockFromIsr()   port_unlock_from_isr()
 Leaves the kernel lock mode from within an interrupt handler.
#define CH_IRQ_PROLOGUE()   PORT_IRQ_PROLOGUE()
 IRQ handler enter code.
#define CH_IRQ_EPILOGUE()   PORT_IRQ_EPILOGUE()
 IRQ handler exit code.
#define CH_IRQ_HANDLER(id)   PORT_IRQ_HANDLER(id)
 Standard normal IRQ handler declaration.
#define CH_FAST_IRQ_HANDLER(id)   PORT_FAST_IRQ_HANDLER(id)
 Standard fast IRQ handler declaration.

Functions

void chSysInit (void)
 ChibiOS/RT initialization.
void chSysTimerHandlerI (void)
 Handles time ticks for round robin preemption and timer increments.

Define Documentation

#define chSysHalt (  )     port_halt()

Halts the system.

This function is invoked by the operating system when an unrecoverable error is detected, as example because a programming error in the application code that triggers an assertion while in debug mode.

Definition at line 45 of file chsys.h.

Referenced by chDbgPanic().

#define chSysSwitchI (   ntp,
  otp 
)    port_switch(ntp, otp)

Performs a context switch.

Parameters:
[in] ntp the thread to be switched in
[in] otp the thread to be switched out

Definition at line 53 of file chsys.h.

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

#define chSysDisable (  )     port_disable()

Raises the system interrupt priority mask to the maximum level.

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

Note:
The implementation is architecture dependent, it may just disable the interrupts or be exactly equivalent to chSysDisable().
Do not invoke this API from within a kernel lock.

Definition at line 63 of file chsys.h.

#define chSysSuspend (  )     port_suspend()

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:
The implementation is architecture dependent, it may just disable the interrupts.
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.

Definition at line 76 of file chsys.h.

#define chSysEnable (  )     port_enable()

Lowers the system interrupt priority mask to user level.

All the interrupt sources are enabled.

Note:
The implementation is architecture dependent, it may just enable the interrupts.
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.

Definition at line 87 of file chsys.h.

Referenced by chSysInit().

#define chSysLock (  ) 
Value:
{                                                   \
  if (currp->p_locks++ == 0)                                            \
    port_lock();                                                        \
}

Enters the kernel lock mode.

Note:
The use of kernel lock mode is not recommended in the user code, it is a better idea to use the semaphores or mutexes instead.
See also:
CH_USE_NESTED_LOCKS

Definition at line 97 of file chsys.h.

Referenced by adcStart(), adcStartConversion(), adcStop(), adcStopConversion(), adcWaitConversion(), canGetAndClearFlags(), canReceive(), canSleep(), canStart(), canStop(), canTransmit(), canWakeup(), chCondBroadcast(), chCondSignal(), chCondWait(), chCondWaitTimeout(), chCoreAlloc(), chEvtBroadcast(), chEvtClear(), chEvtPend(), chEvtRegisterMask(), chEvtSignal(), chEvtUnregister(), chEvtWaitAll(), chEvtWaitAllTimeout(), chEvtWaitAny(), chEvtWaitAnyTimeout(), chEvtWaitOne(), chEvtWaitOneTimeout(), chIQGetTimeout(), chIQReadTimeout(), chMBFetch(), chMBPost(), chMBPostAhead(), chMBReset(), chMsgGet(), chMsgRelease(), chMsgSend(), chMsgWait(), chMtxLock(), chMtxTryLock(), chMtxUnlock(), chMtxUnlockAll(), chOQPutTimeout(), chOQWriteTimeout(), chPoolAlloc(), chPoolFree(), chRegFirstThread(), chRegNextThread(), chSemReset(), chSemSignal(), chSemSignalWait(), chSemWait(), chSemWaitTimeout(), chThdAddRef(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), chThdExit(), chThdRelease(), chThdResume(), chThdSetPriority(), chThdSleep(), chThdSleepUntil(), chThdTerminate(), chThdWait(), chThdYield(), chibios_rt::System::Lock(), macWaitReceiveDescriptor(), macWaitTransmitDescriptor(), mmcConnect(), mmcDisconnect(), mmcSequentialRead(), mmcSequentialWrite(), mmcStart(), mmcStartSequentialRead(), mmcStartSequentialWrite(), mmcStop(), mmcStopSequentialRead(), mmcStopSequentialWrite(), pwmDisableChannel(), pwmEnableChannel(), pwmStart(), pwmStop(), sdGetAndClearFlags(), sdStart(), sdStop(), spiSelect(), spiStart(), spiStop(), and spiUnselect().

#define chSysUnlock (  ) 
Value:
{                                                 \
  if (--currp->p_locks == 0)                                            \
    port_unlock();                                                      \
}

Leaves the kernel lock mode.

Note:
The use of kernel lock mode is not recommended in the user code, it is a better idea to use the semaphores or mutexes instead.
See also:
CH_USE_NESTED_LOCKS

Definition at line 114 of file chsys.h.

Referenced by adcStart(), adcStartConversion(), adcStop(), adcStopConversion(), adcWaitConversion(), canGetAndClearFlags(), canReceive(), canSleep(), canStart(), canStop(), canTransmit(), canWakeup(), chCondBroadcast(), chCondSignal(), chCondWait(), chCondWaitTimeout(), chCoreAlloc(), chEvtBroadcast(), chEvtClear(), chEvtPend(), chEvtRegisterMask(), chEvtSignal(), chEvtUnregister(), chEvtWaitAll(), chEvtWaitAllTimeout(), chEvtWaitAny(), chEvtWaitAnyTimeout(), chEvtWaitOne(), chEvtWaitOneTimeout(), chIQGetTimeout(), chIQReadTimeout(), chMBFetch(), chMBPost(), chMBPostAhead(), chMBReset(), chMsgGet(), chMsgRelease(), chMsgSend(), chMsgWait(), chMtxLock(), chMtxTryLock(), chMtxUnlock(), chMtxUnlockAll(), chOQPutTimeout(), chOQWriteTimeout(), chPoolAlloc(), chPoolFree(), chRegFirstThread(), chRegNextThread(), chSemReset(), chSemSignal(), chSemSignalWait(), chSemWait(), chSemWaitTimeout(), chThdAddRef(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), chThdRelease(), chThdResume(), chThdSetPriority(), chThdSleep(), chThdSleepUntil(), chThdTerminate(), chThdWait(), chThdYield(), macWaitReceiveDescriptor(), macWaitTransmitDescriptor(), mmcConnect(), mmcDisconnect(), mmcSequentialRead(), mmcSequentialWrite(), mmcStart(), mmcStartSequentialRead(), mmcStartSequentialWrite(), mmcStop(), mmcStopSequentialRead(), mmcStopSequentialWrite(), pwmDisableChannel(), pwmEnableChannel(), pwmStart(), pwmStop(), sdGetAndClearFlags(), sdStart(), sdStop(), spiSelect(), spiStart(), spiStop(), spiUnselect(), and chibios_rt::System::Unlock().

#define chSysLockFromIsr (  )     port_lock_from_isr()

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.

Definition at line 133 of file chsys.h.

Referenced by CH_IRQ_HANDLER().

#define chSysUnlockFromIsr (  )     port_unlock_from_isr()

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.

Definition at line 146 of file chsys.h.

Referenced by CH_IRQ_HANDLER().

#define CH_IRQ_PROLOGUE (  )     PORT_IRQ_PROLOGUE()

IRQ handler enter code.

Note:
Usually IRQ handlers functions are also declared naked.
On some architectures this macro can be empty.

Definition at line 153 of file chsys.h.

Referenced by CH_IRQ_HANDLER().

#define CH_IRQ_EPILOGUE (  )     PORT_IRQ_EPILOGUE()

IRQ handler exit code.

Note:
Usually IRQ handlers function are also declared naked.
This macro usually performs the final reschedule by using chSchRescRequiredI() and chSchDoRescheduleI().

Definition at line 161 of file chsys.h.

Referenced by CH_IRQ_HANDLER().

#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.

Definition at line 168 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.

Definition at line 176 of file chsys.h.


Function Documentation

void chSysInit ( void   ) 

ChibiOS/RT initialization.

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

Note:
Interrupts should be still disabled when chSysInit() is invoked and are internally enabled.
The main thread is created with priority NORMALPRIO.

Definition at line 73 of file chsys.c.

References chSysEnable, chThdCreateStatic(), core_init(), currp, heap_init(), IDLEPRIO, init_thread(), NORMALPRIO, port_init(), scheduler_init(), setcurrp, trace_init(), and vt_init().

Referenced by chibios_rt::System::Init().

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.

Definition at line 111 of file chsys.c.

References chVTDoTickI, currp, and rlist.

Referenced by CH_IRQ_HANDLER().


Generated on Sun Oct 24 2010 09:40:46 for ChibiOS/RT by doxygen 1.7.1