亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Linux字符設(shè)備驅(qū)動(dòng)解析

原創(chuàng) 2016-11-09 13:30:13 359
摘要:1.驅(qū)動(dòng)即是一個(gè)內(nèi)核模塊,需要模塊初始化函數(shù)module_init()module_exit()2.分配cdevstruct cdev dev;3.初始化cdev并定義file_operation;cdev_init(cdev *,const struct file_operation *);4.獲取設(shè)備號(hào)并注冊(cè)cdev結(jié)構(gòu)alloc_chrdev_region( dev_t *, unsigne

1.驅(qū)動(dòng)即是一個(gè)內(nèi)核模塊,需要模塊初始化函數(shù)

module_init()

module_exit()

2.分配cdev

struct cdev dev;

3.初始化cdev并定義file_operation;

cdev_init(cdev *,const struct file_operation *);

4.獲取設(shè)備號(hào)并注冊(cè)cdev結(jié)構(gòu)

alloc_chrdev_region( dev_t *, unsigned , unsigned , const char *);

cdev_add( struct cdev * ,dev_t ,  unsigned );

5.編寫(xiě)file_operation結(jié)構(gòu)函數(shù),實(shí)現(xiàn)設(shè)備操作;

open、release、write、read等

copy_to_user()把內(nèi)核空間拷貝到用戶空間

copy_from_user()把用戶空間拷貝到內(nèi)核空間

6.驅(qū)動(dòng)程序的注銷(xiāo);

cdev_del(struct cdev *);

unregister_chrdev_region( dev_t, unsigned );

設(shè)備文件需要自己創(chuàng)建

在/proc/devices下看主設(shè)備號(hào)

Makefile

obj-m:=led.o
KERNELDIR:=/home/jz2440/linux-2.6.22.6

PWD:=$(shell pwd)

default:
    $(MAKE) -C $(KERNELDIR)  M=$(PWD) modules

clean:
    rm -rf *.o *.mod.c *.mod.o *.ko


發(fā)布手記

熱門(mén)詞條