1 /* 2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef R_GTM_H 8 #define R_GTM_H 9 10 /*********************************************************************************************************************** 11 * Includes 12 **********************************************************************************************************************/ 13 #include "bsp_api.h" 14 #include "r_gtm_cfg.h" 15 #include "r_timer_api.h" 16 17 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ 18 FSP_HEADER 19 20 /*********************************************************************************************************************** 21 * Macro definitions 22 **********************************************************************************************************************/ 23 24 /** Maximum number of clock counts in 32 bit timer. */ 25 #define GTM_MAX_CLOCK_COUNTS (UINT32_MAX) 26 27 /** Maximum period value allowed for GTM. */ 28 #define GTM_MAX_PERIOD ((uint64_t) UINT32_MAX + 1ULL) 29 30 /*******************************************************************************************************************//** 31 * @addtogroup GTM 32 * @{ 33 **********************************************************************************************************************/ 34 35 /*********************************************************************************************************************** 36 * Typedef definitions 37 **********************************************************************************************************************/ 38 39 /** Optional GTM interrupt setting */ 40 typedef enum e_gtm_giws_type 41 { 42 GTM_GIWS_TYPE_DISABLED = 0, ///< Do not generate interrupt when timer started 43 GTM_GIWS_TYPE_ENABLED = 1, ///< Generates interrupt when timer started 44 } gtm_giws_type_t; 45 46 /** Optional GTM timer mode setting */ 47 typedef enum e_gtm_timer_mode 48 { 49 GTM_TIMER_MODE_INTERVAL = 0, ///< Use interval timer mode 50 GTM_TIMER_MODE_FREERUN = 1, ///< Use free-running comparison mode 51 } gtm_timer_mode_t; 52 53 /** Channel control block. DO NOT INITIALIZE. Initialization occurs when @ref timer_api_t::open is called. */ 54 typedef struct st_gtm_instance_ctrl 55 { 56 uint32_t open; // Whether or not channel is open 57 const timer_cfg_t * p_cfg; // Pointer to initial configurations 58 R_GTM0_Type * p_reg; // Base register for this channel 59 uint32_t period; // Current timer period (counts) 60 61 void (* p_callback)(timer_callback_args_t * p_arg); // Pointer to callback 62 timer_callback_args_t * p_callback_memory; // Pointer to pre-allocated callback argument 63 void const * p_context; // Pointer to context to be passed into callback function 64 } gtm_instance_ctrl_t; 65 66 /** Optional GTM extension data structure.*/ 67 typedef struct st_gtm_extended_cfg 68 { 69 gtm_giws_type_t generate_interrupt_when_starts; // Controls enabling/disabling of interrupt requests when start 70 gtm_timer_mode_t gtm_mode; // Select GTM timer mode 71 } gtm_extended_cfg_t; 72 73 /********************************************************************************************************************** 74 * Exported global variables 75 **********************************************************************************************************************/ 76 77 /** @cond INC_HEADER_DEFS_SEC */ 78 /** Filled in Interface API structure for this Instance. */ 79 extern const timer_api_t g_timer_on_gtm; 80 81 /** @endcond */ 82 83 fsp_err_t R_GTM_Close(timer_ctrl_t * const p_ctrl); 84 fsp_err_t R_GTM_PeriodSet(timer_ctrl_t * const p_ctrl, uint32_t const period_counts); 85 fsp_err_t R_GTM_DutyCycleSet(timer_ctrl_t * const p_ctrl, uint32_t const duty_cycle_counts, uint32_t const pin); 86 fsp_err_t R_GTM_Reset(timer_ctrl_t * const p_ctrl); 87 fsp_err_t R_GTM_Start(timer_ctrl_t * const p_ctrl); 88 fsp_err_t R_GTM_Enable(timer_ctrl_t * const p_ctrl); 89 fsp_err_t R_GTM_Disable(timer_ctrl_t * const p_ctrl); 90 fsp_err_t R_GTM_InfoGet(timer_ctrl_t * const p_ctrl, timer_info_t * const p_info); 91 fsp_err_t R_GTM_StatusGet(timer_ctrl_t * const p_ctrl, timer_status_t * const p_status); 92 fsp_err_t R_GTM_Stop(timer_ctrl_t * const p_ctrl); 93 fsp_err_t R_GTM_Open(timer_ctrl_t * const p_ctrl, timer_cfg_t const * const p_cfg); 94 fsp_err_t R_GTM_CallbackSet(timer_ctrl_t * const p_api_ctrl, 95 void ( * p_callback)(timer_callback_args_t * p_arg), 96 void const * const p_context, 97 timer_callback_args_t * const p_callback_memory); 98 99 /*******************************************************************************************************************//** 100 * @} (end defgroup GTM) 101 **********************************************************************************************************************/ 102 103 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ 104 105 FSP_FOOTER 106 107 #endif /* R_GTM_H */ 108