X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=firmware%2Fapps%2Favr%2Favr.c;h=953156347217821a47119797905589d0becb302e;hb=68b3ba0e68376630d0ce37c80048b3c107661007;hp=f1fe5b78eaa1b63c761b8c37bf7485a335edd620;hpb=eddb0eb08f187dc156a6cb51878104df67d97436;p=goodfet diff --git a/firmware/apps/avr/avr.c b/firmware/apps/avr/avr.c index f1fe5b7..9531563 100644 --- a/firmware/apps/avr/avr.c +++ b/firmware/apps/avr/avr.c @@ -11,37 +11,39 @@ #include #include "avr.h" -#include "glitch.h" +//#include "glitch.h" //! Setup the AVR pins. void avrsetup(){ spisetup(); - - glitchsetup(); } //! Initialized an attached AVR. void avrconnect(){ //set I/O pins - avrsetup(); + avrsetup(); //Cut this? + + SETSS; + //delay(50); //Pulse !RST (SS) at least twice while CLK is low. CLRCLK; CLRSS; + //delay(5); SETSS; CLRCLK; - delay(500); + //delay(5); CLRSS; - delay(500); + //delay(5); //Enable programming avr_prgen(); } //! Read and write an SPI byte with delays. -unsigned char avrtrans8(unsigned char byte){ - register unsigned int bit; +u8 avrtrans8(u8 byte){ + register u16 bit; //This function came from the SPI Wikipedia article. //Minor alterations. @@ -70,7 +72,7 @@ u8 avrexchange(u8 a, u8 b, u8 c, u8 d){ avrtrans8(a); avrtrans8(b); if(avrtrans8(c)!=b){ - debugstr("AVR sync error, b not returned as c."); + //debugstr("AVR sync error, b not returned as c."); //Reconnect here? } return avrtrans8(d); @@ -104,6 +106,11 @@ void avr_erase(){ u8 avr_lockbits(){ return avrexchange(0x58, 0, 0, 0); } +//! Write lock bits. +void avr_setlock(u8 bits){ + avrexchange(0xAC,0xE0,0x00, + bits); +} //! Read a byte of EEPROM. u8 avr_peekeeprom(u16 adr){ @@ -130,10 +137,11 @@ void avrhandle(unsigned char app, unsigned long len){ unsigned long i; unsigned int at; - static u8 connected=0; + /* if(!avr_isready() && connected) debugstr("AVR is not yet ready."); + */ switch(verb){ case READ: @@ -146,9 +154,10 @@ void avrhandle(unsigned char app, avrsetup(); txdata(app,verb,0); break; - case START://returns device code + case START: avrconnect(); - //no break here + txdata(app,verb,0); + break;//Used to fall through here. case AVR_PEEKSIG: for(i=0;i<4;i++) cmddata[i]=avr_sig(i); @@ -162,7 +171,10 @@ void avrhandle(unsigned char app, cmddata[0]=avr_lockbits(); txdata(app,verb,1); break; - + case AVR_POKELOCK: + avr_setlock(cmddata[0]); + txdata(app,verb,0); + break; case AVR_POKEEEPROM: avr_pokeeeprom(cmddataword[0], cmddata[2]); //no break here.