GLITCH application is coming together.
[goodfet] / firmware / goodfet.c
1 /*! \file goodfet.c\r
2   \author Travis Goodspeed\r
3   \brief Main module.\r
4   \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
7 */\r
8 \r
9 \r
10 #include "platform.h"\r
11 #include "command.h"\r
12 #include "apps.h"\r
13 #include "glitch.h"\r
14 \r
15 \r
16 //LED on P1.0\r
17 //IO on P5\r
18 \r
19 //! Initialize registers and all that jazz.\r
20 void init(){\r
21   WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer\r
22   \r
23   //LED out and on.\r
24   PLEDDIR |= PLEDPIN;\r
25   PLEDOUT &= ~PLEDPIN;\r
26   \r
27   //Setup clocks, unique to each '430.\r
28   msp430_init_dco();\r
29   msp430_init_uart();\r
30   \r
31   //Enable Interrupts.\r
32   //eint();\r
33 }\r
34 \r
35 \r
36 //! Handle a command.\r
37 void handle(unsigned char app,\r
38             unsigned char verb,\r
39             unsigned long len){\r
40   //debugstr("GoodFET");\r
41   switch(app){\r
42   case GLITCH:\r
43     glitchhandle(app,verb,len);\r
44     break;\r
45   case MONITOR:\r
46     monitorhandle(app,verb,len);\r
47     break;\r
48   case SPI:\r
49     spihandle(app,verb,len);\r
50     break;\r
51   case AVR:\r
52     avrhandle(app,verb,len);\r
53     break;\r
54   case I2CAPP:\r
55     i2chandle(app,verb,len);\r
56     break;\r
57   case CHIPCON:\r
58     cchandle(app,verb,len);\r
59     break;\r
60   case JTAG:\r
61     jtaghandle(app,verb,len);\r
62     break;\r
63   case JTAG430: //Also JTAG430X, JTAG430X2\r
64     jtag430x2handle(app,verb,len);\r
65     break;\r
66   default:\r
67     if(pluginhandle){\r
68       pluginhandle(app,verb,len);\r
69     }else{\r
70       debugstr("Plugin missing.");\r
71       txdata(app,NOK,0);\r
72     }\r
73       \r
74     break;\r
75   }\r
76 }\r
77 \r
78 //! Main loop.\r
79 int main(void)\r
80 {\r
81   volatile unsigned int i;\r
82   unsigned char app, verb;\r
83   unsigned long len;\r
84   \r
85   init();\r
86   glitchsetup();\r
87   \r
88   txstring(MONITOR,OK,"http://goodfet.sf.net/");\r
89   \r
90   \r
91   //Command loop.  There's no end!\r
92   while(1){\r
93     //Magic 3\r
94     app=serial_rx();\r
95     verb=serial_rx();\r
96     //len=serial_rx();\r
97     len=rxword();\r
98     \r
99     //Read data, looking for buffer overflow.y\r
100     if(len<=CMDDATALEN){\r
101       for(i=0;i<len;i++){\r
102         cmddata[i]=serial_rx();\r
103       }\r
104       handle(app,verb,len);\r
105     }else{\r
106       //Listen to the blaberring.\r
107       for(i-0;i<len;i++)\r
108         serial_rx();\r
109       //Reply with an error.\r
110       debugstr("Buffer length exceeded.");\r
111       txdata(MONITOR,NOK,0);\r
112     }\r
113   }\r
114 }\r
115 \r