Imported Upstream version 2.9.0
[debian/cc1111] / 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, but that's
51     // about the only functional library service.
52     printf("TINIm400 monitor rev 0.0\n");
53
54     romInit(1, SPEED_2X);
55
56     // Now we're cooking with gas.
57     
58     while (1)
59     {
60         // monitor prompt.
61         printf("-> ");
62         
63         gets(buffer); // unsafe, of course, should use some equivalent of fgets.
64         
65         if (!strcmp(buffer, "ledon"))
66         {
67             P5 &= ~4; // LED on.
68             printf("LED on.\n");
69         }
70         else if (!strcmp(buffer, "ledoff"))
71         {
72             P5 |= 4;
73             printf("LED off.\n");
74         }
75         else if (!strcmp(buffer, "clock"))
76         {
77             printf("Clock: %ld\n", ClockTicks());
78         }
79         else if (!strcmp(buffer, "thread"))
80         {
81             printf("Thread ID: %d\n", (int)task_getthreadID());
82         }
83         else if (!strcmp(buffer, "sleep"))
84         {
85             printf("Sleeping for 10 seconds...\n");
86             
87             ClockMilliSecondsDelay(10 * 1000);
88             
89             printf("Back.\n");
90         }
91         else if (!strcmp(buffer, "pmr"))
92         {
93             printf("PMR: %x\n", PMR);
94         }
95         else if (!strcmp(buffer, "exif"))
96         {
97             printf("EXIF: %x\n", EXIF);
98         }
99         else if (!strcmp(buffer, "blink"))
100         {
101             blinker();
102         }
103         else if (!strcmp(buffer, "t0"))
104         {
105             printf("TH0:TL0 %x:%x\n", TH0, TL0);
106         }
107         else if (!strcmp(buffer, "t2"))
108         {
109             printf("TH2:TL2 %x:%x\n", TH2, TH2);
110         }       
111         else if (!strcmp(buffer, "faster"))
112         {
113             printf("going really fast...\n");
114             P5 |= 4; // LED off.
115
116             PMR = 0x82; 
117             PMR = 0x8a; // 8a for REAL fast
118             PMR = 0x9a; // 9a for REAL fast.
119             
120             while (!(EXIF & 8))
121                 ;
122
123             PMR = 0x1a; // 1a for REAL fast.
124             
125 _asm
126                 nop
127 _endasm;                
128             
129             P5 &= ~5; // LED on.
130         }
131         else if (buffer[0])
132         {
133             printf("Unknown command \"%s\".\n", buffer);
134             usage();
135         }
136     }
137 }