Dropped ugly 'blocks' kludge for a 16-bit length field.
[goodfet] / firmware / apps / jtag / jtag430.c
index 6913626..d0b83cb 100644 (file)
@@ -113,7 +113,6 @@ void jtag430_writeflashword(unsigned int adr, unsigned int data){
   
   //Pulse TCLK
   jtag430_tclk_flashpulses(35); //35 standard
-  
 }
 
 //! Configure flash, then write a word.
@@ -276,7 +275,7 @@ void jtag430_setinstrfetch(){
 //! Handles classic MSP430 JTAG commands.  Forwards others to JTAG.
 void jtag430handle(unsigned char app,
                   unsigned char verb,
-                  unsigned char len){
+                  unsigned long len){
   register char blocks;
   unsigned long at;
   unsigned int i, val;
@@ -307,33 +306,24 @@ void jtag430handle(unsigned char app,
     
   case JTAG430_READMEM:
   case PEEK:
-    /*
-    cmddataword[0]=jtag430_readmem(cmddataword[0]);
-    txdata(app,verb,2);
-    */
-    blocks=(len>4?cmddata[4]:1);
     at=cmddatalong[0];
     
     //Fetch large blocks for bulk fetches,
     //small blocks for individual peeks.
-    if(blocks>1)
-      len=0x80;
-    
-    serial_tx(app);
-    serial_tx(verb);
-    serial_tx(len);
+    if(len>5)
+      len=(cmddataword[2]);//always even.
+    else
+      len=2;
+    len&=~1;//clue lsbit
     
-    while(blocks--){
-      for(i=0;i<len;i+=2){
-       jtag430_resettap();
-       //delay(10);
-       
-       val=jtag430_readmem(at);
-       
-       at+=2;
-       serial_tx(val&0xFF);
-       serial_tx((val&0xFF00)>>8);
-      }
+    txhead(app,verb,len);
+    for(i=0;i<len;i+=2){
+      jtag430_resettap();
+      val=jtag430_readmem(at);
+      
+      at+=2;
+      serial_tx(val&0xFF);
+      serial_tx((val&0xFF00)>>8);
     }
     break;
   case JTAG430_WRITEMEM:
@@ -346,13 +336,18 @@ void jtag430handle(unsigned char app,
   case JTAG430_WRITEFLASH:
     //debugstr("Poking flash memory.");
     jtag430_writeflash(cmddataword[0],cmddataword[2]);
+    
+    //Try again if failure.
+    if(cmddataword[0]!=jtag430_readmem(cmddataword[0]))
+      jtag430_writeflash(cmddataword[0],cmddataword[2]);
+    
+    //Return result.
     cmddataword[0]=jtag430_readmem(cmddataword[0]);
+    
     txdata(app,verb,2);
     break;
   case JTAG430_ERASEFLASH:
-    jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
-    jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
-    jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
+    jtag430_eraseflash(ERASE_MASS,0xFFFE,0x3000);
     txdata(app,verb,0);
     break;
   case JTAG430_SETPC:
@@ -371,5 +366,5 @@ void jtag430handle(unsigned char app,
   default:
     jtaghandle(app,verb,len);
   }
-  jtag430_resettap();
+  //jtag430_resettap();  //DO NOT UNCOMMENT
 }