SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
STK C PeriodicTrigger API

Pure C interface for stk::time::PeriodicTrigger. More...

Collaboration diagram for STK C PeriodicTrigger API:

Classes

struct  stk_periodic_trigger_mem_t
 Opaque memory container for a stk_periodic_trigger_t instance. More...

Macros

#define STK_PERIODIC_TRIGGER_IMPL_SIZE   16
 A memory size (multiples of stk_word_t) required for PeriodicTrigger instance.

Typedefs

typedef struct stk_periodic_trigger_mem_t stk_periodic_trigger_mem_t
 Opaque memory container for a stk_periodic_trigger_t instance.
typedef struct stk_periodic_trigger_t stk_periodic_trigger_t
 Opaque handle to a stk::time::PeriodicTrigger instance.

Functions

stk_periodic_trigger_tstk_periodic_trigger_create (stk_periodic_trigger_mem_t *memory, uint32_t memory_size, uint32_t period, bool started)
 Construct PeriodicTrigger instance in the supplied memory buffer.
void stk_periodic_trigger_destroy (stk_periodic_trigger_t *trig)
 Destroy instance (calls the C++ destructor in-place).
bool stk_periodic_trigger_poll (stk_periodic_trigger_t *trig)
 Check whether the scheduled trigger time has been reached.
void stk_periodic_trigger_set_period (stk_periodic_trigger_t *trig, uint32_t period)
 Change the trigger period while preserving phase.
void stk_periodic_trigger_restart (stk_periodic_trigger_t *trig)
 Reset and start the trigger from the current tick count.
uint32_t stk_periodic_trigger_get_period (const stk_periodic_trigger_t *trig)
 Get currently configured trigger period.

Detailed Description

Pure C interface for stk::time::PeriodicTrigger.

Typical usage:

stk_periodic_trigger_t *trig = stk_periodic_trigger_create(&mem, sizeof(mem), 500, true);
// Inside a task loop:
{
// executed once per 500-tick period
}
stk_periodic_trigger_t * stk_periodic_trigger_create(stk_periodic_trigger_mem_t *memory, uint32_t memory_size, uint32_t period, bool started)
Construct PeriodicTrigger instance in the supplied memory buffer.
bool stk_periodic_trigger_poll(stk_periodic_trigger_t *trig)
Check whether the scheduled trigger time has been reached.
Opaque memory container for a stk_periodic_trigger_t instance.
Definition stk_c_time.h:292

Macro Definition Documentation

◆ STK_PERIODIC_TRIGGER_IMPL_SIZE

#define STK_PERIODIC_TRIGGER_IMPL_SIZE   16

A memory size (multiples of stk_word_t) required for PeriodicTrigger instance.

Definition at line 287 of file stk_c_time.h.

Typedef Documentation

◆ stk_periodic_trigger_mem_t

typedef struct stk_periodic_trigger_mem_t stk_periodic_trigger_mem_t

Opaque memory container for a stk_periodic_trigger_t instance.

Note
Declare as static or on the stack (not on the heap).

◆ stk_periodic_trigger_t

typedef struct stk_periodic_trigger_t stk_periodic_trigger_t

Opaque handle to a stk::time::PeriodicTrigger instance.

Definition at line 298 of file stk_c_time.h.

Function Documentation

◆ stk_periodic_trigger_create()

stk_periodic_trigger_t * stk_periodic_trigger_create ( stk_periodic_trigger_mem_t * memory,
uint32_t memory_size,
uint32_t period,
bool started )

Construct PeriodicTrigger instance in the supplied memory buffer.

Parameters
[in]memoryPointer to the caller-supplied memory container.
[in]memory_sizeSize of the container in bytes (must be >= sizeof(stk_periodic_trigger_mem_t)).
[in]periodTrigger period in ticks. Must be > 0.
[in]startedtrue to create instance in a started state, false otherwise.
Returns
Trigger handle on success, or NULL if memory is NULL or memory_size is too small.
Note
The trigger is created in a stopped state. Call stk_periodic_trigger_restart() before polling.

Definition at line 344 of file stk_c_time.cpp.

