I2C committed but not tested.
[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   default:\r
46     txdata(app,NOK,0);\r
47   }\r
48 }\r
49 \r
50 //! Main loop.\r
51 int main(void)\r
52 {\r
53   volatile unsigned int i;\r
54   unsigned char app, verb, len;\r
55   \r
56   init();\r
57   \r
58   //Ready\r
59   txdata(MONITOR,OK,0);\r
60   \r
61   //Command loop.  There's no end!\r
62   while(1){\r
63     //Magic 3\r
64     app=serial_rx();\r
65     verb=serial_rx();\r
66     len=serial_rx();\r
67     \r
68     //Read data, if any\r
69     for(i=0;i<len;i++){\r
70       cmddata[i]=serial_rx();\r
71     }\r
72     handle(app,verb,len);\r
73   }\r
74 }\r
75 \r