From: travisutk Date: Sun, 6 Feb 2011 01:44:03 +0000 (+0000) Subject: Refactoring a lot of the P5 stuff. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=854dba571fe62948dfb23a396be3299225fcbb05 Refactoring a lot of the P5 stuff. 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 --- diff --git a/firmware/Makefile b/firmware/Makefile index b96d358..b0ec46a 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -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 diff --git a/firmware/apps/chipcon/chipcon.c b/firmware/apps/chipcon/chipcon.c index 392e900..83bc898 100644 --- a/firmware/apps/chipcon/chipcon.c +++ b/firmware/apps/chipcon/chipcon.c @@ -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: diff --git a/firmware/apps/radios/ccspi.c b/firmware/apps/radios/ccspi.c index ab1051f..74dde4f 100644 --- a/firmware/apps/radios/ccspi.c +++ b/firmware/apps/radios/ccspi.c @@ -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;iapp == 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); } diff --git a/firmware/include/jtag.h b/firmware/include/jtag.h index 7aa1856..bdcd803 100644 --- a/firmware/include/jtag.h +++ b/firmware/include/jtag.h @@ -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 diff --git a/firmware/include/sbw.h b/firmware/include/sbw.h index 91fcad1..206dd6a 100644 --- a/firmware/include/sbw.h +++ b/firmware/include/sbw.h @@ -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 { \ diff --git a/firmware/include/spi.h b/firmware/include/spi.h index dfbb28a..0f272da 100644 --- a/firmware/include/spi.h +++ b/firmware/include/spi.h @@ -11,17 +11,17 @@ #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 diff --git a/firmware/platforms/goodfet.h b/firmware/platforms/goodfet.h index ba9b0c2..d421bd7 100644 --- a/firmware/platforms/goodfet.h +++ b/firmware/platforms/goodfet.h @@ -20,6 +20,18 @@ #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. diff --git a/firmware/platforms/nhbadge.h b/firmware/platforms/nhbadge.h index 24544b3..8e3e59f 100644 --- a/firmware/platforms/nhbadge.h +++ b/firmware/platforms/nhbadge.h @@ -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 diff --git a/firmware/platforms/nhbadgeb.h b/firmware/platforms/nhbadgeb.h index 895df8a..57efd0b 100644 --- a/firmware/platforms/nhbadgeb.h +++ b/firmware/platforms/nhbadgeb.h @@ -8,19 +8,25 @@ #include #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 + diff --git a/firmware/platforms/telosb.h b/firmware/platforms/telosb.h index 59495eb..235faee 100644 --- a/firmware/platforms/telosb.h +++ b/firmware/platforms/telosb.h @@ -12,17 +12,42 @@ #include #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.