From: travisutk Date: Sun, 6 Feb 2011 19:55:37 +0000 (+0000) Subject: Telos B port is now working, and the CC2420 driver is coming together. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=e027df82b3f7b6c0ed428a504220e13ae02886e9;ds=sidebyside Telos B port is now working, and the CC2420 driver is coming together. ZigBee by nightfall! git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@895 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/client/GoodFETCC.py b/client/GoodFETCC.py index d8cd955..fcb5311 100644 --- a/client/GoodFETCC.py +++ b/client/GoodFETCC.py @@ -593,7 +593,7 @@ class GoodFETCC(GoodFET): 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"); diff --git a/client/GoodFETCCSPI.py b/client/GoodFETCCSPI.py index bbe2d17..2dfaa7e 100644 --- a/client/GoodFETCCSPI.py +++ b/client/GoodFETCCSPI.py @@ -11,10 +11,28 @@ from GoodFET import GoodFET; class GoodFETCCSPI(GoodFET): CCSPIAPP=0x51; + CCversions={0x233d: "CC2420", + } def setup(self): """Move the FET into the CCSPI application.""" self.writecmd(self.CCSPIAPP,0x10,0,self.data); #CCSPI/SETUP + #Set up the radio for ZigBee + self.strobe(0x01); #SXOSCON + self.poke(0x11, 0x0AC2); #MDMCTRL0 + self.poke(0x12, 0x0500); #MDMCTRL1 + self.poke(0x1C, 0x007F); #IOCFG0 + self.poke(0x19, 0x01C4); #SECCTRL0, disabling crypto + + def ident(self): + return self.peek(0x1E); #MANFIDL + def identstr(self): + manfidl=self.peek(0x1E); + #manfidh=self.peek(0x1f); + try: + return "%s" % (self.CCversions[manfidl]); + except: + return "Unknown0x%04x" % manfidl; def trans8(self,byte): """Read and write 8 bits by CCSPI.""" data=self.CCSPItrans([byte]); @@ -30,35 +48,45 @@ class GoodFETCCSPI(GoodFET): data=[reg]; self.trans(data); return ord(self.data[0]); + def CC_RFST_IDLE(self): + """Switch the radio to idle mode, clearing overflows and errors.""" + self.strobe(0x00); #SNOP? + def CC_RFST_TX(self): + """Switch the radio to TX mode.""" + self.strobe(0x04); #0x05 for CCA + def CC_RFST_RX(self): + """Switch the radio to RX mode.""" + self.strobe(0x03); + def CC_RFST_CAL(self): + """Calibrate strobe the radio.""" + self.strobe(0x02); + def CC_RFST(self,state=0x00): + self.strobe(state); + return; def peek(self,reg,bytes=2): """Read a CCSPI Register. For long regs, result is flipped.""" + + #Reg is ORed with 0x40 by the GoodFET. data=[reg,0,0]; #Automatically calibrate the len. bytes=2; self.writecmd(self.CCSPIAPP,0x02,len(data),data); - toret=0; - #print "Status: %02x" % ord(self.data[0]); - for i in range(0,bytes): - toret=toret|(ord(self.data[i+1])<<(8*i)); + toret=( + ord(self.data[2])+ + (ord(self.data[1])<<8) + ); return toret; - def poke(self,reg,val,bytes=-1): + def poke(self,reg,val,bytes=2): """Write a CCSPI Register.""" - data=[reg]; - - #Automatically calibrate the len. - if bytes==-1: - bytes=1; - if reg==0x0a or reg==0x0b or reg==0x10: bytes=5; - - for i in range(0,bytes): - data=data+[(val>>(8*i))&0xFF]; + data=[reg,(val>>8)&0xFF,val&0xFF]; self.writecmd(self.CCSPIAPP,0x03,len(data),data); - if self.peek(reg,bytes)!=val and reg!=0x07: - print "Warning, failed to set r%02x=%02x, got %02x." %(reg, - val, - self.peek(reg,bytes)); + if self.peek(reg,bytes)!=val: + print "Warning, failed to set r%02x=0x%04x, got %02x." %( + reg, + val, + self.peek(reg,bytes)); return; def status(self): @@ -67,45 +95,29 @@ class GoodFETCCSPI(GoodFET): print "Status=%02x" % status; #Radio stuff begins here. - def RF_setenc(self,code="GFSK"): + def RF_setenc(self,code="802.15.4"): """Set the encoding type.""" - if code!=GFSK: - return "%s not supported by the CCSPI24L01. Try GFSK." return; def RF_getenc(self): """Get the encoding type.""" - return "GFSK"; + return "802.15.4"; def RF_getrate(self): - rate=self.peek(0x06)&0x28; - if rate==0x28: - rate=250*10**3; #256kbps - elif rate==0x08: - rate=2*10**6; #2Mbps - elif rate==0x00: - rate=1*10**6; #1Mbps - return rate; - def RF_setrate(self,rate=2*10**6): - r6=self.peek(0x06); #RF_SETUP register - r6=r6&(~0x28); #Clear rate fields. - if rate==2*10**6: - r6=r6|0x08; - elif rate==1*10**6: - r6=r6; - elif rate==250*10**3: - r6=r6|0x20; - print "Setting r6=%02x." % r6; - self.poke(0x06,r6); #Write new setting. + return 0; + def RF_setrate(self,rate=0): + return 0; def RF_setfreq(self,frequency): """Set the frequency in Hz.""" - - print "TODO write the setfreq() function."; + mhz=frequency/1000000; + fsctrl=self.peek(0x18)&~0x3FF; + fsctrl=fsctrl+int(mhz-2048) + self.poke(0x18,fsctrl); def RF_getfreq(self): """Get the frequency in Hz.""" - print "TODO write the getfreq() function."; - return 0; + fsctrl=self.peek(0x18); + mhz=2048+(fsctrl&0x3ff) + return mhz*1000000; def RF_getsmac(self): """Return the source MAC address.""" - return 0xdeadbeef; def RF_setsmac(self,mac): """Set the source MAC address.""" @@ -116,7 +128,10 @@ class GoodFETCCSPI(GoodFET): def RF_settmac(self,mac): """Set the target MAC address.""" return 0xdeadbeef; - + def RF_getrssi(self): + """Returns the received signal strenght, with a weird offset.""" + rssival=self.peek(0x13)&0xFF; #raw RSSI register, should normalize this + return rssival^0x80; def RF_rxpacket(self): """Get a packet from the radio. Returns None if none is waiting.""" print "Don't know how to get a packet."; diff --git a/client/goodfet.ccspi b/client/goodfet.ccspi index 50501c5..fb89dcf 100755 --- a/client/goodfet.ccspi +++ b/client/goodfet.ccspi @@ -8,7 +8,7 @@ import sys; import binascii; -import array; +import array, time; from GoodFETCCSPI import GoodFETCCSPI; @@ -31,17 +31,36 @@ client.setup(); #Might read as all ones if chip has a startup delay. if(sys.argv[1]=="info"): - print "Status is %02x" % client.strobe(0x00); + print "Found %s" % client.identstr(); + print "Freq: %05.05f MHz" % (client.RF_getfreq()/(10**6)); if(sys.argv[1]=="regs"): for adr in range(0x10,0x40): #*1024): val=client.peek(adr); - print "%04x:=%02x" % (adr,val); + print "%04x:=0x%04x" % (adr,val); if(sys.argv[1]=="test"): data=client.trans([0x20, 0xde, 0xad]); print "%02x %02x" % (ord(data[1]), ord(data[2])); data=client.trans([0x40|0x20, 0xde, 0xad]); print "%02x %02x" % (ord(data[1]), ord(data[2])); +if(sys.argv[1]=="rssi"): + if len(sys.argv)>2: + client.RF_setfreq(eval(sys.argv[2])); + print "Listening on %f MHz." % (client.RF_getfreq()/10.0**6); + + client.strobe(0x02); #Calibrate + time.sleep(1); + while 1: + client.CC_RFST_RX(); + #client.strobe(0x03); #SRXON + rssi=client.RF_getrssi(); + #client.CC_RFST_IDLE(); #idle + time.sleep(0.01); + string=""; + for foo in range(0,rssi>>2): + string=("%s."%string); + print "%02x %04i %s" % (rssi,rssi, string); + if(sys.argv[1]=="peek"): start=0x0000; if(len(sys.argv)>2): @@ -51,7 +70,7 @@ if(sys.argv[1]=="peek"): stop=int(sys.argv[3],16); print "Peeking from %04x to %04x." % (start,stop); while start<=stop: - print "%04x: %02x" % (start,client.peek(start)); + print "%04x: 0x%04x" % (start,client.peek(start)); start=start+1; if(sys.argv[1]=="poke"): start=0x0000; @@ -60,7 +79,7 @@ if(sys.argv[1]=="poke"): start=int(sys.argv[2],16); if(len(sys.argv)>3): val=int(sys.argv[3],16); - print "Poking %02x to become %010x." % (start,val); + print "Poking r%02x to become 0x%04x." % (start,val); client.poke(start,val); diff --git a/firmware/apps/radios/ccspi.c b/firmware/apps/radios/ccspi.c index ff46616..dd86e8c 100644 --- a/firmware/apps/radios/ccspi.c +++ b/firmware/apps/radios/ccspi.c @@ -54,10 +54,14 @@ void ccspisetup(){ DIRCE; P4OUT|=BIT5; //activate CC2420 voltage regulator - P4OUT|=BIT6; //bring CC2420 out of reset + msdelay(100); + + //Reset the CC2420. + P4OUT&=~BIT6; + P4OUT|=BIT6; //Begin a new transaction. - CLRSS; + CLRSS; SETSS; } @@ -118,32 +122,18 @@ void ccspi_handle_fn( uint8_t const app, //debugstr("Chipcon SPI handler."); switch(verb){ + case PEEK: + cmddata[0]|=0x40; //Set the read bit. + //DO NOT BREAK HERE. case READ: case WRITE: + case POKE: CLRSS; //Drop !SS to begin transaction. for(i=0;i @@ -14,6 +14,10 @@ #include "spi.h" +#define SPIAPPLICATION + +#include "platform.h" + //! Handles a monitor command. void spi_handle_fn( uint8_t const app, uint8_t const verb, diff --git a/firmware/platforms/telosb.h b/firmware/platforms/telosb.h index 26da46b..f91aa55 100644 --- a/firmware/platforms/telosb.h +++ b/firmware/platforms/telosb.h @@ -45,15 +45,20 @@ P6OUT = 0x00; //Radio CS is P4.2 -//#define SETSS P4OUT|=BIT2 -//#define CLRSS P4OUT&=~BIT2 -//#define DIRSS P4DIR|=BIT2 +#define SETSS P4OUT|=BIT2 +#define CLRSS P4OUT&=~BIT2 +#define DIRSS P4DIR|=BIT2 -//Flash CS is P4.4 + +//Flash CS is P4.4, redefine only for the SPI app. +#ifdef SPIAPPLICATION +#undef SETSS +#undef CLRSS +#undef DIRSS #define SETSS P4OUT|=BIT4 #define CLRSS P4OUT&=~BIT4 #define DIRSS P4DIR|=BIT4 - +#endif //CC2420 Chip Enable #define SETCE P4OUT|=BIT6