From owner-freebsd-current@FreeBSD.ORG Fri Oct 9 20:29:07 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0B46D106566B for ; Fri, 9 Oct 2009 20:29:07 +0000 (UTC) (envelope-from tom@tomjudge.com) Received: from tomjudge.vm.bytemark.co.uk (tomjudge.vm.bytemark.co.uk [80.68.91.100]) by mx1.freebsd.org (Postfix) with ESMTP id B0EEB8FC18 for ; Fri, 9 Oct 2009 20:29:06 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by tomjudge.vm.bytemark.co.uk (Postfix) with ESMTP id 4CAF0489D2; Fri, 9 Oct 2009 21:29:05 +0100 (BST) X-Virus-Scanned: Debian amavisd-new at tomjudge.vm.bytemark.co.uk Received: from tomjudge.vm.bytemark.co.uk ([127.0.0.1]) by localhost (tomjudge.vm.bytemark.co.uk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RH8AIzxQ+1kq; Fri, 9 Oct 2009 21:29:01 +0100 (BST) Received: from rita.nodomain (unknown [192.168.205.6]) by tomjudge.vm.bytemark.co.uk (Postfix) with ESMTP id 859A748988; Fri, 9 Oct 2009 21:29:00 +0100 (BST) Message-ID: <4ACF9CE7.30808@tomjudge.com> Date: Fri, 09 Oct 2009 20:28:23 +0000 From: Tom Judge User-Agent: Thunderbird 2.0.0.23 (X11/20090822) MIME-Version: 1.0 To: Sylwester Sosnowski References: <4ACF131C.1060201@ext.no-route.org> In-Reply-To: <4ACF131C.1060201@ext.no-route.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-current@freebsd.org Subject: Re: Support for PC Engines ALIX2 reset pushbutton. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Oct 2009 20:29:07 -0000 Hi Sylwester, This is interesting, what boards should be supported? (I have a couple of 2d3's) I will be needing something like this for my current project as well. Thanks TJ Sylwester Sosnowski wrote: > Hello, > > I've just written an user-space utility for handling the PC Enginges ALIX' > reset-pushbutton. It's a quick-and-dirty prototype and does the same what > "shutdown -h now" does. I'll do a clean rewrite later. > > Any comments or suggestions appreciated. > > > Here is the prototype: > > ----- BEGIN ----- > > /* > * User-space reset-button support for PC Engines ALIX boards. > * This is a prototype. > * > * Usage: > * Use from rc(8). > */ > > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > > // MY_NAME is the process name used in syslog. > #define MY_NAME "resetguard" > > // GPIO_RESET > u_int32_t switchAddr = 0x61b0; > int switchBit = 8; > > // GPIO_LED3 > u_int32_t ledAddr = 0x6180; > int ledBit = 11; > > > // Blink GPIO_LED3. > void blinkLed(int times) > { > int i; > > for (i=0; i { > outl(ledAddr, 1 << (ledBit + 16)); > usleep(80000); > outl(ledAddr, 1 << ledBit); > usleep(80000); > } > } > > // Return GPIO_RESET state. > char isResetPressed() { > return ((inl(switchAddr) & (1 << switchBit)) == 0); > } > > int main() { > int fd; // Define our file descriptor > char *empty_environ[] = { NULL }; // Environment for halt(8) > > if(geteuid()) > { > errx(1, "You're not super-user."); // Show error and exit. > } > > > fd = open("/dev/io", O_RDONLY); // Read-only file descriptor for /dev/io > > if (fd == -1) { // On error (e.g. wrong permissions) > perror("Cannot open /dev/io."); // Print error message > exit(1); // and exit with status 1 > } > > /* > * At this point we'll be polling the GPIO-Pin of the Reset-button > * at the front of the PC Engines Alix board every 450ms. > * If the pin is HIGH, resetBoard() will be called. > */ > > while(1) // Infinite loop > { > usleep(4000000); // Wait ca. 450ms before probing again > if(isResetPressed()) { // If resetPressed() returns 1.. > blinkLed(4); // Blink GPIO_LED3 4 times > > setlogmask(LOG_UPTO (LOG_NOTICE)); // LOG_NOTICE > > // We'll be logging to LOG_LOCAL1 > openlog(MY_NAME, LOG_CONS | LOG_NDELAY, LOG_LOCAL1); > > // Write message to syslog > syslog(LOG_NOTICE, "Event detected on GPIO_RESET (UID %d)", getuid()); > > // Close Log > closelog(); > > // Halt system (like "shutdown -h now" does) > execle(_PATH_HALT, "halt", "-l", sync, (char *)NULL, empty_environ); > > // Exit with status 0 > exit(0); > } > } > > exit(0); // This should never be reached (exit 0) > } > > > ----- END ----- > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >