fsl_flexio_spi_edma.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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_FLEXIO_SPI_EDMA_H_
  35. #define _FSL_FLEXIO_SPI_EDMA_H_
  36. #include "fsl_flexio_spi.h"
  37. #include "fsl_edma.h"
  38. /*!
  39. * @addtogroup flexio_edma_spi
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @name Driver version */
  46. /*@{*/
  47. /*! @brief FlexIO SPI EDMA driver version 2.1.3. */
  48. #define FSL_FLEXIO_SPI_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 1, 3))
  49. /*@}*/
  50. /*! @brief typedef for flexio_spi_master_edma_handle_t in advance. */
  51. typedef struct _flexio_spi_master_edma_handle flexio_spi_master_edma_handle_t;
  52. /*! @brief Slave handle is the same with master handle. */
  53. typedef flexio_spi_master_edma_handle_t flexio_spi_slave_edma_handle_t;
  54. /*! @brief FlexIO SPI master callback for finished transmit */
  55. typedef void (*flexio_spi_master_edma_transfer_callback_t)(FLEXIO_SPI_Type *base,
  56. flexio_spi_master_edma_handle_t *handle,
  57. status_t status,
  58. void *userData);
  59. /*! @brief FlexIO SPI slave callback for finished transmit */
  60. typedef void (*flexio_spi_slave_edma_transfer_callback_t)(FLEXIO_SPI_Type *base,
  61. flexio_spi_slave_edma_handle_t *handle,
  62. status_t status,
  63. void *userData);
  64. /*! @brief FlexIO SPI eDMA transfer handle, users should not touch the content of the handle.*/
  65. struct _flexio_spi_master_edma_handle
  66. {
  67. size_t transferSize; /*!< Total bytes to be transferred. */
  68. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  69. bool txInProgress; /*!< Send transfer in progress */
  70. bool rxInProgress; /*!< Receive transfer in progress */
  71. edma_handle_t *txHandle; /*!< DMA handler for SPI send */
  72. edma_handle_t *rxHandle; /*!< DMA handler for SPI receive */
  73. flexio_spi_master_edma_transfer_callback_t callback; /*!< Callback for SPI DMA transfer */
  74. void *userData; /*!< User Data for SPI DMA callback */
  75. };
  76. /*******************************************************************************
  77. * APIs
  78. ******************************************************************************/
  79. #if defined(__cplusplus)
  80. extern "C" {
  81. #endif
  82. /*!
  83. * @name eDMA Transactional
  84. * @{
  85. */
  86. /*!
  87. * @brief Initializes the FlexIO SPI master eDMA handle.
  88. *
  89. * This function initializes the FlexIO SPI master eDMA handle which can be used for other FlexIO SPI master
  90. * transactional
  91. * APIs.
  92. * For a specified FlexIO SPI instance, call this API once to get the initialized handle.
  93. *
  94. * @param base Pointer to FLEXIO_SPI_Type structure.
  95. * @param handle Pointer to flexio_spi_master_edma_handle_t structure to store the transfer state.
  96. * @param callback SPI callback, NULL means no callback.
  97. * @param userData callback function parameter.
  98. * @param txHandle User requested eDMA handle for FlexIO SPI RX eDMA transfer.
  99. * @param rxHandle User requested eDMA handle for FlexIO SPI TX eDMA transfer.
  100. * @retval kStatus_Success Successfully create the handle.
  101. * @retval kStatus_OutOfRange The FlexIO SPI eDMA type/handle table out of range.
  102. */
  103. status_t FLEXIO_SPI_MasterTransferCreateHandleEDMA(FLEXIO_SPI_Type *base,
  104. flexio_spi_master_edma_handle_t *handle,
  105. flexio_spi_master_edma_transfer_callback_t callback,
  106. void *userData,
  107. edma_handle_t *txHandle,
  108. edma_handle_t *rxHandle);
  109. /*!
  110. * @brief Performs a non-blocking FlexIO SPI transfer using eDMA.
  111. *
  112. * @note This interface returns immediately after transfer initiates. Call
  113. * FLEXIO_SPI_MasterGetTransferCountEDMA to poll the transfer status and check
  114. * whether the FlexIO SPI transfer is finished.
  115. *
  116. * @param base Pointer to FLEXIO_SPI_Type structure.
  117. * @param handle Pointer to flexio_spi_master_edma_handle_t structure to store the transfer state.
  118. * @param xfer Pointer to FlexIO SPI transfer structure.
  119. * @retval kStatus_Success Successfully start a transfer.
  120. * @retval kStatus_InvalidArgument Input argument is invalid.
  121. * @retval kStatus_FLEXIO_SPI_Busy FlexIO SPI is not idle, is running another transfer.
  122. */
  123. status_t FLEXIO_SPI_MasterTransferEDMA(FLEXIO_SPI_Type *base,
  124. flexio_spi_master_edma_handle_t *handle,
  125. flexio_spi_transfer_t *xfer);
  126. /*!
  127. * @brief Aborts a FlexIO SPI transfer using eDMA.
  128. *
  129. * @param base Pointer to FLEXIO_SPI_Type structure.
  130. * @param handle FlexIO SPI eDMA handle pointer.
  131. */
  132. void FLEXIO_SPI_MasterTransferAbortEDMA(FLEXIO_SPI_Type *base, flexio_spi_master_edma_handle_t *handle);
  133. /*!
  134. * @brief Gets the remaining bytes for FlexIO SPI eDMA transfer.
  135. *
  136. * @param base Pointer to FLEXIO_SPI_Type structure.
  137. * @param handle FlexIO SPI eDMA handle pointer.
  138. * @param count Number of bytes transferred so far by the non-blocking transaction.
  139. */
  140. status_t FLEXIO_SPI_MasterTransferGetCountEDMA(FLEXIO_SPI_Type *base,
  141. flexio_spi_master_edma_handle_t *handle,
  142. size_t *count);
  143. /*!
  144. * @brief Initializes the FlexIO SPI slave eDMA handle.
  145. *
  146. * This function initializes the FlexIO SPI slave eDMA handle.
  147. *
  148. * @param base Pointer to FLEXIO_SPI_Type structure.
  149. * @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
  150. * @param callback SPI callback, NULL means no callback.
  151. * @param userData callback function parameter.
  152. * @param txHandle User requested eDMA handle for FlexIO SPI TX eDMA transfer.
  153. * @param rxHandle User requested eDMA handle for FlexIO SPI RX eDMA transfer.
  154. */
  155. static inline void FLEXIO_SPI_SlaveTransferCreateHandleEDMA(FLEXIO_SPI_Type *base,
  156. flexio_spi_slave_edma_handle_t *handle,
  157. flexio_spi_slave_edma_transfer_callback_t callback,
  158. void *userData,
  159. edma_handle_t *txHandle,
  160. edma_handle_t *rxHandle)
  161. {
  162. FLEXIO_SPI_MasterTransferCreateHandleEDMA(base, handle, callback, userData, txHandle, rxHandle);
  163. }
  164. /*!
  165. * @brief Performs a non-blocking FlexIO SPI transfer using eDMA.
  166. *
  167. * @note This interface returns immediately after transfer initiates. Call
  168. * FLEXIO_SPI_SlaveGetTransferCountEDMA to poll the transfer status and
  169. * check whether the FlexIO SPI transfer is finished.
  170. *
  171. * @param base Pointer to FLEXIO_SPI_Type structure.
  172. * @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
  173. * @param xfer Pointer to FlexIO SPI transfer structure.
  174. * @retval kStatus_Success Successfully start a transfer.
  175. * @retval kStatus_InvalidArgument Input argument is invalid.
  176. * @retval kStatus_FLEXIO_SPI_Busy FlexIO SPI is not idle, is running another transfer.
  177. */
  178. status_t FLEXIO_SPI_SlaveTransferEDMA(FLEXIO_SPI_Type *base,
  179. flexio_spi_slave_edma_handle_t *handle,
  180. flexio_spi_transfer_t *xfer);
  181. /*!
  182. * @brief Aborts a FlexIO SPI transfer using eDMA.
  183. *
  184. * @param base Pointer to FLEXIO_SPI_Type structure.
  185. * @param handle Pointer to flexio_spi_slave_edma_handle_t structure to store the transfer state.
  186. */
  187. static inline void FLEXIO_SPI_SlaveTransferAbortEDMA(FLEXIO_SPI_Type *base, flexio_spi_slave_edma_handle_t *handle)
  188. {
  189. FLEXIO_SPI_MasterTransferAbortEDMA(base, handle);
  190. }
  191. /*!
  192. * @brief Gets the remaining bytes to be transferred for FlexIO SPI eDMA.
  193. *
  194. * @param base Pointer to FLEXIO_SPI_Type structure.
  195. * @param handle FlexIO SPI eDMA handle pointer.
  196. * @param count Number of bytes transferred so far by the non-blocking transaction.
  197. */
  198. static inline status_t FLEXIO_SPI_SlaveTransferGetCountEDMA(FLEXIO_SPI_Type *base,
  199. flexio_spi_slave_edma_handle_t *handle,
  200. size_t *count)
  201. {
  202. return FLEXIO_SPI_MasterTransferGetCountEDMA(base, handle, count);
  203. }
  204. /*! @} */
  205. #if defined(__cplusplus)
  206. }
  207. #endif
  208. /*!
  209. * @}
  210. */
  211. #endif