SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
Timer

Typedefs

typedef enum cy_timer_trigger_type cy_timer_trigger_type_t
typedef void(* cy_timer_callback_t) (cy_timer_callback_arg_t arg)

Enumerations

enum  cy_timer_trigger_type {
  CY_TIMER_TYPE_PERIODIC ,
  CY_TIMER_TYPE_ONCE
}
cy_rslt_t cy_rtos_timer_init (cy_timer_t *timer, cy_timer_trigger_type_t type, cy_timer_callback_t fun, cy_timer_callback_arg_t arg)
cy_rslt_t cy_rtos_timer_start (const cy_timer_t *timer, cy_time_t num_ms)
cy_rslt_t cy_rtos_timer_stop (const cy_timer_t *timer)
cy_rslt_t cy_rtos_timer_is_running (const cy_timer_t *timer, bool *state)
cy_rslt_t cy_rtos_timer_deinit (cy_timer_t *timer)
#define cy_rtos_init_timer(timer, type, fun, arg)
#define cy_rtos_start_timer(timer, num_ms)
#define cy_rtos_stop_timer(timer)
#define cy_rtos_is_running_timer(timer, state)
#define cy_rtos_deinit_timer(timer)

Detailed Description

APIs for creating and working with Timers.

Macro Definition Documentation

◆ cy_rtos_deinit_timer

#define cy_rtos_deinit_timer ( timer)
Value:
cy_rslt_t cy_rtos_timer_deinit(cy_timer_t *timer)

Deinit the timer.

This function deinitializes the timer and frees all consumed resources.

Parameters
[in]timerPointer to the timer handle
Returns
The status of the deinit request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM, CY_RTOS_GENERAL_ERROR].
Specific for kernel:

Definition at line 1654 of file cyabs_rtos.h.

◆ cy_rtos_init_timer

#define cy_rtos_init_timer ( timer,
type,
fun,
arg )
Value:
cy_rtos_timer_init(timer, type, fun, arg)
cy_rslt_t cy_rtos_timer_init(cy_timer_t *timer, cy_timer_trigger_type_t type, cy_timer_callback_t fun, cy_timer_callback_arg_t arg)

Create a new timer.

This function initializes a timer object.

Note
The timer is not active until start is called.
The callback may be (likely will be) called from a different thread.
Parameters
[out]timerPointer to the timer handle to initialize
[in]typeType of timer (periodic or once)
[in]funThe function
[in]argArgument to pass along to the callback function
Returns
The status of the init request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM].
Specific for kernel:

Definition at line 1601 of file cyabs_rtos.h.

1601#define cy_rtos_init_timer(timer, type, fun, arg) \
1602 cy_rtos_timer_init(timer, type, fun, arg)

◆ cy_rtos_is_running_timer

#define cy_rtos_is_running_timer ( timer,
state )
Value:
cy_rslt_t cy_rtos_timer_is_running(const cy_timer_t *timer, bool *state)

Returns state of a timer.

Parameters
[in]timerPointer to the timer handle
[out]stateReturn value for state, true if running, false otherwise
Returns
The status of the is_running request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM].
Specific for kernel:

Definition at line 1640 of file cyabs_rtos.h.

1640#define cy_rtos_is_running_timer(timer, state) \
1641 cy_rtos_timer_is_running(timer, state)

◆ cy_rtos_start_timer

#define cy_rtos_start_timer ( timer,
num_ms )
Value:
cy_rtos_timer_start(timer, num_ms)
cy_rslt_t cy_rtos_timer_start(const cy_timer_t *timer, cy_time_t num_ms)

Sends a request to start the timer. Depending on the priorities of threads in the system, it may be necessary for high priority items to wait before the timer actually starts running.

Parameters
[in]timerPointer to the timer handle
[in]num_msThe number of milliseconds to wait before the timer fires
Returns
The status of the start request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM, CY_RTOS_GENERAL_ERROR].
Specific for kernel:

Definition at line 1615 of file cyabs_rtos.h.

1615#define cy_rtos_start_timer(timer, num_ms) \
1616 cy_rtos_timer_start(timer, num_ms)

◆ cy_rtos_stop_timer

#define cy_rtos_stop_timer ( timer)
Value:
cy_rslt_t cy_rtos_timer_stop(const cy_timer_t *timer)

Sends a request to stop the timer. Depending on the priorities of threads in the system, it may be necessary for high priority items to wait before the timer is actually stopped.

Parameters
[in]timerPointer to the timer handle
Returns
The status of the stop request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM, CY_RTOS_GENERAL_ERROR].
Specific for kernel:

Definition at line 1628 of file cyabs_rtos.h.

Typedef Documentation

