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
21 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
\r
25 PLEDOUT &= ~PLEDPIN;
\r
27 //Setup clocks, unique to each '430.
\r
31 //DAC should be at full voltage if it exists.
\r
33 glitchvoltages(0xfff,0xfff);
\r
36 //Enable Interrupts.
\r
41 //! Handle a command.
\r
42 void handle(unsigned char app,
\r
45 //debugstr("GoodFET");
\r
49 glitchhandle(app,verb,len);
\r
52 monitorhandle(app,verb,len);
\r
55 spihandle(app,verb,len);
\r
58 avrhandle(app,verb,len);
\r
61 i2chandle(app,verb,len);
\r
64 cchandle(app,verb,len);
\r
67 jtaghandle(app,verb,len);
\r
70 ejtaghandle(app,verb,len);
\r
72 case JTAG430: //Also JTAG430X, JTAG430X2
\r
73 jtag430x2handle(app,verb,len);
\r
77 pluginhandle(app,verb,len);
\r
79 debugstr("Plugin missing.");
\r
90 volatile unsigned int i;
\r
91 unsigned char app, verb;
\r
93 // MSP reboot count for reset input & reboot function located at 0xFFFE
\r
94 volatile unsigned int reset_count = 0;
\r
95 void (*reboot_function)(void) = (void *) 0xFFFE;
\r
99 txstring(MONITOR,OK,"http://goodfet.sf.net/");
\r
102 //Command loop. There's no end!
\r
107 // If the app is the reset byte (0x80) increment and loop
\r
111 if (reset_count > 4) {
\r
112 // We could trigger the WDT with either:
\r
115 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
\r
116 // but instead we'll jump to our reboot function pointer
\r
117 (*reboot_function)();
\r
129 //Read data, looking for buffer overflow.y
\r
130 if(len<=CMDDATALEN){
\r
131 for(i=0;i<len;i++){
\r
132 cmddata[i]=serial_rx();
\r
134 handle(app,verb,len);
\r
136 //Listen to the blaberring.
\r
139 //Reply with an error.
\r
140 debugstr("Buffer length exceeded.");
\r
141 txdata(MONITOR,NOK,0);
\r