+ response:
+ len=1;
+ while(
+ (cmddata[len++]=spitrans8(0xFF))!=0xA7
+ );
+ if(cmddata[0]==0xFE)
+ while(len<cmddata[1]+3)
+ cmddata[len++]=spitrans8(0xFF);
+ SETSS; //Raise !SS to end transaction.
+
+ txdata(app,verb,len);
+ return;
+}
+
+//! Handles a monitor command.
+void spi_handle_fn( uint8_t const app,
+ uint8_t const verb,
+ uint32_t const len)
+{
+ unsigned long i, l;
+
+ //Raise !SS to end transaction, just in case we forgot.
+ SETSS;
+ //spisetup();
+
+ switch(verb)
+ {
+ case READ:
+ case WRITE:
+ CLRSS; //Drop !SS to begin transaction.
+ for(i=0;i<len;i++)
+ cmddata[i]=spitrans8(cmddata[i]);
+ SETSS; //Raise !SS to end transaction.
+ txdata(app,verb,len);
+ break;
+
+ case SPI_RW_EM260: //SPI exchange with an EM260
+ spi_rw_em260(app,verb,len);
+ break;
+
+ case SPI_JEDEC://Grab 3-byte JEDEC ID.
+ CLRSS; //Drop !SS to begin transaction.
+ spitrans8(0x9f);
+ l=3; //Length is variable in some chips, 3 minimum.
+ for(i = 0; i < l; i++)
+ cmddata[i]=spitrans8(cmddata[i]);
+ txdata(app,verb,len);
+ SETSS; //Raise !SS to end transaction.
+ break;
+
+ case PEEK://Grab 128 bytes from an SPI Flash ROM
+ spiflash_peek(app,verb,len);
+ break;
+
+ case POKE://Poke up bytes from an SPI Flash ROM.
+ spiflash_pokeblocks(cmddatalong[0],//adr
+ cmddata+4,//buf
+ len-4);//len
+ txdata(app,verb,0);
+ break;
+
+ case SPI_ERASE://Erase the SPI Flash ROM.
+ spiflash_wrten();
+ CLRSS; //Drop !SS to begin transaction.
+ spitrans8(0xC7);//Chip Erase
+ SETSS; //Raise !SS to end transaction.
+
+ while(spiflash_status()&0x01)//while busy
+ PLEDOUT^=PLEDPIN;
+ PLEDOUT&=~PLEDPIN;
+
+ txdata(app,verb,0);
+ break;
+
+ case SETUP:
+ spisetup();
+ txdata(app,verb,0);
+ break;
+ }