[Armadeus-commitlog] armadeus branch, master, updated. release-3.2-334-ge93ef0a
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2010-05-04 12:45: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 e93ef0a43eec633fcb03a4c345457f89eca6cf9d (commit)
from be149f1fc2815c742bf3ae4c7883c3fab0392730 (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 e93ef0a43eec633fcb03a4c345457f89eca6cf9d
Author: Fabien Marteau <fab...@ar...>
Date: Tue May 4 14:44:53 2010 +0200
[AsDevices] Add blocking read function (not tested), correct indent
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/as_gpio.c | 104 +++++++++++++++++++++++++-------
target/packages/as_devices/c/as_gpio.h | 30 +++++++---
2 files changed, 105 insertions(+), 29 deletions(-)
diff --git a/target/packages/as_devices/c/as_gpio.c b/target/packages/as_devices/c/as_gpio.c
index fe33c73..a2f7916 100644
--- a/target/packages/as_devices/c/as_gpio.c
+++ b/target/packages/as_devices/c/as_gpio.c
@@ -29,17 +29,16 @@
#include <sys/ioctl.h>
#include <linux/ppdev.h>
-#define PORT_SIZE (32)
#define GPIORDDIRECTION _IOR(PP_IOCTL, 0xF0, int)
#define GPIOWRDIRECTION _IOW(PP_IOCTL, 0xF1, int)
-#define GPIORDDATA _IOR(PP_IOCTL, 0xF2, int)
-#define GPIOWRDATA _IOW(PP_IOCTL, 0xF3, int)
-#define GPIORDMODE _IOR(PP_IOCTL, 0xF4, int)
-#define GPIOWRMODE _IOW(PP_IOCTL, 0xF5, int)
+#define GPIORDDATA _IOR(PP_IOCTL, 0xF2, int)
+#define GPIOWRDATA _IOW(PP_IOCTL, 0xF3, int)
+#define GPIORDMODE _IOR(PP_IOCTL, 0xF4, int)
+#define GPIOWRMODE _IOW(PP_IOCTL, 0xF5, int)
-#define GPIORDPULLUP _IOR(PP_IOCTL, 0xF6, int)
-#define GPIOWRPULLUP _IOR(PP_IOCTL, 0xF7, int)
+#define GPIORDPULLUP _IOR(PP_IOCTL, 0xF6, int)
+#define GPIOWRPULLUP _IOR(PP_IOCTL, 0xF7, int)
#define GPIORDIRQMODE_H _IOR(PP_IOCTL, 0xF8, int)
#define GPIORDIRQMODE_L _IOR(PP_IOCTL, 0xF9, int)
@@ -47,6 +46,9 @@
#define GPIOWRIRQMODE_L _IOR(PP_IOCTL, 0xFB, int)
#define GPIO_BASE_PORT ("/dev/gpio/port")
+#define GPIO_BASE_PIN ("/dev/gpio/P")
+
+#define BUFF_SIZE (300)
#ifdef APF9328
# define NUMBER_OF_PORTS 4
@@ -64,6 +66,7 @@ as_gpio_open(char aPortChar)
struct as_gpio_device *dev;
char gpio_file_path[50];
int ret=0;
+ int i;
if (((aPortChar-'A') > (NUMBER_OF_PORTS-1)) || ((aPortChar-'A') < 0))
{
@@ -89,6 +92,11 @@ as_gpio_open(char aPortChar)
dev->port_letter = aPortChar;
dev->fdev = ret;
+ for(i=0; i < PORT_SIZE; i++)
+ {
+ dev->fpin[i] = -1;
+ dev->irq_mode[i] = GPIO_IRQ_MODE_NOINT;
+ }
return dev;
}
@@ -138,9 +146,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)
+as_gpio_set_pin_value(struct as_gpio_device *aDev,
+ int aPinNum,
+ int aValue)
{
int ret=0;
int portval;
@@ -165,8 +173,8 @@ as_gpio_set_pin_value( struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_pin_value( struct as_gpio_device *aDev,
- int aPinNum)
+int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev,
+ int aPinNum)
{
int ret=0;
int portval;
@@ -185,8 +193,30 @@ 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)
+{
+ /* TODO */
+ int ret;
+ char value;
+
+ if ( aPinNum >= PORT_SIZE ) return -1; /* aPinNum wrong */
+ if ( aPinNum < 0 ) return -1;
+
+ if ( aDev->fpin[aPinNum] == -1) return -1; /* irq must be configured before */
+
+ ret = read(aDev->fpin[aPinNum], &value, 1);
+ if ( ret < 0) return ret;
+
+ if (value != 0) return 1;
+ else return 0;
+
+}
+
+/*------------------------------------------------------------------------------*/
+
int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev,
- int aPinNum)
+ int aPinNum)
{
int ret=0;
int portval;
@@ -207,8 +237,8 @@ int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
- int aPinNum,
- int aValue)
+ int aPinNum,
+ int aValue)
{
int ret=0;
int portval;
@@ -234,7 +264,7 @@ int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev,
- int aPinNum)
+ int aPinNum)
{
int ret=0;
int portval;
@@ -269,11 +299,13 @@ int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev,
/*------------------------------------------------------------------------------*/
int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
- int aPinNum,
- int aMode)
+ int aPinNum,
+ int aMode)
{
int ret=0;
+ int i;
int portval;
+ char buffer[BUFF_SIZE];
/* check mode value */
if (aMode > 3)
@@ -315,8 +347,33 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
}
}
- return 0;
+
+ /* close fpin file */
+ if ( (aMode == GPIO_IRQ_MODE_NOINT) && (aDev->fpin[aPinNum] != -1))
+ {
+ close(aDev->fpin[aPinNum]);
+ aDev->fpin[aPinNum] = -1;
+ }
+
+ /* open fpin file */
+ if ( (aMode != GPIO_IRQ_MODE_NOINT) && (aDev->fpin[aPinNum] == -1))
+ {
+ ret = snprintf(buffer, BUFF_SIZE, "%s%c%d",
+ GPIO_BASE_PIN, aDev->port_letter, aPinNum);
+ if ( ret < 0)
+ return ret;
+
+ ret = open(buffer, O_RDONLY);
+ if( ret < 0)
+ return ret;
+
+ aDev->fpin[aPinNum] = ret;
+ }
+
+ aDev->irq_mode[i] = aMode;
+
+ return 0;
}
/*------------------------------------------------------------------------------*/
@@ -324,8 +381,13 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
int32_t
as_gpio_close(struct as_gpio_device *aDev)
{
- int ret;
- ret = close(aDev->fdev);
+ int i;
+ close(aDev->fdev);
+ for (i=0; i < PORT_SIZE; i++)
+ {
+ if (aDev->fpin[i] != -1)
+ close(aDev->fpin[i]);
+ }
free(aDev);
return 0;
}
diff --git a/target/packages/as_devices/c/as_gpio.h b/target/packages/as_devices/c/as_gpio.h
index 2f591fe..edda56b 100644
--- a/target/packages/as_devices/c/as_gpio.h
+++ b/target/packages/as_devices/c/as_gpio.h
@@ -33,14 +33,18 @@ extern "C" {
#define GPIO_IRQ_MODE_FALLING (2)
#define GPIO_IRQ_MODE_BOTH (3)
-//TODO: manage irq
+#define PORT_SIZE (32)
+
+//TODO: test irq
/**
* Store gpio parameters
*/
struct as_gpio_device {
unsigned char port_letter;
- int fdev;
+ int fdev; /* port file */
+ int fpin[PORT_SIZE]; /* pin file for blocking read */
+ int irq_mode[PORT_SIZE];
};
/** @brief Initialize port access
@@ -85,6 +89,16 @@ int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev,
int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev,
int aPinNum);
+/** @brief Get pin value, blocking until interrupt occur
+ *
+ * @param aDev as_gpio_device pointer structure
+ * @param aPinNum pin number
+ *
+ * @return pin value if positive or null, error if negative
+ */
+int32_t as_gpio_blocking_get_pin_value(struct as_gpio_device *aDev,
+ int aPinNum);
+
/** @brief Get pin pull-up value
*
* @param aDev as_gpio_device pointer structure
@@ -93,7 +107,7 @@ int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev,
* @return pin pull up value if positive or null, error if negative
*/
int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev,
- int aPinNum);
+ int aPinNum);
/** @brief Set pin pull-up value
*
@@ -104,8 +118,8 @@ int32_t as_gpio_get_pullup_value(struct as_gpio_device *aDev,
* @return error if negative
*/
int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
- int aPinNum,
- int aValue);
+ int aPinNum,
+ int aValue);
/** @brief Set pin irq mode
*
@@ -116,8 +130,8 @@ int32_t as_gpio_set_pullup_value(struct as_gpio_device *aDev,
* @return error if negative
*/
int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
- int aPinNum,
- int aMode);
+ int aPinNum,
+ int aMode);
/** @brief Get pin irq mode value
*
@@ -127,7 +141,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev,
* @return pin mode value if positive or null, error if negative
*/
int32_t as_gpio_get_irq_mode(struct as_gpio_device *aDev,
- int aPinNum);
+ int aPinNum);
/** @brief Close port access
*
hooks/post-receive
--
armadeus
|