Giving up on MSP430X2 for a second, getting back to SPI.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Fri, 4 Sep 2009 08:54:10 +0000 (08:54 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Fri, 4 Sep 2009 08:54:10 +0000 (08:54 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@121 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

firmware/apps/jtag/jtag.c
firmware/apps/jtag/jtag430.c
firmware/apps/jtag/jtag430x2.c

index 5abba15..af420c7 100644 (file)
@@ -55,14 +55,19 @@ unsigned char jtagtrans8(unsigned char byte){
 unsigned long jtagtransn(unsigned long word,
                         unsigned int bitcount){
   unsigned int bit;
-  unsigned int high=(word>>16);
-  SAVETCLK;
+  //0x8000
+  unsigned long high;
   
+  if(bitcount==20)
+    high=0x80000;
+  if(bitcount==16)
+    high= 0x8000;
   
+  SAVETCLK;
   
   for (bit = 0; bit < bitcount; bit++) {
     /* write MOSI on trailing edge of previous clock */
-    if (word & 0x8000)
+    if (word & high)
       {SETMOSI;}
     else
       {CLRMOSI;}
@@ -137,7 +142,7 @@ void jtag_stop(){
 
 unsigned int drwidth=20;
 //! Shift all bits of the DR.
-unsigned long jtag_dr_shift(unsigned long in){
+unsigned long jtag_dr_shift20(unsigned long in){
   // idle
   SETTMS;
   CLRTCK;
@@ -151,14 +156,26 @@ unsigned long jtag_dr_shift(unsigned long in){
   SETTCK;
   
   // shift DR, then idle
-  return(jtagtransn(in,drwidth));
+  return(jtagtransn(in,20));
 }
 
 
 //! Shift 16 bits of the DR.
 unsigned int jtag_dr_shift16(unsigned int in){
-  //This name is deprecated, kept around to find 16-bit dependent code.
-  return jtag_dr_shift(in);
+  // idle
+  SETTMS;
+  CLRTCK;
+  SETTCK;
+  // select DR
+  CLRTMS;
+  CLRTCK;
+  SETTCK;
+  // capture IR
+  CLRTCK;
+  SETTCK;
+  
+  // shift DR, then idle
+  return(jtagtransn(in,16));
 }
 
 
index d518ca1..52601d8 100644 (file)
@@ -51,6 +51,7 @@ unsigned int jtag430_readmem(unsigned int adr){
   
   CLRTCLK;
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
+  
   if(adr>0xFF)
     jtag_dr_shift16(0x2409);//word read
   else
index e25a905..5cafafe 100644 (file)
@@ -53,11 +53,13 @@ unsigned int jtag430_coreid(){
 
 unsigned long jtag430_deviceid(){
   jtag_ir_shift8(IR_DEVICE_ID);
-  return jtag_dr_shift(0);
+  return jtag_dr_shift20(0);
 }
 
 //! Set the program counter.
 void jtag430x2_setpc(unsigned long pc){
+  //From SLAU265.
+  
   unsigned short Mova;
   unsigned short Pc_l;
 
@@ -85,15 +87,18 @@ void jtag430x2_setpc(unsigned long pc){
       jtag_dr_shift16(0x4303);
       CLRTCLK;
       jtag_ir_shift8(IR_ADDR_CAPTURE);
-      jtag_dr_shift(0x00000);
+      jtag_dr_shift20(0x00000);
+  }else{
+    while(1) P1OUT^=1; //Lock LED if locked up.
   }
 }
 
+
 //! Read data from address
 unsigned int jtag430x2_readmem(unsigned int adr){
   unsigned int toret;
   
-  //SETPC_430Xv2(StartAddr);
+  jtag430x2_setpc(adr);
   SETTCLK;
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
   jtag_dr_shift16(0x0501);
@@ -128,6 +133,7 @@ void jtag430x2handle(unsigned char app,
       drwidth=16;
     }else if(jtagid==MSP430X2JTAGID){
       jtag430mode=MSP430X2MODE;
+      drwidth=20;
     }else{
       txdata(app,NOK,1);
       return;
@@ -140,6 +146,7 @@ void jtag430x2handle(unsigned char app,
   case JTAG430_READMEM:
   case PEEK:
     cmddataword[0]=jtag430x2_readmem(cmddataword[0]);
+    //cmddataword[0]=jtag430_readmem(cmddataword[0]);
     txdata(app,verb,2);
     break;
   case JTAG430_COREIP_ID: