More reliably chipcon.
[goodfet] / firmware / goodfet.c
index bf63b13..467ebae 100644 (file)
@@ -1,5 +1,6 @@
 /*! \file goodfet.c\r
   \author Travis Goodspeed\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
   This is the main module of the GoodFET, which calls the initialization\r
   routines and delegates commands to the various applications.\r
@@ -29,12 +30,16 @@ void init(){
   \r
   //Enable Interrupts.\r
   //eint();\r
   \r
   //Enable Interrupts.\r
   //eint();\r
+\r
+\r
 }\r
 \r
 }\r
 \r
+\r
 //! Handle a command.\r
 void handle(unsigned char app,\r
            unsigned char verb,\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
   switch(app){\r
   case MONITOR:\r
     monitorhandle(app,verb,len);\r
@@ -42,6 +47,9 @@ void handle(unsigned char app,
   case SPI:\r
     spihandle(app,verb,len);\r
     break;\r
   case SPI:\r
     spihandle(app,verb,len);\r
     break;\r
+  case AVR:\r
+    avrhandle(app,verb,len);\r
+    break;\r
   case I2CAPP:\r
     i2chandle(app,verb,len);\r
     break;\r
   case I2CAPP:\r
     i2chandle(app,verb,len);\r
     break;\r
@@ -55,11 +63,13 @@ void handle(unsigned char app,
     jtag430x2handle(app,verb,len);\r
     break;\r
   default:\r
     jtag430x2handle(app,verb,len);\r
     break;\r
   default:\r
-    #ifdef HANDLEOTHER\r
-    HANDLEOTHER(app,verb,len);\r
-    #else\r
-    txdata(app,NOK,0);\r
-    #endif\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
     break;\r
   }\r
 }\r
@@ -68,7 +78,8 @@ void handle(unsigned char app,
 int main(void)\r
 {\r
   volatile unsigned int i;\r
 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
   init();\r
   \r
@@ -79,13 +90,23 @@ int main(void)
     //Magic 3\r
     app=serial_rx();\r
     verb=serial_rx();\r
     //Magic 3\r
     app=serial_rx();\r
     verb=serial_rx();\r
-    len=serial_rx();\r
+    //len=serial_rx();\r
+    len=rxword();\r
     \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
     }\r
-    handle(app,verb,len);\r
   }\r
 }\r
 \r
   }\r
 }\r
 \r