#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
//#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;
}
//! 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.
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:
};
-#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;
//! 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++)
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.
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.
txdata(app,verb,0);
break;
case CCSPI_RX:
- RADIOPASSIVE;
//Get the packet.
CLRSS;
ccspitrans8(CCSPI_RXFIFO);
}
- SETSS;//End session
- RADIOACTIVE;
}
//! Set up the pins for NRF mode.
void nrfsetup(){
SETSS;
- P5DIR&=~MISO;
- P5DIR|=MOSI+SCK;
+ SPIDIR&=~MISO;
+ SPIDIR|=MOSI+SCK;
DIRSS;
DIRCE;
//! 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;
-
}
//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);
}
#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
#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
// 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 { \
#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
#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.
#define SETCE P5OUT|=BIT5
#define CLRCE P5OUT&=~BIT5
#define DIRCE P5DIR|=BIT5
+
+#define SPIOUT P5OUT
+#define SPIDIR P5DIR
+#define SPIIN P5IN
+#define SPIREN P5REN
#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;
#define SETCE P4OUT|=BIT5
#define CLRCE P4OUT&=~BIT5
#define DIRCE P4DIR|=BIT5
+
#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.