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
19 //! Initialize registers and all that jazz.
\r
22 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
\r
26 PLEDOUT &= ~PLEDPIN;
\r
28 //Setup clocks, unique to each '430.
\r
32 //DAC should be at full voltage if it exists.
\r
34 //glitchvoltages(0xfff,0xfff);
\r
35 ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref on
\r
36 for(i=0;i!=0xFFFF;i++) asm("nop");
\r
37 DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
\r
38 DAC12_0DAT = 0xFFF; //Max voltage
\r
41 //Enable Interrupts.
\r
46 //! Handle a command.
\r
47 void handle(unsigned char app,
\r
50 //debugstr("GoodFET");
\r
54 glitchhandle(app,verb,len);
\r
57 monitorhandle(app,verb,len);
\r
60 spihandle(app,verb,len);
\r
63 avrhandle(app,verb,len);
\r
66 i2chandle(app,verb,len);
\r
69 cchandle(app,verb,len);
\r
72 jtaghandle(app,verb,len);
\r
75 ejtaghandle(app,verb,len);
\r
77 case JTAG430: //Also JTAG430X, JTAG430X2
\r
78 jtag430x2handle(app,verb,len);
\r
82 pluginhandle(app,verb,len);
\r
84 debugstr("Plugin missing.");
\r
95 volatile unsigned int i;
\r
96 unsigned char app, verb;
\r
98 // MSP reboot count for reset input & reboot function located at 0xFFFE
\r
99 volatile unsigned int reset_count = 0;
\r
100 void (*reboot_function)(void) = (void *) 0xFFFE;
\r
104 txstring(MONITOR,OK,"http://goodfet.sf.net/");
\r
107 //Command loop. There's no end!
\r
112 // If the app is the reset byte (0x80) increment and loop
\r
116 if (reset_count > 4) {
\r
117 // We could trigger the WDT with either:
\r
120 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
\r
121 // but instead we'll jump to our reboot function pointer
\r
122 (*reboot_function)();
\r
134 //Read data, looking for buffer overflow.y
\r
135 if(len<=CMDDATALEN){
\r
136 for(i=0;i<len;i++){
\r
137 cmddata[i]=serial_rx();
\r
139 handle(app,verb,len);
\r
141 //Listen to the blaberring.
\r
144 //Reply with an error.
\r
145 debugstr("Buffer length exceeded.");
\r
146 txdata(MONITOR,NOK,0);
\r