|
px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
|
Non-blocking software timers that have to be polled to determine if they have expired.
File(s):
These timers are suitable for applications that are not timing critical. A global counter is incremented with each clock tick and this value is polled to determine if a timer has expired. Provision is made for counter roll-over.
This module depends on a system clock module, e.g. px_sysclk.h : System Clock using a TMRx peripheral to return a counter that is incremented with every system clock tick. The number of ticks per second (Hz) is defined with PX_SYSTMR_TICKS_PER_SEC.
Example:
Data Structures | |
| struct | px_systmr_t |
| Structure to track state of a timer. More... | |
Macros | |
| #define | PX_SYSTMR_TICKS_PER_SEC PX_SYSCLK_CFG_TICKS_PER_SEC |
| The number of timer ticks per second. More... | |
| #define | PX_SYSTMR_MS_TO_TICKS(delay_in_ms) PX_UDIV_ROUND((delay_in_ms) * PX_SYSTMR_TICKS_PER_SEC, 1000ul) |
| Macro used to convert a timeout in milliseconds to timer ticks. More... | |
Typedefs | |
| typedef px_sysclk_ticks_t | px_systmr_ticks_t |
| Size definition of the tick counter. More... | |
Enumerations | |
| enum | px_systmr_state_t |
| Timer state. More... | |
Functions | |
| void | px_systmr_start (px_systmr_t *systmr, const px_systmr_ticks_t delay_in_ticks) |
| Start a timer. More... | |
| bool | px_systmr_has_started (const px_systmr_t *systmr) |
| See if a timer has been started. More... | |
| bool | px_systmr_has_expired (px_systmr_t *systmr) |
| See if a timer has expired. More... | |
| void | px_systmr_stop (px_systmr_t *systmr) |
| Stop a running timer. More... | |
| void | px_systmr_restart (px_systmr_t *systmr) |
| Restart a timer with the delay set with px_systmr_start(). More... | |
| void | px_systmr_reset (px_systmr_t *systmr) |
| Reset a timer with the delay set with px_systmr_start(). More... | |
| void | px_systmr_wait (const px_systmr_ticks_t delay_in_ticks) |
| Blocking wait for specified number of ticks. More... | |
| px_systmr_ticks_t | px_systmr_ticks_elapsed (px_systmr_t *systmr) |
| Return the number of ticks that have elapsed sinced the timer has been started. More... | |
| struct px_systmr_t |
Structure to track state of a timer.
Definition at line 74 of file px_systmr.h.
| Data Fields | ||
|---|---|---|
| px_systmr_state_t | state | State of timer: STOPPED, STARTED or EXPIRED. |
| px_systmr_ticks_t | start_tick | Tick when timer started. |
| px_systmr_ticks_t | delay_in_ticks | Timer delay, used for subsequent timer restarts/resets. |
| #define PX_SYSTMR_TICKS_PER_SEC PX_SYSCLK_CFG_TICKS_PER_SEC |
The number of timer ticks per second.
Definition at line 59 of file px_systmr.h.
| #define PX_SYSTMR_MS_TO_TICKS | ( | delay_in_ms | ) | PX_UDIV_ROUND((delay_in_ms) * PX_SYSTMR_TICKS_PER_SEC, 1000ul) |
Macro used to convert a timeout in milliseconds to timer ticks.
| [in] | delay_in_ms | Delay in milliseconds |
Definition at line 177 of file px_systmr.h.
| typedef px_sysclk_ticks_t px_systmr_ticks_t |
Size definition of the tick counter.
Definition at line 63 of file px_systmr.h.
| enum px_systmr_state_t |
Timer state.
Definition at line 66 of file px_systmr.h.
| void px_systmr_start | ( | px_systmr_t * | systmr, |
| const px_systmr_ticks_t | delay_in_ticks | ||
| ) |
Start a timer.
| [in,out] | systmr | Pointer to a timer object |
| [in] | delay_in_ticks | Delay in timer ticks |
Definition at line 35 of file px_systmr.c.
| bool px_systmr_has_started | ( | const px_systmr_t * | systmr | ) |
See if a timer has been started.
| [in] | systmr | Pointer to a timer object |
| true | timer started |
| false | timer stopped or expired |
Definition at line 45 of file px_systmr.c.
| bool px_systmr_has_expired | ( | px_systmr_t * | systmr | ) |
See if a timer has expired.
| [in,out] | systmr | Pointer to a timer object |
| true | timer expired |
| false | timer not expired or timer stopped |
Definition at line 57 of file px_systmr.c.
| void px_systmr_stop | ( | px_systmr_t * | systmr | ) |
Stop a running timer.
| [in,out] | systmr | Pointer to a timer object |
Definition at line 103 of file px_systmr.c.
| void px_systmr_restart | ( | px_systmr_t * | systmr | ) |
Restart a timer with the delay set with px_systmr_start().
The timer will expire from the current timer tick + systmr->delay_in_ticks.
| [in,out] | systmr | Pointer to a timer object |
Definition at line 109 of file px_systmr.c.
| void px_systmr_reset | ( | px_systmr_t * | systmr | ) |
Reset a timer with the delay set with px_systmr_start().
The timer will expire on systmr->start_tick + systmr->delay_in_ticks.
Use this function instead of px_systmr_restart() for periodic timers, because the frequency will not drift over time. An error may accumulate if there is a delay between px_systmr_has_expired() and px_systmr_restart(). Thus the prefered usage for a periodic timer is:
| [in,out] | systmr | Pointer to a timer object |
Definition at line 117 of file px_systmr.c.
| void px_systmr_wait | ( | const px_systmr_ticks_t | delay_in_ticks | ) |
Blocking wait for specified number of ticks.
| [in] | delay_in_ticks | Delay in timer ticks |
Definition at line 125 of file px_systmr.c.
| px_systmr_ticks_t px_systmr_ticks_elapsed | ( | px_systmr_t * | systmr | ) |
Return the number of ticks that have elapsed sinced the timer has been started.
| [in,out] | systmr | Pointer to a timer object |
Definition at line 135 of file px_systmr.c.