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.
15 #define RESET 0x80 // not a real app -- causes firmware to reset
18 //! Initialize registers and all that jazz.
21 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
28 /* P5.0 out and low; this is chosen for the PIC app (in which P5.0
29 is !MCLR) to ensure that an attached PIC chip, if present, is
30 immediately driven to reset state. A brief explanation of why this
33 At least dsPIC33F and PIC24H --and very likely other 16-bit PIC
34 families-- draw a large amount of current when running, especially
35 when using a fast clock: from 60 mA up to approx. 90 mA. If the
36 PIC target begins to run before the client can request a new ICSP
37 session, which requires much less current (e.g., less than 2 mA),
38 then the MSP430 chip on the GoodFET will fail to start and the FTDI
39 may have trouble communicating with the client. The latter likely
40 relates to the FTDI on-chip 3V3 regulator being specified up to
44 //P5REN &= ~BIT0; //DO NOT UNCOMMENT. Breaks GF1x support.
46 //This will have to be cut soon. Use pulling resistors instead.
52 //Setup clocks, unique to each '430.
56 //DAC should be at full voltage if it exists.
58 //glitchvoltages(0xfff,0xfff);
59 ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref on
60 //for(i=0;i!=0xFFFF;i++) asm("nop"); //DO NOT UNCOMMENT, breaks GCC4
61 DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
62 DAC12_0DAT = 0xFFF; //Max voltage 0xfff
63 DAC12_1CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
64 DAC12_1DAT = 0x000; //Min voltage 0x000
69 This part is really ugly. GSEL (P5.7) must be high to select
70 normal voltage, but a lot of applications light to swing it low
71 to be a nuissance. To get around this, we assume that anyone
72 with a glitching FET will also have a DAC, then we set that DAC
75 At some point, each target must be sanitized to show that it
76 doesn't clear P5OUT or P5DIR.
78 P5DIR|=BIT7; P5OUT=BIT7; //Normal Supply
79 //P5DIR&=~BIT7; //Glitch Supply
91 void handle(uint8_t const app,
97 //debugstr("GoodFET");
100 // find the app and call the handle fn
101 for(i = 0; i < num_apps; i++)
103 if(apps[i]->app == app)
105 // call the app's handle fn
106 (*(apps[i]->handle))(app, verb, len);
113 // if we get here, then the desired app is not copiled in
115 debugstr("App 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/");
135 //Command loop. There's no end!
141 // If the app is the reset byte (0x80) increment and loop
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)();
167 //Read data, looking for buffer overflow.y
168 if(len <= CMDDATALEN)
170 for(i = 0; i < len; i++)
172 cmddata[i] = serial_rx();
175 handle(app,verb,len);
179 //Listen to the blaberring.
180 for(i = 0; i < len; i++)
183 //Reply with an error.
184 debugstr("Buffer length exceeded.");
185 txdata(MONITOR,NOK,0);