fsl_lpuart_edma.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_LPUART_EDMA_H_
  35. #define _FSL_LPUART_EDMA_H_
  36. #include "fsl_lpuart.h"
  37. #include "fsl_edma.h"
  38. /*!
  39. * @addtogroup lpuart_edma_driver
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @name Driver version */
  46. /*@{*/
  47. /*! @brief LPUART EDMA driver version 2.2.5. */
  48. #define FSL_LPUART_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 2, 5))
  49. /*@}*/
  50. /* Forward declaration of the handle typedef. */
  51. typedef struct _lpuart_edma_handle lpuart_edma_handle_t;
  52. /*! @brief LPUART transfer callback function. */
  53. typedef void (*lpuart_edma_transfer_callback_t)(LPUART_Type *base,
  54. lpuart_edma_handle_t *handle,
  55. status_t status,
  56. void *userData);
  57. /*!
  58. * @brief LPUART eDMA handle
  59. */
  60. struct _lpuart_edma_handle
  61. {
  62. lpuart_edma_transfer_callback_t callback; /*!< Callback function. */
  63. void *userData; /*!< LPUART callback function parameter.*/
  64. size_t rxDataSizeAll; /*!< Size of the data to receive. */
  65. size_t txDataSizeAll; /*!< Size of the data to send out. */
  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 LPUART handle which is used in transactional functions.
  84. * @param base LPUART peripheral base address.
  85. * @param handle Pointer to lpuart_edma_handle_t structure.
  86. * @param callback Callback function.
  87. * @param userData User data.
  88. * @param txEdmaHandle User requested DMA handle for TX DMA transfer.
  89. * @param rxEdmaHandle User requested DMA handle for RX DMA transfer.
  90. */
  91. void LPUART_TransferCreateHandleEDMA(LPUART_Type *base,
  92. lpuart_edma_handle_t *handle,
  93. lpuart_edma_transfer_callback_t callback,
  94. void *userData,
  95. edma_handle_t *txEdmaHandle,
  96. edma_handle_t *rxEdmaHandle);
  97. /*!
  98. * @brief Sends data using eDMA.
  99. *
  100. * This function sends data using eDMA. This is a non-blocking function, which returns
  101. * right away. When all data is sent, the send callback function is called.
  102. *
  103. * @param base LPUART peripheral base address.
  104. * @param handle LPUART handle pointer.
  105. * @param xfer LPUART eDMA transfer structure. See #lpuart_transfer_t.
  106. * @retval kStatus_Success if succeed, others failed.
  107. * @retval kStatus_LPUART_TxBusy Previous transfer on going.
  108. * @retval kStatus_InvalidArgument Invalid argument.
  109. */
  110. status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer);
  111. /*!
  112. * @brief Receives data using eDMA.
  113. *
  114. * This function receives data using eDMA. This is non-blocking function, which returns
  115. * right away. When all data is received, the receive callback function is called.
  116. *
  117. * @param base LPUART peripheral base address.
  118. * @param handle Pointer to lpuart_edma_handle_t structure.
  119. * @param xfer LPUART eDMA transfer structure, see #lpuart_transfer_t.
  120. * @retval kStatus_Success if succeed, others fail.
  121. * @retval kStatus_LPUART_RxBusy Previous transfer ongoing.
  122. * @retval kStatus_InvalidArgument Invalid argument.
  123. */
  124. status_t LPUART_ReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer);
  125. /*!
  126. * @brief Aborts the sent data using eDMA.
  127. *
  128. * This function aborts the sent data using eDMA.
  129. *
  130. * @param base LPUART peripheral base address.
  131. * @param handle Pointer to lpuart_edma_handle_t structure.
  132. */
  133. void LPUART_TransferAbortSendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle);
  134. /*!
  135. * @brief Aborts the received data using eDMA.
  136. *
  137. * This function aborts the received data using eDMA.
  138. *
  139. * @param base LPUART peripheral base address.
  140. * @param handle Pointer to lpuart_edma_handle_t structure.
  141. */
  142. void LPUART_TransferAbortReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle);
  143. /*!
  144. * @brief Gets the number of bytes written to the LPUART TX register.
  145. *
  146. * This function gets the number of bytes written to the LPUART TX
  147. * register by DMA.
  148. *
  149. * @param base LPUART peripheral base address.
  150. * @param handle LPUART handle pointer.
  151. * @param count Send bytes count.
  152. * @retval kStatus_NoTransferInProgress No send in progress.
  153. * @retval kStatus_InvalidArgument Parameter is invalid.
  154. * @retval kStatus_Success Get successfully through the parameter \p count;
  155. */
  156. status_t LPUART_TransferGetSendCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count);
  157. /*!
  158. * @brief Gets the number of received bytes.
  159. *
  160. * This function gets the number of received bytes.
  161. *
  162. * @param base LPUART peripheral base address.
  163. * @param handle LPUART handle pointer.
  164. * @param count Receive bytes count.
  165. * @retval kStatus_NoTransferInProgress No receive in progress.
  166. * @retval kStatus_InvalidArgument Parameter is invalid.
  167. * @retval kStatus_Success Get successfully through the parameter \p count;
  168. */
  169. status_t LPUART_TransferGetReceiveCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count);
  170. /*@}*/
  171. #if defined(__cplusplus)
  172. }
  173. #endif
  174. /*! @}*/
  175. #endif /* _FSL_LPUART_EDMA_H_ */