◆ cy_timer_callback_t

typedef void(* cy_timer_callback_t) (cy_timer_callback_arg_t arg)

The callback function to be called by a timer

Definition at line 186 of file cyabs_rtos.h.

◆ cy_timer_trigger_type_t

The type of timer

Enumeration Type Documentation

◆ cy_timer_trigger_type

The type of timer

Enumerator
CY_TIMER_TYPE_PERIODIC 

called periodically until stopped

CY_TIMER_TYPE_ONCE 

called once only

Definition at line 161 of file cyabs_rtos.h.

162{
enum cy_timer_trigger_type cy_timer_trigger_type_t
@ CY_TIMER_TYPE_ONCE
Definition cyabs_rtos.h:164
@ CY_TIMER_TYPE_PERIODIC
Definition cyabs_rtos.h:163

Function Documentation

◆ cy_rtos_timer_deinit()

cy_rslt_t cy_rtos_timer_deinit ( cy_timer_t * timer)

Deinit the timer.

This function deinitializes the timer and frees all consumed resources.

Parameters
[in]timerPointer to the timer handle
Returns
The status of the deinit request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM, CY_RTOS_GENERAL_ERROR].
Specific for kernel:

< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())

< the timer host rejected the command

Definition at line 1471 of file cyabs_rtos_stk.cpp.

1472{
1473 if (!IsValid(timer))
1474 {
1475 return CY_RTOS_BAD_PARAM;
1476 }
1477
1478 CyTimer *const t = TimerOf(timer);
1479
1480 // A timer which was never started is unknown to the host. Otherwise StopSync() guarantees that no
1481 // command, queue node or running callback references the timer once it returned RES_OK/RES_INACTIVE.
1482 // RES_QUEUED (ISR, kernel not running) gives no such guarantee: the timer must then stay alive.
1483 if (t->m_started)
1484 {
1485 if (InIsr())
1486 {
1487 return Fail(CY_RTOS_STK_ERR_CONTEXT);
1488 }
1489
1490 const stk::time::TimerHost::EResult res = g_TimerHost.StopSync(*t);
1491
1493 {
1494 return Fail(CY_RTOS_STK_ERR_TIMER_HOST);
1495 }
1496 }
1497
1498 timer->id = 0U;
1499 t->~CyTimer();
1500
1501 return CY_RSLT_SUCCESS;
1502}
#define CY_RTOS_STK_ERR_TIMER_HOST
#define CY_RTOS_STK_ERR_CONTEXT
static PosixTimer * TimerOf(timer_t id)
#define CY_RTOS_BAD_PARAM
Definition cyabs_rtos.h:96
EResult
Outcome of a command: returned by the asynchronous API (Start(), Stop(), ...) and by the synchronous ...
@ RES_INACTIVE
The timer is not active, but the command requires it to be active (stop, reset).
@ RES_OK
Sync: the command was executed. Async: the command was accepted into the command queue.

References CY_RTOS_BAD_PARAM, CY_RTOS_STK_ERR_CONTEXT, CY_RTOS_STK_ERR_TIMER_HOST, cy_timer_t::id, stk::time::TimerHost::RES_INACTIVE, stk::time::TimerHost::RES_OK, stk::time::TimerHost::StopSync(), and TimerOf().

Here is the call graph for this function:

◆ cy_rtos_timer_init()

cy_rslt_t cy_rtos_timer_init ( cy_timer_t * timer,
cy_timer_trigger_type_t type,
cy_timer_callback_t fun,
cy_timer_callback_arg_t arg )

Create a new timer.

This function initializes a timer object.

Note
The timer is not active until start is called.
The callback may be (likely will be) called from a different thread.
Parameters
[out]timerPointer to the timer handle to initialize
[in]typeType of timer (periodic or once)
[in]funThe function
[in]argArgument to pass along to the callback function
Returns
The status of the init request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM].
Specific for kernel:

< kernel is not initialized (see cy_rtos_stk_kernel_init())

Definition at line 1401 of file cyabs_rtos_stk.cpp.

1403{
1404 if ((timer == nullptr) || (fun == nullptr))
1405 {
1406 return CY_RTOS_BAD_PARAM;
1407 }
1408 if (KState() == stk::IKernel::KSTATE_INACTIVE)
1409 {
1410 return Fail(CY_RTOS_STK_ERR_KERNEL_STATE); // the timer host starts with cy_rtos_stk_kernel_init()
1411 }
1412
1413 (void)new (static_cast<void *>(timer->storage)) CyTimer((type == CY_TIMER_TYPE_ONCE), fun, arg);
1414 timer->id = ID_TIMER;
1415
1416 return CY_RSLT_SUCCESS;
1417}
#define CY_RTOS_STK_ERR_KERNEL_STATE
@ KSTATE_INACTIVE
Not ready, IKernel::Initialize() must be called.
uint64_t storage[(16U)]

