r4295 - in developers/zecke: . apm_bios_test
zecke at sita.openmoko.org
zecke at sita.openmoko.org
Tue Apr 1 22:47:20 CEST 2008
Author: zecke
Date: 2008-04-01 22:47:14 +0200 (Tue, 01 Apr 2008)
New Revision: 4295
Added:
developers/zecke/apm_bios_test/
developers/zecke/apm_bios_test/apm_bios_test.c
Log:
Add my simple apm test to see if one can delay going to suspend. One can.
Added: developers/zecke/apm_bios_test/apm_bios_test.c
===================================================================
--- developers/zecke/apm_bios_test/apm_bios_test.c 2008-04-01 19:54:23 UTC (rev 4294)
+++ developers/zecke/apm_bios_test/apm_bios_test.c 2008-04-01 20:47:14 UTC (rev 4295)
@@ -0,0 +1,85 @@
+/*
+ * (C) Copyright 2008 Openmoko Inc.
+ *
+ * Simple utility to test the apm_bio acknowledge feature
+ *
+ * Trying to read just event will give mysterious failures. Other
+ * than that a pretty easy interface to use
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include <linux/apm_bios.h>
+
+static void user_suspend(int fd)
+{
+ sleep(3);
+ printf("Ack'ing suspend now\n");
+ ioctl(fd, APM_IOC_SUSPEND, NULL);
+ printf("Resumed now\n");
+}
+
+
+int main(int argc, char** argv)
+{
+ int apm_bios_fd = open("/dev/apm_bios", O_RDWR);
+ if (apm_bios_fd < 0) {
+ perror("apm_bios");
+ return EXIT_FAILURE;
+ }
+
+ apm_event_t event[16];
+ while (1) {
+ fd_set rfds;
+ struct timeval tv;
+ int retval;
+ int i;
+
+ FD_ZERO(&rfds);
+ FD_SET(apm_bios_fd, &rfds);
+ retval = select(apm_bios_fd + 1, &rfds, NULL, NULL, NULL);
+ if (retval == -1)
+ perror("select()");
+ else if (retval) {
+ retval = read(apm_bios_fd, (void*)&event, sizeof(event));
+ if (retval < 0) {
+ perror("Failed to read");
+ continue;
+ }
+
+ for (i= 0; i < retval/sizeof(apm_event_t); ++i) {
+#define HANDLE(x) \
+ case x: printf("%s: %u\n", #x, event[i]); \
+ break;
+#define HANDLE_CALL(x, y) \
+ case x: printf("%s: %u\n", #x, event[i]); \
+ y \
+ break;
+ switch(event[i]) {
+ HANDLE(APM_SYS_STANDBY)
+ HANDLE(APM_SYS_SUSPEND)
+ HANDLE(APM_NORMAL_RESUME)
+ HANDLE(APM_CRITICAL_RESUME)
+ HANDLE(APM_LOW_BATTERY)
+ HANDLE(APM_POWER_STATUS_CHANGE)
+ HANDLE(APM_UPDATE_TIME)
+ HANDLE(APM_CRITICAL_SUSPEND)
+ HANDLE(APM_USER_STANDBY)
+ HANDLE_CALL(APM_USER_SUSPEND, user_suspend(apm_bios_fd);)
+ HANDLE(APM_STANDBY_RESUME)
+ HANDLE(APM_CAPABILITY_CHANGE)
+ };
+ }
+ }
+ }
+
+
+ perror("reading");
+ return EXIT_FAILURE;
+}
Property changes on: developers/zecke/apm_bios_test/apm_bios_test.c
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the commitlog
mailing list