[debian/all] wake when needed
Timo Juhani Lindfors
timo.lindfors at iki.fi
Sun Jan 25 13:19:10 CET 2009
"Nikita V. Youshchenko" <yoush at debian.org> writes:
> Is there any working methond to make freerunner suspend sleep and later
> wakeup not later than at a given moment?
Yes.
#include <stdio.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <time.h>
int main(int argc, char **argv) {
int fd, ret;
struct rtc_wkalrm wkalrm;
assert(argc == 2);
fd = open("/dev/rtc0", O_RDONLY);
assert(fd);
{
struct tm *tm;
time_t secs;
secs = atol(argv[1]);
assert(secs > 86400*365*(2000-1970));
assert(secs < 86400*365*(2030-1970));
tm = gmtime(&secs);
assert(tm);
wkalrm.time.tm_sec = tm->tm_sec;
wkalrm.time.tm_min = tm->tm_min;
wkalrm.time.tm_hour = tm->tm_hour;
wkalrm.time.tm_mday = tm->tm_mday;
wkalrm.time.tm_mon = tm->tm_mon;
wkalrm.time.tm_year = tm->tm_year;
wkalrm.time.tm_wday = tm->tm_wday;
wkalrm.time.tm_yday = tm->tm_yday;
wkalrm.time.tm_isdst = tm->tm_isdst;
}
wkalrm.enabled = 1;
ret = ioctl(fd, RTC_WKALM_SET, &wkalrm);
assert(ret != -1);
return 0;
}
works for me with andy-tracking b8b36e5ec3d.
More information about the community
mailing list