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