Using Android wake alarms

762 views
Skip to first unread message

Guru Prasad

unread,
Sep 30, 2013, 3:15:41 PM9/30/13
to android...@googlegroups.com
Hi,

I'm working with a fairly old version of the Linux kernel (v3.0) on
the Android platform (4.1.1_r4).

From my understanding, it should be possible to wake the system from suspend so as long as I can
request an alarm from ANDROID_ALARM_ELAPSED_REALTIME

I'm trying to look at the Android platform AlarmManager code; both
Java and native, to try and figure out exactly how I'm supposed to use
this interface.

So far, after looking at
frameworks/base/services/jni/com_android_server_AlarmManagerService.cpp
frameworks/base/services/java/com/android/server/AlarmManagerService.java

I'm now trying to set an alarm using something like
struct timespec ts;
ts.tv_nsec     = 0;
ts.tv_sec       = 15;

int alarm_fd = open("/dev/alarm", O_RDWR);
int result = ioctl(alarm_fd,
ANDROID_ALARM_SET(ANDROID_
ALARM_ELAPSED_REALTIME), &ts);


However, upon execution, kmsg shows me the following
[  430.304171] alarm_release: clear alarm, pending 0


I've also confirmed that the device does not wake up from suspend
using the above snippet.

I'm not sure what I'm doing wrong..I've tried to replicate most of what the AlarmMAnagerService.cpp is doing..


I would greatly appreciate it if someone could help me with the Android alarm interface


Thanks

Yu Baolin

unread,
Oct 4, 2013, 2:25:16 AM10/4/13
to android...@googlegroups.com
Hi Prasad,

Command ANDROID_ALARM_ELAPSED_REALTIME can't wake up system. 
You can try ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP command, and you should confirm whether the real rtc chip on your platform supports wakeup function and the rtc driver enables it.
Because the android alarm is just a virtual driver, it will finally call the real rtc driver to set alarm to the chip.

Thanks
Gary

在 2013年10月1日星期二UTC+8上午3时15分41秒,Guru Prasad写道:

Anirudh Gargi

unread,
Oct 30, 2013, 3:11:29 AM10/30/13
to android...@googlegroups.com
HI Guru, 

Also, if you can use RTC hardware to do so , infact the android alarm manager internally uses the RTC hw to wakeup from suspend. 
(As that is one of the area of board that is still powered , when we in suspend. )

Usually the RTC is exposed as an sys file entry with name like RTC0 or RTC1 depending on the type of SOC chipset used. 

To set and unset the a future wakeup is as easy as doing a echo in sys file entry. 
Like  Echo an enrty of 2 min in future and remove USB cable , see if it wakes up, if u have serial cable , looks for the kernel logs to confirm the wakeup interrupt.  


Note : I had done some work on the abovem, setting alarm works fine when value is greater than 5sec or so. But setting lower values fails most of the times.(i guess some h/w dependency). 

Hope it helps. 

-Anirudh
Reply all
Reply to author
Forward
0 new messages