distortos  v0.5.0
object-oriented C++ RTOS for microcontrollers
distortos::architecture Namespace Reference

Architecture-related code of distortos project. More...

Namespaces

Classes

struct  ExceptionFpuStackFrame
 stack frame for ARMv7-M created by hardware on exception entry when FPU context is active More...
 
struct  ExceptionStackFrame
 stack frame for ARMv6-M and ARMv7-M created by hardware on exception entry More...
 
struct  SoftwareStackFrame
 stack frame for ARMv6-M and ARMv7-M created by software during context switch More...
 
struct  StackFrame
 complete stack frame of thread for ARMv6-M and ARMv7-M More...
 

Typedefs

using InterruptMask = uint32_t
 interrupt mask More...
 

Functions

InterruptMask disableInterruptMasking ()
 Disables interrupt masking. More...
 
InterruptMask enableInterruptMasking ()
 Enables interrupt masking. More...
 
std::pair< void *, size_t > getMainStack ()
 Gets the stack used to run main(). More...
 
std::pair< int, void * > initializeStack (void *buffer, size_t size, Thread &thread, void(&run)(Thread &), void(*preTerminationHook)(Thread &), void(&terminationHook)(Thread &))
 Architecture-specific stack initialization. More...
 
bool isInInterruptContext ()
 Architecture-specific check of context. More...
 
void lowLevelInitialization ()
 Low level architecture initialization. More...
 
void requestContextSwitch ()
 Architecture-specific request for context switch. More...
 
int requestFunctionExecution (internal::ThreadControlBlock &threadControlBlock, void(&function)())
 Requests execution of provided function in the specified thread. More...
 
void restoreInterruptMasking (InterruptMask interruptMask)
 Restores interrupt masking. More...
 
void startScheduling ()
 Architecture-specific start of scheduling. More...
 
int supervisorCall (int(&function)(int, int, int, int), int argument1, int argument2, int argument3, int argument4)
 Supervisor call. More...
 
int supervisorCall (int(&function)(int, int, int), const int argument1, const int argument2, const int argument3)
 Supervisor call - overload with 3 arguments. More...
 
int supervisorCall (int(&function)(int, int), const int argument1, const int argument2)
 Supervisor call - overload with 2 arguments. More...
 
int supervisorCall (int(&function)(int), const int argument)
 Supervisor call - overload with 1 argument. More...
 
int supervisorCall (int(&function)())
 Supervisor call - overload with no arguments. More...
 

Variables

char __process_stack_start []
 beginning of process stack - imported from linker script More...
 
char __process_stack_size []
 size of process stack, bytes - imported from linker script More...
 

Detailed Description

Architecture-related code of distortos project.

Typedef Documentation

◆ InterruptMask

using distortos::architecture::InterruptMask = typedef uint32_t

interrupt mask

Function Documentation

◆ disableInterruptMasking()

InterruptMask distortos::architecture::disableInterruptMasking ( )

Disables interrupt masking.

Enables normal-priority interrupts.

Returns
previous value of interrupts' mask, must be used for matched restoreInterruptMasking() call

◆ enableInterruptMasking()

InterruptMask distortos::architecture::enableInterruptMasking ( )

Enables interrupt masking.

Disables normal-priority interrupts.

Note
High-priority interrupts are not controlled by distortos, so they may be left enabled. Support for that feature is architecture-dependent.
Returns
previous value of interrupts' mask, must be used for matched restoreInterruptMasking() call

◆ getMainStack()

std::pair< void *, size_t > distortos::architecture::getMainStack ( )

Gets the stack used to run main().

Returns
beginning of stack and its size in bytes
Here is the caller graph for this function:

◆ initializeStack()

std::pair< int, void * > distortos::architecture::initializeStack ( void *  buffer,
size_t  size,
Thread thread,
void(&)(Thread &)  run,
void(*)(Thread &)  preTerminationHook,
void(&)(Thread &)  terminationHook 
)

Architecture-specific stack initialization.

This function fills provided buffer with hardware and software stack frame and calculates value of stack pointer register. After this function completes, stack is ready for context switching.

Attention
buffer and size must be properly adjusted for architecture requirements
Parameters
[in]bufferis a pointer to stack's buffer
[in]sizeis the size of stack's buffer, bytes
[in]threadis a reference to Thread object passed to function
[in]runis a reference to Thread's "run" function
[in]preTerminationHookis a pointer to Thread's pre-termination hook, nullptr to skip
[in]terminationHookis a reference to Thread's termination hook
Returns
pair with return code (0 on success, error code otherwise) and value that can be used as thread's stack pointer, ready for context switching; error codes:
  • ENOSPC - size of provided buffer is too small for stack frame;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInInterruptContext()

bool distortos::architecture::isInInterruptContext ( )

Architecture-specific check of context.

