X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fspi%2Fspi.c;h=e07cdb544a43d8a8674eb51162bf4bc2f478e095;hp=98ff8f743dc42ddeb70af87d35c536c58e0ea3ce;hb=5fb0341d348e101b30794945a6c91546e25e8e7b;hpb=87fdfdcad02b7ada70fc1681d63e2ed2359dbfe9 diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index 98ff8f7..e07cdb5 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -14,11 +14,32 @@ #include "spi.h" +//! Handles a monitor command. +void spi_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const len); + +// define the spi app's app_t +app_t const spi_app = { + + /* app number */ + SPI, + + /* handle fn */ + spi_handle_fn, + + /* name */ + "SPI", + + /* desc */ + "\tThe SPI app handles the SPI bus protocol, turning\n" + "\tyour GoodFET into a USB-to-SPI adapter.\n" +}; + //This could be more accurate. //Does it ever need to be? #define SPISPEED 0 -#define SPIDELAY(x) -//delay(x) +#define SPIDELAY(x) delay(x) //! Set up the pins for SPI mode. @@ -29,8 +50,10 @@ void spisetup(){ DIRSS; //Begin a new transaction. + CLRSS; SETSS; + } @@ -47,14 +70,15 @@ unsigned char spitrans8(unsigned char byte){ else CLRMOSI; byte <<= 1; - + + //SPIDELAY(100); SETCLK; + //SPIDELAY(100); /* read MISO on trailing edge */ byte |= READMISO; CLRCLK; } - return byte; } @@ -220,71 +244,145 @@ void spiflash_erasesector(unsigned long adr){ } -//! Handles a monitor command. -void spihandle(unsigned char app, - unsigned char verb, - unsigned long len){ - unsigned long i; +//! Wake an EM260 Radio +void em260_wake(){ + //debugstr("Waking EM260."); + #define RST BIT6 + P2DIR|=RST; + SETRST; + delay(1024); - //Raise !SS to end transaction, just in case we forgot. - SETSS; - spisetup(); - - switch(verb){ - //PEEK and POKE might come later. - case READ: - case WRITE: - CLRSS; //Drop !SS to begin transaction. - for(i=0;i