2005-07-19 15:21:51 +02:00
|
|
|
#include "sysutil.h"
|
2005-08-05 18:46:27 +02:00
|
|
|
#include <timers.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
2005-06-01 16:31:00 +02:00
|
|
|
* tickdelay *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2012-11-15 12:06:41 +01:00
|
|
|
int tickdelay(clock_t ticks)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-05-13 11:33:53 +02:00
|
|
|
/* This function uses the synchronous alarm to delay for a while. This works
|
|
|
|
* even if a previous synchronous alarm was scheduled, because the remaining
|
|
|
|
* tick of the previous alarm are returned so that it can be rescheduled.
|
|
|
|
* Note however that a long tick_delay (longer than the remaining time of the
|
|
|
|
* previous) alarm will also delay the previous alarm.
|
|
|
|
*/
|
|
|
|
message m, m_alarm;
|
2005-04-21 16:53:53 +02:00
|
|
|
int s;
|
|
|
|
|
2006-11-10 19:13:02 +01:00
|
|
|
if (ticks <= 0) return OK; /* check for robustness */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
m.ALRM_EXP_TIME = ticks; /* request message after ticks */
|
|
|
|
m.ALRM_ABS_TIME = 0; /* ticks are relative to now */
|
2010-02-09 16:20:09 +01:00
|
|
|
s = _kernel_call(SYS_SETALARM, &m);
|
2005-05-13 11:33:53 +02:00
|
|
|
if (s != OK) return(s);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2010-03-23 01:09:11 +01:00
|
|
|
sef_receive(CLOCK,&m_alarm); /* await synchronous alarm */
|
2005-05-13 11:33:53 +02:00
|
|
|
|
|
|
|
/* Check if we must reschedule the current alarm. */
|
2005-08-05 18:46:27 +02:00
|
|
|
if (m.ALRM_TIME_LEFT > 0 && m.ALRM_TIME_LEFT != TMR_NEVER) {
|
2005-05-13 11:33:53 +02:00
|
|
|
m.ALRM_EXP_TIME = m.ALRM_TIME_LEFT - ticks;
|
|
|
|
if (m.ALRM_EXP_TIME <= 0)
|
|
|
|
m.ALRM_EXP_TIME = 1;
|
2010-02-09 16:20:09 +01:00
|
|
|
s = _kernel_call(SYS_SETALARM, &m);
|
2005-05-13 11:33:53 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-13 11:33:53 +02:00
|
|
|
return(s);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|