Skip to content

Commit 54051ed

Browse files
Hieu Nguyennhutnguyenkc
authored andcommitted
hal: renesas: rzn: Add DMA support for RZ/N series
Add HAL FSP DMAC files to support DMA for RZ/N series Signed-off-by: Hieu Nguyen <[email protected]> Signed-off-by: Nhut Nguyen <[email protected]>
1 parent f6eabee commit 54051ed

File tree

3 files changed

+1812
-0
lines changed

3 files changed

+1812
-0
lines changed
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
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 DMAC
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_DMAC_H
13+
#define R_DMAC_H
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "bsp_api.h"
19+
#include "r_dmac_cfg.h"
20+
#include "r_transfer_api.h"
21+
22+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
23+
FSP_HEADER
24+
25+
/***********************************************************************************************************************
26+
* Macro definitions
27+
**********************************************************************************************************************/
28+
29+
/** Max configurable number of transfers in TRANSFER_MODE_NORMAL. */
30+
#define DMAC_MAX_NORMAL_TRANSFER_LENGTH (0xFFFFFFFF)
31+
32+
/** Max number of transfers per block in TRANSFER_MODE_BLOCK */
33+
#define DMAC_MAX_BLOCK_TRANSFER_LENGTH (0xFFFFFFFF)
34+
35+
/***********************************************************************************************************************
36+
* Typedef definitions
37+
**********************************************************************************************************************/
38+
39+
/** Indicates the descriptor is enabled or disabled. */
40+
typedef enum e_dmac_link_valid
41+
{
42+
DMAC_LINK_VALID_DESCRIPTOR_DISABLE = 0, ///< The Descriptor is disabled.
43+
DMAC_LINK_VALID_DESCRIPTOR_ENABLE = 1, ///< The Descriptor is enabled.
44+
} dmac_link_valid_t;
45+
46+
/** Indicates that the link ends during DMA transfer of this descriptor. */
47+
typedef enum e_dmac_link_end
48+
{
49+
DMAC_LINK_END_DISABLE = 0, ///< The link continues.
50+
DMAC_LINK_END_ENABLE = 1, ///< The link ends.
51+
} dmac_link_end_t;
52+
53+
/** Masks write back execution of the dmac_link_cfg_t::link_valid. When disable, DMAC does not perform write-back operation. */
54+
typedef enum e_dmac_link_write_back
55+
{
56+
DMAC_LINK_WRITE_BACK_ENABLE = 0, ///< Set dmac_link_cfg_t::link_valid to disable after the DMA transfer ends.
57+
DMAC_LINK_WRITE_BACK_DISABLE = 1, ///< Remain dmac_link_cfg_t::link_valid after DMA transfer ends.
58+
} dmac_link_write_back_t;
59+
60+
/** When dmac_link_cfg_t::link_valid is DMAC_LINK_VALID_DESCRIPTOR_DISABLE at loading of header, specifies whether DMA transfer completion interrupt mask or not. */
61+
typedef enum e_dmac_link_interrupt_mask
62+
{
63+
DMAC_LINK_INTERRUPT_MASK_DISABLE = 0, ///< DMA transfer completion interrupt is asserted.
64+
DMAC_LINK_INTERRUPT_MASK_ENABLE = 1, ///< DMA transfer completion interrupt is masked.
65+
} dmac_link_interrupt_mask_t;
66+
67+
/** Descriptor structure used in DMAC link mode, and variables of dmac_link_cfg_t must be allocated in the memory area. */
68+
#if defined(BSP_CFG_CORE_CA55)
69+
typedef struct st_dmac_link_cfg
70+
{
71+
union
72+
{
73+
uint32_t header_u32; ///< Descriptor header
74+
struct
75+
{
76+
dmac_link_valid_t link_valid : 1; ///< The descriptor is valid or not.
77+
dmac_link_end_t link_end : 1; ///< The descriptor is end or not.
78+
dmac_link_write_back_t write_back_disable : 1; ///< Write back enable or not.
79+
dmac_link_interrupt_mask_t interrupt_mask : 1; ///< Interrupt mask is enable or not.
80+
uint32_t : 28;
81+
} header;
82+
};
83+
volatile uint32_t src_addr; ///< Source address.
84+
volatile uint32_t dest_addr; ///< Destination address.
85+
volatile uint32_t transaction_byte; ///< Transaction byte.
86+
volatile uint32_t channel_cfg; ///< Channel configuration (Set value for CHCFG_n register).
87+
volatile uint32_t channel_interval; ///< Channel interval (Set value for CHITVL register).
88+
volatile uint32_t channel_extension_cfg; ///< Channel extension configuration (Set value for CHEXT_n register).
89+
volatile uint32_t next_link_addr; ///< Next link address.
90+
} dmac_link_cfg_t;
91+
#else
92+
typedef struct st_dmac_link_cfg
93+
{
94+
union
95+
{
96+
uint32_t header_u32; ///< Descriptor header
97+
struct
98+
{
99+
dmac_link_valid_t link_valid : 1; ///< The descriptor is valid or not.
100+
dmac_link_end_t link_end : 1; ///< The descriptor is end or not.
101+
dmac_link_write_back_t write_back_disable : 1; ///< Write back enable or not.
102+
dmac_link_interrupt_mask_t interrupt_mask : 1; ///< Interrupt mask is enable or not.
103+
uint32_t : 28;
104+
} header;
105+
};
106+
void const * volatile p_src; ///< Source address.
107+
void * volatile p_dest; ///< Destination address.
108+
volatile uint32_t transaction_byte; ///< Transaction byte.
109+
volatile uint32_t channel_cfg; ///< Channel configuration (Set value for CHCFG_n register).
110+
volatile uint32_t channel_interval; ///< Channel interval (Set value for CHITVL register).
111+
volatile uint32_t channel_extension_cfg; ///< Channel extension configuration (Set value for CHEXT_n register).
112+
void * volatile p_next_link_addr; ///< Next link address.
113+
} dmac_link_cfg_t;
114+
#endif
115+
116+
/** Select the Next register set to be executed next. */
117+
typedef enum e_dmac_register_select_reverse
118+
{
119+
DMAC_REGISTER_SELECT_REVERSE_DISABLE = 0x0, ///< Use Next0 register set.
120+
DMAC_REGISTER_SELECT_REVERSE_ENABLE = 0x1, ///< Use Next1 register set.
121+
DMAC_REGISTER_SELECT_REVERSE_ENABLE_PERFORM_ACCORDINGLY = 0x3, ///< Use Next1 register set after Next0 register set transfer completed.
122+
} dmac_register_select_reverse_t;
123+
124+
/** DACK output mode. See 'DMA Transfer Request Detection Operation Setting Table' of RZ microprocessor manual. */
125+
typedef enum e_dmac_ack_mode
126+
{
127+
DMAC_ACK_MODE_LEVEL_MODE = 1, ///< Level mode.
128+
DMAC_ACK_MODE_BUS_CYCLE_MODE = 2, ///< Bus cycle mode.
129+
DMAC_ACK_MODE_MASK_DACK_OUTPUT = 4, ///< Output is masked.
130+
} dmac_ack_mode_t;
131+
132+
/** Detection method of the DMA request signal. See 'DMA Transfer Request Detection Operation Setting Table' of RZ microprocessor manual. */
133+
typedef enum e_dmac_detection
134+
{
135+
DMAC_DETECTION_FALLING_EDGE = 1, ///< Falling edge detection.
136+
DMAC_DETECTION_RISING_EDGE = 2, ///< Rising edge detection.
137+
DMAC_DETECTION_LOW_LEVEL = 5, ///< Low level detection.
138+
DMAC_DETECTION_HIGH_LEVEL = 6, ///< High level detection.
139+
} dmac_detection_t;
140+
141+
/** DMA activation request source select. See 'DMA Transfer Request Detection Operation Setting Table' of RZ microprocessor manual. */
142+
typedef enum e_dmac_request_direction
143+
{
144+
DMAC_REQUEST_DIRECTION_SOURCE_MODULE = 0, ///< Requested by a transfer source module.
145+
DMAC_REQUEST_DIRECTION_DESTINATION_MODULE = 1, ///< Requested by a transfer destination module.
146+
} dmac_request_direction_t;
147+
148+
/** DMAC channel scheduling. */
149+
typedef enum e_dmac_channel_scheduling
150+
{
151+
DMAC_CHANNEL_SCHEDULING_FIXED = 0, ///< Fixed priority mode.
152+
DMAC_CHANNEL_SCHEDULING_ROUND_ROBIN = 1, ///< Round-robin mode.
153+
} dmac_channel_scheduling_t;
154+
155+
/** DMAC mode setting. */
156+
typedef enum e_dmac_mode_select
157+
{
158+
DMAC_MODE_SELECT_REGISTER = 0, ///< Register mode.
159+
DMAC_MODE_SELECT_LINK = 1, ///< Link mode.
160+
} dmac_mode_select_t;
161+
162+
/** Control block used by driver. DO NOT INITIALIZE - this structure will be initialized in @ref transfer_api_t::open. */
163+
typedef struct st_dmac_instance_ctrl
164+
{
165+
uint32_t open; // Driver ID
166+
167+
transfer_cfg_t const * p_cfg;
168+
169+
dmac_mode_select_t dmac_mode;
170+
dmac_link_cfg_t const * p_descriptor;
171+
172+
/* Pointer to base register. */
173+
R_DMAC0_Type * p_reg;
174+
175+
void (* p_callback)(transfer_callback_args_t *); // Pointer to callback
176+
transfer_callback_args_t * p_callback_memory; // Pointer to optional callback argument memory
177+
void const * p_context; // Pointer to context to be passed into callback function
178+
} dmac_instance_ctrl_t;
179+
180+
/** DMAC transfer configuration extension. This extension is required. */
181+
typedef struct st_dmac_extended_cfg
182+
{
183+
uint8_t unit; ///< Unit number
184+
uint8_t channel; ///< Channel number
185+
IRQn_Type dmac_int_irq; ///< DMAC interrupt number
186+
uint8_t dmac_int_ipl; ///< DMAC interrupt priority
187+
uint32_t dmac_int_irq_detect_type; ///< DMAC interrupt detection type
188+
189+
/** Select which event will trigger the transfer. */
190+
elc_event_t activation_source;
191+
192+
dmac_ack_mode_t ack_mode; ///< DACK output mode
193+
dmac_detection_t detection_mode; ///< DMAC request detection method
194+
dmac_request_direction_t activation_request_source_select; ///< DMAC activation request source
195+
196+
dmac_register_select_reverse_t next_register_operation; ///< Next register operation settings
197+
198+
dmac_mode_select_t dmac_mode; ///< DMAC Mode
199+
200+
dmac_link_cfg_t const * p_descriptor; ///< The address of the descriptor (DMA Link Mode only)
201+
202+
uint16_t transfer_interval; ///< DMA transfer interval
203+
dmac_channel_scheduling_t channel_scheduling; ///< DMA channel scheduling
204+
205+
/** Callback for transfer end interrupt. */
206+
void (* p_callback)(transfer_callback_args_t * cb_data);
207+
208+
/** Placeholder for user data. Passed to the user p_callback in ::transfer_callback_args_t. */
209+
void const * p_context;
210+
} dmac_extended_cfg_t;
211+
212+
/**********************************************************************************************************************
213+
* Exported global variables
214+
**********************************************************************************************************************/
215+
216+
/** @cond INC_HEADER_DEFS_SEC */
217+
/** Filled in Interface API structure for this Instance. */
218+
extern const transfer_api_t g_transfer_on_dmac;
219+
220+
/** @endcond */
221+
222+
/***********************************************************************************************************************
223+
* Public Function Prototypes
224+
**********************************************************************************************************************/
225+
fsp_err_t R_DMAC_Open(transfer_ctrl_t * const p_ctrl, transfer_cfg_t const * const p_cfg);
226+
fsp_err_t R_DMAC_Reconfigure(transfer_ctrl_t * const p_ctrl, transfer_info_t * p_info);
227+
fsp_err_t R_DMAC_Reset(transfer_ctrl_t * const p_ctrl,
228+
void const * volatile p_src,
229+
void * volatile p_dest,
230+
uint16_t const num_transfers);
231+
fsp_err_t R_DMAC_SoftwareStart(transfer_ctrl_t * const p_ctrl, transfer_start_mode_t mode);
232+
fsp_err_t R_DMAC_SoftwareStop(transfer_ctrl_t * const p_ctrl);
233+
fsp_err_t R_DMAC_Enable(transfer_ctrl_t * const p_ctrl);
234+
fsp_err_t R_DMAC_Disable(transfer_ctrl_t * const p_ctrl);
235+
fsp_err_t R_DMAC_InfoGet(transfer_ctrl_t * const p_ctrl, transfer_properties_t * const p_info);
236+
fsp_err_t R_DMAC_Close(transfer_ctrl_t * const p_ctrl);
237+
fsp_err_t R_DMAC_Reload(transfer_ctrl_t * const p_ctrl, void const * p_src, void * p_dest,
238+
uint32_t const num_transfers);
239+
fsp_err_t R_DMAC_CallbackSet(transfer_ctrl_t * const p_ctrl,
240+
void ( * p_callback)(transfer_callback_args_t *),
241+
void const * const p_context,
242+
transfer_callback_args_t * const p_callback_memory);
243+
fsp_err_t R_DMAC_LinkDescriptorSet(transfer_ctrl_t * const p_ctrl, dmac_link_cfg_t * p_descriptor);
244+
245+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
246+
FSP_FOOTER
247+
248+
#endif
249+
250+
/*******************************************************************************************************************//**
251+
* @} (end defgroup DMAC)
252+
**********************************************************************************************************************/

0 commit comments

Comments
 (0)