348{
349 STK_ASSERT(memory != nullptr);
350 STK_ASSERT(memory_size >= sizeof(stk_periodic_trigger_t));
351 if (memory == nullptr || memory_size < sizeof(stk_periodic_trigger_t))
352 return nullptr;
353
354 return new (memory->data) stk_periodic_trigger_t(static_cast<Ticks>(period), started);
355}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:330
struct stk_periodic_trigger_t stk_periodic_trigger_t
Opaque handle to a stk::time::PeriodicTrigger instance.
Definition stk_c_time.h:298
int64_t Ticks
Ticks value.
Definition stk_common.h:128
Memory-related primitives.

References STK_ASSERT.

◆ stk_periodic_trigger_destroy()

void stk_periodic_trigger_destroy ( stk_periodic_trigger_t * trig)

Destroy instance (calls the C++ destructor in-place).

Parameters
[in]trigTrigger handle. May be NULL (no-op).

Definition at line 357 of file stk_c_time.cpp.

358{
359 if (trig != nullptr)
360 trig->~stk_periodic_trigger_t();
361}

◆ stk_periodic_trigger_get_period()

uint32_t stk_periodic_trigger_get_period ( const stk_periodic_trigger_t * trig)

Get currently configured trigger period.

Parameters
[in]trigTrigger handle.
Returns
Period in ticks.

Definition at line 384 of file stk_c_time.cpp.

385{
386 STK_ASSERT(trig != nullptr);
387
388 return static_cast<uint32_t>(trig->handle.GetPeriod());
389}
uint32_t GetPeriod() const
Get currently configured trigger period.
time::PeriodicTrigger handle

References stk::time::PeriodicTrigger::GetPeriod(), stk_periodic_trigger_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_periodic_trigger_poll()

bool stk_periodic_trigger_poll ( stk_periodic_trigger_t * trig)

Check whether the scheduled trigger time has been reached.

Parameters
[in]trigTrigger handle (must be started).
Returns
true once when the current tick count reaches or exceeds the scheduled trigger time, false otherwise.
Note
Implements absolute-time scheduling. When firing occurs, the internal next-trigger time is advanced by exactly one period (not reset to the current time), preserving long-term frequency stability.
At most one true is returned per call. If multiple full periods have elapsed since the previous call, subsequent calls will continue advancing one period at a time until the schedule catches up.

Definition at line 363 of file stk_c_time.cpp.

364{
365 STK_ASSERT(trig != nullptr);
366
367 return trig->handle.Poll();
368}
bool Poll()
Check whether the scheduled trigger time has been reached.

References stk_periodic_trigger_t::handle, stk::time::PeriodicTrigger::Poll(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_periodic_trigger_restart()

void stk_periodic_trigger_restart ( stk_periodic_trigger_t * trig)

Reset and start the trigger from the current tick count.

Parameters
[in]trigTrigger handle.
Note
Sets the internal next-trigger time to (current ticks + period). The next firing occurs no earlier than period ticks after this call. Does not change the configured period.

Definition at line 377 of file stk_c_time.cpp.

378{
379 STK_ASSERT(trig != nullptr);
380
381 trig->handle.Restart();
382}
void Restart()
Reset the trigger and start.

References stk_periodic_trigger_t::handle, stk::time::PeriodicTrigger::Restart(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_periodic_trigger_set_period()

void stk_periodic_trigger_set_period ( stk_periodic_trigger_t * trig,
uint32_t period )

Change the trigger period while preserving phase.

Parameters
[in]trigTrigger handle.
[in]periodNew trigger period in ticks. Must be > 0.
Note
Adjusts the internally stored next-trigger time so that the relative progress toward the next firing is preserved. Takes effect immediately.

Definition at line 370 of file stk_c_time.cpp.

371{
372 STK_ASSERT(trig != nullptr);
373
374 trig->handle.SetPeriod(static_cast<Ticks>(period));
375}
void SetPeriod(uint32_t period)
Change the trigger period while preserving phase.

References stk_periodic_trigger_t::handle, stk::time::PeriodicTrigger::SetPeriod(), and STK_ASSERT.

Here is the call graph for this function: