fsl_i2c_edma.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_I2C_DMA_H_
  31. #define _FSL_I2C_DMA_H_
  32. #include "fsl_i2c.h"
  33. #include "fsl_dmamux.h"
  34. #include "fsl_edma.h"
  35. /*!
  36. * @addtogroup i2c_edma_driver
  37. * @{
  38. */
  39. /*******************************************************************************
  40. * Definitions
  41. ******************************************************************************/
  42. /*! @brief I2C master eDMA handle typedef. */
  43. typedef struct _i2c_master_edma_handle i2c_master_edma_handle_t;
  44. /*! @brief I2C master eDMA transfer callback typedef. */
  45. typedef void (*i2c_master_edma_transfer_callback_t)(I2C_Type *base,
  46. i2c_master_edma_handle_t *handle,
  47. status_t status,
  48. void *userData);
  49. /*! @brief I2C master eDMA transfer structure. */
  50. struct _i2c_master_edma_handle
  51. {
  52. i2c_master_transfer_t transfer; /*!< I2C master transfer structure. */
  53. size_t transferSize; /*!< Total bytes to be transferred. */
  54. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  55. uint8_t state; /*!< I2C master transfer status. */
  56. edma_handle_t *dmaHandle; /*!< The eDMA handler used. */
  57. i2c_master_edma_transfer_callback_t
  58. completionCallback; /*!< A callback function called after the eDMA transfer is finished. */
  59. void *userData; /*!< A callback parameter passed to the callback function. */
  60. };
  61. /*******************************************************************************
  62. * API
  63. ******************************************************************************/
  64. #if defined(__cplusplus)
  65. extern "C" {
  66. #endif /*_cplusplus. */
  67. /*!
  68. * @name I2C Block eDMA Transfer Operation
  69. * @{
  70. */
  71. /*!
  72. * @brief Initializes the I2C handle which is used in transcational functions.
  73. *
  74. * @param base I2C peripheral base address.
  75. * @param handle A pointer to the i2c_master_edma_handle_t structure.
  76. * @param callback A pointer to the user callback function.
  77. * @param userData A user parameter passed to the callback function.
  78. * @param edmaHandle eDMA handle pointer.
  79. */
  80. void I2C_MasterCreateEDMAHandle(I2C_Type *base,
  81. i2c_master_edma_handle_t *handle,
  82. i2c_master_edma_transfer_callback_t callback,
  83. void *userData,
  84. edma_handle_t *edmaHandle);
  85. /*!
  86. * @brief Performs a master eDMA non-blocking transfer on the I2C bus.
  87. *
  88. * @param base I2C peripheral base address.
  89. * @param handle A pointer to the i2c_master_edma_handle_t structure.
  90. * @param xfer A pointer to the transfer structure of i2c_master_transfer_t.
  91. * @retval kStatus_Success Sucessfully completed the data transmission.
  92. * @retval kStatus_I2C_Busy A previous transmission is still not finished.
  93. * @retval kStatus_I2C_Timeout Transfer error, waits for a signal timeout.
  94. * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
  95. * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
  96. */
  97. status_t I2C_MasterTransferEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle, i2c_master_transfer_t *xfer);
  98. /*!
  99. * @brief Gets a master transfer status during the eDMA non-blocking transfer.
  100. *
  101. * @param base I2C peripheral base address.
  102. * @param handle A pointer to the i2c_master_edma_handle_t structure.
  103. * @param count A number of bytes transferred by the non-blocking transaction.
  104. */
  105. status_t I2C_MasterTransferGetCountEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle, size_t *count);
  106. /*!
  107. * @brief Aborts a master eDMA non-blocking transfer early.
  108. *
  109. * @param base I2C peripheral base address.
  110. * @param handle A pointer to the i2c_master_edma_handle_t structure.
  111. */
  112. void I2C_MasterTransferAbortEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle);
  113. /* @} */
  114. #if defined(__cplusplus)
  115. }
  116. #endif /*_cplusplus. */
  117. /*@}*/
  118. #endif /*_FSL_I2C_DMA_H_*/