interpret.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00025 /*
00026 Things to watch for:
00027   > Ttimeout = 25mS-35mS (clk held low)
00028   > Tbuf = buss free time after stop > 5uS.
00029   > Tpor = 500mS max = startup time allowed before device must respond to SMBus cmds
00030   > Tpdn = power-down time =  >=2.5secs of bus low  (3.1.4.2)
00031 
00032 Ttimeout (Bus Timeout) is detected by reasserting a wdog timer
00033 each time a transition occurs in the TWI state machine.
00034 
00035 Tbuf is assured by requiring that the user exit the state machine
00036 completely after sending or receiving a STOP condition, rather than
00037 looping around internal to the state machine to send the next START.
00038 
00039 Tpor is dependent on the list of startup tasks.  The Power-On Reset itself
00040 is determined to have occurred via the interrupt.
00041 
00042 Tpdn is determined by:
00043 
00044 
00045 SMBus requires that the TWI module act both as a Slave device and, on occasion,
00046 as a Master.  The management of the hardware for operating between these two
00047 modes is handled in the TWI.C module.  Essentially, the TWI module is kept in
00048 Slave mode by default.  When in IDLE state *AND* the bus is Idle, it checks for
00049 the presence of a command in the Master Command buffer.  If present, it will
00050 initiate the switch to Master Mode and commence the transmission.
00051 
00052 Note that to know for certain that the bus is Idle, we must rely on TWSR.
00053 Fortunately, TWSR does in fact accurately reflect the condition of the bus
00054 regardless of whether the Mega406 is actually communicating on it or not.
00055 
00056 */
00057 
00058 
00059 //As defined by SMBus spec, used for dynamically assigned addresses.
00060 #define SMB_defaultaddr 0xC2
00061 
00062 //Addresses
00063 #define SMB_prototype0 0x90
00064 #define SMB_prototype1 0x92
00065 #define SMB_prototype2 0x94
00066 #define SMB_prototype3 0x96
00067 
00068 //Command Type flags
00069 #define SMBinvalid 1
00070 #define SMBmaster  2
00071 #define SMBslave   4
00072 #define SCRW 0x10       /*SMBus Command Read Word*/
00073 #define SCWW 0x20       /*SMBus Command Write Word*/
00074 #define SCRG 0x40       /*SMBus Command Read Block(Group)*/
00075 #define SCWG 0x80       /*SMBus Command Write Block (Group)*/
00076 
00077 
00078 
00079 //Information within the table is defined as follows:
00080 //  [0] = Command-associated features & characteristics flags.
00081 //  [1] =
00082 //  [2] =
00083 //  [3] =
00084 
00085 __flash unsigned char SM_Cmd_Table[0x40][2] =
00086 {
00087   { SMBslave|SCRW|SCWW, },      //Manufacturer Access, 0x00, r/w word;
00088   { SMBslave|SCRW|SCWW, },      //RemainingCapacityAlarm*, 0x01, r/w word; in mAh or 10mWh
00089   { SMBslave|SCRW|SCWW, },      //RemainingTimeAlarm*, 0x02, r/w word; in minutes
00090   { SMBslave|SCRW|SCWW, },      //BatteryMode, 0x03, r/w word; in bit flags
00091   { SMBslave|SCRW|SCWW, },      //AtRate 0x04 r/w mA or 10mW
00092   { SMBslave|SCRW,      },      //AtRateTimeToFull 0x05 r minutes
00093   { SMBslave|SCRW,      },      //AtRateTimeToEmpty* 0x06 r minutes
00094   { SMBslave|SCRW,      },      //AtRateOK* 0x07 r Boolean
00095 
00096   { SMBslave|SCRW,      },      //Temperature 0x08 r 0.1°K
00097   { SMBslave|SCRW,      },      //Voltage 0x09 r mV
00098   { SMBslave|SCRW,      },      //Current 0x0a r mA
00099   { SMBslave|SCRW,      },      //AverageCurrent 0x0b r mA
00100   { SMBslave|SCRW,      },      //MaxError 0x0c r percent
00101   { SMBslave|SCRW,      },      //RelativeStateOfCharge 0x0d r percent
00102   { SMBslave|SCRW,      },      //AbsoluteStateOfCharge 0x0e r percent
00103   { SMBslave|SCRW,      },      //RemainingCapacity 0x0f r mAh or 10mWh
00104 
00105   { SMBslave|SCRW,      },      //FullChargeCapacity 0x10 r mAh or 10mWh
00106   { SMBslave|SCRW,      },      //RunTimeToEmpty* 0x11 r minutes
00107   { SMBslave|SCRW,      },      //AverageTimeToEmpty* 0x12 r minutes
00108   { SMBslave|SCRW,      },      //AverageTimeToFull 0x13 r minutes
00109   { SMBslave|SMBmaster|SCRW|SCWW,},      //ChargingCurrent 0x14 r mA
00110   { SMBslave|SMBmaster|SCRW|SCWW,},      //ChargingVoltage 0x15 r mV
00111   { SMBslave|SCRW,      },      //BatteryStatus* 0x16 r bit flags
00112   { SMBslave|SCRW,      },      //CycleCount 0x17 r count
00113 
00114   { SMBslave|SCRW,      },      //DesignCapacity 0x18 r mAh or 10mWh
00115   { SMBslave|SCRW,      },      //DesignVoltage 0x19 r mV
00116   { SMBslave|SCRW,      },      //SpecificationInfo 0x1a r unsigned int
00117   { SMBslave|SCRW,      },      //ManufactureDate 0x1b r unsigned int
00118   { SMBslave|SCRW,      },      //SerialNumber 0x1c r number
00119   { SMBinvalid,         },      //reserved 0x1d
00120   { SMBinvalid,         },      //reserved 0x1e
00121   { SMBinvalid,         },      //reserved 0x1f
00122 
00123   { SMBslave|SCRG,      },      //ManufacturerName 0x20 r string
00124   { SMBslave|SCRG,      },      //DeviceName 0x21 r string
00125   { SMBslave|SCRG,      },      //DeviceChemistry 0x22 r string
00126   { SMBslave|SCRG,      },      //ManufacturerData 0x23 r data
00127   { SMBinvalid,         },      //reserved 0x24
00128   { SMBinvalid,         },      //reserved 0x25
00129   { SMBinvalid,         },      //reserved 0x26
00130   { SMBinvalid,         },      //reserved 0x27
00131 
00132   { SMBinvalid,         },      //reserved 0x28
00133   { SMBinvalid,         },      //reserved 0x29
00134   { SMBinvalid,         },      //reserved 0x2a
00135   { SMBinvalid,         },      //reserved 0x2b
00136   { SMBinvalid,         },      //reserved 0x2c
00137   { SMBinvalid,         },      //reserved 0x2d
00138   { SMBinvalid,         },      //reserved 0x2e
00139   { SMBslave|SCRW|SCWW, },      //OptionalMfgFunction5 0x2f r/w data
00140 
00141   { SMBinvalid,         },      //reserved 0x30
00142   { SMBinvalid,         },      //reserved 0x31
00143   { SMBinvalid,         },      //reserved 0x32
00144   { SMBinvalid,         },      //reserved 0x33
00145   { SMBinvalid,         },      //reserved 0x34
00146   { SMBinvalid,         },      //reserved 0x35
00147   { SMBinvalid,         },      //reserved 0x36
00148   { SMBinvalid,         },      //reserved 0x37
00149 
00150   { SMBinvalid,         },      //reserved 0x38
00151   { SMBinvalid,         },      //reserved 0x39
00152   { SMBinvalid,         },      //reserved 0x3a
00153   { SMBinvalid,         },      //reserved 0x3b
00154   { SMBslave|SCRW|SCWW, },      //OptionalMfgFunction4 0x3c r/w word
00155   { SMBslave|SCRW|SCWW, },      //OptionalMfgFunction3 0x3d r/w word
00156   { SMBslave|SCRW|SCWW, },      //OptionalMfgFunction2 0x3e r/w word
00157   { SMBslave|SCRW|SCWW, }       //OptionalMfgFunction1 0x3f r/w word
00158 };
00159 
00160 
00161 
00162 /*
00163 
00164 Status Handler:
00165 
00166 Current         TWSR                                               Next
00167 State          Status     Meaning               Actions            State
00168 ----------     ------   ------------    ----------------------  ------------
00169 Idle            0x60    saw SLA w/WR    set TWEA                  Wait4Cmd
00170 
00171                 0xA8    saw SLA w/RD    goto ReplyData              n/a
00172 
00173 Wait4Cmd        0x80    got CMD         store Cmd Byte,         
00174                                         set TWEA                  Wait4RW
00175                 
00176 Wait4RW         0x80    got data byte   goto Wait4Data handler      n/a
00177 
00178                 0xA0    SLA incoming    set up data for Reply       Idle
00179                                         (based on Cmd rcvd)     
00180 
00181 Wait4Data       0x80    got data        store Data byte,
00182                                         set TWEA                  Wait4Data
00183 
00184                 0xA0    got Stop        flag MsgDone.               Idle
00185                         
00186 ReplyData       0xA8    must send first   load TWDR, and set      ReplyData
00187                         byte of Reply     TWEA only if not last
00188 
00189                 0xB8    got ACK; send     Load TWDR, and set      ReplyData
00190                         out more data.    TWEA only if not last
00191 
00192                 0xC0    got NAK         if have more, flag Error;   Idle
00193                                         if no more, done.           Idle
00194 
00195                 0xC8    got ACK after     flag error,               Idle
00196                         sent Final Byte   set TWEA.
00197 
00198 
00199 
00200 Normal sequence for Write Word without PEC:
00201 
00202 CURRENT
00203 STATE      BUS ACTIVITY      TWSR    RESPONSE
00204 -------    ----------------  ----    --------------------------------------------------
00205 Idle       Receives SLA+W    0x60    Clear SMB_Master_Request_Delay. State=Wait4Cmd.
00206 Wait4Cmd   Receives Cmd      0x80    Get Features & validate command. State=Wait4RW.
00207 Wait4RW    Receives LowByte  0x80    Init RX buffer & store. State=Wait4Data.
00208 Wait4Data  Receives HighByte 0x80    Store. Flag Foreground to process it.
00209 < Foreground routine analyzes received command, then clears TWINT. Master issues STOP. >
00210 Wait4Data  Receives STOP     0xA0    State=Idle.
00211 
00212 
00213 Normal sequence for Write Word WITH PEC:
00214 
00215 CURRENT
00216 STATE      BUS ACTIVITY      TWSR    RESPONSE
00217 -------    ----------------  ----    --------------------------------------------------
00218 Idle       Receives SLA+W    0x60    Clear SMB_Master_Request_Delay. State=Wait4Cmd.
00219 Wait4Cmd   Receives Cmd      0x80    Get Features & validate command. State=Wait4RW.
00220 Wait4RW    Receives LowByte  0x80    Init RX buffer & store. State=Wait4Data.
00221 Wait4Data  Receives HighByte 0x80    Store.
00222 Wait4Data  Receive PEC       0x80    Store. Flag Foreground to process it.
00223 < Foreground routine analyzes received command, then clears TWINT. Master issues STOP. >
00224 Wait4Data  Receive STOP      0xA0    State=Idle.
00225 
00226 
00227 
00228 
00229 Normal sequence for Read Word without PEC:
00230 
00231 CURRENT
00232 STATE      BUS ACTIVITY      TWSR    RESPONSE
00233 -------    ---------------   ----    --------------------------------------------------
00234 Idle       Received SLA+W    0x60    Clear SMB_Master_Request_Delay. State=Wait4Cmd.
00235 Wait4Cmd   Received Cmd      0x80    Get Features & validate command. State=Wait4RW.
00236 Wait4RW    Received Start    0xA0    Flag foreground to set up Reply data. State=ReplyData.
00237 < Foreground routine analyzes received command, then clears TWINT. Master continues. >
00238 ReplyData  Received SLA+R    0xA8    Load TWDR & set TWEA.
00239 ReplyData  Received ACK      0xB8    Load TWDR but do not set TWEA (expect NAK back).
00240 ReplyData  Received NAK      0xC0    State=Idle.
00241 
00242 
00243 Normal sequence for Read Word WITH PEC:
00244 
00245 CURRENT
00246 STATE      BUS ACTIVITY      TWSR    RESPONSE
00247 -------    ---------------   ----    --------------------------------------------------
00248 Idle       Received SLA+W    0x60    Clear SMB_Master_Request_Delay. State=Wait4Cmd.
00249 Wait4Cmd   Received Cmd      0x80    Get Features & validate command. State=Wait4RW.
00250 Wait4RW    Received Start    0xA0    Flag foreground to set up Reply data. State=ReplyData.
00251 < Foreground routine analyzes received command, then clears TWINT. Master continues. >
00252 ReplyData  Received SLA+R    0xA8    Load TWDR & set TWEA.
00253 ReplyData  Received ACK      0xB8    Load TWDR & set TWEA.
00254 ReplyData  Received ACK      0xB8    Load TWDR but do not set TWEA (expect NAK back).
00255 ReplyData  Received NAK      0xC0    State=Idle.
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 */
00265 
00266 
00267 

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