fsl_i2c_edma.h 5.6 KB

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