X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fspi%2Fspi.c;h=1cb12e5187b7c7ab8327c8351bb6e5b7ff0b2dfb;hp=47c42c5852717806e017fa5dea4a6a4d30928561;hb=e027df82b3f7b6c0ed428a504220e13ae02886e9;hpb=cc92cb4cc1f80259236ddf86911c03c0365db5ea diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index 47c42c5..1cb12e5 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -5,7 +5,7 @@ //Higher level left to client application. -#include "platform.h" + #include "command.h" #include @@ -14,21 +14,47 @@ #include "spi.h" +#define SPIAPPLICATION + +#include "platform.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. 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; } @@ -47,8 +73,10 @@ unsigned char spitrans8(unsigned char byte){ else CLRMOSI; byte <<= 1; - + + //SPIDELAY(100); SETCLK; + //SPIDELAY(100); /* read MISO on trailing edge */ byte |= READMISO; @@ -233,121 +261,131 @@ void em260_wake(){ //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){ +//! Handle an EM260 exchange. +void spi_rw_em260(u8 app, u8 verb, u32 len){ unsigned long i; - static int state=0; - - //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