Print configuration instructions.
[goodfet] / firmware / goodfet.c
index d993167..b9485aa 100644 (file)
@@ -1,13 +1,16 @@
-//GOODFET Main File\r
-//Includes several applications.\r
+/*! \file goodfet.c\r
+  \author Travis Goodspeed\r
+  \brief Main module.\r
+  \r
+  This is the main module of the GoodFET, which calls the initialization\r
+  routines and delegates commands to the various applications.\r
+*/\r
+\r
 \r
 #include "platform.h"\r
 #include "command.h"\r
 #include "apps.h"\r
 \r
-#include <signal.h>\r
-#include <io.h>\r
-#include <iomacros.h>\r
 \r
 \r
 //LED on P1.0\r
 \r
 //! Initialize registers and all that jazz.\r
 void init(){\r
-  volatile unsigned int i;\r
   WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer\r
   \r
-  //LED and TX OUT\r
+  //LED out and on.\r
   PLEDDIR |= PLEDPIN;\r
+  PLEDOUT |= PLEDPIN;\r
   \r
+  //Setup clocks, unique to each '430.\r
   msp430_init_dco();\r
   msp430_init_uart();\r
   \r
@@ -28,10 +32,12 @@ void init(){
   //eint();\r
 }\r
 \r
+\r
 //! Handle a command.\r
 void handle(unsigned char app,\r
            unsigned char verb,\r
-           unsigned char len){\r
+           unsigned long len){\r
+  //debugstr("GoodFET");\r
   switch(app){\r
   case MONITOR:\r
     monitorhandle(app,verb,len);\r
@@ -39,7 +45,10 @@ void handle(unsigned char app,
   case SPI:\r
     spihandle(app,verb,len);\r
     break;\r
-  case I2C:\r
+  case AVR:\r
+    avrhandle(app,verb,len);\r
+    break;\r
+  case I2CAPP:\r
     i2chandle(app,verb,len);\r
     break;\r
   case CHIPCON:\r
@@ -48,11 +57,17 @@ void handle(unsigned char app,
   case JTAG:\r
     jtaghandle(app,verb,len);\r
     break;\r
-  case JTAG430:\r
-    jtag430handle(app,verb,len);\r
+  case JTAG430: //Also JTAG430X, JTAG430X2\r
+    jtag430x2handle(app,verb,len);\r
     break;\r
   default:\r
-    txdata(app,NOK,0);\r
+    if(pluginhandle){\r
+      pluginhandle(app,verb,len);\r
+    }else{\r
+      debugstr("Plugin missing.");\r
+      txdata(app,NOK,0);\r
+    }\r
+      \r
     break;\r
   }\r
 }\r
@@ -61,13 +76,11 @@ void handle(unsigned char app,
 int main(void)\r
 {\r
   volatile unsigned int i;\r
-  unsigned char app, verb, len;\r
+  unsigned char app, verb;\r
+  unsigned long len;\r
   \r
   init();\r
   \r
-  \r
-  //Ready\r
-  //txdata(MONITOR,OK,0);\r
   txstring(MONITOR,OK,"http://goodfet.sf.net/");\r
   \r
   //Command loop.  There's no end!\r
@@ -75,13 +88,23 @@ int main(void)
     //Magic 3\r
     app=serial_rx();\r
     verb=serial_rx();\r
-    len=serial_rx();\r
+    //len=serial_rx();\r
+    len=rxword();\r
     \r
-    //Read data, if any\r
-    for(i=0;i<len;i++){\r
-      cmddata[i]=serial_rx();\r
+    //Read data, looking for buffer overflow.y\r
+    if(len<=CMDDATALEN){\r
+      for(i=0;i<len;i++){\r
+       cmddata[i]=serial_rx();\r
+      }\r
+      handle(app,verb,len);\r
+    }else{\r
+      //Listen to the blaberring.\r
+      for(i-0;i<len;i++)\r
+       serial_rx();\r
+      //Reply with an error.\r
+      debugstr("Buffer length exceeded.");\r
+      txdata(MONITOR,NOK,0);\r
     }\r
-    handle(app,verb,len);\r
   }\r
 }\r
 \r