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
\r
38 //Enable Interrupts.
\r
43 //! Handle a command.
\r
44 void handle(unsigned char app,
\r
47 //debugstr("GoodFET");
\r
51 glitchhandle(app,verb,len);
\r
54 monitorhandle(app,verb,len);
\r
57 spihandle(app,verb,len);
\r
60 avrhandle(app,verb,len);
\r
63 i2chandle(app,verb,len);
\r
66 cchandle(app,verb,len);
\r
69 jtaghandle(app,verb,len);
\r
72 ejtaghandle(app,verb,len);
\r
74 case JTAG430: //Also JTAG430X, JTAG430X2
\r
75 jtag430x2handle(app,verb,len);
\r
79 pluginhandle(app,verb,len);
\r
81 debugstr("Plugin missing.");
\r
92 volatile unsigned int i;
\r
93 unsigned char app, verb;
\r
95 // MSP reboot count for reset input & reboot function located at 0xFFFE
\r
96 volatile unsigned int reset_count = 0;
\r
97 void (*reboot_function)(void) = (void *) 0xFFFE;
\r
101 txstring(MONITOR,OK,"http://goodfet.sf.net/");
\r
104 //Command loop. There's no end!
\r
109 // If the app is the reset byte (0x80) increment and loop
\r
113 if (reset_count > 4) {
\r
114 // We could trigger the WDT with either:
\r
117 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
\r
118 // but instead we'll jump to our reboot function pointer
\r
119 (*reboot_function)();
\r
131 //Read data, looking for buffer overflow.y
\r
132 if(len<=CMDDATALEN){
\r
133 for(i=0;i<len;i++){
\r
134 cmddata[i]=serial_rx();
\r
136 handle(app,verb,len);
\r
138 //Listen to the blaberring.
\r
141 //Reply with an error.
\r
142 debugstr("Buffer length exceeded.");
\r
143 txdata(MONITOR,NOK,0);
\r