SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
anonymous_namespace{threadx_stk.cpp}::StkThread Class Referencefinal
Inheritance diagram for anonymous_namespace{threadx_stk.cpp}::StkThread:
Collaboration diagram for anonymous_namespace{threadx_stk.cpp}::StkThread:

Public Member Functions

 StkThread (TX_THREAD *tx)
virtual ~StkThread ()
void Run () override
 Entry point of the user task.
void OnExit () override
 Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).
const stk::Word * GetStack () const override
 Get pointer to the stack memory.
size_t GetStackSize () const override
 Get number of elements of the stack memory array.
stk::EAccessMode GetAccessMode () const override
 Get pointer to the stack memory.
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).
stk::Weight GetWeight () const override
 Get static base weight of the task.
const char * GetTraceName () const override
 Get task trace name set by application.
stk::Timeout GetTimeSlice () const override
 Get time-slice quantum of the task (ticks). KERNEL_TIMESLICE only.
virtual size_t GetStackSpace () const
 Get available stack space.

Public Attributes

TX_THREAD * m_tx
volatile stk::Weight m_weight
stk::Timeout m_time_slice
volatile bool m_registered
volatile bool m_removed
volatile UINT m_wait_kind
volatile bool m_abort

Private Member Functions

 STK_NONCOPYABLE_CLASS (StkThread)

Detailed Description

Definition at line 142 of file threadx_stk.cpp.

Constructor & Destructor Documentation

◆ StkThread()

anonymous_namespace{threadx_stk.cpp}::StkThread::StkThread ( TX_THREAD * tx)
inlineexplicit

Definition at line 147 of file threadx_stk.cpp.

150 m_registered(false), m_removed(true), m_wait_kind(TX_READY), m_abort(false)
151 {}
#define TX_READY
Definition tx_api.h:160
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:170
__stk_forceinline stk::Weight ToStkWeight(UINT priority, UINT threshold)
UINT tx_thread_preempt_threshold
Definition tx_api.h:251
ULONG tx_thread_time_slice
Definition tx_api.h:247
UINT tx_thread_priority
Definition tx_api.h:249

References m_abort, m_registered, m_removed, m_time_slice, m_tx, m_wait_kind, m_weight, anonymous_namespace{threadx_stk.cpp}::ToStkWeight(), and TX_READY.

Referenced by STK_NONCOPYABLE_CLASS().

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

◆ ~StkThread()

virtual anonymous_namespace{threadx_stk.cpp}::StkThread::~StkThread ( )
inlinevirtual

Definition at line 153 of file threadx_stk.cpp.

154 {}

Member Function Documentation

◆ GetAccessMode()

stk::EAccessMode anonymous_namespace{threadx_stk.cpp}::StkThread::GetAccessMode ( ) const
inlineoverridevirtual

Get pointer to the stack memory.

Note
Optional. ARM TrustZone only.
Returns
Pointer to the Secure stack memory.

Get up to (STK_MPU_TASK_REGIONS - 1) application-defined MPU regions for this task.

When STK_MPU_STACK_GUARD is enabled, each task owns STK_MPU_TASK_REGIONS (2, 4, 6, 8, 12 or 16, see STK_MPU_TASK_REGIONS) hardware MPU region slots. Slot 0 is always the automatic stack guard, computed by the driver from the task's own stack memory (see IStackMemory::GetStack/GetStackSize). This hook supplies the remaining STK_MPU_TASK_REGIONS-1 slots, letting an application additionally sandbox a task to e.g. a private data buffer, a specific peripheral block, or a shared IPC region - on top of its stack guard.

