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.
19 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
25 //Setup clocks, unique to each '430.
29 //DAC should be at full voltage if it exists.
31 //glitchvoltages(0xfff,0xfff);
32 ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref on
33 for(i=0;i!=0xFFFF;i++) asm("nop");
34 DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
35 DAC12_0DAT = 0xFFF; //Max voltage 0xfff
36 DAC12_1CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
37 DAC12_1DAT = 0x000; //Min voltage 0x000
42 This part is really ugly. GSEL (P5.7) must be high to select
43 normal voltage, but a lot of applications light to swing it low
44 to be a nuissance. To get around this, we assume that anyone
45 with a glitching FET will also have a DAC, then we set that DAC
48 At some point, each target must be sanitized to show that it
49 doesn't clear P5OUT or P5DIR.
51 P5DIR|=BIT7; P5OUT=BIT7; //Normal Supply
52 //P5DIR&=~BIT7; //Glitch Supply
60 void handle(unsigned char app,
63 //debugstr("GoodFET");
67 glitchhandle(app,verb,len);
70 monitorhandle(app,verb,len);
73 spihandle(app,verb,len);
76 avrhandle(app,verb,len);
78 #ifdef INSTALL_PIC_APP
80 pichandle(app,verb,len);
84 i2chandle(app,verb,len);
87 cchandle(app,verb,len);
90 jtaghandle(app,verb,len);
93 ejtaghandle(app,verb,len);
95 case JTAG430: //Also JTAG430X, JTAG430X2
96 jtag430x2handle(app,verb,len);
99 smartcardhandle(app,verb,len);
102 jtagarm7tdmihandle(app,verb,len);
106 pluginhandle(app,verb,len);
108 debugstr("Plugin missing.");
119 volatile unsigned int i;
120 unsigned char app, verb;
122 // MSP reboot count for reset input & reboot function located at 0xFFFE
123 volatile unsigned int reset_count = 0;
124 void (*reboot_function)(void) = (void *) 0xFFFE;
128 txstring(MONITOR,OK,"http://goodfet.sf.net/");
131 //Command loop. There's no end!
136 // If the app is the reset byte (0x80) increment and loop
140 if (reset_count > 4) {
141 // We could trigger the WDT with either:
144 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
145 // but instead we'll jump to our reboot function pointer
146 (*reboot_function)();
158 //Read data, looking for buffer overflow.y
161 cmddata[i]=serial_rx();
163 handle(app,verb,len);
165 //Listen to the blaberring.
168 //Reply with an error.
169 debugstr("Buffer length exceeded.");
170 txdata(MONITOR,NOK,0);