2 \author Travis Goodspeed
5 This is the main module of the GoodFET, which calls the initialization
6 routines and delegates commands to the various applications.
16 //! Initialize registers and all that jazz.
22 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
29 /* P5.0 out and low; this is chosen for the PIC app (in which P5.0
30 is !MCLR) to ensure that an attached PIC chip, if present, is
31 immediately driven to reset state. A brief explanation of why this
34 At least dsPIC33F and PIC24H --and very likely other 16-bit PIC
35 families-- draw a large amount of current when running, especially
36 when using a fast clock: from 60 mA up to approx. 90 mA. If the
37 PIC target begins to run before the client can request a new ICSP
38 session, which requires much less current (e.g., less than 2 mA),
39 then the MSP430 chip on the GoodFET will fail to start and the FTDI
40 may have trouble communicating with the client. The latter likely
41 relates to the FTDI on-chip 3V3 regulator being specified up to
45 //P5REN &= ~BIT0; //DO NOT UNCOMMENT. Breaks GF1x support.
47 //This will have to be cut soon. Use pulling resistors instead.
53 //Setup clocks, unique to each '430.
57 //DAC should be at full voltage if it exists.
59 //glitchvoltages(0xfff,0xfff);
60 ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref on
61 for(i=0;i!=0xFFFF;i++) asm("nop");
62 DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
63 DAC12_0DAT = 0xFFF; //Max voltage 0xfff
64 DAC12_1CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
65 DAC12_1DAT = 0x000; //Min voltage 0x000
70 This part is really ugly. GSEL (P5.7) must be high to select
71 normal voltage, but a lot of applications light to swing it low
72 to be a nuissance. To get around this, we assume that anyone
73 with a glitching FET will also have a DAC, then we set that DAC
76 At some point, each target must be sanitized to show that it
77 doesn't clear P5OUT or P5DIR.
79 P5DIR|=BIT7; P5OUT=BIT7; //Normal Supply
80 //P5DIR&=~BIT7; //Glitch Supply
88 void handle(unsigned char app,
91 //debugstr("GoodFET");
95 glitchhandle(app,verb,len);
98 monitorhandle(app,verb,len);
101 spihandle(app,verb,len);
104 nrfhandle(app,verb,len);
107 ccspihandle(app,verb,len);
110 avrhandle(app,verb,len);
113 pichandle(app,verb,len);
116 adchandle(app,verb,len);
119 i2chandle(app,verb,len);
122 cchandle(app,verb,len);
125 jtaghandle(app,verb,len);
128 ejtaghandle(app,verb,len);
130 case JTAG430: //Also JTAG430X, JTAG430X2
131 //Revert this when X2 support returns.
132 jtag430x2handle(app,verb,len);
133 //jtag430handle(app,verb,len);
136 smartcardhandle(app,verb,len);
139 jtagarm7tdmihandle(app,verb,len);
143 pluginhandle(app,verb,len);
145 debugstr("Plugin missing.");
156 volatile unsigned int i;
157 unsigned char app, verb;
159 // MSP reboot count for reset input & reboot function located at 0xFFFE
160 volatile unsigned int reset_count = 0;
161 void (*reboot_function)(void) = (void *) 0xFFFE;
165 txstring(MONITOR,OK,"http://goodfet.sf.net/");
168 //Command loop. There's no end!
173 // If the app is the reset byte (0x80) increment and loop
177 if (reset_count > 4) {
178 // We could trigger the WDT with either:
181 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
182 // but instead we'll jump to our reboot function pointer
183 (*reboot_function)();
195 //Read data, looking for buffer overflow.y
198 cmddata[i]=serial_rx();
200 handle(app,verb,len);
202 //Listen to the blaberring.
205 //Reply with an error.
206 debugstr("Buffer length exceeded.");
207 txdata(MONITOR,NOK,0);