Reliability patch to Chipcon.
[goodfet] / firmware / apps / chipcon / chipcon.c
index d4e8177..28440c4 100644 (file)
@@ -1,17 +1,16 @@
-//GoodFET ChipCon Debugging Application
-//Handles basic I/O for the Chipcon 8051 debugging protocol.
+/*! \file chipcon.c
+  \author Travis Goodspeed
+  \brief Chipcon 8051 debugging.
+*/
 
 
-//Higher level left to client application.
 
 //This is like SPI, except that you read or write, not both.
 
 
 //This is like SPI, except that you read or write, not both.
 
-/** N.B. The READ verb performs a write of all (any) supplied data,
+/* N.B. The READ verb performs a write of all (any) supplied data,
     then reads a single byte reply from the target.  The WRITE verb
     only writes.
 */
 
     then reads a single byte reply from the target.  The WRITE verb
     only writes.
 */
 
-//This is REALLY untested.
-
 #include "platform.h"
 #include "command.h"
 #include "chipcon.h"
 #include "platform.h"
 #include "command.h"
 #include "chipcon.h"
@@ -21,7 +20,7 @@
 #include <iomacros.h>
 
 
 #include <iomacros.h>
 
 
-/** Concerning clock rates,
+/* Concerning clock rates,
     the maximimum clock rates are defined on page 4 of the spec.
     They vary, but are roughly 30MHz.  Raising this clock rate might
     allow for clock glitching, but the GoodFET isn't sufficient fast for that.
     the maximimum clock rates are defined on page 4 of the spec.
     They vary, but are roughly 30MHz.  Raising this clock rate might
     allow for clock glitching, but the GoodFET isn't sufficient fast for that.
@@ -37,7 +36,7 @@
 
 //This could be more accurate.
 //Does it ever need to be?
 
 //This could be more accurate.
 //Does it ever need to be?
-#define CCSPEED 0
+#define CCSPEED 3
 #define CCDELAY(x) delay(x)
 
 #define SETMOSI P5OUT|=MOSI
 #define CCDELAY(x) delay(x)
 
 #define SETMOSI P5OUT|=MOSI
@@ -125,7 +124,10 @@ void ccread(unsigned char len){
 //! Handles a monitor command.
 void cchandle(unsigned char app,
               unsigned char verb,
 //! Handles a monitor command.
 void cchandle(unsigned char app,
               unsigned char verb,
-              unsigned char len){
+              unsigned long len){
+  //Always init.  Might help with buggy lines.
+  ccdebuginit();
+  
   switch(verb){
     //CC_PEEK and CC_POKE will come later.
   case READ:  //Write a command and return 1-byte reply.
   switch(verb){
     //CC_PEEK and CC_POKE will come later.
   case READ:  //Write a command and return 1-byte reply.
@@ -217,7 +219,6 @@ void cchandle(unsigned char app,
     txdata(app,verb,1);
     break;
   case CC_SET_PC:
     txdata(app,verb,1);
     break;
   case CC_SET_PC:
-    
   case CC_CLOCK_INIT:
   case CC_WRITE_FLASH_PAGE:
   case CC_MASS_ERASE_FLASH:
   case CC_CLOCK_INIT:
   case CC_WRITE_FLASH_PAGE:
   case CC_MASS_ERASE_FLASH:
@@ -333,6 +334,11 @@ unsigned char cc_debug(unsigned char len,
              unsigned char c){
   unsigned char cmd=0x54+(len&0x3);//(len&0x3);
   CCWRITE;
              unsigned char c){
   unsigned char cmd=0x54+(len&0x3);//(len&0x3);
   CCWRITE;
+  cctrans8(0xFF);//resync
+  cctrans8(0xFF);//resync
+  cctrans8(0xFF);//resync
+  cctrans8(0xFF);//resync
+  cctrans8(0xFF);//resync
   cctrans8(cmd);
   if(len--)
     cctrans8(a);
   cctrans8(cmd);
   if(len--)
     cctrans8(a);
@@ -362,7 +368,7 @@ unsigned char cc_peekcodebyte(unsigned long adr){
   //CLR A
   cc_debug(2, 0xE4, 0, 0);
   //MOVC A, @A+DPTR;
   //CLR A
   cc_debug(2, 0xE4, 0, 0);
   //MOVC A, @A+DPTR;
-  toret=cc_debug(1, 0x93, 0, 0);
+  toret=cc_debug(3, 0x93, 0, 0);
   //INC DPTR
   //cc_debug(1, 0xA3, 0, 0);
   
   //INC DPTR
   //cc_debug(1, 0xA3, 0, 0);