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

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

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, internal::RunnableThread &runnableThread)
 Architecture-specific stack initialization. More...
 
bool isInInterruptContext ()
 Architecture-specific check of context. 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...
 
int supervisorCall (int(&function)(int, int, int, int), int argument1, int argument2, int argument3, int argument4)
 Supervisor call. 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,
internal::RunnableThread runnableThread 
)

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]runnableThreadis a reference to internal::RunnableThread object that is being run
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:

◆ 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:

◆ supervisorCall()

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:

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