High level interface for interacting with the low-power timer (LPTimer).
LPTimer can operate in all possible low power modes. It can be used either to measure timing between events, or to perform some action after a specified interval of time.
See Snippet 2: LPTimer interrupts.
The following snippet initializes a LPTimer in free running mode.
The following snippet initializes a LPTimer and uses mtb_hal_lptimer_set_delay() to trigger an interrupt on match. Subsequent interrupts can be triggered at required times using mtb_hal_lptimer_set_delay() called from the ISR.
API Reference | |
LPTimer HAL Results | |
LPTimer specific return codes. | |
Typedefs | |
typedef void(* | mtb_hal_lptimer_event_callback_t) (void *callback_arg, mtb_hal_lptimer_event_t event) |
Handler for LPTimer interrupts. | |
Enumerations | |
enum | mtb_hal_lptimer_event_t { MTB_HAL_LPTIMER_COMPARE_MATCH } |
LPTimer interrupt triggers. | |
Functions | |
cy_rslt_t | mtb_hal_lptimer_setup (mtb_hal_lptimer_t *obj, const mtb_hal_lptimer_configurator_t *config) |
Sets up a HAL instance to use the specified hardware resource. More... | |
cy_rslt_t | mtb_hal_lptimer_set_delay (mtb_hal_lptimer_t *obj, uint32_t delay) |
Update the match/compare value. More... | |
uint32_t | mtb_hal_lptimer_read (const mtb_hal_lptimer_t *obj) |
Read the current tick. More... | |
void | mtb_hal_lptimer_register_callback (mtb_hal_lptimer_t *obj, mtb_hal_lptimer_event_callback_t callback, void *callback_arg) |
Register a LPTimer match event handler. More... | |
void | mtb_hal_lptimer_enable_event (mtb_hal_lptimer_t *obj, mtb_hal_lptimer_event_t event, bool enable) |
Configure and Enable/Disable the LPTimer events. More... | |
cy_rslt_t | mtb_hal_lptimer_process_interrupt (mtb_hal_lptimer_t *obj) |
Process interrupts related related to an LPTimer instance. More... | |
cy_rslt_t mtb_hal_lptimer_setup | ( | mtb_hal_lptimer_t * | obj, |
const mtb_hal_lptimer_configurator_t * | config | ||
) |
Sets up a HAL instance to use the specified hardware resource.
This hardware resource must have already been configured via the PDL.
[out] | obj | The HAL driver instance object. The caller must allocate the memory for this object, but the HAL will initialize its contents |
[in] | config | The configurator-generated HAL config structure for this peripheral instance |
cy_rslt_t mtb_hal_lptimer_set_delay | ( | mtb_hal_lptimer_t * | obj, |
uint32_t | delay | ||
) |
Update the match/compare value.
Update the match value of an already configured LPTimer set up to generate an interrupt on match delay from the current counter value. Note that this function does not reinitialize the counter or the associated peripheral initialization sequence.
[in] | obj | The LPTimer object |
[in] | delay | The ticks to wait. The minimum permitted delay value can be found in the implementation specific documentation. |
EXAMPLE: Supposed T=C0=C1=0, and we need to trigger an interrupt at T=0x18000. We set C0_match to 0x8000 and C1 match to 1. At T = 0x8000, C0_value matches C0_match so C1 get incremented. C1/C0=0x18000. At T = 0x18000, C0_value matches C0_match again so C1 get incremented from 1 to 2. When C1 get incremented from 1 to 2 the interrupt is generated. At T = 0x18000, C1/C0 = 0x28000.
uint32_t mtb_hal_lptimer_read | ( | const mtb_hal_lptimer_t * | obj | ) |
Read the current tick.
If no rollover has occurred, the seconds passed since mtb_hal_lptimer_init() or mtb_hal_lptimer_set_time() was called can be found by dividing the ticks returned by this function by the frequency of the source clock (Refer to BSP Settings section in the kit's BSP API Reference Manual for details on the clock source for LPTimer).
[in] | obj | The LPTimer object |
void mtb_hal_lptimer_register_callback | ( | mtb_hal_lptimer_t * | obj, |
mtb_hal_lptimer_event_callback_t | callback, | ||
void * | callback_arg | ||
) |
Register a LPTimer match event handler.
This function will be called when one of the events enabled by mtb_hal_lptimer_enable_event occurs.
[in] | obj | The LPTimer object |
[in] | callback | The callback handler which will be invoked when the interrupt triggers |
[in] | callback_arg | Generic argument that will be provided to the handler when called |
void mtb_hal_lptimer_enable_event | ( | mtb_hal_lptimer_t * | obj, |
mtb_hal_lptimer_event_t | event, | ||
bool | enable | ||
) |
Configure and Enable/Disable the LPTimer events.
When an enabled event occurs, the function specified by mtb_hal_lptimer_register_callback will be called.
[in] | obj | The LPTimer object |
[in] | event | The LPTimer event type |
[in] | enable | True to turn on event, False to turn off |
cy_rslt_t mtb_hal_lptimer_process_interrupt | ( | mtb_hal_lptimer_t * | obj | ) |
Process interrupts related related to an LPTimer instance.
[in] | obj | HAL object for which the interrupt should be processed |