1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2020 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 #ifndef _FSL_I2C_DMA_H_ 9 #define _FSL_I2C_DMA_H_ 10 11 #include "fsl_i2c.h" 12 #include "fsl_edma.h" 13 14 /*! 15 * @addtogroup i2c_edma_driver 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*@{*/ 25 /*! @brief I2C EDMA driver version. */ 26 #define FSL_I2C_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 9)) 27 /*@}*/ 28 29 /*! @brief Retry times for waiting flag. */ 30 #ifndef I2C_RETRY_TIMES 31 #define I2C_RETRY_TIMES 0U /* Define to zero means keep waiting until the flag is assert/deassert. */ 32 #endif 33 34 /*! @brief I2C master eDMA handle typedef. */ 35 typedef struct _i2c_master_edma_handle i2c_master_edma_handle_t; 36 37 /*! @brief I2C master eDMA transfer callback typedef. */ 38 typedef void (*i2c_master_edma_transfer_callback_t)(I2C_Type *base, 39 i2c_master_edma_handle_t *handle, 40 status_t status, 41 void *userData); 42 43 /*! @brief I2C master eDMA transfer structure. */ 44 struct _i2c_master_edma_handle 45 { 46 i2c_master_transfer_t transfer; /*!< I2C master transfer structure. */ 47 size_t transferSize; /*!< Total bytes to be transferred. */ 48 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 49 uint8_t state; /*!< I2C master transfer status. */ 50 edma_handle_t *dmaHandle; /*!< The eDMA handler used. */ 51 i2c_master_edma_transfer_callback_t 52 completionCallback; /*!< A callback function called after the eDMA transfer is finished. */ 53 void *userData; /*!< A callback parameter passed to the callback function. */ 54 }; 55 56 /******************************************************************************* 57 * API 58 ******************************************************************************/ 59 60 #if defined(__cplusplus) 61 extern "C" { 62 #endif /*_cplusplus. */ 63 64 /*! 65 * @name I2C Block eDMA Transfer Operation 66 * @{ 67 */ 68 69 /*! 70 * @brief Initializes the I2C handle which is used in transactional functions. 71 * 72 * @param base I2C peripheral base address. 73 * @param handle A pointer to the i2c_master_edma_handle_t structure. 74 * @param callback A pointer to the user callback function. 75 * @param userData A user parameter passed to the callback function. 76 * @param edmaHandle eDMA handle pointer. 77 */ 78 void I2C_MasterCreateEDMAHandle(I2C_Type *base, 79 i2c_master_edma_handle_t *handle, 80 i2c_master_edma_transfer_callback_t callback, 81 void *userData, 82 edma_handle_t *edmaHandle); 83 84 /*! 85 * @brief Performs a master eDMA non-blocking transfer on the I2C bus. 86 * 87 * @param base I2C peripheral base address. 88 * @param handle A pointer to the i2c_master_edma_handle_t structure. 89 * @param xfer A pointer to the transfer structure of i2c_master_transfer_t. 90 * @retval kStatus_Success Successfully completed the data transmission. 91 * @retval kStatus_I2C_Busy A previous transmission is still not finished. 92 * @retval kStatus_I2C_Timeout Transfer error, waits for a signal timeout. 93 * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost. 94 * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer. 95 */ 96 status_t I2C_MasterTransferEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle, i2c_master_transfer_t *xfer); 97 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 /*! 108 * @brief Aborts a master eDMA non-blocking transfer early. 109 * 110 * @param base I2C peripheral base address. 111 * @param handle A pointer to the i2c_master_edma_handle_t structure. 112 */ 113 void I2C_MasterTransferAbortEDMA(I2C_Type *base, i2c_master_edma_handle_t *handle); 114 115 /* @} */ 116 #if defined(__cplusplus) 117 } 118 #endif /*_cplusplus. */ 119 /*@}*/ 120 #endif /*_FSL_I2C_DMA_H_*/ 121