SuperTinyKernel™ RTOS 1.05.3
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::time::TimerHost::Timer Class Referenceabstract

Abstract base class for a timer managed by TimerHost. More...

#include <stk_time_timer.h>

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

Public Member Functions

 Timer ()
 ~Timer ()
 Destructor.
virtual void OnExpired (TimerHost *host)=0
bool IsActive () const
Ticks GetDeadline () const
Ticks GetTimestamp () const
uint32_t GetPeriod () const
uint32_t GetRemainingTime () const
 Get remaining ticks until the timer next expires.

Private Types

typedef DListEntry< Timer, _ClosedLoop > DLEntryType
 Convenience alias for this entry type. Used to avoid repeating the full template spelling.
typedef DListHead< Timer, _ClosedLoop > DLHeadType
 Convenience alias for the corresponding list head type.

Private Member Functions

 STK_NONCOPYABLE_CLASS (Timer)
DLHeadTypeGetHead () const
 Get the list head this entry currently belongs to.
DLEntryTypeGetNext () const
 Get the next entry in the list.
DLEntryTypeGetPrev () const
 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
 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
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).

Friends

class TimerHost

Detailed Description

Abstract base class for a timer managed by TimerHost.

To implement a concrete timer, inherit from this class and override OnExpired(). The timer instance must outlive the TimerHost or be explicitly stopped before destruction, as TimerHost holds a non-owning pointer to each active timer.

Each Timer instance may be registered with at most one TimerHost at a time.

See also
TimerHost::Start, TimerHost::Stop, TimerHost::Reset, TimerHost::Restart

Definition at line 137 of file stk_time_timer.h.

Member Typedef Documentation

◆ DLEntryType

typedef DListEntry<Timer, _ClosedLoop> stk::util::DListEntry< Timer, _ClosedLoop >::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, _ClosedLoop> stk::util::DListEntry< Timer, _ClosedLoop >::DLHeadType
inherited

Convenience alias for the corresponding list head type.

Definition at line 75 of file stk_linked_list.h.

Constructor & Destructor Documentation

◆ Timer()

stk::time::TimerHost::Timer::Timer ( )
inline

Definition at line 142 of file stk_time_timer.h.

142 : m_deadline(0), m_timestamp(0), m_period(0), m_active(false), m_pending(false)
143 {}
volatile bool m_active
true if active
Ticks m_deadline
absolute expiration time (ticks)
Ticks m_timestamp
time at which timer expired (ticks), updated by TimerHost
uint32_t m_period
reload period in ticks (0 = one-shot)
volatile bool m_pending
true if pending to be handled

References m_active, m_deadline, m_pending, m_period, and m_timestamp.

Referenced by STK_NONCOPYABLE_CLASS().

Here is the caller graph for this function:

◆ ~Timer()

stk::time::TimerHost::Timer::~Timer ( )
inline

Destructor.

Note
MISRA deviation: [STK-DEV-005] Rule 10-3-2.

Definition at line 148 of file stk_time_timer.h.

149 {}

Member Function Documentation

◆ GetDeadline()

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

Definition at line 154 of file stk_time_timer.h.

154{ return m_deadline; }

References m_deadline.

Referenced by stk_timer_get_deadline().

Here is the caller graph for this function:

◆ GetHead()

DLHeadType * stk::util::DListEntry< Timer, _ClosedLoop >::GetHead ( ) const
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, _ClosedLoop >::GetNext ( ) const
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 (_ClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 88 of file stk_linked_list.h.

88{ return m_next; }

◆ GetPeriod()

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

Definition at line 156 of file stk_time_timer.h.

156{ return m_period; }

References m_period.

Referenced by stk_timer_get_period().

Here is the caller graph for this function:

◆ GetPrev()

DLEntryType * stk::util::DListEntry< Timer, _ClosedLoop >::GetPrev ( ) const
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 (_ClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 96 of file stk_linked_list.h.

96{ return m_prev; }

◆ GetRemainingTime()

uint32_t stk::time::TimerHost::Timer::GetRemainingTime ( ) const
inline

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

371{
372 if (!m_active)
373 return 0;
374
375 // if deadline has passed but not yet been processed by the tick task,
376 // remaining would be negative, result fits in uint32_t because delay and
377 // period are uint32_t, so remaining time is bounded by uint32_t max
378 Ticks remaining = m_deadline - GetTicks();
379 return (remaining > 0 ? static_cast<uint32_t>(remaining) : 0);
380}
Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:248
int64_t Ticks
Ticks value.
Definition stk_common.h:150

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

Referenced by stk_timer_get_remaining_time().

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

◆ GetTimestamp()

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

Definition at line 155 of file stk_time_timer.h.

155{ return m_timestamp; }

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
inline

Definition at line 153 of file stk_time_timer.h.

153{ return m_active; }

References m_active.

Referenced by stk::test::timer::MultipleTimersTask< _AccessMode >::Run(), stk_timer_destroy(), and stk_timer_is_active().

Here is the caller graph for this function:

◆ IsLinked()

bool stk::util::DListEntry< Timer, _ClosedLoop >::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 101 of file stk_linked_list.h.

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

◆ Link()

void stk::util::DListEntry< Timer, _ClosedLoop >::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 137 of file stk_linked_list.h.

138 {
139 m_head = head;
140 m_next = next;
141 m_prev = prev;
142
143 if (m_prev != nullptr)
144 m_prev->m_next = this;
145
146 if (m_next != nullptr)
147 m_next->m_prev = this;
148 }
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()

virtual void stk::time::TimerHost::Timer::OnExpired ( TimerHost * host)
pure virtual

Implemented in CTimerWrapper, and stk::test::timer::TestTimer.

References TimerHost.

Referenced by stk::time::TimerHost::ProcessTimers().

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

◆ operator const Timer *()

stk::util::DListEntry< Timer, _ClosedLoop >::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, _ClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 115 of file stk_linked_list.h.

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

◆ operator Timer *()

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

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

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

Definition at line 108 of file stk_linked_list.h.

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

◆ STK_NONCOPYABLE_CLASS()

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

References Timer().

Here is the call graph for this function:

◆ Unlink()

void stk::util::DListEntry< Timer, _ClosedLoop >::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 157 of file stk_linked_list.h.

158 {
159 if (m_prev != nullptr)
161
162 if (m_next != nullptr)
164
165 m_head = nullptr;
166 m_next = nullptr;
167 m_prev = nullptr;
168 }

◆ TimerHost

friend class TimerHost
friend

Definition at line 139 of file stk_time_timer.h.

References TimerHost.

Referenced by CTimerWrapper::OnExpired(), OnExpired(), and TimerHost.

Member Data Documentation

◆ m_active

◆ m_deadline

Ticks stk::time::TimerHost::Timer::m_deadline
private

absolute expiration time (ticks)

Definition at line 169 of file stk_time_timer.h.

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

◆ m_head

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

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

Definition at line 170 of file stk_linked_list.h.

◆ m_next

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

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

Definition at line 171 of file stk_linked_list.h.

◆ m_pending

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

◆ m_period

uint32_t stk::time::TimerHost::Timer::m_period
private

◆ m_prev

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

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

Definition at line 172 of file stk_linked_list.h.

◆ m_timestamp

Ticks stk::time::TimerHost::Timer::m_timestamp
private

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

Definition at line 170 of file stk_time_timer.h.

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


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