|
SmartSnippets DA1459x SDK
|
Go to the documentation of this file.
46 #if dg_configUSE_HW_TIMER
55 #define TBA(id) ((TIMER_Type *)id)
72 #define HW_TIMER_REG_GETF(id, reg, field) \
73 ((TBA(id)->reg & (TIMER_##reg##_##field##_Msk)) >> (TIMER_##reg##_##field##_Pos))
84 #define HW_TIMER_REG_SETF(id, reg, field, val) \
85 TBA(id)->reg = ((TBA(id)->reg & ~(TIMER_##reg##_##field##_Msk)) | \
86 ((TIMER_##reg##_##field##_Msk) & ((val) << (TIMER_##reg##_##field##_Pos))))
92 #define TIMER_MAX_PRESCALER_VAL (TIMER_TIMER_SETTINGS_REG_TIM_PRESCALER_Msk >> \
93 TIMER_TIMER_SETTINGS_REG_TIM_PRESCALER_Pos)
99 #define TIMER_MAX_RELOAD_VAL TIMER_TIMER_SETTINGS_REG_TIM_RELOAD_Msk
105 #define TIMER_MAX_SHOTWIDTH_VAL TIMER_TIMER_SHOTWIDTH_REG_TIM_SHOTWIDTH_Msk
112 #define TIMER_MAX_PWM_FREQ_VAL TIMER_TIMER_PWM_CTRL_REG_TIM_PWM_FREQ_Msk
118 #define TIMER_MAX_PWM_DC_VAL TIMER_TIMER_PWM_CTRL_REG_TIM_PWM_DC_Msk
124 #define HW_TIMER ((void *)TIMER_BASE)
125 #define HW_TIMER2 ((void *)TIMER2_BASE)
126 #define HW_TIMER3 ((void *)TIMER3_BASE)
127 #define HW_TIMER4 ((void *)TIMER4_BASE)
128 typedef void * HW_TIMER_ID;
385 }
else if (
id == HW_TIMER2) {
387 }
else if (
id == HW_TIMER3) {
389 }
else if (
id == HW_TIMER4) {
405 }
else if (
id == HW_TIMER2) {
407 }
else if (
id == HW_TIMER3) {
409 }
else if (
id == HW_TIMER4) {
428 }
else if (
id == HW_TIMER2) {
430 }
else if (
id == HW_TIMER3) {
432 }
else if (
id == HW_TIMER4) {
517 TBA(
id)->TIMER_SHOTWIDTH_REG = duration;
568 REG_SETF(TIMER, TIMER_CTRL_REG, TIM_IN3_EVENT_FALL_EN, edge);
581 REG_SETF(TIMER, TIMER_CTRL_REG, TIM_IN4_EVENT_FALL_EN, edge);
600 uint32_t tmp = TIMER->TIMER_CTRL_REG;
601 REG_SET_FIELD(TIMER, TIMER_CTRL_REG, TIM_CAP_GPIO1_IRQ_EN, tmp, (mask & 0x1));
602 REG_SET_FIELD(TIMER, TIMER_CTRL_REG, TIM_CAP_GPIO2_IRQ_EN, tmp, ((mask & 0x2) >> 1));
603 REG_SET_FIELD(TIMER, TIMER_CTRL_REG, TIM_CAP_GPIO3_IRQ_EN, tmp, ((mask & 0x4) >> 2));
604 REG_SET_FIELD(TIMER, TIMER_CTRL_REG, TIM_CAP_GPIO4_IRQ_EN, tmp, ((mask & 0x8) >> 3));
605 TIMER->TIMER_CTRL_REG = tmp;
617 TBA(
id)->TIMER_GPIO1_CONF_REG = gpio;
629 TBA(
id)->TIMER_GPIO2_CONF_REG = gpio;
642 TIMER->TIMER_GPIO3_CONF_REG = gpio;
655 TIMER->TIMER_GPIO4_CONF_REG = gpio;
729 return TBA(
id)->TIMER_SHOTWIDTH_REG;
779 return REG_GETF(TIMER, TIMER_CTRL_REG, TIM_IN3_EVENT_FALL_EN);
790 return REG_GETF(TIMER, TIMER_CTRL_REG, TIM_IN4_EVENT_FALL_EN);
803 return TBA(
id)->TIMER_GPIO1_CONF_REG;
816 return TBA(
id)->TIMER_GPIO2_CONF_REG;
827 return TIMER->TIMER_GPIO3_CONF_REG;
838 return TIMER->TIMER_GPIO4_CONF_REG;
851 return TBA(
id)->TIMER_CAPTURE_GPIO1_REG;
864 return TBA(
id)->TIMER_CAPTURE_GPIO2_REG;
875 return TIMER->TIMER_CAPTURE_GPIO3_REG;
886 return TIMER->TIMER_CAPTURE_GPIO4_REG;
938 return TBA(
id)->TIMER_TIMER_VAL_REG;
986 return ((TIMER->TIMER_STATUS_REG &
1025 return TBA(
id)->TIMER_PRESCALER_VAL_REG;
1214 TIMER->TIMER_CLEAR_GPIO_EVENT_REG = mask;
1228 TIMER->TIMER_CLEAR_IRQ_REG = 0;
1229 }
else if (
id == HW_TIMER2) {
1230 TIMER2->TIMER2_CLEAR_IRQ_REG = 0;
1231 }
else if (
id == HW_TIMER3) {
1232 TIMER3->TIMER3_CLEAR_IRQ_REG = 0;
1233 }
else if (
id == HW_TIMER4) {
1234 TIMER4->TIMER4_CLEAR_IRQ_REG = 0;
__STATIC_INLINE uint16_t hw_timer_get_prescaler_val(HW_TIMER_ID id)
Get the current prescaler counter value.
Definition: hw_timer.h:1023
Definition: hw_timer.h:138
__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event3_trigger(void)
Get a type of the edge which triggers event3. Valid only for Timer.
Definition: hw_timer.h:777
HW_TIMER_GPIO gpio2
Definition: hw_timer.h:257
Definition: hw_timer.h:215
#define TIMER_MAX_PWM_FREQ_VAL
Maximum value for timer PWM Frequency (16bits).
Definition: hw_timer.h:112
__STATIC_INLINE bool hw_timer_get_gpio1_state(HW_TIMER_ID id)
Get the current state of Event input 1 (IN1)
Definition: hw_timer.h:962
__STATIC_INLINE void hw_timer_set_oneshot_delay(HW_TIMER_ID id, uint32_t delay)
Set pulse delay in oneshot mode.
Definition: hw_timer.h:498
#define REG_SETF(base, reg, field, new_val)
Set the value of a register field.
Definition: sdk_defs.h:738
Definition: hw_timer.h:201
void(* hw_timer_handler_cb)(void)
Timer interrupt callback.
Definition: hw_timer.h:229
Definition: hw_timer.h:202
__STATIC_FORCEINLINE uint32_t hw_timer_get_count(HW_TIMER_ID id)
Get the tick count of the timer.
Definition: hw_timer.h:935
Definition: hw_timer.h:214
Definition: hw_timer.h:206
__STATIC_INLINE void hw_timer_set_event3_trigger(HW_TIMER_TRIGGER edge)
Set a type of the edge which triggers event3.
Definition: hw_timer.h:566
bool pwm_active_in_sleep
Definition: hw_timer.h:291
uint32_t shot_width
Definition: hw_timer.h:274
__STATIC_INLINE void hw_timer_set_pwm_freq(HW_TIMER_ID id, uint32_t value)
Set PWM frequency prescaler.
Definition: hw_timer.h:1142
#define GPREG_SET_FREEZE_REG_FRZ_SWTIM_Msk
Definition: DA1459x-00.h:3296
#define HW_TIMER_REG_GETF(id, reg, field)
Definition for the PWM synchronization bitfield.
Definition: hw_timer.h:72
Definition: hw_timer.h:194
__STATIC_INLINE void hw_timer_clear_gpio_event(uint8_t mask)
Clear capture time GPIO event.
Definition: hw_timer.h:1212
Timer configuration.
Definition: hw_timer.h:311
Definition: hw_timer.h:175
#define TIMER_TIMER_STATUS_REG_TIM_GPIO4_EVENT_PENDING_Msk
Definition: DA1459x-00.h:5084
#define HW_TIMER
Timer id.
Definition: hw_timer.h:124
__STATIC_INLINE void hw_timer_enable(HW_TIMER_ID id)
Enable the timer.
Definition: hw_timer.h:1075
Definition: hw_timer.h:213
__STATIC_INLINE uint32_t hw_timer_get_capture4(void)
Get the capture time for event on GPIO4. Valid only for Timer.
Definition: hw_timer.h:884
HW_TIMER_TRIGGER trigger4
Definition: hw_timer.h:262
__STATIC_INLINE void hw_timer_set_pwm_duty_cycle(HW_TIMER_ID id, uint32_t value)
Set PWM duty cycle.
Definition: hw_timer.h:1161
__STATIC_INLINE uint32_t hw_timer_get_reload(HW_TIMER_ID id)
Get timer reload value.
Definition: hw_timer.h:697
Timer configuration for oneshot mode.
Definition: hw_timer.h:272
__STATIC_INLINE void hw_timer_enable_clk(HW_TIMER_ID id)
Enable the timer clock.
Definition: hw_timer.h:1101
uint16_t frequency
Definition: hw_timer.h:293
Definition: hw_timer.h:204
__STATIC_INLINE HW_TIMER_ONESHOT hw_timer_get_oneshot_phase(HW_TIMER_ID id)
Get the current phase of the one shot mode.
Definition: hw_timer.h:949
__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.
Definition: hw_timer.h:541
Central include header file with platform definitions.
__RETAINED_CODE void hw_timer_register_int(const HW_TIMER_ID id, hw_timer_handler_cb handler)
Register an interrupt handler.
void hw_timer_configure_timer(HW_TIMER_ID id, const timer_config_timer_capture *cfg)
Timer configuration for timer/capture mode.
__STATIC_INLINE bool hw_timer_frozen(const HW_TIMER_ID id)
Check if timer is frozen.
Definition: hw_timer.h:424
__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event2_trigger(HW_TIMER_ID id)
Get a type of the edge which triggers event2.
Definition: hw_timer.h:766
__STATIC_INLINE HW_TIMER_CLK_SRC hw_timer_get_clk(HW_TIMER_ID id)
Get clock source of the timer.
Definition: hw_timer.h:665
__STATIC_INLINE uint32_t hw_timer_get_capture1(HW_TIMER_ID id)
Get the capture time for event on GPIO1.
Definition: hw_timer.h:849
timer_config_pwm pwm
Definition: hw_timer.h:319
HW_TIMER_TRIGGER trigger1
Definition: hw_timer.h:256
Definition: hw_timer.h:156
#define TIMER_TIMER_STATUS_REG_TIM_GPIO1_EVENT_PENDING_Msk
Definition: DA1459x-00.h:5090
Definition: hw_timer.h:220
__STATIC_INLINE void hw_timer_set_gpio_event_int(uint8_t mask)
Select which time capture event GPIOs will create a capture IRQ.
Definition: hw_timer.h:598
#define TIMER_MAX_PWM_DC_VAL
Maximum value for timer PWM duty cycle (16bits).
Definition: hw_timer.h:118
#define HW_TIMER_REG_SETF(id, reg, field, val)
Set the value of a field of a TIMER register.
Definition: hw_timer.h:84
Definition: hw_timer.h:208
Definition: hw_timer.h:178
uint8_t prescaler
Definition: hw_timer.h:313
#define GPREG_RESET_FREEZE_REG_FRZ_SWTIM2_Msk
Definition: DA1459x-00.h:3264
HW_GPIO_PIN
GPIO pin number.
Definition: hw_gpio.h:106
__STATIC_INLINE void hw_timer_set_event4_gpio(HW_TIMER_GPIO gpio)
Set a GPIO input which triggers event4.
Definition: hw_timer.h:653
HW_TIMER_TRIGGER trigger3
Definition: hw_timer.h:260
HW_TIMER_TRIGGER trigger2
Definition: hw_timer.h:258
__STATIC_INLINE uint32_t hw_timer_get_pwm_duty_cycle(HW_TIMER_ID id)
Get PWM duty cycle.
Definition: hw_timer.h:1193
__STATIC_INLINE void hw_timer_set_shot_width(HW_TIMER_ID id, uint32_t duration)
Set shot width.
Definition: hw_timer.h:514
HW_TIMER_DIR
Counting direction.
Definition: hw_timer.h:155
Definition: hw_timer.h:209
__RETAINED_HOT_CODE void hw_timer_unregister_int(const HW_TIMER_ID id)
Unregister an interrupt handler.
Definition: hw_timer.h:205
__STATIC_INLINE bool hw_timer_get_freerun(HW_TIMER_ID id)
Get free-running mode state.
Definition: hw_timer.h:740
HW_GPIO_PORT
GPIO port number.
Definition: hw_gpio.h:96
__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.
Definition: hw_timer.h:553
Definition: hw_timer.h:210
__STATIC_INLINE void hw_timer_set_freerun(HW_TIMER_ID id, bool enable)
Turn on free run mode of the timer.
Definition: hw_timer.h:529
Definition: hw_timer.h:139
__STATIC_INLINE uint32_t hw_timer_get_shot_width(HW_TIMER_ID id)
Get shot width.
Definition: hw_timer.h:727
Definition: hw_timer.h:195
#define TIMER_MAX_SHOTWIDTH_VAL
Maximum value for timer shot phase duration value in oneshot mode (24bits).
Definition: hw_timer.h:105
__STATIC_INLINE void hw_timer_clear_interrupt(const HW_TIMER_ID id)
Clear timer interrupt.
Definition: hw_timer.h:1225
HW_GPIO_PORT port
Definition: hw_timer.h:289
__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event4_trigger(void)
Get a type of the edge which triggers event4. Valid only for Timer.
Definition: hw_timer.h:788
HW_TIMER_GPIO gpio
Definition: hw_timer.h:275
#define TIMER_TIMER_STATUS_REG_TIM_GPIO2_EVENT_PENDING_Msk
Definition: DA1459x-00.h:5088
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.
void hw_timer_init(HW_TIMER_ID id, const timer_config *cfg)
Timer initialization.
HW_TIMER_MODE
Mode of operation.
Definition: hw_timer.h:137
void hw_timer_configure(HW_TIMER_ID id, const timer_config *cfg)
Timer configuration.
Definition: hw_timer.h:147
timer_config_timer_capture timer
Definition: hw_timer.h:316
#define GPREG_RESET_FREEZE_REG_FRZ_SWTIM4_Msk
Definition: DA1459x-00.h:3260
#define GPREG_SET_FREEZE_REG_FRZ_SWTIM2_Msk
Definition: DA1459x-00.h:3288
__STATIC_INLINE void hw_timer_set_event4_trigger(HW_TIMER_TRIGGER edge)
Set a type of the edge which triggers event4.
Definition: hw_timer.h:579
__STATIC_INLINE void hw_timer_set_event2_gpio(HW_TIMER_ID id, HW_TIMER_GPIO gpio)
Set a GPIO input which triggers event2.
Definition: hw_timer.h:627
__STATIC_INLINE void hw_timer_set_event1_gpio(HW_TIMER_ID id, HW_TIMER_GPIO gpio)
Set a GPIO input which triggers event1.
Definition: hw_timer.h:615
__STATIC_INLINE bool hw_timer_get_gpio2_state(HW_TIMER_ID id)
Get the current state of Event input 2 (IN2)
Definition: hw_timer.h:1001
HW_TIMER_TRIGGER trigger
Definition: hw_timer.h:276
HW_TIMER_CLK_SRC clk_src
Definition: hw_timer.h:312
Definition: hw_timer.h:200
#define TIMER_MAX_RELOAD_VAL
Maximum value for timer reload value (24bits).
Definition: hw_timer.h:99
HW_GPIO_MODE mode
Definition: hw_gpio.h:211
__STATIC_INLINE uint32_t hw_timer_get_pwm_freq(HW_TIMER_ID id)
Get PWM frequency.
Definition: hw_timer.h:1178
__STATIC_INLINE void hw_timer_set_clk(HW_TIMER_ID id, HW_TIMER_CLK_SRC clk)
Set clock source of the timer.
Definition: hw_timer.h:446
bool free_run
Definition: hw_timer.h:254
HW_TIMER_DIR direction
Definition: hw_timer.h:252
#define TIMER_TIMER_STATUS_REG_TIM_GPIO3_EVENT_PENDING_Msk
Definition: DA1459x-00.h:5086
Definition: hw_timer.h:207
Timer PWM configuration.
Definition: hw_timer.h:287
Definition: hw_timer.h:196
Definition: hw_timer.h:217
Definition: hw_timer.h:212
HW_TIMER_GPIO
GPIOs for timer trigger.
Definition: hw_timer.h:189
Definition: hw_timer.h:198
Definition: hw_timer.h:221
Definition: hw_timer.h:218
HW_TIMER_GPIO gpio4
Definition: hw_timer.h:261
#define TIMER_MAX_PRESCALER_VAL
Maximum value for timer pre-scaler (5bits).
Definition: hw_timer.h:92
Definition of API for the GPIO Low Level Driver.
Definition: hw_timer.h:211
__STATIC_INLINE void hw_timer_set_mode(HW_TIMER_ID id, HW_TIMER_MODE mode)
Set timer mode.
Definition: hw_timer.h:909
__STATIC_INLINE uint32_t hw_timer_get_oneshot_delay(HW_TIMER_ID id)
Get pulse delay in oneshot mode.
Definition: hw_timer.h:712
Definition: hw_timer.h:203
void hw_timer_configure_oneshot(HW_TIMER_ID id, const timer_config_oneshot *cfg)
Timer configuration for oneshot mode.
__STATIC_INLINE HW_TIMER_MODE hw_timer_get_mode(HW_TIMER_ID id)
Return timer mode.
Definition: hw_timer.h:920
#define REG_GETF(base, reg, field)
Return the value of a register field.
Definition: sdk_defs.h:711
void hw_timer_configure_pwm(HW_TIMER_ID id, const timer_config_pwm *cfg)
Timer PWM configuration.
__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event1_gpio(HW_TIMER_ID id)
Get a GPIO input which triggers event1.
Definition: hw_timer.h:801
Definition: hw_timer.h:191
__STATIC_INLINE uint32_t hw_timer_get_capture2(HW_TIMER_ID id)
Get the capture time for event on GPIO2.
Definition: hw_timer.h:862
void hw_timer_unregister_capture_int(void)
Unregister an interrupt handler for GPIO triggered Timer Capture interrupt.
void(* hw_timer_capture_handler_cb)(uint8_t gpio_event)
Timer capture interrupt callback.
Definition: hw_timer.h:242
Definition: hw_timer.h:166
Definition: hw_timer.h:192
#define REG_SET_FIELD(base, reg, field, var, val)
Set register field value.
Definition: sdk_defs.h:626
Definition: hw_timer.h:199
#define GPREG_RESET_FREEZE_REG_FRZ_SWTIM_Msk
Definition: DA1459x-00.h:3272
Definition: hw_timer.h:216
Definition: hw_timer.h:165
Definition: hw_timer.h:148
#define GPREG_RESET_FREEZE_REG_FRZ_SWTIM3_Msk
Definition: DA1459x-00.h:3262
HW_TIMER_GPIO gpio1
Definition: hw_timer.h:255
Definition: hw_timer.h:176
timer_config_oneshot oneshot
Definition: hw_timer.h:317
HW_TIMER_MODE mode
Definition: hw_timer.h:314
#define GPREG_SET_FREEZE_REG_FRZ_SWTIM3_Msk
Definition: DA1459x-00.h:3286
__STATIC_FORCEINLINE void hw_timer_set_reload(HW_TIMER_ID id, uint32_t value)
Set timer reload value.
Definition: hw_timer.h:479
__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event3_gpio(void)
Get a GPIO input which triggers event3. Valid only for Timer.
Definition: hw_timer.h:825
#define GPREG_SET_FREEZE_REG_FRZ_SWTIM4_Msk
Definition: DA1459x-00.h:3284
Definition: hw_timer.h:190
uint32_t reload_val
Definition: hw_timer.h:253
__STATIC_INLINE void hw_timer_disable(HW_TIMER_ID id)
Disable the timer.
Definition: hw_timer.h:1088
Definition: hw_timer.h:157
__STATIC_INLINE uint32_t hw_timer_get_capture3(void)
Get the capture time for event on GPIO3. Valid only for Timer.
Definition: hw_timer.h:873
HW_TIMER_GPIO gpio3
Definition: hw_timer.h:259
__STATIC_INLINE uint8_t hw_timer_get_gpio_event_pending(void)
Get the time capture event GPIOs pending events.
Definition: hw_timer.h:984
__STATIC_INLINE void hw_timer_freeze(const HW_TIMER_ID id)
Freeze timer.
Definition: hw_timer.h:381
HW_TIMER_CLK_SRC
Clock source for timer.
Definition: hw_timer.h:146
__STATIC_INLINE HW_TIMER_TRIGGER hw_timer_get_event1_trigger(HW_TIMER_ID id)
Get a type of the edge which triggers event1.
Definition: hw_timer.h:753
uint32_t delay
Definition: hw_timer.h:273
Definition: hw_timer.h:219
Definition: hw_timer.h:197
__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event2_gpio(HW_TIMER_ID id)
Get a GPIO input which triggers event2.
Definition: hw_timer.h:814
__STATIC_INLINE void hw_timer_set_event3_gpio(HW_TIMER_GPIO gpio)
Set a GPIO input which triggers event3.
Definition: hw_timer.h:640
__STATIC_INLINE uint32_t hw_timer_get_prescaler(HW_TIMER_ID id)
Get timer clock prescaler.
Definition: hw_timer.h:682
HW_TIMER_TRIGGER
Type of triggering events.
Definition: hw_timer.h:164
HW_GPIO_PIN pin
Definition: hw_timer.h:288
Definition: hw_timer.h:177
__STATIC_INLINE void hw_timer_unfreeze(const HW_TIMER_ID id)
Unfreeze timer.
Definition: hw_timer.h:401
Definition: hw_timer.h:222
__STATIC_INLINE void hw_timer_set_direction(HW_TIMER_ID id, HW_TIMER_DIR dir)
Set the direction of timer counting.
Definition: hw_timer.h:897
HW_TIMER_ONESHOT
One shot mode phases.
Definition: hw_timer.h:174
__STATIC_INLINE void hw_timer_disable_clk(HW_TIMER_ID id)
Disable the timer clock.
Definition: hw_timer.h:1112
Definition: hw_timer.h:193
__STATIC_INLINE HW_TIMER_GPIO hw_timer_get_event4_gpio(void)
Get a GPIO input which triggers event4. Valid only for Timer.
Definition: hw_timer.h:836
Timer configuration for timer/capture mode.
Definition: hw_timer.h:251
__STATIC_INLINE void hw_timer_set_prescaler(HW_TIMER_ID id, uint8_t value)
Set timer clock prescaler.
Definition: hw_timer.h:460