Hardware Abstraction Layer (HAL)

General Description

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

Data Structures

struct  cyhal_t2timer_cfg_t
 Describes the current configuration of a T2Timer timer. More...
 

Macros

#define CYHAL_T2TIMER_RSLT_ERR_BAD_ARGUMENT    (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_T2TIMER, 0))
 Bad argument. More...
 
#define CYHAL_T2TIMER_RSLT_ERR_INIT    (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_T2TIMER, 1))
 Failed to initialize Timer.
 
#define CYHAL_T2TIMER_RSLT_ERR    (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_T2TIMER, 2))
 T2Timer backend failed. More...
 
#define CYHAL_CLOCK_T2TIMER   (const void*)(0xFFFFFFFF)
 Used to specificially request a T2Timer through timer initialization function.
 

Typedefs

typedef void(* timerCallback) (INT32 arg)
 Handler for timer events.
 

Functions

void _cyhal_t2timer_register_callback (cyhal_t2timer_t *obj, cy_israddress callback, void *callback_arg)
 Registers a callback function and callback arguments to a T2Timer. More...
 
void _cyhal_t2timer_free (cyhal_t2timer_t *obj)
 Frees a T2Timer instance. More...
 
cy_rslt_t _cyhal_t2timer_init (cyhal_t2timer_t *obj, cyhal_t2timer_t *config)
 Initializes a T2Timer timer instance. More...
 
cy_rslt_t _cyhal_t2timer_configure (cyhal_t2timer_t *obj, cyhal_t2timer_cfg_t *config)
 Configures the timer. More...
 
cy_rslt_t _cyhal_t2timer_set_frequency (cyhal_t2timer_t *obj, uint32_t hz)
 Configures the timer frequency. More...
 
cy_rslt_t _cyhal_t2timer_start (cyhal_t2timer_t *obj)
 Start the timer. More...
 
cy_rslt_t _cyhal_t2timer_stop (cyhal_t2timer_t *obj)
 Stop the timer. More...
 
cy_rslt_t _cyhal_t2timer_reset (cyhal_t2timer_t *obj)
 Reset the timer. More...
 
uint32_t _cyhal_t2timer_read (const cyhal_t2timer_t *obj)
 Read the timer value. More...
 

Data Structure Documentation

◆ 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.

Macro Definition Documentation

◆ CYHAL_T2TIMER_RSLT_ERR_BAD_ARGUMENT

#define CYHAL_T2TIMER_RSLT_ERR_BAD_ARGUMENT    (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_T2TIMER, 0))

Bad argument.

eg: null pointer

◆ CYHAL_T2TIMER_RSLT_ERR

T2Timer backend failed.

eg: failed to start or stop

Function Documentation

◆ _cyhal_t2timer_register_callback()

void _cyhal_t2timer_register_callback ( cyhal_t2timer_t obj,
cy_israddress  callback,
void *  callback_arg 
)

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]objThe timer object
[in]callbackThe callback function
[in]callback_argArguments passed to the callback function

◆ _cyhal_t2timer_free()

void _cyhal_t2timer_free ( cyhal_t2timer_t obj)

Frees a T2Timer instance.

Parameters
[in]objThe timer object to free

◆ _cyhal_t2timer_init()

cy_rslt_t _cyhal_t2timer_init ( cyhal_t2timer_t obj,
cyhal_t2timer_t config 
)

Initializes a T2Timer timer instance.

Parameters
[in]objThe timer object to initialize
[in]configSettings to initialize with. If NULL, uses default
Returns
The status of the initialization

◆ _cyhal_t2timer_configure()

cy_rslt_t _cyhal_t2timer_configure ( cyhal_t2timer_t obj,
cyhal_t2timer_cfg_t config 
)

Configures the timer.

Note
All T2Timer configurations only take effect after starting or restarting the timer.
Parameters
[in]objThe timer object to configure
[in]configSettings to define desired timer behavior
Returns
The status of the configure request

◆ _cyhal_t2timer_set_frequency()

cy_rslt_t _cyhal_t2timer_set_frequency ( cyhal_t2timer_t obj,
uint32_t  hz 
)

Configures the timer frequency.

Note
All T2Timer configurations only take effect after starting or restarting the timer.
Parameters
[in]objThe timer object to configure
[in]hzThe frequency rate in Hz
Returns
The status of the set_frequency request

◆ _cyhal_t2timer_start()

cy_rslt_t _cyhal_t2timer_start ( cyhal_t2timer_t obj)

Start the timer.

Parameters
[in]objThe timer object to start
Returns
The status of the start request

◆ _cyhal_t2timer_stop()

cy_rslt_t _cyhal_t2timer_stop ( cyhal_t2timer_t obj)

Stop the timer.

Parameters
[in]objThe timer object to stop
Returns
The status of the stop request

◆ _cyhal_t2timer_reset()

cy_rslt_t _cyhal_t2timer_reset ( cyhal_t2timer_t obj)

Reset the timer.

Parameters
[in]objThe timer object to restart
Returns
The status of the restart request

◆ _cyhal_t2timer_read()

uint32_t _cyhal_t2timer_read ( const cyhal_t2timer_t obj)

Read the timer value.

Parameters
[in]objThe timer object to read
Returns
The remaining time left on the timer in us