Created intelligent sniffer (isniff) to help decode CAN messages
[goodfet] / client / GoodFETCC.py
index 04826f4..1d5a7b7 100644 (file)
@@ -11,18 +11,40 @@ import binascii;
 from GoodFET import GoodFET;
 from intelhex import IntelHex;
 
-import xml.dom.minidom, time;
+import xml.dom.minidom, time, os;
 
 class GoodFETCC(GoodFET):
     """A GoodFET variant for use with Chipcon 8051 Zigbee SoC."""
     APP=0x30;
     
-    smartrfpath="/opt/smartrf7";
+    smartrfpath=None;
+    def __init__(self,filename=None):
+        """GoodFETCC constructor.
+        Mostly concerned with finding SmartRF7."""
+        if self.smartrfpath==None:
+            self.smartrfpath=os.environ.get("SMARTRF");
+        if self.smartrfpath==None and os.name=='nt':
+            pf=os.environ['PROGRAMFILES'];
+            self.smartrfpath="%s\\\\Texas Instruments\\\\SmartRF Tools\\\\SmartRF Studio 7" % pf;
+            
+        if self.smartrfpath==None:
+            self.smartrfpath="/opt/smartrf7";
+        
+    haveloadedsymbols=False;
     def loadsymbols(self):
-        try: self.SRF_loadsymbols();
+        if self.haveloadedsymbols:
+            return;
+        try:
+            self.SRF_loadsymbols();
+            self.haveloadedsymbols=True;
         except:
-            if self.verbose>0: print "SmartRF not found at %s." % self.smartrfpath;
+            ident=self.CCident();
+            if ident==0x0000 or ident==0xFFFF:
+                print "Chip ID is 0x%04x, implying a wiring problem." % ident;
+            else:
+                print "SmartRF not found for chip 0x%04x." % ident;
     def SRF_chipdom(self,chip="cc1110", doc="register_definition.xml"):
+    #def SRF_chipdom(self,chip="cc1110", doc="workingconfig.xml"):
         """Loads the chip XML definitions from SmartRF7."""
         fn="%s/config/xml/%s/%s" % (self.smartrfpath,chip,doc);
         #print "Opening %s" % fn;
@@ -195,13 +217,11 @@ class GoodFETCC(GoodFET):
             h=IntelHex(filename);
             for i in h._buf.keys():
                 self.CCpokedatabyte(i,h[i]);
-        
         #Execute it.
         self.CCdebuginstr([0x02, 0xf0, 0x00]); #ljmp 0xF000
         self.resume();
         while wait>0 and (0==self.CCstatus()&0x20):
             a=1;
-            #time.sleep(0.1);
             #print "Waiting for shell code to return.";
         return;
     def ishalted(self):
@@ -396,9 +416,15 @@ class GoodFETCC(GoodFET):
         self.pokebysym("SYNC0",0xB0);
         self.pokebysym("ADDR", 0xB0);
         return;
-    def config_ook(self,band="none"):
-        self.pokebysym("FSCTRL1"  , 0x0C) #08   # Frequency synthesizer control.
-        self.pokebysym("FSCTRL0"  , 0x00)   # Frequency synthesizer control.
+
+    def config_ademco(self, band="lf"):
+        pass
+        # FIXME Temporary placeholder for me to write the Ademco protocol into the GoodFET Chipcon Application
+        # TODO  Also, write a class that takes in the XML registration files and sets values (not just addresses)
+
+       def config_ook(self,band="none"):
+               self.pokebysym("FSCTRL1"  , 0x0C) #08   # Frequency synthesizer control.
+               self.pokebysym("FSCTRL0"  , 0x00)   # Frequency synthesizer control.
         
         #Don't change these while the radio is active.
         self.pokebysym("FSCAL3"   , 0xEA)   # Frequency synthesizer calibration.
@@ -686,7 +712,7 @@ class GoodFETCC(GoodFET):
         if(ident1!=ident2 or ident2!=ident3):
             print "Error, repeated ident attempts unequal."
             print "%04x, %04x, %04x" % (ident1, ident2, ident3);
