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::time::TimerHost::TimerWorkerTask Class Reference

Internal kernel task used by TimerHost for both the tick task and handler tasks. More...

Inheritance diagram for stk::time::TimerHost::TimerWorkerTask:
Collaboration diagram for stk::time::TimerHost::TimerWorkerTask:

Public Member Functions

 TimerWorkerTask ()
 Default constructor. All members are zero/null-initialized.
EAccessMode GetAccessMode () const override
 Get hardware access mode of the user task.
void OnDeadlineMissed (uint32_t) override
 Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time mode (see stk::KERNEL_HRT).
void OnExit () override
 Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).
int32_t GetWeight () const override
 Get static base weight of the task.
const char * GetTraceName () const override
 Get task trace name set by application.
const WordGetStack () const override
 Get pointer to the stack memory.
size_t GetStackSize () const override
 Get number of elements of the stack memory array.
size_t GetStackSizeBytes () const override
 Get size of the memory in bytes.
void Initialize (TimerHost *host, Word *stack, size_t stack_size, EAccessMode mode, TimerFuncType const func)
 Bind this task to a host, stack buffer, access mode, and entry function.
void SetWeight (int32_t weight)
 Override the scheduling weight assigned by Initialize().
TId GetId () const
 Get task Id set by application.
virtual size_t GetStackSpace () const
 Get available stack space.

Private Member Functions

void Run () override
 Timer task entry point.

Private Attributes

TimerFuncType m_func
 entry function (tick loop or handler loop)
TimerHostm_host
 owning TimerHost instance
Wordm_stack
 pointer to stack buffer
size_t m_stack_size
 stack size in words
EAccessMode m_mode
 kernel access mode
int32_t m_weight
 scheduling weight

Detailed Description

Internal kernel task used by TimerHost for both the tick task and handler tasks.

Wraps a free function pointer (TimerFuncType) so that the same ITask-derived class can serve either role (tick or handler) with different stack buffers, access modes, and entry points supplied at Initialize() time.

Note
This class is an implementation detail of TimerHost and is not part of the public API. Do not instantiate or inherit from it directly.

Definition at line 330 of file stk_time_timer.h.

Constructor & Destructor Documentation

◆ TimerWorkerTask()

stk::time::TimerHost::TimerWorkerTask::TimerWorkerTask ( )
inlineexplicit

Default constructor. All members are zero/null-initialized.

Definition at line 334 of file stk_time_timer.h.

335 : m_func(nullptr), m_host(nullptr), m_stack(nullptr), m_stack_size(0U),
337 {}
@ ACCESS_USER
Unprivileged access mode (access to some hardware is restricted, see CPU manual for details).
Definition stk_common.h:33
constexpr Weight DEFAULT_WEIGHT
Weight value: default weight of value (1) (see SwitchStrategySmoothWeightedRoundRobin).
Definition stk_common.h:199
TimerFuncType m_func
entry function (tick loop or handler loop)
size_t m_stack_size
stack size in words
TimerHost * m_host
owning TimerHost instance
Word * m_stack
pointer to stack buffer
EAccessMode m_mode
kernel access mode

References stk::ACCESS_USER, stk::DEFAULT_WEIGHT, m_func, m_host, m_mode, m_stack, m_stack_size, and m_weight.

Member Function Documentation

◆ GetAccessMode()

EAccessMode stk::time::TimerHost::TimerWorkerTask::GetAccessMode ( ) const
inlineoverridevirtual

Get hardware access mode of the user task.

Implements stk::ITask.

Definition at line 340 of file stk_time_timer.h.

340{ return m_mode; }

References m_mode.

◆ GetId()

TId stk::ITask::GetId ( ) const
inlineinherited

Get task Id set by application.

Implementation of ITask::GetId, see ITask. Placed here as it depends on GetTidFromUserTask.

Returns
Application-defined task identifier. Return 0 if unused.
Note
Used for debugging and tracing only. The kernel does not interpret this value.

Definition at line 234 of file stk_helper.h.

235{
236 return GetTidFromUserTask(this);
237}
static constexpr TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Definition stk_arch.h:520

References stk::GetTidFromUserTask().

Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Bind(), and stk_task_get_id().

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

◆ GetStack()

const Word * stk::time::TimerHost::TimerWorkerTask::GetStack ( ) const
inlineoverridevirtual

Get pointer to the stack memory.

Implements stk::IStackMemory.

Definition at line 347 of file stk_time_timer.h.

347{ return m_stack; }

References m_stack.

◆ GetStackSize()

size_t stk::time::TimerHost::TimerWorkerTask::GetStackSize ( ) const
inlineoverridevirtual

Get number of elements of the stack memory array.

Implements stk::IStackMemory.

Definition at line 348 of file stk_time_timer.h.

348{ return m_stack_size; }

References m_stack_size.

◆ GetStackSizeBytes()

size_t stk::time::TimerHost::TimerWorkerTask::GetStackSizeBytes ( ) const
inlineoverridevirtual

Get size of the memory in bytes.

Implements stk::IStackMemory.

Definition at line 349 of file stk_time_timer.h.

349{ return (m_stack_size * sizeof(Word)); }
uintptr_t Word
Native processor word type.
Definition stk_common.h:115

References m_stack_size.

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

◆ GetTraceName()

const char * stk::time::TimerHost::TimerWorkerTask::GetTraceName ( ) const
inlineoverridevirtual

