fsl_flexio_uart_edma.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_FLEXIO_UART_EDMA_H_
  9. #define _FSL_FLEXIO_UART_EDMA_H_
  10. #include "fsl_flexio_uart.h"
  11. #include "fsl_edma.h"
  12. /*!
  13. * @addtogroup flexio_edma_uart
  14. * @{
  15. */
  16. /*******************************************************************************
  17. * Definitions
  18. ******************************************************************************/
  19. /*! @name Driver version */
  20. /*@{*/
  21. /*! @brief FlexIO UART EDMA driver version. */
  22. #define FSL_FLEXIO_UART_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 4, 1))
  23. /*@}*/
  24. /* Forward declaration of the handle typedef. */
  25. typedef struct _flexio_uart_edma_handle flexio_uart_edma_handle_t;
  26. /*! @brief UART transfer callback function. */
  27. typedef void (*flexio_uart_edma_transfer_callback_t)(FLEXIO_UART_Type *base,
  28. flexio_uart_edma_handle_t *handle,
  29. status_t status,
  30. void *userData);
  31. /*!
  32. * @brief UART eDMA handle
  33. */
  34. struct _flexio_uart_edma_handle
  35. {
  36. flexio_uart_edma_transfer_callback_t callback; /*!< Callback function. */
  37. void *userData; /*!< UART callback function parameter.*/
  38. size_t txDataSizeAll; /*!< Total bytes to be sent. */
  39. size_t rxDataSizeAll; /*!< Total bytes to be received. */
  40. edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */
  41. edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */
  42. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  43. volatile uint8_t txState; /*!< TX transfer state. */
  44. volatile uint8_t rxState; /*!< RX transfer state */
  45. };
  46. /*******************************************************************************
  47. * API
  48. ******************************************************************************/
  49. #if defined(__cplusplus)
  50. extern "C" {
  51. #endif
  52. /*!
  53. * @name eDMA transactional
  54. * @{
  55. */
  56. /*!
  57. * @brief Initializes the UART handle which is used in transactional functions.
  58. *
  59. * @param base Pointer to FLEXIO_UART_Type.
  60. * @param handle Pointer to flexio_uart_edma_handle_t structure.
  61. * @param callback The callback function.
  62. * @param userData The parameter of the callback function.
  63. * @param rxEdmaHandle User requested DMA handle for RX DMA transfer.
  64. * @param txEdmaHandle User requested DMA handle for TX DMA transfer.
  65. * @retval kStatus_Success Successfully create the handle.
  66. * @retval kStatus_OutOfRange The FlexIO SPI eDMA type/handle table out of range.
  67. */
  68. status_t FLEXIO_UART_TransferCreateHandleEDMA(FLEXIO_UART_Type *base,
  69. flexio_uart_edma_handle_t *handle,
  70. flexio_uart_edma_transfer_callback_t callback,
  71. void *userData,
  72. edma_handle_t *txEdmaHandle,
  73. edma_handle_t *rxEdmaHandle);
  74. /*!
  75. * @brief Sends data using eDMA.
  76. *
  77. * This function sends data using eDMA. This is a non-blocking function, which returns
  78. * right away. When all data is sent out, the send callback function is called.
  79. *
  80. * @param base Pointer to FLEXIO_UART_Type
  81. * @param handle UART handle pointer.
  82. * @param xfer UART eDMA transfer structure, see #flexio_uart_transfer_t.
  83. * @retval kStatus_Success if succeed, others failed.
  84. * @retval kStatus_FLEXIO_UART_TxBusy Previous transfer on going.
  85. */
  86. status_t FLEXIO_UART_TransferSendEDMA(FLEXIO_UART_Type *base,
  87. flexio_uart_edma_handle_t *handle,
  88. flexio_uart_transfer_t *xfer);
  89. /*!
  90. * @brief Receives data using eDMA.
  91. *
  92. * This function receives data using eDMA. This is a non-blocking function, which returns
  93. * right away. When all data is received, the receive callback function is called.
  94. *
  95. * @param base Pointer to FLEXIO_UART_Type
  96. * @param handle Pointer to flexio_uart_edma_handle_t structure
  97. * @param xfer UART eDMA transfer structure, see #flexio_uart_transfer_t.
  98. * @retval kStatus_Success if succeed, others failed.
  99. * @retval kStatus_UART_RxBusy Previous transfer on going.
  100. */
  101. status_t FLEXIO_UART_TransferReceiveEDMA(FLEXIO_UART_Type *base,
  102. flexio_uart_edma_handle_t *handle,
  103. flexio_uart_transfer_t *xfer);
  104. /*!
  105. * @brief Aborts the sent data which using eDMA.
  106. *
  107. * This function aborts sent data which using eDMA.
  108. *
  109. * @param base Pointer to FLEXIO_UART_Type
  110. * @param handle Pointer to flexio_uart_edma_handle_t structure
  111. */
  112. void FLEXIO_UART_TransferAbortSendEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle);
  113. /*!
  114. * @brief Aborts the receive data which using eDMA.
  115. *
  116. * This function aborts the receive data which using eDMA.
  117. *
  118. * @param base Pointer to FLEXIO_UART_Type
  119. * @param handle Pointer to flexio_uart_edma_handle_t structure
  120. */
  121. void FLEXIO_UART_TransferAbortReceiveEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle);
  122. /*!
  123. * @brief Gets the number of bytes sent out.
  124. *
  125. * This function gets the number of bytes sent out.
  126. *
  127. * @param base Pointer to FLEXIO_UART_Type
  128. * @param handle Pointer to flexio_uart_edma_handle_t structure
  129. * @param count Number of bytes sent so far by the non-blocking transaction.
  130. * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
  131. * @retval kStatus_Success Successfully return the count.
  132. */
  133. status_t FLEXIO_UART_TransferGetSendCountEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle, size_t *count);
  134. /*!
  135. * @brief Gets the number of bytes received.
  136. *
  137. * This function gets the number of bytes received.
  138. *
  139. * @param base Pointer to FLEXIO_UART_Type
  140. * @param handle Pointer to flexio_uart_edma_handle_t structure
  141. * @param count Number of bytes received so far by the non-blocking transaction.
  142. * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
  143. * @retval kStatus_Success Successfully return the count.
  144. */
  145. status_t FLEXIO_UART_TransferGetReceiveCountEDMA(FLEXIO_UART_Type *base,
  146. flexio_uart_edma_handle_t *handle,
  147. size_t *count);
  148. /*@}*/
  149. #if defined(__cplusplus)
  150. }
  151. #endif
  152. /*! @}*/
  153. #endif /* _FSL_UART_EDMA_H_ */