-        
+
         #Single step, printing PC.
         print "Tracing execution at startup."
         for i in range(1,15):
@@ -703,7 +729,7 @@ class GoodFETCC(GoodFET):
                 print "ERROR: PC changed during CCdebuginstr([NOP])!";
         
         print "Checking pokes to XRAM."
-        for i in range(0xf000,0xf020):
+        for i in range(self.execbuf,self.execbuf+0x20):
             self.CCpokedatabyte(i,0xde);
             if(self.CCpeekdatabyte(i)!=0xde):
                 print "Error in XDATA at 0x%04x" % i;
@@ -714,7 +740,7 @@ class GoodFETCC(GoodFET):
         print "Done.";
 
     def setup(self):
-        """Move the FET into the CC2430/CC2530 application."""
+        """Move the FET into the Chipcon 8051 application."""
         #print "Initializing Chipcon.";
         self.writecmd(self.APP,0x10,0,self.data);
     def CCrd_config(self):
@@ -740,9 +766,21 @@ class GoodFETCC(GoodFET):
                 0x9100:"cc2511",
                 0xA500:"cc2530", #page 57 of SWRU191B
                 0xB500:"cc2531",
-                0x9500:"CC2533",
-                0x8D00:"CC2540",
+                0x9500:"cc2533",
+                0x8D00:"cc2540",
                 0xFF00:"CCmissing"};
+    execbuf=None;
+    CCexecbuf= {0x0100:0xF000,
+                0x1100:0xF000,
+                0x8500:0xF000,
+                0x8900:0xF000,
+                0x8100:0xF000,
+                0x9100:0xF000,
+                0xA500:0x0000, #CC2530
+                0xB500:0x8000,
+                0x9500:0x8000,
+                0x8D00:0x8000,
+                0xFF00:None} #missing
     CCpagesizes={0x01: 1024, #"CC1110",
                  0x11: 1024, #"CC1111",
                  0x85: 2048, #"CC2430",
@@ -753,13 +791,16 @@ class GoodFETCC(GoodFET):
                  0xB5: 2048, #"CC2531",
                  0x95: 2048, #"CC2533",
                  0x8D: 2048, #"CC2540",
-                 0xFF: 0    } #"CCmissing"};
+                 0xFF: None}
     def infostring(self):
         return self.CCidentstr();
     def CCidentstr(self):
         ident=self.CCident();
         chip=self.CCversions.get(ident&0xFF00);
+        execbuf=self.CCexecbuf.get(ident&0xFF00);
         pagesize=self.CCpagesizes.get(ident>0xFF);
+        self.execbuf=execbuf;
+        
         try:
             return "%s/r%0.4x/ps0x%0.4x" % (chip, ident, pagesize); 
         except:
@@ -887,21 +928,17 @@ class GoodFETCC(GoodFET):
         return str;
     def start(self):
         """Start debugging."""
+        ident=0x0000;
+        #while ident==0xFFFF or ident==0x0000:
         self.setup();
         self.writecmd(self.APP,0x20,0,self.data);
-        ident=self.CCident();
-        if ident==0xFFFF or ident==0x0000:
-            self.writecmd(self.APP,0x20,0,self.data);
-            ident=self.CCident();
-        
+        identa=self.CCident();
+        self.CCidentstr();
         
-        #print "Target identifies as %s." % ident;
-        #print "Status: %s." % self.status();
-        self.CCreleasecpu();
-        self.CChaltcpu();
+        ident=self.CCident();
         #Get SmartRF Studio regs if they exist.
         self.loadsymbols(); 
-        
+        #print "Status: %s" % self.status();
     def stop(self):
         """Stop debugging."""
         self.writecmd(self.APP,0x21,0,self.data);
@@ -939,7 +976,9 @@ class GoodFETCC(GoodFET):
         secret=self.CCpeekcodebyte(0);
         #print "Got secret %02x" % secret;
         return secret;
-
+    
+    #FIXME: This is CC1110-specific and duplicates functionality of 
+    #       SmartRF7 integration.
     CCspecfuncregs={
         'P0':0x80,
         'SP':0x81,