ChibiOS  0.0.0
Port Core
Collaboration diagram for Port Core:

Detailed Description

Non portable code templates.

Macros

#define PORT_IDLE_THREAD_STACK_SIZE   32
 Stack size for the system idle thread. More...
 
#define PORT_INT_REQUIRED_STACK   256
 Per-thread stack overhead for interrupts servicing. More...
 
#define PORT_USE_ALT_TIMER   FALSE
 Enables an alternative timer implementation. More...
 
#define PORT_XXX_ENABLE_WFI_IDLE   FALSE
 Enables a "wait for interrupt" instruction in the idle loop. More...
 
#define PORT_SETUP_CONTEXT(tp, wbase, wtop, pf, arg)
 Platform dependent part of the chThdCreateI() API. More...
 
#define PORT_WA_SIZE(n)
 Computes the thread working area global size. More...
 
#define PORT_WORKING_AREA(s, n)   stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof (stkalign_t)]
 Static working area allocation. More...
 
#define PORT_IRQ_IS_VALID_PRIORITY(n)   false
 Priority level verification macro. More...
 
#define PORT_IRQ_IS_VALID_KERNEL_PRIORITY(n)   false
 Priority level verification macro. More...
 
#define PORT_IRQ_PROLOGUE()
 IRQ prologue code. More...
 
#define PORT_IRQ_EPILOGUE()
 IRQ epilogue code. More...
 
#define PORT_IRQ_HANDLER(id)   void id(void)
 IRQ handler function declaration. More...
 
#define PORT_FAST_IRQ_HANDLER(id)   void id(void)
 Fast IRQ handler function declaration. More...
 
#define port_switch(ntp, otp)   _port_switch(ntp, otp)
 Performs a context switch between two threads. More...
 

Port Capabilities and Constants

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

Architecture and Compiler

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

Typedefs

typedef uint64_t stkalign_t
 Type of stack and memory alignment enforcement. More...
 

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

Functions

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

Macro Definition Documentation

#define PORT_SUPPORTS_RT   FALSE

This port supports a realtime counter.

Definition at line 44 of file chcore.h.

#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 chCoreAlloc(), chCoreAllocI(), chGuardedPoolObjectInit(), and chPoolObjectInit().

#define PORT_STACK_ALIGN   sizeof (stkalign_t)

Stack alignment constant.

Note
It is the alignement required for the stack pointer.

Definition at line 56 of file chcore.h.

Referenced by chThdCreateStatic(), and chThdCreateSuspendedI().

#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(), chThdCreateStatic(), and chThdCreateSuspendedI().

#define PORT_ARCHITECTURE_XXX

Macro defining an XXX architecture.

Definition at line 72 of file chcore.h.

#define PORT_ARCHITECTURE_XXX_YYY

Macro defining the specific XXX architecture.

Definition at line 77 of file chcore.h.

#define PORT_ARCHITECTURE_NAME   "XXX Architecture"

Name of the implemented architecture.

Definition at line 82 of file chcore.h.

#define PORT_COMPILER_NAME   "GCC " __VERSION__

Compiler name and version.

Definition at line 88 of file chcore.h.

#define PORT_INFO   "no info"

Port-specific information string.

Definition at line 97 of file chcore.h.

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

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

#define PORT_USE_ALT_TIMER   FALSE

Enables an alternative timer implementation.

Usually the port uses a timer interface defined in the file chcore_timer.h, if this option is enabled then the file chcore_timer_alt.h is included instead.

Definition at line 130 of file chcore.h.

#define PORT_XXX_ENABLE_WFI_IDLE   FALSE

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

Definition at line 137 of file chcore.h.

#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 200 of file chcore.h.

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

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

Computes the thread working area global size.

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

Definition at line 207 of file chcore.h.

#define PORT_WORKING_AREA (   s,
 
)    stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof (stkalign_t)]

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 219 of file chcore.h.

#define PORT_IRQ_IS_VALID_PRIORITY (   n)    false

Priority level verification macro.

Definition at line 225 of file chcore.h.

#define PORT_IRQ_IS_VALID_KERNEL_PRIORITY (   n)    false

Priority level verification macro.

Definition at line 230 of file chcore.h.

#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 237 of file chcore.h.

#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 244 of file chcore.h.

#define PORT_IRQ_HANDLER (   id)    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 251 of file chcore.h.

#define PORT_FAST_IRQ_HANDLER (   id)    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 258 of file chcore.h.

#define port_switch (   ntp,
  otp 
)    _port_switch(ntp, 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 271 of file chcore.h.

Referenced by chSchDoReschedule(), chSchGoSleepTimeoutS(), and chSysInit().

Typedef Documentation

typedef uint64_t stkalign_t

Type of stack and memory alignment enforcement.

Note
In this architecture the stack alignment is enforced to 64 bits.

Definition at line 156 of file chcore.h.

Function Documentation

void _port_init ( void  )

Port-related initialization code.

Note
This function is usually empty.

Definition at line 59 of file chcore.c.

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.

static syssts_t port_get_irq_status ( void  )
inlinestatic

Returns a word encoding the current interrupts status.

Returns
The interrupts status.

Definition at line 313 of file chcore.h.

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

static bool port_irq_enabled ( syssts_t  sts)
inlinestatic

Checks the interrupt status.

Parameters
[in]ststhe interrupt status word
Returns
The interrupt status.
Return values
falsethe word specified a disabled interrupts status.
truethe word specified an enabled interrupts status.

Definition at line 327 of file chcore.h.

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

static 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 341 of file chcore.h.

Referenced by chSysGetStatusAndLockX(), and chSysRestoreStatusX().

static void port_lock ( void  )
inlinestatic

Kernel-lock action.

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

Definition at line 351 of file chcore.h.

Referenced by chSysLock().

static void port_unlock ( void  )
inlinestatic

Kernel-unlock action.

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

Definition at line 360 of file chcore.h.

Referenced by chSysUnlock().

static 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 370 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().

static 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 380 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().

static void port_disable ( void  )
inlinestatic

Disables all the interrupt sources.

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

Definition at line 388 of file chcore.h.

Referenced by chSysDisable(), and chSysHalt().

static void port_suspend ( void  )
inlinestatic

Disables the interrupt sources below kernel-level priority.

Note
Interrupt sources above kernel level remains enabled.

Definition at line 396 of file chcore.h.

Referenced by chSysSuspend().

static void port_enable ( void  )
inlinestatic

Enables all the interrupt sources.

Definition at line 403 of file chcore.h.

Referenced by chSysEnable().

static 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 414 of file chcore.h.

Referenced by _idle_thread().

static 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 425 of file chcore.h.