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
FrtosTimer Struct Reference
Inheritance diagram for FrtosTimer:
Collaboration diagram for FrtosTimer:

Public Types

enum  { DLEntryTag = 1 }
 A tag for type-safe casts done by CastListEntryToParent. More...

Public Member Functions

 FrtosTimer (const char *name, TickType_t period, bool auto_reload, void *timer_id, TimerCallbackFunction_t cb)
virtual ~FrtosTimer ()
void OnExpired (stk::time::TimerHost *) override
 Callback invoked by the handler task when this timer expires.
bool IsActive () const
 Check whether the timer is currently active.
Ticks GetDeadline () const
 Get the absolute time in ticks at which the timer will expire.
Ticks GetTimestamp () const
 Get the tick count at which the timer last expired.
uint32_t GetPeriod () const
 Get the reload period of the timer.
uint32_t GetRemainingTicks () const
 Get remaining ticks until the timer next expires.

Static Public Member Functions

static bool EnsureTimerHost ()

Public Attributes

const char * m_name
TickType_t m_period
bool m_auto_reload
void * m_timer_id
TimerCallbackFunction_t m_callback
bool m_cb_owned

Private Types

enum  
 A tag for type-safe casts done by CastListEntryToParent. More...
typedef DListEntry< Timer, TClosedLoop > DLEntryType
 Convenience alias for this entry type. Used to avoid repeating the full template spelling.
typedef DListHead< Timer, TClosedLoop > DLHeadType
 Convenience alias for the corresponding list head type.

Private Member Functions

 STK_NONCOPYABLE_CLASS (Timer)
DLHeadTypeGetHead ()
 Get the list head this entry currently belongs to.
DLEntryTypeGetNext ()
 Get the next entry in the list.
DLEntryTypeGetPrev ()
 Get the previous entry in the list.
bool IsLinked () const
 Check whether this entry is currently a member of any list.
 operator Timer * ()
 Implicit conversion to a mutable pointer to the host object (T).
 operator const Timer * () const
 Implicit conversion to a const pointer to the host object (T).
void Link (DLHeadType *head, DLEntryType *next, DLEntryType *prev)
 Wire this entry into a list between prev and next.
void Unlink ()
 Remove this entry from its current list.

Private Attributes

Ticks m_deadline
 absolute expiration time (ticks)
Ticks m_timestamp
 absolute time at which timer expired (ticks), updated by TimerHost
volatile bool m_active
 true if active
volatile bool m_pending
 true if pending to be handled
volatile bool m_rearming
 true while a CMD_RESTART / CMD_START_OR_RESET is already in the command queue
DLHeadTypem_head
 Owning list head, or NULL when the entry is not linked.
DLEntryTypem_next
 Next entry in the list, or NULL (open list boundary) / first entry (closed loop).
DLEntryTypem_prev
 Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).

Detailed Description

Definition at line 762 of file freertos_stk.cpp.

Member Typedef Documentation

◆ DLEntryType

typedef DListEntry<Timer, TClosedLoop> stk::util::DListEntry< Timer, TClosedLoop >::DLEntryType
inherited

Convenience alias for this entry type. Used to avoid repeating the full template spelling.

Definition at line 75 of file stk_linked_list.h.

◆ DLHeadType

typedef DListHead<Timer, TClosedLoop> stk::util::DListEntry< Timer, TClosedLoop >::DLHeadType
inherited

Convenience alias for the corresponding list head type.

Definition at line 80 of file stk_linked_list.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited

A tag for type-safe casts done by CastListEntryToParent.

See also
CastListEntryToParent.
Enumerator
DLEntryTag 

Definition at line 158 of file stk_time_timer.h.

◆ anonymous enum

anonymous enum
inherited

A tag for type-safe casts done by CastListEntryToParent.

See also
CastListEntryToParent.

Definition at line 70 of file stk_linked_list.h.

70{ DLEntryTag = 1 };
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...

Constructor & Destructor Documentation

◆ FrtosTimer()

FrtosTimer::FrtosTimer ( const char * name,
TickType_t period,
bool auto_reload,
void * timer_id,
TimerCallbackFunction_t cb )
inlineexplicit

Definition at line 764 of file freertos_stk.cpp.

