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 copiled in
74 debugstr("App missing.");
83 volatile unsigned int i;
84 unsigned char app, verb;
86 // MSP reboot count for reset input & reboot function located at 0xFFFE
87 volatile unsigned int reset_count = 0;
88 #if (platform == tilaunchpad)
91 //ret = setjmp(warmstart);// needs to be here since context from init() would be gone
94 coldstart(); // basic hardware setup, clock to TUSB3410, and enable
95 } else if (ret == 2) {
96 dputs("\nalmost BSL only one RTS change\n");
97 } else if (ret > 2) { // reset released after more than two tst transisitions
98 // We could write a BSL, a nice exercise for a Sunday afternoon.
100 //call_BSL(); // once you are done uncomment ;-)
101 } else { // we come here after DTR high (release reset)
102 dputs("\nWarmstart\n");
104 #elif (platform == donbfet)
105 extern void donbfet_reboot(void);
106 void (*reboot_function)(void) = donbfet_reboot;
108 void (*reboot_function)(void) = (void *) 0xFFFE;
112 txstring(MONITOR,OK,"http://goodfet.sf.net/");
113 //txstring(0xab,0xcd,"http://goodfet.sf.net/");
116 //Command loop. There's no end!
122 // If the app is the reset byte (0x80) increment and loop
129 // We could trigger the WDT with either:
132 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
133 // but instead we'll jump to our reboot function pointer
135 # if (platform == tilaunchpad)
136 // do we really need this, we do not want to reset the TUSB3410
137 dputs("reset_count>4\n");
139 //longjmp(warmstart,111);
143 (*reboot_function)();
146 # if (platform == donbfet)
147 (*reboot_function)();
149 debugstr("Rebooting not supported on this platform.");
164 //Read data, looking for buffer overflow.
165 if(len <= CMDDATALEN)
167 for(i = 0; i < len; i++)
169 cmddata[i] = serial_rx();
172 handle(app,verb,len);
176 //Listen to the blaberring.
177 for(i = 0; i < len; i++)
180 //Reply with an error.
181 debugstr("Buffer length exceeded.");
182 txdata(MONITOR,NOK,0);