SmartSnippets DA1459x SDK
Files | Data Structures | Macros | Typedefs | Enumerations | Functions

Timer. More...

Files

file  hw_timer.h
 Definition of API for the Timer, Timer2, Timer3 and Timer4 Low Level Driver.
 

Data Structures

struct  timer_config_timer_capture
 Timer configuration for timer/capture mode. More...
 
struct  timer_config_oneshot
 Timer configuration for oneshot mode. More...
 
struct  timer_config_pwm
 Timer PWM configuration. More...
 
struct  timer_config
 Timer configuration. More...
 

Macros

#define HW_TIMER_REG_GETF(id, reg, field)   ((TBA(id)->reg & (TIMER_##reg##_##field##_Msk)) >> (TIMER_##reg##_##field##_Pos))
 Definition for the PWM synchronization bitfield. More...
 
#define HW_TIMER_REG_SETF(id, reg, field, val)
 Set the value of a field of a TIMER register. More...
 
#define TIMER_MAX_PRESCALER_VAL
 Maximum value for timer pre-scaler (5bits). More...
 
#define TIMER_MAX_RELOAD_VAL   TIMER_TIMER_SETTINGS_REG_TIM_RELOAD_Msk
 Maximum value for timer reload value (24bits). More...
 
#define TIMER_MAX_SHOTWIDTH_VAL   TIMER_TIMER_SHOTWIDTH_REG_TIM_SHOTWIDTH_Msk
 Maximum value for timer shot phase duration value in oneshot mode (24bits). More...
 
#define TIMER_MAX_PWM_FREQ_VAL   TIMER_TIMER_PWM_CTRL_REG_TIM_PWM_FREQ_Msk
 Maximum value for timer PWM Frequency (16bits). More...
 
#define TIMER_MAX_PWM_DC_VAL   TIMER_TIMER_PWM_CTRL_REG_TIM_PWM_DC_Msk
 Maximum value for timer PWM duty cycle (16bits). More...
 
#define HW_TIMER   ((void *)TIMER_BASE)
 Timer id. More...
 

Typedefs

typedef void(* hw_timer_handler_cb) (void)
 Timer interrupt callback. More...
 
typedef void(* hw_timer_capture_handler_cb) (uint8_t gpio_event)
 Timer capture interrupt callback. More...
 

Enumerations

enum  HW_TIMER_MODE { HW_TIMER_MODE_TIMER = 0, HW_TIMER_MODE_ONESHOT = 1 }
 Mode of operation. More...
 
enum  HW_TIMER_CLK_SRC { HW_TIMER_CLK_SRC_INT = 0, HW_TIMER_CLK_SRC_EXT = 1 }
 Clock source for timer. More...
 
enum  HW_TIMER_DIR { HW_TIMER_DIR_UP = 0, HW_TIMER_DIR_DOWN = 1 }
 Counting direction. More...
 
enum  HW_TIMER_TRIGGER { HW_TIMER_TRIGGER_RISING = 0, HW_TIMER_TRIGGER_FALLING = 1 }
 Type of triggering events. More...
 
enum  HW_TIMER_ONESHOT { HW_TIMER_ONESHOT_WAIT = 0, HW_TIMER_ONESHOT_DELAY = 1, HW_TIMER_ONESHOT_STARTED = 2, HW_TIMER_ONESHOT_ACTIVE = 3 }
 One shot mode phases. More...
 
enum  HW_TIMER_GPIO {
  HW_TIMER_GPIO_GPIO_NONE = 0, HW_TIMER_GPIO_PIN_P0_0 = 1, HW_TIMER_GPIO_PIN_P0_1 = 2, HW_TIMER_GPIO_PIN_P0_2 = 3,
  HW_TIMER_GPIO_PIN_P0_3 = 4, HW_TIMER_GPIO_PIN_P0_4 = 5, HW_TIMER_GPIO_PIN_P0_5 = 6, HW_TIMER_GPIO_PIN_P0_6 = 7,
  HW_TIMER_GPIO_PIN_P0_7 = 8, HW_TIMER_GPIO_PIN_P0_8 = 9, HW_TIMER_GPIO_PIN_P0_9 = 10, HW_TIMER_GPIO_PIN_P0_10 = 11,
  HW_TIMER_GPIO_PIN_P0_11 = 12, HW_TIMER_GPIO_PIN_P0_12 = 13, HW_TIMER_GPIO_PIN_P0_13 = 14, HW_TIMER_GPIO_PIN_P0_14 = 15,
  HW_TIMER_GPIO_PIN_P0_15 = 16, HW_TIMER_GPIO_PIN_P1_0 = 17, HW_TIMER_GPIO_PIN_P1_1 = 18, HW_TIMER_GPIO_PIN_P1_2 = 19,
  HW_TIMER_GPIO_PIN_P1_3 = 20, HW_TIMER_GPIO_PIN_P1_4 = 21, HW_TIMER_GPIO_PIN_P1_5 = 22, HW_TIMER_GPIO_PIN_P1_6 = 23,
  HW_TIMER_GPIO_PIN_P1_7 = 24, HW_TIMER_GPIO_PIN_P1_8 = 25, HW_TIMER_GPIO_PIN_P1_9 = 26, HW_TIMER_GPIO_PIN_P1_10 = 27,
  HW_TIMER_GPIO_PIN_P1_11 = 28, HW_TIMER_GPIO_PIN_P1_12 = 29, HW_TIMER_GPIO_PIN_P1_13 = 30, HW_TIMER_GPIO_PIN_P1_14 = 31,
  HW_TIMER_GPIO_PIN_P1_15 = 32
}
 GPIOs for timer trigger. More...
 

