Refactoring a lot of the P5 stuff.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 6 Feb 2011 01:44:03 +0000 (01:44 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 6 Feb 2011 01:44:03 +0000 (01:44 +0000)
TelosB still isn't working, for reasons that I don't understand.

git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@889 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

13 files changed:
firmware/Makefile
firmware/apps/chipcon/chipcon.c
firmware/apps/radios/ccspi.c
firmware/apps/radios/nrf.c
firmware/apps/spi/spi.c
firmware/goodfet.c
firmware/include/jtag.h
firmware/include/sbw.h
firmware/include/spi.h
firmware/platforms/goodfet.h
firmware/platforms/nhbadge.h
firmware/platforms/nhbadgeb.h
firmware/platforms/telosb.h

index b96d358..b0ec46a 100644 (file)
@@ -93,7 +93,7 @@ CC=msp430-gcc -Wall -Os -g -mmcu=$(mcu) -D$(mcu) -D$(platform) -Dplatform=$(plat
 #config = monitor sbw  chipcon nrf ccspi spi jtagarm7 jtag430 jtag430x2 avr
 
 # New default.
-config = monitor chipcon nrf spi jtagarm7 jtag430 jtag430x2 avr
+config = monitor chipcon ccspi nrf spi jtagarm7 jtag430 jtag430x2 avr
 
 
 # Build the needed list of app and lib object files from the config
index 392e900..83bc898 100644 (file)
@@ -62,19 +62,19 @@ app_t const chipcon_app = {
 //#define CCDELAY(x) delay(x)
 #define CCDELAY(x) 
 
-#define SETMOSI P5OUT|=MOSI
-#define CLRMOSI P5OUT&=~MOSI
-#define SETCLK P5OUT|=SCK
-#define CLRCLK P5OUT&=~SCK
-#define READMISO (P5IN&MISO?1:0)
+#define SETMOSI SPIOUT|=MOSI
+#define CLRMOSI SPIOUT&=~MOSI
+#define SETCLK SPIOUT|=SCK
+#define CLRCLK SPIOUT&=~SCK
+#define READMISO (SPIIN&MISO?1:0)
 
-#define CCWRITE P5DIR|=MOSI
-#define CCREAD P5DIR&=~MISO
+#define CCWRITE SPIDIR|=MOSI
+#define CCREAD SPIDIR&=~MISO
 
 //! Set up the pins for CC mode.  Does not init debugger.
 void ccsetup(){
-  P5OUT|=MOSI+SCK+RST;
-  P5DIR|=MOSI+SCK+RST;
+  SPIOUT|=MOSI+SCK+RST;
+  SPIDIR|=MOSI+SCK+RST;
   //P5REN=0xFF;
 }
 
@@ -97,31 +97,31 @@ void ccsetup(){
 //! Initialize the debugger
 void ccdebuginit(){
   //Port output BUT NOT DIRECTION is set at start.
-  P5OUT|=MOSI+SCK+RST;
+  SPIOUT|=MOSI+SCK+RST;
   
   //delay(30); //So the beginning is ready for glitching.
   
   //Two positive debug clock pulses while !RST is low.
   //Take RST low, pulse twice, then high.
-  P5OUT&=~SCK;
+  SPIOUT&=~SCK;
   delay(10);
-  P5OUT&=~RST;
+  SPIOUT&=~RST;
   
   delay(10);
   
   //Two rising edges.
-  P5OUT^=SCK; //up
+  SPIOUT^=SCK; //up
   delay(1);
-  P5OUT^=SCK; //down
+  SPIOUT^=SCK; //down
   delay(1);
-  P5OUT^=SCK; //up
+  SPIOUT^=SCK; //up
   delay(1);
-  P5OUT^=SCK; //Unnecessary.
+  SPIOUT^=SCK; //Unnecessary.
   delay(1);
   //delay(0);
   
   //Raise !RST.
-  P5OUT|=RST;
+  SPIOUT|=RST;
 }
 
 //! Read and write a CC bit.
@@ -206,9 +206,9 @@ void cc_handle_fn( uint8_t const app,
     break;
   case STOP://exit debugger
     //Take RST low, then high.
-    P5OUT&=~RST;
+    SPIOUT&=~RST;
     CCDELAY(CCSPEED);
-    P5OUT|=RST;
+    SPIOUT|=RST;
     txdata(app,verb,0);
     break;
   case SETUP:
index ab1051f..74dde4f 100644 (file)
@@ -47,17 +47,21 @@ app_t const ccspi_app = {
 };
 
 
-#define RADIOACTIVE SETCE
-#define RADIOPASSIVE CLRCE
+#define RADIOACTIVE CLRCE
+#define RADIOPASSIVE SETCE
 
 //! Set up the pins for CCSPI mode.
 void ccspisetup(){
-  SETSS;
-  P5DIR&=~MISO;
-  P5DIR|=MOSI+SCK;
+  SPIDIR&=~MISO;
+  SPIDIR|=MOSI+SCK;
   DIRSS;
   DIRCE;
   
+  //Telos B Radio VReg Enable
+  P4DIR|=BIT5+BIT2+BIT6+BIT7;
+  P4OUT|=BIT5+BIT7;
+  P4OUT&=~(BIT6+BIT2);
+  
   //Begin a new transaction.
   CLRSS; 
   SETSS;
@@ -113,20 +117,14 @@ u8 ccspi_regread(u8 reg, u8 *buf, int len){
 
 //! Handles a Chipcon SPI command.
 void ccspi_handle_fn( uint8_t const app,
-                                         uint8_t const verb,
-                                         uint32_t const len)
-{
+                     uint8_t const verb,
+                     uint32_t const len){
   unsigned long i;
   
-  //Drop CE to passify radio.
-  RADIOPASSIVE;
-  //Raise !SS to end transaction, just in case we forgot.
-  SETSS;
-  ccspisetup();
+  //debugstr("Chipcon SPI handler.");
   
   switch(verb){
-    //PEEK and POKE might come later.
-  case READ:  
+  case READ:
   case WRITE:
     CLRSS; //Drop !SS to begin transaction.
     for(i=0;i<len;i++)
@@ -137,7 +135,7 @@ void ccspi_handle_fn( uint8_t const app,
 
   case PEEK://Grab CCSPI Register
     CLRSS; //Drop !SS to begin transaction.
-    ccspitrans8(CCSPI_R_REGISTER | cmddata[0]); //000A AAAA
+    cmddata[0]=ccspitrans8(/*CCSPI_R_REGISTER |*/ cmddata[0]); //000A AAAA
     for(i=1;i<len;i++)
       cmddata[i]=ccspitrans8(cmddata[i]);
     SETSS;  //Raise !SS to end transaction.
@@ -146,7 +144,7 @@ void ccspi_handle_fn( uint8_t const app,
     
   case POKE://Poke CCSPI Register
     CLRSS; //Drop !SS to begin transaction.
-    ccspitrans8(CCSPI_W_REGISTER | cmddata[0]); //001A AAAA
+    cmddata[0]=ccspitrans8(/* CCSPI_W_REGISTER |*/ 0x40 | cmddata[0]); //02AA AAAA
     for(i=1;i<len;i++)
       cmddata[i]=ccspitrans8(cmddata[i]);
     SETSS;  //Raise !SS to end transaction.
@@ -157,7 +155,6 @@ void ccspi_handle_fn( uint8_t const app,
     txdata(app,verb,0);
     break;
   case CCSPI_RX:
-    RADIOPASSIVE;
     //Get the packet.
     CLRSS;
     ccspitrans8(CCSPI_RXFIFO);
@@ -185,6 +182,4 @@ void ccspi_handle_fn( uint8_t const app,
   }
   
 
-  SETSS;//End session
-  RADIOACTIVE;
 }
index 0b1b6bd..e607bf6 100644 (file)
@@ -43,8 +43,8 @@ app_t const nrf_app = {
 //! Set up the pins for NRF mode.
 void nrfsetup(){
   SETSS;
-  P5DIR&=~MISO;
-  P5DIR|=MOSI+SCK;
+  SPIDIR&=~MISO;
+  SPIDIR|=MOSI+SCK;
   DIRSS;
   DIRCE;
   
index e07cdb5..aa3c5ec 100644 (file)
@@ -45,15 +45,14 @@ app_t const spi_app = {
 //! Set up the pins for SPI mode.
 void spisetup(){
   SETSS;
-  P5DIR|=MOSI+SCK+BIT0; //BIT0 might be SS
-  P5DIR&=~MISO;
+  SPIDIR|=MOSI+SCK+BIT0; //BIT0 might be SS
+  SPIDIR&=~MISO;
   DIRSS;
   
   //Begin a new transaction.
   
   CLRSS; 
   SETSS;
-  
 }
 
 
index c7563e6..a3f3587 100644 (file)
@@ -84,37 +84,38 @@ void init()
 
        //Enable Interrupts.
        //eint();
+       
+       #ifdef INITPLATFORM
+       INITPLATFORM;
+       #endif
 }
 
 
 //! Handle a command.
 void handle(uint8_t const app,
-                       uint8_t const verb,
-                       uint32_t const len)
-{
-       int i;
-
-       //debugstr("GoodFET");
-       PLEDOUT&=~PLEDPIN;
-
-       // find the app and call the handle fn
-       for(i = 0; i < num_apps; i++)
-       {
-               if(apps[i]->app == app)
-               {
-                       // call the app's handle fn
-                       (*(apps[i]->handle))(app, verb, len);
-
-                       // exit early
-                       return;
-               }
-       }
-
-       // if we get here, then the desired app is not copiled in 
-       // this firmware
-       debugstr("App missing.");
-       debughex(app);
-       txdata(app, NOK, 0);
+           uint8_t const verb,
+           uint32_t const len){
+  int i;
+
+  //debugstr("GoodFET");
+  PLEDOUT&=~PLEDPIN;
+
+  // find the app and call the handle fn
+  for(i = 0; i < num_apps; i++){
+    if(apps[i]->app == app){
+      // call the app's handle fn
+      (*(apps[i]->handle))(app, verb, len);
+      
+      // exit early
+      return;
+    }
+  }
+
+  // if we get here, then the desired app is not copiled in 
+  // this firmware
+  debugstr("App missing.");
+  debughex(app);
+  txdata(app, NOK, 0);
 }
 
 
index 7aa1856..bdcd803 100644 (file)
@@ -65,17 +65,18 @@ void jtag_resettap();
 #define JTAGSPEED 20
 #define JTAGDELAY(x) delay(x)
 
-#define SETMOSI P5OUT|=MOSI
-#define CLRMOSI P5OUT&=~MOSI
-#define SETCLK P5OUT|=SCK
-#define CLRCLK P5OUT&=~SCK
-#define READMISO (P5IN&MISO?1:0)
-#define SETTMS P5OUT|=TMS
-#define CLRTMS P5OUT&=~TMS
-#define SETTCK P5OUT|=TCK
-#define CLRTCK P5OUT&=~TCK
-#define SETTDI P5OUT|=TDI
-#define CLRTDI P5OUT&=~TDI
+
+#define SETMOSI SPIOUT|=MOSI
+#define CLRMOSI SPIOUT&=~MOSI
+#define SETCLK SPIOUT|=SCK
+#define CLRCLK SPIOUT&=~SCK
+#define READMISO (SPIIN&MISO?1:0)
+#define SETTMS SPIOUT|=TMS
+#define CLRTMS SPIOUT&=~TMS
+#define SETTCK SPIOUT|=TCK
+#define CLRTCK SPIOUT&=~TCK
+#define SETTDI SPIOUT|=TDI
+#define CLRTDI SPIOUT&=~TDI
 
 #define SETTST P4OUT|=TST
 #define CLRTST P4OUT&=~TST
@@ -86,8 +87,8 @@ void jtag_resettap();
 #define CLRTCLK CLRTDI
 
 extern int savedtclk;
-#define SAVETCLK savedtclk=P5OUT&TCLK;
-#define RESTORETCLK if(savedtclk) P5OUT|=TCLK; else P5OUT&=~TCLK
+#define SAVETCLK savedtclk=SPIOUT&TCLK;
+#define RESTORETCLK if(savedtclk) SPIOUT|=TCLK; else SPIOUT&=~TCLK
 
 //Replace every "CLRTCK SETTCK" with this.
 #define TCKTOCK CLRTCK,SETTCK
index 91fcad1..206dd6a 100644 (file)
@@ -62,17 +62,17 @@ void sbwCLRTCLK();
 
 // Macros
 #define SBWCLK() do { \
-    P5OUT &= ~SBWTCK; \
+    SPIOUT &= ~SBWTCK; \
     asm("nop");              \
     asm("nop");              \
     asm("nop");              \
-    P5OUT |= SBWTCK;  \
+    SPIOUT |= SBWTCK;  \
   } while (0)
 #define SETSBWIO(x) do {                       \
   if (x)                                       \
-    P5OUT |= SBWTDIO;                          \
+    SPIOUT |= SBWTDIO;                         \
   else                                         \
-    P5OUT &= ~SBWTDIO;                         \
+    SPIOUT &= ~SBWTDIO;                                \
   } while (0)
 #undef RESTORETCLK
 #define RESTORETCLK do {                       \
index dfbb28a..0f272da 100644 (file)
 #define SPI 0x01
 
 //Pins and I/O
-//#define SS BIT0
 #define MOSI BIT1
 #define MISO BIT2
 #define SCK  BIT3
 
-#define SETMOSI P5OUT|=MOSI
-#define CLRMOSI P5OUT&=~MOSI
-#define SETCLK P5OUT|=SCK
-#define CLRCLK P5OUT&=~SCK
-#define READMISO (P5IN&MISO?1:0)
+#define SETMOSI SPIOUT|=MOSI
+#define CLRMOSI SPIOUT&=~MOSI
+#define SETCLK SPIOUT|=SCK
+#define CLRCLK SPIOUT&=~SCK
+#define READMISO (SPIIN&MISO?1:0)
 
+//FIXME this should be defined by the platform.
 #define SETTST P4OUT|=TST
 #define CLRTST P4OUT&=~TST
 #define SETRST P2OUT|=RST
index ba9b0c2..d421bd7 100644 (file)
 #define P5DIR P3DIR
 #define P5IN P3IN
 #define P5REN P3REN
+
+#define SPIOUT P3OUT
+#define SPIDIR P3DIR
+#define SPIIN  P3IN
+#define SPIREN P3REN
+#else
+
+#define SPIOUT P5OUT
+#define SPIDIR P5DIR
+#define SPIIN  P5IN
+#define SPIREN P5REN
+
 #endif
 
 //This is how things used to work, don't do it anymore.
index 24544b3..8e3e59f 100644 (file)
@@ -26,3 +26,8 @@
 #define SETCE P5OUT|=BIT5
 #define CLRCE P5OUT&=~BIT5
 #define DIRCE P5DIR|=BIT5
+
+#define SPIOUT P5OUT
+#define SPIDIR P5DIR
+#define SPIIN  P5IN
+#define SPIREN P5REN
index 895df8a..57efd0b 100644 (file)
@@ -8,19 +8,25 @@
 #include <io.h>
 #endif
 
+//This nonsense is deprecated.
+//Remove as soon as is convenient.
 #define P5OUT P4OUT
 #define P5DIR P4DIR
 #define P5IN P4IN
 #define P5REN P4REN
 
+#define SPIOUT P4OUT
+#define SPIDIR P4DIR
+#define SPIIN  P4IN
+#define SPIREN P4REN
+
+
 
 //LED on P1.0
 #define PLEDOUT P1OUT
 #define PLEDDIR P1DIR
 #define PLEDPIN BIT0
 
-
-//No longer works for Hope badge.
 #define SETSS P4OUT|=BIT4
 #define CLRSS P4OUT&=~BIT4
 #define DIRSS P4DIR|=BIT4;
@@ -31,3 +37,4 @@
 #define SETCE P4OUT|=BIT5
 #define CLRCE P4OUT&=~BIT5
 #define DIRCE P4DIR|=BIT5
+
index 59495eb..235faee 100644 (file)
 #include <io.h>
 #endif
 
-
-//LED on P1.0
+//LED on P5.4
 #define PLEDOUT P5OUT
 #define PLEDDIR P5DIR
 #define PLEDPIN BIT4
 
 
+#define SPIOUT P3OUT
+#define SPIDIR P3DIR
+#define SPIIN  P3IN
+#define SPIREN P3REN
+#define P5OUT P3OUT
+#define P5DIR P3DIR
+#define P5IN  P3IN
+#define P5REN P3REN
+
+
+/* For the radio to be used:
+   4.6 (!RST) must be low
+   4.5 (VREF_EN) must be high
+   4.2 (!CS) must be low for the transaction.
+*/
+
+#define INITPLATFORM \
+  P4DIR|=BIT6+BIT5+BIT2+BIT7+BIT4; \
+  P4OUT=BIT5;
+
 //Radio CS is P4.2
 #define SETSS P4OUT|=BIT2
 #define CLRSS P4OUT&=~BIT2
-#define DIRSS P4DIR|=BIT2;
+#define DIRSS P4DIR|=BIT2
+
+//Flash CS is P4.4
+//#define SETSS P4OUT|=BIT4
+//#define CLRSS P4OUT&=~BIT4
+//#define DIRSS P4DIR|=BIT4
 
 
 //CC2420 Chip Reset.  Need to document this.