2 # GoodFET Client Library
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
6 # This code is being rewritten and refactored. You've been warned!
11 from GoodFET import GoodFET;
12 from intelhex import IntelHex;
14 class GoodFETCC(GoodFET):
15 """A GoodFET variant for use with Chipcon 8051 Zigbeema SoC."""
18 self.writecmd(0x30,0x86,0,self.data);
19 def CCreleasecpu(self):
21 self.writecmd(0x30,0x87,0,self.data);
25 #print "Status: %s" % self.CCstatusstr();
27 #Grab ident three times, should be equal.
28 ident1=self.CCident();
29 ident2=self.CCident();
30 ident3=self.CCident();
31 if(ident1!=ident2 or ident2!=ident3):
32 print "Error, repeated ident attempts unequal."
33 print "%04x, %04x, %04x" % (ident1, ident2, ident3);
35 #Single step, printing PC.
36 print "Tracing execution at startup."
39 byte=self.CCpeekcodebyte(i);
40 #print "PC=%04x, %02x" % (pc, byte);
43 print "Verifying that debugging a NOP doesn't affect the PC."
46 self.CCdebuginstr([0x00]);
47 if(pc!=self.CCgetPC()):
48 print "ERROR: PC changed during CCdebuginstr([NOP])!";
51 #print "Status: %s." % self.CCstatusstr();
57 """Move the FET into the CC2430/CC2530 application."""
58 #print "Initializing Chipcon.";
59 self.writecmd(0x30,0x10,0,self.data);
60 def CCrd_config(self):
61 """Read the config register of a Chipcon."""
62 self.writecmd(0x30,0x82,0,self.data);
63 return ord(self.data[0]);
64 def CCwr_config(self,config):
65 """Write the config register of a Chipcon."""
66 self.writecmd(0x30,0x81,1,[config&0xFF]);
68 """Set the flash lock bit in info mem."""
69 self.writecmd(0x30, 0x9A, 0, None);
72 CCversions={0x0100:"CC1110",
77 0xA500:"CC2530", #page 52 of SWRU191
82 chip=self.CCversions.get(ident&0xFF00);
83 return "%s/r%02x" % (chip, ident&0xFF);
85 """Get a chipcon's ID."""
86 self.writecmd(0x30,0x8B,0,None);
87 chip=ord(self.data[0]);
88 rev=ord(self.data[1]);
91 """Get a chipcon's PC."""
92 self.writecmd(0x30,0x83,0,None);
96 def CCdebuginstr(self,instr):
97 self.writecmd(0x30,0x88,len(instr),instr);
98 return ord(self.data[0]);
99 def CCpeekcodebyte(self,adr):
100 """Read the contents of code memory at an address."""
101 self.data=[adr&0xff, (adr&0xff00)>>8];
102 self.writecmd(0x30,0x90,2,self.data);
103 return ord(self.data[0]);
104 def CCpeekdatabyte(self,adr):
105 """Read the contents of data memory at an address."""
106 self.data=[adr&0xff, (adr&0xff00)>>8];
107 self.writecmd(0x30,0x91, 2, self.data);
108 return ord(self.data[0]);
109 def CCpokedatabyte(self,adr,val):
110 """Write a byte to data memory."""
111 self.data=[adr&0xff, (adr&0xff00)>>8, val];
112 self.writecmd(0x30, 0x92, 3, self.data);
113 return ord(self.data[0]);
114 def CCchiperase(self):
115 """Erase all of the target's memory."""
116 self.writecmd(0x30,0x80,0,None);
118 """Check the status."""
119 self.writecmd(0x30,0x84,0,None);
120 return ord(self.data[0])
122 CCstatusbits={0x80 : "erase_busy",
126 0x08 : "halt_status",
131 CCconfigbits={0x20 : "soft_power_mode", #new for CC2530
134 0x02 : "timer_suspend",
135 0x01 : "sel_flash_info_page" #stricken from CC2530
138 def CCstatusstr(self):
139 """Check the status as a string."""
140 status=self.CCstatus();
145 str="%s %s" %(self.CCstatusbits[i],str);
149 """Start debugging."""
150 self.writecmd(0x30,0x20,0,self.data);
151 ident=self.CCidentstr();
152 print "Target identifies as %s." % ident;
153 #print "Status: %s." % self.CCstatusstr();
156 #print "Status: %s." % self.CCstatusstr();
159 """Stop debugging."""
160 self.writecmd(0x30,0x21,0,self.data);
161 def CCstep_instr(self):
162 """Step one instruction."""
163 self.writecmd(0x30,0x89,0,self.data);
164 def CCeraseflashbuffer(self):
165 """Erase the 2kB flash buffer"""
166 self.writecmd(0x30,0x99);
167 def CCflashpage(self,adr):
168 """Flash 2kB a page of flash from 0xF000 in XDATA"""
173 print "Flashing buffer to 0x%06x" % adr;
174 self.writecmd(0x30,0x95,4,data);