Returns
Pointer to a constant MpuRegionList containing up to (STK_MPU_TASK_REGIONS - 1) region descriptors, or nullptr if no extra task regions are configured. Array element i is applied at task-relative region index i +1 (i.e. the slots following the stack guard).
Note
Optional. Only consulted when STK_MPU_STACK_GUARD is enabled; a no-op on platforms/builds without MPU stack-guard support.
Read once, when the task is bound via Kernel::AddTask() (through IPlatform::InitStack()), not re-evaluated on every context switch. The underlying MpuRegionList instance referenced by the returned pointer must remain valid (e.g. a static const instance); a stack-local temporary is invalid once this function returns.
Warning
An element count greater than (STK_MPU_TASK_REGIONS - 1) is clamped by the driver (STK_ASSERT fires in debug builds); only the first STK_MPU_TASK_REGIONS-1 entries are ever applied.
class MyTask : public stk::Task<256, stk::ACCESS_USER>
{
static constexpr stk::MpuRegionConfig s_extra_regions[] =
{
{ .addr = MY_BUFFER_ADDR, .size = MY_BUFFER_SIZE,
.access_perm = stk::hw::mpu::ACCESS_FULL,
.mem_type = stk::hw::mpu::TYPE_NORMAL_CACHEABLE,
.exec = stk::hw::mpu::EXEC_NEVER },
};
const stk::MpuRegionList *GetMpuRegions() const override
{
static const stk::MpuRegionList mpu_regions(s_extra_regions, 1U);
return &mpu_regions;
}
void Run() override { ... }
};
virtual void Run()=0
Entry point of the user task.
Partial implementation of the user task.
Definition stk_helper.h:98
See also
TaskMpu::Configure, IPlatform::InitStack, MpuRegionList

Get hardware access mode of the user task.

Implements stk::ITask.

Definition at line 193 of file threadx_stk.cpp.

193{ return stk::ACCESS_PRIVILEGED; }
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Definition stk_common.h:38

References stk::ACCESS_PRIVILEGED.

◆ GetStack()

const stk::Word * anonymous_namespace{threadx_stk.cpp}::StkThread::GetStack ( ) const
inlineoverridevirtual

Get pointer to the stack memory.

Implements stk::IStackMemory.

Definition at line 189 of file threadx_stk.cpp.

189{ return static_cast<const stk::Word *>(m_tx->tx_thread_stack_start); }
uintptr_t Word
Native processor word type.
Definition stk_common.h:160

References m_tx.

◆ GetStackSize()

size_t anonymous_namespace{threadx_stk.cpp}::StkThread::GetStackSize ( ) const
inlineoverridevirtual

Get number of elements of the stack memory array.

Implements stk::IStackMemory.

Definition at line 190 of file threadx_stk.cpp.

190{ return (static_cast<size_t>(m_tx->tx_thread_stack_size) / sizeof(stk::Word)); }

References m_tx.

◆ 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 465 of file stk_common.h.

466 {
467 const ArrayView<const Word> stack(GetStack(), GetStackSize());
468 const size_t total_size = stack.GetSize();
469 size_t space = 0U;
470
471 for (size_t i = 0U; i < total_size; ++i)
472 {
473 if (stack[i] == STK_STACK_MEMORY_FILLER)
474 {
475 space = i + 1U;
476 }
477 else
478 {
479 break; // terminate loop as soon as watermark ends
480 }
481 }
482
483 return space;
484 }
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:563
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:

◆ GetTimeSlice()

stk::Timeout anonymous_namespace{threadx_stk.cpp}::StkThread::GetTimeSlice ( ) const
inlineoverridevirtual

Get time-slice quantum of the task (ticks). KERNEL_TIMESLICE only.

Returns
Number of ticks the task may run before being rotated behind its same-priority peers, or NO_TIME_SLICE (default) to run until it blocks, yields or is preempted.
Note
Read once when the task is bound by Kernel::AddTask(). Use IKernelService::SetTimeSlice() to change it at run-time.
See also
stk::KERNEL_TIMESLICE, IKernelService::SetTimeSlice

Reimplemented from stk::ITask.

Definition at line 197 of file threadx_stk.cpp.

197{ return m_time_slice; }

References m_time_slice.

◆ GetTraceName()

const char * anonymous_namespace{threadx_stk.cpp}::StkThread::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 196 of file threadx_stk.cpp.

196{ return m_tx->tx_thread_name; }

References m_tx.

