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 #if (platform == tilaunchpad)
19 #include "msp430_serial.h"
22 #define RESET 0x80 // not a real app -- causes firmware to reset
25 //! General init function, calls platform-specific one.
28 #define INITCHIP msp430_init();
32 #define INITCHIP arduino_init();
35 #if (platform == donbfet)
36 # define INITCHIP donbfet_init();
42 #warning "No init() routine for this platform!"
53 void handle(uint8_t const app,
58 //debugstr("GoodFET");
61 // find the app and call the handle fn
62 for(i = 0; i < num_apps; i++){
63 if(apps[i]->app == app){
64 // call the app's handle fn
65 (*(apps[i]->handle))(app, verb, len);
72 // if we get here, then the desired app is not compiled into
74 debugstr("App missing.");
82 volatile unsigned int i;
83 unsigned char app, verb;
85 // MSP reboot count for reset input & reboot function located at 0xFFFE
86 volatile unsigned int reset_count = 0;
88 silent=0; //Don't trust globals.
90 #if (platform == tilaunchpad)
93 //ret = setjmp(warmstart);// needs to be here since context from init() would be gone
96 coldstart(); // basic hardware setup, clock to TUSB3410, and enable
97 } else if (ret == 2) {
98 dputs("\nalmost BSL only one RTS change\n");
99 } else if (ret > 2) { // reset released after more than two tst transisitions
100 // We could write a BSL, a nice exercise for a Sunday afternoon.
102 //call_BSL(); // once you are done uncomment ;-)
103 } else { // we come here after DTR high (release reset)
104 dputs("\nWarmstart\n");
108 #if (platform == donbfet)
109 extern void donbfet_reboot(void);
110 void (*reboot_function)(void) = donbfet_reboot;
112 void (*reboot_function)(void) = (void *) 0xFFFE;
117 txstring(MONITOR,OK,"http://goodfet.sf.net/");
118 //txstring(0xab,0xcd,"http://goodfet.sf.net/");
121 //Command loop. There's no end!
126 // If the app is the reset byte (0x80) increment and loop
130 if (reset_count > 4){
131 // We could trigger the WDT with either:
134 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
135 // but instead we'll jump to our reboot function pointer
136 (*reboot_function)();
137 debugstr("Rebooting not supported on this platform.");
148 //Read data, looking for buffer overflow.
149 if(len <= CMDDATALEN){
150 for(i = 0; i < len; i++)
151 cmddata[i] = serial_rx();
153 handle(app,verb,len);
155 //Listen to the blaberring.
156 for(i = 0; i < len; i++)
159 //Reply with an error.
160 debugstr("Buffer length exceeded.");
161 txdata(MONITOR,NOK,0);