|
| 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_transfer_api.h" |
| 20 | +#include "r_dmac_cfg.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 | +typedef transfer_callback_args_t dmac_callback_args_t; |
| 40 | + |
| 41 | +/** Events that can trigger a callback function. */ |
| 42 | +typedef enum e_dmac_event |
| 43 | +{ |
| 44 | + DMAC_EVENT_TRANSFER_END = 0, ///< DMA transfer has completed. |
| 45 | + DMAC_EVENT_TRANSFER_ERROR = 1, ///< A bus error occurred during DMA transfer. |
| 46 | +} dmac_event_t; |
| 47 | + |
| 48 | +/** Transfer size specifies the size of each individual transfer. */ |
| 49 | +typedef enum e_dmac_transfer_size |
| 50 | +{ |
| 51 | + DMAC_TRANSFER_SIZE_1_BYTE = 0, ///< Each transfer transfers a 8-bit value. |
| 52 | + DMAC_TRANSFER_SIZE_2_BYTE = 1, ///< Each transfer transfers a 16-bit value. |
| 53 | + DMAC_TRANSFER_SIZE_4_BYTE = 2, ///< Each transfer transfers a 32-bit value. |
| 54 | + DMAC_TRANSFER_SIZE_8_BYTE = 3, ///< Each transfer transfers a 64-bit value. |
| 55 | + DMAC_TRANSFER_SIZE_16_BYTE = 4, ///< Each transfer transfers a 128-bit value. |
| 56 | + DMAC_TRANSFER_SIZE_32_BYTE = 5, ///< Each transfer transfers a 256-bit value. |
| 57 | + DMAC_TRANSFER_SIZE_64_BYTE = 6, ///< Each transfer transfers a 512-bit value. |
| 58 | + DMAC_TRANSFER_SIZE_128_BYTE = 7, ///< Each transfer transfers a 1024-bit value. |
| 59 | +} dmac_transfer_size_t; |
| 60 | + |
| 61 | +/** DACK output mode. See RZ/T2M hardware manual Table 14.19 DMA Transfer Request Detection Operation Setting Table. */ |
| 62 | +typedef enum e_dmac_ack_mode |
| 63 | +{ |
| 64 | + DMAC_ACK_MODE_LEVEL_MODE = 1, ///< Level mode. |
| 65 | + DMAC_ACK_MODE_BUS_CYCLE_MODE = 2, ///< Bus cycle mode. |
| 66 | + DMAC_ACK_MODE_MASK_DACK_OUTPUT = 4, ///< Output is masked. |
| 67 | +} dmac_ack_mode_t; |
| 68 | + |
| 69 | +/** Detection method of the DMA request signal. See RZ/T2M hardware manual Table 14.19 DMA Transfer Request Detection Operation Setting Table. */ |
| 70 | +typedef enum e_dmac_detection |
| 71 | +{ |
| 72 | + DMAC_DETECTION_FALLING_EDGE = 1, ///< Falling edge detection. |
| 73 | + DMAC_DETECTION_RISING_EDGE = 2, ///< Rising edge detection. |
| 74 | + DMAC_DETECTION_LOW_LEVEL = 5, ///< Low level detection. |
| 75 | + DMAC_DETECTION_HIGH_LEVEL = 6, ///< High level detection. |
| 76 | +} dmac_detection_t; |
| 77 | + |
| 78 | +/** DMA activation request source select. See RZ/T2M hardware manual Table 14.19 DMA Transfer Request Detection Operation Setting Table. */ |
| 79 | +typedef enum e_dmac_request_direction |
| 80 | +{ |
| 81 | + DMAC_REQUEST_DIRECTION_SOURCE_MODULE = 0, ///< Requested by a transfer source module. |
| 82 | + DMAC_REQUEST_DIRECTION_DESTINATION_MODULE = 1, ///< Requested by a transfer destination module. |
| 83 | +} dmac_request_direction_t; |
| 84 | + |
| 85 | +/** Select the Next register set to be executed next. */ |
| 86 | +typedef enum e_dmac_continuous_setting |
| 87 | +{ |
| 88 | + DMAC_CONTINUOUS_SETTING_TRANSFER_NEXT0_ONCE = 0x0, ///< Transfer only once using the Next0 register set. |
| 89 | + DMAC_CONTINUOUS_SETTING_TRANSFER_NEXT0_NEXT1_ALTERNATELY = 0x3, ///< Transfers are performed alternately with the Next0 register set and the Next1 register set. |
| 90 | +} dmac_continuous_setting_t; |
| 91 | + |
| 92 | +/** Register set settings. */ |
| 93 | +typedef struct st_dmac_next1_register_setting |
| 94 | +{ |
| 95 | + void const * p_src; ///< Source pointer. |
| 96 | + void * p_dest; ///< Destination pointer. |
| 97 | + uint32_t length; ///< Transfer Byte. |
| 98 | +} dmac_next1_register_setting_t; |
| 99 | + |
| 100 | +/** DMAC channel scheduling. */ |
| 101 | +typedef enum e_dmac_channel_scheduling |
| 102 | +{ |
| 103 | + DMAC_CHANNEL_SCHEDULING_FIXED = 0, ///< Fixed priority mode. |
| 104 | + DMAC_CHANNEL_SCHEDULING_ROUND_ROBIN = 1, ///< Round-robin mode. |
| 105 | +} dmac_channel_scheduling_t; |
| 106 | + |
| 107 | +/** DMAC mode setting. */ |
| 108 | +typedef enum e_dmac_mode_select |
| 109 | +{ |
| 110 | + DMAC_MODE_SELECT_REGISTER = 0, ///< Register mode. |
| 111 | + DMAC_MODE_SELECT_LINK = 1, ///< Link mode. |
| 112 | +} dmac_mode_select_t; |
| 113 | + |
| 114 | +/** Indicates the descriptor is enabled or disabled. */ |
| 115 | +typedef enum e_dmac_link_valid |
| 116 | +{ |
| 117 | + DMAC_LINK_VALID_DESCRIPTOR_DISABLE = 0, ///< The Descriptor is disabled. |
| 118 | + DMAC_LINK_VALID_DESCRIPTOR_ENABLE = 1, ///< The Descriptor is enabled. |
| 119 | +} dmac_link_valid_t; |
| 120 | + |
| 121 | +/** Indicates that the link ends during DMA transfer of this descriptor. */ |
| 122 | +typedef enum e_dmac_link_end |
| 123 | +{ |
| 124 | + DMAC_LINK_END_DISABLE = 0, ///< The link continues. |
| 125 | + DMAC_LINK_END_ENABLE = 1, ///< The link ends. |
| 126 | +} dmac_link_end_t; |
| 127 | + |
| 128 | +/** Masks write back execution of the dmac_link_cfg_t::link_valid. When disable, DMAC does not perform write-back operation. */ |
| 129 | +typedef enum e_dmac_link_write_back |
| 130 | +{ |
| 131 | + DMAC_LINK_WRITE_BACK_ENABLE = 0, ///< Set dmac_link_cfg_t::link_valid to disable after the DMA transfer ends. |
| 132 | + DMAC_LINK_WRITE_BACK_DISABLE = 1, ///< Remain dmac_link_cfg_t::link_valid after DMA transfer ends. |
| 133 | +} dmac_link_write_back_t; |
| 134 | + |
| 135 | +/** 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. */ |
| 136 | +typedef enum e_dmac_link_interrupt_mask |
| 137 | +{ |
| 138 | + DMAC_LINK_INTERRUPT_MASK_DISABLE = 0, ///< DMA transfer completion interrupt is asserted. |
| 139 | + DMAC_LINK_INTERRUPT_MASK_ENABLE = 1, ///< DMA transfer completion interrupt is masked. |
| 140 | +} dmac_link_interrupt_mask_t; |
| 141 | + |
| 142 | +/** Descriptor structure used in DMAC link mode, and variables of dmac_link_cfg_t must be allocated in the memory area. */ |
| 143 | +#if (BSP_FEATURE_DMAC_64BIT_SYSTEM == 1) |
| 144 | +typedef struct st_dmac_link_cfg |
| 145 | +{ |
| 146 | + union |
| 147 | + { |
| 148 | + uint32_t header_u32; ///< Descriptor header |
| 149 | + struct |
| 150 | + { |
| 151 | + dmac_link_valid_t link_valid : 1; ///< The descriptor is valid or not. |
| 152 | + dmac_link_end_t link_end : 1; ///< The descriptor is end or not. |
| 153 | + dmac_link_write_back_t write_back_disable : 1; ///< Write back enable or not. |
| 154 | + dmac_link_interrupt_mask_t interrupt_mask : 1; ///< Interrupt mask is enable or not. |
| 155 | + uint32_t : 28; |
| 156 | + } header; |
| 157 | + }; |
| 158 | + volatile uint32_t src_addr; ///< Source address. |
| 159 | + volatile uint32_t dest_addr; ///< Destination address. |
| 160 | + volatile uint32_t transaction_byte; ///< Transaction byte. |
| 161 | + volatile uint32_t channel_cfg; ///< Channel configuration (Set value for CHCFG_n register). |
| 162 | + volatile uint32_t channel_interval; ///< Channel interval (Set value for CHITVL register). |
| 163 | + volatile uint32_t channel_extension_cfg; ///< Channel extension configuration (Set value for CHEXT_n register). |
| 164 | + volatile uint32_t next_link_addr; ///< Next link address. |
| 165 | +} dmac_link_cfg_t; |
| 166 | +#else |
| 167 | +typedef struct st_dmac_link_cfg |
| 168 | +{ |
| 169 | + union |
| 170 | + { |
| 171 | + uint32_t header_u32; ///< Descriptor header |
| 172 | + struct |
| 173 | + { |
| 174 | + dmac_link_valid_t link_valid : 1; ///< The descriptor is valid or not. |
| 175 | + dmac_link_end_t link_end : 1; ///< The descriptor is end or not. |
| 176 | + dmac_link_write_back_t write_back_disable : 1; ///< Write back enable or not. |
| 177 | + dmac_link_interrupt_mask_t interrupt_mask : 1; ///< Interrupt mask is enable or not. |
| 178 | + uint32_t : 28; |
| 179 | + } header; |
| 180 | + }; |
| 181 | + void const * volatile p_src; ///< Source address. |
| 182 | + void * volatile p_dest; ///< Destination address. |
| 183 | + volatile uint32_t transaction_byte; ///< Transaction byte. |
| 184 | + volatile uint32_t channel_cfg; ///< Channel configuration (Set value for CHCFG_n register). |
| 185 | + volatile uint32_t channel_interval; ///< Channel interval (Set value for CHITVL register). |
| 186 | + volatile uint32_t channel_extension_cfg; ///< Channel extension configuration (Set value for CHEXT_n register). |
| 187 | + void * volatile p_next_link_addr; ///< Next link address. |
| 188 | +} dmac_link_cfg_t; |
| 189 | +#endif |
| 190 | + |
| 191 | +/** Control block used by driver. DO NOT INITIALIZE - this structure will be initialized in @ref transfer_api_t::open. */ |
| 192 | +typedef struct st_dmac_instance_ctrl |
| 193 | +{ |
| 194 | + uint32_t open; // Driver ID |
| 195 | + |
| 196 | + transfer_cfg_t const * p_cfg; |
| 197 | + |
| 198 | + dmac_link_cfg_t const * p_descriptor; |
| 199 | + |
| 200 | + /* Pointer to base register. */ |
| 201 | + R_DMA0_Type * p_reg; |
| 202 | + |
| 203 | + void (* p_callback)(dmac_callback_args_t *); // Pointer to callback |
| 204 | + dmac_callback_args_t * p_callback_memory; // Pointer to optional callback argument memory |
| 205 | + void const * p_context; |
| 206 | +} dmac_instance_ctrl_t; |
| 207 | + |
| 208 | +/** DMAC transfer configuration extension. This extension is required. */ |
| 209 | +typedef struct st_dmac_extended_cfg |
| 210 | +{ |
| 211 | + uint8_t channel; ///< Channel number |
| 212 | + IRQn_Type dmac_int_irq; ///< DMAC interrupt number |
| 213 | + uint8_t dmac_int_ipl; ///< DMAC interrupt priority |
| 214 | + uint32_t dmac_int_irq_detect_type; ///< DMAC interrupt detection type |
| 215 | + |
| 216 | + /** Select which event will trigger the transfer. */ |
| 217 | + dmac_trigger_event_t activation_source; |
| 218 | + |
| 219 | + /** The interrupt ID number that corresponds to the Activation Source. */ |
| 220 | + IRQn_Type activation_irq_number; |
| 221 | + |
| 222 | + dmac_ack_mode_t ack_mode; ///< DACK output mode |
| 223 | + dmac_detection_t detection_mode; ///< DMAC request detection method |
| 224 | + dmac_request_direction_t activation_request_source_select; ///< DMAC activation request source |
| 225 | + |
| 226 | + dmac_mode_select_t dmac_mode; ///< DMAC Mode |
| 227 | + dmac_link_cfg_t const * p_descriptor; ///< The address of the descriptor (DMA Link Mode only) |
| 228 | + dmac_continuous_setting_t continuous_setting; ///< Next register operation settings |
| 229 | + uint16_t transfer_interval; ///< DMA transfer interval |
| 230 | + dmac_channel_scheduling_t channel_scheduling; ///< DMA channel scheduling |
| 231 | + |
| 232 | + /** Callback for transfer end interrupt. */ |
| 233 | + void (* p_callback)(dmac_callback_args_t * cb_data); |
| 234 | + dmac_callback_args_t * p_callback_memory; |
| 235 | + |
| 236 | + /** Placeholder for user data. Passed to the user p_callback in ::transfer_callback_args_t. */ |
| 237 | + void const * p_context; |
| 238 | +} dmac_extended_cfg_t; |
| 239 | + |
| 240 | +/** DMAC transfer configuration extension. This extension is required. */ |
| 241 | +typedef struct st_dmac_extended_info |
| 242 | +{ |
| 243 | + /** Select number of source bytes to transfer at once. */ |
| 244 | + dmac_transfer_size_t src_size; |
| 245 | + |
| 246 | + /** Select number of destnination bytes to transfer at once. */ |
| 247 | + dmac_transfer_size_t dest_size; |
| 248 | + |
| 249 | + /** Next1 Register set settings */ |
| 250 | + dmac_next1_register_setting_t * p_next1_register_setting; |
| 251 | +} dmac_extended_info_t; |
| 252 | + |
| 253 | +/********************************************************************************************************************** |
| 254 | + * Exported global variables |
| 255 | + **********************************************************************************************************************/ |
| 256 | + |
| 257 | +/** @cond INC_HEADER_DEFS_SEC */ |
| 258 | +/** Filled in Interface API structure for this Instance. */ |
| 259 | +extern const transfer_api_t g_transfer_on_dmac; |
| 260 | + |
| 261 | +/** @endcond */ |
| 262 | + |
| 263 | +/*********************************************************************************************************************** |
| 264 | + * Public Function Prototypes |
| 265 | + **********************************************************************************************************************/ |
| 266 | +fsp_err_t R_DMAC_Open(transfer_ctrl_t * const p_api_ctrl, transfer_cfg_t const * const p_cfg); |
| 267 | +fsp_err_t R_DMAC_Reconfigure(transfer_ctrl_t * const p_api_ctrl, transfer_info_t * p_info); |
| 268 | +fsp_err_t R_DMAC_Reset(transfer_ctrl_t * const p_api_ctrl, |
| 269 | + void const * volatile p_src, |
| 270 | + void * volatile p_dest, |
| 271 | + uint16_t const num_transfers); |
| 272 | +fsp_err_t R_DMAC_SoftwareStart(transfer_ctrl_t * const p_api_ctrl, transfer_start_mode_t mode); |
| 273 | +fsp_err_t R_DMAC_SoftwareStop(transfer_ctrl_t * const p_api_ctrl); |
| 274 | +fsp_err_t R_DMAC_Enable(transfer_ctrl_t * const p_api_ctrl); |
| 275 | +fsp_err_t R_DMAC_Disable(transfer_ctrl_t * const p_api_ctrl); |
| 276 | +fsp_err_t R_DMAC_InfoGet(transfer_ctrl_t * const p_api_ctrl, transfer_properties_t * const p_info); |
| 277 | +fsp_err_t R_DMAC_Close(transfer_ctrl_t * const p_api_ctrl); |
| 278 | +fsp_err_t R_DMAC_Reload(transfer_ctrl_t * const p_api_ctrl, |
| 279 | + void const * p_src, |
| 280 | + void * p_dest, |
| 281 | + uint32_t const num_transfers); |
| 282 | +fsp_err_t R_DMAC_CallbackSet(transfer_ctrl_t * const p_api_ctrl, |
| 283 | + void ( * p_callback)(dmac_callback_args_t *), |
| 284 | + void const * const p_context, |
| 285 | + dmac_callback_args_t * const p_callback_memory); |
| 286 | +fsp_err_t R_DMAC_LinkDescriptorSet(transfer_ctrl_t * const p_api_ctrl, dmac_link_cfg_t * p_descriptor); |
| 287 | + |
| 288 | +/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ |
| 289 | +FSP_FOOTER |
| 290 | + |
| 291 | +#endif |
| 292 | + |
| 293 | +/*******************************************************************************************************************//** |
| 294 | + * @} (end defgroup DMAC) |
| 295 | + **********************************************************************************************************************/ |
0 commit comments