Read works now but uses git statusbusy waitgit status

master
Stefan Krulj 14 years ago
parent f530fb60c9
commit 180b078714
  1. 16
      char_dev.c
  2. 23
      ftdi_daemon.c
  3. 11
      gpio_callbacks.c
  4. 10
      usb_gpio.c

@ -1,13 +1,4 @@
static char device_buffer[1];
static int major;
static uint8_t buff_empty=1;
static uint8_t buff_start;
static uint8_t buff_end;
static uint8_t buffer[BUFFER_SIZE];
static uint8_t readBuffer(void){
uint8_t ret;
if(buff_empty){
@ -59,16 +50,17 @@ static ssize_t device_write(struct file *filp, const char __user *buff, size_t l
if(len!=1){
return -EINVAL;
}
ret = copy_from_user(device_buffer, buff, len);
ret = copy_from_user(pin_status, buff, len);
if( ret<0 ){
printk("<1>%s: Device write error!\n",MOD_NAME);
return 0;
}
n_written=0;
return len;
}
struct file_operations fops = {
read: device_read,
write: device_write,
read: device_read,
write: device_write,
};

@ -41,7 +41,8 @@ static int get_value(unsigned offset){
DEBUG_OUT("%s: GET_VALUE of pin%d\n",MOD_NAME,offset);
if( !is_output(offset) ){
if( ftdi_read_pins(&ftdic,&USB_GPIO_PIN) < 0){
if( ftdi_read_pins(&ftdic,&USB_GPIO_PIN) < 0){
LOG("%s: Unable to read pin%d \n",MOD_NAME,offset);
}
return !!((USB_GPIO_PIN) & (1<<offset));
@ -142,7 +143,7 @@ enum cmd_states {CMD_PORT_NUM, CMD_CMD};
static int cmd_fsm(char c){
static int state = CMD_PORT_NUM;
static char pin = 0;
int ret;
int val;
switch(state){
case CMD_PORT_NUM:
pin=c;
@ -165,9 +166,14 @@ static int cmd_fsm(char c){
set_value((unsigned)pin,0);
return 0;
case CMD_READ:
ret = get_value((unsigned)pin);
DEBUG_OUT("Value of %d is %d\n", pin,ret);
fputc((char)ret,fd);
val = get_value((unsigned)pin);
DEBUG_OUT("Value of %d is %d\n", pin,val);
errno=0;
fputc((char)val,fd);
if( errno ){
LOG("%s: Error writing to device ernno=%d\n",MOD_NAME,errno );
}
fflush(fd);
return 0;
}
}
@ -176,7 +182,12 @@ static int cmd_fsm(char c){
int main(void){
int ret=ftdi_chip_init();
fd=fopen("/dev/usb_gpio","rw");
errno=0;
fd=fopen("/dev/usb_gpio","r+");
if(fd==(void*)0){
LOG("%s: Could not open device errno=%d\n",MOD_NAME,errno );
return errno;
}
if(ret!=0){
return ret;
}

@ -1,13 +1,14 @@
static int get_value(struct gpio_chip *gc, unsigned offset){
int ret;
DEBUG_OUT("<1>%s: GET_VALUE of pin%d ",MOD_NAME,offset);
ret=writeToBuffer(offset);
ret|=writeToBuffer(CMD_READ);
writeToBuffer(offset);
writeToBuffer(CMD_READ);
return -ret;
n_written=1;
while(n_written){};
return pin_status[0];
}
static void set_value(struct gpio_chip *chip, unsigned offset, int value){

@ -3,6 +3,16 @@
static struct gpio_chip ft232_chip;
static struct subprocess_info *sub_info;
static char pin_status[1];
static int major;
static uint8_t buff_empty=1;
static uint8_t buff_start;
static uint8_t buff_end;
static uint8_t buffer[BUFFER_SIZE];
static volatile int n_written;
#include "char_dev.c"
#include "gpio_callbacks.c"

Loading…
Cancel
Save