References CY_RTOS_BAD_PARAM, CY_RTOS_STK_ERR_KERNEL_STATE, CY_TIMER_TYPE_ONCE, cy_timer_t::id, stk::IKernel::KSTATE_INACTIVE, and cy_timer_t::storage.

◆ cy_rtos_timer_is_running()

cy_rslt_t cy_rtos_timer_is_running ( const cy_timer_t * timer,
bool * state )

Returns state of a timer.

Parameters
[in]timerPointer to the timer handle
[out]stateReturn value for state, true if running, false otherwise
Returns
The status of the is_running request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM].
Specific for kernel:

< the timer host rejected the command

Definition at line 1445 of file cyabs_rtos_stk.cpp.

1446{
1447 if (!IsValid(timer) || (state == nullptr))
1448 {
1449 return CY_RTOS_BAD_PARAM;
1450 }
1451
1453 const stk::time::TimerHost::EResult res = g_TimerHost.QuerySync(*TimerOf(timer), info);
1454
1456 {
1457 *state = info.active;
1458 }
1459 else if (res == stk::time::TimerHost::RES_QUEUED)
1460 {
1461 *state = TimerOf(timer)->IsActive(); // advisory (ISR, or the kernel is not running)
1462 }
1463 else
1464 {
1465 return Fail(CY_RTOS_STK_ERR_TIMER_HOST);
1466 }
1467
1468 return CY_RSLT_SUCCESS;
1469}
bool IsActive() const
Check whether the timer is currently active.
@ RES_QUEUED
The calling context can not wait: the command was queued asynchronously, its outcome is unknown.
Consistent snapshot of a timer, see QuerySync().
bool active
True if the timer is active.

References stk::time::TimerHost::TimerInfo::active, CY_RTOS_BAD_PARAM, CY_RTOS_STK_ERR_TIMER_HOST, stk::time::Timer::IsActive(), stk::time::TimerHost::QuerySync(), stk::time::TimerHost::RES_OK, stk::time::TimerHost::RES_QUEUED, and TimerOf().

Here is the call graph for this function:

◆ cy_rtos_timer_start()

cy_rslt_t cy_rtos_timer_start ( const cy_timer_t * timer,
cy_time_t num_ms )

Sends a request to start the timer. Depending on the priorities of threads in the system, it may be necessary for high priority items to wait before the timer actually starts running.

Parameters
[in]timerPointer to the timer handle
[in]num_msThe number of milliseconds to wait before the timer fires
Returns
The status of the start request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM, CY_RTOS_GENERAL_ERROR].
Specific for kernel:

Definition at line 1420 of file cyabs_rtos_stk.cpp.

1421{
1422 if (!IsValid(timer) || (num_ms == 0U) || (num_ms == CY_RTOS_NEVER_TIMEOUT))
1423 {
1424 return CY_RTOS_BAD_PARAM;
1425 }
1426
1427 CyTimer *const t = TimerOf(timer);
1428 const uint32_t ticks = MsToTicks(num_ms);
1429
1430 t->m_started = true;
1431
1432 return TimerResultToCy(g_TimerHost.RestartSync(*t, ticks, (t->m_oneshot ? 0U : ticks)));
1433}
#define CY_RTOS_NEVER_TIMEOUT
Definition cyabs_rtos.h:77
static stk::Timeout MsToTicks(uint32_t ms)

References CY_RTOS_BAD_PARAM, CY_RTOS_NEVER_TIMEOUT, MsToTicks(), stk::time::TimerHost::RestartSync(), and TimerOf().

Here is the call graph for this function:

◆ cy_rtos_timer_stop()

cy_rslt_t cy_rtos_timer_stop ( const cy_timer_t * timer)

Sends a request to stop the timer. Depending on the priorities of threads in the system, it may be necessary for high priority items to wait before the timer is actually stopped.

Parameters
[in]timerPointer to the timer handle
Returns
The status of the stop request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM, CY_RTOS_GENERAL_ERROR].
Specific for kernel:

Definition at line 1435 of file cyabs_rtos_stk.cpp.

1436{
1437 if (!IsValid(timer))
1438 {
1439 return CY_RTOS_BAD_PARAM;
1440 }
1441
1442 return TimerResultToCy(g_TimerHost.StopSync(*TimerOf(timer)));
1443}

References CY_RTOS_BAD_PARAM, stk::time::TimerHost::StopSync(), and TimerOf().

Here is the call graph for this function: