SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::PlatformContext Class Reference

Base platform context for all platform implementations. More...

#include <stk_arch_common.h>

Collaboration diagram for stk::PlatformContext:

Public Member Functions

 PlatformContext ()
STK_VIRT_DTOR ~PlatformContext ()=default
 Destructor.
virtual void Initialize (IPlatform::IEventHandler *handler, IKernelService *service, Stack *exit_trap, uint32_t resolution_us)
 Initialize context.

Static Public Member Functions

static Word InitStackMemory (IStackMemory *const memory)
 Initialize stack memory by filling it with STK_STACK_MEMORY_FILLER.

Public Attributes

IPlatform::IEventHandlerm_handler
 kernel event handler
IKernelServicem_service
 kernel service
Stackm_stack_idle
 idle task stack
Stackm_stack_active
 active task stack
uint32_t m_tick_resolution
 system tick resolution (microseconds)

Protected Member Functions

 STK_NONCOPYABLE_CLASS (PlatformContext)

Detailed Description

Base platform context for all platform implementations.

Definition at line 24 of file stk_arch_common.h.

Constructor & Destructor Documentation

◆ PlatformContext()

stk::PlatformContext::PlatformContext ( )
inlineexplicit

Definition at line 27 of file stk_arch_common.h.

27 : m_handler(nullptr), m_service(nullptr), m_stack_idle(nullptr),
29 {}
IPlatform::IEventHandler * m_handler
kernel event handler
Stack * m_stack_active
active task stack
Stack * m_stack_idle
idle task stack
IKernelService * m_service
kernel service
uint32_t m_tick_resolution
system tick resolution (microseconds)

References m_handler, m_service, m_stack_active, m_stack_idle, and m_tick_resolution.

Referenced by STK_NONCOPYABLE_CLASS().

Here is the caller graph for this function:

◆ ~PlatformContext()

STK_VIRT_DTOR stk::PlatformContext::~PlatformContext ( )
default

Destructor.

Note
MISRA deviation: [STK-DEV-005] Rule 10-3-2.

References STK_VIRT_DTOR.

Member Function Documentation

◆ Initialize()

virtual void stk::PlatformContext::Initialize ( IPlatform::IEventHandler * handler,
IKernelService * service,
Stack * exit_trap,
uint32_t resolution_us )
inlinevirtual

Initialize context.

Parameters
[in]handlerEvent handler.
[in]serviceKernel service.
[in]exit_trapExit trap's stack.
[in]resolution_usTick resolution in microseconds (for example 1000 equals to 1 millisecond resolution).

Definition at line 42 of file stk_arch_common.h.

44 {
45 m_handler = handler;
46 m_service = service;
47 m_stack_idle = exit_trap;
48 m_stack_active = nullptr;
49 m_tick_resolution = resolution_us;
50 }

References m_handler, m_service, m_stack_active, m_stack_idle, and m_tick_resolution.

◆ InitStackMemory()

Word stk::PlatformContext::InitStackMemory ( IStackMemory *const memory)
inlinestatic

Initialize stack memory by filling it with STK_STACK_MEMORY_FILLER.

Note
Returned pointer is for a stack growing from top to down.
Parameters
[in]memoryStack memory to initialize.
Returns
Top of the stack memory (valid memory region is (stack_top - sizeof(Word))).

Definition at line 57 of file stk_arch_common.h.

58 {
59 STK_ASSERT(memory != nullptr);
60
61 ArrayView<Word> stack(const_cast<Word *>(memory->GetStack()), memory->GetStackSize());
62 STK_ASSERT(stack.GetSize() >= STACK_SIZE_MIN);
63
64 // initialize stack memory to satisfy stack integrity check in Kernel::StateSwitch
65 for (size_t i = 0U; i < stack.GetSize(); ++i)
66 {
67 stack[i] = STK_STACK_MEMORY_FILLER;
68 }
69
70 // get address of the last valid item and step forward by 1 Word size to point to the top
71 const Word stack_top = hw::PtrToWord(memory->GetStack()) + (stack.GetSize() * sizeof(Word));
72
73 // expecting STK_STACK_MEMORY_ALIGN-byte aligned memory for a stack
74 STK_ASSERT((stack_top & (STK_STACK_MEMORY_ALIGN - 1U)) == 0U);
75
76 return stack_top;
77 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:409
#define STK_STACK_MEMORY_ALIGN
Stack memory alignment.
Definition stk_defs.h:468
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:456
uintptr_t Word
Native processor word type.
Definition stk_common.h:136
@ STACK_SIZE_MIN
Minimum stack size in elements of Word. Used as a lower bound for all stack allocations (user task,...
Definition stk_common.h:96
static constexpr Word PtrToWord(T *const ptr) noexcept
Cast a pointer to a CPU register-width integer.
Definition stk_arch.h:106

References stk::ArrayView< T >::GetSize(), stk::hw::PtrToWord(), stk::STACK_SIZE_MIN, STK_ASSERT, STK_STACK_MEMORY_ALIGN, and STK_STACK_MEMORY_FILLER.

Here is the call graph for this function:

◆ STK_NONCOPYABLE_CLASS()

stk::PlatformContext::STK_NONCOPYABLE_CLASS ( PlatformContext )
protected

References PlatformContext().

Here is the call graph for this function:

Member Data Documentation

◆ m_handler

IPlatform::IEventHandler* stk::PlatformContext::m_handler

kernel event handler

Definition at line 79 of file stk_arch_common.h.

Referenced by Initialize(), and PlatformContext().

◆ m_service

IKernelService* stk::PlatformContext::m_service

kernel service

Definition at line 80 of file stk_arch_common.h.

Referenced by Initialize(), and PlatformContext().

◆ m_stack_active

Stack* stk::PlatformContext::m_stack_active

active task stack

Definition at line 82 of file stk_arch_common.h.

Referenced by Initialize(), and PlatformContext().

◆ m_stack_idle

Stack* stk::PlatformContext::m_stack_idle

idle task stack

Definition at line 81 of file stk_arch_common.h.

Referenced by Initialize(), and PlatformContext().

◆ m_tick_resolution

uint32_t stk::PlatformContext::m_tick_resolution

system tick resolution (microseconds)

Definition at line 83 of file stk_arch_common.h.

Referenced by Initialize(), and PlatformContext().


The documentation for this class was generated from the following file: