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
StkThread Class Referencefinal
Inheritance diagram for StkThread:
Collaboration diagram for StkThread:

Public Types

enum class  JoinState : uint8_t {
  Detached ,
  Joinable ,
  Exited ,
  Joined
}

Public Member Functions

 StkThread ()
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::WordGetStack () 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 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).
int32_t GetWeight () const override
 Get static base weight of the task.
const char * GetTraceName () const override
 Get task trace name set by application.
virtual IStackMemory * GetSecureStackMemory ()
 Get pointer to the stack memory.
TId GetId () const
 Get task Id set by application.
virtual size_t GetStackSpace () const
 Get available stack space.

Static Public Member Functions

static osThreadId_t ConvertTIdToThreadId (const stk::TId tid)

Public Attributes

osThreadFunc_t m_func
void * m_argument
const char * m_name
volatile int32_t m_stk_priority
stk::Wordm_stack
size_t m_stack_size
volatile JoinState m_join_state
stk::sync::ConditionVariable m_join_cv
stk::sync::EventFlags m_thread_flags
bool m_stack_owned
bool m_suspended
bool m_cb_owned

Private Member Functions

 STK_NONCOPYABLE_CLASS (StkThread)

Detailed Description

Definition at line 175 of file cmsis_os2_stk.cpp.

Member Enumeration Documentation

◆ JoinState

enum class StkThread::JoinState : uint8_t
strong
Enumerator
Detached 
Joinable 
Exited 
Joined 

Definition at line 181 of file cmsis_os2_stk.cpp.

182 {
183 Detached, // osThreadDetach() was called, or created with osThreadDetached
184 Joinable, // created with osThreadJoinable, not yet joined or exited
185 Exited, // Run() has returned; OnExit() has fired; not yet joined
186 Joined, // a joiner has already collected the result; further joins are errors
187 };

Constructor & Destructor Documentation

◆ StkThread()

StkThread::StkThread ( )
inlineexplicit

Definition at line 189 of file cmsis_os2_stk.cpp.

190 : m_func(nullptr), m_argument(nullptr), m_name(nullptr),
193 m_stack_owned(false), m_suspended(false), m_cb_owned(true)
194 {}
static __stk_forceinline int32_t CmsisPrioToStk(osPriority_t p)
@ osPriorityNormal
Priority: normal.
Definition cmsis_os2.h:196
stk::Word * m_stack
size_t m_stack_size
volatile JoinState m_join_state
volatile int32_t m_stk_priority
osThreadFunc_t m_func
const char * m_name
void * m_argument

References CmsisPrioToStk(), m_argument, m_cb_owned, m_func, m_join_state, m_name, m_stack, m_stack_owned, m_stack_size, m_stk_priority, m_suspended, and osPriorityNormal.

Referenced by ConvertTIdToThreadId(), and STK_NONCOPYABLE_CLASS().

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

◆ ~StkThread()

virtual StkThread::~StkThread ( )
inlinevirtual

Definition at line 196 of file cmsis_os2_stk.cpp.

197 {
198 if (m_stack_owned && (m_stack != nullptr))
199 {
200 delete[] m_stack;
201 m_stack = nullptr;
202 }
203 }

References m_stack, and m_stack_owned.

Member Function Documentation

◆ ConvertTIdToThreadId()

osThreadId_t StkThread::ConvertTIdToThreadId ( const stk::TId tid)
inlinestatic

Definition at line 230 of file cmsis_os2_stk.cpp.

231 {
232 // tid is hw::PtrToWord(this) where 'this' is the StkThread* - cast it back.
233 return reinterpret_cast<osThreadId_t>(static_cast<void *>(
234 reinterpret_cast<StkThread *>(static_cast<uintptr_t>(tid))));
235 }
void * osThreadId_t
Definition cmsis_os2.h:311

References StkThread().

Referenced by osMutexGetOwner(), and osThreadGetId().

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

◆ GetAccessMode()

stk::EAccessMode StkThread::GetAccessMode ( ) const
inlineoverridevirtual

Get hardware access mode of the user task.

Implements stk::ITask.

Definition at line 225 of file cmsis_os2_stk.cpp.

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

References stk::ACCESS_PRIVILEGED.

◆ 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 228 of file stk_helper.h.

229{
230 return GetTidFromUserTask(this);
231}
static constexpr TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Definition stk_arch.h:526

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:

◆ GetSecureStackMemory()

virtual IStackMemory * stk::ITask::GetSecureStackMemory ( )
inlinevirtualinherited

Get pointer to the stack memory.

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

Definition at line 692 of file stk_common.h.

692{ return nullptr; }

◆ GetStack()

const stk::Word * StkThread::GetStack ( ) const
inlineoverridevirtual

Get pointer to the stack memory.

Implements stk::IStackMemory.

Definition at line 221 of file cmsis_os2_stk.cpp.

221{ return m_stack; }

References m_stack.

◆ GetStackSize()

size_t StkThread::GetStackSize ( ) const
inlineoverridevirtual

Get number of elements of the stack memory array.

Implements stk::IStackMemory.

Definition at line 222 of file cmsis_os2_stk.cpp.

222{ return m_stack_size; }

References m_stack_size.

Referenced by osThreadGetStackSize().

Here is the caller graph for this function:

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

337 {
338 const ArrayView<const Word> stack(GetStack(), GetStackSize());
339 const size_t total_size = stack.GetSize();
340 size_t space = 0U;
341
342 for (size_t i = 0U; i < total_size; ++i)
343 {
344 if (stack[i] == STK_STACK_MEMORY_FILLER)
345 {
346 space = i + 1U;
347 }
348 else
349 {
350 break; // terminate loop as soon as watermark ends
351 }
352 }
353
354 return space;
355 }
#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 * 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 228 of file cmsis_os2_stk.cpp.

228{ return m_name; }

References m_name.

◆ GetWeight()

int32_t 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 227 of file cmsis_os2_stk.cpp.

227{ return m_stk_priority; }

References m_stk_priority.

◆ OnDeadlineMissed()

void 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 226 of file cmsis_os2_stk.cpp.

226{}

◆ OnExit()

void 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 212 of file cmsis_os2_stk.cpp.

213 {
215
216 // wake any osThreadJoin() caller
217 m_join_cv.NotifyAll();
218 }
stk::sync::ConditionVariable m_join_cv

References Exited, m_join_cv, and m_join_state.

◆ Run()

void 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 205 of file cmsis_os2_stk.cpp.

206 {
208
209 // KERNEL_DYNAMIC: returning from Run() removes the task automatically.
210 }

References m_argument, and m_func.

◆ STK_NONCOPYABLE_CLASS()

StkThread::STK_NONCOPYABLE_CLASS ( StkThread )
private

References StkThread().

Here is the call graph for this function:

Member Data Documentation

◆ m_argument

void* StkThread::m_argument

Definition at line 239 of file cmsis_os2_stk.cpp.

Referenced by osThreadNew(), Run(), and StkThread().

◆ m_cb_owned

bool StkThread::m_cb_owned

Definition at line 249 of file cmsis_os2_stk.cpp.

Referenced by StkThread().

◆ m_func

osThreadFunc_t StkThread::m_func

Definition at line 238 of file cmsis_os2_stk.cpp.

Referenced by osThreadNew(), Run(), and StkThread().

◆ m_join_cv

stk::sync::ConditionVariable StkThread::m_join_cv

Definition at line 245 of file cmsis_os2_stk.cpp.

Referenced by OnExit(), and osThreadJoin().

◆ m_join_state

volatile JoinState StkThread::m_join_state

◆ m_name

const char* StkThread::m_name

Definition at line 240 of file cmsis_os2_stk.cpp.

Referenced by GetTraceName(), osThreadNew(), and StkThread().

◆ m_stack

stk::Word* StkThread::m_stack

Definition at line 242 of file cmsis_os2_stk.cpp.

Referenced by GetStack(), osThreadNew(), StkThread(), and ~StkThread().

◆ m_stack_owned

bool StkThread::m_stack_owned

Definition at line 247 of file cmsis_os2_stk.cpp.

Referenced by osThreadNew(), StkThread(), and ~StkThread().

◆ m_stack_size

size_t StkThread::m_stack_size

Definition at line 243 of file cmsis_os2_stk.cpp.

Referenced by GetStackSize(), osThreadNew(), and StkThread().

◆ m_stk_priority

volatile int32_t StkThread::m_stk_priority

◆ m_suspended

bool StkThread::m_suspended

Definition at line 248 of file cmsis_os2_stk.cpp.

Referenced by osThreadGetState(), osThreadResume(), osThreadSuspend(), and StkThread().

◆ m_thread_flags

stk::sync::EventFlags StkThread::m_thread_flags

Definition at line 246 of file cmsis_os2_stk.cpp.

Referenced by osThreadFlagsClear(), osThreadFlagsSet(), and osThreadFlagsWait().


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