From 5f2ab1f941fa5a9da6b04f4175a2324dd2a2c70b Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Wed, 11 Jul 2012 00:08:55 +0200 Subject: [PATCH] read now uses semaphores (and still works ;) ) --- char_dev.c | 2 +- gpio_callbacks.c | 3 +-- usb_gpio.c | 4 +++- usb_gpio.h | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/char_dev.c b/char_dev.c index ad57e0d..02a19df 100644 --- a/char_dev.c +++ b/char_dev.c @@ -55,7 +55,7 @@ static ssize_t device_write(struct file *filp, const char __user *buff, size_t l printk("<1>%s: Device write error!\n",MOD_NAME); return 0; } - n_written=0; + up(&read_sema); return len; } diff --git a/gpio_callbacks.c b/gpio_callbacks.c index 0043467..3fc5727 100644 --- a/gpio_callbacks.c +++ b/gpio_callbacks.c @@ -5,8 +5,7 @@ static int get_value(struct gpio_chip *gc, unsigned offset){ writeToBuffer(offset); writeToBuffer(CMD_READ); - n_written=1; - while(n_written){}; + down(&read_sema); return pin_status[0]; } diff --git a/usb_gpio.c b/usb_gpio.c index 33b3cb7..cc95a3f 100644 --- a/usb_gpio.c +++ b/usb_gpio.c @@ -2,6 +2,7 @@ static struct gpio_chip ft232_chip; static struct subprocess_info *sub_info; +static struct semaphore read_sema; static char pin_status[1]; static int major; @@ -11,7 +12,6 @@ static uint8_t buff_end; static uint8_t buffer[BUFFER_SIZE]; -static volatile int n_written; #include "char_dev.c" #include "gpio_callbacks.c" @@ -42,6 +42,8 @@ static int usb_gpio_init(void) { printk("<1>%s: Assigned device major #%d minor #0!\n",MOD_NAME,major); printk("<1>%s: Create device file with: \"mknod /dev/usb_gpio c %d 0\"\n",MOD_NAME,major); + sema_init(&read_sema,0); + //GPIO registration ft232_chip.label = MOD_NAME; diff --git a/usb_gpio.h b/usb_gpio.h index 4ba63fc..72188be 100644 --- a/usb_gpio.h +++ b/usb_gpio.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "usb_gpio_util.h"