0de9a448acc2a5483d24fd7e9dfeffe9cdcff0a9
[goodfet] / firmware / apps / jtag / jtag430x2.c
1 /*! \file jtag430x2.c
2   \author Travis Goodspeed <travis at radiantmachines.com>
3   
4   This is an implementation of the MSP430X2 JTAG protocol
5   for the GoodFET project at http://goodfet.sf.net/
6   
7   See the license file for details of proper use.
8 */
9
10 #include "platform.h"
11 #include "command.h"
12 #include "jtag.h"
13
14 unsigned char jtagid;
15
16 //! Get the JTAG ID
17 unsigned char jtag430x2_jtagid(){
18   jtag430_resettap();
19   return jtagid=jtag_ir_shift8(IR_BYPASS);
20 }
21 //! Start JTAG, take pins
22 unsigned char jtag430x2_start(){
23   jtagsetup();
24   P1OUT^=1;
25   
26   //Known-good starting position.
27   //Might be unnecessary.
28   SETTST;
29   SETRST;
30   
31   delay(0xFFFF);
32   
33   //Entry sequence from Page 67 of SLAU265A for 4-wire MSP430 JTAG
34   CLRRST;
35   delay(10);
36   CLRTST;
37   delay(5);
38   SETTST;
39   msdelay(5);
40   SETRST;
41   P5DIR&=~RST;
42   
43   delay(0xFFFF);
44   
45   //Perform a reset and disable watchdog.
46   return jtag430x2_jtagid();
47 }
48
49
50 //! Handles classic MSP430 JTAG commands.  Forwards others to JTAG.
51 void jtag430x2handle(unsigned char app,
52                    unsigned char verb,
53                    unsigned char len){
54   
55   switch(verb){
56   case START:
57     //Enter JTAG mode.
58     do cmddata[0]=jtag430x2_start();
59     while(cmddata[0]==00 || cmddata[0]==0xFF);
60     
61     //TAP setup, fuse check
62     //jtag430_resettap();
63     txdata(app,verb,1);
64     break;
65   case JTAG430_HALTCPU:
66   case JTAG430_RELEASECPU:
67   case JTAG430_SETINSTRFETCH:
68   case JTAG430_READMEM:
69   case PEEK:
70   case JTAG430_WRITEMEM:
71   case POKE:
72   case JTAG430_WRITEFLASH:
73   case JTAG430_ERASEFLASH:
74   case JTAG430_SETPC:
75   default:
76     jtaghandle(app,verb,len);
77   }
78   jtag430_resettap();
79 }