#include "xil_types.h"
#include "xil_assert.h"
#include "xstatus.h"
#include "xiicps_hw.h"
Classes | |
struct | XIicPs_Config |
struct | XIicPs |
Defines | |
#define | XIICPS_H |
Configuration options | |
#define | XIICPS_7_BIT_ADDR_OPTION 0x01 |
#define | XIICPS_10_BIT_ADDR_OPTION 0x02 |
#define | XIICPS_SLAVE_MON_OPTION 0x04 |
#define | XIICPS_REP_START_OPTION 0x08 |
Callback events | |
#define | XIICPS_EVENT_COMPLETE_SEND 0x0001 |
#define | XIICPS_EVENT_COMPLETE_RECV 0x0002 |
#define | XIICPS_EVENT_TIME_OUT 0x0004 |
#define | XIICPS_EVENT_ERROR 0x0008 |
#define | XIICPS_EVENT_ARB_LOST 0x0010 |
#define | XIICPS_EVENT_NACK 0x0020 |
#define | XIICPS_EVENT_SLAVE_RDY 0x0040 |
#define | XIICPS_EVENT_RX_OVR 0x0080 |
#define | XIICPS_EVENT_TX_OVR 0x0100 |
#define | XIICPS_EVENT_RX_UNF 0x0200 |
Role constants | |
These constants are used to pass into the device setup routines to set up the device according to transfer direction. | |
#define | SENDING_ROLE 1 |
#define | RECVING_ROLE 0 |
#define | XIICPS_MAX_TRANSFER_SIZE (255 - 3) |
#define | XIicPs_SendByte(InstancePtr) |
#define | XIicPs_RecvByte(InstancePtr) |
typedef void(* | XIicPs_IntrHandler )(void *CallBackRef, u32 StatusEvent) |
XIicPs_Config * | XIicPs_LookupConfig (u16 DeviceId) |
int | XIicPs_CfgInitialize (XIicPs *InstancePtr, XIicPs_Config *Config, u32 EffectiveAddr) |
void | XIicPs_Abort (XIicPs *InstancePtr) |
void | XIicPs_Reset (XIicPs *InstancePtr) |
int | XIicPs_BusIsBusy (XIicPs *InstancePtr) |
void | XIicPs_SetStatusHandler (XIicPs *InstancePtr, void *CallBackRef, XIicPs_IntrHandler FuncPtr) |
void | XIicPs_MasterSend (XIicPs *InstancePtr, u8 *MsgPtr, int ByteCount, u16 SlaveAddr) |
void | XIicPs_MasterRecv (XIicPs *InstancePtr, u8 *MsgPtr, int ByteCount, u16 SlaveAddr) |
int | XIicPs_MasterSendPolled (XIicPs *InstancePtr, u8 *MsgPtr, int ByteCount, u16 SlaveAddr) |
int | XIicPs_MasterRecvPolled (XIicPs *InstancePtr, u8 *MsgPtr, int ByteCount, u16 SlaveAddr) |
void | XIicPs_EnableSlaveMonitor (XIicPs *InstancePtr, u16 SlaveAddr) |
void | XIicPs_DisableSlaveMonitor (XIicPs *InstancePtr) |
void | XIicPs_MasterInterruptHandler (XIicPs *InstancePtr) |
void | XIicPs_SetupSlave (XIicPs *InstancePtr, u16 SlaveAddr) |
void | XIicPs_SlaveSend (XIicPs *InstancePtr, u8 *MsgPtr, int ByteCount) |
void | XIicPs_SlaveRecv (XIicPs *InstancePtr, u8 *MsgPtr, int ByteCount) |
int | XIicPs_SlaveSendPolled (XIicPs *InstancePtr, u8 *MsgPtr, int ByteCount) |
int | XIicPs_SlaveRecvPolled (XIicPs *InstancePtr, u8 *MsgPtr, int ByteCount) |
void | XIicPs_SlaveInterruptHandler (XIicPs *InstancePtr) |
int | XIicPs_SelfTest (XIicPs *InstancePtr) |
int | XIicPs_SetOptions (XIicPs *InstancePtr, u32 Options) |
int | XIicPs_ClearOptions (XIicPs *InstancePtr, u32 Options) |
u32 | XIicPs_GetOptions (XIicPs *InstancePtr) |
int | XIicPs_SetSClk (XIicPs *InstancePtr, u32 FsclHz) |
u32 | XIicPs_GetSClk (XIicPs *InstancePtr) |
#define RECVING_ROLE 0 |
Transfer direction is receiving
#define SENDING_ROLE 1 |
Transfer direction is sending
#define XIICPS_10_BIT_ADDR_OPTION 0x02 |
10-bit address mode
#define XIICPS_7_BIT_ADDR_OPTION 0x01 |
7-bit address mode
#define XIICPS_EVENT_ARB_LOST 0x0010 |
Arbitration lost
#define XIICPS_EVENT_COMPLETE_RECV 0x0002 |
Receive Complete Event
#define XIICPS_EVENT_COMPLETE_SEND 0x0001 |
Transmit Complete Event
#define XIICPS_EVENT_ERROR 0x0008 |
Receive error
#define XIICPS_EVENT_NACK 0x0020 |
NACK Received
#define XIICPS_EVENT_RX_OVR 0x0080 |
RX overflow
#define XIICPS_EVENT_RX_UNF 0x0200 |
RX underflow
#define XIICPS_EVENT_SLAVE_RDY 0x0040 |
Slave ready
#define XIICPS_EVENT_TIME_OUT 0x0004 |
Transfer timed out
#define XIICPS_EVENT_TX_OVR 0x0100 |
TX overflow
#define XIICPS_H |
#define XIICPS_MAX_TRANSFER_SIZE (255 - 3) |
#define XIicPs_RecvByte | ( | InstancePtr | ) |
{ \ *(InstancePtr)->RecvBufferPtr ++ = \ (u8)XIicPs_In32((InstancePtr)->Config.BaseAddress \ + XIICPS_DATA_OFFSET); \ (InstancePtr)->RecvByteCount --; \ }
#define XIICPS_REP_START_OPTION 0x08 |
Repeated Start
#define XIicPs_SendByte | ( | InstancePtr | ) |
{ \ XIicPs_Out32((InstancePtr)->Config.BaseAddress \ + XIICPS_DATA_OFFSET, \ *(InstancePtr)->SendBufferPtr ++); \ (InstancePtr)->SendByteCount --; \ }
#define XIICPS_SLAVE_MON_OPTION 0x04 |
Slave monitor mode
typedef void(* XIicPs_IntrHandler)(void *CallBackRef, u32 StatusEvent) |
The handler data type allows the user to define a callback function to respond to interrupt events in the system. This function is executed in interrupt context, so amount of processing should be minimized.
CallBackRef | is the 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 not important to the driver, so it is a void pointer. | |
StatusEvent | indicates one or more status events that occurred. |
void XIicPs_Abort | ( | XIicPs * | InstancePtr | ) |
Aborts a transfer in progress by resetting the FIFOs. The byte counts are cleared.
InstancePtr | is a pointer to the XIicPs instance. |
int XIicPs_BusIsBusy | ( | XIicPs * | InstancePtr | ) |
Check whether the I2C bus is busy
InstancePtr | is a pointer to the XIicPs instance. |
int XIicPs_CfgInitialize | ( | XIicPs * | InstancePtr, | |
XIicPs_Config * | ConfigPtr, | |||
u32 | EffectiveAddr | |||
) |
Initializes a specific XIicPs instance such that the driver is ready to use.
The state of the device after initialization is:
InstancePtr | is a pointer to the XIicPs instance. | |
ConfigPtr | is a reference to a structure containing information about a specific IIC device. This function initializes an InstancePtr object for a specific device specified by the contents of Config. | |
EffectiveAddr | is the device base address in the virtual memory address space. The caller is responsible for keeping the address mapping from EffectiveAddr to the device physical base address unchanged once this function is invoked. Unexpected errors may occur if the address mapping changes after this function is called. If address translation is not used, use ConfigPtr->BaseAddress for this parameter, passing the physical address instead. |
int XIicPs_ClearOptions | ( | XIicPs * | InstancePtr, | |
u32 | Options | |||
) |
This function clears the options for the IIC device driver. The options control how the device behaves relative to the IIC bus. The device must be idle rather than busy transferring data before setting these device options.
InstancePtr | is a pointer to the XIicPs instance. | |
Options | contains the specified options to be cleared. This is a bit mask where a 1 means to turn the option off. One or more bit values may be contained in the mask. See the bit definitions named XIICPS_*_OPTION in xiicps.h. |
void XIicPs_DisableSlaveMonitor | ( | XIicPs * | InstancePtr | ) |
This function disables slave monitor mode.
InstancePtr | is a pointer to the XIicPs instance. |
void XIicPs_EnableSlaveMonitor | ( | XIicPs * | InstancePtr, | |
u16 | SlaveAddr | |||
) |
This function enables the slave monitor mode.
It enables slave monitor in the control register and enables slave ready interrupt. It then does an address transfer to slave. Interrupt handler will signal the caller if slave responds to the address transfer.
InstancePtr | is a pointer to the XIicPs instance. | |
SlaveAddr | is the address of the slave we want to contact. |
u32 XIicPs_GetOptions | ( | XIicPs * | InstancePtr | ) |
This function gets the options for the IIC device. The options control how the device behaves relative to the IIC bus.
InstancePtr | is a pointer to the XIicPs instance. |
u32 XIicPs_GetSClk | ( | XIicPs * | InstancePtr | ) |
This function gets the serial clock rate for the IIC device. The device must be idle rather than busy transferring data before setting these device options.
InstancePtr | is a pointer to the XIicPs instance. |
XIicPs_Config* XIicPs_LookupConfig | ( | u16 | DeviceId | ) |
Looks up the device configuration based on the unique device ID. A table contains the configuration info for each device in the system.
DeviceId | contains the ID of the device to look up the configuration for. |
void XIicPs_MasterInterruptHandler | ( | XIicPs * | InstancePtr | ) |
The interrupt handler for the master mode. It does the protocol handling for the interrupt-driven transfers.
Completion events and errors are signaled to upper layer for proper handling.
The interrupts that are handled are:
If the Master is receiving data then the data is read from the FIFO and the Master has to request for more data (if there is more data to receive). If all the data has been received then a completion event is signalled to the upper layer by calling the callback handler. It is an error if the amount of received data is more than expected.
InstancePtr | is a pointer to the XIicPs instance. |
void XIicPs_MasterRecv | ( | XIicPs * | InstancePtr, | |
u8 * | MsgPtr, | |||
int | ByteCount, | |||
u16 | SlaveAddr | |||
) |
This function initiates an interrupt-driven receive in master mode.
It sets the transfer size register so the slave can send data to us. The rest of the work is managed by interrupt handler.
InstancePtr | is a pointer to the XIicPs instance. | |
MsgPtr | is the pointer to the receive buffer. | |
ByteCount | is the number of bytes to be received. | |
SlaveAddr | is the address of the slave we are receiving from. |
int XIicPs_MasterRecvPolled | ( | XIicPs * | InstancePtr, | |
u8 * | MsgPtr, | |||
int | ByteCount, | |||
u16 | SlaveAddr | |||
) |
This function initiates a polled mode receive in master mode.
It repeatedly sets the transfer size register so the slave can send data to us. It polls the data register for data to come in. If slave fails to send us data, it fails with time out.
InstancePtr | is a pointer to the XIicPs instance. | |
MsgPtr | is the pointer to the receive buffer. | |
ByteCount | is the number of bytes to be received. | |
SlaveAddr | is the address of the slave we are receiving from. |
void XIicPs_MasterSend | ( | XIicPs * | InstancePtr, | |
u8 * | MsgPtr, | |||
int | ByteCount, | |||
u16 | SlaveAddr | |||
) |
This function initiates an interrupt-driven send in master mode.
It tries to send the first FIFO-full of data, then lets the interrupt handler to handle the rest of the data if there is any.
InstancePtr | is a pointer to the XIicPs instance. | |
MsgPtr | is the pointer to the send buffer. | |
ByteCount | is the number of bytes to be sent. | |
SlaveAddr | is the address of the slave we are sending to. |
int XIicPs_MasterSendPolled | ( | XIicPs * | InstancePtr, | |
u8 * | MsgPtr, | |||
int | ByteCount, | |||
u16 | SlaveAddr | |||
) |
This function initiates a polled mode send in master mode.
It sends data to the FIFO and waits for the slave to pick them up. If slave fails to remove data from FIFO, the send fails with time out.
InstancePtr | is a pointer to the XIicPs instance. | |
MsgPtr | is the pointer to the send buffer. | |
ByteCount | is the number of bytes to be sent. | |
SlaveAddr | is the address of the slave we are sending to. |
void XIicPs_Reset | ( | XIicPs * | InstancePtr | ) |
Resets the IIC device. Reset must only be called after the driver has been initialized. The configuration of the device after reset is the same as its configuration after initialization. Any data transfer that is in progress is aborted.
The upper layer software is responsible for re-configuring (if necessary) and reenabling interrupts for the IIC device after the reset.
InstancePtr | is a pointer to the XIicPs instance. |
int XIicPs_SelfTest | ( | XIicPs * | InstancePtr | ) |
Runs a self-test on the driver/device. The self-test is destructive in that a reset of the device is performed in order to check the reset values of the registers and to get the device into a known state.
Upon successful return from the self-test, the device is reset.
InstancePtr | is a pointer to the XIicPs instance. |
int XIicPs_SetOptions | ( | XIicPs * | InstancePtr, | |
u32 | Options | |||
) |
This function sets the options for the IIC device driver. The options control how the device behaves relative to the IIC bus. The device must be idle rather than busy transferring data before setting these device options.
InstancePtr | is a pointer to the XIicPs instance. | |
Options | contains the specified options to be set. This is a bit mask where a 1 means to turn the option on. One or more bit values may be contained in the mask. See the bit definitions named XIICPS_*_OPTION in xiicps.h. |
int XIicPs_SetSClk | ( | XIicPs * | InstancePtr, | |
u32 | FsclHz | |||
) |
This function sets the serial clock rate for the IIC device. The device must be idle rather than busy transferring data before setting these device options.
The data rate is set by values in the control register. The formula for determining the correct register values is: Fscl = Fpclk/(22 x (divisor_a+1) x (divisor_b+1)) See the hardware data sheet for a full explanation of setting the serial clock rate.
InstancePtr | is a pointer to the XIicPs instance. | |
FsclHz | is the clock frequency in Hz. The two most common clock rates are 100KHz and 400KHz. |
void XIicPs_SetStatusHandler | ( | XIicPs * | InstancePtr, | |
void * | CallBackRef, | |||
XIicPs_IntrHandler | FuncPtr | |||
) |
This function sets the status callback function, the status handler, which the driver calls when it encounters conditions that should be reported to the higher layer software. The handler executes in an interrupt context, so the amount of processing should be minimized
Refer to the xiicps.h file for a list of the Callback events. The events are defined to start with XIICPS_EVENT_*.
InstancePtr | is a pointer to the XIicPs instance. | |
CallBackRef | is the upper layer callback reference passed back when the callback function is invoked. | |
FuncPtr | is the pointer to the callback function. |
The handler is called within interrupt context, so it should finish its work quickly.
void XIicPs_SetupSlave | ( | XIicPs * | InstancePtr, | |
u16 | SlaveAddr | |||
) |
This function sets up the device to be a slave.
InstancePtr | is a pointer to the XIicPs instance. | |
SlaveAddr | is the address of the slave we are receiving from. |
void XIicPs_SlaveInterruptHandler | ( | XIicPs * | InstancePtr | ) |
The interrupt handler for slave mode. It does the protocol handling for the interrupt-driven transfers.
Completion events and errors are signaled to upper layer for proper handling.
The interrupts that are handled are:
If the instance is receiving, it means that the master has writen more data to us. Receive more data, and check whether we are done with with this receive.
It is an error if the amount of transfered data is less than expected.
InstancePtr | is a pointer to the XIicPs instance. |
void XIicPs_SlaveRecv | ( | XIicPs * | InstancePtr, | |
u8 * | MsgPtr, | |||
int | ByteCount | |||
) |
This function setup a slave interrupt-driven receive. Data processing for the receive is handled by the interrupt handler.
InstancePtr | is a pointer to the XIicPs instance. | |
MsgPtr | is the pointer to the receive buffer. | |
ByteCount | is the number of bytes to be received. |
int XIicPs_SlaveRecvPolled | ( | XIicPs * | InstancePtr, | |
u8 * | MsgPtr, | |||
int | ByteCount | |||
) |
This function receives a buffer in polled mode as a slave.
InstancePtr | is a pointer to the XIicPs instance. | |
MsgPtr | is the pointer to the receive buffer. | |
ByteCount | is the number of bytes to be received. |
void XIicPs_SlaveSend | ( | XIicPs * | InstancePtr, | |
u8 * | MsgPtr, | |||
int | ByteCount | |||
) |
This function setup a slave interrupt-driven send. It set the repeated start for the device is the tranfer size is larger than FIFO depth. Data processing for the send is initiated by the interrupt handler.
InstancePtr | is a pointer to the XIicPs instance. | |
MsgPtr | is the pointer to the send buffer. | |
ByteCount | is the number of bytes to be sent. |
int XIicPs_SlaveSendPolled | ( | XIicPs * | InstancePtr, | |
u8 * | MsgPtr, | |||
int | ByteCount | |||
) |
This function sends a buffer in polled mode as a slave.
InstancePtr | is a pointer to the XIicPs instance. | |
MsgPtr | is the pointer to the send buffer. | |
ByteCount | is the number of bytes to be sent. |
Copyright © 1995-2014 Xilinx, Inc. All rights reserved.