Functions

void hw_timer_init (HW_TIMER_ID id, const timer_config *cfg)
 Timer initialization. More...
 
void hw_timer_configure (HW_TIMER_ID id, const timer_config *cfg)
 Timer configuration. More...
 
void hw_timer_configure_timer (HW_TIMER_ID id, const timer_config_timer_capture *cfg)
 Timer configuration for timer/capture mode. More...
 
void hw_timer_configure_oneshot (HW_TIMER_ID id, const timer_config_oneshot *cfg)
 Timer configuration for oneshot mode. More...
 
__STATIC_INLINE void hw_timer_freeze (const HW_TIMER_ID id)
 Freeze timer. More...
 
__STATIC_INLINE void hw_timer_unfreeze (const HW_TIMER_ID id)
 Unfreeze timer. More...
 
__STATIC_INLINE bool hw_timer_frozen (const HW_TIMER_ID id)
 Check if timer is frozen. More...
 
__STATIC_INLINE void hw_timer_set_clk (HW_TIMER_ID id, HW_TIMER_CLK_SRC clk)
 Set clock source of the timer. More...
 
__STATIC_INLINE void hw_timer_set_prescaler (HW_TIMER_ID id, uint8_t value)
 Set timer clock prescaler. More...
 
__STATIC_FORCEINLINE void hw_timer_set_reload (HW_TIMER_ID id, uint32_t value)
 Set timer reload value. More...
 
__STATIC_INLINE void hw_timer_set_oneshot_delay (HW_TIMER_ID id, uint32_t delay)
 Set pulse delay in oneshot mode. More...
 
__STATIC_INLINE void hw_timer_set_shot_width (HW_TIMER_ID id, uint32_t duration)
 Set shot width. More...
 
__STATIC_INLINE void hw_timer_set_freerun (HW_TIMER_ID id, bool enable)
 Turn on free run mode of the timer. More...
 
__STATIC_INLINE void hw_timer_set_event1_trigger (HW_TIMER_ID id, HW_TIMER_TRIGGER edge)
 Set a type of the edge which triggers event1. More...
 
__STATIC_INLINE void hw_timer_set_event2_trigger (HW_TIMER_ID id, HW_TIMER_TRIGGER edge)
 Set a type of the edge which triggers event2. More...
 
__STATIC_INLINE void hw_timer_set_event3_trigger (HW_TIMER_TRIGGER edge)
 Set a type of the edge which triggers event3. More...
 
__STATIC_INLINE void hw_timer_set_event4_trigger (HW_TIMER_TRIGGER edge)
 Set a type of the edge which triggers event4. More...
 
__STATIC_INLINE void hw_timer_set_gpio_event_int (uint8_t mask)
 Select which time capture event GPIOs will create a capture IRQ. More...
 
__STATIC_INLINE void hw_timer_set_event1_gpio (HW_TIMER_ID id, HW_TIMER_GPIO gpio)
 Set a GPIO input which triggers event1. More...
 
__STATIC_INLINE void hw_timer_set_event2_gpio (HW_TIMER_ID id, HW_TIMER_GPIO gpio)
 Set a GPIO input which triggers event2. More...
 
__STATIC_INLINE void hw_timer_set_event3_gpio (HW_TIMER_GPIO gpio)
 Set a GPIO input which triggers event3. More...
 
__STATIC_INLINE void hw_timer_set_event4_gpio (HW_TIMER_GPIO gpio)
 Set a GPIO input which triggers event4. More...
 
__STATIC_INLINE HW_TIMER_CLK_SRC hw_timer_get_clk (HW_TIMER_ID id)
 Get clock source of the timer. More...
 
__STATIC_INLINE uint32_t hw_timer_get_prescaler (HW_TIMER_ID id)
 Get timer clock prescaler. More...
 
__STATIC_INLINE uint32_t hw_timer_get_reload (HW_TIMER_ID id)
 Get timer reload value. More...
 
__STATIC_INLINE uint32_t hw_timer_get_oneshot_delay (HW_TIMER_ID id)
 Get pulse delay in oneshot mode. More...
 
__STATIC_INLINE uint32_t hw_timer_get_shot_width (HW_TIMER_ID id)
 Get shot width. More...
 
__STATIC_INLINE bool hw_timer_get_freerun (HW_TIMER_ID id)
 Get free-running mode state. More...
 
__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event1_trigger (HW_TIMER_ID id)
 Get a type of the edge which triggers event1. More...
 
__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event2_trigger (HW_TIMER_ID id)
 Get a type of the edge which triggers event2. More...
 
__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event3_trigger (void)
 Get a type of the edge which triggers event3. Valid only for Timer. More...
 
__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event4_trigger (void)
 Get a type of the edge which triggers event4. Valid only for Timer. More...
 
__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event1_gpio (HW_TIMER_ID id)
 Get a GPIO input which triggers event1. More...
 
__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event2_gpio (HW_TIMER_ID id)
 Get a GPIO input which triggers event2. More...
 
