More DS400 support
[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     puts("clock: reports millisecond timer.");
15     puts("sleep: sleeps for 10 seconds (or forever if you didn't startclock first).");
16 }
17
18 void blinker(void)
19 {
20     int i, j;
21     
22     while (1)
23     {
24         P5 |= 4;
25         for (j = 0; j < 10; j++)
26         {
27             for (i = 0; i < 32767; i++)
28             {
29                 ;
30             }
31         }
32         
33         P5 &= ~4;
34         
35         for (j = 0; j < 10; j++)
36         {
37             for (i = 0; i < 32767; i++)
38             {
39                 ;
40             }
41         }       
42     }
43 }
44
45
46 void main(void)
47 {
48     char buffer[80];
49     
50     // At this stage, the rom isn't initalized. We do have polled serial I/O, though.
51     printf("TINIm400 monitor rev 0.0\n");
52     
53     P5 |= 4; // LED off.
54     
55     // double the cpu speed.
56     if (1)
57     {
58         PMR = 0x82;
59         PMR = 0x92;
60         
61         while (!(EXIF & 8))
62             ;
63         
64         PMR = 0x12;
65     }
66     
67     // Intialize the ROM.
68     if (romInit(1))
69     {
70         // We're hosed. romInit will have printed an error, nothing more to do.
71         return;
72     }
73     
74     P5 &= ~4; // LED on.
75
76     // Switch to interrupt driven serial I/O now that the rom is initialized.
77     Serial0SwitchToBuffered();
78
79     while (1)
80     {
81         // monitor prompt.
82         printf("-> ");
83         
84         gets(buffer); // unsafe, of course, should use some equivalent of fgets.
85         
86         if (!strcmp(buffer, "ledon"))
87         {
88             P5 &= ~4; // LED on.
89             printf("LED on.\n");
90         }
91         else if (!strcmp(buffer, "ledoff"))
92         {
93             P5 |= 4;
94             printf("LED off.\n");
95         }
96         else if (!strcmp(buffer, "clock"))
97         {
98             printf("Clock: %ld\n", ClockTicks());
99         }
100         else if (!strcmp(buffer, "thread"))
101         {
102             printf("Thread ID: %d\n", (int)DSS_getthreadID());
103         }
104         else if (!strcmp(buffer, "sleep"))
105         {
106             printf("Sleeping for 10 seconds...\n");
107             
108             ClockMilliSecondsDelay(10 * 1000);
109             
110             printf("Back.\n");
111         }
112         else if (!strcmp(buffer, "pmr"))
113         {
114             printf("PMR: %x\n", PMR);
115         }
116         else if (!strcmp(buffer, "exif"))
117         {
118             printf("EXIF: %x\n", EXIF);
119         }
120         else if (!strcmp(buffer, "blink"))
121         {
122             blinker();
123         }
124         else if (!strcmp(buffer, "t0"))
125         {
126             printf("TH0:TL0 %x:%x\n", TH0, TL0);
127         }
128         else if (!strcmp(buffer, "t2"))
129         {
130             printf("TH2:TL2 %x:%x\n", TH2, TH2);
131         }       
132         else if (!strcmp(buffer, "faster"))
133         {
134             printf("going really fast...\n");
135             P5 |= 4; // LED off.
136
137             PMR = 0x82; 
138             PMR = 0x8a; // 8a for REAL fast
139             PMR = 0x9a; // 9a for REAL fast.
140             
141             while (!(EXIF & 8))
142                 ;
143
144             PMR = 0x1a; // 1a for REAL fast.
145             
146 _asm
147                 nop
148 _endasm;                
149             
150             P5 &= ~5; // LED on.
151         }
152         else if (buffer[0])
153         {
154             printf("Unknown command \"%s\".\n", buffer);
155             usage();
156         }
157     }
158 }