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);
79 i2chandle(app,verb,len);
82 cchandle(app,verb,len);
85 jtaghandle(app,verb,len);
88 ejtaghandle(app,verb,len);
90 case JTAG430: //Also JTAG430X, JTAG430X2
91 jtag430x2handle(app,verb,len);
94 smartcardhandle(app,verb,len);
98 pluginhandle(app,verb,len);
100 debugstr("Plugin missing.");
111 volatile unsigned int i;
112 unsigned char app, verb;
114 // MSP reboot count for reset input & reboot function located at 0xFFFE
115 volatile unsigned int reset_count = 0;
116 void (*reboot_function)(void) = (void *) 0xFFFE;
120 txstring(MONITOR,OK,"http://goodfet.sf.net/");
123 //Command loop. There's no end!
128 // If the app is the reset byte (0x80) increment and loop
132 if (reset_count > 4) {
133 // We could trigger the WDT with either:
136 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
137 // but instead we'll jump to our reboot function pointer
138 (*reboot_function)();
150 //Read data, looking for buffer overflow.y
153 cmddata[i]=serial_rx();
155 handle(app,verb,len);
157 //Listen to the blaberring.
160 //Reply with an error.
161 debugstr("Buffer length exceeded.");
162 txdata(MONITOR,NOK,0);