mirror of
https://github.com/netbirdio/FreeBSD-ports.git
synced 2026-05-22 18:42:42 -07:00
Importing sysutils/wrapalixresetbutton from pfPorts
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PORTNAME= wrapalixresetbutton
|
||||
PORTVERSION= 0.0.6
|
||||
CATEGORIES= sysutils
|
||||
MASTER_SITES= # empty
|
||||
DISTFILES= # none
|
||||
EXTRACT_ONLY= # empty
|
||||
|
||||
MAINTAINER= garga@pfsense.org
|
||||
COMMENT= Run various pfSense scripts on event
|
||||
|
||||
PLIST_FILES= sbin/wrapresetbtn \
|
||||
sbin/alixresetbtn \
|
||||
sbin/FW7541resetbtn \
|
||||
sbin/APUresetbtn \
|
||||
sbin/RCC-VEresetbtn \
|
||||
sbin/RCC-DFFresetbtn
|
||||
|
||||
ONLY_FOR_ARCHS= i386 amd64
|
||||
|
||||
do-extract:
|
||||
${MKDIR} ${WRKSRC}
|
||||
|
||||
do-build:
|
||||
${CC} ${CFLAGS} -lpthread -o ${WRKSRC}/wrapresetbtn ${FILESDIR}/wrapresetbtn.c
|
||||
${CC} ${CFLAGS} -lpthread -o ${WRKSRC}/alixresetbtn ${FILESDIR}/alixresetbtn.c
|
||||
${CC} ${CFLAGS} -lpthread -o ${WRKSRC}/FW7541resetbtn ${FILESDIR}/FW7541resetbtn.c
|
||||
${CC} ${CFLAGS} -lpthread -o ${WRKSRC}/APUresetbtn ${FILESDIR}/APUresetbtn.c
|
||||
${CC} ${CFLAGS} -lpthread -o ${WRKSRC}/RCC-VEresetbtn ${FILESDIR}/RCC-VE.c
|
||||
|
||||
do-install:
|
||||
${INSTALL_PROGRAM} ${WRKSRC}/wrapresetbtn ${STAGEDIR}${PREFIX}/sbin
|
||||
${INSTALL_PROGRAM} ${WRKSRC}/alixresetbtn ${STAGEDIR}${PREFIX}/sbin
|
||||
${INSTALL_PROGRAM} ${WRKSRC}/FW7541resetbtn ${STAGEDIR}${PREFIX}/sbin
|
||||
${INSTALL_PROGRAM} ${WRKSRC}/APUresetbtn ${STAGEDIR}${PREFIX}/sbin
|
||||
${INSTALL_PROGRAM} ${WRKSRC}/RCC-VEresetbtn ${STAGEDIR}${PREFIX}/sbin
|
||||
${LN} -sf RCC-VEresetbtn ${STAGEDIR}${PREFIX}/sbin/RCC-DFFresetbtn
|
||||
|
||||
.include <bsd.port.mk>
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
Copyright (C) 2014 Ermal Luci
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int iofd, i;
|
||||
u_char ch = 0;
|
||||
|
||||
iofd = open("/dev/gpioapu", O_RDWR);
|
||||
if (iofd == -1) {
|
||||
perror("cannot open /dev/gpioapu");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* check whether the switch S1 is pressed */
|
||||
read(iofd, &ch, sizeof(ch));
|
||||
if (ch == '1') {
|
||||
/* nothing to do */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* wait for 2 seconds and make sure that the switch is
|
||||
pressed all the time */
|
||||
for (i = 0; i < 20; i++) {
|
||||
usleep(100000);
|
||||
read(iofd, &ch, sizeof(ch));
|
||||
if (ch == '1') {
|
||||
/* switch was released too soon */
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
/* blink all three LEDs five times to indicate reset */
|
||||
for (i = 0; i < 5; i++) {
|
||||
write(iofd, "111", strlen("111"));
|
||||
usleep(300000);
|
||||
write(iofd, "000", strlen("000"));
|
||||
usleep(300000);
|
||||
}
|
||||
|
||||
/* restore normal LED state */
|
||||
write(iofd, "100", strlen("100"));
|
||||
|
||||
close(iofd);
|
||||
|
||||
/* return special code 99 to indicate factory defaults should be loaded */
|
||||
exit(99);
|
||||
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
Copyright (C) 2014 Ermal Luci
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
|
||||
btn_tst.c: main application for Lanner platform Software Button program
|
||||
|
||||
Lanner Platform Miscellaneous Utility
|
||||
Copyright(c) 2010 Lanner Electronics Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer,
|
||||
without modification.
|
||||
2. Redistributions in binary form must reproduce at minimum a disclaimer
|
||||
similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
|
||||
redistribution must be conditioned upon including a substantially
|
||||
similar Disclaimer requirement for further binary redistribution.
|
||||
3. Neither the names of the above-listed copyright holders nor the names
|
||||
of any contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
Alternatively, this software may be distributed under the terms of the
|
||||
GNU General Public License ("GPL") version 2 as published by the Free
|
||||
Software Foundation.
|
||||
|
||||
NO WARRANTY
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/*
|
||||
* Platform Depend GPIOs for Status LEDs
|
||||
*/
|
||||
|
||||
/*
|
||||
*------------------------------------------------------------------------------
|
||||
* MB-7541 Version V1.0
|
||||
*
|
||||
* The IO interface for Status LED is connected to Winbond SIO 83627 GPIO 31 32
|
||||
* Refer to Winbond 83627 datasheet for details.
|
||||
* The truth table is defined as below:
|
||||
* GPIO31 GPIO32 LED_STATUS
|
||||
* 0 0 OFF
|
||||
* 0 1 Red
|
||||
* 1 0 GREEN
|
||||
* 1 1 OFF
|
||||
*------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Device Depend Definition : Winbond 83627 SIO
|
||||
*/
|
||||
#define INDEX_PORT 0x2E
|
||||
#define DATA_PORT 0x2F
|
||||
|
||||
|
||||
#define GPIO31_BIT (1 << 1)
|
||||
#define GPIO32_BIT (1 << 2)
|
||||
#define GPIO_GPIO31_GPIO32_MASK (GPIO31_BIT | GPIO32_BIT)
|
||||
#define LED_OFF 0
|
||||
#define LED_RED GPIO32_BIT
|
||||
#define LED_GREEN GPIO31_BIT
|
||||
|
||||
/*
|
||||
* Platform Depend GPIOs for Reset Button
|
||||
*/
|
||||
|
||||
/*
|
||||
*------------------------------------------------------------------------------
|
||||
* MB-7541 Version V 0.1
|
||||
*
|
||||
* The IO interface for Reset Button is connected to Intel ICH8-M GPIO 20.
|
||||
* Refer to Intel ICH8-M datasheet for details.
|
||||
* The high/low definition is as below:
|
||||
* GPIO20 Button Status
|
||||
* --------------------------
|
||||
* 1 Button Pressed
|
||||
* 0 Button Released
|
||||
*------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Device Depend Definition : Intel ICH8-M chipset
|
||||
*/
|
||||
#define SB_GPIO_PORT_BASE 0x500
|
||||
#define SB_GPIO_PORT_USE_SEL 0x2
|
||||
#define SB_GPIO_PORT_IO_SEL 0x6
|
||||
#define SB_GPIO_PORT_OFFSET 0xE
|
||||
#define SB_GPIO_PORT_REG SB_GPIO_PORT_BASE+SB_GPIO_PORT_OFFSET
|
||||
|
||||
#define GPIO20_BIT (1 << 4)
|
||||
|
||||
#define STATUS_BITMASK GPIO20_BIT
|
||||
#define STATUS_PRESSED 0
|
||||
#define STATUS_RELEASED GPIO20_BIT
|
||||
|
||||
/*
|
||||
* Return value:
|
||||
* 0: BUTTON Pressed
|
||||
* 1: BUTTON Released
|
||||
*/
|
||||
static unsigned char
|
||||
get_btn_status(void)
|
||||
{
|
||||
return ( inb(SB_GPIO_PORT_REG) & STATUS_BITMASK);
|
||||
}
|
||||
|
||||
static void
|
||||
enter_w83627_config(void)
|
||||
{
|
||||
outb(INDEX_PORT, 0x87); // Must Do It Twice
|
||||
outb(INDEX_PORT, 0x87);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
exit_w83627_config(void)
|
||||
{
|
||||
outb(INDEX_PORT, 0xAA);
|
||||
return;
|
||||
}
|
||||
|
||||
static unsigned char
|
||||
read_w83627_reg(int LDN, int reg)
|
||||
{
|
||||
unsigned char tmp = 0;
|
||||
|
||||
enter_w83627_config();
|
||||
outb(INDEX_PORT, 0x07); // LDN Register
|
||||
outb(DATA_PORT, LDN); // Select LDNx
|
||||
outb(INDEX_PORT, reg); // Select Register
|
||||
tmp = inb( DATA_PORT); // Read Register
|
||||
exit_w83627_config();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
write_w83627_reg(int LDN, int reg, int value)
|
||||
{
|
||||
enter_w83627_config();
|
||||
outb(INDEX_PORT, 0x07); // LDN Register
|
||||
outb(DATA_PORT, LDN); // Select LDNx
|
||||
outb(INDEX_PORT, reg); // Select Register
|
||||
outb(DATA_PORT, value); // Write Register
|
||||
exit_w83627_config();
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
led_on()
|
||||
{
|
||||
unsigned char tmp;
|
||||
|
||||
tmp=read_w83627_reg(0x09, 0xF1);
|
||||
tmp &= ~(GPIO_GPIO31_GPIO32_MASK);
|
||||
tmp |= LED_GREEN;
|
||||
write_w83627_reg(0x09, 0xF1, tmp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
led_off()
|
||||
{
|
||||
unsigned char tmp;
|
||||
|
||||
tmp = read_w83627_reg(0x09, 0xF1);
|
||||
tmp &= ~(GPIO_GPIO31_GPIO32_MASK);
|
||||
tmp |= LED_OFF;
|
||||
write_w83627_reg(0x09, 0xF1, tmp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
sled_gpio_init(void)
|
||||
{
|
||||
unsigned char tmp;
|
||||
|
||||
/* set GP31/32 as Output function */
|
||||
tmp = read_w83627_reg(0x09, 0x30);
|
||||
tmp |= 0x02;
|
||||
write_w83627_reg(0x09, 0x30, tmp);
|
||||
/* set GP31/32 as Output function */
|
||||
tmp=read_w83627_reg(0x09, 0xF0);
|
||||
tmp &= ~(GPIO_GPIO31_GPIO32_MASK);
|
||||
write_w83627_reg(0x09, 0xF0, tmp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
btn_gpio_init(void)
|
||||
{
|
||||
unsigned char tmp;
|
||||
/* platform initial code */
|
||||
|
||||
/* Reset button initial function */
|
||||
|
||||
/* select GPIO function */
|
||||
tmp= inb(SB_GPIO_PORT_BASE+SB_GPIO_PORT_USE_SEL);
|
||||
tmp |= GPIO20_BIT;
|
||||
outb(SB_GPIO_PORT_BASE+SB_GPIO_PORT_USE_SEL, tmp);
|
||||
|
||||
/* set to input mode */
|
||||
tmp= inb(SB_GPIO_PORT_BASE+SB_GPIO_PORT_IO_SEL);
|
||||
tmp |= GPIO20_BIT;
|
||||
outb(SB_GPIO_PORT_BASE+SB_GPIO_PORT_IO_SEL, tmp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int iofd, i;
|
||||
|
||||
iofd = open("/dev/io", O_RDONLY);
|
||||
if (iofd == -1) {
|
||||
perror("cannot open /dev/io");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
btn_gpio_init();
|
||||
|
||||
/* check whether the switch S1 is pressed */
|
||||
if (get_btn_status() != STATUS_PRESSED) {
|
||||
/* nothing to do */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* wait for 2 seconds and make sure that the switch is
|
||||
pressed all the time */
|
||||
for (i = 0; i < 20; i++) {
|
||||
usleep(100000);
|
||||
if (get_btn_status() != STATUS_PRESSED) {
|
||||
/* switch was released too soon */
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
sled_gpio_init();
|
||||
|
||||
/* blink all three LEDs five times to indicate reset */
|
||||
for (i = 0; i < 5; i++) {
|
||||
led_on();
|
||||
usleep(300000);
|
||||
led_off();
|
||||
usleep(300000);
|
||||
}
|
||||
|
||||
/* restore normal LED state */
|
||||
led_off();
|
||||
|
||||
close(iofd);
|
||||
|
||||
/* return special code 99 to indicate factory defaults should be loaded */
|
||||
exit(99);
|
||||
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
Copyright (C) 2015 Ermal LUÇI
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/pciio.h>
|
||||
|
||||
#define GPIOBASE 0x0500
|
||||
#define GPIO_SC_USE_SEL (GPIOBASE + 0x00)
|
||||
#define GPIO_SC_IO_SEL (GPIOBASE + 0x04)
|
||||
#define GPIO_SC_GP_LVL (GPIOBASE + 0x08)
|
||||
|
||||
int switch_gpio = 11;
|
||||
int led_gpio = 15;
|
||||
|
||||
static int gpio_read(int reg, int gpio) {
|
||||
int c;
|
||||
|
||||
c = inl(reg);
|
||||
if (c & (1 << gpio))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gpio_write(int reg, int gpio, int on) {
|
||||
int c;
|
||||
|
||||
c = inl(reg);
|
||||
if (on)
|
||||
c |= (1 << gpio);
|
||||
else
|
||||
c &= ~(1 << gpio);
|
||||
outl(reg, c);
|
||||
}
|
||||
|
||||
static void led_on() {
|
||||
gpio_write(GPIO_SC_GP_LVL, led_gpio, 1);
|
||||
}
|
||||
|
||||
static void led_off() {
|
||||
gpio_write(GPIO_SC_GP_LVL, led_gpio, 0);
|
||||
}
|
||||
|
||||
static char is_switch_pressed() {
|
||||
return (gpio_read(GPIO_SC_GP_LVL, switch_gpio) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int iofd, i;
|
||||
|
||||
iofd = open("/dev/io", O_RDONLY);
|
||||
if (iofd == -1) {
|
||||
perror("cannot open /dev/io");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("GPIO_SC_USE_SEL: %x\n", inl(GPIO_SC_USE_SEL));
|
||||
printf("GPIO_SC_IO_SEL: %x\n", inl(GPIO_SC_IO_SEL));
|
||||
printf("SC_GP_LVL: %x\n", inl(GPIO_SC_GP_LVL));
|
||||
#endif
|
||||
|
||||
/* Check if the pin is configured for GPIO */
|
||||
if (!gpio_read(GPIO_SC_USE_SEL, switch_gpio)) {
|
||||
/* Enable it for GPIO */
|
||||
gpio_write(GPIO_SC_USE_SEL, switch_gpio, 1);
|
||||
gpio_write(GPIO_SC_IO_SEL, switch_gpio, 1);
|
||||
#ifdef DEBUG
|
||||
printf("GPIO_SC_USE_SEL: %x\n", inl(GPIO_SC_USE_SEL));
|
||||
printf("GPIO_SC_IO_SEL: %x\n", inl(GPIO_SC_IO_SEL));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* check whether the switch S1 is pressed */
|
||||
if (!is_switch_pressed()) {
|
||||
/* Disable for GPIO */
|
||||
gpio_write(GPIO_SC_USE_SEL, switch_gpio, 0);
|
||||
gpio_write(GPIO_SC_IO_SEL, switch_gpio, 0);
|
||||
#ifdef DEBUG
|
||||
printf("GPIO_SC_USE_SEL: %x\n", inl(GPIO_SC_USE_SEL));
|
||||
printf("GPIO_SC_IO_SEL: %x\n", inl(GPIO_SC_IO_SEL));
|
||||
#endif
|
||||
|
||||
/* nothing to do */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* wait for 2 seconds and make sure that the switch is
|
||||
pressed all the time */
|
||||
for (i = 0; i < 20; i++) {
|
||||
usleep(100000);
|
||||
if (!is_switch_pressed()) {
|
||||
/* switch was released too soon */
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
gpio_write(GPIO_SC_IO_SEL, led_gpio, 1);
|
||||
/* blink all three LEDs five times to indicate reset */
|
||||
for (i = 0; i < 5; i++) {
|
||||
led_on();
|
||||
usleep(300000);
|
||||
led_off();
|
||||
usleep(300000);
|
||||
}
|
||||
|
||||
led_off();
|
||||
|
||||
/* Disable for GPIO */
|
||||
gpio_write(GPIO_SC_USE_SEL, switch_gpio, 0);
|
||||
gpio_write(GPIO_SC_IO_SEL, switch_gpio, 0);
|
||||
gpio_write(GPIO_SC_IO_SEL, led_gpio, 0);
|
||||
#ifdef DEBUG
|
||||
printf("GPIO_SC_USE_SEL: %x\n", inl(GPIO_SC_USE_SEL));
|
||||
printf("GPIO_SC_IO_SEL: %x\n", inl(GPIO_SC_IO_SEL));
|
||||
#endif
|
||||
|
||||
close(iofd);
|
||||
|
||||
/* return special code 99 to indicate factory defaults should be loaded */
|
||||
exit(99);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
$Id$
|
||||
part of m0n0wall (http://m0n0.ch/wall)
|
||||
|
||||
Copyright (C) 2007 Manuel Kasper <mk@neon1.net>.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/* GPIO ports for LEDs */
|
||||
u_int32_t led_ports[3] = {0x6100, 0x6180, 0x6180};
|
||||
int led_bits[3] = {6, 9, 11};
|
||||
u_int32_t switch_port = 0x61b0;
|
||||
int switch_bit = 8;
|
||||
|
||||
void led_on(int i) {
|
||||
outl(led_ports[i], 1 << (led_bits[i] + 16));
|
||||
}
|
||||
|
||||
void led_off(int i) {
|
||||
outl(led_ports[i], 1 << led_bits[i]);
|
||||
}
|
||||
|
||||
char is_switch_pressed() {
|
||||
return ((inl(switch_port) & (1 << switch_bit)) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int iofd, i;
|
||||
|
||||
iofd = open("/dev/io", O_RDONLY);
|
||||
if (iofd == -1) {
|
||||
perror("cannot open /dev/io");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* check whether the switch S1 is pressed */
|
||||
if (!is_switch_pressed()) {
|
||||
/* nothing to do */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* wait for 2 seconds and make sure that the switch is
|
||||
pressed all the time */
|
||||
for (i = 0; i < 20; i++) {
|
||||
usleep(100000);
|
||||
if (!is_switch_pressed()) {
|
||||
/* switch was released too soon */
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
/* blink all three LEDs five times to indicate reset */
|
||||
for (i = 0; i < 5; i++) {
|
||||
led_on(0); led_on(1); led_on(2);
|
||||
usleep(300000);
|
||||
led_off(0); led_off(1); led_off(2);
|
||||
usleep(300000);
|
||||
}
|
||||
|
||||
/* restore normal LED state */
|
||||
led_on(0);
|
||||
|
||||
close(iofd);
|
||||
|
||||
/* return special code 99 to indicate factory defaults should be loaded */
|
||||
exit(99);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
$Id$
|
||||
part of m0n0wall (http://m0n0.ch/wall)
|
||||
|
||||
Copyright (C) 2007 Manuel Kasper <mk@neon1.net>.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define GCBBASE 0x9000
|
||||
#define PMRADDR (GCBBASE + 0x30)
|
||||
#define GPIOBASE 0xF400
|
||||
#define GPIO_SCSR (GPIOBASE + 0x20)
|
||||
#define GPIO_SCAR (GPIOBASE + 0x24)
|
||||
|
||||
/* GPIOs for LEDs */
|
||||
int led_gpio[3] = {2, 3, 18};
|
||||
int switch_gpio = 40;
|
||||
|
||||
int gpio_read(int gpio) {
|
||||
|
||||
u_int32_t offset = 0x04;
|
||||
u_int32_t c;
|
||||
|
||||
if (gpio >= 32) {
|
||||
offset = 0x14;
|
||||
gpio -= 32;
|
||||
}
|
||||
|
||||
c = inl(GPIOBASE + offset);
|
||||
if (c & (1 << gpio))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gpio_write(int gpio, int on) {
|
||||
|
||||
u_int32_t offset = 0x00;
|
||||
u_int32_t c;
|
||||
|
||||
if (gpio >= 32) {
|
||||
offset = 0x10;
|
||||
gpio -= 32;
|
||||
}
|
||||
|
||||
c = inl(GPIOBASE + offset);
|
||||
if (on)
|
||||
c |= (1 << gpio);
|
||||
else
|
||||
c &= ~(1 << gpio);
|
||||
outl(GPIOBASE + offset, c);
|
||||
}
|
||||
|
||||
|
||||
void led_on(int i) {
|
||||
gpio_write(led_gpio[i], 0);
|
||||
}
|
||||
|
||||
void led_off(int i) {
|
||||
gpio_write(led_gpio[i], 1);
|
||||
}
|
||||
|
||||
char is_switch_pressed() {
|
||||
return (gpio_read(switch_gpio) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int iofd, i;
|
||||
|
||||
iofd = open("/dev/io", O_RDONLY);
|
||||
if (iofd == -1) {
|
||||
perror("cannot open /dev/io");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* check whether the switch S1 is pressed */
|
||||
if (!is_switch_pressed()) {
|
||||
/* nothing to do */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* wait for 2 seconds and make sure that the switch is
|
||||
pressed all the time */
|
||||
for (i = 0; i < 20; i++) {
|
||||
usleep(100000);
|
||||
if (!is_switch_pressed()) {
|
||||
/* switch was released too soon */
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
/* blink all three LEDs five times to indicate reset */
|
||||
for (i = 0; i < 5; i++) {
|
||||
led_on(0); led_on(1); led_on(2);
|
||||
usleep(300000);
|
||||
led_off(0); led_off(1); led_off(2);
|
||||
usleep(300000);
|
||||
}
|
||||
|
||||
/* restore normal LED state */
|
||||
led_on(0);
|
||||
|
||||
close(iofd);
|
||||
|
||||
/* return special code 99 to indicate factory defaults should be loaded */
|
||||
exit(99);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Daemon to detect button press on alix and wrap that spawns a config reset.
|
||||
Reference in New Issue
Block a user