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
28 //Setup clocks, unique to each '430.
32 //DAC should be at full voltage if it exists.
34 //glitchvoltages(0xfff,0xfff);
35 ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref on
36 for(i=0;i!=0xFFFF;i++) asm("nop");
37 DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
38 DAC12_0DAT = 0xFFF; //Max voltage 0xfff
39 DAC12_1CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
40 DAC12_1DAT = 0x000; //Min voltage 0x000
45 This part is really ugly. GSEL (P5.7) must be high to select
46 normal voltage, but a lot of applications light to swing it low
47 to be a nuissance. To get around this, we assume that anyone
48 with a glitching FET will also have a DAC, then we set that DAC
51 At some point, each target must be sanitized to show that it
52 doesn't clear P5OUT or P5DIR.
54 P5DIR|=BIT7; P5OUT=BIT7; //Normal Supply
55 //P5DIR&=~BIT7; //Glitch Supply
63 void handle(unsigned char app,
66 //debugstr("GoodFET");
70 glitchhandle(app,verb,len);
73 monitorhandle(app,verb,len);
76 spihandle(app,verb,len);
79 nrfhandle(app,verb,len);
82 avrhandle(app,verb,len);
85 pichandle(app,verb,len);
89 i2chandle(app,verb,len);
92 cchandle(app,verb,len);
95 jtaghandle(app,verb,len);
98 ejtaghandle(app,verb,len);
100 case JTAG430: //Also JTAG430X, JTAG430X2
101 //Revert this when X2 support returns.
102 jtag430x2handle(app,verb,len);
103 //jtag430handle(app,verb,len);
106 smartcardhandle(app,verb,len);
109 jtagarm7tdmihandle(app,verb,len);
113 pluginhandle(app,verb,len);
115 debugstr("Plugin missing.");
126 volatile unsigned int i;
127 unsigned char app, verb;
129 // MSP reboot count for reset input & reboot function located at 0xFFFE
130 volatile unsigned int reset_count = 0;
131 void (*reboot_function)(void) = (void *) 0xFFFE;
135 txstring(MONITOR,OK,"http://goodfet.sf.net/");
138 //Command loop. There's no end!
143 // If the app is the reset byte (0x80) increment and loop
147 if (reset_count > 4) {
148 // We could trigger the WDT with either:
151 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
152 // but instead we'll jump to our reboot function pointer
153 (*reboot_function)();
165 //Read data, looking for buffer overflow.y
168 cmddata[i]=serial_rx();
170 handle(app,verb,len);
172 //Listen to the blaberring.
175 //Reply with an error.
176 debugstr("Buffer length exceeded.");
177 txdata(MONITOR,NOK,0);