769 : m_name(name), m_period(period), m_auto_reload(auto_reload),
770 m_timer_id(timer_id), m_callback(cb), m_cb_owned(true)
771 {}
void * m_timer_id
TickType_t m_period
const char * m_name
TimerCallbackFunction_t m_callback

References m_auto_reload, m_callback, m_cb_owned, m_name, m_period, and m_timer_id.

◆ ~FrtosTimer()

virtual FrtosTimer::~FrtosTimer ( )
inlinevirtual

Definition at line 773 of file freertos_stk.cpp.

773{}

Member Function Documentation

◆ EnsureTimerHost()

bool FrtosTimer::EnsureTimerHost ( )
inlinestatic

Definition at line 780 of file freertos_stk.cpp.

781 {
782 if (g_TimerHost == nullptr)
783 {
784 g_TimerHost = new (g_TimerHostBuf) stk::time::TimerHost();
786 }
787 return (g_TimerHost != nullptr);
788 }
static FrtosKernel g_StkKernel
static stk::time::TimerHost * g_TimerHost
static stk::Word g_TimerHostBuf[StkGetWordCountForType< stk::time::TimerHost >()]
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Definition stk_common.h:34
void Initialize(IKernel *kernel, EAccessMode mode)
Initialize timer host instance.

References stk::ACCESS_PRIVILEGED, g_StkKernel, g_TimerHost, and g_TimerHostBuf.

Referenced by xTimerCreate(), xTimerCreateStatic(), and xTimerPendFunctionCall().

Here is the caller graph for this function:

◆ GetDeadline()

Ticks stk::time::TimerHost::Timer::GetDeadline ( ) const
inlineinherited

Get the absolute time in ticks at which the timer will expire.

Returns
Absolute expiration deadline in ticks.
Note
Meaningful only when IsActive() returns true.

Definition at line 180 of file stk_time_timer.h.

180{ return m_deadline; }
Ticks m_deadline
absolute expiration time (ticks)

References m_deadline.

Referenced by stk_timer_get_deadline(), and xTimerGetExpiryTime().

Here is the caller graph for this function:

◆ GetHead()

DLHeadType * stk::util::DListEntry< Timer, TClosedLoop >::GetHead ( )
inlineinherited

Get the list head this entry currently belongs to.

Returns
Pointer to the owning DListHead, or NULL if the entry is not linked.

Definition at line 85 of file stk_linked_list.h.

85{ return m_head; }

◆ GetNext()

DLEntryType * stk::util::DListEntry< Timer, TClosedLoop >::GetNext ( )
inlineinherited

Get the next entry in the list.

