X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fspi%2Fspi.c;h=c58b4bc1e1a34bd7b5645fca9c8d975dfdb2c3b3;hp=93a41b9fd53bda2beeb666ad8b295a8892e888f0;hb=9db7b366db7bd2535064bcdb0ae0ea89b2e6988f;hpb=92560226caf1a463eb144324978b0a390327e09e diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index 93a41b9..c58b4bc 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -66,6 +66,34 @@ unsigned char spitrans8(unsigned char byte){ return 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. +} + +//! 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. void spihandle(unsigned char app, unsigned char verb, @@ -102,6 +130,28 @@ void spihandle(unsigned char app, txdata(app,verb,len); 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. + + //First three bytes are address, then data. + for(i=0;i