Skip to content

Commit ea2604a

Browse files
Phuc Phamnhutnguyenkc
authored andcommitted
hal: renesas: rza: Add ADC support for RZ/A series
Add HAL FSP ADC files for RZ/A series Signed-off-by: Phuc Pham <[email protected]> Signed-off-by: Nhut Nguyen <[email protected]>
1 parent 34eb6b8 commit ea2604a

File tree

5 files changed

+1132
-2
lines changed

5 files changed

+1132
-2
lines changed

drivers/rz/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_IOPORT
3939
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_SCIF_UART
4040
fsp/src/${SOC_SERIES_PREFIX}/r_scif_uart/r_scif_uart.c)
4141

42-
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_ADC
43-
fsp/src/${SOC_SERIES_PREFIX}/r_adc_c/r_adc_c.c)
42+
if(CONFIG_DT_HAS_RENESAS_RZ_ADC_C_ENABLED)
43+
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_ADC
44+
fsp/src/${SOC_SERIES_PREFIX}/r_adc_c/r_adc_c.c)
45+
else()
46+
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_ADC
47+
fsp/src/${SOC_SERIES_PREFIX}/r_adc/r_adc.c)
48+
endif()
4449

4550
zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_MHU
4651
fsp/src/${SOC_SERIES_PREFIX}/r_mhu_ns/r_mhu_ns.c)

