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

Public Member Functions

void OnExpired (stk::time::TimerHost *host) 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.

Private Types

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
uint32_t m_period
 reload period in ticks (0 = one-shot)
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 833 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 70 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 75 of file stk_linked_list.h.

Member Function Documentation

◆ 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 174 of file stk_time_timer.h.

174{ 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 80 of file stk_linked_list.h.

80{ return m_head; }
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...

◆ 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 93 of file stk_linked_list.h.

93{ 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 185 of file stk_time_timer.h.

185{ 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 109 of file stk_linked_list.h.

109{ 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 472 of file stk_time_timer.h.

473{
474 uint32_t remaining_ticks = 0U;
475
476 if (m_active)
477 {
478 // if deadline has passed but not yet been processed by the tick task,
479 // remaining would be negative, result fits in uint32_t because delay and
480 // period are uint32_t, so remaining time is bounded by uint32_t max
481 const Ticks remaining = m_deadline - GetTicks();
482
483 if (remaining > 0)
484 {
485 remaining_ticks = static_cast<uint32_t>(remaining);
486 }
487 }
488
489 return remaining_ticks;
490}
Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:274
int64_t Ticks
Ticks value.
Definition stk_common.h:130
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 180 of file stk_time_timer.h.

180{ 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 168 of file stk_time_timer.h.

168{ return m_active; }

References m_active.

Referenced by osTimerDelete(), 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 122 of file stk_linked_list.h.

122{ 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 157 of file stk_linked_list.h.

158 {
159 m_head = head;
160 m_next = next;
161 m_prev = prev;
162
163 if (m_prev != nullptr)
164 {
165 m_prev->m_next = this;
166 }
167
168 if (m_next != nullptr)
169 {
170 m_next->m_prev = this;
171 }
172 }
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 FrtosPendDrainer::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 835 of file freertos_stk.cpp.

836 {
837 PendCall call;
838 while (g_PendCallPipe.TryRead(call))
839 call.func(call.param1, call.param2);
840
841 // Pipe is empty: stop the auto-reload drainer until the next enqueue.
842 // host->Stop() is safe to call from OnExpired() because the TimerHost
843 // removes the timer from the active list before dispatching OnExpired.
844 if (host != nullptr)
845 host->Stop(*this);
846 }
static stk::sync::PipeT< PendCall, 8U > g_PendCallPipe
bool Stop(Timer &tmr)
Stop running timer.
PendedFunction_t func
void * param1
uint32_t param2

References PendCall::func, g_PendCallPipe, PendCall::param1, PendCall::param2, and stk::time::TimerHost::Stop().

Here is the call graph for this function:

◆ 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 136 of file stk_linked_list.h.

136{ 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 129 of file stk_linked_list.h.

129{ 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 181 of file stk_linked_list.h.

182 {
183 if (m_prev != nullptr)
184 {
186 }
187
188 if (m_next != nullptr)
189 {
191 }
192
193 m_head = nullptr;
194 m_next = nullptr;
195 m_prev = nullptr;
196 }

Member Data Documentation

◆ m_active

◆ m_deadline

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

absolute expiration time (ticks)

Definition at line 198 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 198 of file stk_linked_list.h.

◆ 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 199 of file stk_linked_list.h.

◆ m_pending

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

◆ m_period

uint32_t stk::time::TimerHost::Timer::m_period
privateinherited

◆ 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 200 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 203 of file stk_time_timer.h.

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

◆ m_timestamp

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

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

Definition at line 199 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: