X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFETCC.py;h=6096d1e9c8c9fe1afd3cba5c72f28369cffcc863;hp=3e16ca78c5530832621f26b3abe42923b9dfea99;hb=1dd8dfdddbbd222887c1c362bd9474a802e2c830;hpb=042a155324ef5b76951e0194f61ab28c1c0521ce diff --git a/client/GoodFETCC.py b/client/GoodFETCC.py index 3e16ca7..6096d1e 100644 --- a/client/GoodFETCC.py +++ b/client/GoodFETCC.py @@ -11,7 +11,7 @@ import binascii; from GoodFET import GoodFET; from intelhex import IntelHex; -import xml.dom.minidom; +import xml.dom.minidom, time; class GoodFETCC(GoodFET): """A GoodFET variant for use with Chipcon 8051 Zigbee SoC.""" @@ -24,7 +24,7 @@ class GoodFETCC(GoodFET): def loadsymbols(self): try: self.SRF_loadsymbols(); except: - if self.verbose==1: print "SmartRF load failed."; + if self.verbose>0: print "SmartRF not found at %s." % self.smartrfpath; def SRF_chipdom(self,chip="cc1110", doc="register_definition.xml"): fn="%s/config/xml/%s/%s" % (self.smartrfpath,chip,doc); #print "Opening %s" % fn; @@ -32,7 +32,11 @@ class GoodFETCC(GoodFET): def CMDrs(self,args=[]): """Chip command to grab the radio state.""" - self.SRF_radiostate(); + try: + self.SRF_radiostate(); + except: + print "Error printing radio state."; + print "SmartRF not found at %s." % self.smartrfpath; def SRF_bitfieldstr(self,bf): name="unused"; start=0; @@ -72,10 +76,194 @@ class GoodFETCC(GoodFET): 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 + + hz=frequency; + freq=int(hz/396.728515625); + + freq0=freq&0xFF; + freq1=(freq&0xFF00)>>8; + freq2=(freq&0xFF0000)>>16; + + self.pokebysym("FREQ2",freq2); + self.pokebysym("FREQ1",freq1); + self.pokebysym("FREQ0",freq0); + + + def RF_getfreq(self): + """Get the frequency in Hz.""" + #FIXME CC1110 specific + + #return (2400+self.peek(0x05))*10**6 + #self.poke(0x05,chan); + + #freq2=self.CCpeekdatabyte(0xdf09); + #freq1=self.CCpeekdatabyte(0xdf0a); + #freq0=self.CCpeekdatabyte(0xdf0b); + freq=0; + try: + freq2=self.peekbysym("FREQ2"); + freq1=self.peekbysym("FREQ1"); + freq0=self.peekbysym("FREQ0"); + freq=(freq2<<16)+(freq1<<8)+freq0; + except: + freq=0; + + hz=freq*396.728515625; + + return hz; + + + def CC1110_crystal(self): + """Start the main crystal of the CC1110 oscillating, needed for radio use.""" + + #//C code for the same. + #SLEEP &= ~SLEEP_OSC_PD; + #while( !(SLEEP & SLEEP_XOSC_S) ); + #CLKCON = (CLKCON & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKSPD_DIV_1; + #while (CLKCON & CLKCON_OSC); + #SLEEP |= SLEEP_OSC_PD; + + #registers and constants. + #FIXME cc1110 specific + SLEEP=0xDFBE; + SLEEP_OSC_PD=0x04; + CLKCON=0xDFC6; + SLEEP_XOSC_S=0x40; + CLKCON_CLKSPD=0x07 + CLKCON_OSC=0x40; + CLKSPD_DIV_1=0x00; + + sleep=self.peekbyte(SLEEP); + sleep&=~SLEEP_XOSC_S; + self.pokebyte(SLEEP,sleep); + while(0==(self.peekbyte(SLEEP)&SLEEP_XOSC_S)): + time.sleep(0.1); + clkcon=self.peekbyte(CLKCON); + clkcon=(clkcon & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKSPD_DIV_1 + self.pokebyte(CLKCON,clkcon); + clkcon=0; + while(clkcon&CLKCON_OSC): + clkcon=self.peekbyte(CLKCON); + sleep=self.peekbyte(SLEEP); + sleep|=SLEEP_OSC_PD; + self.pokebyte(SLEEP,sleep); + + return; + def RF_idle(self): + RFST=0xDFE1 + self.pokebyte(RFST,0x04); #Return to idle state. + + def RF_carrier(self): + """Hold a carrier wave on the present frequency.""" + + self.CC1110_crystal(); #FIXME, '1110 specific. + self.RF_idle(); + + #self.resume(); + #time.sleep(1); + #self.halt(); + + RFST=0xDFE1; + + + #0a00 + #self.pokebysym("FSCTRL1" , 0x12) # Frequency synthesizer control. + #self.pokebysym("FSCTRL0" , 0x00) # Frequency synthesizer control. + self.pokebysym("FSCTRL1" , 0x0a) # Frequency synthesizer control. + self.pokebysym("FSCTRL0" , 0x00) # Frequency synthesizer control. + + #Don't change these while the radio is active. + self.pokebysym("FSCAL3" , 0xA9) # Frequency synthesizer calibration. + self.pokebysym("FSCAL2" , 0x0A) # Frequency synthesizer calibration. + self.pokebysym("FSCAL1" , 0x00) # Frequency synthesizer calibration. + self.pokebysym("FSCAL0" , 0x11) # Frequency synthesizer calibration. + + #Ossmann's settings, not yet sure how they differ. + #self.pokebysym("FSCAL3" , 0xEA) # Frequency synthesizer calibration. + #self.pokebysym("FSCAL2" , 0x2A) # Frequency synthesizer calibration. + #self.pokebysym("FSCAL1" , 0x00) # Frequency synthesizer calibration. + #self.pokebysym("FSCAL0" , 0x1F) # Frequency synthesizer calibration. + + + #self.pokebysym("FREQ2" , 0x10) # Frequency control word, high byte. + #self.pokebysym("FREQ1" , 0xEC) # Frequency control word, middle byte. + #self.pokebysym("FREQ0" , 0x4E) # Frequency control word, low byte. + self.pokebysym("MDMCFG4" , 0x86) # Modem configuration. + self.pokebysym("MDMCFG3" , 0x83) # Modem configuration. + self.pokebysym("MDMCFG2" , 0x30) # Modem configuration. + self.pokebysym("MDMCFG1" , 0x22) # Modem configuration. + self.pokebysym("MDMCFG0" , 0xF8) # Modem configuration. + self.pokebysym("CHANNR" , 0x00) # Channel number. + self.pokebysym("DEVIATN" , 0x00) # Modem deviation setting (when FSK modulation is enabled). + self.pokebysym("FREND1" , 0x56) # Front end RX configuration. + + self.pokebysym("FREND0" , 0x10) # Front end RX configuration. + self.pokebysym("MCSM0" , 0x14) # Main Radio Control State Machine configuration. + self.pokebysym("FOCCFG" , 0x16) # Frequency Offset Compensation Configuration. + self.pokebysym("BSCFG" , 0x6C) # Bit synchronization Configuration. + + self.pokebysym("AGCCTRL2" , 0x03) # AGC control. + self.pokebysym("AGCCTRL1" , 0x40) # AGC control. + self.pokebysym("AGCCTRL0" , 0x91) # AGC control. + + + + + + + self.pokebysym("TEST2" , 0x88) # Various test settings. + self.pokebysym("TEST1" , 0x31) # Various test settings. + self.pokebysym("TEST0" , 0x09) # Various test settings. + self.pokebysym("PA_TABLE0", 0xC0) # PA output power setting. + self.pokebysym("PKTCTRL1" , 0x04) # Packet automation control. + self.pokebysym("PKTCTRL0" , 0x22) # Packet automation control. + self.pokebysym("ADDR" , 0x00) # Device address. + self.pokebysym("PKTLEN" , 0xFF) # Packet length. + + self.pokebysym("SYNC1",0xAA); + self.pokebysym("SYNC0",0xAA); + + + + #while ((MARCSTATE & MARCSTATE_MARC_STATE) != MARC_STATE_TX); + state=0; + + while((state!=0x13)): + self.pokebyte(RFST,0x03); #RFST=RFST_STX + time.sleep(0.1); + state=self.peekbysym("MARCSTATE")&0x1F; + print "state=%02x" % state; + print "Holding a carrier on %f MHz." % (self.RF_getfreq()/10**6); + + #Not needed, radio works when CPU is halted. + #self.resume(); + + return; + + def RF_getrssi(self): - """Returns the received signal strenght, from 0 to 1.""" - rssireg=self.symbols.get("RSSI"); - return self.CCpeekdatabyte(rssireg); + """Returns the received signal strenght, with a weird offset.""" + try: + rssireg=self.symbols.get("RSSI"); + return self.CCpeekdatabyte(rssireg); + except: + if self.verbose>0: print "RSSI reg doesn't exist."; + try: + #RSSI doesn't exist on 2.4GHz devices. Maybe RSSIL and RSSIH? + rssilreg=self.symbols.get("RSSIL"); + rssil=self.CCpeekdatabyte(rssilreg); + rssihreg=self.symbols.get("RSSIL"); + rssih=self.CCpeekdatabyte(rssihreg); + return (rssih<<8)|rssil; + except: + if self.verbose>0: print "RSSIL/RSSIH regs don't exist."; + + return 0; + + def SRF_loadsymbols(self): ident=self.CCident(); chip=self.CCversions.get(ident&0xFF00); @@ -229,12 +417,12 @@ class GoodFETCC(GoodFET): def CCdebuginstr(self,instr): self.writecmd(self.APP,0x88,len(instr),instr); return ord(self.data[0]); - def peekblock(self,address,length,memory="vn"): + def peekblock(self,adr,length,memory="vn"): """Return a block of data.""" - data=range(0,length); - for foo in range(0,length): - data[foo]=self.peek8(address+foo,memory); - return data; + data=[adr&0xff, (adr&0xff00)>>8, + length&0xFF,(length&0xFF00)>>8]; + self.writecmd(self.APP,0x91,4,data); + return [ord(x) for x in self.data] def peek8(self,address, memory="code"): if(memory=="code" or memory=="flash" or memory=="vn"): return self.CCpeekcodebyte(address); @@ -271,7 +459,10 @@ class GoodFETCC(GoodFET): self.data=[adr&0xff, val&0xff]; self.writecmd(self.APP,0x02, 2, self.data); return ord(self.data[0]); - + def pokebyte(self,adr,val,mem="data"): + if mem!="data": + print "FIXME: poking of non data bytes not yet supported."; + self.CCpokedatabyte(adr,val); def CCpokedatabyte(self,adr,val): """Write a byte to data memory.""" self.data=[adr&0xff, (adr&0xff00)>>8, val];