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 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 size_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 size_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 340 of file stk_c_time.cpp.

344{
345 STK_ASSERT(memory != nullptr);
346 STK_ASSERT(memory_size >= sizeof(stk_periodic_trigger_t));
347 if (memory == nullptr || memory_size < sizeof(stk_periodic_trigger_t))
348 return nullptr;
349
350 return new (memory->data) stk_periodic_trigger_t{ time::PeriodicTrigger(static_cast<Ticks>(period), started) };
351}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:330
int64_t Ticks
Ticks value.
Definition stk_common.h:150
Lightweight periodic trigger: returns true once per configured period when polled.

References stk_periodic_trigger_mem_t::data, and 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 353 of file stk_c_time.cpp.

354{
355 if (trig != nullptr)
356 trig->~stk_periodic_trigger_t();
357}

◆ 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 380 of file stk_c_time.cpp.

381{
382 STK_ASSERT(trig != nullptr);
383
384 return static_cast<uint32_t>(trig->handle.GetPeriod());
385}
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 359 of file stk_c_time.cpp.

360{
361 STK_ASSERT(trig != nullptr);
362
363 return trig->handle.Poll();
364}
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 373 of file stk_c_time.cpp.

374{
375 STK_ASSERT(trig != nullptr);
376
377 trig->handle.Restart();
378}
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 366 of file stk_c_time.cpp.

367{
368 STK_ASSERT(trig != nullptr);
369
370 trig->handle.SetPeriod(static_cast<Ticks>(period));
371}
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: