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 import xml.dom.minidom, time;
16 class GoodFETCC(GoodFET):
17 """A GoodFET variant for use with Chipcon 8051 Zigbee SoC."""
23 smartrfpath="/opt/smartrf7";
24 def loadsymbols(self):
25 try: self.SRF_loadsymbols();
27 if self.verbose>0: print "SmartRF not found at %s." % self.smartrfpath;
28 def SRF_chipdom(self,chip="cc1110", doc="register_definition.xml"):
29 fn="%s/config/xml/%s/%s" % (self.smartrfpath,chip,doc);
30 #print "Opening %s" % fn;
31 return xml.dom.minidom.parse(fn)
33 def CMDrs(self,args=[]):
34 """Chip command to grab the radio state."""
36 self.SRF_radiostate();
38 print "Error printing radio state.";
39 print "SmartRF not found at %s." % self.smartrfpath;
40 def SRF_bitfieldstr(self,bf):
47 for e in bf.childNodes:
48 if e.localName=="Name" and e.childNodes: name= e.childNodes[0].nodeValue;
49 elif e.localName=="Start": start=e.childNodes[0].nodeValue;
50 elif e.localName=="Stop": stop=e.childNodes[0].nodeValue;
51 return " [%s:%s] %30s " % (start,stop,name);
52 def SRF_radiostate(self):
54 chip=self.CCversions.get(ident&0xFF00);
55 dom=self.SRF_chipdom(chip,"register_definition.xml");
56 for e in dom.getElementsByTagName("registerdefinition"):
57 for f in e.childNodes:
58 if f.localName=="DeviceName":
59 print "// %s RadioState" % (f.childNodes[0].nodeValue);
60 elif f.localName=="Register":
65 for g in f.childNodes:
66 if g.localName=="Name":
67 name=g.childNodes[0].nodeValue;
68 elif g.localName=="Address":
69 address=g.childNodes[0].nodeValue;
70 elif g.localName=="Description":
72 description=g.childNodes[0].nodeValue;
73 elif g.localName=="Bitfield":
74 bitfields+="%17s/* %-50s */\n" % ("",self.SRF_bitfieldstr(g));
75 #print "SFRX(%10s, %s); /* %50s */" % (name,address, description);
76 print "%-10s=0x%02x; /* %-50s */" % (
77 name,self.CCpeekdatabyte(eval(address)), description);
78 if bitfields!="": print bitfields.rstrip();
79 def RF_setfreq(self,frequency):
80 """Set the frequency in Hz."""
81 #FIXME CC1110 specific
84 freq=int(hz/396.728515625);
87 freq1=(freq&0xFF00)>>8;
88 freq2=(freq&0xFF0000)>>16;
90 self.pokebysym("FREQ2",freq2);
91 self.pokebysym("FREQ1",freq1);
92 self.pokebysym("FREQ0",freq0);
96 """Get the frequency in Hz."""
97 #FIXME CC1110 specific
99 #return (2400+self.peek(0x05))*10**6
100 #self.poke(0x05,chan);
102 #freq2=self.CCpeekdatabyte(0xdf09);
103 #freq1=self.CCpeekdatabyte(0xdf0a);
104 #freq0=self.CCpeekdatabyte(0xdf0b);
107 freq2=self.peekbysym("FREQ2");
108 freq1=self.peekbysym("FREQ1");
109 freq0=self.peekbysym("FREQ0");
110 freq=(freq2<<16)+(freq1<<8)+freq0;
114 hz=freq*396.728515625;
117 def shellcodefile(self,filename,wait=1):
118 """Run a fragment of shellcode by name."""
119 #FIXME: should identify chip model number, use shellcode for that chip.
121 file=file.replace("GoodFETCC.pyc","GoodFETCC.py");
122 path=file.replace("client/GoodFETCC.py","shellcode/chipcon/cc1110/");
123 #print "File\t%s" % file;
124 #print "Path\t%s" % path;
125 filename=path+filename;
126 #print "Loading shelcode from %s" % filename;
129 h=IntelHex(filename);
130 for i in h._buf.keys():
131 self.CCpokedatabyte(i,h[i]);
134 self.CCdebuginstr([0x02, 0xf0, 0x00]); #ljmp 0xF000
136 while wait>0 and (0==self.CCstatus()&0x20):
139 #print "Waiting for shell code to return.";
141 def shellcode(self,code,wait=1):
142 """Copy a block of code into RAM and execute it."""
146 self.pokebyte(0xF000+i,byte);
148 #print "Code loaded, executing."
149 self.CCdebuginstr([0x02, 0xf0, 0x00]); #ljmp 0xF000
151 while wait>0 and (0==self.CCstatus()&0x20):
154 #print "Waiting for shell code to return.";
156 def CC1110_crystal(self):
157 """Start the main crystal of the CC1110 oscillating, needed for radio use."""
158 code=[0x53, 0xBE, 0xFB, #anl SLEEP, #0xFB
160 0xE5, 0xBE, #mov a,SLEEP
161 0x30, 0xE6, 0xFB, #jnb acc.6, back
162 0x53, 0xc6, 0xB8, #anl CLKCON, #0xB8
164 0xE5, 0xC6, #mov a,CLKCON
165 0x20, 0xE6, 0xFB, #jb acc.6, two
166 0x43, 0xBE, 0x04, #orl SLEEP, #0x04
169 self.shellcode(code);
171 #Slower to load, but produced from C.
172 #self.shellcodefile("crystal.ihx");
175 """Move the radio to its idle state."""
179 #Chipcon RF strobes. CC1110 specific
184 def CC_RFST_IDLE(self):
185 """Switch the radio to idle mode, clearing overflows and errors."""
186 self.CC_RFST(self.RFST_IDLE);
187 def CC_RFST_TX(self):
188 """Switch the radio to TX mode."""
189 self.CC_RFST(self.RFST_TX);
190 def CC_RFST_RX(self):
191 """Switch the radio to RX mode."""
192 self.CC_RFST(self.RFST_RX);
193 def CC_RFST_CAL(self):
194 """Calibrate strobe the radio."""
195 self.CC_RFST(self.RFST_CAL);
196 def CC_RFST(self,state=RFST_IDLE):
198 self.pokebyte(RFST,state); #Return to idle state.
201 def config_simpliciti(self,band="none"):
202 self.pokebysym("FSCTRL1" , 0x08) # Frequency synthesizer control.
203 self.pokebysym("FSCTRL0" , 0x00) # Frequency synthesizer control.
205 #Don't change these while the radio is active.
206 self.pokebysym("FSCAL3" , 0xEA) # Frequency synthesizer calibration.
207 self.pokebysym("FSCAL2" , 0x2A) # Frequency synthesizer calibration.
208 self.pokebysym("FSCAL1" , 0x00) # Frequency synthesizer calibration.
209 self.pokebysym("FSCAL0" , 0x1F) # Frequency synthesizer calibration.
211 if band=="ismeu" or band=="eu":
212 self.pokebysym("FREQ2" , 0x21) # Frequency control word, high byte.
213 self.pokebysym("FREQ1" , 0x71) # Frequency control word, middle byte.
214 self.pokebysym("FREQ0" , 0x7a) # Frequency control word, low byte.
215 if band=="ismus" or band=="us":
216 self.pokebysym("FREQ2" , 0x22) # Frequency control word, high byte.
217 self.pokebysym("FREQ1" , 0xB1) # Frequency control word, middle byte.
218 self.pokebysym("FREQ0" , 0x3B) # Frequency control word, low byte.
219 if band=="ismlf" or band=="lf":
220 self.pokebysym("FREQ2" , 0x10) # Frequency control word, high byte.
221 self.pokebysym("FREQ1" , 0xB0) # Frequency control word, middle byte.
222 self.pokebysym("FREQ0" , 0x71) # Frequency control word, low byte.
224 self.pokebysym("MDMCFG4" , 0x7B) # Modem configuration.
225 self.pokebysym("MDMCFG3" , 0x83) # Modem configuration.
226 self.pokebysym("MDMCFG2" , 0x13) # Modem configuration.
227 self.pokebysym("MDMCFG1" , 0x22) # Modem configuration.
228 self.pokebysym("MDMCFG0" , 0xF8) # Modem configuration.
229 if band=="ismus" or band=="us":
230 self.pokebysym("CHANNR" , 20) # Channel number.
232 self.pokebysym("CHANNR" , 0x00) # Channel number.
233 self.pokebysym("DEVIATN" , 0x42) # Modem deviation setting (when FSK modulation is enabled).
235 self.pokebysym("FREND1" , 0xB6) # Front end RX configuration.
236 self.pokebysym("FREND0" , 0x10) # Front end RX configuration.
237 self.pokebysym("MCSM0" , 0x18) # Main Radio Control State Machine configuration.
238 self.pokebysym("FOCCFG" , 0x1D) # Frequency Offset Compensation Configuration.
239 self.pokebysym("BSCFG" , 0x1C) # Bit synchronization Configuration.
241 self.pokebysym("AGCCTRL2" , 0xC7) # AGC control.
242 self.pokebysym("AGCCTRL1" , 0x00) # AGC control.
243 self.pokebysym("AGCCTRL0" , 0xB2) # AGC control.
245 self.pokebysym("TEST2" , 0x81) # Various test settings.
246 self.pokebysym("TEST1" , 0x35) # Various test settings.
247 self.pokebysym("TEST0" , 0x09) # Various test settings.
248 self.pokebysym("PA_TABLE0", 0xC0) # PA output power setting.
249 self.pokebysym("PKTCTRL1" , 0x04) # Packet automation control, w/ lqi
250 #self.pokebysym("PKTCTRL1" , 0x00) # Packet automation control. w/o lqi
251 self.pokebysym("PKTCTRL0" , 0x05) # Packet automation control, w/ checksum.
252 self.pokebysym("PKTCTRL0" , 0x00) # Packet automation control, w/o checksum, fixed length
253 self.pokebysym("ADDR" , 0x01) # Device address.
254 self.pokebysym("PKTLEN" , 0xFF) # Packet length.
256 self.pokebysym("SYNC1",0xD3);
257 self.pokebysym("SYNC0",0x91);
259 def RF_carrier(self):
260 """Hold a carrier wave on the present frequency."""
262 self.CC1110_crystal(); #FIXME, '1110 specific.
272 self.pokebysym("FSCTRL1" , 0x0a) # Frequency synthesizer control.
273 self.pokebysym("FSCTRL0" , 0x00) # Frequency synthesizer control.
275 #Don't change these while the radio is active.
276 self.pokebysym("FSCAL3" , 0xA9) # Frequency synthesizer calibration.
277 self.pokebysym("FSCAL2" , 0x0A) # Frequency synthesizer calibration.
278 self.pokebysym("FSCAL1" , 0x00) # Frequency synthesizer calibration.
279 self.pokebysym("FSCAL0" , 0x11) # Frequency synthesizer calibration.
282 #self.pokebysym("FREQ2" , 0x10) # Frequency control word, high byte.
283 #self.pokebysym("FREQ1" , 0xEC) # Frequency control word, middle byte.
284 #self.pokebysym("FREQ0" , 0x4E) # Frequency control word, low byte.
285 self.pokebysym("MDMCFG4" , 0x86) # Modem configuration.
286 self.pokebysym("MDMCFG3" , 0x83) # Modem configuration.
287 self.pokebysym("MDMCFG2" , 0x30) # Modem configuration.
288 self.pokebysym("MDMCFG1" , 0x22) # Modem configuration.
289 self.pokebysym("MDMCFG0" , 0xF8) # Modem configuration.
290 self.pokebysym("CHANNR" , 0x00) # Channel number.
291 self.pokebysym("DEVIATN" , 0x00) # Modem deviation setting (when FSK modulation is enabled).
292 self.pokebysym("FREND1" , 0x56) # Front end RX configuration.
294 self.pokebysym("FREND0" , 0x10) # Front end RX configuration.
295 self.pokebysym("MCSM0" , 0x14) # Main Radio Control State Machine configuration.
296 self.pokebysym("FOCCFG" , 0x16) # Frequency Offset Compensation Configuration.
297 self.pokebysym("BSCFG" , 0x6C) # Bit synchronization Configuration.
299 self.pokebysym("AGCCTRL2" , 0x03) # AGC control.
300 self.pokebysym("AGCCTRL1" , 0x40) # AGC control.
301 self.pokebysym("AGCCTRL0" , 0x91) # AGC control.
303 self.pokebysym("TEST2" , 0x88) # Various test settings.
304 self.pokebysym("TEST1" , 0x31) # Various test settings.
305 self.pokebysym("TEST0" , 0x09) # Various test settings.
306 self.pokebysym("PA_TABLE0", 0xC0) # PA output power setting.
307 self.pokebysym("PKTCTRL1" , 0x04) # Packet automation control.
308 self.pokebysym("PKTCTRL0" , 0x22) # Packet automation control.
309 self.pokebysym("ADDR" , 0x00) # Device address.
310 self.pokebysym("PKTLEN" , 0xFF) # Packet length.
312 self.pokebysym("SYNC1",0xAA);
313 self.pokebysym("SYNC0",0xAA);
317 #while ((MARCSTATE & MARCSTATE_MARC_STATE) != MARC_STATE_TX);
320 while((state!=0x13)):
321 self.pokebyte(RFST,0x03); #RFST=RFST_STX
323 state=self.peekbysym("MARCSTATE")&0x1F;
324 #print "state=%02x" % state;
325 print "Holding a carrier on %f MHz." % (self.RF_getfreq()/10**6);
327 #Not needed, radio works when CPU is halted.
332 def RF_getsmac(self):
333 """Return the source MAC address."""
335 #Register 0A is RX_ADDR_P0, five bytes.
336 mac=self.peekbysym("ADDR");
338 def RF_setsmac(self,mac):
339 """Set the source MAC address."""
340 self.pokebysym("ADDR",mac);
342 def RF_gettmac(self):
343 """Return the target MAC address."""
345 def RF_settmac(self,mac):
346 """Set the target MAC address."""
348 def RF_rxpacket(self):
349 """Get a packet from the radio. Returns None if none is waiting."""
350 self.shellcodefile("rxpacket.ihx");
351 len=self.peek8(0xFE00,"xdata");
352 return self.peekblock(0xFE00,len+1,"data");
353 def RF_txpacket(self,packet):
354 """Transmit a packet. Untested."""
356 self.pokeblock(0xFE00,packet,"data");
357 self.shellcodefile("txpacket.ihx");
359 def RF_txrxpacket(self,packet):
360 """Transmit a packet. Untested."""
362 self.pokeblock(0xFE00,packet,"data");
363 self.shellcodefile("txrxpacket.ihx");
364 len=self.peek8(0xFE00,"xdata");
365 return self.peekblock(0xFE00,len+1,"data");
367 def RF_getrssi(self):
368 """Returns the received signal strenght, with a weird offset."""
370 rssireg=self.symbols.get("RSSI");
371 return self.CCpeekdatabyte(rssireg)^0x80;
373 if self.verbose>0: print "RSSI reg doesn't exist.";
375 #RSSI doesn't exist on 2.4GHz devices. Maybe RSSIL and RSSIH?
376 rssilreg=self.symbols.get("RSSIL");
377 rssil=self.CCpeekdatabyte(rssilreg);
378 rssihreg=self.symbols.get("RSSIL");
379 rssih=self.CCpeekdatabyte(rssihreg);
380 return (rssih<<8)|rssil;
382 if self.verbose>0: print "RSSIL/RSSIH regs don't exist.";
388 def SRF_loadsymbols(self):
389 ident=self.CCident();
390 chip=self.CCversions.get(ident&0xFF00);
391 dom=self.SRF_chipdom(chip,"register_definition.xml");
392 for e in dom.getElementsByTagName("registerdefinition"):
393 for f in e.childNodes:
394 if f.localName=="Register":
399 for g in f.childNodes:
400 if g.localName=="Name":
401 name=g.childNodes[0].nodeValue;
402 elif g.localName=="Address":
403 address=g.childNodes[0].nodeValue;
404 elif g.localName=="Description":
406 description=g.childNodes[0].nodeValue;
407 elif g.localName=="Bitfield":
408 bitfields+="%17s/* %-50s */\n" % ("",self.SRF_bitfieldstr(g));
409 #print "SFRX(%10s, %s); /* %50s */" % (name,address, description);
410 self.symbols.define(eval(address),name,description,"data");
416 self.writecmd(self.APP,0x86,0,self.data);
419 def CCreleasecpu(self):
420 """Resume the CPU."""
421 self.writecmd(self.APP,0x87,0,self.data);
425 #print "Status: %s" % self.CCstatusstr();
427 #Grab ident three times, should be equal.
428 ident1=self.CCident();
429 ident2=self.CCident();
430 ident3=self.CCident();
431 if(ident1!=ident2 or ident2!=ident3):
432 print "Error, repeated ident attempts unequal."
433 print "%04x, %04x, %04x" % (ident1, ident2, ident3);
435 #Single step, printing PC.
436 print "Tracing execution at startup."
437 for i in range(1,15):
439 byte=self.CCpeekcodebyte(i);
440 #print "PC=%04x, %02x" % (pc, byte);
443 print "Verifying that debugging a NOP doesn't affect the PC."
444 for i in range(1,15):
446 self.CCdebuginstr([0x00]);
447 if(pc!=self.CCgetPC()):
448 print "ERROR: PC changed during CCdebuginstr([NOP])!";
450 print "Checking pokes to XRAM."
451 for i in range(0xf000,0xf020):
452 self.CCpokedatabyte(i,0xde);
453 if(self.CCpeekdatabyte(i)!=0xde):
454 print "Error in XDATA at 0x%04x" % i;
456 #print "Status: %s." % self.CCstatusstr();
462 """Move the FET into the CC2430/CC2530 application."""
463 #print "Initializing Chipcon.";
464 self.writecmd(self.APP,0x10,0,self.data);
465 def CCrd_config(self):
466 """Read the config register of a Chipcon."""
467 self.writecmd(self.APP,0x82,0,self.data);
468 return ord(self.data[0]);
469 def CCwr_config(self,config):
470 """Write the config register of a Chipcon."""
471 self.writecmd(self.APP,0x81,1,[config&0xFF]);
472 def CClockchip(self):
473 """Set the flash lock bit in info mem."""
474 self.writecmd(self.APP, 0x9A, 0, None);
476 """Set the flash lock bit in info mem."""
480 CCversions={0x0100:"cc1110",
486 0xA500:"cc2530", #page 52 of SWRU191
489 CCpagesizes={0x01: 1024, #"CC1110",
490 0x11: 1024, #"CC1111",
491 0x85: 2048, #"CC2430",
492 0x89: 2048, #"CC2431",
493 0x81: 1024, #"CC2510",
494 0x91: 1024, #"CC2511",
495 0xA5: 2048, #"CC2530", #page 52 of SWRU191
496 0xB5: 2048, #"CC2531",
497 0xFF: 0 } #"CCmissing"};
498 def infostring(self):
499 return self.CCidentstr();
500 def CCidentstr(self):
501 ident=self.CCident();
502 chip=self.CCversions.get(ident&0xFF00);
503 pagesize=self.CCpagesizes.get(ident>0xFF);
505 return "%s/r%0.4x/ps0x%0.4x" % (chip, ident, pagesize);
507 return "%04x" % ident;
509 """Get a chipcon's ID."""
510 self.writecmd(self.APP,0x8B,0,None);
511 chip=ord(self.data[0]);
512 rev=ord(self.data[1]);
513 return (chip<<8)+rev;
514 def CCpagesize(self):
515 """Get a chipcon's ID."""
516 self.writecmd(self.APP,0x8B,0,None);
517 chip=ord(self.data[0]);
518 size=self.CCpagesizes.get(chip);
520 print "ERROR: Pagesize undefined.";
521 print "chip=%0.4x" %chip;
526 return self.CCgetPC();
528 """Get a chipcon's PC."""
529 self.writecmd(self.APP,0x83,0,None);
530 hi=ord(self.data[0]);
531 lo=ord(self.data[1]);
533 def CCcmd(self,phrase):
534 self.writecmd(self.APP,0x00,len(phrase),phrase);
535 val=ord(self.data[0]);
536 print "Got %02x" % val;
538 def CCdebuginstr(self,instr):
539 self.writecmd(self.APP,0x88,len(instr),instr);
540 return ord(self.data[0]);
541 #def peekblock(self,adr,length,memory="vn"):
542 # """Return a block of data, broken"""
543 # data=[adr&0xff, (adr&0xff00)>>8,
544 # length&0xFF,(length&0xFF00)>>8];
545 # self.writecmd(self.APP,0x91,4,data);
546 # return [ord(x) for x in self.data]
547 def peek8(self,address, memory="code"):
548 if(memory=="code" or memory=="flash" or memory=="vn"):
549 return self.CCpeekcodebyte(address);
550 elif(memory=="data" or memory=="xdata" or memory=="ram"):
551 return self.CCpeekdatabyte(address);
552 elif(memory=="idata" or memory=="iram"):
553 return self.CCpeekirambyte(address);
554 print "%s is an unknown memory." % memory;
556 def CCpeekcodebyte(self,adr):
557 """Read the contents of code memory at an address."""
558 self.data=[adr&0xff, (adr&0xff00)>>8];
559 self.writecmd(self.APP,0x90,2,self.data);
560 return ord(self.data[0]);
561 def CCpeekdatabyte(self,adr):
562 """Read the contents of data memory at an address."""
563 self.data=[adr&0xff, (adr&0xff00)>>8];
564 self.writecmd(self.APP,0x91, 2, self.data);
565 return ord(self.data[0]);
566 def CCpeekirambyte(self,adr):
567 """Read the contents of IRAM at an address."""
568 self.data=[adr&0xff];
569 self.writecmd(self.APP,0x02, 1, self.data);
570 return ord(self.data[0]);
571 def CCpeekiramword(self,adr):
572 """Read the little-endian contents of IRAM at an address."""
573 return self.CCpeekirambyte(adr)+(
574 self.CCpeekirambyte(adr+1)<<8);
575 def CCpokeiramword(self,adr,val):
576 self.CCpokeirambyte(adr,val&0xff);
577 self.CCpokeirambyte(adr+1,(val>>8)&0xff);
578 def CCpokeirambyte(self,adr,val):
579 """Write the contents of IRAM at an address."""
580 self.data=[adr&0xff, val&0xff];
581 self.writecmd(self.APP,0x02, 2, self.data);
582 return ord(self.data[0]);
583 def pokebyte(self,adr,val,mem="data"):
585 print "FIXME: poking of non data bytes not yet supported.";
586 self.CCpokedatabyte(adr,val);
587 def CCpokedatabyte(self,adr,val):
588 """Write a byte to data memory."""
589 self.data=[adr&0xff, (adr&0xff00)>>8, val];
590 self.writecmd(self.APP, 0x92, 3, self.data);
591 return ord(self.data[0]);
592 def CCchiperase(self):
593 """Erase all of the target's memory."""
594 self.writecmd(self.APP,0x80,0,None);
596 """Erase all of the target's memory."""
601 """Check the status."""
602 self.writecmd(self.APP,0x84,0,None);
603 return ord(self.data[0])
605 CCstatusbits={0x80 : "erase_busy",
609 0x08 : "halt_status",
614 CCconfigbits={0x20 : "soft_power_mode", #new for CC2530
617 0x02 : "timer_suspend",
618 0x01 : "sel_flash_info_page" #stricken from CC2530
622 """Check the status as a string."""
623 status=self.CCstatus();
628 str="%s %s" %(self.CCstatusbits[i],str);
632 """Start debugging."""
634 self.writecmd(self.APP,0x20,0,self.data);
635 ident=self.CCidentstr();
636 #print "Target identifies as %s." % ident;
637 #print "Status: %s." % self.status();
640 #Get SmartRF Studio regs if they exist.
644 """Stop debugging."""
645 self.writecmd(self.APP,0x21,0,self.data);
646 def CCstep_instr(self):
647 """Step one instruction."""
648 self.writecmd(self.APP,0x89,0,self.data);
649 def CCeraseflashbuffer(self):
650 """Erase the 2kB flash buffer"""
651 self.writecmd(self.APP,0x99);
652 def CCflashpage(self,adr):
653 """Flash 2kB a page of flash from 0xF000 in XDATA"""
658 print "Flashing buffer to 0x%06x" % adr;
659 self.writecmd(self.APP,0x95,4,data);
661 def setsecret(self,value):
662 """Set a secret word for later retreival. Used by glitcher."""
664 pagelen = self.CCpagesize(); #Varies by chip.
665 print "page=%04x, pagelen=%04x" % (page,pagelen);
667 self.CCeraseflashbuffer();
668 print "Setting secret to %x" % value;
669 self.CCpokedatabyte(0xF000,value);
670 self.CCpokedatabyte(0xF800,value);
671 print "Setting secret to %x==%x" % (value,
672 self.CCpeekdatabyte(0xf000));
674 print "code[0]=%x" % self.CCpeekcodebyte(0);
676 """Get a secret word. Used by glitcher."""
677 secret=self.CCpeekcodebyte(0);
678 #print "Got secret %02x" % secret;
681 def dump(self,file,start=0,stop=0xffff):
682 """Dump an intel hex file from code memory."""
683 print "Dumping code from %04x to %04x as %s." % (start,stop,file);
687 h[i]=self.CCpeekcodebyte(i);
689 print "Dumped %04x."%i;
690 h.write_hex_file(file); #buffer to disk.
692 h.write_hex_file(file);
694 def flash(self,file):
695 """Flash an intel hex file to code memory."""
696 print "Flashing %s" % file;
700 pagelen = self.CCpagesize(); #Varies by chip.
702 #print "page=%04x, pagelen=%04x" % (page,pagelen);
706 #Wipe the RAM buffer for the next flash page.
707 self.CCeraseflashbuffer();
708 for i in h._buf.keys():
709 while(i>=page+pagelen):
711 self.CCflashpage(page);
712 #client.CCeraseflashbuffer();
714 print "Flashed page at %06x" % page
717 #Place byte into buffer.
718 self.CCpokedatabyte(0xF000+i-page,
722 print "Buffering %04x toward %06x" % (i,page);
724 self.CCflashpage(page);
725 print "Flashed final page at %06x" % page;