19feb6393914e7a0ae4622ee75ebfccb493084c8
[goodfet] / firmware / apps / goodfet.c
1 //GOODFET Main File\r
2 //Includes several applications.\r
3 \r
4 #include "platform.h"\r
5 #include "command.h"\r
6 #include "apps.h"\r
7 \r
8 #include <signal.h>\r
9 #include <io.h>\r
10 #include <iomacros.h>\r
11 \r
12 \r
13 //LED on P1.0\r
14 //IO on P5\r
15 \r
16 //! Initialize registers and all that jazz.\r
17 void init(){\r
18   volatile unsigned int i;\r
19   WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer\r
20   \r
21   //LED and TX OUT\r
22   PLEDDIR |= PLEDPIN;\r
23   \r
24   msp430_init_dco();\r
25   msp430_init_uart();\r
26   \r
27   //Enable Interrupts.\r
28   //eint();\r
29 }\r
30 \r
31 //! Handle a command.\r
32 void handle(unsigned char app,\r
33             unsigned char verb,\r
34             unsigned char len){\r
35   switch(app){\r
36   case MONITOR:\r
37     monitorhandle(app,verb,len);\r
38     break;\r
39   case SPI:\r
40     spihandle(app,verb,len);\r
41     break;\r
42   case I2C:\r
43     i2chandle(app,verb,len);\r
44     break;\r
45   case CHIPCON:\r
46     cchandle(app,verb,len);\r
47     break;\r
48   case JTAG:\r
49     jtaghandle(app,verb,len);\r
50     break;\r
51   default:\r
52     txdata(app,NOK,0);\r
53     break;\r
54   }\r
55 }\r
56 \r
57 //! Main loop.\r
58 int main(void)\r
59 {\r
60   volatile unsigned int i;\r
61   unsigned char app, verb, len;\r
62   \r
63   init();\r
64   \r
65   //Ready\r
66   txdata(MONITOR,OK,0);\r
67   \r
68   //Command loop.  There's no end!\r
69   while(1){\r
70     //Magic 3\r
71     app=serial_rx();\r
72     verb=serial_rx();\r
73     len=serial_rx();\r
74     \r
75     //Read data, if any\r
76     for(i=0;i<len;i++){\r
77       cmddata[i]=serial_rx();\r
78     }\r
79     handle(app,verb,len);\r
80   }\r
81 }\r
82 \r