__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event3_gpio (void)
 Get a GPIO input which triggers event3. Valid only for Timer. More...
 
__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event4_gpio (void)
 Get a GPIO input which triggers event4. Valid only for Timer. More...
 
__STATIC_INLINE uint32_t hw_timer_get_capture1 (HW_TIMER_ID id)
 Get the capture time for event on GPIO1. More...
 
__STATIC_INLINE uint32_t hw_timer_get_capture2 (HW_TIMER_ID id)
 Get the capture time for event on GPIO2. More...
 
__STATIC_INLINE uint32_t hw_timer_get_capture3 (void)
 Get the capture time for event on GPIO3. Valid only for Timer. More...
 
__STATIC_INLINE uint32_t hw_timer_get_capture4 (void)
 Get the capture time for event on GPIO4. Valid only for Timer. More...
 
__STATIC_INLINE void hw_timer_set_direction (HW_TIMER_ID id, HW_TIMER_DIR dir)
 Set the direction of timer counting. More...
 
__STATIC_INLINE void hw_timer_set_mode (HW_TIMER_ID id, HW_TIMER_MODE mode)
 Set timer mode. More...
 
__STATIC_INLINE HW_TIMER_MODE hw_timer_get_mode (HW_TIMER_ID id)
 Return timer mode. More...
 
__STATIC_FORCEINLINE uint32_t hw_timer_get_count (HW_TIMER_ID id)
 Get the tick count of the timer. More...
 
__STATIC_INLINE HW_TIMER_ONESHOT hw_timer_get_oneshot_phase (HW_TIMER_ID id)
 Get the current phase of the one shot mode. More...
 
__STATIC_INLINE bool hw_timer_get_gpio1_state (HW_TIMER_ID id)
 Get the current state of Event input 1 (IN1) More...
 
__STATIC_INLINE uint8_t hw_timer_get_gpio_event_pending (void)
 Get the time capture event GPIOs pending events. More...
 
__STATIC_INLINE bool hw_timer_get_gpio2_state (HW_TIMER_ID id)
 Get the current state of Event input 2 (IN2) More...
 
__STATIC_INLINE uint16_t hw_timer_get_prescaler_val (HW_TIMER_ID id)
 Get the current prescaler counter value. More...
 
__RETAINED_CODE void hw_timer_register_int (const HW_TIMER_ID id, hw_timer_handler_cb handler)
 Register an interrupt handler. More...
 
__RETAINED_HOT_CODE void hw_timer_unregister_int (const HW_TIMER_ID id)
 Unregister an interrupt handler. More...
 
void hw_timer_register_capture_int (hw_timer_capture_handler_cb handler, uint8_t gpio_mask)
 Register an interrupt handler for GPIO triggered Timer Capture interrupt. More...
 
void hw_timer_unregister_capture_int (void)
 Unregister an interrupt handler for GPIO triggered Timer Capture interrupt. More...
 
__STATIC_INLINE void hw_timer_enable (HW_TIMER_ID id)
 Enable the timer. More...
 
__STATIC_INLINE void hw_timer_disable (HW_TIMER_ID id)
 Disable the timer. More...
 
__STATIC_INLINE void hw_timer_enable_clk (HW_TIMER_ID id)
 Enable the timer clock. More...
 
__STATIC_INLINE void hw_timer_disable_clk (HW_TIMER_ID id)
 Disable the timer clock. More...
 
void hw_timer_configure_pwm (HW_TIMER_ID id, const timer_config_pwm *cfg)
 Timer PWM configuration. More...
 
__STATIC_INLINE void hw_timer_set_pwm_freq (HW_TIMER_ID id, uint32_t value)
 Set PWM frequency prescaler. More...
 
__STATIC_INLINE void hw_timer_set_pwm_duty_cycle (HW_TIMER_ID id, uint32_t value)
 Set PWM duty cycle. More...
 
__STATIC_INLINE uint32_t hw_timer_get_pwm_freq (HW_TIMER_ID id)
 Get PWM frequency. More...
 
__STATIC_INLINE uint32_t hw_timer_get_pwm_duty_cycle (HW_TIMER_ID id)
 Get PWM duty cycle. More...
 
__STATIC_INLINE void hw_timer_clear_gpio_event (uint8_t mask)
 Clear capture time GPIO event. More...
 
__STATIC_INLINE void hw_timer_clear_interrupt (const HW_TIMER_ID id)
 Clear timer interrupt. More...
 

Detailed Description

Timer.

Macro Definition Documentation

◆ HW_TIMER

#define HW_TIMER   ((void *)TIMER_BASE)

Timer id.

◆ HW_TIMER_REG_GETF

