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"):
"""Loads the chip XML definitions from SmartRF7."""
fn="%s/config/xml/%s/%s" % (self.smartrfpath,chip,doc);
elif e.localName=="Start": start=e.childNodes[0].nodeValue;
elif e.localName=="Stop": stop=e.childNodes[0].nodeValue;
return " [%s:%s] %30s " % (start,stop,name);
+
def SRF_radiostate(self):
ident=self.CCident();
chip=self.CCversions.get(ident&0xFF00);
print "%-10s=0x%02x; /* %-50s */" % (
name,self.CCpeekdatabyte(eval(address)), description);
if bitfields!="": print bitfields.rstrip();
+
+ def SRF_radiostate_select(self,args=[]):
+ lreg = []
+ ident=self.CCident();
+ chip=self.CCversions.get(ident&0xFF00);
+ dom=self.SRF_chipdom(chip,"register_definition.xml");
+ for reg in args:
+ if reg.lower() == "help":
+ lreg = "help"
+ break
+ lreg.append(reg.lower())
+ for e in dom.getElementsByTagName("registerdefinition"):
+ for f in e.childNodes:
+ if f.localName=="DeviceName":
+ print "// %s RadioState" % (f.childNodes[0].nodeValue);
+ elif f.localName=="Register":
+ name="unknownreg";
+ address="0xdead";
+ description="";
+ bitfields="";
+ for g in f.childNodes:
+ if g.localName=="Name":
+ name=g.childNodes[0].nodeValue;
+ elif g.localName=="Address":
+ address=g.childNodes[0].nodeValue;
+ elif g.localName=="Description":
+ if g.childNodes:
+ description=g.childNodes[0].nodeValue;
+ elif g.localName=="Bitfield":
+ bitfields+="%17s/* %-50s */\n" % ("",self.SRF_bitfieldstr(g));
+ #print "SFRX(%10s, %s); /* %50s */" % (name,address, description);
+ if lreg == "help":
+ print "%-10s /* %-50s */" % (name, description);
+ elif name.lower() in lreg:
+ print "%-10s=0x%02x; /* %-50s */" % (
+ name,self.CCpeekdatabyte(eval(address)), description);
+ if bitfields!="": print bitfields.rstrip();
+
def RF_setfreq(self,frequency):
"""Set the frequency in Hz."""
#FIXME CC1110 specific
return hz;
def RF_getchannel(self):
- """Get the frequency in Hz."""
+ """Get the hex channel."""
#FIXME CC1110 specific
freq=0;
try:
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):
self.pokebysym("MDMCFG1" , 0x22) # Modem configuration.
self.pokebysym("MDMCFG0" , 0xF8) # Modem configuration.
-
self.pokebysym("SYNC1",0xAA);
self.pokebysym("SYNC0",0xAA);
-
-
#while ((MARCSTATE & MARCSTATE_MARC_STATE) != MARC_STATE_TX);
state=0;
except:
if self.verbose>0: print "RSSI reg doesn't exist.";
try:
- #RSSI doesn't exist on 2.4GHz devices. Maybe RSSIL and RSSIH?
+ #RSSI doesn't exist on some 2.4GHz devices. Maybe RSSIL and RSSIH?
rssilreg=self.symbols.get("RSSIL");
rssil=self.CCpeekdatabyte(rssilreg);
rssihreg=self.symbols.get("RSSIL");
return 0;
-
-
def SRF_loadsymbols(self):
ident=self.CCident();
chip=self.CCversions.get(ident&0xFF00);
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):
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;
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):
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",
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:
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);
#print "Got secret %02x" % secret;
return secret;
+ #FIXME: This is CC1110-specific and duplicates functionality of
+ # SmartRF7 integration.
+ CCspecfuncregs={
+ 'P0':0x80,
+ 'SP':0x81,
+ 'DPL0':0x82,
+ 'DPH0':0x83,
+ 'DPL1':0x84,
+ 'DPH1':0x85,
+ 'U0CSR':0x86,
+ 'PCON':0x87,
+ 'TCON':0x88,
+ 'P0IFG':0x89,
+ 'P1IFG':0x8A,
+ 'P2IFG':0x8B,
+ 'PICTL':0x8C,
+ 'P1IEN':0x8D,
+ 'P0INP':0x8F,
+ 'P1':0x90,
+ 'RFIM':0x91,
+ 'DPS':0x92,
+ 'MPAGE':0x93,
+ 'ENDIAN':0x95,
+ 'S0CON':0x98,
+ 'IEN2':0x9A,
+ 'S1CON':0x9B,
+ 'T2CT':0x9C,
+ 'T2PR':0x9D,
+ 'T2CTL':0x9E,
+ 'P2':0xA0,
+ 'WORIRQ':0xA1,
+ 'WORCTRL':0xA2,
+ 'WOREVT0':0xA3,
+ 'WOREVT1':0xA4,
+ 'WORTIME0':0xA5,
+ 'WORTIME1':0xA6,
+ 'IEN0':0xA8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xED,
+ 'T4CCTL1':0xEE,
+ 'T4CC1':0xEF,
+ 'B':0xF0,
+ 'PERCFG':0xF1,
+ 'ADCCFG':0xF2,
+ 'P0SEL':0xF3,
+ 'P1SEL':0xF4,
+ 'P2SEL':0xF5,
+ 'P1INP':0xF6,
+ 'P2INP':0xF7,
+ 'U1CSR':0xF8,
+ 'U1DBUF':0xF9,
+ 'U1BAUD':0xFA,
+ 'U1UCR':0xFB,
+ 'U1GCR':0xFC,
+ 'P0DIR':0xFD,
+ 'P1DIR':0xFE,
+ 'P2DIR':0xFF
+ }
+ def getSPR(self,args=[]):
+ """Get special function registers."""
+ print "Special Function Registers:"
+ if len(args):
+ for e in args:
+ print " %-8s : 0x%0.2x"%(e,self.CCpeekcodebyte(self.CCspecfuncregs[e]))
+ else:
+ for e in self.CCspecfuncregs.keys():
+ print " %-8s : 0x%0.2x"%(e,self.CCpeekcodebyte(self.CCspecfuncregs[e]))
+
def dump(self,file,start=0,stop=0xffff):
"""Dump an intel hex file from code memory."""
print "Dumping code from %04x to %04x as %s." % (start,stop,file);