Get task trace name set by application.

Returns
Null-terminated name string, or NULL if unused.
Note
Used for debugging and tracing only (e.g. SEGGER SystemView). Kernel does not interpret this value.

Reimplemented from stk::ITask.

Definition at line 344 of file stk_time_timer.h.

344{ return nullptr; }

◆ GetWeight()

int32_t stk::time::TimerHost::TimerWorkerTask::GetWeight ( ) const
inlineoverridevirtual

Get static base weight of the task.

Returns
Static weight value of the task (must be non-zero, positive 24-bit number).
See also
SwitchStrategyFixedPriority, SwitchStrategySmoothWeightedRoundRobin, IKernelTask::GetWeight, IKernelService::InheritWeight, IKernelService::RestoreWeight

Reimplemented from stk::ITask.

Definition at line 343 of file stk_time_timer.h.

343{ return m_weight; }

References m_weight.

◆ Initialize()

void stk::time::TimerHost::TimerWorkerTask::Initialize ( TimerHost * host,
Word * stack,
size_t stack_size,
EAccessMode mode,
TimerFuncType const func )
inline

Bind this task to a host, stack buffer, access mode, and entry function.

Parameters
[in]hostTimerHost instance this task belongs to.
[in]stackPointer to the pre-allocated stack memory.
[in]stack_sizeStack size in words.
[in]modeKernel access mode (user or privileged).
[in]funcEntry function called in the task's context.
Note
Must be called before the task is added to the kernel.

Definition at line 359 of file stk_time_timer.h.

361 {
362 m_host = host;
363 m_func = func;
364 m_stack = stack;
365 m_stack_size = stack_size;
366 m_mode = mode;
368 }

References stk::DEFAULT_WEIGHT, m_func, m_host, m_mode, m_stack, m_stack_size, m_weight, and stk::time::TimerHost::TimerHost().

Here is the call graph for this function:

◆ OnDeadlineMissed()

void stk::time::TimerHost::TimerWorkerTask::OnDeadlineMissed ( uint32_t duration)
inlineoverridevirtual

Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time mode (see stk::KERNEL_HRT).

Parameters
[in]durationElapsed active time in ticks at the point the deadline was detected. Always greater than the task's configured deadline (ticks).
Note
Optional handler. Use it for fault logging.
After this call returns, IPlatform::ProcessHardFault() is invoked and the system enters a safe state. This function should not attempt to recover scheduling.

Reimplemented from stk::ITask.

Definition at line 341 of file stk_time_timer.h.

341{}

◆ OnExit()

void stk::time::TimerHost::TimerWorkerTask::OnExit ( )
inlineoverridevirtual

Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).

Note
The task's stack is no longer in use but the ITask object itself is still valid.
The default no-op implementation is sufficient for detached tasks. Override to implement join semantics (signal a waiting joiner).
Called in kernel/tick context - keep it short. ISR-safe primitives only (e.g. stk::sync::Semaphore::Signal(), stk::sync::EventFlags::Set()).
KERNEL_DYNAMIC only. Never called in KERNEL_STATIC mode.

Reimplemented from stk::ITask.

Definition at line 342 of file stk_time_timer.h.

342{}

◆ Run()

void stk::time::TimerHost::TimerWorkerTask::Run ( )
inlineoverrideprivatevirtual

Timer task entry point.

Implements stk::ITask.

Definition at line 377 of file stk_time_timer.h.

377{ m_func(m_host); }

References m_func, and m_host.

◆ SetWeight()

void stk::time::TimerHost::TimerWorkerTask::SetWeight ( int32_t weight)
inline

Override the scheduling weight assigned by Initialize().

Parameters
[in]weightNew scheduling weight value.

Definition at line 373 of file stk_time_timer.h.

373{ m_weight = weight; }

References m_weight.

Member Data Documentation

◆ m_func

TimerFuncType stk::time::TimerHost::TimerWorkerTask::m_func
private

entry function (tick loop or handler loop)

Definition at line 379 of file stk_time_timer.h.

Referenced by Initialize(), Run(), and TimerWorkerTask().

◆ m_host

TimerHost* stk::time::TimerHost::TimerWorkerTask::m_host
private

owning TimerHost instance

Definition at line 380 of file stk_time_timer.h.

Referenced by Initialize(), Run(), and TimerWorkerTask().

◆ m_mode

EAccessMode stk::time::TimerHost::TimerWorkerTask::m_mode
private

kernel access mode

Definition at line 383 of file stk_time_timer.h.

Referenced by GetAccessMode(), Initialize(), and TimerWorkerTask().

◆ m_stack

Word* stk::time::TimerHost::TimerWorkerTask::m_stack
private

pointer to stack buffer

Definition at line 381 of file stk_time_timer.h.

Referenced by GetStack(), Initialize(), and TimerWorkerTask().

◆ m_stack_size

size_t stk::time::TimerHost::TimerWorkerTask::m_stack_size
private

stack size in words

Definition at line 382 of file stk_time_timer.h.

Referenced by GetStackSize(), GetStackSizeBytes(), Initialize(), and TimerWorkerTask().

◆ m_weight

int32_t stk::time::TimerHost::TimerWorkerTask::m_weight
private

scheduling weight

Definition at line 384 of file stk_time_timer.h.

Referenced by GetWeight(), Initialize(), SetWeight(), and TimerWorkerTask().


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