X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fspi%2Fspi.c;h=47c42c5852717806e017fa5dea4a6a4d30928561;hp=dd92ba2096fc41f76cac5dbf09b7107cd70dd2a6;hb=cc92cb4cc1f80259236ddf86911c03c0365db5ea;hpb=97143fece53250662a3ffd22f141619a4902eda7 diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index dd92ba2..47c42c5 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -24,7 +24,7 @@ //! Set up the pins for SPI mode. void spisetup(){ SETSS; - P5DIR|=MOSI+SCK; //BIT0 might be SS + P5DIR|=MOSI+SCK+BIT0; //BIT0 might be SS P5DIR&=~MISO; DIRSS; @@ -54,7 +54,6 @@ unsigned char spitrans8(unsigned char byte){ byte |= READMISO; CLRCLK; } - return byte; } @@ -220,11 +219,27 @@ void spiflash_erasesector(unsigned long adr){ } +//! Wake an EM260 Radio +void em260_wake(){ + //debugstr("Waking EM260."); + #define RST BIT6 + P2DIR|=RST; + SETRST; + delay(1024); + + CLRRST;//Wake chip. + while(P4IN&1); + SETRST;//Woken. + //debugstr("EM260 is now awake."); + delay(1024); //DO NOT REMOVE, fails without. +} + //! Handles a monitor command. void spihandle(unsigned char app, unsigned char verb, unsigned long len){ unsigned long i; + static int state=0; //Raise !SS to end transaction, just in case we forgot. SETSS; @@ -240,8 +255,57 @@ void spihandle(unsigned char app, SETSS; //Raise !SS to end transaction. txdata(app,verb,len); break; + + case SPI_RW_EM260: //SPI exchange with an EM260 + P4DIR=0; //TODO ASAP remove P4 references. + P4OUT=0xFF; + P4REN=0xFF; + + //See GoodFETEM260.py for details. + //The EM260 requires that the host wait for the client. + + /* + if((~P4IN)&1) + debugstr("Detected HOST_INT."); + */ + + //if(!state++) + //if(state++&1) + em260_wake(); + + SETMOSI; //Autodetected SPI mode. + CLRSS; //Drop !SS to begin transaction. + //Host to slave. Ignore data. + for(i=0;i