OSDN Git Service

Moved the junk codes to junk directory.
[kozos-expbrd/kozos_expbrd.git] / firm / junk / 04 / os / clock.c
1 #include "defines.h"
2 #include "kozos.h"
3 #include "consdrv.h"
4 #include "timerdrv.h"
5 #include "leddrv.h"
6 #include "lib.h"
7 #include "sw.h"
8
9 /* ¥¿¥¤¥Þ¤Î¥«¥¦¥ó¥È³«»Ï¤ò¥¿¥¤¥Þ¡¦¥É¥é¥¤¥Ð¤Ë°ÍÍꤹ¤ë */
10 static void send_start(int msec)
11 {
12   struct timerreq *req;
13   req = kz_kmalloc(sizeof(*req));
14   req->id = MSGBOX_ID_TIMEXPIRE;
15   req->msec = msec;
16   kz_send(MSGBOX_ID_TIMDRIVE, TIMERDRV_CMD_START, (char *)req);
17 }
18
19 static void send_led_write(int target, int state)
20 {
21   char *p;
22   p = kz_kmalloc(2);
23   p[0] = state ? LEDDRV_CMD_LED_ON : LEDDRV_CMD_LED_OFF;
24   p[1] = '0' + target;
25   kz_send(MSGBOX_ID_LEDDRIVE, 2, p);
26 }
27
28 static void send_led_toggle(int target)
29 {
30   char *p;
31   p = kz_kmalloc(2);
32   p[0] = LEDDRV_CMD_LED_TOGGLE;
33   p[1] = '0' + target;
34   kz_send(MSGBOX_ID_LEDDRIVE, 2, p);
35 }
36
37 int clock_main(int argc, char *argv[])
38 {
39   sw_init();
40
41   while (1) {
42     send_start(100);
43     kz_recv(MSGBOX_ID_TIMEXPIRE, NULL, NULL);
44     if (sw_read(Sw1)) {
45       send_led_write(0, 1);
46     } else {
47       send_led_toggle(0);
48     }
49
50     send_start(100);
51     kz_recv(MSGBOX_ID_TIMEXPIRE, NULL, NULL);
52     if (sw_read(Sw2)) {
53       send_led_write(1, 1);
54     } else {
55       send_led_toggle(1);
56     }
57   }
58
59   return 0;
60 }