X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fspi%2Fspi.c;h=c58b4bc1e1a34bd7b5645fca9c8d975dfdb2c3b3;hp=0a15799a084762d27780e34deb3779246672f0e6;hb=9db7b366db7bd2535064bcdb0ae0ea89b2e6988f;hpb=4cf3fdb6a6d9a8844481d661e4d4c957c6a2ec87 diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index 0a15799..c58b4bc 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -68,12 +68,30 @@ 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; //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. @@ -113,7 +131,9 @@ void spihandle(unsigned char app, P5OUT|=SS; //Raise !SS to end transaction. break; case POKE://Poke up bytes from an SPI Flash ROM. + spiflash_setstatus(0x02); spiflash_wrten(); + P5OUT&=~SS; //Drop !SS to begin transaction. spitrans8(0x02); //Poke command. @@ -121,6 +141,8 @@ void spihandle(unsigned char app, for(i=0;i