[Armadeus-commitlog] armadeus branch, master, updated. release-3.2-398-g34c7c2d
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2010-06-03 15:47:26
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via 34c7c2ddbe769c3cfd041e782f6d8bee1f7f59bb (commit)
via 722ddfd1db7938a18cf26036e4b1c9f033a2d036 (commit)
via 92b802738699d0df30d0f1cc78e748cb37796f64 (commit)
via 85879ff87b4be857cd6f2bda99ba8a33d5b49932 (commit)
from a2a46d3af3ae68e818466187cf83990fb096440c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 34c7c2ddbe769c3cfd041e782f6d8bee1f7f59bb
Merge: 722ddfd1db7938a18cf26036e4b1c9f033a2d036 a2a46d3af3ae68e818466187cf83990fb096440c
Author: Fabien Marteau <fab...@ar...>
Date: Thu Jun 3 17:46:46 2010 +0200
Merge branch 'master' of git://armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 722ddfd1db7938a18cf26036e4b1c9f033a2d036
Author: Fabien Marteau <fab...@ar...>
Date: Thu Jun 3 17:46:23 2010 +0200
[as_devices] adding timeout for blocking read
commit 92b802738699d0df30d0f1cc78e748cb37796f64
Author: Fabien Marteau <fab...@ar...>
Date: Thu Jun 3 17:44:38 2010 +0200
[kernel] adding poll capability in gpio driver (for select() )
commit 85879ff87b4be857cd6f2bda99ba8a33d5b49932
Author: Fabien Marteau <fab...@ar...>
Date: Thu Jun 3 11:52:41 2010 +0200
[kernel] Adding interrupt status read/write capability on gpio driver
-----------------------------------------------------------------------
Summary of changes:
target/linux/modules/gpio/core.c | 48 ++++++++++-
target/linux/modules/gpio/core.h | 9 ++-
target/packages/as_devices/c/as_gpio.c | 141 +++++++++++++++++++++-----------
target/packages/as_devices/c/as_gpio.h | 8 ++-
target/packages/as_devices/test_c.h | 4 +-
5 files changed, 150 insertions(+), 60 deletions(-)
diff --git a/target/linux/modules/gpio/core.c b/target/linux/modules/gpio/core.c
index b07c7ef..6296a0a 100755
--- a/target/linux/modules/gpio/core.c
+++ b/target/linux/modules/gpio/core.c
@@ -35,6 +35,7 @@
#include <linux/cdev.h> /* struct cdev */
#include <mach/hardware.h>
#include <asm/mach/map.h>
+#include <linux/poll.h>
#ifdef CONFIG_ARCH_MX2
#include <mach/iomux-mx1-mx2.h>
#endif
@@ -390,9 +391,20 @@ static unsigned int get_port_mode(unsigned int aPort)
return value;
}
+
+static unsigned int get_port_isr(unsigned int aPort)
+{
+ return __raw_readl(VA_GPIO_BASE + MXC_ISR(aPort));
+}
+
+static void set_port_isr(unsigned int aPort, unsigned int aIsr)
+{
+ __raw_writel(aIsr & 0xffffffff, VA_GPIO_BASE + MXC_ISR(aPort));
+}
+
static unsigned int get_port_pull_up(unsigned int aPort)
{
- return __raw_readl(VA_GPIO_BASE + MXC_PUEN(aPort));
+ return __raw_readl(VA_GPIO_BASE + MXC_PUEN(aPort));
}
static void set_port_pullup(unsigned int aPort, unsigned int aPullMask)
@@ -538,7 +550,6 @@ static irqreturn_t armadeus_gpio_interrupt(int irq, void *dev_id)
return IRQ_HANDLED;
}
-/* Handles open() done on /dev/gpioxx */
static int armadeus_gpio_dev_open(struct inode *inode, struct file *file)
{
unsigned minor = MINOR(inode->i_rdev);
@@ -764,6 +775,18 @@ int armadeus_gpio_dev_ioctl(struct inode *inode, struct file *filp,
}
break;
+ case GPIORDISR:
+ value = get_port_isr(MAX_MINOR - minor);
+ ret = __put_user(value, (unsigned int *)arg);
+ break;
+
+ case GPIOWRISR:
+ ret = __get_user(value, (unsigned int *)arg);
+ if (ret == 0) {
+ set_port_isr(MAX_MINOR - minor, value);
+ }
+ break;
+
default:
printk("IOCTL not supported\n");
ret = -ENOTTY;
@@ -776,13 +799,29 @@ out:
return ret;
}
-static int armadeus_gpio_fasync(int fd, struct file* filp, int on)
+static int armadeus_gpio_dev_fasync(int fd, struct file* filp, int on)
{
struct gpio_item* gpio = filp->private_data;
return fasync_helper(fd, filp, on, &(gpio->async_queue));
}
+static unsigned int armadeus_gpio_dev_poll(struct file *filp, poll_table *wait)
+{
+ struct gpio_item *gpio = filp->private_data;
+ unsigned int mask = 0;
+
+ spin_lock_irq(&gpio->lock);
+
+ poll_wait(filp, &gpio->change_wq, wait);
+ if (gpio->changed)
+ {
+ mask |= (POLLIN | POLLRDNORM);
+ }
+ spin_unlock_irq(&gpio->lock);
+ return mask;
+}
+
static struct file_operations gpio_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
@@ -791,7 +830,8 @@ static struct file_operations gpio_fops = {
.open = armadeus_gpio_dev_open,
.release = armadeus_gpio_dev_release,
.ioctl = armadeus_gpio_dev_ioctl,
- .fasync = armadeus_gpio_fasync,
+ .fasync = armadeus_gpio_dev_fasync,
+ .poll = armadeus_gpio_dev_poll,
};
diff --git a/target/linux/modules/gpio/core.h b/target/linux/modules/gpio/core.h
index 9307e45..7262961 100755
--- a/target/linux/modules/gpio/core.h
+++ b/target/linux/modules/gpio/core.h
@@ -38,12 +38,15 @@
#define GPIOWRMODE _IOW(PP_IOCTL, 0xF5, int)
#define GPIORDPULLUP _IOR(PP_IOCTL, 0xF6, int)
-#define GPIOWRPULLUP _IOR(PP_IOCTL, 0xF7, int)
+#define GPIOWRPULLUP _IOW(PP_IOCTL, 0xF7, int)
#define GPIORDIRQMODE_H _IOR(PP_IOCTL, 0xF8, int)
#define GPIORDIRQMODE_L _IOR(PP_IOCTL, 0xF9, int)
-#define GPIOWRIRQMODE_H _IOR(PP_IOCTL, 0xFA, int)
-#define GPIOWRIRQMODE_L _IOR(PP_IOCTL, 0xFB, int)
+#define GPIOWRIRQMODE_H _IOW(PP_IOCTL, 0xFA, int)
+#define GPIOWRIRQMODE_L _IOW(PP_IOCTL, 0xFB, int)
+
+#define GPIORDISR _IOR(PP_IOCTL, 0xFC, int)
+#define GPIOWRISR _IOW(PP_IOCTL, 0xFD, int)
/* Pretend we're PPDEV for IOCTL */
#include <linux/ppdev.h>
diff --git a/target/packages/as_devices/c/as_gpio.c b/target/packages/as_devices/c/as_gpio.c
index 737af96..eef3f1e 100644
--- a/target/packages/as_devices/c/as_gpio.c
+++ b/target/packages/as_devices/c/as_gpio.c
@@ -1,23 +1,23 @@
/*
-** The ARMadeus Project
-**
-** Copyright (C) 2009-2010 The armadeus systems team
-** Fabien Marteau <fab...@ar...>
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License as published by the Free Software Foundation; either
-** version 2.1 of the License, or (at your option) any later version.
-**
-** This library is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-** Lesser General Public License for more details.
-**
-** You should have received a copy of the GNU Lesser General Public
-** License along with this library; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
+ ** The ARMadeus Project
+ **
+ ** Copyright (C) 2009-2010 The armadeus systems team
+ ** Fabien Marteau <fab...@ar...>
+ **
+ ** This library is free software; you can redistribute it and/or
+ ** modify it under the terms of the GNU Lesser General Public
+ ** License as published by the Free Software Foundation; either
+ ** version 2.1 of the License, or (at your option) any later version.
+ **
+ ** This library is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ** Lesser General Public License for more details.
+ **
+ ** You should have received a copy of the GNU Lesser General Public
+ ** License along with this library; if not, write to the Free Software
+ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
#include "as_gpio.h"
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h> /* for close() */
+#include <sys/select.h>
#include <sys/ioctl.h>
#include <linux/ppdev.h>
@@ -38,12 +39,15 @@
#define GPIOWRMODE _IOW(PP_IOCTL, 0xF5, int)
#define GPIORDPULLUP _IOR(PP_IOCTL, 0xF6, int)
-#define GPIOWRPULLUP _IOR(PP_IOCTL, 0xF7, int)
+#define GPIOWRPULLUP _IOW(PP_IOCTL, 0xF7, int)
#define GPIORDIRQMODE_H _IOR(PP_IOCTL, 0xF8, int)
#define GPIORDIRQMODE_L _IOR(PP_IOCTL, 0xF9, int)
-#define GPIOWRIRQMODE_H _IOR(PP_IOCTL, 0xFA, int)
-#define GPIOWRIRQMODE_L _IOR(PP_IOCTL, 0xFB, int)
+#define GPIOWRIRQMODE_H _IOW(PP_IOCTL, 0xFA, int)
+#define GPIOWRIRQMODE_L _IOW(PP_IOCTL, 0xFB, int)
+
+#define GPIORDISR _IOR(PP_IOCTL, 0xFC, int)
+#define GPIOWRISR _IOW(PP_IOCTL, 0xFD, int)
#define GPIO_BASE_PORT ("/dev/gpio/port")
#define GPIO_BASE_PIN ("/dev/gpio/P")
@@ -67,8 +71,7 @@
/*------------------------------------------------------------------------------*/
-struct as_gpio_device *
-as_gpio_open(char aPortChar)
+struct as_gpio_device *as_gpio_open(char aPortChar)
{
struct as_gpio_device *dev;
char gpio_file_path[50];
@@ -83,7 +86,7 @@ as_gpio_open(char aPortChar)
/* make gpio port string path */
ret = snprintf(gpio_file_path,50, "%s%c",
- GPIO_BASE_PORT, aPortChar);
+ GPIO_BASE_PORT, aPortChar);
if (ret < 0) {
ERROR("Can't forge gpio port path\n");
return NULL;
@@ -116,10 +119,9 @@ as_gpio_open(char aPortChar)
/*------------------------------------------------------------------------------*/
-int32_t
-as_gpio_set_pin_direction(struct as_gpio_device *aDev,
- int aPinNum,
- int aDirection)
+int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev,
+ int aPinNum,
+ int aDirection)
{
int ret=0;
int portval;
@@ -162,10 +164,9 @@ as_gpio_set_pin_direction(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
-int32_t
-as_gpio_set_pin_value(struct as_gpio_device *aDev,
- int aPinNum,
- int aValue)
+int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev,
+ int aPinNum,
+ int aValue)
{
int ret=0;
int portval;
@@ -214,15 +215,22 @@ int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
- int aPinNum)
+ int aPinNum,
+ int aDelay_s,
+ int aDelay_us)
{
int ret;
char value;
+ fd_set rfds;
+ struct timeval tv;
+ int retval;
+
+
if (aPinNum >= PORT_SIZE )
{
ERROR("Pin num %d upper than port size (%d)\n", aPinNum, PORT_SIZE);
- return -1; /* aPinNum wrong */
+ return -1;
}
if (aPinNum < 0 )
{
@@ -236,17 +244,32 @@ int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
return -1;
}
- ret = read(aDev->fpin[aPinNum], &value, 1);
- if (ret < 0)
+ FD_ZERO(&rfds);
+ FD_SET(aDev->fpin[aPinNum], &rfds);
+
+ tv.tv_sec = aDelay_s;
+ tv.tv_usec = aDelay_us;
+
+ /* flush the file */
+ retval = select(aDev->fpin[aPinNum]+1, &rfds, NULL, NULL, &tv);
+ if (retval > 0)
{
- ERROR("can't read pin %d value \n",aPinNum);
- return ret;
+ printf("DEBUG: read value\n");
+ ret = read(aDev->fpin[aPinNum], &value, 1);
+ if (ret < 0)
+ {
+ ERROR("Can't read pin value\n");
+ return -1;
+ }
+ if (value != 0)
+ return 1;
+ else return 0;
+ } else if (retval == 0) {
+ return -10;
+ } else {
+ return -1;
}
- if (value != 0)
- return 1;
- else return 0;
-
}
/*------------------------------------------------------------------------------*/
@@ -350,6 +373,11 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
int portval;
char buffer[BUFF_SIZE];
+ fd_set rfds;
+ struct timeval tv;
+ int retval;
+
+
/* check mode value */
if (aMode > 3)
{
@@ -361,7 +389,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
if (aPinNum >= PORT_SIZE)
{
ERROR("Pin num %d upper than port size (%d)\n", aPinNum, PORT_SIZE);
- return -1;
+ return -2;
}
/* close fpin file */
@@ -388,7 +416,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
return ret;
}
-} else {
+ } else {
ret = ioctl(aDev->fdev, GPIORDIRQMODE_H, &portval);
if (ret < 0) {
@@ -406,11 +434,11 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
}
}
- /* open fpin file */
if ((aMode != GPIO_IRQ_MODE_NOINT) && (aDev->fpin[aPinNum] == -1))
{
+ /* open fpin file */
ret = snprintf(buffer, BUFF_SIZE, "%s%c%d",
- GPIO_BASE_PIN, aDev->port_letter, aPinNum);
+ GPIO_BASE_PIN, aDev->port_letter, aPinNum);
if (ret < 0)
{
ERROR("Can't forge fpin path\n");
@@ -424,6 +452,22 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
return ret;
}
aDev->fpin[aPinNum] = ret;
+
+ }
+
+
+ FD_ZERO(&rfds);
+ FD_SET(aDev->fpin[aPinNum], &rfds);
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 1;
+
+
+ /* flush the file */
+ retval = select(aDev->fpin[aPinNum]+1, &rfds, NULL, NULL, &tv);
+ if (retval)
+ {
+ read(aDev->fpin[aPinNum], buffer, BUFF_SIZE);
}
aDev->irq_mode[aPinNum] = aMode;
@@ -432,8 +476,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
-int32_t
-as_gpio_close(struct as_gpio_device *aDev)
+int32_t as_gpio_close(struct as_gpio_device *aDev)
{
int i;
close(aDev->fdev);
diff --git a/target/packages/as_devices/c/as_gpio.h b/target/packages/as_devices/c/as_gpio.h
index edda56b..d644511 100644
--- a/target/packages/as_devices/c/as_gpio.h
+++ b/target/packages/as_devices/c/as_gpio.h
@@ -93,11 +93,15 @@ int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev,
*
* @param aDev as_gpio_device pointer structure
* @param aPinNum pin number
+ * @param aDelay_s waiting delay in seconds
+ * @param aDelay_us waiting delay in useconds (plus delay in seconds)
*
- * @return pin value if positive or null, error if negative
+ * @return pin value if positive or null, read error if -1, timeout if -10
*/
int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
- int aPinNum);
+ int aPinNum,
+ int aDelay_s,
+ int aDelay_us);
/** @brief Get pin pull-up value
*
diff --git a/target/packages/as_devices/test_c.h b/target/packages/as_devices/test_c.h
index b763ed6..04fa50c 100644
--- a/target/packages/as_devices/test_c.h
+++ b/target/packages/as_devices/test_c.h
@@ -437,7 +437,7 @@ void test_gpio()
char c_value;
int32_t value;
char port_letter = 'F';
- int pin_num = 14;
+ int pin_num = 13;
int port_direction = 0;
int port_value = 1;
int pullup=1;
@@ -621,7 +621,7 @@ void test_gpio()
pressEnterToContinue();
break;
case 'a' : printf("Blocking read \n");
- ret = as_gpio_blocking_get_pin_value(gpio_dev, pin_num);
+ ret = as_gpio_blocking_get_pin_value(gpio_dev, pin_num, 10, 0);
if (ret < 0)
{
printf("Error, can't read value\n");
hooks/post-receive
--
armadeus
|