fsl_flexio_spi_edma.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_FLEXIO_SPI_EDMA_H_
  31. #define _FSL_FLEXIO_SPI_EDMA_H_
  32. #include "fsl_flexio_spi.h"
  33. #include "fsl_edma.h"
  34. /*!
  35. * @addtogroup flexio_edma_spi
  36. * @{
  37. */
  38. /*******************************************************************************
  39. * Definitions
  40. ******************************************************************************/
  41. /*! @brief typedef for flexio_spi_master_edma_handle_t in advance. */
  42. typedef struct _flexio_spi_master_edma_handle flexio_spi_master_edma_handle_t;
  43. /*! @brief Slave handle is the same with master handle. */
  44. typedef flexio_spi_master_edma_handle_t flexio_spi_slave_edma_handle_t;
  45. /*! @brief FlexIO SPI master callback for finished transmit */
  46. typedef void (*flexio_spi_master_edma_transfer_callback_t)(FLEXIO_SPI_Type *base,
  47. flexio_spi_master_edma_handle_t *handle,
  48. status_t status,
  49. void *userData);
  50. /*! @brief FlexIO SPI slave callback for finished transmit */
  51. typedef void (*flexio_spi_slave_edma_transfer_callback_t)(FLEXIO_SPI_Type *base,
  52. flexio_spi_slave_edma_handle_t *handle,
  53. status_t status,
  54. void *userData);
  55. /*! @brief FlexIO SPI eDMA transfer handle, users should not touch the content of the handle.*/
  56. struct _flexio_spi_master_edma_handle
  57. {
  58. size_t transferSize; /*!< Total bytes to be transferred. */
  59. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  60. bool txInProgress; /*!< Send transfer in progress */
  61. bool rxInProgress; /*!< Receive transfer in progress */
  62. edma_handle_t *txHandle; /*!< DMA handler for SPI send */
  63. edma_handle_t *rxHandle; /*!< DMA handler for SPI receive */
  64. flexio_spi_master_edma_transfer_callback_t callback; /*!< Callback for SPI DMA transfer */
  65. void *userData; /*!< User Data for SPI DMA callback */
  66. };
  67. /*******************************************************************************
  68. * APIs
  69. ******************************************************************************/
  70. #if defined(__cplusplus)
  71. extern "C" {
  72. #endif
  73. /*!
  74. * @name eDMA Transactional
  75. * @{
  76. */
  77. /*!
  78. * @brief Initializes the FlexIO SPI master eDMA handle.
  79. *
  80. * This function initializes the FlexIO SPI master eDMA handle which can be used for other FlexIO SPI master transactional
  81. * APIs.
  82. * For a specified FlexIO SPI instance, call this API once to get the initialized handle.
  83. *
  84. * @param base Pointer to FLEXIO_SPI_Type structure.
  85. * @param handle Pointer to flexio_spi_master_edma_handle_t structure to store the transfer state.
  86. * @param callback SPI callback, NULL means no callback.
  87. * @param userData callback function parameter.
  88. * @param txHandle User requested eDMA handle for FlexIO SPI RX eDMA transfer.
  89. * @param rxHandle User requested eDMA handle for FlexIO SPI TX eDMA transfer.
  90. * @retval kStatus_Success Successfully create the handle.
  91. * @retval kStatus_OutOfRange The FlexIO SPI eDMA type/handle table out of range.
  92. */
  93. status_t FLEXIO_SPI_MasterTransferCreateHandleEDMA(FLEXIO_SPI_Type *base,
  94. flexio_spi_master_edma_handle_t *handle,
  95. flexio_spi_master_edma_transfer_callback_t callback,
  96. void *userData,
  97. edma_handle_t *txHandle,
  98. edma_handle_t *rxHandle);
  99. /*!
  100. * @brief Performs a non-blocking FlexIO SPI transfer using eDMA.
  101. *
  102. * @note This interface returns immediately after transfer initiates. Call
  103. * FLEXIO_SPI_MasterGetTransferCountEDMA to poll the transfer status and check
  104. * whether the FlexIO SPI transfer is finished.
  105. *
  106. * @param base Pointer to FLEXIO_SPI_Type structure.
  107. * @param handle Pointer to flexio_spi_master_edma_handle_t structure to store the transfer state.
  108. * @param xfer Pointer to FlexIO SPI transfer structure.
  109. * @retval kStatus_Success Successfully start a transfer.
  110. * @retval kStatus_InvalidArgument Input argument is invalid.
  111. * @retval kStatus_FLEXIO_SPI_Busy FlexIO SPI is not idle, is running another transfer.
  112. */
  113. status_t FLEXIO_SPI_MasterTransferEDMA(FLEXIO_SPI_Type *base,
  114. flexio_spi_master_edma_handle_t *handle,
  115. flexio_spi_transfer_t *xfer);
  116. /*!
  117. * @brief Aborts a FlexIO SPI transfer using eDMA.
  118. *
  119. * @param base Pointer to FLEXIO_SPI_Type structure.
  120. * @param handle FlexIO SPI eDMA handle pointer.
  121. */
  122. void FLEXIO_SPI_MasterTransferAbortEDMA(FLEXIO_SPI_Type *base, flexio_spi_master_edma_handle_t *handle);
  123. /*!
  124. * @brief Gets the remaining bytes for FlexIO SPI eDMA transfer.
  125. *
  126. * @param base Pointer to FLEXIO_SPI_Type structure.
  127. * @param handle FlexIO SPI eDMA handle pointer.
  128. * @param count Number of bytes transferred so far by the non-blocking transaction.
  129. */
  130. status_t FLEXIO_SPI_MasterTransferGetCountEDMA(FLEXIO_SPI_Type *base,
  131. flexio_spi_master_edma_handle_t *handle,
  132. size_t *count);
  133. /*!
  134. * @brief Initializes the FlexIO SPI slave eDMA handle.
  135. *
  136. * This function initializes the FlexIO SPI slave eDMA handle.
  137. *
  138. * @param base Pointer to FLEXIO_SPI_Type structure.
  139. * @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
  140. * @param callback SPI callback, NULL means no callback.
  141. * @param userData callback function parameter.
  142. * @param txHandle User requested eDMA handle for FlexIO SPI TX eDMA transfer.
  143. * @param rxHandle User requested eDMA handle for FlexIO SPI RX eDMA transfer.
  144. */
  145. static inline void FLEXIO_SPI_SlaveTransferCreateHandleEDMA(FLEXIO_SPI_Type *base,
  146. flexio_spi_slave_edma_handle_t *handle,
  147. flexio_spi_slave_edma_transfer_callback_t callback,
  148. void *userData,
  149. edma_handle_t *txHandle,
  150. edma_handle_t *rxHandle)
  151. {
  152. FLEXIO_SPI_MasterTransferCreateHandleEDMA(base, handle, callback, userData, txHandle, rxHandle);
  153. }
  154. /*!
  155. * @brief Performs a non-blocking FlexIO SPI transfer using eDMA.
  156. *
  157. * @note This interface returns immediately after transfer initiates. Call
  158. * FLEXIO_SPI_SlaveGetTransferCountEDMA to poll the transfer status and
  159. * check whether the FlexIO SPI transfer is finished.
  160. *
  161. * @param base Pointer to FLEXIO_SPI_Type structure.
  162. * @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
  163. * @param xfer Pointer to FlexIO SPI transfer structure.
  164. * @retval kStatus_Success Successfully start a transfer.
  165. * @retval kStatus_InvalidArgument Input argument is invalid.
  166. * @retval kStatus_FLEXIO_SPI_Busy FlexIO SPI is not idle, is running another transfer.
  167. */
  168. status_t FLEXIO_SPI_SlaveTransferEDMA(FLEXIO_SPI_Type *base,
  169. flexio_spi_slave_edma_handle_t *handle,
  170. flexio_spi_transfer_t *xfer);
  171. /*!
  172. * @brief Aborts a FlexIO SPI transfer using eDMA.
  173. *
  174. * @param base Pointer to FLEXIO_SPI_Type structure.
  175. * @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
  176. */
  177. static inline void FLEXIO_SPI_SlaveTransferAbortEDMA(FLEXIO_SPI_Type *base, flexio_spi_slave_edma_handle_t *handle)
  178. {
  179. FLEXIO_SPI_MasterTransferAbortEDMA(base, handle);
  180. }
  181. /*!
  182. * @brief Gets the remaining bytes to be transferred for FlexIO SPI eDMA.
  183. *
  184. * @param base Pointer to FLEXIO_SPI_Type structure.
  185. * @param handle FlexIO SPI eDMA handle pointer.
  186. * @param count Number of bytes transferred so far by the non-blocking transaction.
  187. */
  188. static inline status_t FLEXIO_SPI_SlaveTransferGetCountEDMA(FLEXIO_SPI_Type *base,
  189. flexio_spi_slave_edma_handle_t *handle,
  190. size_t *count)
  191. {
  192. return FLEXIO_SPI_MasterTransferGetCountEDMA(base, handle, count);
  193. }
  194. /*! @} */
  195. #if defined(__cplusplus)
  196. }
  197. #endif
  198. /*!
  199. * @}
  200. */
  201. #endif