fsl_dmic_dma.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, 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_DMIC_DMA_H_
  35. #define _FSL_DMIC_DMA_H_
  36. #include "fsl_common.h"
  37. #include "fsl_dma.h"
  38. /*!
  39. * @addtogroup dmic_dma_driver
  40. * @{
  41. */
  42. /*! @file */
  43. /*******************************************************************************
  44. * Definitions
  45. ******************************************************************************/
  46. /*!
  47. * @name DMIC DMA version
  48. * @{
  49. */
  50. /*! @brief DMIC DMA driver version 2.0.0. */
  51. #define FSL_DMIC_DMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  52. /*@}*/
  53. /*! @brief DMIC transfer structure. */
  54. typedef struct _dmic_transfer
  55. {
  56. uint16_t *data; /*!< The buffer of data to be transfer.*/
  57. size_t dataSize; /*!< The byte count to be transfer. */
  58. } dmic_transfer_t;
  59. /* Forward declaration of the handle typedef. */
  60. typedef struct _dmic_dma_handle dmic_dma_handle_t;
  61. /*! @brief DMIC transfer callback function. */
  62. typedef void (*dmic_dma_transfer_callback_t)(DMIC_Type *base,
  63. dmic_dma_handle_t *handle,
  64. status_t status,
  65. void *userData);
  66. /*!
  67. * @brief DMIC DMA handle
  68. */
  69. struct _dmic_dma_handle
  70. {
  71. DMIC_Type *base; /*!< DMIC peripheral base address. */
  72. dma_handle_t *rxDmaHandle; /*!< The DMA RX channel used. */
  73. dmic_dma_transfer_callback_t callback; /*!< Callback function. */
  74. void *userData; /*!< DMIC callback function parameter.*/
  75. size_t transferSize; /*!< Size of the data to receive. */
  76. volatile uint8_t state; /*!< Internal state of DMIC DMA transfer */
  77. };
  78. /*******************************************************************************
  79. * API
  80. ******************************************************************************/
  81. #ifdef __cplusplus
  82. extern "C" {
  83. #endif /* _cplusplus */
  84. /*!
  85. * @name DMA transactional
  86. * @{
  87. */
  88. /*!
  89. * @brief Initializes the DMIC handle which is used in transactional functions.
  90. * @param base DMIC peripheral base address.
  91. * @param handle Pointer to dmic_dma_handle_t structure.
  92. * @param callback Callback function.
  93. * @param userData User data.
  94. * @param rxDmaHandle User-requested DMA handle for RX DMA transfer.
  95. */
  96. status_t DMIC_TransferCreateHandleDMA(DMIC_Type *base,
  97. dmic_dma_handle_t *handle,
  98. dmic_dma_transfer_callback_t callback,
  99. void *userData,
  100. dma_handle_t *rxDmaHandle);
  101. /*!
  102. * @brief Receives data using DMA.
  103. *
  104. * This function receives data using DMA. This is a non-blocking function, which returns
  105. * right away. When all data is received, the receive callback function is called.
  106. *
  107. * @param base USART peripheral base address.
  108. * @param handle Pointer to usart_dma_handle_t structure.
  109. * @param xfer DMIC DMA transfer structure. See #dmic_transfer_t.
  110. * @param dmic_channel DMIC channel
  111. * @retval kStatus_Success
  112. */
  113. status_t DMIC_TransferReceiveDMA(DMIC_Type *base,
  114. dmic_dma_handle_t *handle,
  115. dmic_transfer_t *xfer,
  116. uint32_t dmic_channel);
  117. /*!
  118. * @brief Aborts the received data using DMA.
  119. *
  120. * This function aborts the received data using DMA.
  121. *
  122. * @param base DMIC peripheral base address
  123. * @param handle Pointer to dmic_dma_handle_t structure
  124. */
  125. void DMIC_TransferAbortReceiveDMA(DMIC_Type *base, dmic_dma_handle_t *handle);
  126. /*!
  127. * @brief Get the number of bytes that have been received.
  128. *
  129. * This function gets the number of bytes that have been received.
  130. *
  131. * @param base DMIC peripheral base address.
  132. * @param handle DMIC handle pointer.
  133. * @param count Receive bytes count.
  134. * @retval kStatus_NoTransferInProgress No receive in progress.
  135. * @retval kStatus_InvalidArgument Parameter is invalid.
  136. * @retval kStatus_Success Get successfully through the parameter count;
  137. */
  138. status_t DMIC_TransferGetReceiveCountDMA(DMIC_Type *base, dmic_dma_handle_t *handle, uint32_t *count);
  139. /* @} */
  140. #if defined(__cplusplus)
  141. }
  142. #endif
  143. /*! @}*/
  144. #endif /* _FSL_DMIC_DMA_H_ */