at_wini also needs a pci_reserve() for the pci compatability device, if
[minix3.git] / lib / sysutil / tickdelay.c
blobbb74160bbe74fd67bf20006ee641a02ffb3c8c33
1 #include "sysutil.h"
2 #include <timers.h>
4 /*===========================================================================*
5 * tickdelay *
6 *===========================================================================*/
7 PUBLIC int tickdelay(ticks)
8 long ticks; /* number of ticks to wait */
10 /* This function uses the synchronous alarm to delay for a while. This works
11 * even if a previous synchronous alarm was scheduled, because the remaining
12 * tick of the previous alarm are returned so that it can be rescheduled.
13 * Note however that a long tick_delay (longer than the remaining time of the
14 * previous) alarm will also delay the previous alarm.
16 message m, m_alarm;
17 int s;
19 if (ticks <= 0) return OK; /* check for robustness */
21 m.ALRM_ENDPT = SELF; /* SELF means this process nr */
22 m.ALRM_EXP_TIME = ticks; /* request message after ticks */
23 m.ALRM_ABS_TIME = 0; /* ticks are relative to now */
24 s = _taskcall(SYSTASK, SYS_SETALARM, &m);
25 if (s != OK) return(s);
27 receive(CLOCK,&m_alarm); /* await synchronous alarm */
29 /* Check if we must reschedule the current alarm. */
30 if (m.ALRM_TIME_LEFT > 0 && m.ALRM_TIME_LEFT != TMR_NEVER) {
31 m.ALRM_EXP_TIME = m.ALRM_TIME_LEFT - ticks;
32 if (m.ALRM_EXP_TIME <= 0)
33 m.ALRM_EXP_TIME = 1;
34 s = _taskcall(SYSTASK, SYS_SETALARM, &m);
37 return(s);