#include
//file_operations宣告
#include
//module_init module_exit宣告
#include
//_init _exit巨集定義宣告
#include
//class device宣告
#include
//copy_from_user的標頭檔案
#include
//裝置號 dev_t型別宣告
#include
// ioremap iounmap的標頭檔案
static
struct class *pin4_class;
static
struct device *pin4_class_dev;
static dev_t devno;
//裝置號
static
int major=
231;
//主裝置號
static
int minor=0;
//次裝置號
static
char
*module_name =
"pin4"
;//模組名
static
intpin4_read
(struct file *file,
char __user *buf,size_t size,loff_t *ppos)
//led_open
static
intpin4_open
(struct inode *inode,
struct file *file)
//led_write
static ssize_t pin4_write
(struct file *file,
const
char __user *buf,size_t count,loff_t *ppos)
static
struct file_operations pin4_fops=
;int __init pin4_drv_init
(void
)//真實驅動入口
void __exit pin4_drv_exit
(void
)module_init
(pin4_drv_init)
;//1入口,核心載入該驅動時,呼叫這個巨集
module_exit
(pin4_drv_exit)
;module_license
("gpl 2"
);
上層程式
#include
#include
#include
#include
intmain()
else
fd=writte
(fd,
'1',1)
;}
編譯
進入核心目錄下
cd ->driver->char
到目錄下後,把模板程式新增進去
然後vi makefile,進入後按照格式新增
obj-m += pin4driver.o
編譯arch=arm cross_compile=arm-linux-gnueabihf- kernul=kernel7 make modules
之後scp 拷貝到樹莓派
sudo chmod 666 /dev/pin4
樹莓派驅動框架
include file operations宣告 include module init module exit宣告 include init exit 巨集定義宣告 include class devise宣告 include copy from user 的標頭檔案 include 裝置號 d...
樹莓派驅動框架
檔名為pin4driver.c include file operations宣告 include module init module exit宣告 include init exit 巨集定義宣告 include class devise宣告 include copy from user 的標頭...
基於樹莓派的Linux字元裝置驅動框架
include file operations宣告 include module init module exit宣告 include init exit 巨集定義宣告 include class devise宣告 include copy from user 的標頭檔案 include 裝置號 d...