Data Structures | |
union | SMBus_Ctrl |
SMBus control register. More... | |
struct | SMBus_Phy |
Physical and Data Link Layer object. More... | |
struct | SMBus_Nwk |
Definition of SMBus Network structure. More... | |
union | SMBus_Status |
SMBus Status Register. More... | |
struct | SMBus |
Main SMBus object. More... | |
Macros | |
#define | SMB_PEC_SUPPORTED (1) |
Define to support Packet Error Checking (PEC) | |
#define | SMB_MANUAL_ACK_ENABLE (0) |
Define to enable Manual ACK workaround. More... | |
#define | SMB_CRC8_USE_LOOKUP_TABLE (1) |
#define | SMB_MAX_PAYLOAD_SIZE (32) |
Maximum payload as specified by SMBus Spec. | |
#define | SMB_MAX_PACKET_SIZE (SMB_MAX_PAYLOAD_SIZE + 3) |
Max packet size = Payload+PEC+CMD+Len. | |
#define | RESPONSE_NTR 0x00 |
Default response when there's nothing to send. | |
#define | SMBUS_RET_OK (1) |
Return value when successful. | |
#define | SMBUS_RET_ERROR (-1) |
Return value when an error ocurred. | |
Functions | |
void | SMBus_processDone (SMBus *smbus) |
Clears the current state of SMBus. More... | |
uint8_t | SMBus_getRxPayloadAvailable (SMBus *smbus) |
Returns the number of received bytes from last transaction. More... | |
SMBus_State | SMBus_getState (SMBus *smbus) |
Returns the state of the SMBus module. More... | |
void | SMBus_enablePEC (SMBus *smbus) |
Enables PEC support. More... | |
void | SMBus_disablePEC (SMBus *smbus) |
Disables PEC support. More... | |
void | SMBus_slaveInit (SMBus *smbus, uint16_t i2cAddr) |
Initialize the SMBus interface as a slave. More... | |
void | SMBus_slaveEnableInt (SMBus *smbus) |
Enables the I2C interrupts for a slave. More... | |
SMBus_State | SMBus_slaveProcessInt (SMBus *smbus) |
I2C Interrupt Service routine for a slave. More... | |
void | SMBus_masterReset (SMBus *smbus) |
Force reset to SMBus master interface. More... | |
SMBus_State | SMBus_slaveProcessTimeoutInt (SMBus *smbus) |
Timer interrupt service routine for slave application. More... | |
void | SMBus_slaveSetAddress (SMBus *smbus, uint8_t slaveAddr) |
Set the slave's own I2C address. More... | |
void | SMBus_slaveSetRxBuffer (SMBus *smbus, uint8_t *data, uint8_t size) |
Initialize the reception buffer for slave. More... | |
void | SMBus_slaveSetTxBuffer (SMBus *smbus, uint8_t *data, uint8_t size) |
Initialize the transmission buffer for slave. More... | |
void | SMBus_slaveReportError (SMBus *smbus, SMBus_ErrorCode errorCode) |
Reports an error to SMBus driver from the slave. More... | |
uint8_t | SMBus_slaveGetCommand (SMBus *smbus) |
Return the current command (Rxbuffer[0]) received by the slave. More... | |
uint8_t | SMBus_slaveClearStatusReg (SMBus *smbus, uint8_t val) |
Clear the slave's status register. More... | |
uint8_t | SMBus_slaveWriteCtrlReg (SMBus *smbus, uint8_t val) |
Write a value to the slave's control register. More... | |
void | SMBus_masterInit (SMBus *smbus, uint16_t i2cAddr, uint32_t busClk) |
Initialize the SMBus Interface for a master. More... | |
void | SMBus_masterEnableInt (SMBus *smbus) |
Enables the I2C interrupts for a master. More... | |
SMBus_State | SMBus_masterProcessInt (SMBus *smbus) |
I2C Interrupt Service routine for a master. More... | |
SMBus_State | SMBus_masterProcessTimeoutInt (SMBus *smbus) |
Timer interrupt service routine for a master. More... | |
int8_t | SMBus_masterProcessCall (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t *rxData) |
Sends a process call to a slave. More... | |
int8_t | SMBus_masterProcessCallBlock (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t txSize, uint8_t *rxData) |
Sends a block write-block read process call. More... | |
int8_t | SMBus_masterSendByte (SMBus *smbus, uint8_t targetAddr, uint8_t txData) |
Sends byte to the slave. More... | |
int8_t | SMBus_masterReceiveByte (SMBus *smbus, uint8_t targetAddr, uint8_t *rxData) |
Receive a byte from the slave. More... | |
int8_t | SMBus_masterReadBlock (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *rxData) |
Receive a block of data from the slave. More... | |
int8_t | SMBus_masterWriteBlock (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t txSize) |
Transmit a block of data to the slave. More... | |
int8_t | SMBus_masterReadByteWord (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *rxData, uint8_t rxSize) |
Send a command requesting a byte or word of data from the slave. More... | |
int8_t | SMBus_masterWriteByteWord (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t txSize) |
Send a command transmitting a byte or word of data from the slave. More... | |
int8_t | SMBus_masterQuickCommand (SMBus *smbus, uint8_t targetAddr, bool write) |
Send a SMBus "quick command". More... | |
int8_t | SMBus_masterWaitUntilDone (SMBus *smbus, int32_t timeout) |
Wait until the previous SMBus command is executed. More... | |
#define SMB_CRC8_USE_LOOKUP_TABLE (1) |
Define method used to calculate CRC8:
#define SMB_MANUAL_ACK_ENABLE (0) |
Define to enable Manual ACK workaround.
The MSP403 eUSCI doesn't support tesing a received byte and NACK/ACK immediately. This workaround uses DMA to stretch SCL low immediately after a byte is received. The DMA ISR is attended and the application then decides if it needs to ACK or NACK the byte This capability is not supported on devices that do not have DMA (e.g. MSP430G2xxx.
enum SMBus_ErrorCode |
enum SMBus_NwkState |
SMBus network layer states.
enum SMBus_State |
SMBus state sent to application layer.
Enumerator | |
---|---|
SMBus_State_DataSizeError |
Nothing special to report. |
SMBus_State_PECError |
Incorrect packet size. |
SMBus_State_TimeOutError |
PEC Error detected. |
SMBus_State_Slave_FirstByte |
Timeout Error. |
SMBus_State_Slave_ByteReceived |
1st byte (cmd) received |
SMBus_State_Slave_QCMD |
Slave received a byte (2-n) |
SMBus_State_Slave_CmdComplete |
Quick Command detected. |
SMBus_State_Slave_Error |
Complete packet received by slave. |
SMBus_State_Slave_NotReady |
SMBus Slave Error. |
SMBus_State_Slave_NTR |
SMBus Buffers haven't been initialized. |
SMBus_State_Master_ArbLost |
No Interrupt flags detected. |
SMBus_State_Master_NACK |
Arbitration Lost. |
SMBus_State_Master_Error |
Unexpected NACKed. |
SMBus_State_Unknown |
SMBus Master error. |
enum SMBus_Stop |
void SMBus_disablePEC | ( | SMBus * | smbus | ) |
Disables PEC support.
smbus | Pointer to SMBus structure |
References SMBus_Ctrl::bits, and SMBus::ctrl.
void SMBus_enablePEC | ( | SMBus * | smbus | ) |
Enables PEC support.
smbus | Pointer to SMBus structure |
References SMBus_Ctrl::bits, and SMBus::ctrl.
uint8_t SMBus_getRxPayloadAvailable | ( | SMBus * | smbus | ) |
Returns the number of received bytes from last transaction.
smbus | Pointer to SMBus structure |
References SMBus_NWK_getRxPayloadSize().
SMBus_State SMBus_getState | ( | SMBus * | smbus | ) |
Returns the state of the SMBus module.
smbus | Pointer to SMBus structure |
References SMBus::state.
void SMBus_masterEnableInt | ( | SMBus * | smbus | ) |
Enables the I2C interrupts for a master.
This function enables the eUSCI Start,Stop, RX,TX, Timeout interrupts. SMBus_masterInit() must be called before this function. If SMB_MANUAL_ACK_ENABLE is enabled, it enables DMA to handle the RX.
smbus | Pointer to SMBus structure |
References SMBus_PHY_masterEnableInt().
Referenced by SMBus_PHY_masterEnable().
void SMBus_masterInit | ( | SMBus * | smbus, |
uint16_t | i2cAddr, | ||
uint32_t | busClk | ||
) |
Initialize the SMBus Interface for a master.
Initializes the NWK and PHY layers
smbus | Pointer to SMBus structure |
i2cAddr | Base address of I2C module. For MSP430G2xxx devices, this parameter is ignored. |
busClk | SMCLK Frequency |
References SMBus_Ctrl::bits, SMBus::ctrl, SMBus_Nwk::currentAddr, SMBus_Ctrl::master, SMBus::nwk, SMBus_Nwk::pec, SMBus_Nwk::recByteTxPtr, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxIndex, SMBus_Nwk::rxLen, SMBus_Nwk::rxSize, SMBus_PHY_masterInit(), SMBus::state, SMBus::status, SMBus_Nwk::txBuffPtr, SMBus_Nwk::txIndex, SMBus_Nwk::txLen, SMBus_Nwk::txSize, SMBus_Ctrl::u8byte, and SMBus_Status::u8byte.
int8_t SMBus_masterProcessCall | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | command, | ||
uint8_t * | txData, | ||
uint8_t * | rxData | ||
) |
Sends a process call to a slave.
Send process call to the slave. A command byte and 2 bytes of TX data are required. Two bytes of data will be returned by the slave in rxData.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
command | Command byte for slave |
txData | TX data buffer |
rxData | RX data buffer |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.
int8_t SMBus_masterProcessCallBlock | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | command, | ||
uint8_t * | txData, | ||
uint8_t | txSize, | ||
uint8_t * | rxData | ||
) |
Sends a block write-block read process call.
Send block write-block read process call to the slave. A command byte, length and tx data byte array are required. Ensure that rxData is large enough to hold the data received from the slave.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
command | Command byte for slave |
txData | TX data buffer |
txSize | Size of the txData buffer |
rxData | RX data buffer |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMB_MAX_PAYLOAD_SIZE, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.
SMBus_State SMBus_masterProcessInt | ( | SMBus * | smbus | ) |
I2C Interrupt Service routine for a master.
Handles the interrupts for SMBus passing information to NWK layer Should be called by application when USCI interrupt is detected
smbus | Pointer to SMBus structure |
References SMBus_PHY_masterProcessInt().
SMBus_State SMBus_masterProcessTimeoutInt | ( | SMBus * | smbus | ) |
Timer interrupt service routine for a master.
Handles the interrupts for SMBus tiemout processing for USCI devices. Should be called by application when Timer interrupt is detected
smbus | Pointer to SMBus structure |
References SMBus_PHY_masterProcessTimeoutInt().
int8_t SMBus_masterQuickCommand | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
bool | write | ||
) |
Send a SMBus "quick command".
A "quick command" is only a trigger. There is no data sent or received.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
write | true if this is a write command, false if this is a read command |
References SMBus_Nwk::currentAddr, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TXQuickCMD, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.
int8_t SMBus_masterReadBlock | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | command, | ||
uint8_t * | rxData | ||
) |
Receive a block of data from the slave.
Send block data receive call to the slave. A command byte, length and rx data byte array are required. Ensure that rxData is large enough to hold the data received from the slave.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
command | Command byte for slave |
rxData | RX data buffer |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.
int8_t SMBus_masterReadByteWord | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | command, | ||
uint8_t * | rxData, | ||
uint8_t | rxSize | ||
) |
Send a command requesting a byte or word of data from the slave.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
command | Command byte for slave |
rxData | RX data buffer |
rxSize | Must be 1 or 2 bytes |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.
int8_t SMBus_masterReceiveByte | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t * | rxData | ||
) |
Receive a byte from the slave.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
rxData | RX data buffer |
References SMBus_Nwk::currentAddr, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startRxTransfer(), SMBus_NwkState_RX, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.
void SMBus_masterReset | ( | SMBus * | smbus | ) |
Force reset to SMBus master interface.
Resets the network and PHY layers
smbus | Pointer to SMBus structure |
References SMBus_NWK_masterReset().
int8_t SMBus_masterSendByte | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | txData | ||
) |
Sends byte to the slave.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
txData | TX data buffer |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.
int8_t SMBus_masterWaitUntilDone | ( | SMBus * | smbus, |
int32_t | timeout | ||
) |
Wait until the previous SMBus command is executed.
smbus | Pointer to SMBus structure |
timeout | Software timeout |
References SMBus::nwk, SMBUS_RET_ERROR, and SMBUS_RET_OK.
int8_t SMBus_masterWriteBlock | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | command, | ||
uint8_t * | txData, | ||
uint8_t | txSize | ||
) |
Transmit a block of data to the slave.
Send block of data to the slave. A command byte, length and tx data byte array are required.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
command | Command byte for slave |
txData | TX data buffer |
txSize | Size of the txData buffer |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxLen, SMB_MAX_PAYLOAD_SIZE, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.
int8_t SMBus_masterWriteByteWord | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | command, | ||
uint8_t * | txData, | ||
uint8_t | txSize | ||
) |
Send a command transmitting a byte or word of data from the slave.
smbus | Pointer to SMBus structure |
targetAddr | Slave address |
command | Command byte for slave |
txData | TX data buffer |
txSize | Must be 1 or 2 bytes |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.
void SMBus_processDone | ( | SMBus * | smbus | ) |
Clears the current state of SMBus.
Must be called by application in order to clear the state machine when a byte/packet was processed
smbus | Pointer to SMBus structure |
References SMBus::state.
uint8_t SMBus_slaveClearStatusReg | ( | SMBus * | smbus, |
uint8_t | val | ||
) |
Clear the slave's status register.
smbus | Pointer to SMBus structure |
val | Bits cleared from status register (1=X, 0=clear) |
References SMBus::status, and SMBus_Status::u8byte.
void SMBus_slaveEnableInt | ( | SMBus * | smbus | ) |
Enables the I2C interrupts for a slave.
This function enables the eUSCI Start,Stop, RX,TX, Timeout interrupts If SMB_MANUAL_ACK_ENABLE is enabled, it enables DMA to handle the RX SMBus_slaveInit() must be called before this function
smbus | Pointer to SMBus structure |
References SMBus_PHY_slaveEnableInt().
Referenced by SMBus_PHY_slaveEnable().
uint8_t SMBus_slaveGetCommand | ( | SMBus * | smbus | ) |
Return the current command (Rxbuffer[0]) received by the slave.
smbus | Pointer to SMBus structure |
References SMBus_Nwk::currentCmd, and SMBus::nwk.
void SMBus_slaveInit | ( | SMBus * | smbus, |
uint16_t | i2cAddr | ||
) |
Initialize the SMBus interface as a slave.
Initializes the NWK and PHY layers.
smbus | Pointer to SMBus structure |
i2cAddr | Base address of I2C module. For MSP430G2xxx devices, this parameter is ignored. |
References SMBus_Ctrl::bits, SMBus::ctrl, SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus_Ctrl::master, SMBus::nwk, SMBus_Nwk::pec, SMBus_Nwk::recByteTxPtr, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxIndex, SMBus_Nwk::rxLen, SMBus_Nwk::rxSize, SMBus_PHY_slaveInit(), SMBus::state, SMBus::status, SMBus_Nwk::txBuffPtr, SMBus_Nwk::txIndex, SMBus_Nwk::txLen, SMBus_Nwk::txSize, SMBus_Ctrl::u8byte, and SMBus_Status::u8byte.
SMBus_State SMBus_slaveProcessInt | ( | SMBus * | smbus | ) |
I2C Interrupt Service routine for a slave.
Handles the interrupts for SMBus passing information to NWK layer Should be called by application when USCI/DMA interrupt is detected Note that this routine also checks the DMA due to the SW ACK workaround if SMB_MANUAL_ACK_ENABLE is defined.
smbus | Pointer to SMBus structure |
References SMBus_PHY_slaveProcessInt(), SMBus_State_Slave_NTR, and SMBus::state.
SMBus_State SMBus_slaveProcessTimeoutInt | ( | SMBus * | smbus | ) |
Timer interrupt service routine for slave application.
Handles the interrupts for SMBus tiemout processing for USCI devices. Should be called by application when Timer interrupt is detected
smbus | Pointer to SMBus structure |
References SMBus_PHY_slaveProcessTimeoutInt().
void SMBus_slaveReportError | ( | SMBus * | smbus, |
SMBus_ErrorCode | errorCode | ||
) |
Reports an error to SMBus driver from the slave.
Used to signal an error when incorrect command/data is detected by the slave
smbus | Pointer to SMBus structure |
errorCode | SMBus_ErrorCode |
References SMBus_Status::bits, SMBus_Status::cmdErr, SMBus::nwk, SMBus_Status::packErr, SMBus_ErrorCode_Cmd, SMBus_ErrorCode_Packet, SMBus_NwkState_Error, and SMBus::status.
void SMBus_slaveSetAddress | ( | SMBus * | smbus, |
uint8_t | slaveAddr | ||
) |
Set the slave's own I2C address.
smbus | Pointer to SMBus structure |
slaveAddr | Slave I2C address |
References SMBus_Ctrl::bits, SMBus::ctrl, SMBus::ownSlaveAddr, SMBus_Ctrl::phyEn, and SMBus_PHY_enable().
void SMBus_slaveSetRxBuffer | ( | SMBus * | smbus, |
uint8_t * | data, | ||
uint8_t | size | ||
) |
Initialize the reception buffer for slave.
smbus | Pointer to SMBus structure |
data | Pointer to Application RX buffer |
size | Maximum size of buffer |
References SMBus::nwk, SMBus_Nwk::rxBuffPtr, and SMBus_Nwk::rxSize.
void SMBus_slaveSetTxBuffer | ( | SMBus * | smbus, |
uint8_t * | data, | ||
uint8_t | size | ||
) |
Initialize the transmission buffer for slave.
smbus | Pointer to SMBus structure |
data | Pointer to Application TX buffer |
size | Maximum size of buffer |
References SMBus::nwk, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txSize.
uint8_t SMBus_slaveWriteCtrlReg | ( | SMBus * | smbus, |
uint8_t | val | ||
) |
Write a value to the slave's control register.
smbus | Pointer to SMBus structure |
val | Value being written to the Control register |
References SMBus::ctrl, SMBus_Ctrl::u8byte, and SMBus_Ctrl::writeableBits.