View source for Talk:Wishlist/Alarm daemon

From Openmoko

Jump to: navigation, search

You do not have permission to edit this page, for the following reasons:

  • The action you have requested is limited to users in the group: Administrators.
  • You must confirm your email address before editing pages. Please set and validate your email address through your user preferences.

You can view and copy the source of this page:

Return to Talk:Wishlist/Alarm daemon.

Personal tools

After asking on the mailing list how to wake up a system on specific time I was asked to document what I found out.

The fist one is a C program (may be run on x86) which shows what are the request codes for different ioctl calls:

#include <stdio.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>

int main() {
	printf("RTC_RD_TIME = %d\n", RTC_RD_TIME);
	printf("RTC_SET_TIME = %d\n", RTC_SET_TIME);
	printf("RTC_ALM_READ = %d\n", RTC_ALM_READ);
	printf("RTC_ALM_SET = %d\n", RTC_ALM_SET);
	printf("RTC_IRQP_READ = %d\n", RTC_IRQP_READ);
	printf("RTC_IRQP_SET = %d\n", RTC_IRQP_SET);
	printf("RTC_AIE_ON = %d\n", RTC_AIE_ON);
	printf("RTC_AIE_OFF = %d\n", RTC_AIE_OFF);
	printf("RTC_UIE_ON = %d\n", RTC_UIE_ON);
	printf("RTC_UIE_OFF = %d\n", RTC_UIE_OFF);
	printf("RTC_PIE_ON = %d\n", RTC_PIE_ON);
	printf("RTC_PIE_OFF = %d\n", RTC_PIE_OFF);
	printf("RTC_EPOCH_READ = %d\n", RTC_EPOCH_READ);
	printf("RTC_EPOCH_SET = %d\n", RTC_EPOCH_SET);
}

This sample script wake up the system after 5 minutes. It requires python-fcntl and python-datetime to run.

import fcntl, struct, datetime

RTC_RD_TIME = -2145095671
RTC_SET_TIME = 1076129802
RTC_ALM_READ = -2145095672
RTC_ALM_SET = 1076129799
RTC_IRQP_READ = -2147192821
RTC_IRQP_SET = 1074032652
RTC_AIE_ON = 28673
RTC_AIE_OFF = 28674
RTC_UIE_ON = 28675
RTC_UIE_OFF = 28676
RTC_PIE_ON = 28677
RTC_PIE_OFF = 28678
RTC_EPOCH_READ = -2147192819
RTC_EPOCH_SET = 1074032654
	
def pack_data(data):
        return struct.pack('iiiiiiiii',
                           data.second, data.minute, data.hour,
                           data.day, data.month - 1, data.year - 1900,
                           0, 0, 0);

def unpack_data(rtc_data):
        data = struct.unpack('iiiiiiiii', rtc_data)
        datetime.datetime(rtc_data[5] + 1900, rtc_data[4] + 1, rtc_data[3],
                          rtc_data[2], rtc_data[1], rtc_data[0])

rtc = open("/dev/rtc0", "r")
fcntl.ioctl(rtc, RTC_ALM_SET,
            pack_data(datetime.datetime.utcnow() +
                      datetime.timedelta(0, 5*60)))
fcntl.ioctl(rtc, RTC_AIE_ON, 0) # In this call the 3rd argument is ignored

Please note however that the year, month and day are ignore while setting the interrupt.

About the powering down. It can be handle by script that: - Normally a interrupt will be set some time before alarm - On shutdown the interrupt is move a bit into future

--Uzytkownik 19:49, 31 July 2008 (UTC)