Checks whether thread or interrupt context is currently active. An example use is when the application needs to decide between blocking or non-blocking behaviour, as blocking is not possible in interrupt context.

Returns
true if the function was called from interrupt context or false if it was called from thread context
Here is the caller graph for this function:

◆ lowLevelInitialization()

void distortos::architecture::lowLevelInitialization ( )

Low level architecture initialization.

Low level board initialization.

This function is called before constructors for global and static objects from __libc_init_array() via address in distortosPreinitArray[].

◆ requestContextSwitch()

void distortos::architecture::requestContextSwitch ( )

Architecture-specific request for context switch.

Causes the architecture to do context save, call internal::getScheduler().switchContext() and do context restore. The call to internal::getScheduler().switchContext() must be done from the context in which such call is valid (usually system interrupt).

Here is the caller graph for this function:

◆ requestFunctionExecution()

int distortos::architecture::requestFunctionExecution ( internal::ThreadControlBlock threadControlBlock,
void(&)()  function 
)

Requests execution of provided function in the specified thread.

Main use case for this function is to request execution of signals delivery function. In such case it is called when an unblocked signal, which is not ignored, is generated or queued for specified thread.

It must arrange for given function to be executed in specified thread as soon as possible. This generally requires dealing with following scenarios:

  • current thread is sending the request to non-current thread;
  • interrupt is sending the request to current thread;
  • interrupt is sending the request to non-current thread;
Warning
Current thread must not send the request to itself!
Parameters
[in]threadControlBlockis a reference to internal::ThreadControlBlock of thread in which function should be executed
[in]functionis a reference to function that should be executed in thread associated with threadControlBlock
Returns
0 on success, error code otherwise:
  • ENOSPC - amount of free stack is too small to request function execution;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ restoreInterruptMasking()

void distortos::architecture::restoreInterruptMasking ( InterruptMask  interruptMask)

Restores interrupt masking.

Restores previous interrupt masking state (before matching enableInterruptMasking() or disableInterruptMasking() was called), enabling some (maybe all, maybe none) interrupts.

Parameters
[in]interruptMaskis the value of interrupts' mask, must come from previous call to enableInterruptMasking() or disableInterruptMasking()
Here is the caller graph for this function:

◆ startScheduling()

void distortos::architecture::startScheduling ( )

Architecture-specific start of scheduling.

Initializes all required hardware/software to perform context switching and starts the scheduling.

◆ supervisorCall() [1/5]

int distortos::architecture::supervisorCall ( int(&)(int, int, int, int)  function,
int  argument1,
int  argument2,
int  argument3,
int  argument4 
)

Supervisor call.

Requests execution of function with arguments from SVC_Handler().

Parameters
[in]functionis a reference to function that will be executed
[in]argument1is the first argument for function
[in]argument2is the second argument for function
[in]argument3is the third argument for function
[in]argument4is the fourth argument for function
Returns
value returned by function
Here is the caller graph for this function:

◆ supervisorCall() [2/5]

int distortos::architecture::supervisorCall ( int(&)(int, int, int)  function,
const int  argument1,
const int  argument2,
const int  argument3 
)
inline

Supervisor call - overload with 3 arguments.

Requests execution of function with arguments from SVC_Handler().

Parameters
[in]functionis a reference to function that will be executed
[in]argument1is the first argument for function
[in]argument2is the second argument for function
[in]argument3is the third argument for function
Returns
value returned by function
Here is the call graph for this function:

◆ supervisorCall() [3/5]

int distortos::architecture::supervisorCall ( int(&)(int, int)  function,
const int  argument1,
const int  argument2 
)
inline

Supervisor call - overload with 2 arguments.

Requests execution of function with arguments from SVC_Handler().

Parameters
[in]functionis a reference to function that will be executed
[in]argument1is the first argument for function
[in]argument2is the second argument for function
Returns
value returned by function
Here is the call graph for this function:

◆ supervisorCall() [4/5]

int distortos::architecture::supervisorCall ( int(&)(int)  function,
const int  argument 
)
inline

Supervisor call - overload with 1 argument.

Requests execution of function with arguments from SVC_Handler().

Parameters
[in]functionis a reference to function that will be executed
[in]argumentis the argument for function
Returns
value returned by function
Here is the call graph for this function:

◆ supervisorCall() [5/5]

int distortos::architecture::supervisorCall ( int(&)()  function)
inline

Supervisor call - overload with no arguments.

Requests execution of function with arguments from SVC_Handler().

Parameters
[in]functionis a reference to function that will be executed
Returns
value returned by function
Here is the call graph for this function:

Variable Documentation

◆ __process_stack_size

char distortos::architecture::__process_stack_size[]

size of process stack, bytes - imported from linker script

◆ __process_stack_start

char distortos::architecture::__process_stack_start[]

beginning of process stack - imported from linker script