X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fspi%2Fspi.c;h=dc1c28675750cb047d6022c021cdf5e5fcb7404e;hp=eed955333c6b42dc0cfb175b08c51602ce7cddb1;hb=f0b3193e5145770ef1bc255b5983e36e37ca5a9b;hpb=30b52ae1a038f8ad3c563bf8e12f3a849abf8704 diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index eed9553..dc1c286 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -17,8 +17,7 @@ //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 +28,10 @@ void spisetup(){ DIRSS; //Begin a new transaction. + CLRSS; SETSS; + } @@ -47,8 +48,10 @@ unsigned char spitrans8(unsigned char byte){ else CLRMOSI; byte <<= 1; - + + //SPIDELAY(100); SETCLK; + //SPIDELAY(100); /* read MISO on trailing edge */ byte |= READMISO; @@ -233,6 +236,67 @@ void em260_wake(){ //debugstr("EM260 is now awake."); delay(1024); //DO NOT REMOVE, fails without. } +//! Handle an EM260 exchange. +void spi_rw_em260(u8 app, u8 verb, u32 len){ + unsigned long i; + u8 lastin; + + 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."); + */ + + em260_wake(); + + + SETMOSI; //Autodetected SPI mode. + CLRSS; //Drop !SS to begin transaction. + //Host to slave. Ignore data. + for(i=0;i