C Microkernel Realtime eXecutive
Realtime Operating System for Cortex-M based microcontrollers
 
Loading...
Searching...
No Matches

Functions

uint32_t * get_exception_arg_addr (ExceptionFrame *frame, unsigned argno, bool fp_active)
 Retrieve address of n-th argument from exception frame.
 
void os_request_context_switch (bool activate)
 Request context switch.
 
uint32_t os_perform_thread_switch (uint32_t LR)
 Handle task switch.
 
void PendSV_Handler (void)
 Wrapper for for Pending service interrupt handler.
 

Detailed Description

Function Documentation

◆ get_exception_arg_addr()

uint32_t * get_exception_arg_addr ( ExceptionFrame frame,
unsigned  argno,
bool  fp_active 
)

Retrieve address of n-th argument from exception frame.

This function calculates address of n-th argument of function call from exception frame. This is used whenever it is known, that exception frame was stored as an effect of __SVC() call. It will automatically handle exception frame padding.

Parameters
frameexception frame base address (usually value of SP)
argnonumber of argument retrieved
Returns
address of argument relative to exception frame

◆ os_perform_thread_switch()

uint32_t os_perform_thread_switch ( uint32_t  LR)

Handle task switch.

This function performs the heavy lifting of context switching when CPU is switched from one task to another. It saves the SP of suspended thread, then modifies the PSP to match the saved value of incoming thread and if needed it performs signal handler injection and/or MPU register reconfiguration. Saving and restoring of registers is performed by the wrapper to avoid C function preamble interference.

Parameters
[in]LRcopy of the LR value of the PendSV_Handler
Returns
value that has to be used as new LR before PendSV_Handler quits

◆ os_request_context_switch()

void os_request_context_switch ( bool  activate)
inline

Request context switch.

This function is called by the platform independent part of the kernel when cpu_context structure is filled with valid data and context switch shall happen. The implementation of this function should configure the hardware in a way that context switch will happen as soon as kernel finishes its work and is ready to return the CPU back to the userspace code.

◆ PendSV_Handler()

void PendSV_Handler ( void  )

Wrapper for for Pending service interrupt handler.

CMRX uses pending service to handle heavy lifting of thread switching. At the time PendSV is scheduled, the decision on which thread to run next has already been made. This code just performs the switch.

This assembly stub makes sure that all thread registers are properly saved and restored during thread switch, so the actual implementation may be written as plain C function without involving surprises.