drivers/rz/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ Patch List:
5858
Replace the inclusion of cr/cr_compiler.h and cr/core_cr.h with core_cr8.h
5959
Impacted files:
6060
drivers/rz/fsp/src/rzv/bsp/cmsis/Device/RENESAS/Include/R9A09G057H.h
61+
62+
* Rename adc_scan_end_isr to adc_c_scan_end_isr.
63+
Rename g_adc_on_adc to g_adc_on_adc_c with _c suffix.
64+
Impacted files:
65+
drivers/rz/fsp/src/rza/r_adc_c/r_adc_c.c
66+
drivers/rz/fsp/inc/instances/rza/r_adc_c.h
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @addtogroup ADC
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_ADC_C_H
13+
#define R_ADC_C_H
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
19+
#include <r_adc_c_cfg.h>
20+
#include "r_adc_api.h"
21+
#include "bsp_api.h"
22+
23+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
24+
FSP_HEADER
25+
26+
/***********************************************************************************************************************
27+
* Macro definitions
28+
**********************************************************************************************************************/
29+
30+
/** For ADC Scan configuration adc_channel_cfg_t::scan_mask.
31+
* Use bitwise OR to combine these masks for desired channels. */
32+
typedef enum e_adc_c_mask
33+
{
34+
ADC_C_MASK_OFF = (0U), ///< No channels selected
35+
ADC_C_MASK_CHANNEL_0 = (1U << 0U), ///< Channel 0 mask
36+
ADC_C_MASK_CHANNEL_1 = (1U << 1U), ///< Channel 1 mask
37+
} adc_c_mask_t;
38+
39+
/** ADC trigger mode select */
40+
typedef enum e_adc_c_trigger_mode
41+
{
42+
ADC_C_TRIGGER_MODE_SOFTWARE = 0U, ///< Software trigger mode
43+
ADC_C_TRIGGER_MODE_HARDWARE = 1U, ///< Hardware trigger mode
44+
} adc_c_trigger_mode_t;
45+
46+
/** ADC hardware trigger source select */
47+
typedef enum e_adc_c_active_trigger
48+
{
49+
ADC_C_ACTIVE_TRIGGER_EXTERNAL = 0U, ///< External trigger input
50+
ADC_C_ACTIVE_TRIGGER_TRGA0N = 1U, ///< Compare match with or input capture to MTU0.TGRA
51+
ADC_C_ACTIVE_TRIGGER_TRGA1N = 2U, ///< Compare match with or input capture to MTU1.TGRA
52+
ADC_C_ACTIVE_TRIGGER_TRGA2N = 3U, ///< Compare match with or input capture to MTU2.TGRA
53+
ADC_C_ACTIVE_TRIGGER_TRGA3N = 4U, ///< Compare match with or input capture to MTU3.TGRA
54+
ADC_C_ACTIVE_TRIGGER_TRGA4N = 5U, ///< Compare match with or input capture to MTU4.TGRA
55+
ADC_C_ACTIVE_TRIGGER_TRGA6N = 6U, ///< Compare match with or input capture to MTU6.TGRA
56+
ADC_C_ACTIVE_TRIGGER_TRGA7N = 7U, ///< Compare match with or input capture to MTU7.TGRA
57+
ADC_C_ACTIVE_TRIGGER_TRG0N = 8U, ///< Compare match with MTU0.TGRE
58+
ADC_C_ACTIVE_TRIGGER_TRG4AN = 9U, ///< Compare match between MTU4.TADCORA and MTU4.TCNT
59+
ADC_C_ACTIVE_TRIGGER_TRG4BN = 10U, ///< Compare match between MTU4.TADCORB and MTU4.TCNT
60+
ADC_C_ACTIVE_TRIGGER_TRG4AN_BN = 11U, ///< Compare match between MTU4.TADCORA and MTU4.TCNT, or between MTU4.TADCORB and MTU4.TCNT
61+
ADC_C_ACTIVE_TRIGGER_TRG4ABN = 12U, ///< Compare match between MTU4.TADCORA and MTU4.TCNT, and between MTU4.TADCORB and MTU4.TCNT (when interrupt skipping function 2 is in use)
62+
ADC_C_ACTIVE_TRIGGER_TRG7AN = 13U, ///< Compare match between MTU7.TADCORA and MTU7.TCNT
63+
ADC_C_ACTIVE_TRIGGER_TRG7BN = 14U, ///< Compare match between MTU7.TADCORB and MTU7.TCNT
64+
ADC_C_ACTIVE_TRIGGER_TRG7AN_BN = 15U, ///< Compare match between MTU7.TADCORA and MTU7.TCNT, or between MTU7.TADCORB and MTU7.TCNT
65+
ADC_C_ACTIVE_TRIGGER_TRG7ABN = 16U, ///< Compare match between MTU7.TADCORA and MTU7.TCNT, and between MTU7.TADCORB and MTU7.TCNT
66+
} adc_c_active_trigger_t;
67+
68+
/** valid edge of the trigger select */
69+
typedef enum e_adc_c_trigger_edge
70+
{
71+
ADC_C_TRIGGER_EDGE_FALLING = 1U, ///< Falling edge
72+
ADC_C_TRIGGER_EDGE_RISING = 2U, ///< Rising edge
73+
ADC_C_TRIGGER_EDGE_BOTH = 3U, ///< Both edges
74+
} adc_c_trigger_edge_t;
75+
76+
/** ADC trigger input mode select */
77+
typedef enum e_adc_c_input_mode
78+
{
79+
ADC_C_INPUT_MODE_AUTO = 0U, ///< Auto mode
80+
ADC_C_INPUT_MODE_STEP = 1U, ///< Step mode
81+
} adc_c_input_mode_t;
82+
83+
/** ADC operating mode select */
84+
typedef enum e_adc_c_operating_mode
85+
{
86+
ADC_C_OPERATING_MODE_SCAN = 0U, ///< Scan mode
87+
ADC_C_OPERATING_MODE_SELECT = 1U, ///< Select mode
88+
} adc_c_operating_mode_t;
89+
90+
/** ADC buffer mode select */
91+
typedef enum e_adc_c_buffer_mode
92+
{
93+
ADC_C_BUFFER_MODE_1 = 0U, ///< 1-buffer mode
94+
ADC_C_BUFFER_MODE_4 = 1U, ///< 4-buffer mode
95+
} adc_c_buffer_mode_t;
96+
97+
/** Select the number of stages of the AD external trigger pin filter. */
98+
typedef enum e_adc_c_filter_stage_setting
99+
{
100+
ADC_C_FILTER_STAGE_SETTING_DISABLE = 0U, ///< Filter is disabled.
101+
ADC_C_FILTER_STAGE_SETTING_4 = 1U, ///< 12.5 ns (80 MHz) x 4 stages
102+
ADC_C_FILTER_STAGE_SETTING_8 = 2U, ///< 12.5 ns (80 MHz) x 8 stages
103+
ADC_C_FILTER_STAGE_SETTING_12 = 3U, ///< 12.5 ns (80 MHz) x 12 stages
104+
ADC_C_FILTER_STAGE_SETTING_16 = 4U, ///< 12.5 ns (80 MHz) x 16 stages
105+
} adc_c_filter_stage_setting_t;
106+
107+
/** Enable or disable the conversion end interrupt of channel */
108+
typedef enum e_adc_c_interrupt_channel_setting
109+
{
110+
ADC_C_INTERRUPT_CHANNEL_SETTING_DISABLE = 0, ///< Interrupt output is disabled.
111+
ADC_C_INTERRUPT_CHANNEL_SETTING_ENABLE = 1, ///< Interrupt output is enabled.
112+
} adc_c_interrupt_channel_setting_t;
113+
114+
/** Extended configuration structure for ADC. */
115+
typedef struct st_adc_c_extended_cfg
116+
{
117+
adc_c_trigger_mode_t trigger_mode; ///< Trigger mode.
118+
adc_c_active_trigger_t trigger_source; ///< Hardware trigger source.
119+
adc_c_trigger_edge_t trigger_edge; ///< Valid edge of the trigger source.
120+
adc_c_input_mode_t input_mode; ///< Trigger input mode.
121+
adc_c_operating_mode_t operating_mode; ///< Operating mode.
122+
adc_c_buffer_mode_t buffer_mode; ///< Buffer mode.
123+
uint16_t sampling_time; ///< Sampling period. (6~2800)
124+
adc_c_filter_stage_setting_t external_trigger_filter; ///< AD external trigger pin filter.
125+
} adc_c_extended_cfg_t;
126+
127+
/** ADC channel(s) configuration */
128+
typedef struct st_adc_c_channel_cfg
129+
{
130+
uint32_t scan_mask; ///< Channels/bits: bit 0 is ch0; bit 1 is ch1.
131+
adc_c_interrupt_channel_setting_t interrupt_setting; ///< Interrupt setting.
132+
} adc_c_channel_cfg_t;
133+
134+
/***********************************************************************************************************************
135+
* Typedef definitions
136+
**********************************************************************************************************************/
137+
138+
/** ADC instance control block. DO NOT INITIALIZE. Initialized in @ref adc_api_t::open(). */
139+
typedef struct
140+
{
141+
R_ADC_Type * p_reg; // Base register
142+
adc_cfg_t const * p_cfg;
143+
uint32_t opened; // Boolean to verify that the Unit has been initialized
144+
uint32_t initialized; // Initialized status of ADC
145+
uint32_t scan_mask; // Scan mask used for Normal scan
146+
uint32_t scan_start;
147+
uint32_t operating_mode;
148+
uint32_t buffer_mode;
149+
150+
void (* p_callback)(adc_callback_args_t *); // Pointer to callback that is called when an adc_event_t occurs.
151+
adc_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.
152+
153+
/* Pointer to context to be passed into callback function */
154+
void const * p_context;
155+
} adc_c_instance_ctrl_t;
156+
157+
/**********************************************************************************************************************
158+
* Exported global variables
159+
**********************************************************************************************************************/
160+
161+
/** @cond INC_HEADER_DEFS_SEC */
162+
/** Interface Structure for user access */
163+
extern const adc_api_t g_adc_on_adc_c;
164+
165+
/** @endcond */
166+
167+
/***********************************************************************************************************************
168+
* Public APIs
169+
**********************************************************************************************************************/
170+
fsp_err_t R_ADC_C_Open(adc_ctrl_t * p_ctrl, adc_cfg_t const * const p_cfg);
171+
fsp_err_t R_ADC_C_ScanCfg(adc_ctrl_t * p_ctrl, void const * const p_channel_cfg);
172+
fsp_err_t R_ADC_C_InfoGet(adc_ctrl_t * p_ctrl, adc_info_t * p_adc_info);
173+
fsp_err_t R_ADC_C_ScanStart(adc_ctrl_t * p_ctrl);
174+
fsp_err_t R_ADC_C_ScanGroupStart(adc_ctrl_t * p_ctrl, adc_group_mask_t group_id);
175+
fsp_err_t R_ADC_C_ScanStop(adc_ctrl_t * p_ctrl);
176+
fsp_err_t R_ADC_C_StatusGet(adc_ctrl_t * p_ctrl, adc_status_t * p_status);
177+
fsp_err_t R_ADC_C_Read(adc_ctrl_t * p_ctrl, adc_channel_t const reg_id, uint16_t * const p_data);
178+
fsp_err_t R_ADC_C_Read32(adc_ctrl_t * p_ctrl, adc_channel_t const reg_id, uint32_t * const p_data);
179+
fsp_err_t R_ADC_C_SampleStateCountSet(adc_ctrl_t * p_ctrl, uint16_t num_states);
180+
fsp_err_t R_ADC_C_Close(adc_ctrl_t * p_ctrl);
181+
fsp_err_t R_ADC_C_OffsetSet(adc_ctrl_t * const p_ctrl, adc_channel_t const reg_id, int32_t offset);
182+
fsp_err_t R_ADC_C_Calibrate(adc_ctrl_t * const p_ctrl, void const * p_extend);
183+
fsp_err_t R_ADC_C_CallbackSet(adc_ctrl_t * const p_api_ctrl,
184+
void ( * p_callback)(adc_callback_args_t *),
185+
void const * const p_context,
186+
adc_callback_args_t * const p_callback_memory);
187+
188+
/*******************************************************************************************************************//**
189+
* @} (end defgroup ADC)
190+
**********************************************************************************************************************/
191+
192+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
193+
FSP_FOOTER
194+
195+
#endif

0 commit comments

Comments
 (0)