fsl_lpi2c_edma.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_LPI2C_EDMA_H_
  35. #define _FSL_LPI2C_EDMA_H_
  36. #include "fsl_lpi2c.h"
  37. #include "fsl_edma.h"
  38. /*******************************************************************************
  39. * Definitions
  40. ******************************************************************************/
  41. /*! @name Driver version */
  42. /*@{*/
  43. /*! @brief LPI2C EDMA driver version 2.1.5. */
  44. #define FSL_LPI2C_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 1, 5))
  45. /*@}*/
  46. /*!
  47. * @addtogroup lpi2c_master_edma_driver
  48. * @{
  49. */
  50. /* Forward declaration of the transfer descriptor and handle typedefs. */
  51. typedef struct _lpi2c_master_edma_handle lpi2c_master_edma_handle_t;
  52. /*!
  53. * @brief Master DMA completion callback function pointer type.
  54. *
  55. * This callback is used only for the non-blocking master transfer API. Specify the callback you wish to use
  56. * in the call to LPI2C_MasterCreateEDMAHandle().
  57. *
  58. * @param base The LPI2C peripheral base address.
  59. * @param handle Handle associated with the completed transfer.
  60. * @param completionStatus Either #kStatus_Success or an error code describing how the transfer completed.
  61. * @param userData Arbitrary pointer-sized value passed from the application.
  62. */
  63. typedef void (*lpi2c_master_edma_transfer_callback_t)(LPI2C_Type *base,
  64. lpi2c_master_edma_handle_t *handle,
  65. status_t completionStatus,
  66. void *userData);
  67. /*!
  68. * @brief Driver handle for master DMA APIs.
  69. * @note The contents of this structure are private and subject to change.
  70. */
  71. struct _lpi2c_master_edma_handle
  72. {
  73. LPI2C_Type *base; /*!< LPI2C base pointer. */
  74. bool isBusy; /*!< Transfer state machine current state. */
  75. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  76. uint16_t commandBuffer[7]; /*!< LPI2C command sequence. */
  77. lpi2c_master_transfer_t transfer; /*!< Copy of the current transfer info. */
  78. lpi2c_master_edma_transfer_callback_t completionCallback; /*!< Callback function pointer. */
  79. void *userData; /*!< Application data passed to callback. */
  80. edma_handle_t *rx; /*!< Handle for receive DMA channel. */
  81. edma_handle_t *tx; /*!< Handle for transmit DMA channel. */
  82. edma_tcd_t tcds[2]; /*!< Software TCD. Two are allocated to provide enough room to align to 32-bytes. */
  83. };
  84. /*! @} */
  85. /*******************************************************************************
  86. * API
  87. ******************************************************************************/
  88. #if defined(__cplusplus)
  89. extern "C" {
  90. #endif
  91. /*!
  92. * @addtogroup lpi2c_master_edma_driver
  93. * @{
  94. */
  95. /*! @name Master DMA */
  96. /*@{*/
  97. /*!
  98. * @brief Create a new handle for the LPI2C master DMA APIs.
  99. *
  100. * The creation of a handle is for use with the DMA APIs. Once a handle
  101. * is created, there is not a corresponding destroy handle. If the user wants to
  102. * terminate a transfer, the LPI2C_MasterTransferAbortEDMA() API shall be called.
  103. *
  104. * For devices where the LPI2C send and receive DMA requests are OR'd together, the @a txDmaHandle
  105. * parameter is ignored and may be set to NULL.
  106. *
  107. * @param base The LPI2C peripheral base address.
  108. * @param[out] handle Pointer to the LPI2C master driver handle.
  109. * @param rxDmaHandle Handle for the eDMA receive channel. Created by the user prior to calling this function.
  110. * @param txDmaHandle Handle for the eDMA transmit channel. Created by the user prior to calling this function.
  111. * @param callback User provided pointer to the asynchronous callback function.
  112. * @param userData User provided pointer to the application callback data.
  113. */
  114. void LPI2C_MasterCreateEDMAHandle(LPI2C_Type *base,
  115. lpi2c_master_edma_handle_t *handle,
  116. edma_handle_t *rxDmaHandle,
  117. edma_handle_t *txDmaHandle,
  118. lpi2c_master_edma_transfer_callback_t callback,
  119. void *userData);
  120. /*!
  121. * @brief Performs a non-blocking DMA-based transaction on the I2C bus.
  122. *
  123. * The callback specified when the @a handle was created is invoked when the transaction has
  124. * completed.
  125. *
  126. * @param base The LPI2C peripheral base address.
  127. * @param handle Pointer to the LPI2C master driver handle.
  128. * @param transfer The pointer to the transfer descriptor.
  129. * @retval #kStatus_Success The transaction was started successfully.
  130. * @retval #kStatus_LPI2C_Busy Either another master is currently utilizing the bus, or another DMA
  131. * transaction is already in progress.
  132. */
  133. status_t LPI2C_MasterTransferEDMA(LPI2C_Type *base,
  134. lpi2c_master_edma_handle_t *handle,
  135. lpi2c_master_transfer_t *transfer);
  136. /*!
  137. * @brief Returns number of bytes transferred so far.
  138. *
  139. * @param base The LPI2C peripheral base address.
  140. * @param handle Pointer to the LPI2C master driver handle.
  141. * @param[out] count Number of bytes transferred so far by the non-blocking transaction.
  142. * @retval #kStatus_Success
  143. * @retval #kStatus_NoTransferInProgress There is not a DMA transaction currently in progress.
  144. */
  145. status_t LPI2C_MasterTransferGetCountEDMA(LPI2C_Type *base, lpi2c_master_edma_handle_t *handle, size_t *count);
  146. /*!
  147. * @brief Terminates a non-blocking LPI2C master transmission early.
  148. *
  149. * @note It is not safe to call this function from an IRQ handler that has a higher priority than the
  150. * eDMA peripheral's IRQ priority.
  151. *
  152. * @param base The LPI2C peripheral base address.
  153. * @param handle Pointer to the LPI2C master driver handle.
  154. * @retval #kStatus_Success A transaction was successfully aborted.
  155. * @retval #kStatus_LPI2C_Idle There is not a DMA transaction currently in progress.
  156. */
  157. status_t LPI2C_MasterTransferAbortEDMA(LPI2C_Type *base, lpi2c_master_edma_handle_t *handle);
  158. /*@}*/
  159. /*! @} */
  160. #if defined(__cplusplus)
  161. }
  162. #endif
  163. #endif /* _FSL_LPI2C_EDMA_H_ */