fsl_i2c_edma.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_edma.h"
  38. /*!
  39. * @addtogroup i2c_edma_driver
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @name Driver version */
  46. /*@{*/
  47. /*! @brief I2C EDMA driver version 2.0.5. */
  48. #define FSL_I2C_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 5))
  49. /*@}*/
  50. /*! @brief I2C master eDMA handle typedef. */
  51. typedef struct _i2c_master_edma_handle i2c_master_edma_handle_t;
  52. /*! @brief I2C master eDMA transfer callback typedef. */
  53. typedef void (*i2c_master_edma_transfer_callback_t)(I2C_Type *base,
  54. i2c_master_edma_handle_t *handle,
  55. status_t status,
  56. void *userData);
  57. /*! @brief I2C master eDMA transfer structure. */
  58. struct _i2c_master_edma_handle
  59. {
  60. i2c_master_transfer_t transfer; /*!< I2C master transfer structure. */
  61. size_t transferSize; /*!< Total bytes to be transferred. */
  62. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  63. uint8_t state; /*!< I2C master transfer status. */
  64. edma_handle_t *dmaHandle; /*!< The eDMA handler used. */
  65. i2c_master_edma_transfer_callback_t
  66. completionCallback; /*!< A callback function called after the eDMA transfer is finished. */
  67. void *userData; /*!< A callback parameter passed to the callback function. */
  68. };
  69. /*******************************************************************************
  70. * API
  71. ******************************************************************************/
  72. #if defined(__cplusplus)
  73. extern "C" {
  74. #endif /*_cplusplus. */
  75. /*!
  76. * @name I2C Block eDMA Transfer Operation
  77. * @{
  78. */
  79. /*!
  80. * @brief Initializes the I2C handle which is used in transcational functions.
  81. *
  82. * @param base I2C peripheral base address.
  83. * @param handle A pointer to the i2c_master_edma_handle_t structure.
  84. * @param callback A pointer to the user callback function.
  85. * @param userData A user parameter passed to the callback function.
  86. * @param edmaHandle eDMA handle pointer.
  87. */
  88. void I2C_MasterCreateEDMAHandle(I2C_Type *base,
  89. i2c_master_edma_handle_t *handle,
  90. i2c_master_edma_transfer_callback_t callback,
  91. void *userData,
  92. edma_handle_t *edmaHandle);
  93. /*!
  94. * @brief Performs a master eDMA non-blocking transfer on the I2C bus.
  95. *
  96. * @param base I2C peripheral base address.
  97. * @param handle A pointer to the i2c_master_edma_handle_t structure.
  98. * @param xfer A pointer to the transfer structure of i2c_master_transfer_t.
  99. * @retval kStatus_Success Sucessfully completed the data transmission.
  100. * @retval kStatus_I2C_Busy A previous transmission is still not finished.
  101. * @retval kStatus_I2C_Timeout Transfer error, waits for a signal timeout.
  102. * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
  103. * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
  104. */
  105. status_t I2C_MasterTransferEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle, i2c_master_transfer_t *xfer);
  106. /*!
  107. * @brief Gets a master transfer status during the eDMA non-blocking transfer.
  108. *
  109. * @param base I2C peripheral base address.
  110. * @param handle A pointer to the i2c_master_edma_handle_t structure.
  111. * @param count A number of bytes transferred by the non-blocking transaction.
  112. */
  113. status_t I2C_MasterTransferGetCountEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle, size_t *count);
  114. /*!
  115. * @brief Aborts a master eDMA non-blocking transfer early.
  116. *
  117. * @param base I2C peripheral base address.
  118. * @param handle A pointer to the i2c_master_edma_handle_t structure.
  119. */
  120. void I2C_MasterTransferAbortEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle);
  121. /* @} */
  122. #if defined(__cplusplus)
  123. }
  124. #endif /*_cplusplus. */
  125. /*@}*/
  126. #endif /*_FSL_I2C_DMA_H_*/