fsl_i2c_dma.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_I2C_DMA_H_
  35. #define _FSL_I2C_DMA_H_
  36. #include "fsl_i2c.h"
  37. #include "fsl_dma.h"
  38. /*!
  39. * @addtogroup i2c_dma_driver
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @name Driver version */
  46. /*@{*/
  47. /*! @brief I2C DMA driver version 2.0.3. */
  48. #define FSL_I2C_DMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
  49. /*@}*/
  50. /*! @brief Maximum lenght of single DMA transfer (determined by capability of the DMA engine) */
  51. #define I2C_MAX_DMA_TRANSFER_COUNT 1024
  52. /*! @brief I2C master dma handle typedef. */
  53. typedef struct _i2c_master_dma_handle i2c_master_dma_handle_t;
  54. /*! @brief I2C master dma transfer callback typedef. */
  55. typedef void (*i2c_master_dma_transfer_callback_t)(I2C_Type *base,
  56. i2c_master_dma_handle_t *handle,
  57. status_t status,
  58. void *userData);
  59. /*! @brief I2C master dma transfer structure. */
  60. struct _i2c_master_dma_handle
  61. {
  62. uint8_t state; /*!< Transfer state machine current state. */
  63. uint32_t transferCount; /*!< Indicates progress of the transfer */
  64. uint32_t remainingBytesDMA; /*!< Remaining byte count to be transferred using DMA. */
  65. uint8_t *buf; /*!< Buffer pointer for current state. */
  66. uint32_t remainingSubaddr;
  67. uint8_t subaddrBuf[4];
  68. dma_handle_t *dmaHandle; /*!< The DMA handler used. */
  69. i2c_master_transfer_t transfer; /*!< Copy of the current transfer info. */
  70. i2c_master_dma_transfer_callback_t completionCallback; /*!< Callback function called after dma transfer finished. */
  71. void *userData; /*!< Callback parameter passed to callback function. */
  72. };
  73. /*******************************************************************************
  74. * API
  75. ******************************************************************************/
  76. #if defined(__cplusplus)
  77. extern "C" {
  78. #endif /*_cplusplus. */
  79. /*!
  80. * @name I2C Block DMA Transfer Operation
  81. * @{
  82. */
  83. /*!
  84. * @brief Init the I2C handle which is used in transcational functions
  85. *
  86. * @param base I2C peripheral base address
  87. * @param handle pointer to i2c_master_dma_handle_t structure
  88. * @param callback pointer to user callback function
  89. * @param userData user param passed to the callback function
  90. * @param dmaHandle DMA handle pointer
  91. */
  92. void I2C_MasterTransferCreateHandleDMA(I2C_Type *base,
  93. i2c_master_dma_handle_t *handle,
  94. i2c_master_dma_transfer_callback_t callback,
  95. void *userData,
  96. dma_handle_t *dmaHandle);
  97. /*!
  98. * @brief Performs a master dma non-blocking transfer on the I2C bus
  99. *
  100. * @param base I2C peripheral base address
  101. * @param handle pointer to i2c_master_dma_handle_t structure
  102. * @param xfer pointer to transfer structure of i2c_master_transfer_t
  103. * @retval kStatus_Success Sucessully complete the data transmission.
  104. * @retval kStatus_I2C_Busy Previous transmission still not finished.
  105. * @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
  106. * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
  107. * @retval kStataus_I2C_Nak Transfer error, receive Nak during transfer.
  108. */
  109. status_t I2C_MasterTransferDMA(I2C_Type *base, i2c_master_dma_handle_t *handle, i2c_master_transfer_t *xfer);
  110. /*!
  111. * @brief Get master transfer status during a dma non-blocking transfer
  112. *
  113. * @param base I2C peripheral base address
  114. * @param handle pointer to i2c_master_dma_handle_t structure
  115. * @param count Number of bytes transferred so far by the non-blocking transaction.
  116. */
  117. status_t I2C_MasterTransferGetCountDMA(I2C_Type *base, i2c_master_dma_handle_t *handle, size_t *count);
  118. /*!
  119. * @brief Abort a master dma non-blocking transfer in a early time
  120. *
  121. * @param base I2C peripheral base address
  122. * @param handle pointer to i2c_master_dma_handle_t structure
  123. */
  124. void I2C_MasterTransferAbortDMA(I2C_Type *base, i2c_master_dma_handle_t *handle);
  125. /* @} */
  126. #if defined(__cplusplus)
  127. }
  128. #endif /*_cplusplus. */
  129. /*@}*/
  130. #endif /*_FSL_I2C_DMA_H_*/