/** * @file IxI2cDrv.h * * @brief Header file for the IXP400 I2C Driver (IxI2cDrv) * * @version $Revision: 0.1 $ * * @par * IXP400 SW Release version 2.0 * * -- Copyright Notice -- * * @par * Copyright 2001-2005, Intel Corporation. * All rights reserved. * * @par * SPDX-License-Identifier: BSD-3-Clause * @par * -- End of Copyright Notice -- */ /** * @defgroup IxI2cDrv IXP400 I2C Driver(IxI2cDrv) API * * @brief IXP400 I2C Driver Public API * * @{ */ #ifndef IXI2CDRV_H #define IXI2CDRV_H #ifdef __ixp46X #include "IxOsal.h" /* * Section for #define */ /** * @ingroup IxI2cDrv * @brief The interval of micro/mili seconds the IXP will wait before it polls for * status from the ixI2cIntrXferStatus; Every 20us is 1 byte @ * 400Kbps and 4 bytes @ 100Kbps. This is dependent on delay type selected * through the API ixI2cDrvDelayTypeSelect. */ #define IX_I2C_US_POLL_FOR_XFER_STATUS 20 /** * @ingroup IxI2cDrv * @brief The number of tries that will be attempted to call a callback * function if the callback does not or is unable to resolve the * issue it is called to resolve */ #define IX_I2C_NUM_OF_TRIES_TO_CALL_CALLBACK_FUNC 10 /** * @ingroup IxI2cDrv * @brief Number of tries slave will poll the IDBR Rx full bit before it * gives up */ #define IX_I2C_NUM_TO_POLL_IDBR_RX_FULL 0x100 /** * @ingroup IxI2cDrv * @brief Number of tries slave will poll the IDBR Tx empty bit before it * gives up */ #define IX_I2C_NUM_TO_POLL_IDBR_TX_EMPTY 0x100 /* * Section for enum */ /** * @ingroup IxI2cDrv * * @enum IxI2cMasterStatus * * @brief The master status - transfer complete, bus error or arbitration loss */ typedef enum { IX_I2C_MASTER_XFER_COMPLETE = IX_SUCCESS, IX_I2C_MASTER_XFER_BUS_ERROR, IX_I2C_MASTER_XFER_ARB_LOSS } IxI2cMasterStatus; /** * @ingroup IxI2cDrv * * @enum IX_I2C_STATUS * * @brief The status that can be returned in a I2C driver initialization */ typedef enum { IX_I2C_SUCCESS = IX_SUCCESS, /**< Success status */ IX_I2C_FAIL, /**< Fail status */ IX_I2C_NOT_SUPPORTED, /**< hardware does not have dedicated I2C hardware */ IX_I2C_NULL_POINTER, /**< parameter passed in is NULL */ IX_I2C_INVALID_SPEED_MODE_ENUM_VALUE, /**< speed mode selected is invalid */ IX_I2C_INVALID_FLOW_MODE_ENUM_VALUE, /**< flow mode selected is invalid */ IX_I2C_SLAVE_ADDR_CB_MISSING, /**< slave callback is NULL */ IX_I2C_GEN_CALL_CB_MISSING, /**< general callback is NULL */ IX_I2C_INVALID_SLAVE_ADDR, /**< invalid slave address specified */ IX_I2C_INT_BIND_FAIL, /**< interrupt bind fail */ IX_I2C_INT_UNBIND_FAIL, /**< interrupt unbind fail */ IX_I2C_NOT_INIT, /**< I2C is not initialized yet */ IX_I2C_MASTER_BUS_BUSY, /**< master detected a I2C bus busy */ IX_I2C_MASTER_ARB_LOSS, /**< master experienced arbitration loss */ IX_I2C_MASTER_XFER_ERROR, /**< master experienced a transfer error */ IX_I2C_MASTER_BUS_ERROR, /**< master detected a I2C bus error */ IX_I2C_MASTER_NO_BUFFER, /**< no buffer provided for master transfer */ IX_I2C_MASTER_INVALID_XFER_MODE, /**< xfer mode selected is invalid */ IX_I2C_SLAVE_ADDR_NOT_DETECTED, /**< polled slave addr not detected */ IX_I2C_GEN_CALL_ADDR_DETECTED, /**< polling detected general call */ IX_I2C_SLAVE_READ_DETECTED, /**< polling detected slave read request */ IX_I2C_SLAVE_WRITE_DETECTED, /**< polling detected slave write request */ IX_I2C_SLAVE_NO_BUFFER, /**< no buffer provided for slave transfers */ IX_I2C_DATA_SIZE_ZERO, /**< data size transfer is zero - invalid */ IX_I2C_SLAVE_WRITE_BUFFER_EMPTY, /**< slave buffer is used till empty */ IX_I2C_SLAVE_WRITE_ERROR, /**< slave write experienced an error */ IX_I2C_SLAVE_OR_GEN_READ_BUFFER_FULL, /**< slave buffer is filled up */ IX_I2C_SLAVE_OR_GEN_READ_ERROR /**< slave read experienced an error */ } IX_I2C_STATUS; /** * @ingroup IxI2cDrv * * @enum IxI2cSpeedMode * * @brief Type of speed modes supported by the I2C hardware. */ typedef enum { IX_I2C_NORMAL_MODE = 0x0, IX_I2C_FAST_MODE } IxI2cSpeedMode; /** * @ingroup IxI2cDrv * * @enum IxI2cXferMode * * @brief Used for indicating it is a repeated start or normal transfer */ typedef enum { IX_I2C_NORMAL = 0x0, IX_I2C_REPEATED_START } IxI2cXferMode; /** * @ingroup IxI2cDrv * * @enum IxI2cFlowMode * * @brief Used for indicating it is a poll or interrupt mode */ typedef enum { IX_I2C_POLL_MODE = 0x0, IX_I2C_INTERRUPT_MODE } IxI2cFlowMode; /** * @ingroup IxI2cDrv * * @enum IxI2cDelayMode * * @brief Used for selecting looping delay or OS scheduler delay */ typedef enum { IX_I2C_LOOP_DELAY = 1, /**< delay in microseconds */ IX_I2C_SCHED_DELAY /**< delay in miliseconds */ } IxI2cDelayMode; /** * @ingroup IxI2cDrv * * @brief The pointer to the function that will be called when the master * has completed its receive. The parameter that is passed will * provide the status of the read (success, arb loss, or bus * error), the transfer mode (normal or repeated start, the * buffer pointer and number of bytes transferred. */ typedef void (*IxI2cMasterReadCallbackP)(IxI2cMasterStatus, IxI2cXferMode, char*, UINT32); /** * @ingroup IxI2cDrv * * @brief The pointer to the function that will be called when the master * has completed its transmit. The parameter that is passed will * provide the status of the write (success, arb loss, or buss * error), the transfer mode (normal or repeated start), the * buffer pointer and number of bytes transferred. */ typedef void (*IxI2cMasterWriteCallbackP)(IxI2cMasterStatus, IxI2cXferMode, char*, UINT32); /** * @ingroup IxI2cDrv * * @brief The pointer to the function that will be called when a slave * address detected in interrupt mode for a read. The parameters * that is passed will provide the read status, buffer pointer, * buffer size, and the bytes received. When a start of a read * is initiated there will be no buffer allocated and this callback * will be called to request for a buffer. While receiving, if the * buffer gets filled, this callback will be called to request for * a new buffer while sending the filled buffer's pointer and size, * and data size received. When the receive is complete, this * callback will be called to process the data and free the memory * by passing the buffer's pointer and size, and data size received. */ typedef void (*IxI2cSlaveReadCallbackP)(IX_I2C_STATUS, char*, UINT32, UINT32); /** * @ingroup IxI2cDrv * * @brief The pointer to the function that will be called when a slave * address detected in interrupt mode for a write. The parameters * that is passed will provide the write status, buffer pointer, * buffer size, and the bytes received. When a start of a write is * initiated there will be no buffer allocated and this callback * will be called to request for a buffer and to fill it with data. * While transmitting, if the data in the buffer empties, this * callback will be called to request for more data to be filled in * the same or new buffer. When the transmit is complete, this * callback will be called to free the memory or other actions to * be taken. */ typedef void (*IxI2cSlaveWriteCallbackP)(IX_I2C_STATUS, char*, UINT32, UINT32); /** * @ingroup IxI2cDrv * * @brief The pointer to the function that will be called when a general * call detected in interrupt mode for a read. The parameters that * is passed will provide the read status, buffer pointer, buffer * size, and the bytes received. When a start of a read is * initiated there will be no buffer allocated and this callback * will be called to request for a buffer. While receiving, if the * buffer gets filled, this callback will be called to request for * a new buffer while sending the filled buffer's pointer and size, * and data size received. When the receive is complete, this * callback will be called to process the data and free the memory * by passing the buffer's pointer and size, and data size received. */ typedef void (*IxI2cGenCallCallbackP)(IX_I2C_STATUS, char*, UINT32, UINT32); /* * Section for struct */ /** * @brief contains all the variables required to initialize the I2C unit * * Structure to be filled and used for calling initialization */ typedef struct { IxI2cSpeedMode I2cSpeedSelect; /**