◆ GetWeight()

stk::Weight anonymous_namespace{threadx_stk.cpp}::StkThread::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 195 of file threadx_stk.cpp.

195{ return m_weight; }

References m_weight.

◆ OnDeadlineMissed()

void anonymous_namespace{threadx_stk.cpp}::StkThread::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 194 of file threadx_stk.cpp.

194{}

◆ OnExit()

void anonymous_namespace{threadx_stk.cpp}::StkThread::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 182 of file threadx_stk.cpp.

183 {
184 m_registered = false;
185 m_removed = true;
186 }

References m_registered, and m_removed.

◆ Run()

void anonymous_namespace{threadx_stk.cpp}::StkThread::Run ( )
inlineoverridevirtual

Entry point of the user task.

Note
Called by the Kernel when the task is scheduled for execution. Implement this method with the task's main logic.
Warning
If Kernel is configured as KERNEL_STATIC, the body must contain an infinite loop.
void Run( override)
{
while (true)
{
// task logic here
}
}
void Run() override
Entry point of the user task.

Implements stk::ITask.

Definition at line 156 of file threadx_stk.cpp.

157 {
158 TX_THREAD *const tx = m_tx;
159
161
162 if (tx->tx_thread_entry_exit_notify != nullptr)
163 {
165 }
166
168
169 // returning from the entry function completes the thread (KERNEL_DYNAMIC removes the task itself)
171 {
173
174 if (tx->tx_thread_entry_exit_notify != nullptr)
175 {
177 }
178 }
179 }
#define TX_COMPLETED
Definition tx_api.h:161
#define TX_THREAD_EXIT
Definition tx_api.h:149
#define TX_TERMINATED
Definition tx_api.h:162
#define TX_THREAD_ENTRY
Definition tx_api.h:148
struct TX_THREAD_STRUCT TX_THREAD
void(* tx_thread_entry)(ULONG entry_input)
Definition tx_api.h:252
UINT tx_thread_state
Definition tx_api.h:250
ULONG tx_thread_entry_parameter
Definition tx_api.h:253
void(* tx_thread_entry_exit_notify)(struct TX_THREAD_STRUCT *thread_ptr, UINT condition)
Definition tx_api.h:254
ULONG tx_thread_run_count
Definition tx_api.h:244

References m_tx, TX_COMPLETED, TX_TERMINATED, TX_THREAD_ENTRY, TX_THREAD_STRUCT::tx_thread_entry, TX_THREAD_STRUCT::tx_thread_entry_exit_notify, TX_THREAD_STRUCT::tx_thread_entry_parameter, TX_THREAD_EXIT, TX_THREAD_STRUCT::tx_thread_run_count, and TX_THREAD_STRUCT::tx_thread_state.

◆ STK_NONCOPYABLE_CLASS()

anonymous_namespace{threadx_stk.cpp}::StkThread::STK_NONCOPYABLE_CLASS ( StkThread )
private

References StkThread().

Here is the call graph for this function:

Member Data Documentation

◆ m_abort

volatile bool anonymous_namespace{threadx_stk.cpp}::StkThread::m_abort

Definition at line 206 of file threadx_stk.cpp.

Referenced by StkThread().

◆ m_registered

volatile bool anonymous_namespace{threadx_stk.cpp}::StkThread::m_registered

◆ m_removed

◆ m_time_slice

stk::Timeout anonymous_namespace{threadx_stk.cpp}::StkThread::m_time_slice

Definition at line 202 of file threadx_stk.cpp.

Referenced by GetTimeSlice(), and StkThread().

◆ m_tx

TX_THREAD* anonymous_namespace{threadx_stk.cpp}::StkThread::m_tx

◆ m_wait_kind

volatile UINT anonymous_namespace{threadx_stk.cpp}::StkThread::m_wait_kind

◆ m_weight

volatile stk::Weight anonymous_namespace{threadx_stk.cpp}::StkThread::m_weight

Definition at line 201 of file threadx_stk.cpp.

Referenced by GetWeight(), and StkThread().


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