ChibiOS 21.11.4
Port Core

Detailed Description

Non portable code templates.

Collaboration diagram for Port Core:

Port Capabilities and Constants

#define PORT_SUPPORTS_RT   FALSE
 This port supports a realtime counter.
#define PORT_NATURAL_ALIGN   sizeof (void *)
 Natural alignment constant.
#define PORT_STACK_ALIGN   sizeof (stkalign_t)
 Stack alignment constant.
#define PORT_WORKING_AREA_ALIGN   sizeof (stkalign_t)
 Working Areas alignment constant.

Architecture and Compiler

#define PORT_ARCHITECTURE_XXX
 Macro defining an XXX architecture.
#define PORT_ARCHITECTURE_XXX_YYY
 Macro defining the specific XXX architecture.
#define PORT_ARCHITECTURE_NAME   "XXX Architecture"
 Name of the implemented architecture.
#define PORT_COMPILER_NAME   "GCC " __VERSION__
 Compiler name and version.
#define PORT_INFO   "no info"
 Port-specific information string.

Data Structures

struct  port_extctx
 Interrupt saved context. More...
struct  port_intctx
 System saved context. More...
struct  port_context
 Platform dependent part of the thread_t structure. More...

Macros

#define PORT_IDLE_THREAD_STACK_SIZE   32
 Stack size for the system idle thread.
#define PORT_INT_REQUIRED_STACK   256
 Per-thread stack overhead for interrupts servicing.
#define PORT_XXX_ENABLE_WFI_IDLE   FALSE
 Enables a "wait for interrupt" instruction in the idle loop.
#define PORT_THD_FUNCTION(tname, arg)
 Optimized thread function declaration macro.
#define PORT_SETUP_CONTEXT(tp, wbase, wtop, pf, arg)
 Platform dependent part of the chThdCreateI() API.
#define PORT_WA_SIZE(n)
 Computes the thread working area global size.
#define PORT_WORKING_AREA(s, n)
 Static working area allocation.
#define PORT_IRQ_IS_VALID_PRIORITY(n)
 Priority level verification macro.
#define PORT_IRQ_IS_VALID_KERNEL_PRIORITY(n)
 Priority level verification macro.
#define PORT_IRQ_PROLOGUE()
 IRQ prologue code.
#define PORT_IRQ_EPILOGUE()
 IRQ epilogue code.
#define PORT_IRQ_HANDLER(id)
 IRQ handler function declaration.
#define PORT_FAST_IRQ_HANDLER(id)
 Fast IRQ handler function declaration.
#define port_switch(ntp, otp)
 Performs a context switch between two threads.
#define port_get_lock_status()
 Returns a word representing a critical section status.
#define port_is_locked(sts)
 Determines if in a critical section.

Functions

void _port_init (void)
 Port-related initialization code.
void _port_switch (thread_t *ntp, thread_t *otp)
 Performs a context switch between two threads.
static bool port_is_isr_context (void)
 Determines the current execution context.
static void port_lock (void)
 Kernel-lock action.
static void port_unlock (void)
 Kernel-unlock action.
static void port_lock_from_isr (void)
 Kernel-lock action from an interrupt handler.
static void port_unlock_from_isr (void)
 Kernel-unlock action from an interrupt handler.
static void port_disable (void)
 Disables all the interrupt sources.
static void port_suspend (void)
 Disables the interrupt sources below kernel-level priority.
static void port_enable (void)
 Enables all the interrupt sources.
static void port_wait_for_interrupt (void)
 Enters an architecture-dependent IRQ-waiting mode.
static rtcnt_t port_rt_get_counter_value (void)
 Returns the current value of the realtime counter.

Macro Definition Documentation

◆ PORT_SUPPORTS_RT

#define PORT_SUPPORTS_RT   FALSE

This port supports a realtime counter.

Definition at line 44 of file chcore.h.

◆ PORT_NATURAL_ALIGN

#define PORT_NATURAL_ALIGN   sizeof (void *)

Natural alignment constant.

Note
It is the minimum alignment for pointer-size variables.

Definition at line 50 of file chcore.h.

Referenced by chCacheObjectInit(), chCoreAlloc(), chCoreAllocI(), chFifoObjectInit(), chGuardedPoolObjectInit(), chPoolObjectInit(), and chPoolObjectInitAligned().

◆ PORT_STACK_ALIGN

#define PORT_STACK_ALIGN   sizeof (stkalign_t)

Stack alignment constant.

Note
It is the alignment required for the stack pointer.

Definition at line 56 of file chcore.h.

Referenced by chThdCreateI(), chThdCreateStatic(), and chThdCreateSuspendedI().

◆ PORT_WORKING_AREA_ALIGN

#define PORT_WORKING_AREA_ALIGN   sizeof (stkalign_t)

Working Areas alignment constant.

Note
It is the alignment to be enforced for thread working areas.

Definition at line 62 of file chcore.h.

Referenced by chThdCreateFromHeap(), chThdCreateI(), chThdCreateStatic(), and chThdCreateSuspendedI().

◆ PORT_ARCHITECTURE_XXX

#define PORT_ARCHITECTURE_XXX

