fsl_flexio_uart_edma.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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_UART_EDMA_H_
  31. #define _FSL_FLEXIO_UART_EDMA_H_
  32. #include "fsl_flexio_uart.h"
  33. #include "fsl_edma.h"
  34. /*!
  35. * @addtogroup flexio_edma_uart
  36. * @{
  37. */
  38. /*******************************************************************************
  39. * Definitions
  40. ******************************************************************************/
  41. /* Forward declaration of the handle typedef. */
  42. typedef struct _flexio_uart_edma_handle flexio_uart_edma_handle_t;
  43. /*! @brief UART transfer callback function. */
  44. typedef void (*flexio_uart_edma_transfer_callback_t)(FLEXIO_UART_Type *base,
  45. flexio_uart_edma_handle_t *handle,
  46. status_t status,
  47. void *userData);
  48. /*!
  49. * @brief UART eDMA handle
  50. */
  51. struct _flexio_uart_edma_handle
  52. {
  53. flexio_uart_edma_transfer_callback_t callback; /*!< Callback function. */
  54. void *userData; /*!< UART callback function parameter.*/
  55. size_t txDataSizeAll; /*!< Total bytes to be sent. */
  56. size_t rxDataSizeAll; /*!< Total bytes to be received. */
  57. edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */
  58. edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */
  59. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  60. volatile uint8_t txState; /*!< TX transfer state. */
  61. volatile uint8_t rxState; /*!< RX transfer state */
  62. };
  63. /*******************************************************************************
  64. * API
  65. ******************************************************************************/
  66. #if defined(__cplusplus)
  67. extern "C" {
  68. #endif
  69. /*!
  70. * @name eDMA transactional
  71. * @{
  72. */
  73. /*!
  74. * @brief Initializes the UART handle which is used in transactional functions.
  75. *
  76. * @param base Pointer to FLEXIO_UART_Type.
  77. * @param handle Pointer to flexio_uart_edma_handle_t structure.
  78. * @param callback The callback function.
  79. * @param userData The parameter of the callback function.
  80. * @param rxEdmaHandle User requested DMA handle for RX DMA transfer.
  81. * @param txEdmaHandle User requested DMA handle for TX DMA transfer.
  82. * @retval kStatus_Success Successfully create the handle.
  83. * @retval kStatus_OutOfRange The FlexIO SPI eDMA type/handle table out of range.
  84. */
  85. status_t FLEXIO_UART_TransferCreateHandleEDMA(FLEXIO_UART_Type *base,
  86. flexio_uart_edma_handle_t *handle,
  87. flexio_uart_edma_transfer_callback_t callback,
  88. void *userData,
  89. edma_handle_t *txEdmaHandle,
  90. edma_handle_t *rxEdmaHandle);
  91. /*!
  92. * @brief Sends data using eDMA.
  93. *
  94. * This function sends data using eDMA. This is a non-blocking function, which returns
  95. * right away. When all data is sent out, the send callback function is called.
  96. *
  97. * @param base Pointer to FLEXIO_UART_Type
  98. * @param handle UART handle pointer.
  99. * @param xfer UART eDMA transfer structure, see #flexio_uart_transfer_t.
  100. * @retval kStatus_Success if succeed, others failed.
  101. * @retval kStatus_FLEXIO_UART_TxBusy Previous transfer on going.
  102. */
  103. status_t FLEXIO_UART_TransferSendEDMA(FLEXIO_UART_Type *base,
  104. flexio_uart_edma_handle_t *handle,
  105. flexio_uart_transfer_t *xfer);
  106. /*!
  107. * @brief Receives data using eDMA.
  108. *
  109. * This function receives data using eDMA. This is a non-blocking function, which returns
  110. * right away. When all data is received, the receive callback function is called.
  111. *
  112. * @param base Pointer to FLEXIO_UART_Type
  113. * @param handle Pointer to flexio_uart_edma_handle_t structure
  114. * @param xfer UART eDMA transfer structure, see #flexio_uart_transfer_t.
  115. * @retval kStatus_Success if succeed, others failed.
  116. * @retval kStatus_UART_RxBusy Previous transfer on going.
  117. */
  118. status_t FLEXIO_UART_TransferReceiveEDMA(FLEXIO_UART_Type *base,
  119. flexio_uart_edma_handle_t *handle,
  120. flexio_uart_transfer_t *xfer);
  121. /*!
  122. * @brief Aborts the sent data which using eDMA.
  123. *
  124. * This function aborts sent data which using eDMA.
  125. *
  126. * @param base Pointer to FLEXIO_UART_Type
  127. * @param handle Pointer to flexio_uart_edma_handle_t structure
  128. */
  129. void FLEXIO_UART_TransferAbortSendEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle);
  130. /*!
  131. * @brief Aborts the receive data which using eDMA.
  132. *
  133. * This function aborts the receive data which using eDMA.
  134. *
  135. * @param base Pointer to FLEXIO_UART_Type
  136. * @param handle Pointer to flexio_uart_edma_handle_t structure
  137. */
  138. void FLEXIO_UART_TransferAbortReceiveEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle);
  139. /*!
  140. * @brief Gets the number of bytes sent out.
  141. *
  142. * This function gets the number of bytes sent out.
  143. *
  144. * @param base Pointer to FLEXIO_UART_Type
  145. * @param handle Pointer to flexio_uart_edma_handle_t structure
  146. * @param count Number of bytes sent so far by the non-blocking transaction.
  147. * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
  148. * @retval kStatus_Success Successfully return the count.
  149. */
  150. status_t FLEXIO_UART_TransferGetSendCountEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle, size_t *count);
  151. /*!
  152. * @brief Gets the number of bytes received.
  153. *
  154. * This function gets the number of bytes received.
  155. *
  156. * @param base Pointer to FLEXIO_UART_Type
  157. * @param handle Pointer to flexio_uart_edma_handle_t structure
  158. * @param count Number of bytes received so far by the non-blocking transaction.
  159. * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
  160. * @retval kStatus_Success Successfully return the count.
  161. */
  162. status_t FLEXIO_UART_TransferGetReceiveCountEDMA(FLEXIO_UART_Type *base,
  163. flexio_uart_edma_handle_t *handle,
  164. size_t *count);
  165. /*@}*/
  166. #if defined(__cplusplus)
  167. }
  168. #endif
  169. /*! @}*/
  170. #endif /* _FSL_UART_EDMA_H_ */