- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
#define MAX_FILE_LENGHT PAGE_SIZE
#define TYPE(dev) ( MINOR(dev) >> 4)
#define NUM(dev) ( MINOR(dev) & 0xf )
#define IRQ_NUM 1
#define DEV_NAME "keyboard"
#define MAX_DEV_COUNT 5
#define PORT_START 0xff30
int devno,err;
int mj,min;
struct cdev *mydev;
static char *devbuff;
struct dev_state{
int dev_open;
ssize_t dev_read;
ssize_t dev_write;
};
int mydev_ioctl(struct inode *in,struct file *filp,unsigned int ioctl,unsigned long param);
int mydev_open(struct inode *in,struct file* filp);
ssize_t mydev_read(struct file *filp,char *buff,ssize_t len,loff_t pos);
ssize_t mydev_write(struct file *filp, const char *buff, ssize_t len,loff_t pos);
loff_t mydev_llseek(struct file *filp,loff_t pos, int dist);
int mydev_close(struct inode *in , struct file *filp);
static struct dev_state STATE[MAX_DEV_COUNT+1];
struct resource *my_res;
struct file_operations fop_s={
.owner = THIS_MODULE,
.open = mydev_open,
.release = mydev_close,
.read = mydev_read,
.write = mydev_write,
.ioctl = mydev_ioctl,
.llseek = mydev_llseek,
};
static int module3_init(void){
mj=1;
min=1;
my_res->start=0xff30;
my_res->name="myres";
my_res->flags=IORESOURCE_IO | IORESOURCE_IO_FIXED;
my_res->parent=NULL;
my_res->sibling=NULL;
my_res->child=NULL;
struct resource *myres=request_region(200,300,"myreg");
devbuff=(char*)vmalloc(MAX_FILE_LENGHT);
memset(devbuff,0x20,sizeof(devbuff));
devno=MKDEV(mj,min);
mydev=cdev_alloc();
mydev->owner=THIS_MODULE;
cdev_init(mydev,&fop_s);
err=cdev_add(mydev,devno,1);
if(err){
printk(KERN_INFO"Invaid devno %d\n",devno);
return -EFAULT;
};
printk(KERN_INFO"Device"DEV_NAME"was created\n");
return 0;
};
guest 25.12.2009 16:06 # 0
Тигра 25.12.2009 16:07 # 0
guest 26.12.2009 10:37 # 0
guest 31.12.2009 13:40 # 0
guest 01.01.2010 11:11 # 0
...
static char *devbuff;
...
devbuff=(char*)vmalloc(MAX_FILE_LENGHT);
memset(devbuff,0x20,sizeof(devbuff));
...
Но все равно порадовали. +1
guest 01.01.2010 23:33 # −2