完善了README.md...

This commit is contained in:
gatieme
2016-08-02 13:41:01 +08:00
parent 085740011a
commit 65cfa243df
3 changed files with 34 additions and 16 deletions
@@ -54,26 +54,32 @@ int simple_release(struct inode *inode, struct file *filp)
ssize_t simple_read(struct file *filp, char __user *buf, size_t count,loff_t *f_pos)
{
//printk("wait_event_interruptible before\n");
printk("wait_event_interruptible before\n");
wait_event_interruptible(read_queue, simple_flag);
//printk("wait_event_interruptible after\n");
if (copy_to_user( buf, demoBuffer, count))
printk("wait_event_interruptible after\n");
if (copy_to_user( buf, demoBuffer, count))
{
count=-EFAULT;
}
printk("read data : %s\n", demoBuffer);
return count;
}
ssize_t simple_write(struct file *filp, const char __user *buf, size_t count,loff_t *f_pos)
{
memset(demoBuffer, 0, MAX_SIZE);
if (copy_from_user(demoBuffer, buf, count))
{
count = -EFAULT;
goto out;
}
simple_flag=1;
printk("write data : %s\n", demoBuffer);
simple_flag = 1;
wake_up(&read_queue);
out:
return count;
}
@@ -83,7 +89,7 @@ unsigned int simple_poll(struct file * file, poll_table * pt)
unsigned int mask = POLLIN | POLLRDNORM;
printk("poll_wait before\n");
poll_wait(file, &read_queue, pt);
poll_wait(file, &read_queue, pt); /* put current process into the wait queue */
printk("poll_wait after\n");
return mask;
@@ -21,10 +21,13 @@
#define PDEBUGG(fmt, args...) /* nothing: it's a placeholder */
//设备号
#define simple_MAJOR 224
#define simple_MINOR 0
#define COMMAND1 1
#define COMMAND2 2
#define simple_MAJOR 224
#define simple_MINOR 0
#define COMMAND1 1
#define COMMAND2 2
#define MAX_SIZE 256
//设备结构
struct simple_dev
@@ -3,6 +3,7 @@
#include <fcntl.h>
#include <linux/rtc.h>
#include <linux/ioctl.h>
#include <sys/select.h>
#include <stdio.h>
#include <stdlib.h>
@@ -23,9 +24,9 @@ void *readthread(void *arg)
{
char data[MAX_SIZE];
fd_set rfds; //¶ÁÃèÊö·û¼¯ºÏ
fd_set wfds; //дÃèÊö·û¼¯ºÏ
int retval = 0;
fd_set rfds; /* the set of the readable files */
fd_set wfds; /* the set of the writeable files */
int retval = 0;
while( 1 )
{
@@ -43,8 +44,10 @@ void *readthread(void *arg)
exit(-1);
}
data[retval] = 0;
printf("read successfully:%s\n",data);
printf("read successfully : %s\n",data);
}
sleep(1);
}
return (void *)0;
}
@@ -54,8 +57,10 @@ void *readthread(void *arg)
int main(void)
{
int i;
int retval;
int i;
int retval;
char str[3][81] = { "gatieme", "wangpanpan", "Hello World!!!" };
//char (*pstr)[81] = str;
fd = open(DEV_FILE, O_RDWR);
if(fd == -1)
@@ -68,14 +73,18 @@ int main(void)
pthread_t tid;
pthread_create(&tid, NULL, readthread, NULL);
srand(time(NULL));
while( 1 )
{
retval = write(fd, "gatieme", strlen("gatieme"));
i = rand( ) % 3;
retval = write(fd, str[i], strlen(str[i]));
if(retval == -1)
{
perror("write error\n");
exit(-1);
}
sleep(2);
}
close(fd);