]> git.gag.com Git - fw/sdcc/blob - device/examples/ds400/monitor400/mon400.c
More support for DS80C400
[fw/sdcc] / device / examples / ds400 / monitor400 / mon400.c
1 #include <tinibios.h>
2 #include <ds400rom.h>
3
4 #include <stdio.h>
5 #include <string.h>
6
7 #define BUF_LEN 80
8
9 void usage(void)
10 {
11     puts("Available commands:\n");
12     puts("ledon: turns LED on.");
13     puts("ledoff: turns LED off.");
14 }
15
16 void main(void)
17 {
18     char buffer[80];
19     
20     // At this stage, the rom isn't initalized. We do have polled serial I/O, though.
21     printf("TINIm400 monitor rev 0.0\n");
22
23     // Intialize the ROM.
24     if (romInit(1))
25     {
26         // We're hosed. romInit will have printed an error, nothing more to do.
27         return;
28     }
29     
30     P5 &= ~4; // LED on.
31
32     // Switch to interrupt driven serial I/O now that the rom is initialized.
33     Serial0SwitchToBuffered();
34
35     while (1)
36     {
37         // monitor prompt.
38         printf("-> ");
39         
40         gets(buffer); // unsafe, of course, should use some equivalent of fgets.
41         
42         if (!strcmp(buffer, "ledon"))
43         {
44             P5 &= ~4; // LED on.
45             printf("LED on.\n");
46         }
47         else if (!strcmp(buffer, "ledoff"))
48         {
49             P5 |= 4;
50             printf("LED off.\n");
51         }
52         else if (buffer[0])
53         {
54             printf("Unknown command \"%s\".\n", buffer);
55             usage();
56         }
57     }
58 }