fsl_qspi_edma.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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_QSPI_EDMA_H_
  35. #define _FSL_QSPI_EDMA_H_
  36. #include "fsl_qspi.h"
  37. #include "fsl_edma.h"
  38. /*!
  39. * @addtogroup qspi_edma
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @name Driver version */
  46. /*@{*/
  47. /*! @brief QSPI EDMA driver version 2.0.2. */
  48. #define FSL_QSPI_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
  49. /*@}*/
  50. typedef struct _qspi_edma_handle qspi_edma_handle_t;
  51. /*! @brief QSPI eDMA transfer callback function for finish and error */
  52. typedef void (*qspi_edma_callback_t)(QuadSPI_Type *base, qspi_edma_handle_t *handle, status_t status, void *userData);
  53. /*! @brief QSPI DMA transfer handle, users should not touch the content of the handle.*/
  54. struct _qspi_edma_handle
  55. {
  56. edma_handle_t *dmaHandle; /*!< eDMA handler for QSPI send */
  57. size_t transferSize; /*!< Bytes need to transfer. */
  58. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  59. uint8_t count; /*!< The transfer data count in a DMA request */
  60. uint32_t state; /*!< Internal state for QSPI eDMA transfer */
  61. qspi_edma_callback_t callback; /*!< Callback for users while transfer finish or error occurred */
  62. void *userData; /*!< User callback parameter */
  63. };
  64. /*******************************************************************************
  65. * APIs
  66. ******************************************************************************/
  67. #if defined(__cplusplus)
  68. extern "C" {
  69. #endif
  70. /*!
  71. * @name eDMA Transactional
  72. * @{
  73. */
  74. /*!
  75. * @brief Initializes the QSPI handle for send which is used in transactional functions and set the callback.
  76. *
  77. * @param base QSPI peripheral base address
  78. * @param handle Pointer to qspi_edma_handle_t structure
  79. * @param callback QSPI callback, NULL means no callback.
  80. * @param userData User callback function data.
  81. * @param rxDmaHandle User requested eDMA handle for eDMA transfer
  82. */
  83. void QSPI_TransferTxCreateHandleEDMA(QuadSPI_Type *base,
  84. qspi_edma_handle_t *handle,
  85. qspi_edma_callback_t callback,
  86. void *userData,
  87. edma_handle_t *dmaHandle);
  88. /*!
  89. * @brief Initializes the QSPI handle for receive which is used in transactional functions and set the callback.
  90. *
  91. * @param base QSPI peripheral base address
  92. * @param handle Pointer to qspi_edma_handle_t structure
  93. * @param callback QSPI callback, NULL means no callback.
  94. * @param userData User callback function data.
  95. * @param rxDmaHandle User requested eDMA handle for eDMA transfer
  96. */
  97. void QSPI_TransferRxCreateHandleEDMA(QuadSPI_Type *base,
  98. qspi_edma_handle_t *handle,
  99. qspi_edma_callback_t callback,
  100. void *userData,
  101. edma_handle_t *dmaHandle);
  102. /*!
  103. * @brief Transfers QSPI data using an eDMA non-blocking method.
  104. *
  105. * This function writes data to the QSPI transmit FIFO. This function is non-blocking.
  106. * @param base Pointer to QuadSPI Type.
  107. * @param handle Pointer to qspi_edma_handle_t structure
  108. * @param xfer QSPI transfer structure.
  109. */
  110. status_t QSPI_TransferSendEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle, qspi_transfer_t *xfer);
  111. /*!
  112. * @brief Receives data using an eDMA non-blocking method.
  113. *
  114. * This function receive data from the QSPI receive buffer/FIFO. This function is non-blocking. Users shall notice that
  115. * this receive size shall not bigger than 64 bytes. As this interface is used to read flash status registers.
  116. * For flash contents read, please use AHB bus read, this is much more efficiency.
  117. *
  118. * @param base Pointer to QuadSPI Type.
  119. * @param handle Pointer to qspi_edma_handle_t structure
  120. * @param xfer QSPI transfer structure.
  121. */
  122. status_t QSPI_TransferReceiveEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle, qspi_transfer_t *xfer);
  123. /*!
  124. * @brief Aborts the sent data using eDMA.
  125. *
  126. * This function aborts the sent data using eDMA.
  127. *
  128. * @param base QSPI peripheral base address.
  129. * @param handle Pointer to qspi_edma_handle_t structure
  130. */
  131. void QSPI_TransferAbortSendEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle);
  132. /*!
  133. * @brief Aborts the receive data using eDMA.
  134. *
  135. * This function abort receive data which using eDMA.
  136. *
  137. * @param base QSPI peripheral base address.
  138. * @param handle Pointer to qspi_edma_handle_t structure
  139. */
  140. void QSPI_TransferAbortReceiveEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle);
  141. /*!
  142. * @brief Gets the transferred counts of send.
  143. *
  144. * @param base Pointer to QuadSPI Type.
  145. * @param handle Pointer to qspi_edma_handle_t structure.
  146. * @param count Bytes sent.
  147. * @retval kStatus_Success Succeed get the transfer count.
  148. * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
  149. */
  150. status_t QSPI_TransferGetSendCountEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle, size_t *count);
  151. /*!
  152. * @brief Gets the status of the receive transfer.
  153. *
  154. * @param base Pointer to QuadSPI Type.
  155. * @param handle Pointer to qspi_edma_handle_t structure
  156. * @param count Bytes received.
  157. * @retval kStatus_Success Succeed get the transfer count.
  158. * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
  159. */
  160. status_t QSPI_TransferGetReceiveCountEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle, size_t *count);
  161. /* @} */
  162. #if defined(__cplusplus)
  163. }
  164. #endif
  165. /* @} */
  166. #endif /* _FSL_QSPI_EDMA_H_ */