read now uses semaphores (and still works ;) )

master
Stefan Krulj 14 years ago
parent 180b078714
commit 5f2ab1f941
  1. 2
      char_dev.c
  2. 3
      gpio_callbacks.c
  3. 4
      usb_gpio.c
  4. 1
      usb_gpio.h

@ -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;
}

@ -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];
}

@ -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;

@ -12,6 +12,7 @@
#include <linux/msg.h>
#include <linux/fs.h>
#include <linux/semaphore.h>
#include <asm/uaccess.h>
#include "usb_gpio_util.h"

Loading…
Cancel
Save