Skip to content

Commit e4e1779

Browse files
nhutnguyenkcKhiemNguyenT
authored andcommitted
hal: renesas: rza: Add Counter support for RZ/A series
Add GTM FSP HAL driver to support Zephyr Counter driver for RZ/A3UL Signed-off-by: Nhut Nguyen <[email protected]> Signed-off-by: Hieu Nguyen <[email protected]>
1 parent ad270f2 commit e4e1779

File tree

3 files changed

+745
-0
lines changed

3 files changed

+745
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
/* Leading zeroes removed to avoid coding standards violation. */
25+
26+
/** Maximum number of clock counts in 32 bit timer. */
27+
#define GTM_MAX_CLOCK_COUNTS (UINT32_MAX)
28+
29+
/** Maximum period value allowed for GTM. */
30+
#define GTM_MAX_PERIOD ((uint64_t) UINT32_MAX + 1ULL)
31+
32+
/*******************************************************************************************************************//**
33+
* @addtogroup GTM
34+
* @{
35+
**********************************************************************************************************************/
36+
37+
/***********************************************************************************************************************
38+
* Typedef definitions
39+
**********************************************************************************************************************/
40+
41+
/** Optional GTM interrupt setting */
42+
typedef enum e_gtm_giws_type
43+
{
44+
GTM_GIWS_TYPE_DISABLED = 0, ///< Do not generate interrupt when timer started
45+
GTM_GIWS_TYPE_ENABLED = 1, ///< Generates interrupt when timer started
46+
} gtm_giws_type_t;
47+
48+
/** Optional GTM timer mode setting */
49+
typedef enum e_gtm_timer_mode
50+
{
51+
GTM_TIMER_MODE_INTERVAL = 0, ///< Use interval timer mode
52+
GTM_TIMER_MODE_FREERUN = 1, ///< Use free-running comparison mode
53+
} gtm_timer_mode_t;
54+
55+
/** Channel control block. DO NOT INITIALIZE. Initialization occurs when @ref timer_api_t::open is called. */
56+
typedef struct st_gtm_instance_ctrl
57+
{
58+
uint32_t open; // Whether or not channel is open
59+
const timer_cfg_t * p_cfg; // Pointer to initial configurations
60+
R_GTM0_Type * p_reg; // Base register for this channel
61+
uint32_t period; // Current timer period (counts)
62+
63+
void (* p_callback)(timer_callback_args_t * p_arg); // Pointer to callback
64+
timer_callback_args_t * p_callback_memory; // Pointer to pre-allocated callback argument
65+
void const * p_context; // Pointer to context to be passed into callback function
66+
} gtm_instance_ctrl_t;
67+
68+
/** Optional GTM extension data structure.*/
69+
typedef struct st_gtm_extended_cfg
70+
{
71+
gtm_giws_type_t generate_interrupt_when_starts; // Controls enabling/disabling of interrupt requests when start
72+
gtm_timer_mode_t gtm_mode; // Select GTM timer mode
73+
} gtm_extended_cfg_t;
74+
75+
/**********************************************************************************************************************
76+
* Exported global variables
77+
**********************************************************************************************************************/
78+
79+
/** @cond INC_HEADER_DEFS_SEC */
80+
/** Filled in Interface API structure for this Instance. */
81+
extern const timer_api_t g_timer_on_gtm;
82+
83+
/** @endcond */
84+
85+
fsp_err_t R_GTM_Close(timer_ctrl_t * const p_ctrl);
86+
fsp_err_t R_GTM_PeriodSet(timer_ctrl_t * const p_ctrl, uint32_t const period_counts);
87+
fsp_err_t R_GTM_DutyCycleSet(timer_ctrl_t * const p_ctrl, uint32_t const duty_cycle_counts, uint32_t const pin);
88+
fsp_err_t R_GTM_Reset(timer_ctrl_t * const p_ctrl);
89+
fsp_err_t R_GTM_Start(timer_ctrl_t * const p_ctrl);
90+
fsp_err_t R_GTM_Enable(timer_ctrl_t * const p_ctrl);
91+
fsp_err_t R_GTM_Disable(timer_ctrl_t * const p_ctrl);
92+
fsp_err_t R_GTM_InfoGet(timer_ctrl_t * const p_ctrl, timer_info_t * const p_info);
93+
fsp_err_t R_GTM_StatusGet(timer_ctrl_t * const p_ctrl, timer_status_t * const p_status);
94+
fsp_err_t R_GTM_Stop(timer_ctrl_t * const p_ctrl);
95+
fsp_err_t R_GTM_Open(timer_ctrl_t * const p_ctrl, timer_cfg_t const * const p_cfg);
96+
fsp_err_t R_GTM_CallbackSet(timer_ctrl_t * const p_api_ctrl,
97+
void ( * p_callback)(timer_callback_args_t * p_arg),
98+
void const * const p_context,
99+
timer_callback_args_t * const p_callback_memory);
100+
fsp_err_t R_GTM_CompareMatchSet(timer_ctrl_t * const p_ctrl,
101+
uint32_t const compare_match_value,
102+
timer_compare_match_t const match_channel);
103+
104+
/*******************************************************************************************************************//**
105+
* @} (end defgroup GTM)
106+
**********************************************************************************************************************/
107+
108+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
109+
110+
FSP_FOOTER
111+
112+
#endif /* R_GTM_H */

0 commit comments

Comments
 (0)