T2Timer Usage
This device has T2Timer timers in addition to TCPWM timers (see cyhal_timer.h). T2Timer is limited in functionality. It is a basic timer that can be started, stopped, reset, read, and configured. The only notable difference operation compared to TCPWM timers is that T2Timer counts down. For consistency, the value obtained when reading the timer is adjusted to simulate counting up, but it will never exceed the duration set when started.
There are two T2Timer timer instances avalible for use.
The intention is for users to interact w/ the Timer HAL, not directly interact with T2Timer HAL, but either work
|
typedef void(* | timerCallback) (INT32 arg) |
| Handler for timer events.
|
|
◆ cyhal_t2timer_cfg_t
struct cyhal_t2timer_cfg_t |
Data Fields |
bool |
mode |
Whether the timer operates freerunning (true) or periodic (false) |
bool |
counter_mode |
Whether the timer/counter operates wrapping (true) or one shot (false) |
uint32_t |
duration |
Timer comparison value. |
◆ CYHAL_T2TIMER_RSLT_ERR_BAD_ARGUMENT
Bad argument.
eg: null pointer
◆ CYHAL_T2TIMER_RSLT_ERR
T2Timer backend failed.
eg: failed to start or stop
◆ _cyhal_t2timer_register_callback()
Registers a callback function and callback arguments to a T2Timer.
- Note
- All T2Timer configurations only take effect after starting or restarting the timer.
- Parameters
-
[in] | obj | The timer object |
[in] | callback | The callback function |
[in] | callback_arg | Arguments passed to the callback function |
◆ _cyhal_t2timer_free()
Frees a T2Timer instance.
- Parameters
-
[in] | obj | The timer object to free |
◆ _cyhal_t2timer_init()
Initializes a T2Timer timer instance.
- Parameters
-
[in] | obj | The timer object to initialize |
[in] | config | Settings to initialize with. If NULL, uses default |
- Returns
- The status of the initialization
◆ _cyhal_t2timer_configure()
Configures the timer.
- Note
- All T2Timer configurations only take effect after starting or restarting the timer.
- Parameters
-
[in] | obj | The timer object to configure |
[in] | config | Settings to define desired timer behavior |
- Returns
- The status of the configure request
◆ _cyhal_t2timer_set_frequency()
Configures the timer frequency.
- Note
- All T2Timer configurations only take effect after starting or restarting the timer.
- Parameters
-
[in] | obj | The timer object to configure |
[in] | hz | The frequency rate in Hz |
- Returns
- The status of the set_frequency request
◆ _cyhal_t2timer_start()
Start the timer.
- Parameters
-
[in] | obj | The timer object to start |
- Returns
- The status of the start request
◆ _cyhal_t2timer_stop()
Stop the timer.
- Parameters
-
[in] | obj | The timer object to stop |
- Returns
- The status of the stop request
◆ _cyhal_t2timer_reset()
Reset the timer.
- Parameters
-
[in] | obj | The timer object to restart |
- Returns
- The status of the restart request
◆ _cyhal_t2timer_read()
Read the timer value.
- Parameters
-
[in] | obj | The timer object to read |
- Returns
- The remaining time left on the timer in us