[root@bogon 桌面]#
gedit mycdev.c
#include
#include
#include
#include
#include
#include
module_author("me");
module_license("gpl");
#define mycdev_major 231 /*給定的主裝置號*/
#define mycdev_size 100
static int mycdev_open(struct inode *inode, struct file *fp)
static int mycdev_release(struct inode *inode, struct file *fp)
static ssize_t mycdev_read(struct file *fp, char __user *buf, size_t size, loff_t *pos)
/*
for (i = 0; i < count; i++)
*/
printk("reader: %d bytes was read...\n", count);
return count;
}
static ssize_t mycdev_write(struct file *fp, const char __user *buf, size_t size, loff_t *pos)
/* 填充 mycdev的 file operation 結構*/
static const struct file_operations mycdev_fops =
;
/*模組初始化函式*/
static int __init mycdev_init(void)
else
return 0;
}
/*模組解除安裝函式*/
static void __exit mycdev_exit(void)
module_init(mycdev_init);
module_exit(mycdev_exit);
[root@bogon 桌面]#
gedit makefile
obj-m:=mycdev.o
pwd:=$(shell pwd)
cur_path:=$(shell uname -r)
kernel_path:=/usr/src/kernels/$(cur_path)
all:
make -c $(kernel_path) m=$(pwd) modules
clean:
make -c $(kernel_path) m=$(pwd) clean
[root@bogon 桌面]#
gedit mycdev_test.c
#include
#include
#include
#include
#include
int main()
if (ret = read(testdev, buf, 15) <15)
printf("%s\n", buf);
close(testdev);
return 0;
}
[root@bogon 桌面]#
make
[root@bogon 桌面]#
insmod mycdev.ko
[root@bogon 桌面]#
cat /proc/devices
[root@bogon 桌面]#
mknod /dev/mycdev c 231 0
[root@bogon 桌面]#
chmod 777 /dev/mycdev
[root@bogon 桌面]#
gcc mycdev_test.c -o mycdev_test
[root@bogon 桌面]#
./mycdev_test
[root@bogon 桌面]#
dmesg
0 給主人留下些什麼吧!~~
簡單字元驅動程式
mycdev.c include include include include include include include include include include module license gpl define mycdev major 231 cat proc devices檢視...
簡單字元裝置驅動程式 以及 相應測試程式
include include include include include include include include include define device name embedsky leds 載入模式後,執行 cat proc devices 命令看到的裝置名稱 define le...
linux 驅動程式 高階字元驅動程式
ioctl方法 驅動程式的原型實現 int ioctl struct inode inode,struct file filp,unsigned int cmd,unsigned long arg ioctl 命令選擇 位段結構 number direction ioc read ioc write...