Macro defining an XXX architecture.

Definition at line 72 of file chcore.h.

◆ PORT_ARCHITECTURE_XXX_YYY

#define PORT_ARCHITECTURE_XXX_YYY

Macro defining the specific XXX architecture.

Definition at line 77 of file chcore.h.

◆ PORT_ARCHITECTURE_NAME

#define PORT_ARCHITECTURE_NAME   "XXX Architecture"

Name of the implemented architecture.

Definition at line 82 of file chcore.h.

◆ PORT_COMPILER_NAME

#define PORT_COMPILER_NAME   "GCC " __VERSION__

Compiler name and version.

Definition at line 88 of file chcore.h.

◆ PORT_INFO

#define PORT_INFO   "no info"

Port-specific information string.

Definition at line 97 of file chcore.h.

◆ PORT_IDLE_THREAD_STACK_SIZE

#define PORT_IDLE_THREAD_STACK_SIZE   32

Stack size for the system idle thread.

This size depends on the idle thread implementation, usually the idle thread should take no more space than those reserved by PORT_INT_REQUIRED_STACK.

Definition at line 111 of file chcore.h.

Referenced by THD_WORKING_AREA(), and THD_WORKING_AREA().

◆ PORT_INT_REQUIRED_STACK

#define PORT_INT_REQUIRED_STACK   256

Per-thread stack overhead for interrupts servicing.

This constant is used in the calculation of the correct working area size.

Definition at line 120 of file chcore.h.

◆ PORT_XXX_ENABLE_WFI_IDLE

#define PORT_XXX_ENABLE_WFI_IDLE   FALSE

Enables a "wait for interrupt" instruction in the idle loop.

Definition at line 127 of file chcore.h.

◆ PORT_THD_FUNCTION

#define PORT_THD_FUNCTION ( tname,
arg )
Value:
void tname(void *arg)

Optimized thread function declaration macro.

Definition at line 182 of file chcore.h.

◆ PORT_SETUP_CONTEXT

#define PORT_SETUP_CONTEXT ( tp,
wbase,
wtop,
pf,
arg )
Value:
{ \
}

Platform dependent part of the chThdCreateI() API.

This code usually setup the context switching frame represented by an port_intctx structure.

Definition at line 189 of file chcore.h.

Referenced by chThdCreateI(), chThdCreateStatic(), and chThdCreateSuspendedI().

◆ PORT_WA_SIZE

#define PORT_WA_SIZE ( n)
Value:
(sizeof(struct port_intctx) + \
sizeof(struct port_extctx) + \
((size_t)(n)) + ((size_t)(PORT_INT_REQUIRED_STACK)))
#define PORT_INT_REQUIRED_STACK
Per-thread stack overhead for interrupts servicing.
Definition chcore.h:120
Interrupt saved context.
Definition chcore.h:149
System saved context.
Definition chcore.h:161

Computes the thread working area global size.

Note
There is no need to perform alignments in this macro.

Definition at line 196 of file chcore.h.

◆ PORT_WORKING_AREA

#define PORT_WORKING_AREA ( s,
n )
Value:
port_stkalign_t stkalign_t
Definition chearly.h:80
#define THD_WORKING_AREA_SIZE(n)
Calculates the total Working Area size.
Definition chthreads.h:130

Static working area allocation.

This macro is used to allocate a static thread working area aligned as both position and size.

Parameters
[in]sthe name to be assigned to the stack array
[in]nthe stack size to be assigned to the thread

Definition at line 208 of file chcore.h.

◆ PORT_IRQ_IS_VALID_PRIORITY

#define PORT_IRQ_IS_VALID_PRIORITY ( n)
Value:
false

Priority level verification macro.

Definition at line 214 of file chcore.h.

◆ PORT_IRQ_IS_VALID_KERNEL_PRIORITY

#define PORT_IRQ_IS_VALID_KERNEL_PRIORITY ( n)
Value:
false

Priority level verification macro.

Definition at line 219 of file chcore.h.

◆ PORT_IRQ_PROLOGUE

#define PORT_IRQ_PROLOGUE ( )

IRQ prologue code.

This macro must be inserted at the start of all IRQ handlers enabled to invoke system APIs.

Definition at line 226 of file chcore.h.

◆ PORT_IRQ_EPILOGUE

#define PORT_IRQ_EPILOGUE ( )

IRQ epilogue code.

This macro must be inserted at the end of all IRQ handlers enabled to invoke system APIs.

Definition at line 233 of file chcore.h.

◆ PORT_IRQ_HANDLER

#define PORT_IRQ_HANDLER ( id)
Value:
void id(void)

IRQ handler function declaration.

Note
id can be a function name or a vector number depending on the port implementation.

Definition at line 243 of file chcore.h.

◆ PORT_FAST_IRQ_HANDLER

#define PORT_FAST_IRQ_HANDLER ( id)
Value:
void id(void)

Fast IRQ handler function declaration.

Note
id can be a function name or a vector number depending on the port implementation.

Definition at line 254 of file chcore.h.

◆ port_switch

