[Armadeus-commitlog] armadeus branch, master, updated. armadeus-5.0-61-g5313aeb
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2012-10-01 12:16:56
|
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 5313aeb0d07f03441d275cbc8a34c0458b750735 (commit)
via aef9c1ce2a5bb3ff0e8df1f720abced1932fefc3 (commit)
from 96de4fb85b8318aa5c7de239ca58684e24b91891 (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 5313aeb0d07f03441d275cbc8a34c0458b750735
Author: Fabien Marteau <fab...@ar...>
Date: Mon Oct 1 14:13:16 2012 +0200
[as_devices] replace TAB by four spaces
commit aef9c1ce2a5bb3ff0e8df1f720abced1932fefc3
Author: Fabien Marteau <fab...@ar...>
Date: Mon Oct 1 14:12:15 2012 +0200
[as_devices] Fix closing file bug in as_gpio_wait_event, thanks to brett.muir
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/as_gpio.c | 195 ++++++++++++++++----------------
1 files changed, 100 insertions(+), 95 deletions(-)
diff --git a/target/packages/as_devices/c/as_gpio.c b/target/packages/as_devices/c/as_gpio.c
index 9e7748a..adea8a0 100644
--- a/target/packages/as_devices/c/as_gpio.c
+++ b/target/packages/as_devices/c/as_gpio.c
@@ -84,61 +84,61 @@ struct as_gpio_device *as_gpio_open(int aGpioNum)
int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev, char *direction)
{
- char buf[BUFF_SIZE];
- int gpio_fd;
- int ret = 0;
+ char buf[BUFF_SIZE];
+ int gpio_fd;
+ int ret = 0;
if(aDev == NULL){
ERROR("device is NULL\n");
return -EINVAL;
}
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/direction", aDev->port_num);
- gpio_fd = open(buf, O_WRONLY);
- if (gpio_fd < 0) {
- ERROR("Can't open gpio%d direction\n", aDev->port_num);
- return -EINVAL;
- }
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/direction", aDev->port_num);
+ gpio_fd = open(buf, O_WRONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d direction\n", aDev->port_num);
+ return -EINVAL;
+ }
- ret = as_write_buffer_string(gpio_fd, direction);
- if (ret < 0)
- ERROR("Error writing direction\n");
+ ret = as_write_buffer_string(gpio_fd, direction);
+ if (ret < 0)
+ ERROR("Error writing direction\n");
- close(gpio_fd);
+ close(gpio_fd);
- return ret;
+ return ret;
}
/*------------------------------------------------------------------------------*/
const char* as_gpio_get_pin_direction(struct as_gpio_device *aDev)
{
- char buf[BUFF_SIZE];
- static char direction[4];
- FILE *gpio_file;
- int ret = 0;
- static const char none[] = "??";
+ char buf[BUFF_SIZE];
+ static char direction[4];
+ FILE *gpio_file;
+ int ret = 0;
+ static const char none[] = "??";
if(aDev == NULL){
ERROR("device is NULL\n");
return NULL;
}
- snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction",
- aDev->port_num);
- gpio_file = fopen(buf, "r");
- if (!gpio_file) {
- ERROR("Can't open gpio%d direction\n", aDev->port_num);
- return none;
- }
- ret = fscanf(gpio_file, "%s", direction);
- fclose(gpio_file);
- if (ret < 0) {
- ERROR("Can't get gpio%d direction\n", aDev->port_num);
- return none;
- }
-
- return direction;
+ snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction",
+ aDev->port_num);
+ gpio_file = fopen(buf, "r");
+ if (!gpio_file) {
+ ERROR("Can't open gpio%d direction\n", aDev->port_num);
+ return none;
+ }
+ ret = fscanf(gpio_file, "%s", direction);
+ fclose(gpio_file);
+ if (ret < 0) {
+ ERROR("Can't get gpio%d direction\n", aDev->port_num);
+ return none;
+ }
+
+ return direction;
}
/*------------------------------------------------------------------------------*/
@@ -208,100 +208,105 @@ int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev)
int32_t as_gpio_wait_event(struct as_gpio_device *aDev, int delay_ms)
{
- char gpio_sys_name[BUFF_SIZE];
- int gpio_fd;
- struct pollfd poll_set[1];
- int ret;
- char tmp[16];
+ char gpio_sys_name[BUFF_SIZE];
+ int gpio_fd;
+ struct pollfd poll_set[1];
+ int ret;
+ char tmp[16];
if(aDev == NULL){
ERROR("device is NULL\n");
return -EINVAL;
}
- snprintf(gpio_sys_name, BUFF_SIZE, "/sys/class/gpio/gpio%d/value",
- aDev->port_num);
- gpio_fd = open(gpio_sys_name, O_RDONLY);
- if (gpio_fd < 0) {
- ERROR("Can't open gpio%d value\n", aDev->port_num);
- return -EINVAL;
- }
-
- /* flush pending event */
- read(gpio_fd, tmp, sizeof(tmp));
-
- poll_set[0].fd = gpio_fd;
- poll_set[0].events = POLLPRI;
- poll_set[0].revents = 0;
- ret = poll(poll_set, 1, delay_ms);
- if (ret > 0) {
- return read(gpio_fd, tmp, sizeof(tmp));
- } else if (ret < 0) {
- ERROR("poll()");
- return ret;
- }
-
- return -ETIMEDOUT;
+ snprintf(gpio_sys_name, BUFF_SIZE, "/sys/class/gpio/gpio%d/value",
+ aDev->port_num);
+ gpio_fd = open(gpio_sys_name, O_RDONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d value\n", aDev->port_num);
+ return -EINVAL;
+ }
+
+ /* flush pending event */
+ read(gpio_fd, tmp, sizeof(tmp));
+
+ poll_set[0].fd = gpio_fd;
+ poll_set[0].events = POLLPRI;
+ poll_set[0].revents = 0;
+ ret = poll(poll_set, 1, delay_ms);
+ if (ret > 0) {
+ ret = read(gpio_fd, tmp, sizeof(tmp));
+ close(gpio_fd);
+ return ret;
+ } else if (ret < 0) {
+ ERROR("poll()");
+ close(gpio_fd);
+ return ret;
+ }
+
+ /* if ret=0 it's a timeout */
+ close(gpio_fd);
+ return -ETIMEDOUT;
}
/*------------------------------------------------------------------------------*/
const char* as_gpio_get_irq_mode(struct as_gpio_device *aDev)
{
- char buf[BUFF_SIZE];
- static char mode[8];
- FILE *gpio_file;
- int ret = 0;
- static const char unknown[] = "??";
+ char buf[BUFF_SIZE];
+ static char mode[8];
+ FILE *gpio_file;
+ int ret = 0;
+ static const char unknown[] = "??";
if(aDev == NULL){
ERROR("device is NULL\n");
return unknown;
}
- snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/edge", aDev->port_num);
- gpio_file = fopen(buf, "r");
- if (!gpio_file) {
- ERROR("Can't open gpio%d edge\n", aDev->port_num);
- return unknown;
- }
- ret = fscanf(gpio_file, "%s", mode);
- fclose(gpio_file);
- if (ret < 0) {
- ERROR("Can't get gpio%d edge\n", aDev->port_num);
- return unknown;
- }
-
- return mode;
+ snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/edge", aDev->port_num);
+ gpio_file = fopen(buf, "r");
+ if (!gpio_file) {
+ ERROR("Can't open gpio%d edge\n", aDev->port_num);
+ return unknown;
+ }
+ ret = fscanf(gpio_file, "%s", mode);
+ fclose(gpio_file);
+ if (ret < 0) {
+ ERROR("Can't get gpio%d edge\n", aDev->port_num);
+ return unknown;
+ }
+
+ return mode;
}
/*------------------------------------------------------------------------------*/
int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev, char *mode)
{
- char buf[BUFF_SIZE];
- int gpio_fd;
- int ret = 0;
+ char buf[BUFF_SIZE];
+ int gpio_fd;
+ int ret = 0;
if(aDev == NULL){
ERROR("device is NULL\n");
return -EINVAL;
}
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/edge", aDev->port_num);
- gpio_fd = open(buf, O_WRONLY);
- if (gpio_fd < 0) {
- ERROR("Can't open gpio%d edge\n", aDev->port_num);
- return -EINVAL;
- }
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/edge", aDev->port_num);
+ gpio_fd = open(buf, O_WRONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d edge\n", aDev->port_num);
+ return -EINVAL;
+ }
- ret = as_write_buffer_string(gpio_fd, mode);
- if (ret < 0)
- ERROR("Error writing mode\n");
+ ret = as_write_buffer_string(gpio_fd, mode);
+ if (ret < 0)
+ ERROR("Error writing mode\n");
- close(gpio_fd);
+ close(gpio_fd);
- return ret;
+ return ret;
}
/*------------------------------------------------------------------------------*/
hooks/post-receive
--
armadeus
|