![]() |
![]() |
Functions | |
| CSL_Status | I2C_init (Uint16 instanceNum) |
| CSL_Status | I2C_config (CSL_I2cConfig *i2cConfig) |
| CSL_Status | I2C_getConfig (CSL_I2cConfig *i2cgetConfig) |
| CSL_Status | I2C_setup (CSL_I2cSetup *i2cSetup) |
| CSL_Status | I2C_write (Uint16 *i2cWrBuf, Uint16 dataLength, Uint16 slaveAddr, Bool masterMode, Uint16 startStopFlag, Uint16 timeout) |
| CSL_Status | I2C_read (Uint16 *i2cRdBuf, Uint16 dataLength, Uint16 slaveAddr, Bool masterMode, Uint16 startStopFlag, Uint16 timeout, Bool checkBus) |
| CSL_Status | I2C_eventEnable (CSL_I2cEvent i2cEvent) |
| CSL_Status | I2C_eventDisable (CSL_I2cEvent i2cEvent) |
| CSL_Status | I2C_setCallback (CSL_I2cIsrAddr *i2cIsrAddr) |
| Int16 | I2C_getEventId (void) |
| CSL_Status I2C_config | ( | CSL_I2cConfig * | i2cConfig | ) |
============================================================================
I2C_config
Description
Configures the I2C module. Using this function application can pass the value of the each register to be configured.
Arguments
i2cConfig I2C config structure pointer
Return Value CSL_Status
Pre Condition
I2C_init should be called successfully
Post Condition
Configures the I2C registers
Modifies
I2C registers
Example
CSL_Status status;
CSL_I2cConfig i2cConfig;
i2cConfig.icoar = CSL_I2C_ICOAR_DEFVAL;
i2cConfig.icimr = CSL_I2C_ICIMR_DEFVAL;
i2cConfig.icclkl = CSL_I2C_ICCLK_DEFVAL;
i2cConfig.icclkh = CSL_I2C_ICCLK_DEFVAL;
i2cConfig.iccnt = CSL_I2C_DATA_SIZE;
i2cConfig.icsar = CSL_I2C_ICSAR_DEFVAL;
i2cConfig.icmdr = CSL_I2C_ICMDR_WRITE_DEFVAL;
i2cConfig.icemdr = CSL_I2C_ICEMDR_DEFVAL;
i2cConfig.icpsc = CSL_I2C_ICPSC_DEFVAL;
status = I2C_init(CSL_I2C0);
....
status = I2C_config(&i2cConfig);
============================================================================
References CSL_I2C_ICSTR_RESET_VALUE, CSL_I2cObj::i2cRegs, CSL_I2cConfig::icclkh, CSL_I2cConfig::icclkl, CSL_I2cConfig::iccnt, CSL_I2cConfig::icemdr, CSL_I2cConfig::icimr, CSL_I2cConfig::icmdr, CSL_I2cConfig::icoar, CSL_I2cConfig::icpsc, and CSL_I2cConfig::icsar.
| CSL_Status I2C_eventDisable | ( | CSL_I2cEvent | i2cEvent | ) |
============================================================================
I2C_eventDisable
Description
Disables the I2C events. I2C has several events which can generate interrupt to the CPU. Application can disable any of the event using this function.
Arguments
i2cEvent Event to be disabled
Return Value CSL_Status
Pre Condition
I2C_init and I2C_eventEnable should be called successfully
Post Condition
Disables I2C interrupt for a particular event
Modifies
I2C Interrupt enable register
Example
CSL_Status status;
status = I2C_init(CSL_I2C0);
....
....
status = I2C_eventEnable(CSL_I2C_EVENT_ICXRDY);
....
....
status = I2C_eventDisable(CSL_I2C_EVENT_ICXRDY);
============================================================================
References CSL_I2C_EVENT_AAS, CSL_I2C_EVENT_AL, CSL_I2C_EVENT_ARDY, CSL_I2C_EVENT_ICRRDY, CSL_I2C_EVENT_ICXRDY, CSL_I2C_EVENT_NACK, CSL_I2C_EVENT_SCD, and CSL_I2cObj::i2cRegs.
| CSL_Status I2C_eventEnable | ( | CSL_I2cEvent | i2cEvent | ) |
============================================================================
I2C_eventEnable
Description
Enables the I2C events for interrupt generation. I2C has several events which can generate interrupt to the CPU. Application can enable any of the event using this function.
Arguments
i2cEvent Event to be enabled
Return Value CSL_Status
Pre Condition
I2C_init should be called successfully
Post Condition
Enables I2C interrupt for a particular event
Modifies
I2C Interrupt enable register
Example
CSL_Status status;
status = I2C_init(CSL_I2C0);
....
....
status = I2C_eventEnable(CSL_I2C_EVENT_ICXRDY);
============================================================================
References CSL_I2C_EVENT_AAS, CSL_I2C_EVENT_AL, CSL_I2C_EVENT_ARDY, CSL_I2C_EVENT_ICRRDY, CSL_I2C_EVENT_ICXRDY, CSL_I2C_EVENT_NACK, CSL_I2C_EVENT_SCD, and CSL_I2cObj::i2cRegs.
| CSL_Status I2C_getConfig | ( | CSL_I2cConfig * | i2cgetConfig | ) |
============================================================================
I2C_getConfig
Description
Gets the I2C configuration parameters
Arguments
i2cgetConfig I2C Configuration structure pointer
Return Value CSL_Status
Pre Condition
I2C_config should be called successfully
Post Condition
Populates the I2C config structure
Modifies
Structure pointed by getI2cConfig
Example
CSL_Status status;
CSL_I2cConfig i2cConfig;
CSL_I2cConfig i2cgetConfig
i2cConfig.icoar = CSL_I2C_ICOAR_DEFVAL;
i2cConfig.icimr = CSL_I2C_ICIMR_DEFVAL;
i2cConfig.icclkl = CSL_I2C_ICCLK_DEFVAL;
i2cConfig.icclkh = CSL_I2C_ICCLK_DEFVAL;
i2cConfig.iccnt = CSL_I2C_DATA_SIZE;
i2cConfig.icsar = CSL_I2C_ICSAR_DEFVAL;
i2cConfig.icmdr = CSL_I2C_ICMDR_WRITE_DEFVAL;
i2cConfig.icemdr = CSL_I2C_ICEMDR_DEFVAL;
i2cConfig.icpsc = CSL_I2C_ICPSC_DEFVAL;
status = I2C_init(CSL_I2C0);
....
status = I2C_config(&i2cConfig);
....
....
status = I2C_getConfig(&i2cgetConfig);
============================================================================
References CSL_I2cObj::i2cRegs, CSL_I2cConfig::icclkh, CSL_I2cConfig::icclkl, CSL_I2cConfig::iccnt, CSL_I2cConfig::icemdr, CSL_I2cConfig::icimr, CSL_I2cConfig::icmdr, CSL_I2cConfig::icoar, CSL_I2cConfig::icpsc, and CSL_I2cConfig::icsar.
| Int16 I2C_getEventId | ( | void | ) |
============================================================================
I2C_getEventId
Description
Returns the I2C event ID. This event represent the I2C interrupt in the I2C interrupt vector register
Arguments
None
Return Value
I2C Event Id
Pre Condition
None
Post Condition
Returns I2C event Id
Modifies
None
Example
Int16 i2cEvent;
i2cEvent = I2C_getEventId();
============================================================================
References CSL_I2cObj::i2cRegs.
| CSL_Status I2C_init | ( | Uint16 | instanceNum | ) |
============================================================================
I2C_init
Description
Initializes the I2C CSL module
Arguments
instanceNum I2C Hardware instance number
Return Value CSL_Status
Pre Condition
None
Post Condition
Initializes I2C module
Modifies
I2C Object structure
Example
CSL_Status status;
status = I2C_init(CSL_I2C0);
============================================================================
References CSL_I2C0, CSL_I2C_RESET_COUNT_VAL, CSL_I2C_RESET_DELAY, CSL_I2cObj::i2cRegs, and CSL_I2cObj::sysCtrlRegs.
| CSL_Status I2C_read | ( | Uint16 * | i2cRdBuf, |
| Uint16 | dataLength, | ||
| Uint16 | slaveAddr, | ||
| Bool | masterMode, | ||
| Uint16 | startStopFlag, | ||
| Uint16 | timeout, | ||
| Bool | checkBus | ||
| ) |
============================================================================
I2C_read
Description
Receives the I2C data from the I2C device.
Arguments
i2cRdBuf I2C Data buffer pointer
dataLength Number bytes to receive
slaveAddr Address of the slave device
masterMode Master mode flag
startStopFlag Flag for the start and stop bits
timeout Time out variable
checkBus Check Bus busy flag
Return Value CSL_Status
Pre Condition
I2C_init and I2C_config/I2C_setup should be called successfully
Post Condition
Receives the I2C data
Modifies
I2C data buffer
Example
#define CSL_I2C_SYS_CLK (12) // In MHz
#define CSL_I2C_BUS_FREQ (10) // In KHz
#define CSL_I2C_DATA_SIZE (16)
#define CSL_I2C_EEPROM_ADDR (0x50)
#define CSL_I2CEEPROM_ADDR_SIZE (2)
Uint16 i2cDataBuf[CSL_I2C_DATA_SIZE];
CSL_Status status;
CSL_I2cSetup i2cSetup;
i2cSetup.addrMode = CSL_I2C_ADDR_7BIT;
i2cSetup.bitCount = CSL_I2C_BC_8BITS;
i2cSetup.loopBack = CSL_I2C_LOOPBACK_DISABLE;
i2cSetup.freeMode = CSL_I2C_FREEMODE_DISABLE;
i2cSetup.repeatMode = CSL_I2C_REPEATMODE_DISABLE;
i2cSetup.ownAddr = CSL_I2C_OWN_ADDR;
i2cSetup.sysInputClk = CSL_I2C_SYS_CLK;
i2cSetup.i2cBusFreq = CSL_I2C_BUS_FREQ;
status = I2C_init(CSL_I2C0);
....
status = I2C_setup(&i2cSetup);
....
....
status = I2C_read(i2cDataBuf, CSL_I2C_DATA_SIZE, CSL_I2C_EEPROM_ADDR,
TRUE, 1, CSL_I2C_MAX_TIMEOUT, FALSE);
============================================================================
References CSL_I2C_BUS_BUSY_ERR, CSL_I2C_RECEIVE_OVERFLOW_ERR, CSL_I2C_START, CSL_I2C_STOP, CSL_I2C_TIMEOUT_ERROR, and CSL_I2cObj::i2cRegs.
| CSL_Status I2C_setCallback | ( | CSL_I2cIsrAddr * | i2cIsrAddr | ) |
============================================================================
I2C_setCallback
Description
Sets the call back functions for different I2C interrupts. These callback functions are called from the Interrupt service routine based on the interrupt generated by a particular event
Arguments
i2cIsrAddr I2C ISR address structure pointer
Return Value CSL_Status
Pre Condition
None
Post Condition
Sets the call functions
Modifies
Callback pointer array
Example
void alCallback(void); // Arbitration Loss event callback
void nackCallback(void); // No acknowledgement event callback
void ardyCallback(void); // register access ready event callback
void rrdyCallback(void); // receive data ready event callback
void xrdyCallback(void); // transmit data ready event callback
void scdCallback(void); // stop condition detected event callback
void aasCallback(void); // Address As Slave interrupt callback
CSL_I2cIsrAddr i2cIsrAddr;
CSL_Status status;
i2cIsrAddr.alAddr = alCallback;
i2cIsrAddr.nackAddr = nackCallback;
i2cIsrAddr.ardyAddr = ardyCallback;
i2cIsrAddr.rrdyAddr = rrdyCallback;
i2cIsrAddr.xrdyAddr = xrdyCallback;
i2cIsrAddr.scdAddr = scdCallback;
i2cIsrAddr.aasAddr = aasCallback;
status = I2C_setCallback(i2cIsrAddr);
============================================================================
============================================================================
I2C_setCallback
Description
Sets the call back functions for different I2C interrupts. These callback functions are called from the Interrupt service routine based on the interrupt generated by a particular event.
Arguments
i2cIsrAddr I2C ISR address structure pointer
Return Value CSL_Status
Pre Condition
None
Post Condition
Sets the call functions
Modifies
Callback pointer array
Example
void alCallback(void); // Arbitration Loss event callback
void nackCallback(void); // No acknowledgement event callback
void ardyCallback(void); // register access ready event callback
void rrdyCallback(void); // receive data ready event callback
void xrdyCallback(void); // transmit data ready event callback
void scdCallback(void); // stop condition detected event callback
void aasCallback(void); // Address As Slave interrupt callback
CSL_I2cIsrAddr i2cIsrAddr;
CSL_Status status;
i2cIsrAddr.alAddr = alCallback;
i2cIsrAddr.nackAddr = nackCallback;
i2cIsrAddr.ardyAddr = ardyCallback;
i2cIsrAddr.rrdyAddr = rrdyCallback;
i2cIsrAddr.xrdyAddr = xrdyCallback;
i2cIsrAddr.scdAddr = scdCallback;
i2cIsrAddr.aasAddr = aasCallback;
status = I2C_setCallback(i2cIsrAddr);
============================================================================
References CSL_I2cIsrAddr::aasAddr, CSL_I2cIsrAddr::alAddr, CSL_I2cIsrAddr::ardyAddr, CSL_I2C_EVENT_AAS, CSL_I2C_EVENT_AL, CSL_I2C_EVENT_ARDY, CSL_I2C_EVENT_ICRRDY, CSL_I2C_EVENT_ICXRDY, CSL_I2C_EVENT_NACK, CSL_I2C_EVENT_SCD, CSL_I2cObj::I2C_isrDispatchTable, CSL_I2cIsrAddr::nackAddr, CSL_I2cIsrAddr::rrdyAddr, CSL_I2cIsrAddr::scdAddr, and CSL_I2cIsrAddr::xrdyAddr.
| CSL_Status I2C_setup | ( | CSL_I2cSetup * | i2cSetup | ) |
============================================================================
I2C_setup
Description
Sets the I2C hardware registers. This functions task is same as that of I2C_config, but this function provides more flexible interface to the application. Application can pass the individual configuration values rather than the register value.
Arguments
i2cSetup I2C setup structure
Return Value CSL_Status
Pre Condition
I2C_init should be called successfully
Post Condition
Sets the I2C register values
Modifies
I2C registers
Example
#define CSL_I2C_SYS_CLK (12) // In MHz
#define CSL_I2C_BUS_FREQ (10) // In KHz
CSL_Status status;
CSL_I2cSetup i2cSetup;
i2cSetup.addrMode = CSL_I2C_ADDR_7BIT;
i2cSetup.bitCount = CSL_I2C_BC_8BITS;
i2cSetup.loopBack = CSL_I2C_LOOPBACK_DISABLE;
i2cSetup.freeMode = CSL_I2C_FREEMODE_DISABLE;
i2cSetup.repeatMode = CSL_I2C_REPEATMODE_DISABLE;
i2cSetup.ownAddr = CSL_I2C_OWN_ADDR;
i2cSetup.sysInputClk = CSL_I2C_SYS_CLK;
i2cSetup.i2cBusFreq = CSL_I2C_BUS_FREQ;
status = I2C_init(CSL_I2C0);
....
status = I2C_setup(&i2cSetup);
============================================================================
References CSL_I2cSetup::addrMode, CSL_I2cSetup::bitCount, CSL_I2C_CLK_MULT, CSL_I2C_MODULE_CLOCK_FREQ, CSL_I2C_PSC0, CSL_I2C_PSC0_DVAL, CSL_I2C_PSC1, CSL_I2C_PSC1_DVAL, CSL_I2C_PSC2TOFF_DVAL, CSL_I2C_PSC_ADJUST_VAL, CSL_I2cSetup::freeMode, CSL_I2cSetup::i2cBusFreq, CSL_I2cObj::i2cRegs, CSL_I2cSetup::loopBack, CSL_I2cSetup::ownAddr, CSL_I2cSetup::repeatMode, and CSL_I2cSetup::sysInputClk.
| CSL_Status I2C_write | ( | Uint16 * | i2cWrBuf, |
| Uint16 | dataLength, | ||
| Uint16 | slaveAddr, | ||
| Bool | masterMode, | ||
| Uint16 | startStopFlag, | ||
| Uint16 | timeout | ||
| ) |
============================================================================
I2C_write
Description
Transmits the I2C data to I2C device.
Arguments
i2cWrBuf I2C Data buffer pointer
dataLength Number bytes to transmit
slaveAddr Address of the slave device
masterMode Master mode flag
startStopFlag Flag for the start and stop bits
timeout Time out variable
Return Value CSL_Status
Pre Condition
I2C_init and I2C_config/I2C_setup should be called successfully
Post Condition
Transmits the I2C data
Modifies
I2C transmit register
Example
#define CSL_I2C_SYS_CLK (12) // In MHz
#define CSL_I2C_BUS_FREQ (10) // In KHz
#define CSL_I2C_DATA_SIZE (16)
#define CSL_I2C_EEPROM_ADDR (0x50)
Uint16 i2cDataBuf[CSL_I2C_DATA_SIZE];
CSL_Status status;
CSL_I2cSetup i2cSetup;
i2cSetup.addrMode = CSL_I2C_ADDR_7BIT;
i2cSetup.bitCount = CSL_I2C_BC_8BITS;
i2cSetup.loopBack = CSL_I2C_LOOPBACK_DISABLE;
i2cSetup.freeMode = CSL_I2C_FREEMODE_DISABLE;
i2cSetup.repeatMode = CSL_I2C_REPEATMODE_DISABLE;
i2cSetup.ownAddr = CSL_I2C_OWN_ADDR;
i2cSetup.sysInputClk = CSL_I2C_SYS_CLK;
i2cSetup.i2cBusFreq = CSL_I2C_BUS_FREQ;
status = I2C_init(CSL_I2C0);
....
status = I2C_setup(&i2cSetup);
....
....
status = I2C_write(i2cDataBuf, CSL_I2C_DATA_SIZE,
CSL_I2C_EEPROM_ADDR, TRUE, 1,
CSL_I2C_MAX_TIMEOUT);
============================================================================
References CSL_I2C_BUS_BUSY_ERR, CSL_I2C_NACK_ERR, CSL_I2C_START, CSL_I2C_STOP, CSL_I2C_TIMEOUT_ERROR, and CSL_I2cObj::i2cRegs.
1.7.4