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 avrhandle(app,verb,len);
81 #ifdef INSTALL_PIC_APP
83 pichandle(app,verb,len);
87 i2chandle(app,verb,len);
90 cchandle(app,verb,len);
93 jtaghandle(app,verb,len);
96 ejtaghandle(app,verb,len);
98 case JTAG430: //Also JTAG430X, JTAG430X2
99 //Revert this when X2 support returns.
100 //jtag430x2handle(app,verb,len);
101 jtag430handle(app,verb,len);
104 smartcardhandle(app,verb,len);
107 jtagarm7tdmihandle(app,verb,len);
111 pluginhandle(app,verb,len);
113 debugstr("Plugin missing.");
124 volatile unsigned int i;
125 unsigned char app, verb;
127 // MSP reboot count for reset input & reboot function located at 0xFFFE
128 volatile unsigned int reset_count = 0;
129 void (*reboot_function)(void) = (void *) 0xFFFE;
133 txstring(MONITOR,OK,"http://goodfet.sf.net/");
136 //Command loop. There's no end!
141 // If the app is the reset byte (0x80) increment and loop
145 if (reset_count > 4) {
146 // We could trigger the WDT with either:
149 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
150 // but instead we'll jump to our reboot function pointer
151 (*reboot_function)();
163 //Read data, looking for buffer overflow.y
166 cmddata[i]=serial_rx();
168 handle(app,verb,len);
170 //Listen to the blaberring.
173 //Reply with an error.
174 debugstr("Buffer length exceeded.");
175 txdata(MONITOR,NOK,0);