SMBusLibrary
1.0
|
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_CRC8_USE_LOOKUP_TABLE (1) |
#define | SMB_MAX_PAYLOAD_SIZE (255) |
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... | |
uint16_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_targetInit (SMBus *smbus, I2C_Regs *i2cAddr) |
Initialize the SMBus interface as a target. More... | |
void | SMBus_targetEnableInt (SMBus *smbus) |
Enables the I2C interrupts for a target. More... | |
SMBus_State | SMBus_targetProcessInt (SMBus *smbus) |
I2C Interrupt Service routine for a target. More... | |
void | SMBus_controllerReset (SMBus *smbus) |
Force reset to SMBus controller interface. More... | |
void | SMBus_targetSetAddress (SMBus *smbus, uint8_t targetAddr) |
Set the target's own I2C address. More... | |
void | SMBus_targetSetRxBuffer (SMBus *smbus, uint8_t *data, uint16_t size) |
Initialize the reception buffer for target. More... | |
void | SMBus_targetSetTxBuffer (SMBus *smbus, uint8_t *data, uint16_t size) |
Initialize the transmission buffer for target. More... | |
void | SMBus_targetReportError (SMBus *smbus, SMBus_ErrorCode errorCode) |
Reports an error to SMBus driver from the target. More... | |
uint8_t | SMBus_targetGetCommand (SMBus *smbus) |
Return the current command (Rxbuffer[0]) received by the target. More... | |
uint8_t | SMBus_targetClearStatusReg (SMBus *smbus, uint8_t val) |
Clear the target's status register. More... | |
uint8_t | SMBus_targetWriteCtrlReg (SMBus *smbus, uint8_t val) |
Write a value to the target's control register. More... | |
void | SMBus_controllerInit (SMBus *smbus, I2C_Regs *i2cAddr, uint32_t busClk) |
Initialize the SMBus Interface for a controller. More... | |
void | SMBus_controllerEnableInt (SMBus *smbus) |
Enables the I2C interrupts for a controller. More... | |
SMBus_State | SMBus_controllerProcessInt (SMBus *smbus) |
I2C Interrupt Service routine for a controller. More... | |
int8_t | SMBus_controllerProcessCall (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *txData, uint8_t *rxData) |
Sends a process call to a target. More... | |
int8_t | SMBus_controllerProcessCallBlock (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_controllerSendByte (SMBus *smbus, uint8_t targetAddr, uint8_t txData) |
Sends byte to the target. More... | |
int8_t | SMBus_controllerReadByteWord (SMBus *smbus, uint8_t targetAddr, uint8_t command, uint8_t *rxData, uint8_t rxSize) |
Receive a byte from the target. More... | |
int8_t | SMBus_controllerWriteByteWord (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 target. More... | |
int8_t | SMBus_controllerQuickCommand (SMBus *smbus, uint8_t targetAddr, bool write) |
Send a SMBus "quick command". More... | |
int8_t | SMBus_controllerWaitUntilDone (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:
enum SMBus_NwkState |
SMBus network layer states.
enum SMBus_ErrorCode |
enum SMBus_State |
SMBus state sent to application layer.
Enumerator | |
---|---|
SMBus_State_OK | Nothing special to report |
SMBus_State_DataSizeError | Incorrect packet size |
SMBus_State_PECError | PEC Error detected |
SMBus_State_TimeOutError | Timeout Error |
SMBus_State_Target_FirstByte | 1st byte (cmd) received |
SMBus_State_Target_ByteReceived | Target received a byte (2-n) |
SMBus_State_Target_QCMD | Quick Command detected |
SMBus_State_Target_CmdComplete | Complete packet received by target |
SMBus_State_Target_Error | SMBus Target Error |
SMBus_State_Target_NotReady | SMBus Buffers haven't been initialized |
SMBus_State_Target_NTR | No Interrupt flags detected |
SMBus_State_Controller_ArbLost | Arbitration Lost |
SMBus_State_Controller_NACK | Unexpected NACKed |
SMBus_State_Controller_Error | SMBus Controller error |
SMBus_State_Unknown | SMBus State Unknown |
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_OK, and SMBus::state.
uint16_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_enablePEC | ( | SMBus * | smbus | ) |
Enables PEC support.
smbus | Pointer to SMBus structure |
References SMBus_Ctrl::bits, SMBus::ctrl, and SMBus_Ctrl::pecEn.
void SMBus_disablePEC | ( | SMBus * | smbus | ) |
Disables PEC support.
smbus | Pointer to SMBus structure |
References SMBus_Ctrl::bits, SMBus::ctrl, and SMBus_Ctrl::pecEn.
void SMBus_targetInit | ( | SMBus * | smbus, |
I2C_Regs * | i2cAddr | ||
) |
Initialize the SMBus interface as a target.
Initializes the NWK and PHY layers.
smbus | Pointer to SMBus structure |
i2cAddr | Base address of I2C module. |
References SMBus_Ctrl::bits, SMBus_Ctrl::controller, SMBus::ctrl, SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus_Nwk::eState, SMBus::nwk, SMBus_Nwk::pec, SMBus_Nwk::recByteTxPtr, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxIndex, SMBus_Nwk::rxLen, SMBus_Nwk::rxSize, SMBus_NwkState_Idle, SMBus_PHY_targetInit(), SMBus_State_OK, SMBus::state, SMBus::status, SMBus_Nwk::txBuffPtr, SMBus_Nwk::txIndex, SMBus_Nwk::txLen, SMBus_Nwk::txSize, SMBus_Ctrl::u8byte, and SMBus_Status::u8byte.
void SMBus_targetEnableInt | ( | SMBus * | smbus | ) |
Enables the I2C interrupts for a target.
This function enables the I2C Start, Stop, RX, TX, Timeout interrupts
smbus | Pointer to SMBus structure |
References SMBus_PHY_targetEnableInt().
Referenced by SMBus_PHY_targetEnable().
SMBus_State SMBus_targetProcessInt | ( | SMBus * | smbus | ) |
I2C Interrupt Service routine for a target.
Handles the interrupts for SMBus passing information to NWK layer Should be called by application when I2C interrupt is detected
smbus | Pointer to SMBus structure |
References SMBus_PHY_targetProcessInt(), SMBus_State_Target_NTR, and SMBus::state.
void SMBus_controllerReset | ( | SMBus * | smbus | ) |
Force reset to SMBus controller interface.
Resets the network and PHY layers
smbus | Pointer to SMBus structure |
References SMBus_NWK_controllerReset().
void SMBus_targetSetAddress | ( | SMBus * | smbus, |
uint8_t | targetAddr | ||
) |
Set the target's own I2C address.
smbus | Pointer to SMBus structure |
targetAddr | Target I2C address |
References SMBus::ownTargetAddr.
void SMBus_targetSetRxBuffer | ( | SMBus * | smbus, |
uint8_t * | data, | ||
uint16_t | size | ||
) |
Initialize the reception buffer for target.
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_targetSetTxBuffer | ( | SMBus * | smbus, |
uint8_t * | data, | ||
uint16_t | size | ||
) |
Initialize the transmission buffer for target.
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.
void SMBus_targetReportError | ( | SMBus * | smbus, |
SMBus_ErrorCode | errorCode | ||
) |
Reports an error to SMBus driver from the target.
Used to signal an error when incorrect command/data is detected by the target
smbus | Pointer to SMBus structure |
errorCode | SMBus_ErrorCode |
References SMBus_Status::bits, SMBus_Status::cmdErr, SMBus_Nwk::eState, SMBus::nwk, SMBus_Status::packErr, SMBus_ErrorCode_Cmd, SMBus_ErrorCode_Packet, SMBus_NwkState_Error, and SMBus::status.
uint8_t SMBus_targetGetCommand | ( | SMBus * | smbus | ) |
Return the current command (Rxbuffer[0]) received by the target.
smbus | Pointer to SMBus structure |
References SMBus_Nwk::currentCmd, and SMBus::nwk.
uint8_t SMBus_targetClearStatusReg | ( | SMBus * | smbus, |
uint8_t | val | ||
) |
Clear the target'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.
uint8_t SMBus_targetWriteCtrlReg | ( | SMBus * | smbus, |
uint8_t | val | ||
) |
Write a value to the target's control register.
smbus | Pointer to SMBus structure |
val | Value being written to the Control register |
References SMBus::ctrl, SMBus_Ctrl::u8byte, SMBus_Ctrl::writeableBits, and SMBus_Ctrl::writeBits.
void SMBus_controllerInit | ( | SMBus * | smbus, |
I2C_Regs * | i2cAddr, | ||
uint32_t | busClk | ||
) |
Initialize the SMBus Interface for a controller.
Initializes the NWK and PHY layers
smbus | Pointer to SMBus structure |
i2cAddr | Base address of I2C module. |
busClk | SMCLK Frequency |
References SMBus_Ctrl::bits, SMBus_Ctrl::controller, SMBus::ctrl, SMBus_Nwk::currentAddr, SMBus_Nwk::eState, SMBus::nwk, SMBus_Nwk::pec, SMBus_Nwk::recByteTxPtr, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxIndex, SMBus_Nwk::rxLen, SMBus_Nwk::rxSize, SMBus_NwkState_Idle, SMBus_PHY_controllerInit(), SMBus_State_OK, SMBus::state, SMBus::status, SMBus_Nwk::txBuffPtr, SMBus_Nwk::txIndex, SMBus_Nwk::txLen, SMBus_Nwk::txSize, SMBus_Ctrl::u8byte, and SMBus_Status::u8byte.
void SMBus_controllerEnableInt | ( | SMBus * | smbus | ) |
Enables the I2C interrupts for a controller.
This function enables the I2C Start, Stop, RX, TX, Timeout interrupts. SMBus_controllerInit() must be called before this function.
smbus | Pointer to SMBus structure |
References SMBus_PHY_controllerEnableInt().
Referenced by SMBus_PHY_controllerEnable().
SMBus_State SMBus_controllerProcessInt | ( | SMBus * | smbus | ) |
I2C Interrupt Service routine for a controller.
Handles the interrupts for SMBus passing information to NWK layer Should be called by application when I2C interrupt is detected
smbus | Pointer to SMBus structure |
References SMBus_PHY_controllerProcessInt().
int8_t SMBus_controllerProcessCall | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | command, | ||
uint8_t * | txData, | ||
uint8_t * | rxData | ||
) |
Sends a process call to a target.
Send process call to the target. A command byte and 2 bytes of TX data are required. Two bytes of data will be returned by the target in rxData.
smbus | Pointer to SMBus structure |
targetAddr | Target address |
command | Command byte for target |
txData | TX data buffer |
rxData | RX data buffer |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus_Nwk::eState, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.
int8_t SMBus_controllerProcessCallBlock | ( | 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 target. A command byte, length and tx data byte array are required. Ensure that rxData is large enough to hold the data received from the target.
smbus | Pointer to SMBus structure |
targetAddr | Target address |
command | Command byte for target |
txData | TX data buffer |
txSize | Size of the txData buffer |
rxData | RX data buffer |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus_Nwk::eState, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMB_MAX_PAYLOAD_SIZE, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.
int8_t SMBus_controllerSendByte | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | txData | ||
) |
Sends byte to the target.
smbus | Pointer to SMBus structure |
targetAddr | Target address |
txData | TX data buffer |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus_Nwk::eState, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMB_MAX_PAYLOAD_SIZE, SMBus_NWK_startRxTransfer(), SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_RX, SMBus_NwkState_TX, SMBus_NwkState_TX_Block, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.
int8_t SMBus_controllerReadByteWord | ( | SMBus * | smbus, |
uint8_t | targetAddr, | ||
uint8_t | command, | ||
uint8_t * | rxData, | ||
uint8_t | rxSize | ||
) |
Receive a byte from the target.
SMBus Block Read command protocol
Block Read:
Block Read with PEC:
where: S = Start bit Sr = Reapeated Start bit Wr = Write bit (0) Rd = Read bit (1) Target Adddress = SMBus address for target Command Code = Command byte sent to target Data Byte = data sent to target A = Acknowledge from target PEC = Optional Packet Error Code P = Stop bit
SMBus Block Write command protocol
Block Write:
8 1 8 1 1
| Data Byte 2 | A | ... | Data Byte N | A | P |
Block Write with PEC:
8 1 8 1 8 1 1
| Data Byte 2 | A | ... | Data Byte N | A | PEC | A | P |
where: S = Start bit Wr = Write bit (0) Target Adddress = SMBus address for target Command Code = Command byte sent to target Data Byte = data sent to target A = Acknowledge from target PEC = Optional Packet Error Code P = Stop bit
SMBus Read ByteWord command protocol
Read Byte:
Read Byte with PEC:
Read Word:
Read Word with PEC:
where: S = Start bit Wr = Read bit (0) Rd = Read bit (1) Target Adddress = SMBus address for target Command Code = Command byte sent to target Data Byte = data sent to target A = Acknowledge from target PEC = Optional Packet Error Code P = Stop bit
~~~~~~~~
smbus | Pointer to SMBus structure |
targetAddr | Target address |
command | Command byte for target |
rxData | RX data buffer |
rxSize | Must be 1 or 2 bytes |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus_Nwk::eState, SMBus::nwk, SMBus_Nwk::rxBuffPtr, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.
int8_t SMBus_controllerWriteByteWord | ( | 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 target.
smbus | Pointer to SMBus structure |
targetAddr | Target address |
command | Command byte for target |
txData | TX data buffer |
txSize | Must be 1 or 2 bytes |
References SMBus_Nwk::currentAddr, SMBus_Nwk::currentCmd, SMBus_Nwk::eState, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TX, SMBUS_RET_ERROR, SMBUS_RET_OK, SMBus_Nwk::txBuffPtr, and SMBus_Nwk::txLen.
int8_t SMBus_controllerQuickCommand | ( | 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 | Target address |
write | true if this is a write command, false if this is a read command |
References SMBus_Nwk::currentAddr, SMBus_Nwk::eState, SMBus::nwk, SMBus_Nwk::rxLen, SMBus_NWK_startTxTransfer(), SMBus_NwkState_Idle, SMBus_NwkState_TXQuickCMD, SMBUS_RET_ERROR, SMBUS_RET_OK, and SMBus_Nwk::txLen.
int8_t SMBus_controllerWaitUntilDone | ( | SMBus * | smbus, |
int32_t | timeout | ||
) |
Wait until the previous SMBus command is executed.
smbus | Pointer to SMBus structure |
timeout | Software timeout |
References SMBus_Nwk::eState, SMBus::nwk, SMBus_NwkState_Idle, SMBUS_RET_ERROR, and SMBUS_RET_OK.