smbus.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00025 //Prototypes...
00026 void InitSMBus(void);
00027 void SMB_Master(void);
00028 void MasterInsertMsg(unsigned char addr, unsigned char cmd, unsigned int data);
00029 void SMB_CmdInterpreter(void);
00030 void SMB_RestoreBus(void);      //this is used by generic timer to recover BusFault
00031 void InitSMBvariables(void);
00032 void Check50uS(void);
00033 
00034 
00035 
00036 #define SMBvariables SV.SMBvar
00037 #define SMBvar_int   SV.SMBint
00038 
00039 #ifdef MODULE_SMBUS
00040   union { volatile unsigned char SMBvar[29][2]; volatile unsigned int SMBint[29]; } SV;
00041 
00042   //Note: all of these strings must fit inside TW_TxBuf with room for Addr+Cmd+PEC
00043   //Also, at the front of each string is a "string constant" that indicates the
00044   //length of the rest of the string; this constant is in OCTAL!!
00045   __flash char str_MfrName[]    = "\014Atmel Norway"; //__flash char
00046   __flash char str_DeviceName[] = "\005SB100";
00047   __flash char str_DeviceChem[] = "\004LION";
00048   __flash char str_MfrData[]    = "\013MfrDataArea";
00049 
00050 #else
00051 
00052   extern union { volatile unsigned char SMBvar[29][2]; volatile unsigned int SMBint[29]; } SV;
00053 
00054 #endif
00055 
00056 
00057 
00058 #define HOST_ADDR    0x10  // According to smbus specification Appendix C
00059 #define CHARGER_ADDR 0x12
00060 #define BATTERY_ADDR 0x16
00061 
00062 
00063 // Note that the following cmds are both Master Write to Charger, and Slave Read.
00064 #define SMB_M_CMD_CHARGINGCURRENT 0x14
00065 #define SMB_M_CMD_CHARGINGVOLTAGE 0x15
00066 
00067 //This command is Master Write only, to both the Charger & Host addresses
00068 #define SMB_M_CMD_ALARMWARNING 0x16
00069 
00070 
00071 //SMBus Variable + Command Name offset list
00072 #define SMBV_MfrAccess  0
00073 #define SMBV_RemCapAlm  1
00074 #define SMBV_RemTimeAlm 2
00075 #define SMBV_BattMode   3
00076 #define SMBV_AtRate     4
00077 #define SMBV_AtRateTTF  5
00078 #define SMBV_AtRateTTE  6
00079 #define SMBV_AtRateOK   7
00080 
00081 #define SMBV_Temperature 8
00082 #define SMBV_Voltage     9
00083 #define SMBV_Current    10
00084 #define SMBV_AvgCurrent 11
00085 #define SMBV_MaxError   12
00086 #define SMBV_RelSOC     13
00087 #define SMBV_AbsSOC     14
00088 #define SMBV_RemCap     15
00089 
00090 #define SMBV_FullChgCap 16
00091 #define SMBV_RunTTE     17
00092 #define SMBV_AvgTTE     18
00093 #define SMBV_AvgTTF     19
00094 #define SMBV_ChgCurrent 20
00095 #define SMBV_ChgVoltage 21
00096 #define SMBV_BattStatus 22
00097 #define SMBV_CycleCount 23
00098 
00099 #define SMBV_DesignCap  24
00100 #define SMBV_DesignVolt 25
00101 #define SMBV_SpecInfo   26
00102 #define SMBV_MfrDate    27
00103 #define SMBV_SerialNo   28
00104 
00105 #define SMBV_MfrName    32
00106 #define SMBV_DeviceName 33
00107 #define SMBV_DeviceChem 34
00108 #define SMBV_MfrData    35
00109 #define SMBV_Opt5     0x2F
00110 #define SMBV_Opt4     0x3C
00111 #define SMBV_Opt3     0x3D
00112 #define SMBV_Opt2     0x3E
00113 #define SMBV_Opt1     0x3F
00114 
00115 
00116 
00117 //Offsets within each of the 29 SMBvariables elements
00118 #define lobyte 0
00119 #define hibyte 1
00120 
00121 
00122 
00123 
00124 //SMBV_BatteryMode bit definitions
00125 
00126 //  HiByte
00127 #define CHARGE_CONTROLLER_ENABLED       0x01
00128 #define PRIMARY_BATTERY                 0x02
00129 #define ALARM_MODE                      0x20
00130 #define CHARGER_MODE                    0x40
00131 #define CAPACITY_MODE                   0x80
00132 
00133 //  LoByte
00134 #define INTERNAL_CHARGE_CONTROLLER      0x01
00135 #define PRIMARY_BATTERY_SUPPORT         0x02
00136 #define CONDITION_FLAG                  0x80
00137 
00138 
00139 
00140 //SMBV_BatteryStatus bit definitions.
00141 
00142 // HiByte
00143 /* * * * * * Alarm Bits * * * * */
00144 #define OVER_CHARGED_ALARM              0x80
00145 #define TERMINATE_CHARGE_ALARM          0x40
00146 #define OVER_TEMP_ALARM                 0x10
00147 #define TERMINATE_DISCHARGE_ALARM       0x08
00148 #define REMAINING_CAPACITY_ALARM        0x02
00149 #define REMAINING_TIME_ALARM            0x01
00150 
00151 // LoByte
00152 /* * * * * * Status Bits * * * * */
00153 #define INITIALIZED             0x80
00154 #define DISCHARGING             0x40
00155 #define FULLY_CHARGED           0x20
00156 #define FULLY_DISCHARGED        0x10
00157 
00158 /* * * * * * Error Codes * * * * */
00159 #define SMBerr_OK               0x00    // r/w The Smart Battery processed the function code without detecting any errors.
00160 #define SMBerr_Busy             0x01    // r/w The Smart Battery is unable to process the function code at this time.
00161 #define SMBerr_ReservedCommand  0x02    // r/w The Smart Battery detected an attempt to read or write to a function code
00162                                         //     reserved by this version of the specification. The Smart Battery detected
00163                                         //     an attempt to access an unsupported optional manufacturer function code.
00164 #define SMBerr_UnsuptdCommand   0x03    // r/w The Smart Battery does not support this function code which is
00165                                         //     defined in this version of the specification.
00166 #define SMBerr_AccessDenied     0x04    //  w  The Smart Battery detected an attempt to write to a read-only function code.
00167 #define SMBerr_OverUnderflow    0x05    // r/w The Smart Battery detected a data overflow or under flow.
00168 #define SMBerr_BadSize          0x06    //  w  The Smart Battery detected an attempt to write to a function code with
00169                                         //     an incorrect size data block.
00170 #define SMBerr_UnknownError     0x07    // r/w The Smart Battery detected an unidentifiable error.
00171 

Generated on Mon Nov 12 15:59:58 2007 for AVR453 Smart Battery Reference Design by  doxygen 1.5.3