]> git.gag.com Git - fw/sdcc/blobdiff - device/examples/ds400/monitor400/mon400.c
More support for DS80C400
[fw/sdcc] / device / examples / ds400 / monitor400 / mon400.c
diff --git a/device/examples/ds400/monitor400/mon400.c b/device/examples/ds400/monitor400/mon400.c
new file mode 100644 (file)
index 0000000..15b05fb
--- /dev/null
@@ -0,0 +1,58 @@
+#include <tinibios.h>
+#include <ds400rom.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#define BUF_LEN 80
+
+void usage(void)
+{
+    puts("Available commands:\n");
+    puts("ledon: turns LED on.");
+    puts("ledoff: turns LED off.");
+}
+
+void main(void)
+{
+    char buffer[80];
+    
+    // At this stage, the rom isn't initalized. We do have polled serial I/O, though.
+    printf("TINIm400 monitor rev 0.0\n");
+
+    // Intialize the ROM.
+    if (romInit(1))
+    {
+       // We're hosed. romInit will have printed an error, nothing more to do.
+       return;
+    }
+    
+    P5 &= ~4; // LED on.
+
+    // Switch to interrupt driven serial I/O now that the rom is initialized.
+    Serial0SwitchToBuffered();
+
+    while (1)
+    {
+       // monitor prompt.
+        printf("-> ");
+       
+       gets(buffer); // unsafe, of course, should use some equivalent of fgets.
+       
+       if (!strcmp(buffer, "ledon"))
+       {
+           P5 &= ~4; // LED on.
+           printf("LED on.\n");
+       }
+       else if (!strcmp(buffer, "ledoff"))
+       {
+           P5 |= 4;
+           printf("LED off.\n");
+       }
+       else if (buffer[0])
+       {
+           printf("Unknown command \"%s\".\n", buffer);
+           usage();
+       }
+    }
+}