fsl_lpuart_edma.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_LPUART_EDMA_H_
  9. #define _FSL_LPUART_EDMA_H_
  10. #include "fsl_lpuart.h"
  11. #include "fsl_edma.h"
  12. /*!
  13. * @addtogroup lpuart_edma_driver
  14. * @{
  15. */
  16. /*******************************************************************************
  17. * Definitions
  18. ******************************************************************************/
  19. /*! @name Driver version */
  20. /*@{*/
  21. /*! @brief LPUART EDMA driver version. */
  22. #define FSL_LPUART_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 5, 2))
  23. /*@}*/
  24. /* Forward declaration of the handle typedef. */
  25. typedef struct _lpuart_edma_handle lpuart_edma_handle_t;
  26. /*! @brief LPUART transfer callback function. */
  27. typedef void (*lpuart_edma_transfer_callback_t)(LPUART_Type *base,
  28. lpuart_edma_handle_t *handle,
  29. status_t status,
  30. void *userData);
  31. /*!
  32. * @brief LPUART eDMA handle
  33. */
  34. struct _lpuart_edma_handle
  35. {
  36. lpuart_edma_transfer_callback_t callback; /*!< Callback function. */
  37. void *userData; /*!< LPUART callback function parameter.*/
  38. size_t rxDataSizeAll; /*!< Size of the data to receive. */
  39. size_t txDataSizeAll; /*!< Size of the data to send out. */
  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 LPUART handle which is used in transactional functions.
  58. *
  59. * @note This function disables all LPUART interrupts.
  60. *
  61. * @param base LPUART peripheral base address.
  62. * @param handle Pointer to lpuart_edma_handle_t structure.
  63. * @param callback Callback function.
  64. * @param userData User data.
  65. * @param txEdmaHandle User requested DMA handle for TX DMA transfer.
  66. * @param rxEdmaHandle User requested DMA handle for RX DMA transfer.
  67. */
  68. void LPUART_TransferCreateHandleEDMA(LPUART_Type *base,
  69. lpuart_edma_handle_t *handle,
  70. lpuart_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, the send callback function is called.
  79. *
  80. * @param base LPUART peripheral base address.
  81. * @param handle LPUART handle pointer.
  82. * @param xfer LPUART eDMA transfer structure. See #lpuart_transfer_t.
  83. * @retval kStatus_Success if succeed, others failed.
  84. * @retval kStatus_LPUART_TxBusy Previous transfer on going.
  85. * @retval kStatus_InvalidArgument Invalid argument.
  86. */
  87. status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer);
  88. /*!
  89. * @brief Receives data using eDMA.
  90. *
  91. * This function receives data using eDMA. This is non-blocking function, which returns
  92. * right away. When all data is received, the receive callback function is called.
  93. *
  94. * @param base LPUART peripheral base address.
  95. * @param handle Pointer to lpuart_edma_handle_t structure.
  96. * @param xfer LPUART eDMA transfer structure, see #lpuart_transfer_t.
  97. * @retval kStatus_Success if succeed, others fail.
  98. * @retval kStatus_LPUART_RxBusy Previous transfer ongoing.
  99. * @retval kStatus_InvalidArgument Invalid argument.
  100. */
  101. status_t LPUART_ReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer);
  102. /*!
  103. * @brief Aborts the sent data using eDMA.
  104. *
  105. * This function aborts the sent data using eDMA.
  106. *
  107. * @param base LPUART peripheral base address.
  108. * @param handle Pointer to lpuart_edma_handle_t structure.
  109. */
  110. void LPUART_TransferAbortSendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle);
  111. /*!
  112. * @brief Aborts the received data using eDMA.
  113. *
  114. * This function aborts the received data using eDMA.
  115. *
  116. * @param base LPUART peripheral base address.
  117. * @param handle Pointer to lpuart_edma_handle_t structure.
  118. */
  119. void LPUART_TransferAbortReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle);
  120. /*!
  121. * @brief Gets the number of bytes written to the LPUART TX register.
  122. *
  123. * This function gets the number of bytes written to the LPUART TX
  124. * register by DMA.
  125. *
  126. * @param base LPUART peripheral base address.
  127. * @param handle LPUART handle pointer.
  128. * @param count Send bytes count.
  129. * @retval kStatus_NoTransferInProgress No send in progress.
  130. * @retval kStatus_InvalidArgument Parameter is invalid.
  131. * @retval kStatus_Success Get successfully through the parameter \p count;
  132. */
  133. status_t LPUART_TransferGetSendCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count);
  134. /*!
  135. * @brief Gets the number of received bytes.
  136. *
  137. * This function gets the number of received bytes.
  138. *
  139. * @param base LPUART peripheral base address.
  140. * @param handle LPUART handle pointer.
  141. * @param count Receive bytes count.
  142. * @retval kStatus_NoTransferInProgress No receive in progress.
  143. * @retval kStatus_InvalidArgument Parameter is invalid.
  144. * @retval kStatus_Success Get successfully through the parameter \p count;
  145. */
  146. status_t LPUART_TransferGetReceiveCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count);
  147. /*!
  148. * @brief LPUART eDMA IRQ handle function.
  149. *
  150. * This function handles the LPUART tx complete IRQ request and invoke user callback.
  151. * It is not set to static so that it can be used in user application.
  152. * @note This function is used as default IRQ handler by double weak mechanism.
  153. * If user's specific IRQ handler is implemented, make sure this function is invoked in the handler.
  154. *
  155. * @param base LPUART peripheral base address.
  156. * @param lpuartEdmaHandle LPUART handle pointer.
  157. */
  158. void LPUART_TransferEdmaHandleIRQ(LPUART_Type *base, void *lpuartEdmaHandle);
  159. /*@}*/
  160. #if defined(__cplusplus)
  161. }
  162. #endif
  163. /*! @}*/
  164. #endif /* _FSL_LPUART_EDMA_H_ */