10 struct timerbuf *next;
11 kz_msgbox_id_t id; /* ¥¿¥¤¥ÞËþλ»þ¤Î¥á¥Ã¥»¡¼¥¸Á÷¿®Àè */
15 static struct timerreg {
16 struct timerbuf *timers; /* ¥¿¥¤¥Þ¡¦¥Ð¥Ã¥Õ¥¡¤Î¥ê¥ó¥¯¥ê¥¹¥È */
17 int index; /* ÍøÍѤ¹¤ë¥¿¥¤¥Þ¤ÎÈÖ¹æ */
21 * °Ê²¼¤Ï³ä¹þ¤ß¥Ï¥ó¥É¥é¤Ç¤¢¤ê¡¤ÈóƱ´ü¤Ç¸Æ¤Ð¤ì¤ë¤Î¤Ç¡¤¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Ê¤É¤ò
22 * ¸Æ¤Ó½Ð¤¹¾ì¹ç¤Ë¤ÏÃí°Õ¤¬É¬Íס¥
23 * ´ðËܤȤ·¤Æ¡¤°Ê²¼¤Î¤¤¤º¤ì¤«¤ËÅö¤Æ¤Ï¤Þ¤ë´Ø¿ô¤·¤«¸Æ¤Ó½Ð¤·¤Æ¤Ï¤¤¤±¤Ê¤¤¡¥
25 * ¡¦¥¹¥ì¥Ã¥É¤«¤é¸Æ¤Ð¤ì¤ë¤³¤È¤Ï̵¤¤´Ø¿ô¤Ç¤¢¤ë¡¥
26 * ¡¦¥¹¥ì¥Ã¥É¤«¤é¸Æ¤Ð¤ì¤ë¤³¤È¤¬¤¢¤ë¤¬¡¤³ä¹þ¤ß¶Ø»ß¤Ç¸Æ¤Ó½Ð¤·¤Æ¤¤¤ë¡¥
27 * ¤Þ¤¿Èó¥³¥ó¥Æ¥¥¹¥È¾õÂ֤ǸƤФì¤ë¤¿¤á¡¤¥·¥¹¥Æ¥à¡¦¥³¡¼¥ë¤ÏÍøÍѤ·¤Æ¤Ï¤¤¤±¤Ê¤¤¡¥
28 * (¥µ¡¼¥Ó¥¹¡¦¥³¡¼¥ë¤òÍøÍѤ¹¤ë¤³¤È)
30 static void timerdrv_intr(void)
32 struct timerreg *tim = &timerreg;
34 if (timer_is_expired(tim->index)) { /* ¥¿¥¤¥Þ³ä¹þ¤ß */
35 timer_cancel(tim->index);
36 kx_send(MSGBOX_ID_TIMDRIVE, TIMERDRV_CMD_EXPIRE, NULL);
40 static int timerdrv_init(void)
42 memset(&timerreg, 0, sizeof(timerreg));
43 timerreg.index = TIMER_DEFAULT_DEVICE;
47 /* ¥¹¥ì¥Ã¥É¤«¤é¤ÎÍ×µá¤ò½èÍý¤¹¤ë */
48 static int timerdrv_command(struct timerreg *tim, int cmd, char *p)
50 struct timerbuf *tmbuf;
51 struct timerbuf **tmbufp;
56 case TIMERDRV_CMD_EXPIRE: /* ¥¿¥¤¥ÞËþλ */
59 tim->timers = tmbuf->next;
60 kz_send(tmbuf->id, 0, NULL);
63 timer_start(tim->index, tim->timers->msec, 0);
67 case TIMERDRV_CMD_START: /* ¥¿¥¤¥Þ¤Î¥¹¥¿¡¼¥È */
68 req = (struct timerreq *)p;
70 tmbuf = kz_kmalloc(sizeof(*tmbuf));
73 tmbuf->msec = req->msec;
77 t = timer_gettime(tim->index);
80 for (tmbufp = &tim->timers;; tmbufp = &(*tmbufp)->next) {
81 if (*tmbufp == NULL) {
83 if (tmbufp == &tim->timers)
84 timer_start(tim->index, tim->timers->msec, 0);
87 msec = (*tmbufp)->msec - t;
88 if (msec < 0) msec = 0;
89 if (tmbuf->msec < msec) {
90 (*tmbufp)->msec = msec - tmbuf->msec;
91 tmbuf->next = *tmbufp;
93 timer_start(tim->index, tim->timers->msec, 0);
110 int timerdrv_main(int argc, char *argv[])
116 kz_setintr(SOFTVEC_TYPE_TIMINTR, timerdrv_intr); /* ³ä¹þ¤ß¥Ï¥ó¥É¥éÀßÄê */
119 kz_recv(MSGBOX_ID_TIMDRIVE, &cmd, &p);
120 timerdrv_command(&timerreg, cmd, p);