#define HW_TIMER_REG_GETF (   id,
  reg,
  field 
)    ((TBA(id)->reg & (TIMER_##reg##_##field##_Msk)) >> (TIMER_##reg##_##field##_Pos))

Definition for the PWM synchronization bitfield.

Get the value of a field of a TIMER register.

Parameters
[in]ididentifies TIMER, TIMER2, TIMER3 or TIMER4
[in]regis the register to access
[in]fieldis the register field to read
Returns
the value of the register field

◆ HW_TIMER_REG_SETF

#define HW_TIMER_REG_SETF (   id,
  reg,
  field,
  val 
)
Value:
TBA(id)->reg = ((TBA(id)->reg & ~(TIMER_##reg##_##field##_Msk)) | \
((TIMER_##reg##_##field##_Msk) & ((val) << (TIMER_##reg##_##field##_Pos))))

Set the value of a field of a TIMER register.

Parameters
[in]ididentifies TIMER, TIMER2, TIMER3 or TIMER4
[in]regis the register to access
[in]fieldis the register field to write
[in]valis the value to write

◆ TIMER_MAX_PRESCALER_VAL

#define TIMER_MAX_PRESCALER_VAL
Value:
TIMER_TIMER_SETTINGS_REG_TIM_PRESCALER_Pos)

Maximum value for timer pre-scaler (5bits).

◆ TIMER_MAX_PWM_DC_VAL

#define TIMER_MAX_PWM_DC_VAL   TIMER_TIMER_PWM_CTRL_REG_TIM_PWM_DC_Msk

Maximum value for timer PWM duty cycle (16bits).

◆ TIMER_MAX_PWM_FREQ_VAL

#define TIMER_MAX_PWM_FREQ_VAL   TIMER_TIMER_PWM_CTRL_REG_TIM_PWM_FREQ_Msk

Maximum value for timer PWM Frequency (16bits).

◆ TIMER_MAX_RELOAD_VAL

#define TIMER_MAX_RELOAD_VAL   TIMER_TIMER_SETTINGS_REG_TIM_RELOAD_Msk

Maximum value for timer reload value (24bits).

◆ TIMER_MAX_SHOTWIDTH_VAL

#define TIMER_MAX_SHOTWIDTH_VAL   TIMER_TIMER_SHOTWIDTH_REG_TIM_SHOTWIDTH_Msk

Maximum value for timer shot phase duration value in oneshot mode (24bits).

Typedef Documentation

◆ hw_timer_capture_handler_cb

typedef void(* hw_timer_capture_handler_cb) (uint8_t gpio_event)

Timer capture interrupt callback.

Parameters
[in]eventbitmask of capture time event GPIOs. "1" means capture event occurred on GPIO Bit: | 3 | 2 | 1 | 0 | +----—+----—+----—+----—+ | GPIO4 | GPIO3 | GPIO2 | GPIO1 | +----—+----—+----—+----—+

◆ hw_timer_handler_cb

typedef void(* hw_timer_handler_cb) (void)

Timer interrupt callback.

Enumeration Type Documentation

◆ HW_TIMER_CLK_SRC

Clock source for timer.

Enumerator
HW_TIMER_CLK_SRC_INT 

Timer uses the low power clock

HW_TIMER_CLK_SRC_EXT 

Timer uses the DIVN

◆ HW_TIMER_DIR

Counting direction.

Enumerator
HW_TIMER_DIR_UP 

Timer counts up (counter is incremented)

HW_TIMER_DIR_DOWN 

Timer counts down (counter is decremented)

◆ HW_TIMER_GPIO

GPIOs for timer trigger.

In HW_TIMER_MODE_TIMER mode use to select which GPIO will trigger capture time. In HW_TIMER_MODE_ONESHOT mode use to select which GPIO will trigger the programmable pulse.

Enumerator
HW_TIMER_GPIO_GPIO_NONE 

No GPIO

HW_TIMER_GPIO_PIN_P0_0 

GPIO P0_0

HW_TIMER_GPIO_PIN_P0_1 

GPIO P0_1

HW_TIMER_GPIO_PIN_P0_2 

GPIO P0_2

HW_TIMER_GPIO_PIN_P0_3 

GPIO P0_3

HW_TIMER_GPIO_PIN_P0_4 

GPIO P0_4

HW_TIMER_GPIO_PIN_P0_5 

GPIO P0_5

HW_TIMER_GPIO_PIN_P0_6 

GPIO P0_6

HW_TIMER_GPIO_PIN_P0_7 

GPIO P0_7

HW_TIMER_GPIO_PIN_P0_8 

GPIO P0_8

HW_TIMER_GPIO_PIN_P0_9 

GPIO P0_9

HW_TIMER_GPIO_PIN_P0_10 

GPIO P0_10

HW_TIMER_GPIO_PIN_P0_11 

GPIO P0_11

HW_TIMER_GPIO_PIN_P0_12 

GPIO P0_12

HW_TIMER_GPIO_PIN_P0_13 

GPIO P0_13

HW_TIMER_GPIO_PIN_P0_14 

GPIO P0_14

HW_TIMER_GPIO_PIN_P0_15 

GPIO P0_15

HW_TIMER_GPIO_PIN_P1_0 

GPIO P1_0

HW_TIMER_GPIO_PIN_P1_1 

GPIO P1_1

HW_TIMER_GPIO_PIN_P1_2 

GPIO P1_2

HW_TIMER_GPIO_PIN_P1_3 

GPIO P1_3

HW_TIMER_GPIO_PIN_P1_4 

GPIO P1_4

HW_TIMER_GPIO_PIN_P1_5 

GPIO P1_5

HW_TIMER_GPIO_PIN_P1_6 

GPIO P1_6

HW_TIMER_GPIO_PIN_P1_7 

GPIO P1_7

HW_TIMER_GPIO_PIN_P1_8 

GPIO P1_8

HW_TIMER_GPIO_PIN_P1_9 

GPIO P1_9

HW_TIMER_GPIO_PIN_P1_10 

GPIO P1_10

HW_TIMER_GPIO_PIN_P1_11 

GPIO P1_11

HW_TIMER_GPIO_PIN_P1_12 

GPIO P1_12

HW_TIMER_GPIO_PIN_P1_13 

GPIO P1_13

HW_TIMER_GPIO_PIN_P1_14 

GPIO P1_14

HW_TIMER_GPIO_PIN_P1_15 

GPIO P1_15

◆ HW_TIMER_MODE

Mode of operation.

Note
PWM is enabled in both modes.
Enumerator
HW_TIMER_MODE_TIMER 

timer/capture mode. Supported by all timers

HW_TIMER_MODE_ONESHOT 

one-shot mode. Supported only by HW_TIMER and HW_TIMER2

◆ HW_TIMER_ONESHOT

One shot mode phases.

Enumerator
HW_TIMER_ONESHOT_WAIT 

Wait for the event

HW_TIMER_ONESHOT_DELAY 

Delay before started

HW_TIMER_ONESHOT_STARTED 

Start shot

HW_TIMER_ONESHOT_ACTIVE 

Shot is active

◆ HW_TIMER_TRIGGER

Type of triggering events.

Enumerator
HW_TIMER_TRIGGER_RISING 

Event activated rising edge

HW_TIMER_TRIGGER_FALLING 

Event activated falling edge

Function Documentation

◆ hw_timer_clear_gpio_event()

__STATIC_INLINE void hw_timer_clear_gpio_event ( uint8_t  mask)

Clear capture time GPIO event.

Parameters
[in]maskbitmask of capture time event GPIOs. Set "1" to clear event Bit: | 3 | 2 | 1 | 0 | +----—+----—+----—+----—+ event GPIO | GPIO4 | GPIO3 | GPIO2 | GPIO1 | +----—+----—+----—+----—+
Note
Only valid for Timer

◆ hw_timer_clear_interrupt()

__STATIC_INLINE void hw_timer_clear_interrupt ( const HW_TIMER_ID  id)

Clear timer interrupt.

Writing any value clears the interrupt

Parameters
[in]idtimer id

◆ hw_timer_configure()

void hw_timer_configure ( HW_TIMER_ID  id,
const timer_config cfg 
)

Timer configuration.

Shortcut to call appropriate configuration function. If cfg is NULL, this function does nothing except switching timer to selected mode.

Parameters
[in]idtimer id
[in]cfgconfiguration

◆ hw_timer_configure_oneshot()

void hw_timer_configure_oneshot ( HW_TIMER_ID  id,
const timer_config_oneshot cfg 
)

Timer configuration for oneshot mode.

Shortcut to call appropriate configuration function. This does not switch timer to oneshot mode, it should be done separately using hw_timer_set_mode().

Parameters
[in]idtimer id. Valid values for one shot mode are HW_TIMER and HW_TIMER2
[in]cfgconfiguration

◆ hw_timer_configure_pwm()

void hw_timer_configure_pwm ( HW_TIMER_ID  id,
const timer_config_pwm cfg 
)

Timer PWM configuration.

Shortcut to call appropriate configuration function.

Parameters
[in]idtimer id
[in]cfgconfiguration
Note
PWM will not be enabled if either frequency or duty cycle are 0
PD COM should be enabled in order to configure PWM output PIN

◆ hw_timer_configure_timer()

void hw_timer_configure_timer ( HW_TIMER_ID  id,
const timer_config_timer_capture cfg 
)

Timer configuration for timer/capture mode.

Shortcut to call appropriate configuration function. This does not switch timer to timer/capture mode, it should be done separately using hw_timer_set_mode().

Parameters
[in]idtimer id
[in]cfgconfiguration
Note
This function will enable the timer clock before loading the registers and it will leave the timer clock enabled
See also
hw_timer_enable_clk

◆ hw_timer_disable()

__STATIC_INLINE void hw_timer_disable ( HW_TIMER_ID  id)

Disable the timer.

Parameters
[in]idtimer id
Note
This function will disable the timer and timer clock

◆ hw_timer_disable_clk()

__STATIC_INLINE void hw_timer_disable_clk ( HW_TIMER_ID  id)

Disable the timer clock.

Parameters
[in]idtimer id

◆ hw_timer_enable()

__STATIC_INLINE void hw_timer_enable ( HW_TIMER_ID  id)

Enable the timer.

Parameters
[in]idtimer id
Note
Assuming the timer clock is enabled, which is done during timer initialisation (hw_timer_init), the timer will start running immediately after the execution of this function.

◆ hw_timer_enable_clk()

__STATIC_INLINE void hw_timer_enable_clk ( HW_TIMER_ID  id)

Enable the timer clock.

Parameters
[in]idtimer id

◆ hw_timer_freeze()

__STATIC_INLINE void hw_timer_freeze ( const HW_TIMER_ID  id)

Freeze timer.

Parameters
[in]idtimer id

◆ hw_timer_frozen()

__STATIC_INLINE bool hw_timer_frozen ( const HW_TIMER_ID  id)

Check if timer is frozen.

Parameters
[in]idtimer id
Returns
true if it is frozen else false

◆ hw_timer_get_capture1()

__STATIC_INLINE uint32_t hw_timer_get_capture1 ( HW_TIMER_ID  id)

Get the capture time for event on GPIO1.

Parameters
[in]idtimer id
Returns
time for event on GPIO1

◆ hw_timer_get_capture2()

__STATIC_INLINE uint32_t hw_timer_get_capture2 ( HW_TIMER_ID  id)

Get the capture time for event on GPIO2.

Parameters
[in]idtimer id
Returns
time for event on GPIO2

◆ hw_timer_get_capture3()

__STATIC_INLINE uint32_t hw_timer_get_capture3 ( void  )

Get the capture time for event on GPIO3. Valid only for Timer.

Returns
time for event on GPIO3

◆ hw_timer_get_capture4()

__STATIC_INLINE uint32_t hw_timer_get_capture4 ( void  )

Get the capture time for event on GPIO4. Valid only for Timer.

Returns
time for event on GPIO4

◆ hw_timer_get_clk()

__STATIC_INLINE HW_TIMER_CLK_SRC hw_timer_get_clk ( HW_TIMER_ID  id)

Get clock source of the timer.

Parameters
[in]idtimer id
Returns
clock source

◆ hw_timer_get_count()

__STATIC_FORCEINLINE uint32_t hw_timer_get_count ( HW_TIMER_ID  id)

Get the tick count of the timer.

Parameters
[in]idtimer id
Returns
current value of the timer ticks
See also
hw_timer_get_prescaler_val

◆ hw_timer_get_event1_gpio()

__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event1_gpio ( HW_TIMER_ID  id)

Get a GPIO input which triggers event1.

Parameters
[in]idtimer id
Returns
GPIO input

◆ hw_timer_get_event1_trigger()

__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event1_trigger ( HW_TIMER_ID  id)

Get a type of the edge which triggers event1.

Parameters
[in]idtimer id
Returns
edge type

◆ hw_timer_get_event2_gpio()

__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event2_gpio ( HW_TIMER_ID  id)

Get a GPIO input which triggers event2.

Parameters
[in]idtimer id
Returns
GPIO input

◆ hw_timer_get_event2_trigger()

__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event2_trigger ( HW_TIMER_ID  id)

Get a type of the edge which triggers event2.

Parameters
[in]idtimer id
Returns
edge type

◆ hw_timer_get_event3_gpio()

__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event3_gpio ( void  )

Get a GPIO input which triggers event3. Valid only for Timer.

Returns
GPIO input

◆ hw_timer_get_event3_trigger()

__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event3_trigger ( void  )

Get a type of the edge which triggers event3. Valid only for Timer.

Returns
edge type

◆ hw_timer_get_event4_gpio()

__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event4_gpio ( void  )

Get a GPIO input which triggers event4. Valid only for Timer.

Returns
GPIO input

◆ hw_timer_get_event4_trigger()

__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event4_trigger ( void  )

Get a type of the edge which triggers event4. Valid only for Timer.

Returns
edge type

◆ hw_timer_get_freerun()

__STATIC_INLINE bool hw_timer_get_freerun ( HW_TIMER_ID  id)

Get free-running mode state.

Parameters
[in]idtimer id
Returns
free-running mode state

◆ hw_timer_get_gpio1_state()

__STATIC_INLINE bool hw_timer_get_gpio1_state ( HW_TIMER_ID  id)

Get the current state of Event input 1 (IN1)

Parameters
[in]idtimer id
Returns
current logic level of IN1

◆ hw_timer_get_gpio2_state()

__STATIC_INLINE bool hw_timer_get_gpio2_state ( HW_TIMER_ID  id)

Get the current state of Event input 2 (IN2)

Parameters
[in]idtimer id
Returns
current logic level of IN2

◆ hw_timer_get_gpio_event_pending()

__STATIC_INLINE uint8_t hw_timer_get_gpio_event_pending ( void  )

Get the time capture event GPIOs pending events.

This function can be used to read the pending status of the capture time event GPIOs (GPIO1 to GPIO4)

Returns
event bitmap of GPIOs. When "1" GPIO event is pending. Bit: | 3 | 2 | 1 | 0 | +----—+----—+----—+----—+ Event | GPIO4 | GPIO3 | GPIO2 | GPIO1 | +----—+----—+----—+----—+
Note
Only valid for Timer

◆ hw_timer_get_mode()

__STATIC_INLINE HW_TIMER_MODE hw_timer_get_mode ( HW_TIMER_ID  id)

Return timer mode.

Parameters
[in]idtimer id

◆ hw_timer_get_oneshot_delay()

__STATIC_INLINE uint32_t hw_timer_get_oneshot_delay ( HW_TIMER_ID  id)

Get pulse delay in oneshot mode.

Parameters
[in]idtimer id
Returns
delay (ticks)
See also
hw_timer_get_oneshot_delay

◆ hw_timer_get_oneshot_phase()

__STATIC_INLINE HW_TIMER_ONESHOT hw_timer_get_oneshot_phase ( HW_TIMER_ID  id)

Get the current phase of the one shot mode.

Parameters
[in]idtimer id
Returns
current phase of the one shot mode

◆ hw_timer_get_prescaler()

__STATIC_INLINE uint32_t hw_timer_get_prescaler ( HW_TIMER_ID  id)

Get timer clock prescaler.

Actual timer frequency is timer_freq = freq_clock / (retval + 1)

Parameters
[in]idtimer id
Returns
prescaler value
See also
hw_timer_get_prescaler_val

◆ hw_timer_get_prescaler_val()

__STATIC_INLINE uint16_t hw_timer_get_prescaler_val ( HW_TIMER_ID  id)

Get the current prescaler counter value.

This is value of internal counter used for prescaling. It can be used to have finer granularity when reading timer value.

For reading current setting of prescaler, see hw_timer_get_prescaler().

Parameters
[in]idtimer id
Returns
current prescaler counter value
See also
hw_timer_get_count
hw_timer_get_prescaler

◆ hw_timer_get_pwm_duty_cycle()

__STATIC_INLINE uint32_t hw_timer_get_pwm_duty_cycle ( HW_TIMER_ID  id)

Get PWM duty cycle.

Actualy PWM duty cycle is pwm_dc = retval / (pwm_freq + 1)

Parameters
[in]idtimer id
Returns
PWM duty cycle as defined above

◆ hw_timer_get_pwm_freq()

__STATIC_INLINE uint32_t hw_timer_get_pwm_freq ( HW_TIMER_ID  id)

Get PWM frequency.

Actual PWM frequency is pwm_freq = timer_freq / (retval + 1)

Parameters
[in]idtimer id
Returns
PWM frequency as defined above

◆ hw_timer_get_reload()

__STATIC_INLINE uint32_t hw_timer_get_reload ( HW_TIMER_ID  id)

Get timer reload value.

Parameters
[in]idtimer id
Returns
reload value
See also
hw_timer_set_reload

◆ hw_timer_get_shot_width()

__STATIC_INLINE uint32_t hw_timer_get_shot_width ( HW_TIMER_ID  id)

Get shot width.

This applies only to one-shot mode.

Parameters
[in]idtimer id
Returns
shot width value

◆ hw_timer_init()

void hw_timer_init ( HW_TIMER_ID  id,
const timer_config cfg 
)

Timer initialization.

Turn on clock for timer and configure timer. After initialization both timer and its interrupt are disabled. cfg can be NULL - no configuration is performed in such case.

Parameters
[in]idtimer id
[in]cfgconfiguration

◆ hw_timer_register_capture_int()

void hw_timer_register_capture_int ( hw_timer_capture_handler_cb  handler,
uint8_t  gpio_mask 
)

Register an interrupt handler for GPIO triggered Timer Capture interrupt.

Parameters
[in]handlerfunction pointer to handler to call when an interrupt occurs
[in]gpio_maskbitmask of capture time event GPIOs. Set "1" to enable capture interrupt on GPIOx event Bit: | 3 | 2 | 1 | 0 | +----—+----—+----—+----—+ IRQ_EN | GPIO4 | GPIO3 | GPIO2 | GPIO1 | +----—+----—+----—+----—+

◆ hw_timer_register_int()

__RETAINED_CODE void hw_timer_register_int ( const HW_TIMER_ID  id,
hw_timer_handler_cb  handler 
)

Register an interrupt handler.

Parameters
[in]idtimer id
[in]handlerfunction pointer to handler to call when an interrupt occurs

◆ hw_timer_set_clk()

__STATIC_INLINE void hw_timer_set_clk ( HW_TIMER_ID  id,
HW_TIMER_CLK_SRC  clk 
)

Set clock source of the timer.

Parameters
[in]idtimer id
[in]clkclock source of the timer, external or internal

◆ hw_timer_set_direction()

__STATIC_INLINE void hw_timer_set_direction ( HW_TIMER_ID  id,
HW_TIMER_DIR  dir 
)

Set the direction of timer counting.

Parameters
[in]idtimer id
[in]dircounting direction of the timer, up or down

◆ hw_timer_set_event1_gpio()

__STATIC_INLINE void hw_timer_set_event1_gpio ( HW_TIMER_ID  id,
HW_TIMER_GPIO  gpio 
)

Set a GPIO input which triggers event1.

Parameters
[in]idtimer id
[in]gpioGPIO input

◆ hw_timer_set_event1_trigger()

__STATIC_INLINE void hw_timer_set_event1_trigger ( HW_TIMER_ID  id,
HW_TIMER_TRIGGER  edge 
)

Set a type of the edge which triggers event1.

Parameters
[in]idtimer id
[in]edgetype of edge, rising or falling

◆ hw_timer_set_event2_gpio()

__STATIC_INLINE void hw_timer_set_event2_gpio ( HW_TIMER_ID  id,
HW_TIMER_GPIO  gpio 
)

Set a GPIO input which triggers event2.

Parameters
[in]idtimer id
[in]gpioGPIO input

◆ hw_timer_set_event2_trigger()

__STATIC_INLINE void hw_timer_set_event2_trigger ( HW_TIMER_ID  id,
HW_TIMER_TRIGGER  edge 
)

Set a type of the edge which triggers event2.

Parameters
[in]idtimer id
[in]edgetype of edge, rising or falling

◆ hw_timer_set_event3_gpio()

__STATIC_INLINE void hw_timer_set_event3_gpio ( HW_TIMER_GPIO  gpio)

Set a GPIO input which triggers event3.

Parameters
[in]gpioGPIO input
Note
Valid only for Timer

◆ hw_timer_set_event3_trigger()

__STATIC_INLINE void hw_timer_set_event3_trigger ( HW_TIMER_TRIGGER  edge)

Set a type of the edge which triggers event3.

Parameters
[in]edgetype of edge, rising or falling
Note
Valid only for Timer

◆ hw_timer_set_event4_gpio()

__STATIC_INLINE void hw_timer_set_event4_gpio ( HW_TIMER_GPIO  gpio)

Set a GPIO input which triggers event4.

Parameters
[in]gpioGPIO input
Note
Valid only for Timer

◆ hw_timer_set_event4_trigger()

__STATIC_INLINE void hw_timer_set_event4_trigger ( HW_TIMER_TRIGGER  edge)

Set a type of the edge which triggers event4.

Parameters
[in]edgetype of edge, rising or falling
Note
Valid only for Timer

◆ hw_timer_set_freerun()

__STATIC_INLINE void hw_timer_set_freerun ( HW_TIMER_ID  id,
bool  enable 
)

Turn on free run mode of the timer.

This mode is valid only when timer is counting up

Parameters
[in]idtimer id
[in]enableif it is '1' timer does not zero when it reaches the reload value.

◆ hw_timer_set_gpio_event_int()

__STATIC_INLINE void hw_timer_set_gpio_event_int ( uint8_t  mask)

Select which time capture event GPIOs will create a capture IRQ.

Parameters
[in]maskbitmask of capture time event GPIOs. Set "1" to enable capture interrupt on GPIOx event Bit: | 3 | 2 | 1 | 0 | +----—+----—+----—+----—+ IRQ_EN | GPIO4 | GPIO3 | GPIO2 | GPIO1 | +----—+----—+----—+----—+
Note
Valid only for Timer

◆ hw_timer_set_mode()

__STATIC_INLINE void hw_timer_set_mode ( HW_TIMER_ID  id,
HW_TIMER_MODE  mode 
)

Set timer mode.

Parameters
[in]idtimer id
[in]modetimer mode: '1' One shot, '0' counter

◆ hw_timer_set_oneshot_delay()

__STATIC_INLINE void hw_timer_set_oneshot_delay ( HW_TIMER_ID  id,
uint32_t  delay 
)

Set pulse delay in oneshot mode.

Note
This changes the same register value as hw_timer_set_reload() since both parameters share the same register (value is interpreted differently depending on timer mode).
Parameters
[in]idtimer id
[in]delaydelay (ticks). 24 bits long, shall not be greater than 0xffffff
See also
hw_timer_set_reload

◆ hw_timer_set_prescaler()

__STATIC_INLINE void hw_timer_set_prescaler ( HW_TIMER_ID  id,
uint8_t  value 
)

Set timer clock prescaler.

Actual timer frequency is timer_freq = freq_clock / (value + 1)

Parameters
[in]idtimer id
[in]valueprescaler. 5 bits long, shall not be greater than 0x1f

◆ hw_timer_set_pwm_duty_cycle()

__STATIC_INLINE void hw_timer_set_pwm_duty_cycle ( HW_TIMER_ID  id,
uint32_t  value 
)

Set PWM duty cycle.

Actualy PWM duty cycle is pwm_dc = value / (pwm_freq + 1)

Parameters
[in]idtimer id
[in]valuePWM duty cycle defined as above
See also
hw_timer_set_pwm_freq

◆ hw_timer_set_pwm_freq()

__STATIC_INLINE void hw_timer_set_pwm_freq ( HW_TIMER_ID  id,
uint32_t  value 
)

Set PWM frequency prescaler.

Actual PWM frequency is pwm_freq = timer_freq / (value + 1)

Parameters
[in]idtimer id
[in]valuePWM frequency defined as above
See also
hw_timer_set_prescaler

◆ hw_timer_set_reload()

__STATIC_FORCEINLINE void hw_timer_set_reload ( HW_TIMER_ID  id,
uint32_t  value 
)

Set timer reload value.

Note
This changes the same register value as hw_timer_set_oneshot_delay() since both parameters share the same register (value is interpreted differently depending on timer mode).
Parameters
[in]idtimer id
[in]valuereload value. 24 bits long, shall not be greater than 0xffffff
See also
hw_timer_set_oneshot_delay

◆ hw_timer_set_shot_width()

__STATIC_INLINE void hw_timer_set_shot_width ( HW_TIMER_ID  id,
uint32_t  duration 
)

Set shot width.

This applies only to one-shot mode.

Parameters
[in]idtimer id
[in]durationshot phase duration. 24 bits long, shall not be greater than 0xffffff

◆ hw_timer_unfreeze()

__STATIC_INLINE void hw_timer_unfreeze ( const HW_TIMER_ID  id)

Unfreeze timer.

Parameters
[in]idtimer id

◆ hw_timer_unregister_capture_int()

void hw_timer_unregister_capture_int ( void  )

Unregister an interrupt handler for GPIO triggered Timer Capture interrupt.

◆ hw_timer_unregister_int()

__RETAINED_HOT_CODE void hw_timer_unregister_int ( const HW_TIMER_ID  id)

Unregister an interrupt handler.

Parameters
[in]idtimer id
TIMER_TIMER_SETTINGS_REG_TIM_PRESCALER_Msk
#define TIMER_TIMER_SETTINGS_REG_TIM_PRESCALER_Msk
Definition: DA1459x-00.h:5064