fsl_flexio_uart_edma.h 8.0 KB

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