Cleaning up glitching.
[goodfet] / firmware / apps / avr / avr.c
index f1fe5b7..577d878 100644 (file)
@@ -16,8 +16,6 @@
 //! Setup the AVR pins.
 void avrsetup(){
   spisetup();
-  
-  glitchsetup();
 }
 
 //! Initialized an attached AVR.
@@ -31,9 +29,9 @@ void avrconnect(){
 
   SETSS;
   CLRCLK;
-  delay(500);
+  delay(10);
   CLRSS;
-  delay(500);
+  delay(10);
   
   //Enable programming
   avr_prgen();
@@ -70,7 +68,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 +102,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){
@@ -132,8 +135,10 @@ void avrhandle(unsigned char app,
   unsigned int at;
   static u8 connected=0;
   
+  /*
   if(!avr_isready() && connected)
     debugstr("AVR is not yet ready.");
+  */
   
   switch(verb){
   case READ:
@@ -162,7 +167,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.