mirror of https://github.com/zrafa/xinu-avr.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
55 lines
1.2 KiB
/* sleep.c - sleep sleepms */ |
|
|
|
#include <xinu.h> |
|
|
|
#define MAXSECONDS 2147483 /* Max seconds per 32-bit msec */ |
|
|
|
/*------------------------------------------------------------------------ |
|
* sleep - Delay the calling process n seconds |
|
*------------------------------------------------------------------------ |
|
*/ |
|
syscall sleep( |
|
int32 delay /* Time to delay in seconds */ |
|
) |
|
{ |
|
if ( (delay < 0) || (delay > MAXSECONDS) ) { |
|
return SYSERR; |
|
} |
|
sleepms(1000*delay); |
|
return OK; |
|
} |
|
|
|
/*------------------------------------------------------------------------ |
|
* sleepms - Delay the calling process n x 1000 milliseconds |
|
* for example: 1 second = sleepms(1000) |
|
* avr atmega328p specific |
|
*------------------------------------------------------------------------ |
|
*/ |
|
syscall sleepms( |
|
int32 delay /* Time to delay in msec. */ |
|
) |
|
{ |
|
intmask mask; /* Saved interrupt mask */ |
|
|
|
if (delay < 0) { |
|
return SYSERR; |
|
} |
|
|
|
if (delay == 0) { |
|
yield(); |
|
return OK; |
|
} |
|
|
|
/* Delay calling process */ |
|
|
|
mask = disable(); |
|
if (insertd(currpid, sleepq, delay) == SYSERR) { |
|
restore(mask); |
|
return SYSERR; |
|
} |
|
|
|
proctab[currpid].prstate = PR_SLEEP; |
|
resched(); |
|
restore(mask); |
|
return OK; |
|
}
|
|
|