r_transfer_api.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /***********************************************************************************************************************
  2. * Copyright [2020-2023] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved.
  3. *
  4. * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products
  5. * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are
  6. * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use
  7. * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property
  8. * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas
  9. * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION
  10. * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT
  11. * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES
  12. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR
  13. * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM
  14. * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION
  15. * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING,
  16. * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS,
  17. * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY
  18. * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS.
  19. **********************************************************************************************************************/
  20. /*******************************************************************************************************************//**
  21. * @ingroup RENESAS_INTERFACES
  22. * @defgroup TRANSFER_API Transfer Interface
  23. *
  24. * @brief Interface for data transfer functions.
  25. *
  26. * @section TRANSFER_API_SUMMARY Summary
  27. * The transfer interface supports background data transfer (no CPU intervention).
  28. *
  29. *
  30. * @{
  31. **********************************************************************************************************************/
  32. #ifndef R_TRANSFER_API_H
  33. #define R_TRANSFER_API_H
  34. /***********************************************************************************************************************
  35. * Includes
  36. **********************************************************************************************************************/
  37. /* Common error codes and definitions. */
  38. #include "bsp_api.h"
  39. /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
  40. FSP_HEADER
  41. /**********************************************************************************************************************
  42. * Macro definitions
  43. **********************************************************************************************************************/
  44. #define TRANSFER_SETTINGS_MODE_BITS (30U)
  45. #define TRANSFER_SETTINGS_SIZE_BITS (28U)
  46. #define TRANSFER_SETTINGS_SRC_ADDR_BITS (26U)
  47. #define TRANSFER_SETTINGS_CHAIN_MODE_BITS (22U)
  48. #define TRANSFER_SETTINGS_IRQ_BITS (21U)
  49. #define TRANSFER_SETTINGS_REPEAT_AREA_BITS (20U)
  50. #define TRANSFER_SETTINGS_DEST_ADDR_BITS (18U)
  51. /**********************************************************************************************************************
  52. * Typedef definitions
  53. **********************************************************************************************************************/
  54. /** Transfer control block. Allocate an instance specific control block to pass into the transfer API calls.
  55. */
  56. typedef void transfer_ctrl_t;
  57. #ifndef BSP_OVERRIDE_TRANSFER_MODE_T
  58. /** Transfer mode describes what will happen when a transfer request occurs. */
  59. typedef enum e_transfer_mode
  60. {
  61. /** In normal mode, each transfer request causes a transfer of @ref transfer_size_t from the source pointer to
  62. * the destination pointer. The transfer length is decremented and the source and address pointers are
  63. * updated according to @ref transfer_addr_mode_t. After the transfer length reaches 0, transfer requests
  64. * will not cause any further transfers. */
  65. TRANSFER_MODE_NORMAL = 0,
  66. /** Repeat mode is like normal mode, except that when the transfer length reaches 0, the pointer to the
  67. * repeat area and the transfer length will be reset to their initial values. If DMAC is used, the
  68. * transfer repeats only transfer_info_t::num_blocks times. After the transfer repeats
  69. * transfer_info_t::num_blocks times, transfer requests will not cause any further transfers. If DTC is
  70. * used, the transfer repeats continuously (no limit to the number of repeat transfers). */
  71. TRANSFER_MODE_REPEAT = 1,
  72. /** In block mode, each transfer request causes transfer_info_t::length transfers of @ref transfer_size_t.
  73. * After each individual transfer, the source and destination pointers are updated according to
  74. * @ref transfer_addr_mode_t. After the block transfer is complete, transfer_info_t::num_blocks is
  75. * decremented. After the transfer_info_t::num_blocks reaches 0, transfer requests will not cause any
  76. * further transfers. */
  77. TRANSFER_MODE_BLOCK = 2,
  78. /** In addition to block mode features, repeat-block mode supports a ring buffer of blocks and offsets
  79. * within a block (to split blocks into arrays of their first data, second data, etc.) */
  80. TRANSFER_MODE_REPEAT_BLOCK = 3
  81. } transfer_mode_t;
  82. #endif
  83. #ifndef BSP_OVERRIDE_TRANSFER_SIZE_T
  84. /** Transfer size specifies the size of each individual transfer.
  85. * Total transfer length = transfer_size_t * transfer_length_t
  86. */
  87. typedef enum e_transfer_size
  88. {
  89. TRANSFER_SIZE_1_BYTE = 0, ///< Each transfer transfers a 8-bit value
  90. TRANSFER_SIZE_2_BYTE = 1, ///< Each transfer transfers a 16-bit value
  91. TRANSFER_SIZE_4_BYTE = 2 ///< Each transfer transfers a 32-bit value
  92. } transfer_size_t;
  93. #endif
  94. #ifndef BSP_OVERRIDE_TRANSFER_ADDR_MODE_T
  95. /** Address mode specifies whether to modify (increment or decrement) pointer after each transfer. */
  96. typedef enum e_transfer_addr_mode
  97. {
  98. /** Address pointer remains fixed after each transfer. */
  99. TRANSFER_ADDR_MODE_FIXED = 0,
  100. /** Offset is added to the address pointer after each transfer. */
  101. TRANSFER_ADDR_MODE_OFFSET = 1,
  102. /** Address pointer is incremented by associated @ref transfer_size_t after each transfer. */
  103. TRANSFER_ADDR_MODE_INCREMENTED = 2,
  104. /** Address pointer is decremented by associated @ref transfer_size_t after each transfer. */
  105. TRANSFER_ADDR_MODE_DECREMENTED = 3
  106. } transfer_addr_mode_t;
  107. #endif
  108. #ifndef BSP_OVERRIDE_TRANSFER_REPEAT_AREA_T
  109. /** Repeat area options (source or destination). In @ref TRANSFER_MODE_REPEAT, the selected pointer returns to its
  110. * original value after transfer_info_t::length transfers. In @ref TRANSFER_MODE_BLOCK and @ref TRANSFER_MODE_REPEAT_BLOCK,
  111. * the selected pointer returns to its original value after each transfer. */
  112. typedef enum e_transfer_repeat_area
  113. {
  114. /** Destination area repeated in @ref TRANSFER_MODE_REPEAT or @ref TRANSFER_MODE_BLOCK or @ref TRANSFER_MODE_REPEAT_BLOCK. */
  115. TRANSFER_REPEAT_AREA_DESTINATION = 0,
  116. /** Source area repeated in @ref TRANSFER_MODE_REPEAT or @ref TRANSFER_MODE_BLOCK or @ref TRANSFER_MODE_REPEAT_BLOCK. */
  117. TRANSFER_REPEAT_AREA_SOURCE = 1
  118. } transfer_repeat_area_t;
  119. #endif
  120. #ifndef BSP_OVERRIDE_TRANSFER_CHAIN_MODE_T
  121. /** Chain transfer mode options.
  122. * @note Only applies for DTC. */
  123. typedef enum e_transfer_chain_mode
  124. {
  125. /** Chain mode not used. */
  126. TRANSFER_CHAIN_MODE_DISABLED = 0,
  127. /** Switch to next transfer after a single transfer from this @ref transfer_info_t. */
  128. TRANSFER_CHAIN_MODE_EACH = 2,
  129. /** Complete the entire transfer defined in this @ref transfer_info_t before chaining to next transfer. */
  130. TRANSFER_CHAIN_MODE_END = 3
  131. } transfer_chain_mode_t;
  132. #endif
  133. #ifndef BSP_OVERRIDE_TRANSFER_IRQ_T
  134. /** Interrupt options. */
  135. typedef enum e_transfer_irq
  136. {
  137. /** Interrupt occurs only after last transfer. If this transfer is chained to a subsequent transfer,
  138. * the interrupt will occur only after subsequent chained transfer(s) are complete.
  139. * @warning DTC triggers the interrupt of the activation source. Choosing TRANSFER_IRQ_END with DTC will
  140. * prevent activation source interrupts until the transfer is complete. */
  141. TRANSFER_IRQ_END = 0,
  142. /** Interrupt occurs after each transfer.
  143. * @note Not available in all HAL drivers. See HAL driver for details. */
  144. TRANSFER_IRQ_EACH = 1
  145. } transfer_irq_t;
  146. #endif
  147. /** Driver specific information. */
  148. typedef struct st_transfer_properties
  149. {
  150. uint32_t block_count_max; ///< Maximum number of blocks
  151. uint32_t block_count_remaining; ///< Number of blocks remaining
  152. uint32_t transfer_length_max; ///< Maximum number of transfers
  153. uint32_t transfer_length_remaining; ///< Number of transfers remaining
  154. } transfer_properties_t;
  155. #ifndef BSP_OVERRIDE_TRANSFER_INFO_T
  156. /** This structure specifies the properties of the transfer.
  157. * @warning When using DTC, this structure corresponds to the descriptor block registers required by the DTC.
  158. * The following components may be modified by the driver: p_src, p_dest, num_blocks, and length.
  159. * @warning When using DTC, do NOT reuse this structure to configure multiple transfers. Each transfer must
  160. * have a unique transfer_info_t.
  161. * @warning When using DTC, this structure must not be allocated in a temporary location. Any instance of this
  162. * structure must remain in scope until the transfer it is used for is closed.
  163. * @note When using DTC, consider placing instances of this structure in a protected section of memory. */
  164. typedef struct st_transfer_info
  165. {
  166. union
  167. {
  168. struct
  169. {
  170. uint32_t : 16;
  171. uint32_t : 2;
  172. /** Select what happens to destination pointer after each transfer. */
  173. transfer_addr_mode_t dest_addr_mode : 2;
  174. /** Select to repeat source or destination area, unused in @ref TRANSFER_MODE_NORMAL. */
  175. transfer_repeat_area_t repeat_area : 1;
  176. /** Select if interrupts should occur after each individual transfer or after the completion of all planned
  177. * transfers. */
  178. transfer_irq_t irq : 1;
  179. /** Select when the chain transfer ends. */
  180. transfer_chain_mode_t chain_mode : 2;
  181. uint32_t : 2;
  182. /** Select what happens to source pointer after each transfer. */
  183. transfer_addr_mode_t src_addr_mode : 2;
  184. /** Select number of bytes to transfer at once. @see transfer_info_t::length. */
  185. transfer_size_t size : 2;
  186. /** Select mode from @ref transfer_mode_t. */
  187. transfer_mode_t mode : 2;
  188. } transfer_settings_word_b;
  189. uint32_t transfer_settings_word;
  190. };
  191. void const * volatile p_src; ///< Source pointer
  192. void * volatile p_dest; ///< Destination pointer
  193. /** Number of blocks to transfer when using @ref TRANSFER_MODE_BLOCK (both DTC an DMAC) or
  194. * @ref TRANSFER_MODE_REPEAT (DMAC only) or
  195. * @ref TRANSFER_MODE_REPEAT_BLOCK (DMAC only), unused in other modes. */
  196. volatile uint16_t num_blocks;
  197. /** Length of each transfer. Range limited for @ref TRANSFER_MODE_BLOCK, @ref TRANSFER_MODE_REPEAT,
  198. * and @ref TRANSFER_MODE_REPEAT_BLOCK
  199. * see HAL driver for details. */
  200. volatile uint16_t length;
  201. } transfer_info_t;
  202. #endif
  203. /** Driver configuration set in @ref transfer_api_t::open. All elements except p_extend are required and must be
  204. * initialized. */
  205. typedef struct st_transfer_cfg
  206. {
  207. /** Pointer to transfer configuration options. If using chain transfer (DTC only), this can be a pointer to
  208. * an array of chained transfers that will be completed in order. */
  209. transfer_info_t * p_info;
  210. void const * p_extend; ///< Extension parameter for hardware specific settings.
  211. } transfer_cfg_t;
  212. /** Select whether to start single or repeated transfer with software start. */
  213. typedef enum e_transfer_start_mode
  214. {
  215. TRANSFER_START_MODE_SINGLE = 0, ///< Software start triggers single transfer.
  216. TRANSFER_START_MODE_REPEAT = 1 ///< Software start transfer continues until transfer is complete.
  217. } transfer_start_mode_t;
  218. /** Transfer functions implemented at the HAL layer will follow this API. */
  219. typedef struct st_transfer_api
  220. {
  221. /** Initial configuration.
  222. *
  223. * @param[in,out] p_ctrl Pointer to control block. Must be declared by user. Elements set here.
  224. * @param[in] p_cfg Pointer to configuration structure. All elements of this structure
  225. * must be set by user.
  226. */
  227. fsp_err_t (* open)(transfer_ctrl_t * const p_ctrl, transfer_cfg_t const * const p_cfg);
  228. /** Reconfigure the transfer.
  229. * Enable the transfer if p_info is valid.
  230. *
  231. * @param[in,out] p_ctrl Pointer to control block. Must be declared by user. Elements set here.
  232. * @param[in] p_info Pointer to a new transfer info structure.
  233. */
  234. fsp_err_t (* reconfigure)(transfer_ctrl_t * const p_ctrl, transfer_info_t * p_info);
  235. /** Reset source address pointer, destination address pointer, and/or length, keeping all other settings the same.
  236. * Enable the transfer if p_src, p_dest, and length are valid.
  237. *
  238. * @param[in] p_ctrl Control block set in @ref transfer_api_t::open call for this transfer.
  239. * @param[in] p_src Pointer to source. Set to NULL if source pointer should not change.
  240. * @param[in] p_dest Pointer to destination. Set to NULL if destination pointer should not change.
  241. * @param[in] num_transfers Transfer length in normal mode or number of blocks in block mode. In DMAC only,
  242. * resets number of repeats (initially stored in transfer_info_t::num_blocks) in
  243. * repeat mode. Not used in repeat mode for DTC.
  244. */
  245. fsp_err_t (* reset)(transfer_ctrl_t * const p_ctrl, void const * p_src, void * p_dest,
  246. uint16_t const num_transfers);
  247. /** Enable transfer. Transfers occur after the activation source event (or when
  248. * @ref transfer_api_t::softwareStart is called if no peripheral event is chosen as activation source).
  249. *
  250. * @param[in] p_ctrl Control block set in @ref transfer_api_t::open call for this transfer.
  251. */
  252. fsp_err_t (* enable)(transfer_ctrl_t * const p_ctrl);
  253. /** Disable transfer. Transfers do not occur after the activation source event (or when
  254. * @ref transfer_api_t::softwareStart is called if no peripheral event is chosen as the DMAC activation source).
  255. * @note If a transfer is in progress, it will be completed. Subsequent transfer requests do not cause a
  256. * transfer.
  257. *
  258. * @param[in] p_ctrl Control block set in @ref transfer_api_t::open call for this transfer.
  259. */
  260. fsp_err_t (* disable)(transfer_ctrl_t * const p_ctrl);
  261. /** Start transfer in software.
  262. * @warning Only works if no peripheral event is chosen as the DMAC activation source.
  263. * @note Not supported for DTC.
  264. *
  265. * @param[in] p_ctrl Control block set in @ref transfer_api_t::open call for this transfer.
  266. * @param[in] mode Select mode from @ref transfer_start_mode_t.
  267. */
  268. fsp_err_t (* softwareStart)(transfer_ctrl_t * const p_ctrl, transfer_start_mode_t mode);
  269. /** Stop transfer in software. The transfer will stop after completion of the current transfer.
  270. * @note Not supported for DTC.
  271. * @note Only applies for transfers started with TRANSFER_START_MODE_REPEAT.
  272. * @warning Only works if no peripheral event is chosen as the DMAC activation source.
  273. *
  274. * @param[in] p_ctrl Control block set in @ref transfer_api_t::open call for this transfer.
  275. */
  276. fsp_err_t (* softwareStop)(transfer_ctrl_t * const p_ctrl);
  277. /** Provides information about this transfer.
  278. *
  279. * @param[in] p_ctrl Control block set in @ref transfer_api_t::open call for this transfer.
  280. * @param[out] p_properties Driver specific information.
  281. */
  282. fsp_err_t (* infoGet)(transfer_ctrl_t * const p_ctrl, transfer_properties_t * const p_properties);
  283. /** Releases hardware lock. This allows a transfer to be reconfigured using @ref transfer_api_t::open.
  284. *
  285. * @param[in] p_ctrl Control block set in @ref transfer_api_t::open call for this transfer.
  286. */
  287. fsp_err_t (* close)(transfer_ctrl_t * const p_ctrl);
  288. /** To update next transfer information without interruption during transfer.
  289. * Allow further transfer continuation.
  290. *
  291. * @param[in] p_ctrl Control block set in @ref transfer_api_t::open call for this transfer.
  292. * @param[in] p_src Pointer to source. Set to NULL if source pointer should not change.
  293. * @param[in] p_dest Pointer to destination. Set to NULL if destination pointer should not change.
  294. * @param[in] num_transfers Transfer length in normal mode or block mode.
  295. */
  296. fsp_err_t (* reload)(transfer_ctrl_t * const p_ctrl, void const * p_src, void * p_dest,
  297. uint32_t const num_transfers);
  298. } transfer_api_t;
  299. /** This structure encompasses everything that is needed to use an instance of this interface. */
  300. typedef struct st_transfer_instance
  301. {
  302. transfer_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
  303. transfer_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
  304. transfer_api_t const * p_api; ///< Pointer to the API structure for this instance
  305. } transfer_instance_t;
  306. /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
  307. FSP_FOOTER
  308. #endif
  309. /*******************************************************************************************************************//**
  310. * @} (end defgroup TRANSFER_API)
  311. **********************************************************************************************************************/