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;
87 #if (platform == tilaunchpad)
90 //ret = setjmp(warmstart);// needs to be here since context from init() would be gone
93 coldstart(); // basic hardware setup, clock to TUSB3410, and enable
94 } else if (ret == 2) {
95 dputs("\nalmost BSL only one RTS change\n");
96 } else if (ret > 2) { // reset released after more than two tst transisitions
97 // We could write a BSL, a nice exercise for a Sunday afternoon.
99 //call_BSL(); // once you are done uncomment ;-)
100 } else { // we come here after DTR high (release reset)
101 dputs("\nWarmstart\n");
105 #if (platform == donbfet)
106 extern void donbfet_reboot(void);
107 void (*reboot_function)(void) = donbfet_reboot;
109 void (*reboot_function)(void) = (void *) 0xFFFE;
113 txstring(MONITOR,OK,"http://goodfet.sf.net/");
114 //txstring(0xab,0xcd,"http://goodfet.sf.net/");
117 //Command loop. There's no end!
122 // If the app is the reset byte (0x80) increment and loop
126 if (reset_count > 4){
127 // We could trigger the WDT with either:
130 // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
131 // but instead we'll jump to our reboot function pointer
132 (*reboot_function)();
133 debugstr("Rebooting not supported on this platform.");
144 //Read data, looking for buffer overflow.
145 if(len <= CMDDATALEN){
146 for(i = 0; i < len; i++)
148 cmddata[i] = serial_rx();
151 handle(app,verb,len);
153 //Listen to the blaberring.
154 for(i = 0; i < len; i++)
157 //Reply with an error.
158 debugstr("Buffer length exceeded.");
159 txdata(MONITOR,NOK,0);