Skip to content

Commit 6ea0e27

Browse files
nhutnguyenkcKhiemNguyenT
authored andcommitted
hal: renesas: rzt: Add Counter support for RZ/T series
Add CMTW FSP HAL driver to support Zephyr Counter driver for RZ/T2M Signed-off-by: Nhut Nguyen [email protected] Signed-off-by: Hieu Nguyen [email protected]
1 parent c0e8017 commit 6ea0e27

File tree

4 files changed

+1197
-0
lines changed

4 files changed

+1197
-0
lines changed

drivers/rz/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,6 @@ endif()
9393

9494
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_MTU
9595
fsp/src/${SOC_SERIES_PREFIX}/r_mtu3/r_mtu3.c)
96+
97+
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_CMTW
98+
fsp/src/${SOC_SERIES_PREFIX}/r_cmtw/r_cmtw.c)
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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_CMTW_H
8+
#define R_CMTW_H
9+
10+
/***********************************************************************************************************************
11+
* Includes
12+
**********************************************************************************************************************/
13+
#include "bsp_api.h"
14+
#include "r_cmtw_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 16 bit timer. */
25+
#define CMTW_MAX_CLOCK_COUNTS (UINT32_MAX)
26+
27+
/** Maximum period value allowed for CMTW. */
28+
#define CMTW_MAX_PERIOD_32BIT (UINT32_MAX + 1U)
29+
#define CMTW_MAX_PERIOD_16BIT (UINT16_MAX + 1U)
30+
31+
/*******************************************************************************************************************//**
32+
* @addtogroup CMTW
33+
* @{
34+
**********************************************************************************************************************/
35+
36+
/***********************************************************************************************************************
37+
* Typedef definitions
38+
**********************************************************************************************************************/
39+
40+
/** Trigger edge for Input capture function. */
41+
typedef enum e_cmtw_source_edge
42+
{
43+
CMTW_SOURCE_EDGE_RISING = 0U, ///< Input capture trigger on rising edge
44+
CMTW_SOURCE_EDGE_FALLING = 1U, ///< Input capture trigger on falling edge
45+
CMTW_SOURCE_EDGE_BOTH = 2U, ///< Input capture trigger on both edge
46+
} cmtw_source_edge_t;
47+
48+
/** Level of CMTW pin */
49+
typedef enum e_cmtw_output_pin
50+
{
51+
CMTW_OUTPUT_PIN_RETAIN = 0U, ///< Retain output value
52+
CMTW_OUTPUT_PIN_START_LEVEL_LOW = 1U, ///< Pin level low
53+
CMTW_OUTPUT_PIN_START_LEVEL_HIGH = 2U, ///< Pin level high
54+
} cmtw_output_pin_t;
55+
56+
/** Clear source of CMWCNT */
57+
typedef enum e_cmtw_clear_source
58+
{
59+
CMTW_CLEAR_SOURCE_COMPARE_MATCH_CMWCOR = 0U, ///< Counter is cleared by CMWCOR compare match
60+
CMTW_CLEAR_SOURCE_DISABLED = 1U, ///< Counter is not cleared
61+
CMTW_CLEAR_SOURCE_INPUT_CAPTURE_CMWICR0 = 4U, ///< Counter is cleared by CMWICR0 input capture
62+
CMTW_CLEAR_SOURCE_INPUT_CAPTURE_CMWICR1 = 5U, ///< Counter is cleared by CMWICR1 input capture
63+
CMTW_CLEAR_SOURCE_COMPARE_MATCH_CMWOCR0 = 6U, ///< Counter is cleared by CMWOCR0 output compare
64+
CMTW_CLEAR_SOURCE_COMPARE_MATCH_CMWOCR1 = 7U, ///< Counter is cleared by CMWOCR1 output compare
65+
} cmtw_clear_source_t;
66+
67+
/** Output pins, used to select */
68+
typedef enum e_cmtw_io_pin
69+
{
70+
CMTW_IO_PIN_TOC0 = 0, ///< TOC0
71+
CMTW_IO_PIN_TOC1 = 1, ///< TOC1
72+
CMTW_IO_PIN_TOC0_AND_TOC1 = 2, ///< TOC0 and TOC1
73+
} cmtw_io_pin_t;
74+
75+
typedef enum e_cmtw_output_control
76+
{
77+
CMTW_OUTPUT_CONTROL_DISABLED = 0U, ///< OutputCompare disabled
78+
CMTW_OUTPUT_CONTROL_ENABLED = 1U, ///< OutputCompare enabled
79+
} cmtw_output_control_t;
80+
81+
typedef enum e_cmtw_input_control
82+
{
83+
CMTW_INPUT_CONTROL_DISABLED = 0U, ///< InputCapture disabled
84+
CMTW_INPUT_CONTROL_ENABLED = 1U, ///< InputCapture enabled
85+
} cmtw_input_control_t;
86+
87+
/** Channel control block. DO NOT INITIALIZE. Initialization occurs when @ref timer_api_t::open is called. */
88+
typedef struct st_cmtw_instance_ctrl
89+
{
90+
uint32_t open; // Whether or not channel is open
91+
const timer_cfg_t * p_cfg; // Pointer to initial configurations
92+
R_CMTW0_Type * p_reg; // Base register for this channel
93+
uint32_t period; // Current timer period (counts)
94+
uint32_t output_channel_mask; // Output channel bitmask
95+
96+
void (* p_callback)(timer_callback_args_t *); // Pointer to callback that is called when a timer_event_t occurs.
97+
timer_callback_args_t * p_callback_memory; // Pointer to non-secure memory that can be used to pass arguments to a callback in non-secure memory.
98+
void const * p_context; // Pointer to context to be passed into callback function
99+
} cmtw_instance_ctrl_t;
100+
101+
/** Optional CMTW extension data structure.*/
102+
typedef struct st_cmtw_extended_cfg
103+
{
104+
cmtw_output_pin_t toc0; ///< Configure TOC0 pin
105+
cmtw_output_pin_t toc1; ///< Configure TOC1 pin
106+
cmtw_output_control_t toc0_control; ///< OutputCompare0 enable setting
107+
cmtw_output_control_t toc1_control; ///< OutputCompare1 enable setting
108+
cmtw_source_edge_t capture_ic0_source; ///< Event sources that trigger capture of TIC0
109+
cmtw_source_edge_t capture_ic1_source; ///< Event sources that trigger capture of TIC1
110+
cmtw_input_control_t ic0_control; ///< InputCapture0 enable setting
111+
cmtw_input_control_t ic1_control; ///< InputCapture1 enable setting
112+
cmtw_clear_source_t clear_source; ///< Counter clear source
113+
timer_variant_t counter_size; ///< Timer counter size
114+
115+
uint8_t capture_ic0_ipl; ///< InputCapture 0 interrupt priority
116+
uint8_t capture_ic1_ipl; ///< InputCapture 1 interrupt priority
117+
IRQn_Type capture_ic0_irq; ///< InputCapture 0 interrupt
118+
IRQn_Type capture_ic1_irq; ///< InputCapture 1 interrupt
119+
uint8_t compare_oc0_ipl; ///< OutputCompare 0 interrupt priority
120+
uint8_t compare_oc1_ipl; ///< OutputCompare 1 interrupt priority
121+
IRQn_Type compare_oc0_irq; ///< OutputCompare 0 interrupt
122+
IRQn_Type compare_oc1_irq; ///< OutputCompare 1 interrupt
123+
} cmtw_extended_cfg_t;
124+
125+
/**********************************************************************************************************************
126+
* Exported global variables
127+
**********************************************************************************************************************/
128+
129+
/** @cond INC_HEADER_DEFS_SEC */
130+
/** Filled in Interface API structure for this Instance. */
131+
extern const timer_api_t g_timer_on_cmtw;
132+
133+
/** @endcond */
134+
135+
fsp_err_t R_CMTW_Close(timer_ctrl_t * const p_ctrl);
136+
fsp_err_t R_CMTW_PeriodSet(timer_ctrl_t * const p_ctrl, uint32_t const period_counts);
137+
fsp_err_t R_CMTW_DutyCycleSet(timer_ctrl_t * const p_ctrl, uint32_t const duty_cycle_counts, uint32_t const pin);
138+
fsp_err_t R_CMTW_Reset(timer_ctrl_t * const p_ctrl);
139+
fsp_err_t R_CMTW_Start(timer_ctrl_t * const p_ctrl);
140+
fsp_err_t R_CMTW_Enable(timer_ctrl_t * const p_ctrl);
141+
fsp_err_t R_CMTW_Disable(timer_ctrl_t * const p_ctrl);
142+
fsp_err_t R_CMTW_InfoGet(timer_ctrl_t * const p_ctrl, timer_info_t * const p_info);
143+
fsp_err_t R_CMTW_StatusGet(timer_ctrl_t * const p_ctrl, timer_status_t * const p_status);
144+
fsp_err_t R_CMTW_Stop(timer_ctrl_t * const p_ctrl);
145+
fsp_err_t R_CMTW_Open(timer_ctrl_t * const p_ctrl, timer_cfg_t const * const p_cfg);
146+
fsp_err_t R_CMTW_OutputEnable(timer_ctrl_t * const p_ctrl, cmtw_io_pin_t pin);
147+
fsp_err_t R_CMTW_OutputDisable(timer_ctrl_t * const p_ctrl, cmtw_io_pin_t pin);
148+
fsp_err_t R_CMTW_CallbackSet(timer_ctrl_t * const p_ctrl,
149+
void ( * p_callback)(timer_callback_args_t *),
150+
void const * const p_context,
151+
timer_callback_args_t * const p_callback_memory);
152+
153+
/*******************************************************************************************************************//**
154+
* @} (end defgroup CMTW)
155+
**********************************************************************************************************************/
156+
157+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
158+
159+
FSP_FOOTER
160+
161+
#endif // R_CMTW_H

0 commit comments

Comments
 (0)