X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=inline;f=firmware%2Fapps%2Fspi%2Fspi.c;h=e00d2aa2376e22e3380406a8ef817aa7b63a9fbf;hb=d0d48d9cdb77bee064236d148002f98f3c247121;hp=785c47600f73ee7f860ef3e88153e1952795010d;hpb=e858c51543d928d837578d3e03dd5686e888220e;p=goodfet diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index 785c476..e00d2aa 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -68,9 +68,31 @@ unsigned char spitrans8(unsigned char byte){ //! Enable SPI writing void spiflash_wrten(){ - P5OUT&=~SS; //Drop !SS to begin transaction. - spitrans8(0x06);//Chip Erase - 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. @@ -78,6 +100,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: @@ -106,11 +133,22 @@ void spihandle(unsigned char app, len=0x80;//128 byte chunk for(i=0;i