📄 xiic.h
字号:
* without rearbitrating for the bus. The messages * are sent as a series of messages such that the * option must be enabled before the 1st message of * the series, to prevent an stop condition from * being generated on the bus, and disabled before * the last message of the series, to allow the * stop condition to be generated. * * XII_SEND_10_BIT_OPTION The send 10 bit option allows 10 bit addresses * to be sent on the bus when the device is a * master. The device can be configured to respond * as to 7 bit addresses even though it may be * communicating with other devices that support 10 * bit addresses. When this option is not enabled, * only 7 bit addresses are sent on the bus. * * </pre> */#define XII_GENERAL_CALL_OPTION 0x00000001#define XII_REPEATED_START_OPTION 0x00000002#define XII_SEND_10_BIT_OPTION 0x00000004/*@}*//** @name Status events * * The following status events occur during IIC bus processing and are passed * to the status callback. Each event is only valid during the appropriate * processing of the IIC bus. Each of these events are bit fields such that * more than one may be specified. * @{ *//** * <pre> * XII_BUS_NOT_BUSY_EVENT bus transitioned to not busy * XII_ARB_LOST_EVENT arbitration was lost * XII_SLAVE_NO_ACK_EVENT slave did not acknowledge data (had error) * XII_MASTER_READ_EVENT master reading from slave * XII_MASTER_WRITE_EVENT master writing to slave * XII_GENERAL_CALL_EVENT general call to all slaves * </pre> */#define XII_BUS_NOT_BUSY_EVENT 0x00000001#define XII_ARB_LOST_EVENT 0x00000002#define XII_SLAVE_NO_ACK_EVENT 0x00000004#define XII_MASTER_READ_EVENT 0x00000008#define XII_MASTER_WRITE_EVENT 0x00000010#define XII_GENERAL_CALL_EVENT 0x00000020/*@}*//* The following address types are used when setting and getting the addresses * of the driver. These are mutually exclusive such that only one or the other * may be specified. *//** bus address of slave device */#define XII_ADDR_TO_SEND_TYPE 1/** this device's bus address when slave */#define XII_ADDR_TO_RESPOND_TYPE 2/**************************** Type Definitions *******************************//** * This typedef contains configuration information for the device. */typedef struct { u16 DeviceId; /**< Unique ID of device */ u32 BaseAddress;/**< Device base address */ int Has10BitAddr; /**< does device have 10 bit address decoding */ u8 GpOutWidth; /**< number of bits in general purpose output */} XIic_Config;/** * This callback function data type is defined to handle the asynchronous * processing of sent and received data of the IIC driver. The application * using this driver is expected to define a handler of this type to support * interrupt driven mode. The handlers are called in an interrupt context such * that minimal processing should be performed. The handler data type is * utilized for both send and receive handlers. * * @param CallBackRef is a callback reference passed in by the upper layer when * setting the callback functions, and passed back to the upper layer * when the callback is invoked. Its type is unimportant to the driver * component, so it is a void pointer. * * @param ByteCount indicates the number of bytes remaining to be sent or * received. A value of zero indicates that the requested number of * bytes were sent or received. */typedef void (*XIic_Handler) (void *CallBackRef, int ByteCount);/** * This callback function data type is defined to handle the asynchronous * processing of status events of the IIC driver. The application using * this driver is expected to define a handler of this type to support * interrupt driven mode. The handler is called in an interrupt context such * that minimal processing should be performed. * * @param CallBackRef is a callback reference passed in by the upper layer when * setting the callback functions, and passed back to the upper layer * when the callback is invoked. Its type is unimportant to the driver * component, so it is a void pointer. * * @param StatusEvent indicates one or more status events that occurred. See * the definition of the status events above. */typedef void (*XIic_StatusHandler) (void *CallBackRef, int StatusEvent);/** * XIic statistics */typedef struct { u8 ArbitrationLost;/**< Number of times arbitration was lost */ u8 RepeatedStarts; /**< Number of repeated starts */ u8 BusBusy; /**< Number of times bus busy status returned */ u8 RecvBytes; /**< Number of bytes received */ u8 RecvInterrupts; /**< Number of receive interrupts */ u8 SendBytes; /**< Number of transmit bytes received */ u8 SendInterrupts; /**< Number of transmit interrupts */ u8 TxErrors; /**< Number of transmit errors (no ack) */ u8 IicInterrupts; /**< Number of IIC (device) interrupts */} XIicStats;/** * The XIic driver instance data. The user is required to allocate a * variable of this type for every IIC device in the system. A pointer * to a variable of this type is then passed to the driver API functions. */typedef struct { XIicStats Stats; /* Statistics */ u32 BaseAddress; /* Device base address */ int Has10BitAddr; /* TRUE when 10 bit addressing in design */ int IsReady; /* Device is initialized and ready */ int IsStarted; /* Device has been started */ int AddrOfSlave; /* Slave addr writing to */ u32 Options; /* current operating options */ u8 *SendBufferPtr; /* Buffer to send (state) */ u8 *RecvBufferPtr; /* Buffer to receive (state) */ u8 TxAddrMode; /* State of Tx Address transmission */ int SendByteCount; /* Number of data bytes in buffer (state) */ int RecvByteCount; /* Number of empty bytes in buffer (state) */ u32 BNBOnly; /* TRUE when BNB interrupt needs to */ /* call callback */ u8 GpOutWidth; /* General purpose output width */ XIic_StatusHandler StatusHandler; void *StatusCallBackRef; /* Callback reference for status handler */ XIic_Handler RecvHandler; void *RecvCallBackRef; /* Callback reference for recv handler */ XIic_Handler SendHandler; void *SendCallBackRef; /* Callback reference for send handler */ int IsDynamic;} XIic;/***************** Macros (Inline Functions) Definitions *********************//************************** Function Prototypes ******************************//* * Initialization functions in xiic_sinit.c */int XIic_Initialize(XIic * InstancePtr, u16 DeviceId);XIic_Config *XIic_LookupConfig(u16 DeviceId);/* * Required functions in xiic.c */int XIic_CfgInitialize(XIic * InstancePtr, XIic_Config * Config, u32 EffectiveAddr);int XIic_Start(XIic * InstancePtr);int XIic_Stop(XIic * InstancePtr);void XIic_Reset(XIic * InstancePtr);int XIic_SetAddress(XIic * InstancePtr, int AddressType, int Address);u16 XIic_GetAddress(XIic * InstancePtr, int AddressType);int XIic_SetGpOutput(XIic * InstancePtr, u8 OutputValue);int XIic_GetGpOutput(XIic * InstancePtr, u8 *OutputValuePtr);u32 XIic_IsSlave(XIic * InstancePtr);void XIic_SetRecvHandler(XIic * InstancePtr, void *CallBackRef, XIic_Handler FuncPtr);void XIic_SetSendHandler(XIic * InstancePtr, void *CallBackRef, XIic_Handler FuncPtr);void XIic_SetStatusHandler(XIic * InstancePtr, void *CallBackRef, XIic_StatusHandler FuncPtr);/* * Interrupt functions in xiic_intr.c */void XIic_InterruptHandler(void *InstancePtr);/* * Master send and receive functions in normal mode in xiic_master.c */int XIic_MasterRecv(XIic * InstancePtr, u8 *RxMsgPtr, int ByteCount);int XIic_MasterSend(XIic * InstancePtr, u8 *TxMsgPtr, int ByteCount);/* * Master send and receive functions in dynamic mode in xiic_master.c */int XIic_DynMasterRecv(XIic * InstancePtr, u8 *RxMsgPtr, u8 ByteCount);int XIic_DynMasterSend(XIic * InstancePtr, u8 *TxMsgPtr, u8 ByteCount);/* * Dynamic IIC Core Initialization. */int XIic_DynamicInitialize(XIic * InstancePtr);/* * Slave send and receive functions in xiic_slave.c */void XIic_SlaveInclude(void);int XIic_SlaveRecv(XIic * InstancePtr, u8 *RxMsgPtr, int ByteCount);int XIic_SlaveSend(XIic * InstancePtr, u8 *TxMsgPtr, int ByteCount);/* * Statistics functions in xiic_stats.c */void XIic_GetStats(XIic * InstancePtr, XIicStats * StatsPtr);void XIic_ClearStats(XIic * InstancePtr);/* * Self test functions in xiic_selftest.c */int XIic_SelfTest(XIic * InstancePtr);/* * Bus busy Function in xiic.c */u32 XIic_IsIicBusy(XIic * InstancePtr);/* * Options functions in xiic_options.c */void XIic_SetOptions(XIic * InstancePtr, u32 Options);u32 XIic_GetOptions(XIic * InstancePtr);/* * Multi-master functions in xiic_multi_master.c */void XIic_MultiMasterInclude(void);#ifdef __cplusplus}#endif#endif /* end of protection macro */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -