TWI low-level code & command interpreters.
Definition in file smbus.c.
#include <inavr.h>
#include "smbus.h"
#include "timer.h"
#include "pack.h"
#include "analog.h"
#include "calibration.h"
#include <iom406.h>
#include "interpret.h"
#include "main.h"
#include "pwrmgmt.h"
Go to the source code of this file.
Defines | |
| #define | HIGHEST_SMB_CMD 0x3F |
| #define | MODULE_SMBUS |
| #define | SMB_GenBusTimeout 1 |
| #define | SMB_GotCmdData 4 |
| #define | SMB_SetUpReply 2 |
| #define | TWC_GO 0x85 |
| #define | TWC_READ_NoACK 0x85 |
| #define | TWC_RESTART 0xB5 |
| #define | TWC_START 0xA5 |
| #define | TWC_STOP 0x94 |
| #define | TWS_BERR 0x00 |
| #define | TWS_FINAL 0xC8 |
| #define | TWS_LOST_ARB 0x38 |
| #define | TWS_MASK 0xF8 |
| #define | TWS_NSTAT 0xF8 |
| #define | TWS_RACK 0xB8 |
| #define | TWS_RCMD 0x80 |
| #define | TWS_RDATA 0x80 |
| #define | TWS_READ_ACK 0x40 |
| #define | TWS_READ_NAK 0x48 |
| #define | TWS_REPEAT 0xA0 |
| #define | TWS_RESTART 0x10 |
| #define | TWS_RNAK 0xC0 |
| #define | TWS_RSTOP 0xA0 |
| #define | TWS_RXDATA_ACK 0x50 |
| #define | TWS_RXDATA_NACK 0x58 |
| #define | TWS_SLA_R 0xA8 |
| #define | TWS_SLA_W 0x60 |
| #define | TWS_START 0x08 |
| #define | TWS_TXDATA_ACK 0x28 |
| #define | TWS_TXDATA_NAK 0x30 |
| #define | TWS_WRITE_ACK 0x18 |
| #define | TWS_WRITE_NAK 0x20 |
| #define | TXmsgDelete {++TXmsgTail; TXmsgTail &= (4-1); TXmsgQty--;} |
| #define | TXmsgEmpty (TXmsgQty == 0) |
| #define | TXmsgFull (TXmsgQty == 4) |
Typedefs | |
| typedef unsigned char(* | ptr2funcUC_V )(void) |
Enumerations | |
| enum | { TW_IDLE = 0, TW_Wait4Stop, TW_Wait4Cmd, TW_Wait4RW, TW_Wait4Data, TW_ReplyData, TW_MSLA_W, TW_MCMD_W, TW_MDATA_W } |
Functions | |
| void | Check50uS (void) |
| unsigned char | FastCRC (unsigned char LastCRC, unsigned char newbyte) |
| void | FillResponseInt (unsigned int info) |
| void | FillResponseStr (char __flash *source) |
| void | InitSMBus (void) |
| void | InitSMBvariables (void) |
| void | MasterInsertMsg (unsigned char addr, unsigned char cmd, unsigned int data) |
| __interrupt void | PCINT0_ISR (void) |
| __interrupt void | PCINT1_ISR (void) |
| void | SMB_CmdInterpreter (void) |
| void | SMB_Master (void) |
| void | SMB_RestoreBus (void) |
| unsigned char | SMBR_AbsSOC (void) |
| unsigned char | SMBR_AtRate (void) |
| unsigned char | SMBR_AtRateOK (void) |
| unsigned char | SMBR_AtRateTTE (void) |
| unsigned char | SMBR_AtRateTTF (void) |
| unsigned char | SMBR_AvgCurrent (void) |
| unsigned char | SMBR_AvgTTE (void) |
| unsigned char | SMBR_AvgTTF (void) |
| unsigned char | SMBR_BattMode (void) |
| unsigned char | SMBR_BattStatus (void) |
| unsigned char | SMBR_ChgCurrent (void) |
| unsigned char | SMBR_ChgVoltage (void) |
| unsigned char | SMBR_Current (void) |
| unsigned char | SMBR_CycleCount (void) |
| unsigned char | SMBR_DesignCap (void) |
| unsigned char | SMBR_DesignVolt (void) |
| unsigned char | SMBR_DeviceChem (void) |
| unsigned char | SMBR_DeviceName (void) |
| unsigned char | SMBR_FullChgCap (void) |
| unsigned char | SMBR_invalid (void) |
| unsigned char | SMBR_MaxError (void) |
| unsigned char | SMBR_MfrAccess (void) |
| unsigned char | SMBR_MfrData (void) |
| unsigned char | SMBR_MfrDate (void) |
| unsigned char | SMBR_MfrName (void) |
| unsigned char | SMBR_Opt1 (void) |
| unsigned char | SMBR_Opt2 (void) |
| unsigned char | SMBR_Opt3 (void) |
| unsigned char | SMBR_Opt4 (void) |
| unsigned char | SMBR_Opt5 (void) |
| unsigned char | SMBR_RelSOC (void) |
| unsigned char | SMBR_RemCap (void) |
| unsigned char | SMBR_RemCapAlm (void) |
| unsigned char | SMBR_RemTimeAlm (void) |
| unsigned char | SMBR_RunTTE (void) |
| unsigned char | SMBR_SerialNo (void) |
| unsigned char | SMBR_SpecInfo (void) |
| unsigned char | SMBR_Temperature (void) |
| unsigned char | SMBR_Voltage (void) |
| unsigned char | SMBW_AtRate (void) |
| unsigned char | SMBW_BattMode (void) |
| unsigned char | SMBW_Invalid (void) |
| unsigned char | SMBW_MfrAccess (void) |
| unsigned char | SMBW_Opt1 (void) |
| unsigned char | SMBW_Opt2 (void) |
| unsigned char | SMBW_Opt3 (void) |
| unsigned char | SMBW_Opt4 (void) |
| unsigned char | SMBW_Opt5 (void) |
| unsigned char | SMBW_RemCapAlm (void) |
| unsigned char | SMBW_RemTimeAlm (void) |
| __interrupt void | TWI_ISR (void) |
| __interrupt void | TWICD_ISR (void) |
Variables | |
| __flash unsigned char | crctable [16] = {0,0x07,0x0E,0x90, 0x1c,0x1b,0x12,0x15, 0x38,0x3F,0x36,0x31, 0x24,0x23,0x2A,0x2D} |
| __flash unsigned char | crctable2 [16] = {0,0x70,0xE0,0x90, 0xC1,0xB1,0x21,0x51, 0x83,0xF3,0x63,0x13, 0x42,0x32,0xA2,0xD2} |
| unsigned char | CurrentCmd = 0xFF |
| ptr2funcUC_V | SMB_ReadCmd [] |
| ptr2funcUC_V | SMB_WriteCmd [] |
| unsigned char | SMLOCK = 0 |
| unsigned char | TEST50US = 0 |
| unsigned char | TW_MTxBuf [8] |
| unsigned char | TW_MTxBufCnt = 0 |
| unsigned char | TW_MTxBufIndex = 0 |
| unsigned char | TW_RxBuf [10] |
| signed char | TW_RxBufCnt = 0 |
| unsigned char | TW_RxBufIndex = 0 |
| unsigned char | TW_TxBuf [36] |
| unsigned char | TW_TxBufCnt = 0 |
| unsigned char | TW_TxBufIndex = 0 |
| unsigned char | TWI_CmdFlags |
| unsigned char | TWISR_state = TW_IDLE |
| unsigned char | TXmsg [4][4] |
| volatile unsigned char | TXmsgHead = 0 |
| volatile unsigned char | TXmsgQty = 0 |
| volatile unsigned char | TXmsgTail = 0 |
| unsigned char | UsePEC = 0 |
| #define TXmsgEmpty (TXmsgQty == 0) |
| #define TXmsgFull (TXmsgQty == 4) |
| typedef unsigned char(* ptr2funcUC_V)(void) |
| anonymous enum |
| unsigned char FastCRC | ( | unsigned char | LastCRC, | |
| unsigned char | newbyte | |||
| ) |
| void FillResponseInt | ( | unsigned int | info | ) |
Definition at line 920 of file smbus.c.
References TW_TxBuf, TW_TxBufCnt, and TW_TxBufIndex.
Referenced by SMBR_AbsSOC(), SMBR_AtRate(), SMBR_AtRateOK(), SMBR_AtRateTTE(), SMBR_AtRateTTF(), SMBR_AvgCurrent(), SMBR_AvgTTE(), SMBR_AvgTTF(), SMBR_BattMode(), SMBR_BattStatus(), SMBR_ChgCurrent(), SMBR_ChgVoltage(), SMBR_Current(), SMBR_CycleCount(), SMBR_DesignCap(), SMBR_DesignVolt(), SMBR_FullChgCap(), SMBR_MaxError(), SMBR_MfrAccess(), SMBR_MfrDate(), SMBR_Opt4(), SMBR_Opt5(), SMBR_RelSOC(), SMBR_RemCap(), SMBR_RemCapAlm(), SMBR_RemTimeAlm(), SMBR_RunTTE(), SMBR_SerialNo(), SMBR_SpecInfo(), SMBR_Temperature(), and SMBR_Voltage().
| void FillResponseStr | ( | char __flash * | source | ) |
Definition at line 930 of file smbus.c.
References ctr, TW_TxBuf, TW_TxBufCnt, and TW_TxBufIndex.
Referenced by SMBR_DeviceChem(), SMBR_DeviceName(), SMBR_MfrData(), and SMBR_MfrName().
| void InitSMBvariables | ( | void | ) |
Definition at line 1618 of file smbus.c.
Referenced by InitAll().
| void MasterInsertMsg | ( | unsigned char | addr, | |
| unsigned char | cmd, | |||
| unsigned int | data | |||
| ) |
| void SMB_CmdInterpreter | ( | void | ) |
| void SMB_Master | ( | void | ) |
| unsigned char SMBR_AbsSOC | ( | void | ) |
Definition at line 1070 of file smbus.c.
References AbsoluteSOC(), FillResponseInt(), SMBV_AbsSOC, and SMBvar_int.
| unsigned char SMBR_AtRate | ( | void | ) |
| unsigned char SMBR_AtRateOK | ( | void | ) |
Definition at line 1006 of file smbus.c.
References AtRateOK(), FillResponseInt(), SMBV_AtRateOK, and SMBvar_int.
| unsigned char SMBR_AtRateTTE | ( | void | ) |
Definition at line 997 of file smbus.c.
References AtRateTTE(), FillResponseInt(), SMBV_AtRateTTE, and SMBvar_int.
| unsigned char SMBR_AtRateTTF | ( | void | ) |
Definition at line 988 of file smbus.c.
References AtRateTTF(), FillResponseInt(), SMBV_AtRateTTF, and SMBvar_int.
| unsigned char SMBR_AvgCurrent | ( | void | ) |
Definition at line 1043 of file smbus.c.
References CCarray_Average(), FillResponseInt(), SMBV_AvgCurrent, and SMBvar_int.
| unsigned char SMBR_AvgTTE | ( | void | ) |
Definition at line 1106 of file smbus.c.
References FillResponseInt(), SMBV_AvgTTE, SMBvar_int, and TimeToEmpty().
| unsigned char SMBR_AvgTTF | ( | void | ) |
Definition at line 1115 of file smbus.c.
References AvgTimeToFull(), FillResponseInt(), SMBV_AvgTTF, and SMBvar_int.
| unsigned char SMBR_BattMode | ( | void | ) |
Definition at line 974 of file smbus.c.
References FillResponseInt(), SMBV_BattMode, and SMBvar_int.
| unsigned char SMBR_BattStatus | ( | void | ) |
Definition at line 1147 of file smbus.c.
References FillResponseInt(), lobyte, SMBV_BattStatus, SMBvar_int, and SMBvariables.
| unsigned char SMBR_ChgCurrent | ( | void | ) |
Definition at line 1128 of file smbus.c.
References FillResponseInt(), lobyte, SMBV_BattStatus, SMBV_ChgCurrent, SMBvar_int, and SMBvariables.
| unsigned char SMBR_ChgVoltage | ( | void | ) |
Definition at line 1136 of file smbus.c.
References FillResponseInt(), lobyte, SMBV_BattStatus, SMBV_ChgVoltage, SMBvar_int, and SMBvariables.
| unsigned char SMBR_Current | ( | void | ) |
Definition at line 1033 of file smbus.c.
References Current1Sec(), FillResponseInt(), SMBV_Current, and SMBvar_int.
| unsigned char SMBR_CycleCount | ( | void | ) |
Definition at line 1155 of file smbus.c.
References FillResponseInt(), SMBV_CycleCount, and SMBvar_int.
| unsigned char SMBR_DesignCap | ( | void | ) |
Definition at line 1162 of file smbus.c.
References CAPACITY_MODE, FillResponseInt(), hibyte, PACK_DESIGNCAPC5, PACK_DESIGNCAPMW, SMBV_BattMode, SMBV_DesignCap, SMBvar_int, and SMBvariables.
| unsigned char SMBR_DesignVolt | ( | void | ) |
Definition at line 1177 of file smbus.c.
References FillResponseInt(), PACK_NOMINALV, SMBV_DesignVolt, and SMBvar_int.
| unsigned char SMBR_DeviceChem | ( | void | ) |
| unsigned char SMBR_DeviceName | ( | void | ) |
| unsigned char SMBR_FullChgCap | ( | void | ) |
Definition at line 1088 of file smbus.c.
References FillResponseInt(), FullChgCap(), SMBV_FullChgCap, and SMBvar_int.
| unsigned char SMBR_invalid | ( | void | ) |
| unsigned char SMBR_MaxError | ( | void | ) |
Definition at line 1053 of file smbus.c.
References FillResponseInt(), SMBV_MaxError, and SMBvar_int.
| unsigned char SMBR_MfrAccess | ( | void | ) |
Definition at line 952 of file smbus.c.
References FillResponseInt(), SMBV_MfrAccess, and SMBvar_int.
| unsigned char SMBR_MfrData | ( | void | ) |
| unsigned char SMBR_MfrDate | ( | void | ) |
Definition at line 1192 of file smbus.c.
References FillResponseInt(), SMBV_MfrDate, and SMBvar_int.
| unsigned char SMBR_MfrName | ( | void | ) |
| unsigned char SMBR_Opt1 | ( | void | ) |
| unsigned char SMBR_Opt2 | ( | void | ) |
| unsigned char SMBR_Opt3 | ( | void | ) |
| unsigned char SMBR_Opt4 | ( | void | ) |
| unsigned char SMBR_Opt5 | ( | void | ) |
Definition at line 1236 of file smbus.c.
References FillResponseInt().
| unsigned char SMBR_RelSOC | ( | void | ) |
Definition at line 1060 of file smbus.c.
References FillResponseInt(), RelativeSOC(), SMBV_RelSOC, and SMBvar_int.
| unsigned char SMBR_RemCap | ( | void | ) |
Definition at line 1079 of file smbus.c.
References FillResponseInt(), RemainingCap(), SMBV_RemCap, and SMBvar_int.
| unsigned char SMBR_RemCapAlm | ( | void | ) |
Definition at line 960 of file smbus.c.
References FillResponseInt(), SMBV_RemCapAlm, and SMBvar_int.
| unsigned char SMBR_RemTimeAlm | ( | void | ) |
Definition at line 967 of file smbus.c.
References FillResponseInt(), SMBV_RemTimeAlm, and SMBvar_int.
| unsigned char SMBR_RunTTE | ( | void | ) |
Definition at line 1097 of file smbus.c.
References FillResponseInt(), SMBV_RunTTE, SMBvar_int, and TimeToEmpty().
| unsigned char SMBR_SerialNo | ( | void | ) |
Definition at line 1199 of file smbus.c.
References FillResponseInt(), SMBV_SerialNo, and SMBvar_int.
| unsigned char SMBR_SpecInfo | ( | void | ) |
Definition at line 1185 of file smbus.c.
References FillResponseInt(), SMBV_SpecInfo, and SMBvar_int.
| unsigned char SMBR_Temperature | ( | void | ) |
Definition at line 1015 of file smbus.c.
References FillResponseInt(), GetTemperature(), SMBV_Temperature, and SMBvar_int.
| unsigned char SMBR_Voltage | ( | void | ) |
Definition at line 1024 of file smbus.c.
References FillResponseInt(), GetVoltage(), SMBV_Voltage, and SMBvar_int.
| unsigned char SMBW_AtRate | ( | void | ) |
Definition at line 1432 of file smbus.c.
References lobyte, SMBV_AtRate, SMBV_BattStatus, SMBvar_int, SMBvariables, TW_RxBuf, and TW_RxBufIndex.
| unsigned char SMBW_BattMode | ( | void | ) |
Definition at line 1387 of file smbus.c.
References ALARM_MODE, CAPACITY_MODE, CHARGE_CONTROLLER_ENABLED, CHARGER_MODE, INTERNAL_CHARGE_CONTROLLER, lobyte, PRIMARY_BATTERY, SetAlarmMode, SMBerr_AccessDenied, SMBV_BattMode, SMBvar_int, SMBvariables, TW_RxBuf, and TW_RxBufIndex.
| unsigned char SMBW_Invalid | ( | void | ) |
| unsigned char SMBW_MfrAccess | ( | void | ) |
Definition at line 1360 of file smbus.c.
References lobyte, SMBV_BattStatus, SMBV_MfrAccess, SMBvar_int, SMBvariables, TW_RxBuf, and TW_RxBufIndex.
| unsigned char SMBW_Opt1 | ( | void | ) |
| unsigned char SMBW_Opt2 | ( | void | ) |
| unsigned char SMBW_Opt3 | ( | void | ) |
| unsigned char SMBW_Opt4 | ( | void | ) |
Definition at line 1454 of file smbus.c.
References calibration_state_req, SetCalibRequest, TW_RxBuf, and TW_RxBufIndex.
| unsigned char SMBW_RemCapAlm | ( | void | ) |
Definition at line 1369 of file smbus.c.
References lobyte, SMBV_BattStatus, SMBV_RemCapAlm, SMBvar_int, SMBvariables, TW_RxBuf, and TW_RxBufIndex.
| unsigned char SMBW_RemTimeAlm | ( | void | ) |
Definition at line 1378 of file smbus.c.
References lobyte, SMBV_BattStatus, SMBV_RemTimeAlm, SMBvar_int, SMBvariables, TW_RxBuf, and TW_RxBufIndex.
| __interrupt void TWI_ISR | ( | void | ) |
Definition at line 374 of file smbus.c.
References CurrentCmd, HIGHEST_SMB_CMD, lobyte, SCRG, SCRW, SCWG, SCWW, SM_Cmd_Table, SMB_GenBusTimeout, SMB_GotCmdData, SMB_SetUpReply, SMBerr_AccessDenied, SMBerr_BadSize, SMBerr_UnknownError, SMBslave, SMBV_BattStatus, SMBvariables, SMLOCK, Status, TW_IDLE, TW_MCMD_W, TW_MSLA_W, TW_MTxBuf, TW_MTxBufCnt, TW_MTxBufIndex, TW_ReplyData, TW_RxBuf, TW_RxBufCnt, TW_RxBufIndex, TW_TxBuf, TW_TxBufCnt, TW_TxBufIndex, TW_Wait4Cmd, TW_Wait4Data, TW_Wait4RW, TW_Wait4Stop, TWI_CmdFlags, TWISR_state, TWS_RACK, TWS_RCMD, TWS_RDATA, TWS_REPEAT, TWS_RNAK, TWS_RSTOP, TWS_SLA_R, TWS_SLA_W, TWS_START, TWS_TXDATA_ACK, TWS_WRITE_ACK, TXmsgDelete, and UsePEC.
| __interrupt void TWICD_ISR | ( | void | ) |
Definition at line 172 of file smbus.c.
References ChangePowerMode(), hibyte, POWERMODE_ACTIVE, POWERMODE_IDLE, SMBV_BattMode, and SMBvariables.
| __flash unsigned char crctable[16] = {0,0x07,0x0E,0x90, 0x1c,0x1b,0x12,0x15, 0x38,0x3F,0x36,0x31, 0x24,0x23,0x2A,0x2D} |
| __flash unsigned char crctable2[16] = {0,0x70,0xE0,0x90, 0xC1,0xB1,0x21,0x51, 0x83,0xF3,0x63,0x13, 0x42,0x32,0xA2,0xD2} |
| unsigned char CurrentCmd = 0xFF |
| unsigned char SMLOCK = 0 |
| unsigned char TEST50US = 0 |
| unsigned char TW_MTxBuf[8] |
| unsigned char TW_MTxBufCnt = 0 |
| unsigned char TW_MTxBufIndex = 0 |
| signed char TW_RxBufCnt = 0 |
| unsigned char TW_RxBufIndex = 0 |
| unsigned char TW_TxBufCnt = 0 |
| unsigned char TW_TxBufIndex = 0 |
| unsigned char TWI_CmdFlags |
| unsigned char TWISR_state = TW_IDLE |
Definition at line 370 of file smbus.c.
Referenced by SMB_Master(), SMB_RestoreBus(), and TWI_ISR().
| unsigned char TXmsg[4][4] |
| volatile unsigned char TXmsgHead = 0 |
| volatile unsigned char TXmsgQty = 0 |
| volatile unsigned char TXmsgTail = 0 |
1.5.3