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

Definition of API for the Timer, Timer2, Timer3 and Timer4 Low Level Driver. More...

#include <stdbool.h>
#include <stdint.h>
#include "sdk_defs.h"
#include "hw_gpio.h"

Go to the source code of this file.

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

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

Copyright (C) 2017-2023 Renesas Electronics Corporation and/or its affiliates. All rights reserved. Confidential Information.

This software ("Software") is supplied by Renesas Electronics Corporation and/or its affiliates ("Renesas"). Renesas grants you a personal, non-exclusive, non-transferable, revocable, non-sub-licensable right and license to use the Software, solely if used in or together with Renesas products. You may make copies of this Software, provided this copyright notice and disclaimer ("Notice") is included in all such copies. Renesas reserves the right to change or discontinue the Software at any time without notice.

THE SOFTWARE IS PROVIDED "AS IS". RENESAS DISCLAIMS ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. TO THE MAXIMUM EXTENT PERMITTED UNDER LAW, IN NO EVENT SHALL RENESAS BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE, EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. USE OF THIS SOFTWARE MAY BE SUBJECT TO TERMS AND CONDITIONS CONTAINED IN AN ADDITIONAL AGREEMENT BETWEEN YOU AND RENESAS. IN CASE OF CONFLICT BETWEEN THE TERMS OF THIS NOTICE AND ANY SUCH ADDITIONAL LICENSE AGREEMENT, THE TERMS OF THE AGREEMENT SHALL TAKE PRECEDENCE. BY CONTINUING TO USE THIS SOFTWARE, YOU AGREE TO THE TERMS OF THIS NOTICE.IF YOU DO NOT AGREE TO THESE TERMS, YOU ARE NOT PERMITTED TO USE THIS SOFTWARE.