2 \author Travis Goodspeed
\r
5 This is the main module of the GoodFET, which calls the initialization
\r
6 routines and delegates commands to the various applications.
\r
10 #include "platform.h"
\r
11 #include "command.h"
\r
16 //! Initialize registers and all that jazz.
\r
19 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
\r
23 PLEDOUT &= ~PLEDPIN;
\r
25 //Setup clocks, unique to each '430.
\r
29 //DAC should be at full voltage if it exists.
\r
31 //glitchvoltages(0xfff,0xfff);
\r
32 ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref on
\r
33 for(i=0;i!=0xFFFF;i++) asm("nop");
\r
34 DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
\r
35 DAC12_0DAT = 0xFFF; //Max voltage 0xfff
\r
36 DAC12_1CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
\r
37 DAC12_1DAT = 0x000; //Min voltage 0x000
\r
42 This part is really ugly. GSEL (P5.7) must be high to select
\r
43 normal voltage, but a lot of applications light to swing it low
\r
44 to be a nuissance. To get around this, we assume that anyone
\r
45 with a glitching FET will also have a DAC, then we set that DAC
\r
48 At some point, each target must be sanitized to show that it
\r
49 doesn't clear P5OUT or P5DIR.
\r
51 P5DIR|=BIT7; P5OUT=BIT7; //Normal Supply
\r
52 P5DIR&=~BIT7; //Glitch Supply
\r
54 //Enable Interrupts.
\r
59 //! Handle a command.
\r
60 void handle(unsigned char app,
\r
63 //debugstr("GoodFET");
\r
67 glitchhandle(app,verb,len);
\r
70 monitorhandle(app,verb,len);
\r
73 spihandle(app,verb,len);
\r
76 avrhandle(app,verb,len);
\r
79 i2chandle(app,verb,len);
\r
82 cchandle(app,verb,len);
\r
85 jtaghandle(app,verb,len);
\r
88 ejtaghandle(app,verb,len);
\r
90 case JTAG430: //Also JTAG430X, JTAG430X2
\r
91 jtag430x2handle(app,verb,len);
\r
95 pluginhandle(app,verb,len);
\r
97 debugstr("Plugin missing.");
\r
108 volatile unsigned int i;
\r
109 unsigned char app, verb;
\r
111 // MSP reboot count for reset input & reboot function located at 0xFFFE
\r
112 volatile unsigned int reset_count = 0;
\r
113 void (*reboot_function)(void) = (void *) 0xFFFE;
\r
117 txstring(MONITOR,OK,"http://goodfet.sf.net/");
\r
120 //Command loop. There's no end!
\r
125 // If the app is the reset byte (0x80) increment and loop
\r
129 if (reset_count > 4) {
\r
130 // We could trigger the WDT with either:
\r
133 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
\r
134 // but instead we'll jump to our reboot function pointer
\r
135 (*reboot_function)();
\r
147 //Read data, looking for buffer overflow.y
\r
148 if(len<=CMDDATALEN){
\r
149 for(i=0;i<len;i++){
\r
150 cmddata[i]=serial_rx();
\r
152 handle(app,verb,len);
\r
154 //Listen to the blaberring.
\r
157 //Reply with an error.
\r
158 debugstr("Buffer length exceeded.");
\r
159 txdata(MONITOR,NOK,0);
\r