SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::StackMemoryWrapper< _StackSize > Class Template Reference

Adapts an externally-owned stack memory array to the IStackMemory interface. More...

#include <stk_helper.h>

Inheritance diagram for stk::StackMemoryWrapper< _StackSize >:
Collaboration diagram for stk::StackMemoryWrapper< _StackSize >:

Public Types

typedef StackMemoryDef< _StackSize >::Type MemoryType
 The concrete array type that this wrapper accepts, equivalent to StackMemoryDef<_StackSize>::Type.

Public Member Functions

 StackMemoryWrapper (MemoryType *stack)
 Construct a wrapper around an existing stack memory array.
 ~StackMemoryWrapper ()
 Destructor.
WordGetStack () const
 Get pointer to the first element of the wrapped stack array.
size_t GetStackSize () const
 Get number of elements in the wrapped stack array.
size_t GetStackSizeBytes () const
 Get size of the wrapped stack array in bytes.
virtual size_t GetStackSpace ()
 Get available stack space.

Private Attributes

MemoryTypem_stack
 Pointer to the externally-owned stack memory array.

Detailed Description

template<size_t _StackSize>
class stk::StackMemoryWrapper< _StackSize >

Adapts an externally-owned stack memory array to the IStackMemory interface.

Note
Wrapper (Adapter) design pattern. Use when the stack memory is declared separately from the task object (e.g. in a linker section or shared buffer) and needs to be passed to the kernel via the IStackMemory interface.
Template Parameters
_StackSizeStack size in elements of Word. Must be >= STACK_SIZE_MIN.

Definition at line 183 of file stk_helper.h.

Member Typedef Documentation

◆ MemoryType

template<size_t _StackSize>
typedef StackMemoryDef<_StackSize>::Type stk::StackMemoryWrapper< _StackSize >::MemoryType

The concrete array type that this wrapper accepts, equivalent to StackMemoryDef<_StackSize>::Type.

Definition at line 189 of file stk_helper.h.

Constructor & Destructor Documentation

◆ StackMemoryWrapper()

template<size_t _StackSize>
stk::StackMemoryWrapper< _StackSize >::StackMemoryWrapper ( MemoryType * stack)
inlineexplicit

Construct a wrapper around an existing stack memory array.

Parameters
[in]stackPointer to the externally-owned memory array. Must remain valid for the lifetime of this wrapper and of any kernel task using it.
Note
_StackSize must be >= STACK_SIZE_MIN; enforced by a compile-time assertion.

Definition at line 196 of file stk_helper.h.

196 : m_stack(stack)
197 {
199 }
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
Definition stk_defs.h:367
Adapts an externally-owned stack memory array to the IStackMemory interface.
Definition stk_helper.h:184
MemoryType * m_stack
Pointer to the externally-owned stack memory array.
Definition stk_helper.h:220

◆ ~StackMemoryWrapper()

template<size_t _StackSize>
stk::StackMemoryWrapper< _StackSize >::~StackMemoryWrapper ( )
inline

Destructor.

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

Definition at line 204 of file stk_helper.h.

205 {}

Member Function Documentation

◆ GetStack()

template<size_t _StackSize>
Word * stk::StackMemoryWrapper< _StackSize >::GetStack ( ) const
inlinevirtual

Get pointer to the first element of the wrapped stack array.

Implements stk::IStackMemory.

Definition at line 209 of file stk_helper.h.

209{ return (*m_stack); }

◆ GetStackSize()

template<size_t _StackSize>
size_t stk::StackMemoryWrapper< _StackSize >::GetStackSize ( ) const
inlinevirtual

Get number of elements in the wrapped stack array.

Implements stk::IStackMemory.

Definition at line 213 of file stk_helper.h.

213{ return _StackSize; }

◆ GetStackSizeBytes()

template<size_t _StackSize>
size_t stk::StackMemoryWrapper< _StackSize >::GetStackSizeBytes ( ) const
inlinevirtual

Get size of the wrapped stack array in bytes.

Implements stk::IStackMemory.

Definition at line 217 of file stk_helper.h.

217{ return _StackSize * sizeof(Word); }

◆ GetStackSpace()

virtual size_t stk::IStackMemory::GetStackSpace ( )
inlinevirtualinherited

Get available stack space.

Returns
Number of elements of the stack memory array remaining on the stack (computed via the watermark pattern). Returns 0 if the stack has been fully used or the watermark STK_STACK_MEMORY_FILLER was overwritten.
Warning
Stack type: Bottom to Top (index[0]).

Definition at line 252 of file stk_common.h.

253 {
254 const Word *stack = GetStack();
255 const size_t stack_size = GetStackSize();
256
257 // count leading Words equal to STK_STACK_MEMORY_FILLER (watermark)
258 size_t space = 0U;
259 for ( ; (space < stack_size) && (stack[space] == STK_STACK_MEMORY_FILLER); ++space)
260 {}
261
262 return space;
263 }
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:377
uintptr_t Word
Native processor word type.
Definition stk_common.h:113
virtual size_t GetStackSize() const =0
Get number of elements of the stack memory array.
virtual Word * GetStack() const =0
Get pointer to the stack memory.

References GetStack(), GetStackSize(), and STK_STACK_MEMORY_FILLER.

Referenced by osThreadGetStackSpace().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_stack

template<size_t _StackSize>
MemoryType* stk::StackMemoryWrapper< _StackSize >::m_stack
private

Pointer to the externally-owned stack memory array.

Definition at line 220 of file stk_helper.h.


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