Linux 2.6驱动开发--字符设备驱动实例
驱动代码
Makefile文件
#KVER = /usr/src/linux-source-2.6.38
KVER = /lib/modules/`uname -r`/build
CURDIR = $(shell pwd)
# Kernel modules
obj-m := my_device.o
build: kernel_modules
kernel_modules:
$(MAKE) -C $(KVER) M=$(CURDIR) modules
clean:
$(MAKE) -C $(KVER) M=$(CURDIR) clean
测试代码
然后gcc call_test.c -o call_test
sudo insmod#加载驱动
然后创建字符设备
sudo mknod /dev/yming_device c 240 32
分别表示设备文件名,设备类型,主设备号,次设备号
运行call_test,然后使用命令查看驱动的运行信息
dmesg | tail
如下
[ 1190.544602] keyboard: can't emulate rawmode for keycode 240
[ 1190.544620] keyboard: can't emulate rawmode for keycode 240
[ 1521.351828] exe (1755): /proc/1755/oom_adj is deprecated, please use /proc/1755/oom_score_adj instead.
[ 6359.871814] call my device
[ 7014.893799] call my device release
[ 7283.765009] call my device
[ 7289.153601] My device open ->minor: 32
[ 7289.153663] My device read ->buf : 00000030 count 00000031
[ 7289.153667] My device wirte ->buf : 00000041 count 00000042
[ 7289.153671] My device close
浙公网安备 33010602011771号