X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fspi%2Fspi.c;h=c70cdb47e6652c00a1ffbc30375a413efd92c9f0;hp=0a15799a084762d27780e34deb3779246672f0e6;hb=c6e02600ef0e12eb9a7309755740a23b71a62205;hpb=4cf3fdb6a6d9a8844481d661e4d4c957c6a2ec87 diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index 0a15799..c70cdb4 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -35,6 +35,10 @@ void spisetup(){ P5OUT|=SS; P5DIR|=MOSI+SCK+SS; P5DIR&=~MISO; + + //Begin a new transaction. + P5OUT&=~SS; + P5OUT|=SS; } //! Read and write an SPI bit. @@ -68,12 +72,31 @@ unsigned char spitrans8(unsigned char byte){ //! Enable SPI writing void spiflash_wrten(){ - P5OUT&=~SS; //Drop !SS to begin transaction. - spitrans8(0x04);//Write Disable - P5OUT|=SS; //Raise !SS to end transaction. - P5OUT&=~SS; //Drop !SS to begin transaction. - spitrans8(0x06);//Write Enable - P5OUT|=SS; //Raise !SS to end transaction. + P5OUT&=~SS; //Drop !SS to begin transaction. + spitrans8(0x04);//Write Disable + P5OUT|=SS; //Raise !SS to end transaction. + P5OUT&=~SS; //Drop !SS to begin transaction. + spitrans8(0x06);//Write Enable + P5OUT|=SS; //Raise !SS to end transaction. +} + +//! Grab the SPI flash status byte. +unsigned char spiflash_status(){ + unsigned char c; + P5OUT|=SS; //Raise !SS to end transaction. + P5OUT&=~SS; //Drop !SS to begin transaction. + spitrans8(0x05);//GET STATUS + c=spitrans8(0xFF); + P5OUT|=SS; //Raise !SS to end transaction. + return c; +} +//! Grab the SPI flash status byte. +void spiflash_setstatus(unsigned char c){ + P5OUT&=~SS; //Drop !SS to begin transaction. + spitrans8(0x01);//SET STATUS + spitrans8(c); + P5OUT|=SS; //Raise !SS to end transaction. + return c; } //! Handles a monitor command. @@ -81,6 +104,11 @@ void spihandle(unsigned char app, unsigned char verb, unsigned char len){ unsigned char i; + + + //Raise !SS to end transaction, just in case we forgot. + P5OUT|=SS; + switch(verb){ //PEEK and POKE might come later. case READ: @@ -109,18 +137,21 @@ void spihandle(unsigned char app, len=0x80;//128 byte chunk for(i=0;i