fsl_dspi_edma.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_DSPI_EDMA_H_
  35. #define _FSL_DSPI_EDMA_H_
  36. #include "fsl_dspi.h"
  37. #include "fsl_edma.h"
  38. /*!
  39. * @addtogroup dspi_edma_driver
  40. * @{
  41. */
  42. /***********************************************************************************************************************
  43. * Definitions
  44. **********************************************************************************************************************/
  45. /*!
  46. * @brief Forward declaration of the DSPI eDMA master handle typedefs.
  47. */
  48. typedef struct _dspi_master_edma_handle dspi_master_edma_handle_t;
  49. /*!
  50. * @brief Forward declaration of the DSPI eDMA slave handle typedefs.
  51. */
  52. typedef struct _dspi_slave_edma_handle dspi_slave_edma_handle_t;
  53. /*!
  54. * @brief Completion callback function pointer type.
  55. *
  56. * @param base DSPI peripheral base address.
  57. * @param handle A pointer to the handle for the DSPI master.
  58. * @param status Success or error code describing whether the transfer completed.
  59. * @param userData An arbitrary pointer-dataSized value passed from the application.
  60. */
  61. typedef void (*dspi_master_edma_transfer_callback_t)(SPI_Type *base,
  62. dspi_master_edma_handle_t *handle,
  63. status_t status,
  64. void *userData);
  65. /*!
  66. * @brief Completion callback function pointer type.
  67. *
  68. * @param base DSPI peripheral base address.
  69. * @param handle A pointer to the handle for the DSPI slave.
  70. * @param status Success or error code describing whether the transfer completed.
  71. * @param userData An arbitrary pointer-dataSized value passed from the application.
  72. */
  73. typedef void (*dspi_slave_edma_transfer_callback_t)(SPI_Type *base,
  74. dspi_slave_edma_handle_t *handle,
  75. status_t status,
  76. void *userData);
  77. /*! @brief DSPI master eDMA transfer handle structure used for the transactional API. */
  78. struct _dspi_master_edma_handle
  79. {
  80. uint32_t bitsPerFrame; /*!< The desired number of bits per frame. */
  81. volatile uint32_t command; /*!< The desired data command. */
  82. volatile uint32_t lastCommand; /*!< The desired last data command. */
  83. uint8_t fifoSize; /*!< FIFO dataSize. */
  84. volatile bool
  85. isPcsActiveAfterTransfer; /*!< Indicates whether the PCS signal keeps active after the last frame transfer.*/
  86. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  87. volatile uint8_t state; /*!< DSPI transfer state , _dspi_transfer_state.*/
  88. uint8_t *volatile txData; /*!< Send buffer. */
  89. uint8_t *volatile rxData; /*!< Receive buffer. */
  90. volatile size_t remainingSendByteCount; /*!< A number of bytes remaining to send.*/
  91. volatile size_t remainingReceiveByteCount; /*!< A number of bytes remaining to receive.*/
  92. size_t totalByteCount; /*!< A number of transfer bytes*/
  93. uint32_t rxBuffIfNull; /*!< Used if there is not rxData for DMA purpose.*/
  94. uint32_t txBuffIfNull; /*!< Used if there is not txData for DMA purpose.*/
  95. dspi_master_edma_transfer_callback_t callback; /*!< Completion callback. */
  96. void *userData; /*!< Callback user data. */
  97. edma_handle_t *edmaRxRegToRxDataHandle; /*!<edma_handle_t handle point used for RxReg to RxData buff*/
  98. edma_handle_t *edmaTxDataToIntermediaryHandle; /*!<edma_handle_t handle point used for TxData to Intermediary*/
  99. edma_handle_t *edmaIntermediaryToTxRegHandle; /*!<edma_handle_t handle point used for Intermediary to TxReg*/
  100. edma_tcd_t dspiSoftwareTCD[2]; /*!<SoftwareTCD , internal used*/
  101. };
  102. /*! @brief DSPI slave eDMA transfer handle structure used for the transactional API.*/
  103. struct _dspi_slave_edma_handle
  104. {
  105. uint32_t bitsPerFrame; /*!< The desired number of bits per frame. */
  106. uint8_t *volatile txData; /*!< Send buffer. */
  107. uint8_t *volatile rxData; /*!< Receive buffer. */
  108. volatile size_t remainingSendByteCount; /*!< A number of bytes remaining to send.*/
  109. volatile size_t remainingReceiveByteCount; /*!< A number of bytes remaining to receive.*/
  110. size_t totalByteCount; /*!< A number of transfer bytes*/
  111. uint32_t rxBuffIfNull; /*!< Used if there is not rxData for DMA purpose.*/
  112. uint32_t txBuffIfNull; /*!< Used if there is not txData for DMA purpose.*/
  113. uint32_t txLastData; /*!< Used if there is an extra byte when 16bits per frame for DMA purpose.*/
  114. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  115. volatile uint8_t state; /*!< DSPI transfer state.*/
  116. dspi_slave_edma_transfer_callback_t callback; /*!< Completion callback. */
  117. void *userData; /*!< Callback user data. */
  118. edma_handle_t *edmaRxRegToRxDataHandle; /*!<edma_handle_t handle point used for RxReg to RxData buff*/
  119. edma_handle_t *edmaTxDataToTxRegHandle; /*!<edma_handle_t handle point used for TxData to TxReg*/
  120. };
  121. /***********************************************************************************************************************
  122. * API
  123. **********************************************************************************************************************/
  124. #if defined(__cplusplus)
  125. extern "C" {
  126. #endif /*_cplusplus*/
  127. /*Transactional APIs*/
  128. /*!
  129. * @brief Initializes the DSPI master eDMA handle.
  130. *
  131. * This function initializes the DSPI eDMA handle which can be used for other DSPI transactional APIs. Usually, for a
  132. * specified DSPI instance, call this API once to get the initialized handle.
  133. *
  134. * Note that DSPI eDMA has separated (RX and TX as two sources) or shared (RX and TX are the same source) DMA request
  135. * source.
  136. * (1) For the separated DMA request source, enable and set the RX DMAMUX source for edmaRxRegToRxDataHandle and
  137. * TX DMAMUX source for edmaIntermediaryToTxRegHandle.
  138. * (2) For the shared DMA request source, enable and set the RX/RX DMAMUX source for the edmaRxRegToRxDataHandle.
  139. *
  140. * @param base DSPI peripheral base address.
  141. * @param handle DSPI handle pointer to dspi_master_edma_handle_t.
  142. * @param callback DSPI callback.
  143. * @param userData A callback function parameter.
  144. * @param edmaRxRegToRxDataHandle edmaRxRegToRxDataHandle pointer to edma_handle_t.
  145. * @param edmaTxDataToIntermediaryHandle edmaTxDataToIntermediaryHandle pointer to edma_handle_t.
  146. * @param edmaIntermediaryToTxRegHandle edmaIntermediaryToTxRegHandle pointer to edma_handle_t.
  147. */
  148. void DSPI_MasterTransferCreateHandleEDMA(SPI_Type *base,
  149. dspi_master_edma_handle_t *handle,
  150. dspi_master_edma_transfer_callback_t callback,
  151. void *userData,
  152. edma_handle_t *edmaRxRegToRxDataHandle,
  153. edma_handle_t *edmaTxDataToIntermediaryHandle,
  154. edma_handle_t *edmaIntermediaryToTxRegHandle);
  155. /*!
  156. * @brief DSPI master transfer data using eDMA.
  157. *
  158. * This function transfers data using eDMA. This is a non-blocking function, which returns right away. When all data
  159. * is transferred, the callback function is called.
  160. *
  161. * @param base DSPI peripheral base address.
  162. * @param handle A pointer to the dspi_master_edma_handle_t structure which stores the transfer state.
  163. * @param transfer A pointer to the dspi_transfer_t structure.
  164. * @return status of status_t.
  165. */
  166. status_t DSPI_MasterTransferEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle, dspi_transfer_t *transfer);
  167. /*!
  168. * @brief Transfers a block of data using a eDMA method.
  169. *
  170. * This function transfers data using eDNA, the transfer mechanism is half-duplex. This is a non-blocking function,
  171. * which returns right away. When all data is transferred, the callback function is called.
  172. *
  173. * @param base DSPI base pointer
  174. * @param handle A pointer to the dspi_master_edma_handle_t structure which stores the transfer state.
  175. * @param transfer A pointer to the dspi_half_duplex_transfer_t structure.
  176. * @return status of status_t.
  177. */
  178. status_t DSPI_MasterHalfDuplexTransferEDMA(SPI_Type *base,
  179. dspi_master_edma_handle_t *handle,
  180. dspi_half_duplex_transfer_t *xfer);
  181. /*!
  182. * @brief DSPI master aborts a transfer which is using eDMA.
  183. *
  184. * This function aborts a transfer which is using eDMA.
  185. *
  186. * @param base DSPI peripheral base address.
  187. * @param handle A pointer to the dspi_master_edma_handle_t structure which stores the transfer state.
  188. */
  189. void DSPI_MasterTransferAbortEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle);
  190. /*!
  191. * @brief Gets the master eDMA transfer count.
  192. *
  193. * This function gets the master eDMA transfer count.
  194. *
  195. * @param base DSPI peripheral base address.
  196. * @param handle A pointer to the dspi_master_edma_handle_t structure which stores the transfer state.
  197. * @param count A number of bytes transferred by the non-blocking transaction.
  198. * @return status of status_t.
  199. */
  200. status_t DSPI_MasterTransferGetCountEDMA(SPI_Type *base, dspi_master_edma_handle_t *handle, size_t *count);
  201. /*!
  202. * @brief Initializes the DSPI slave eDMA handle.
  203. *
  204. * This function initializes the DSPI eDMA handle which can be used for other DSPI transactional APIs. Usually, for a
  205. * specified DSPI instance, call this API once to get the initialized handle.
  206. *
  207. * Note that DSPI eDMA has separated (RN and TX in 2 sources) or shared (RX and TX are the same source) DMA request
  208. * source.
  209. * (1)For the separated DMA request source, enable and set the RX DMAMUX source for edmaRxRegToRxDataHandle and
  210. * TX DMAMUX source for edmaTxDataToTxRegHandle.
  211. * (2)For the shared DMA request source, enable and set the RX/RX DMAMUX source for the edmaRxRegToRxDataHandle.
  212. *
  213. * @param base DSPI peripheral base address.
  214. * @param handle DSPI handle pointer to dspi_slave_edma_handle_t.
  215. * @param callback DSPI callback.
  216. * @param userData A callback function parameter.
  217. * @param edmaRxRegToRxDataHandle edmaRxRegToRxDataHandle pointer to edma_handle_t.
  218. * @param edmaTxDataToTxRegHandle edmaTxDataToTxRegHandle pointer to edma_handle_t.
  219. */
  220. void DSPI_SlaveTransferCreateHandleEDMA(SPI_Type *base,
  221. dspi_slave_edma_handle_t *handle,
  222. dspi_slave_edma_transfer_callback_t callback,
  223. void *userData,
  224. edma_handle_t *edmaRxRegToRxDataHandle,
  225. edma_handle_t *edmaTxDataToTxRegHandle);
  226. /*!
  227. * @brief DSPI slave transfer data using eDMA.
  228. *
  229. * This function transfers data using eDMA. This is a non-blocking function, which returns right away. When all data
  230. * is transferred, the callback function is called.
  231. * Note that the slave eDMA transfer doesn't support transfer_size is 1 when the bitsPerFrame is greater
  232. * than eight.
  233. * @param base DSPI peripheral base address.
  234. * @param handle A pointer to the dspi_slave_edma_handle_t structure which stores the transfer state.
  235. * @param transfer A pointer to the dspi_transfer_t structure.
  236. * @return status of status_t.
  237. */
  238. status_t DSPI_SlaveTransferEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle, dspi_transfer_t *transfer);
  239. /*!
  240. * @brief DSPI slave aborts a transfer which is using eDMA.
  241. *
  242. * This function aborts a transfer which is using eDMA.
  243. *
  244. * @param base DSPI peripheral base address.
  245. * @param handle A pointer to the dspi_slave_edma_handle_t structure which stores the transfer state.
  246. */
  247. void DSPI_SlaveTransferAbortEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle);
  248. /*!
  249. * @brief Gets the slave eDMA transfer count.
  250. *
  251. * This function gets the slave eDMA transfer count.
  252. *
  253. * @param base DSPI peripheral base address.
  254. * @param handle A pointer to the dspi_slave_edma_handle_t structure which stores the transfer state.
  255. * @param count A number of bytes transferred so far by the non-blocking transaction.
  256. * @return status of status_t.
  257. */
  258. status_t DSPI_SlaveTransferGetCountEDMA(SPI_Type *base, dspi_slave_edma_handle_t *handle, size_t *count);
  259. #if defined(__cplusplus)
  260. }
  261. #endif /*_cplusplus*/
  262. /*!
  263. *@}
  264. */
  265. #endif /*_FSL_DSPI_EDMA_H_*/