fsl_uart_edma.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_UART_EDMA_H_
  31. #define _FSL_UART_EDMA_H_
  32. #include "fsl_uart.h"
  33. #include "fsl_dmamux.h"
  34. #include "fsl_edma.h"
  35. /*!
  36. * @addtogroup uart_edma_driver
  37. * @{
  38. */
  39. /*******************************************************************************
  40. * Definitions
  41. ******************************************************************************/
  42. /* Forward declaration of the handle typedef. */
  43. typedef struct _uart_edma_handle uart_edma_handle_t;
  44. /*! @brief UART transfer callback function. */
  45. typedef void (*uart_edma_transfer_callback_t)(UART_Type *base,
  46. uart_edma_handle_t *handle,
  47. status_t status,
  48. void *userData);
  49. /*!
  50. * @brief UART eDMA handle
  51. */
  52. struct _uart_edma_handle
  53. {
  54. uart_edma_transfer_callback_t callback; /*!< Callback function. */
  55. void *userData; /*!< UART callback function parameter.*/
  56. size_t rxDataSizeAll; /*!< Size of the data to receive. */
  57. size_t txDataSizeAll; /*!< Size of the data to send out. */
  58. edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */
  59. edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */
  60. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  61. volatile uint8_t txState; /*!< TX transfer state. */
  62. volatile uint8_t rxState; /*!< RX transfer state */
  63. };
  64. /*******************************************************************************
  65. * API
  66. ******************************************************************************/
  67. #if defined(__cplusplus)
  68. extern "C" {
  69. #endif
  70. /*!
  71. * @name eDMA transactional
  72. * @{
  73. */
  74. /*!
  75. * @brief Initializes the UART handle which is used in transactional functions.
  76. * @param base UART peripheral base address.
  77. * @param handle Pointer to the uart_edma_handle_t structure.
  78. * @param callback UART callback, NULL means no callback.
  79. * @param userData User callback function data.
  80. * @param rxEdmaHandle User-requested DMA handle for RX DMA transfer.
  81. * @param txEdmaHandle User-requested DMA handle for TX DMA transfer.
  82. */
  83. void UART_TransferCreateHandleEDMA(UART_Type *base,
  84. uart_edma_handle_t *handle,
  85. uart_edma_transfer_callback_t callback,
  86. void *userData,
  87. edma_handle_t *txEdmaHandle,
  88. edma_handle_t *rxEdmaHandle);
  89. /*!
  90. * @brief Sends data using eDMA.
  91. *
  92. * This function sends data using eDMA. This is a non-blocking function, which returns
  93. * right away. When all data is sent, the send callback function is called.
  94. *
  95. * @param base UART peripheral base address.
  96. * @param handle UART handle pointer.
  97. * @param xfer UART eDMA transfer structure. See #uart_transfer_t.
  98. * @retval kStatus_Success if succeeded; otherwise failed.
  99. * @retval kStatus_UART_TxBusy Previous transfer ongoing.
  100. * @retval kStatus_InvalidArgument Invalid argument.
  101. */
  102. status_t UART_SendEDMA(UART_Type *base, uart_edma_handle_t *handle, uart_transfer_t *xfer);
  103. /*!
  104. * @brief Receives data using eDMA.
  105. *
  106. * This function receives data using eDMA. This is a non-blocking function, which returns
  107. * right away. When all data is received, the receive callback function is called.
  108. *
  109. * @param base UART peripheral base address.
  110. * @param handle Pointer to the uart_edma_handle_t structure.
  111. * @param xfer UART eDMA transfer structure. See #uart_transfer_t.
  112. * @retval kStatus_Success if succeeded; otherwise failed.
  113. * @retval kStatus_UART_RxBusy Previous transfer ongoing.
  114. * @retval kStatus_InvalidArgument Invalid argument.
  115. */
  116. status_t UART_ReceiveEDMA(UART_Type *base, uart_edma_handle_t *handle, uart_transfer_t *xfer);
  117. /*!
  118. * @brief Aborts the sent data using eDMA.
  119. *
  120. * This function aborts sent data using eDMA.
  121. *
  122. * @param base UART peripheral base address.
  123. * @param handle Pointer to the uart_edma_handle_t structure.
  124. */
  125. void UART_TransferAbortSendEDMA(UART_Type *base, uart_edma_handle_t *handle);
  126. /*!
  127. * @brief Aborts the receive data using eDMA.
  128. *
  129. * This function aborts receive data using eDMA.
  130. *
  131. * @param base UART peripheral base address.
  132. * @param handle Pointer to the uart_edma_handle_t structure.
  133. */
  134. void UART_TransferAbortReceiveEDMA(UART_Type *base, uart_edma_handle_t *handle);
  135. /*!
  136. * @brief Gets the number of bytes that have been written to UART TX register.
  137. *
  138. * This function gets the number of bytes that have been written to UART TX
  139. * register by DMA.
  140. *
  141. * @param base UART peripheral base address.
  142. * @param handle UART handle pointer.
  143. * @param count Send bytes count.
  144. * @retval kStatus_NoTransferInProgress No send in progress.
  145. * @retval kStatus_InvalidArgument Parameter is invalid.
  146. * @retval kStatus_Success Get successfully through the parameter \p count;
  147. */
  148. status_t UART_TransferGetSendCountEDMA(UART_Type *base, uart_edma_handle_t *handle, uint32_t *count);
  149. /*!
  150. * @brief Gets the number of received bytes.
  151. *
  152. * This function gets the number of received bytes.
  153. *
  154. * @param base UART peripheral base address.
  155. * @param handle UART handle pointer.
  156. * @param count Receive bytes count.
  157. * @retval kStatus_NoTransferInProgress No receive in progress.
  158. * @retval kStatus_InvalidArgument Parameter is invalid.
  159. * @retval kStatus_Success Get successfully through the parameter \p count;
  160. */
  161. status_t UART_TransferGetReceiveCountEDMA(UART_Type *base, uart_edma_handle_t *handle, uint32_t *count);
  162. /*@}*/
  163. #if defined(__cplusplus)
  164. }
  165. #endif
  166. /*! @}*/
  167. #endif /* _FSL_UART_EDMA_H_ */