Returns
Pointer to the next DListEntry, or NULL if this is the last entry (open list) or the first entry (closed loop, where next wraps to first).
Note
In a closed loop (TClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 98 of file stk_linked_list.h.

98{ return m_next; }

◆ GetPeriod()

uint32_t stk::time::TimerHost::Timer::GetPeriod ( ) const
inlineinherited

Get the reload period of the timer.

Returns
Period in ticks, or 0 for a one-shot timer.

Definition at line 191 of file stk_time_timer.h.

191{ return m_period; }
uint32_t m_period
reload period in ticks (0 = one-shot)

References m_period.

Referenced by stk_timer_get_period().

Here is the caller graph for this function:

◆ GetPrev()

DLEntryType * stk::util::DListEntry< Timer, TClosedLoop >::GetPrev ( )
inlineinherited

Get the previous entry in the list.

Returns
Pointer to the previous DListEntry, or NULL if this is the first entry (open list) or the last entry (closed loop, where prev wraps to last).
Note
In a closed loop (TClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 114 of file stk_linked_list.h.

114{ return m_prev; }

◆ GetRemainingTicks()

uint32_t stk::time::TimerHost::Timer::GetRemainingTicks ( ) const
inlineinherited

Get remaining ticks until the timer next expires.

Returns
Ticks remaining, or 0 if already expired / not active.
Note
The value is advisory: it is computed from m_now (the last value written by the tick task) and may be up to one tick task wake cycle stale. If the deadline has already passed but not yet been processed, 0 is returned.

Definition at line 478 of file stk_time_timer.h.

479{
480 uint32_t remaining_ticks = 0U;
481
482 if (m_active)
483 {
484 // if deadline has passed but not yet been processed by the tick task,
485 // remaining would be negative, result fits in uint32_t because delay and
486 // period are uint32_t, so remaining time is bounded by uint32_t max
487 const Ticks remaining = m_deadline - GetTicks();
488
489 if (remaining > 0)
490 {
491 remaining_ticks = static_cast<uint32_t>(remaining);
492 }
493 }
494
495 return remaining_ticks;
496}
int64_t Ticks
Ticks value.
Definition stk_common.h:130
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:319
volatile bool m_active
true if active

References stk::GetTicks(), m_active, and m_deadline.

Referenced by stk_timer_get_remaining_ticks().

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

◆ GetTimestamp()

Ticks stk::time::TimerHost::Timer::GetTimestamp ( ) const
inlineinherited

Get the tick count at which the timer last expired.

Returns
Absolute tick count recorded by the tick task at expiration time, or 0 if the timer has never fired.

Definition at line 186 of file stk_time_timer.h.

186{ return m_timestamp; }
Ticks m_timestamp
absolute time at which timer expired (ticks), updated by TimerHost

References m_timestamp.

Referenced by stk_timer_get_timestamp().

Here is the caller graph for this function:

◆ IsActive()

bool stk::time::TimerHost::Timer::IsActive ( ) const
inlineinherited

Check whether the timer is currently active.

Returns
True if the timer has been started and not yet stopped or expired (one-shot).
Note
The value is advisory, it is written by the tick task and read without synchronization, so it may be transiently stale on multi-core targets.

Definition at line 174 of file stk_time_timer.h.

174{ return m_active; }

References m_active.

Referenced by osTimerDelete(), osTimerIsRunning(), osTimerStop(), stk_timer_destroy(), stk_timer_is_active(), xTimerDelete(), xTimerGetExpiryTime(), xTimerStop(), and xTimerStopFromISR().

Here is the caller graph for this function:

◆ IsLinked()

bool stk::util::DListEntry< Timer, TClosedLoop >::IsLinked ( ) const
inlineinherited

Check whether this entry is currently a member of any list.

Returns
true if linked (m_head != NULL); false otherwise.

Definition at line 127 of file stk_linked_list.h.

127{ return (GetHead() != nullptr); }

◆ Link()

void stk::util::DListEntry< Timer, TClosedLoop >::Link ( DLHeadType * head,
DLEntryType * next,
DLEntryType * prev )
inlineprivateinherited

Wire this entry into a list between prev and next.

Parameters
[in]headThe owning DListHead. Stored as a back-pointer for IsLinked() and ownership checks.
[in]nextThe entry that will follow this one, or NULL if this becomes the last entry.
[in]prevThe entry that will precede this one, or NULL if this becomes the first entry.
Note
Called exclusively by DListHead::Link(). Assumes the entry is not currently linked. Updates the neighbours' forward/back pointers to splice this entry in.

Definition at line 162 of file stk_linked_list.h.

163 {
164 m_head = head;
165 m_next = next;
166 m_prev = prev;
167
168 if (m_prev != nullptr)
169 {
170 m_prev->m_next = this;
171 }
172
173 if (m_next != nullptr)
174 {
175 m_next->m_prev = this;
176 }
177 }
DLEntryType * m_next
Next entry in the list, or NULL (open list boundary) / first entry (closed loop).
DLEntryType * m_prev
Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).

◆ OnExpired()

void FrtosTimer::OnExpired ( stk::time::TimerHost * host)
inlineoverridevirtual

Callback invoked by the handler task when this timer expires.

Parameters
[in]hostPointer to the TimerHost that fired this timer.
Note
Executes in the context of a TimerHost handler task. Implementations must be safe to call from that task's context and should complete quickly, long-running work should be delegated (e.g. via an event or queue) to avoid blocking other expired timers.

Implements stk::time::TimerHost::Timer.

Definition at line 775 of file freertos_stk.cpp.

776 {
777 m_callback(static_cast<TimerHandle_t>(this));
778 }
void * TimerHandle_t
Definition FreeRTOS.h:313

References m_callback.

◆ operator const Timer *()

stk::util::DListEntry< Timer, TClosedLoop >::operator const Timer * ( ) const
inlineinherited

Implicit conversion to a const pointer to the host object (T).

Note
Safe because T must derive from DListEntry<T, TClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 141 of file stk_linked_list.h.

141{ return static_cast<const T *>(this); }

◆ operator Timer *()

stk::util::DListEntry< Timer, TClosedLoop >::operator Timer* ( )
inlineinherited

Implicit conversion to a mutable pointer to the host object (T).

Note
Safe because T must derive from DListEntry<T, TClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 134 of file stk_linked_list.h.

134{ return static_cast<T *>(this); }

◆ STK_NONCOPYABLE_CLASS()

stk::time::TimerHost::Timer::STK_NONCOPYABLE_CLASS ( Timer )
privateinherited

References Timer().

Here is the call graph for this function:

◆ Unlink()

void stk::util::DListEntry< Timer, TClosedLoop >::Unlink ( )
inlineprivateinherited

Remove this entry from its current list.

Note
Called exclusively by DListHead::Unlink(). Patches the neighbours' pointers to bridge over this entry, then clears m_head, m_next, and m_prev to NULL so the entry is in a clean unlinked state.
Does not update DListHead::m_count or m_first / m_last — those are the responsibility of the calling DListHead::Unlink().

Definition at line 186 of file stk_linked_list.h.

187 {
188 if (m_prev != nullptr)
189 {
191 }
192
193 if (m_next != nullptr)
194 {
196 }
197
198 m_head = nullptr;
199 m_next = nullptr;
200 m_prev = nullptr;
201 }

Member Data Documentation

◆ m_active

◆ m_auto_reload

bool FrtosTimer::m_auto_reload

◆ m_callback

TimerCallbackFunction_t FrtosTimer::m_callback

Definition at line 794 of file freertos_stk.cpp.

Referenced by FrtosTimer(), and OnExpired().

◆ m_cb_owned

bool FrtosTimer::m_cb_owned

Definition at line 795 of file freertos_stk.cpp.

Referenced by FrtosTimer(), and xTimerCreateStatic().

◆ m_deadline

Ticks stk::time::TimerHost::Timer::m_deadline
privateinherited

absolute expiration time (ticks)

Definition at line 204 of file stk_time_timer.h.

Referenced by GetDeadline(), GetRemainingTicks(), stk::time::TimerHost::ProcessCommands(), Timer(), and stk::time::TimerHost::UpdateTime().

◆ m_head

DLHeadType* stk::util::DListEntry< Timer, TClosedLoop >::m_head
privateinherited

Owning list head, or NULL when the entry is not linked.

Definition at line 203 of file stk_linked_list.h.

◆ m_name

const char* FrtosTimer::m_name

Definition at line 790 of file freertos_stk.cpp.

Referenced by FrtosTimer().

◆ m_next

DLEntryType* stk::util::DListEntry< Timer, TClosedLoop >::m_next
privateinherited

Next entry in the list, or NULL (open list boundary) / first entry (closed loop).

Definition at line 204 of file stk_linked_list.h.

◆ m_pending

volatile bool stk::time::TimerHost::Timer::m_pending
privateinherited

◆ m_period

TickType_t FrtosTimer::m_period

◆ m_prev

DLEntryType* stk::util::DListEntry< Timer, TClosedLoop >::m_prev
privateinherited

Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).

Definition at line 205 of file stk_linked_list.h.

◆ m_rearming

volatile bool stk::time::TimerHost::Timer::m_rearming
privateinherited

true while a CMD_RESTART / CMD_START_OR_RESET is already in the command queue

Definition at line 209 of file stk_time_timer.h.

Referenced by stk::time::TimerHost::ProcessCommands(), stk::time::TimerHost::PushCommand(), and Timer().

◆ m_timer_id

void* FrtosTimer::m_timer_id

Definition at line 793 of file freertos_stk.cpp.

Referenced by FrtosTimer().

◆ m_timestamp

Ticks stk::time::TimerHost::Timer::m_timestamp
privateinherited

absolute time at which timer expired (ticks), updated by TimerHost

Definition at line 205 of file stk_time_timer.h.

Referenced by GetTimestamp(), Timer(), and stk::time::TimerHost::UpdateTime().


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