A major refactor of the GoodFET firmware build system and apps to give better
[goodfet] / firmware / apps / jtag / jtag430.c
index 5a8da9a..9a33a72 100644 (file)
@@ -5,8 +5,29 @@
 
 #include "platform.h"
 #include "command.h"
-#include "jtag.h"
+#include "jtag430.h"
 
+//! Handles classic MSP430 JTAG commands.  Forwards others to JTAG.
+void jtag430_handle_fn(uint8_t const app,
+                                          uint8_t const verb,
+                                          uint32_t const len);
+
+// define the jtag430 app's app_t
+app_t const jtag430_app = {
+
+       /* app number */
+       JTAG430,
+
+       /* handle fn */
+       jtag430_handle_fn,
+
+       /* name */
+       "JTAG430",
+
+       /* desc */
+       "\tThe JTAG430 app adds to the basic JTAG app\n"
+       "\tsupport for JTAG'ing MSP430 devices.\n"
+};
 
 unsigned int jtag430mode=MSP430X2MODE;
 
@@ -51,7 +72,7 @@ void jtag430_haltcpu(){
 //! Release the CPU
 void jtag430_releasecpu(){
   CLRTCLK;
-  debugstr("Releasing target MSP430.");
+  //debugstr("Releasing target MSP430.");
   
   /*
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
@@ -313,14 +334,13 @@ void jtag430_setinstrfetch(){
 
 
 //! Handles classic MSP430 JTAG commands.  Forwards others to JTAG.
-void jtag430handle(unsigned char app,
-                  unsigned char verb,
-                  unsigned long len){
-  unsigned long at;
+void jtag430_handle_fn(uint8_t const app,
+                                          uint8_t const verb,
+                                          uint32_t const len)
+{
+  unsigned long at, l;
   unsigned int i, val;
   
-  //debugstr("Classic MSP430 handler.");
-  
   
   /* FIXME
    * Sometimes JTAG doesn't init correctly.
@@ -331,9 +351,9 @@ void jtag430handle(unsigned char app,
   while((i=jtag430_readmem(0xff0))==0xFFFF){
     debugstr("Reconnecting to target MSP430.");
     jtag430_start();
-    P1OUT^=1;
+    PLEDOUT^=PLEDPIN;
   }
-  P1OUT&=~1;
+  PLEDOUT&=~PLEDPIN;
   
   
   switch(verb){
@@ -371,13 +391,13 @@ void jtag430handle(unsigned char app,
     //Fetch large blocks for bulk fetches,
     //small blocks for individual peeks.
     if(len>5)
-      len=(cmddataword[2]);//always even.
+      l=(cmddataword[2]);//always even.
     else
-      len=2;
-    len&=~1;//clear lsbit
+      l=2;
+    l&=~1;//clear lsbit
     
-    txhead(app,verb,len);
-    for(i=0;i<len;i+=2){
+    txhead(app,verb,l);
+    for(i = 0; i < l; i += 2) {
       jtag430_resettap();
       val=jtag430_readmem(at);
       
@@ -434,8 +454,8 @@ void jtag430handle(unsigned char app,
     break;
   case JTAG430_SETPC:
     jtag430_haltcpu();
-    debughex("Setting PC.");
-    debughex(cmddataword[0]);
+    //debughex("Setting PC.");
+    //debughex(cmddataword[0]);
     jtag430_setpc(cmddataword[0]);
     jtag430_releasecpu();
     txdata(app,verb,0);
@@ -458,7 +478,7 @@ void jtag430handle(unsigned char app,
     break;
     
   default:
-    jtaghandle(app,verb,len);
+    (*(jtag_app.handle))(app,verb,len);
   }
   //jtag430_resettap();  //DO NOT UNCOMMENT
 }