High level interface for interacting with the Cypress Timer.
This block can be used either to measure timing between events, or perform some action after a specified period of time.
The timer operation is highly configurable; see cyhal_timer_cfg_t.
◆ cyhal_timer_cfg_t
| Data Fields |
|
bool |
is_continuous |
Whether the timer/counter operates continuous (true) or one shot (false) Whether the timer is set to continously run. If true, the timer will run forever. Otherwise, the timer will run once and stop (one shot).
|
|
cyhal_timer_direction_t |
direction |
Direction the timer/counter is running. |
|
bool |
is_compare |
Is it in compare (true) or capture (false) mode. |
|
uint32_t |
period |
Timer/counter period. |
|
uint32_t |
compare_value |
Timer/counter comparison value. |
|
uint32_t |
value |
Current value of the timer/counter. |
◆ CYHAL_TIMER_RSLT_ERR_BAD_ARGUMENT
Bad argument. eg: null pointer
◆ CYHAL_TIMER_RSLT_ERR_CLOCK_INIT
Failed to initialize Timer clock
◆ CYHAL_TIMER_RSLT_ERR_INIT
Failed to initialize Timer
◆ CYHAL_TIMER_RSLT_ERR_SHARED_CLOCK
Cannot change the timer frequency when a shared clock divider is in use
◆ CYHAL_TIMER_DEFAULT_FREQ
| #define CYHAL_TIMER_DEFAULT_FREQ (1000000u) |
Default timer frequency, used when an existing clock divider is not provided to init
◆ cyhal_timer_event_callback_t
◆ cyhal_timer_direction_t
Timer directions
| Enumerator |
|---|
| CYHAL_TIMER_DIR_UP | Counts up.
|
| CYHAL_TIMER_DIR_DOWN | Counts down.
|
| CYHAL_TIMER_DIR_UP_DOWN | Counts up and down, terminal count occurs on both overflow and underflow.
|
◆ cyhal_timer_event_t
Timer/counter interrupt triggers
◆ cyhal_timer_init()
Initialize the timer/counter peripheral and configure the pin.
- Parameters
-
| [out] | obj | The timer/counter object to initialize |
| [in] | pin | optional - The timer/counter compare/capture pin to initialize |
| [in] | clk | optional - The shared clock to use, if not provided a new clock will be allocated and the timer frequency will be set to CYHAL_TIMER_DEFAULT_FREQ |
- Returns
- The status of the init request
◆ cyhal_timer_free()
Deinitialize the timer/counter object
- Parameters
-
| [in,out] | obj | The timer/counter object |
◆ cyhal_timer_configure()
Updates the configuration of the timer/counter object
- Parameters
-
| [in] | obj | The timer/counter object |
| [in] | cfg | The configuration of the timer/counter |
- Returns
- The status of the configure request
◆ cyhal_timer_set_frequency()
Configures the timer frequency. This is not valid to call if a non-null clock divider was provided to cyhal_timer_init
- Parameters
-
| [in] | obj | The timer/counter object |
| [in] | hz | The frequency rate in Hz |
- Returns
- The status of the set_frequency request
◆ cyhal_timer_start()
Starts the timer/counter with the pre-set configuration.
- Parameters
-
| [in] | obj | The timer/counter object |
- Returns
- The status of the start request
◆ cyhal_timer_stop()
Stops the timer/counter.
- Parameters
-
| [in] | obj | The timer/counter object |
- Returns
- The status of the stop request
◆ cyhal_timer_register_callback()
The timer/counter callback handler registration
- Parameters
-
| [in] | obj | The timer/counter object |
| [in] | callback | The callback handler which will be invoked when the event occurs |
| [in] | callback_arg | Generic argument that will be provided to the callback when called |
◆ cyhal_timer_enable_event()
Configure timer/counter event enablement.
- Parameters
-
| [in] | obj | The timer/counter object |
| [in] | event | The timer/counter event type |
| [in] | intrPriority | The priority for NVIC interrupt events |
| [in] | enable | True to turn on interrupts, False to turn off |