fsl_lpi2c_edma.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2021 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_LPI2C_EDMA_H_
  9. #define _FSL_LPI2C_EDMA_H_
  10. #include "fsl_lpi2c.h"
  11. #include "fsl_edma.h"
  12. /*******************************************************************************
  13. * Definitions
  14. ******************************************************************************/
  15. /*! @name Driver version */
  16. /*@{*/
  17. /*! @brief LPI2C EDMA driver version. */
  18. #define FSL_LPI2C_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 3, 0))
  19. /*@}*/
  20. /*!
  21. * @addtogroup lpi2c_master_edma_driver
  22. * @{
  23. */
  24. /* Forward declaration of the transfer descriptor and handle typedefs. */
  25. typedef struct _lpi2c_master_edma_handle lpi2c_master_edma_handle_t;
  26. /*!
  27. * @brief Master DMA completion callback function pointer type.
  28. *
  29. * This callback is used only for the non-blocking master transfer API. Specify the callback you wish to use
  30. * in the call to LPI2C_MasterCreateEDMAHandle().
  31. *
  32. * @param base The LPI2C peripheral base address.
  33. * @param handle Handle associated with the completed transfer.
  34. * @param completionStatus Either kStatus_Success or an error code describing how the transfer completed.
  35. * @param userData Arbitrary pointer-sized value passed from the application.
  36. */
  37. typedef void (*lpi2c_master_edma_transfer_callback_t)(LPI2C_Type *base,
  38. lpi2c_master_edma_handle_t *handle,
  39. status_t completionStatus,
  40. void *userData);
  41. /*!
  42. * @brief Driver handle for master DMA APIs.
  43. * @note The contents of this structure are private and subject to change.
  44. */
  45. struct _lpi2c_master_edma_handle
  46. {
  47. LPI2C_Type *base; /*!< LPI2C base pointer. */
  48. bool isBusy; /*!< Transfer state machine current state. */
  49. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  50. uint16_t commandBuffer[10]; /*!< LPI2C command sequence. When all 10 command words are used:
  51. Start&addr&write[1 word] + subaddr[4 words] + restart&addr&read[1 word] + receive&Size[4 words] */
  52. lpi2c_master_transfer_t transfer; /*!< Copy of the current transfer info. */
  53. lpi2c_master_edma_transfer_callback_t completionCallback; /*!< Callback function pointer. */
  54. void *userData; /*!< Application data passed to callback. */
  55. edma_handle_t *rx; /*!< Handle for receive DMA channel. */
  56. edma_handle_t *tx; /*!< Handle for transmit DMA channel. */
  57. edma_tcd_t tcds[3]; /*!< Software TCD. Three are allocated to provide enough room to align to 32-bytes. */
  58. };
  59. /*! @} */
  60. /*******************************************************************************
  61. * API
  62. ******************************************************************************/
  63. #if defined(__cplusplus)
  64. extern "C" {
  65. #endif
  66. /*!
  67. * @addtogroup lpi2c_master_edma_driver
  68. * @{
  69. */
  70. /*! @name Master DMA */
  71. /*@{*/
  72. /*!
  73. * @brief Create a new handle for the LPI2C master DMA APIs.
  74. *
  75. * The creation of a handle is for use with the DMA APIs. Once a handle
  76. * is created, there is not a corresponding destroy handle. If the user wants to
  77. * terminate a transfer, the LPI2C_MasterTransferAbortEDMA() API shall be called.
  78. *
  79. * For devices where the LPI2C send and receive DMA requests are OR'd together, the @a txDmaHandle
  80. * parameter is ignored and may be set to NULL.
  81. *
  82. * @param base The LPI2C peripheral base address.
  83. * @param[out] handle Pointer to the LPI2C master driver handle.
  84. * @param rxDmaHandle Handle for the eDMA receive channel. Created by the user prior to calling this function.
  85. * @param txDmaHandle Handle for the eDMA transmit channel. Created by the user prior to calling this function.
  86. * @param callback User provided pointer to the asynchronous callback function.
  87. * @param userData User provided pointer to the application callback data.
  88. */
  89. void LPI2C_MasterCreateEDMAHandle(LPI2C_Type *base,
  90. lpi2c_master_edma_handle_t *handle,
  91. edma_handle_t *rxDmaHandle,
  92. edma_handle_t *txDmaHandle,
  93. lpi2c_master_edma_transfer_callback_t callback,
  94. void *userData);
  95. /*!
  96. * @brief Performs a non-blocking DMA-based transaction on the I2C bus.
  97. *
  98. * The callback specified when the @a handle was created is invoked when the transaction has
  99. * completed.
  100. *
  101. * @param base The LPI2C peripheral base address.
  102. * @param handle Pointer to the LPI2C master driver handle.
  103. * @param transfer The pointer to the transfer descriptor.
  104. * @retval kStatus_Success The transaction was started successfully.
  105. * @retval #kStatus_LPI2C_Busy Either another master is currently utilizing the bus, or another DMA
  106. * transaction is already in progress.
  107. */
  108. status_t LPI2C_MasterTransferEDMA(LPI2C_Type *base,
  109. lpi2c_master_edma_handle_t *handle,
  110. lpi2c_master_transfer_t *transfer);
  111. /*!
  112. * @brief Returns number of bytes transferred so far.
  113. *
  114. * @param base The LPI2C peripheral base address.
  115. * @param handle Pointer to the LPI2C master driver handle.
  116. * @param[out] count Number of bytes transferred so far by the non-blocking transaction.
  117. * @retval kStatus_Success
  118. * @retval kStatus_NoTransferInProgress There is not a DMA transaction currently in progress.
  119. */
  120. status_t LPI2C_MasterTransferGetCountEDMA(LPI2C_Type *base, lpi2c_master_edma_handle_t *handle, size_t *count);
  121. /*!
  122. * @brief Terminates a non-blocking LPI2C master transmission early.
  123. *
  124. * @note It is not safe to call this function from an IRQ handler that has a higher priority than the
  125. * eDMA peripheral's IRQ priority.
  126. *
  127. * @param base The LPI2C peripheral base address.
  128. * @param handle Pointer to the LPI2C master driver handle.
  129. * @retval kStatus_Success A transaction was successfully aborted.
  130. * @retval #kStatus_LPI2C_Idle There is not a DMA transaction currently in progress.
  131. */
  132. status_t LPI2C_MasterTransferAbortEDMA(LPI2C_Type *base, lpi2c_master_edma_handle_t *handle);
  133. /*@}*/
  134. /*! @} */
  135. #if defined(__cplusplus)
  136. }
  137. #endif
  138. #endif /* _FSL_LPI2C_EDMA_H_ */