#define port_switch ( ntp,
otp )
Value:
_port_switch(ntp, otp)
void _port_switch(thread_t *ntp, thread_t *otp)
Performs a context switch between two threads.
Definition chcore.c:72

Performs a context switch between two threads.

This is the most critical code in any port, this function is responsible for the context switch between 2 threads.

Note
The implementation of this code affects directly the context switch performance so optimize here as much as you can.
Parameters
[in]ntpthe thread to be switched in
[in]otpthe thread to be switched out

Definition at line 268 of file chcore.h.

Referenced by chSchDoPreemption(), and chSchGoSleepTimeoutS().

◆ port_get_lock_status

#define port_get_lock_status ( )
Value:
0U

Returns a word representing a critical section status.

Returns
The critical section status.

Definition at line 283 of file chcore.h.

Referenced by chSysGetStatusAndLockX(), chSysUnconditionalLock(), chSysUnconditionalLock(), chSysUnconditionalUnlock(), and chSysUnconditionalUnlock().

◆ port_is_locked

#define port_is_locked ( sts)
Value:
((sts) != 0U)

Determines if in a critical section.

Parameters
[in]stsstatus word returned by port_get_lock_status()
Returns
The current status.
Return values
falseif running outside a critical section.
trueif running within a critical section.

Definition at line 293 of file chcore.h.

Referenced by chSysGetStatusAndLockX(), chSysRestoreStatusX(), chSysUnconditionalLock(), chSysUnconditionalLock(), chSysUnconditionalUnlock(), and chSysUnconditionalUnlock().

Function Documentation

◆ _port_init()

void _port_init ( void )

Port-related initialization code.

Note
This function is usually empty.

Definition at line 59 of file chcore.c.

◆ _port_switch()

void _port_switch ( thread_t * ntp,
thread_t * otp )

Performs a context switch between two threads.

This is the most critical code in any port, this function is responsible for the context switch between 2 threads.

Note
The implementation of this code affects directly the context switch performance so optimize here as much as you can.
Parameters
[in]ntpthe thread to be switched in
[in]otpthe thread to be switched out

Definition at line 72 of file chcore.c.

◆ port_is_isr_context()

bool port_is_isr_context ( void )
inlinestatic

Determines the current execution context.

Returns
The execution context.
Return values
falsenot running in ISR mode.
truerunning in ISR mode.

Definition at line 329 of file chcore.h.

Referenced by chSysGetStatusAndLockX(), and chSysRestoreStatusX().

◆ port_lock()

void port_lock ( void )
inlinestatic

Kernel-lock action.

Usually this function just disables interrupts but may perform more actions.

Definition at line 339 of file chcore.h.

Referenced by chSysLock().

◆ port_unlock()

void port_unlock ( void )
inlinestatic

Kernel-unlock action.

Usually this function just enables interrupts but may perform more actions.

Definition at line 348 of file chcore.h.

Referenced by chSysUnlock().

◆ port_lock_from_isr()

void port_lock_from_isr ( void )
inlinestatic

Kernel-lock action from an interrupt handler.

This function is invoked before invoking I-class APIs from interrupt handlers. The implementation is architecture dependent, in its simplest form it is void.

Definition at line 358 of file chcore.h.

Referenced by __dbg_check_enter_isr(), __dbg_check_leave_isr(), __stats_increase_irq(), __trace_isr_enter(), __trace_isr_leave(), and chSysLockFromISR().

◆ port_unlock_from_isr()

void port_unlock_from_isr ( void )
inlinestatic

Kernel-unlock action from an interrupt handler.

This function is invoked after invoking I-class APIs from interrupt handlers. The implementation is architecture dependent, in its simplest form it is void.

Definition at line 368 of file chcore.h.

Referenced by __dbg_check_enter_isr(), __dbg_check_leave_isr(), __stats_increase_irq(), __trace_isr_enter(), __trace_isr_leave(), and chSysUnlockFromISR().

◆ port_disable()

void port_disable ( void )
inlinestatic

Disables all the interrupt sources.

Note
Of course non-maskable interrupt sources are not included.

Definition at line 376 of file chcore.h.

Referenced by chSysDisable(), and chSysHalt().

◆ port_suspend()

void port_suspend ( void )
inlinestatic

Disables the interrupt sources below kernel-level priority.

Note
Interrupt sources above kernel level remains enabled.

Definition at line 384 of file chcore.h.

Referenced by chSysSuspend().

◆ port_enable()

void port_enable ( void )
inlinestatic

Enables all the interrupt sources.

Definition at line 391 of file chcore.h.

Referenced by chSysEnable().

◆ port_wait_for_interrupt()

void port_wait_for_interrupt ( void )
inlinestatic

Enters an architecture-dependent IRQ-waiting mode.

The function is meant to return when an interrupt becomes pending. The simplest implementation is an empty function or macro but this would not take advantage of architecture-specific power saving modes.

Definition at line 402 of file chcore.h.

Referenced by __idle_thread().

◆ port_rt_get_counter_value()

rtcnt_t port_rt_get_counter_value ( void )
inlinestatic

Returns the current value of the realtime counter.

Returns
The realtime counter value.

Definition at line 413 of file chcore.h.