You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

297 rivejä
14 KiB

  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_DSPI_EDMA_H_
  9. #define _FSL_DSPI_EDMA_H_
  10. #include "fsl_dspi.h"
  11. #include "fsl_edma.h"
  12. /*!
  13. * @addtogroup dspi_edma_driver
  14. * @{
  15. */
  16. /***********************************************************************************************************************
  17. * Definitions
  18. **********************************************************************************************************************/
  19. /*! @name Driver version */
  20. /*@{*/
  21. /*! @brief DSPI EDMA driver version 2.2.4 */
  22. #define FSL_DSPI_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 2, 4))
  23. /*@}*/
  24. /*! @brief DSPI EDMA max transfer data size calculate
  25. * @param base DSPI peripheral base address.
  26. * @param width Transfer width
  27. */
  28. #define DSPI_EDMA_MAX_TRANSFER_SIZE(base, width) \
  29. ((1 == FSL_FEATURE_DSPI_HAS_SEPARATE_DMA_RX_TX_REQn(base)) ? ((width > 8U) ? 65534U : 32767U) : \
  30. ((width > 8U) ? 1022U : 511U))
  31. /*!
  32. * @brief Forward declaration of the DSPI eDMA master handle typedefs.
  33. */
  34. typedef struct _dspi_master_edma_handle dspi_master_edma_handle_t;
  35. /*!
  36. * @brief Forward declaration of the DSPI eDMA slave handle typedefs.
  37. */
  38. typedef struct _dspi_slave_edma_handle dspi_slave_edma_handle_t;
  39. /*!
  40. * @brief Completion callback function pointer type.
  41. *
  42. * @param base DSPI peripheral base address.
  43. * @param handle A pointer to the handle for the DSPI master.
  44. * @param status Success or error code describing whether the transfer completed.
  45. * @param userData An arbitrary pointer-dataSized value passed from the application.
  46. */
  47. typedef void (*dspi_master_edma_transfer_callback_t)(SPI_Type *base,
  48. dspi_master_edma_handle_t *handle,
  49. status_t status,
  50. void *userData);
  51. /*!
  52. * @brief Completion callback function pointer type.
  53. *
  54. * @param base DSPI peripheral base address.
  55. * @param handle A pointer to the handle for the DSPI slave.
  56. * @param status Success or error code describing whether the transfer completed.
  57. * @param userData An arbitrary pointer-dataSized value passed from the application.
  58. */
  59. typedef void (*dspi_slave_edma_transfer_callback_t)(SPI_Type *base,
  60. dspi_slave_edma_handle_t *handle,
  61. status_t status,
  62. void *userData);
  63. /*! @brief DSPI master eDMA transfer handle structure used for the transactional API. */
  64. struct _dspi_master_edma_handle
  65. {
  66. uint32_t bitsPerFrame; /*!< The desired number of bits per frame. */
  67. volatile uint32_t command; /*!< The desired data command. */
  68. volatile uint32_t lastCommand; /*!< The desired last data command. */
  69. uint8_t fifoSize; /*!< FIFO dataSize. */
  70. volatile bool
  71. isPcsActiveAfterTransfer; /*!< Indicates whether the PCS signal keeps active after the last frame transfer.*/
  72. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  73. volatile uint8_t state; /*!< DSPI transfer state, see @ref _dspi_transfer_state.*/
  74. uint8_t *volatile txData; /*!< Send buffer. */
  75. uint8_t *volatile rxData; /*!< Receive buffer. */
  76. volatile size_t remainingSendByteCount; /*!< A number of bytes remaining to send.*/
  77. volatile size_t remainingReceiveByteCount; /*!< A number of bytes remaining to receive.*/
  78. size_t totalByteCount; /*!< A number of transfer bytes*/
  79. uint32_t rxBuffIfNull; /*!< Used if there is not rxData for DMA purpose.*/
  80. uint32_t txBuffIfNull; /*!< Used if there is not txData for DMA purpose.*/
  81. dspi_master_edma_transfer_callback_t callback; /*!< Completion callback. */
  82. void *userData; /*!< Callback user data. */
  83. edma_handle_t *edmaRxRegToRxDataHandle; /*!<edma_handle_t handle point used for RxReg to RxData buff*/
  84. edma_handle_t *edmaTxDataToIntermediaryHandle; /*!<edma_handle_t handle point used for TxData to Intermediary*/
  85. edma_handle_t *edmaIntermediaryToTxRegHandle; /*!<edma_handle_t handle point used for Intermediary to TxReg*/
  86. edma_tcd_t dspiSoftwareTCD[2]; /*!<SoftwareTCD , internal used*/
  87. };
  88. /*! @brief DSPI slave eDMA transfer handle structure used for the transactional API.*/
  89. struct _dspi_slave_edma_handle
  90. {
  91. uint32_t bitsPerFrame; /*!< The desired number of bits per frame. */
  92. uint8_t *volatile txData; /*!< Send buffer. */
  93. uint8_t *volatile rxData; /*!< Receive buffer. */
  94. volatile size_t remainingSendByteCount; /*!< A number of bytes remaining to send.*/
  95. volatile size_t remainingReceiveByteCount; /*!< A number of bytes remaining to receive.*/
  96. size_t totalByteCount; /*!< A number of transfer bytes*/
  97. uint32_t rxBuffIfNull; /*!< Used if there is not rxData for DMA purpose.*/
  98. uint32_t txBuffIfNull; /*!< Used if there is not txData for DMA purpose.*/
  99. uint32_t txLastData; /*!< Used if there is an extra byte when 16bits per frame for DMA purpose.*/
  100. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  101. volatile uint8_t state; /*!< DSPI transfer state.*/
  102. dspi_slave_edma_transfer_callback_t callback; /*!< Completion callback. */
  103. void *userData; /*!< Callback user data. */
  104. edma_handle_t *edmaRxRegToRxDataHandle; /*!<edma_handle_t handle point used for RxReg to RxData buff*/
  105. edma_handle_t *edmaTxDataToTxRegHandle; /*!<edma_handle_t handle point used for TxData to TxReg*/
  106. };
  107. /***********************************************************************************************************************
  108. * API
  109. **********************************************************************************************************************/
  110. #if defined(__cplusplus)
  111. extern "C" {
  112. #endif /*_cplusplus*/
  113. /*! @name Transactional APIs*/
  114. /*!
  115. * @brief Initializes the DSPI master eDMA handle.
  116. *
  117. * This function initializes the DSPI eDMA handle which can be used for other DSPI transactional APIs. Usually, for a
  118. * specified DSPI instance, call this API once to get the initialized handle.
  119. *
  120. * @note DSPI eDMA has separated (RX and TX as two sources) or shared (RX and TX are the same source) DMA request
  121. * source.
  122. * - For the separated DMA request source, enable and set the RX DMAMUX source for edmaRxRegToRxDataHandle and
  123. * TX DMAMUX source for edmaIntermediaryToTxRegHandle.
  124. * - For the shared DMA request source, enable and set the RX/RX DMAMUX source for the edmaRxRegToRxDataHandle.
  125. *
  126. * @param base DSPI peripheral base address.
  127. * @param handle DSPI handle pointer to @ref _dspi_master_edma_handle.
  128. * @param callback DSPI callback.
  129. * @param userData A callback function parameter.
  130. * @param edmaRxRegToRxDataHandle edmaRxRegToRxDataHandle pointer to edma_handle_t.
  131. * @param edmaTxDataToIntermediaryHandle edmaTxDataToIntermediaryHandle pointer to edma_handle_t.
  132. * @param edmaIntermediaryToTxRegHandle edmaIntermediaryToTxRegHandle pointer to edma_handle_t.
  133. */
  134. void DSPI_MasterTransferCreateHandleEDMA(SPI_Type *base,
  135. dspi_master_edma_handle_t *handle,
  136. dspi_master_edma_transfer_callback_t callback,
  137. void *userData,
  138. edma_handle_t *edmaRxRegToRxDataHandle,
  139. edma_handle_t *edmaTxDataToIntermediaryHandle,
  140. edma_handle_t *edmaIntermediaryToTxRegHandle);
  141. /*!
  142. * @brief DSPI master transfer data using eDMA.
  143. *
  144. * This function transfers data using eDMA. This is a non-blocking function, which returns right away. When all data
  145. * is transferred, the callback function is called.
  146. *
  147. * @note The max transfer size of each transfer depends on whether the instance's Tx/Rx shares the same DMA request. If
  148. * <b>FSL_FEATURE_DSPI_HAS_SEPARATE_DMA_RX_TX_REQn(x)</b> is true, then the max transfer size is 32767 datawidth of data,
  149. * otherwise is 511.
  150. *
  151. * @param base DSPI peripheral base address.
  152. * @param handle A pointer to the @ref _dspi_master_edma_handle structure which stores the transfer state.
  153. * @param transfer A pointer to the @ref dspi_transfer_t structure.
  154. * @return status of status_t.
  155. */
  156. status_t DSPI_MasterTransferEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle, dspi_transfer_t *transfer);
  157. /*!
  158. * @brief Transfers a block of data using a eDMA method.
  159. *
  160. * This function transfers data using eDNA, the transfer mechanism is half-duplex. This is a non-blocking function,
  161. * which returns right away. When all data is transferred, the callback function is called.
  162. *
  163. * @param base DSPI base pointer
  164. * @param handle A pointer to the @ref _dspi_master_edma_handle structure which stores the transfer state.
  165. * @param xfer A pointer to the @ref dspi_half_duplex_transfer_t structure.
  166. * @return status of status_t.
  167. */
  168. status_t DSPI_MasterHalfDuplexTransferEDMA(SPI_Type *base,
  169. dspi_master_edma_handle_t *handle,
  170. dspi_half_duplex_transfer_t *xfer);
  171. /*!
  172. * @brief DSPI master aborts a transfer which is using eDMA.
  173. *
  174. * This function aborts a transfer which is using eDMA.
  175. *
  176. * @param base DSPI peripheral base address.
  177. * @param handle A pointer to the @ref _dspi_master_edma_handle structure which stores the transfer state.
  178. */
  179. void DSPI_MasterTransferAbortEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle);
  180. /*!
  181. * @brief Gets the master eDMA transfer count.
  182. *
  183. * This function gets the master eDMA transfer count.
  184. *
  185. * @param base DSPI peripheral base address.
  186. * @param handle A pointer to the @ref _dspi_master_edma_handle structure which stores the transfer state.
  187. * @param count A number of bytes transferred by the non-blocking transaction.
  188. * @return status of status_t.
  189. */
  190. status_t DSPI_MasterTransferGetCountEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle, size_t *count);
  191. /*!
  192. * @brief Initializes the DSPI slave eDMA handle.
  193. *
  194. * This function initializes the DSPI eDMA handle which can be used for other DSPI transactional APIs. Usually, for a
  195. * specified DSPI instance, call this API once to get the initialized handle.
  196. *
  197. * @note DSPI eDMA has separated (RN and TX in 2 sources) or shared (RX and TX are the same source) DMA request
  198. * source.
  199. * - For the separated DMA request source, enable and set the RX DMAMUX source for edmaRxRegToRxDataHandle and
  200. * TX DMAMUX source for edmaTxDataToTxRegHandle.
  201. * - For the shared DMA request source, enable and set the RX/RX DMAMUX source for the edmaRxRegToRxDataHandle.
  202. *
  203. * @param base DSPI peripheral base address.
  204. * @param handle DSPI handle pointer to @ref _dspi_slave_edma_handle.
  205. * @param callback DSPI callback.
  206. * @param userData A callback function parameter.
  207. * @param edmaRxRegToRxDataHandle edmaRxRegToRxDataHandle pointer to edma_handle_t.
  208. * @param edmaTxDataToTxRegHandle edmaTxDataToTxRegHandle pointer to edma_handle_t.
  209. */
  210. void DSPI_SlaveTransferCreateHandleEDMA(SPI_Type *base,
  211. dspi_slave_edma_handle_t *handle,
  212. dspi_slave_edma_transfer_callback_t callback,
  213. void *userData,
  214. edma_handle_t *edmaRxRegToRxDataHandle,
  215. edma_handle_t *edmaTxDataToTxRegHandle);
  216. /*!
  217. * @brief DSPI slave transfer data using eDMA.
  218. *
  219. * This function transfers data using eDMA. This is a non-blocking function, which returns right away. When all data
  220. * is transferred, the callback function is called.
  221. * Note that the slave eDMA transfer doesn't support transfer_size is 1 when the bitsPerFrame is greater
  222. * than eight.
  223. *
  224. * @note The max transfer size of each transfer depends on whether the instance's Tx/Rx shares the same DMA request. If
  225. * <b>FSL_FEATURE_DSPI_HAS_SEPARATE_DMA_RX_TX_REQn(x)</b> is true, then the max transfer size is 32767 datawidth of data,
  226. * otherwise is 511.
  227. *
  228. * @param base DSPI peripheral base address.
  229. * @param handle A pointer to the @ref _dspi_slave_edma_handle structure which stores the transfer state.
  230. * @param transfer A pointer to the @ref dspi_transfer_t structure.
  231. * @return status of status_t.
  232. */
  233. status_t DSPI_SlaveTransferEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle, dspi_transfer_t *transfer);
  234. /*!
  235. * @brief DSPI slave aborts a transfer which is using eDMA.
  236. *
  237. * This function aborts a transfer which is using eDMA.
  238. *
  239. * @param base DSPI peripheral base address.
  240. * @param handle A pointer to the @ref _dspi_slave_edma_handle structure which stores the transfer state.
  241. */
  242. void DSPI_SlaveTransferAbortEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle);
  243. /*!
  244. * @brief Gets the slave eDMA transfer count.
  245. *
  246. * This function gets the slave eDMA transfer count.
  247. *
  248. * @param base DSPI peripheral base address.
  249. * @param handle A pointer to the @ref _dspi_slave_edma_handle structure which stores the transfer state.
  250. * @param count A number of bytes transferred so far by the non-blocking transaction.
  251. * @return status of status_t.
  252. */
  253. status_t DSPI_SlaveTransferGetCountEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle, size_t *count);
  254. #if defined(__cplusplus)
  255. }
  256. #endif /*_cplusplus*/
  257. /*!
  258. *@}
  259. */
  260. #endif /*_FSL_DSPI_EDMA_H_*/