fsl_uart_edma.h 7.2 KB

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