Firmware coming together.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Wed, 3 Jun 2009 17:10:12 +0000 (17:10 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Wed, 3 Jun 2009 17:10:12 +0000 (17:10 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@22 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

firmware/apps/Makefile [new file with mode: 0644]
firmware/apps/goodfet.c [new file with mode: 0644]
firmware/apps/monitor/monitor.c [new file with mode: 0644]
firmware/include/apps.h [new file with mode: 0644]
firmware/include/command.h [new file with mode: 0644]
firmware/lib/command.c [new file with mode: 0644]

diff --git a/firmware/apps/Makefile b/firmware/apps/Makefile
new file mode 100644 (file)
index 0000000..83f3125
--- /dev/null
@@ -0,0 +1,24 @@
+
+PORT=/dev/ttyUSB0
+BSL=tos-bsl --invert-reset --invert-test -c $(PORT)
+
+#mcu=msp430x1611
+mcu=msp430x1612
+
+#ldscript is wonky
+GCCINC=-T ../ldscripts/161x.x
+
+CC=msp430-gcc -g -mmcu=$(mcu) -DGCC $(GCCINC) -I ../include
+
+apps= monitor/monitor.c
+libs= ../lib/msp430f1612.c ../lib/command.c
+app=goodfet
+
+install: $(app)
+       $(BSL) -e -p $(app) 
+       $(BSL) -P $(app) -r
+$(app): $(app).c $(libs) $(apps)
+erase:
+       $(BSL) -e 
+clean:
+       rm -f $(app)
diff --git a/firmware/apps/goodfet.c b/firmware/apps/goodfet.c
new file mode 100644 (file)
index 0000000..c5e037e
--- /dev/null
@@ -0,0 +1,78 @@
+//GOODFET Echo test.\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
+//IO on P5\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
+  PLEDDIR |= PLEDPIN;\r
+  \r
+  msp430_init_dco();\r
+  msp430_init_uart();\r
+  \r
+  //Enable Interrupts.\r
+  //eint();\r
+}\r
+\r
+//! Handle a command.\r
+void handle(unsigned char app,\r
+           unsigned char verb,\r
+           unsigned char len){\r
+  switch(app){\r
+  case MONITOR:\r
+    monitorhandle(app,verb,len);\r
+    break;\r
+  default:\r
+    txdata(app,NOK,0);\r
+  }\r
+}\r
+\r
+//! Main loop.\r
+int main(void)\r
+{\r
+  volatile unsigned int i;\r
+  unsigned char app, verb, len;\r
+  \r
+  init();\r
+  \r
+  //Command loop.  There's no end!\r
+  while(1){\r
+    //Ready\r
+    txdata(MONITOR,OK,0);\r
+    \r
+    //Magic 3\r
+    app=serial_rx();\r
+    verb=serial_rx();\r
+    len=serial_rx();\r
+    //Read data, if any\r
+    for(i=0;i<len;i++){\r
+      cmddata[i]=serial_rx();\r
+    }\r
+    handle(app,verb,len);\r
+  }\r
+    \r
+  //while(1) serial_tx(serial_rx());\r
+  while(1) serial_tx(serial_rx());\r
+  \r
+  while(1){\r
+    i = 10000;\r
+    while(i--);\r
+    \r
+    PLEDOUT^=PLEDPIN;  // Blink\r
+  }\r
+}\r
+\r
diff --git a/firmware/apps/monitor/monitor.c b/firmware/apps/monitor/monitor.c
new file mode 100644 (file)
index 0000000..0bb7838
--- /dev/null
@@ -0,0 +1,15 @@
+#include "command.h"
+
+//! Handles a monitor command.
+void monitorhandle(unsigned char app,
+                  unsigned char verb,
+                  unsigned char len){
+  switch(verb){
+  case PEEK:
+    cmddata[0]=memorybyte[cmddataword[0]];
+    txdata(app,verb,1);
+    break;
+  case POKE:
+    break;
+  }
+}
diff --git a/firmware/include/apps.h b/firmware/include/apps.h
new file mode 100644 (file)
index 0000000..8a8b999
--- /dev/null
@@ -0,0 +1,10 @@
+//! Application stuff.
+
+#define MONITOR 0x00
+#define SPI 0x01
+#define I2C 0x02
+#define JTAG 0x10
+#define JTAG430 0x11
+#define CHIPCON 0x30
+#define SIF 0x31
+
diff --git a/firmware/include/command.h b/firmware/include/command.h
new file mode 100644 (file)
index 0000000..5d7813b
--- /dev/null
@@ -0,0 +1,22 @@
+//! Command handling functions.
+
+//! Global data buffer.
+extern unsigned char cmddata[256];
+#define cmddataword ((unsigned int*) cmddata)
+#define memorybyte ((unsigned char*) 0)
+
+// Command prefixes
+#define READ  0x00
+#define WRITE 0x01
+#define PEEK  0x02
+#define POKE  0x03
+#define NOK   0x7E
+#define OK    0x7F
+
+//!Handle a command.  Defined in goodfet.c
+void handle(unsigned char app,unsigned char verb,unsigned  char len);
+
+//!Transmit data.
+void txdata(unsigned char app,
+           unsigned char verb,
+           unsigned char len);
diff --git a/firmware/lib/command.c b/firmware/lib/command.c
new file mode 100644 (file)
index 0000000..c9c1b1c
--- /dev/null
@@ -0,0 +1,16 @@
+//! Different command handling functions.
+
+unsigned char cmddata[256];
+
+//!Transmit data.
+void txdata(unsigned char app,
+           unsigned char verb,
+           unsigned char len){
+  unsigned int i=0;
+  serial_tx(app);
+  serial_tx(verb);
+  serial_tx(len);
+  for(i=0;i<len;i++){
+    serial_tx(cmddata[i]);
+  }
+}