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::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 ()=default
 Destructor.
const WordGetStack () const override
 Get pointer to the first element of the wrapped stack array.
size_t GetStackSize () const override
 Get number of elements in the wrapped stack array.
size_t GetStackSizeBytes () const override
 Get size of the wrapped stack array in bytes.
virtual size_t GetStackSpace () const
 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 136 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 142 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 149 of file stk_helper.h.

149 : m_stack(stack)
150 {
152 }
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
Definition stk_defs.h:446
Adapts an externally-owned stack memory array to the IStackMemory interface.
Definition stk_helper.h:137
MemoryType * m_stack
Pointer to the externally-owned stack memory array.
Definition stk_helper.h:172

◆ ~StackMemoryWrapper()

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

Destructor.

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

Member Function Documentation

◆ GetStack()

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

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

Implements stk::IStackMemory.

Definition at line 161 of file stk_helper.h.

161{ return (*m_stack); }

◆ GetStackSize()

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

Get number of elements in the wrapped stack array.

Implements stk::IStackMemory.

Definition at line 165 of file stk_helper.h.

165{ return _StackSize; }

◆ GetStackSizeBytes()

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

Get size of the wrapped stack array in bytes.

Implements stk::IStackMemory.

Definition at line 169 of file stk_helper.h.

169{ return (_StackSize * sizeof(Word)); }

◆ GetStackSpace()

virtual size_t stk::IStackMemory::GetStackSpace ( ) const
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 319 of file stk_common.h.

320 {
321 const ArrayView<const Word> stack(GetStack(), GetStackSize());
322 const size_t total_size = stack.GetSize();
323 size_t space = 0U;
324
325 for (size_t i = 0U; i < total_size; ++i)
326 {
327 if (stack[i] == STK_STACK_MEMORY_FILLER)
328 {
329 space = i + 1U;
330 }
331 else
332 {
333 break; // terminate loop as soon as watermark ends
334 }
335 }
336
337 return space;
338 }
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:456
virtual size_t GetStackSize() const =0
Get number of elements of the stack memory array.
virtual const Word * GetStack() const =0
Get pointer to the stack memory.

References stk::ArrayView< T >::GetSize(), GetStack(), GetStackSize(), and STK_STACK_MEMORY_FILLER.

Referenced by FrtosTask::GetStackHighWaterMark(), and 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 172 of file stk_helper.h.


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