4 /*===========================================================================*
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.
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)
34 s
= _taskcall(SYSTASK
, SYS_SETALARM
, &m
);