以開發板按鍵為例,在開發板上執行
1.second_drv.c檔案
#include #include #include #include #include #include //包含class_create, device_create, ......這些程式
#include #include #include 版本核心為此位置
//之前版本的核心位置可能為
//#include //#include #include #include //加入兩個結構體,用來供核心自動建立主裝置號
//主要就是在init和exit兩個函式中加入了這兩個結構體
static struct class *seconddrv_class;
static struct class_device *seconddrv_class_dev;
volatile unsigned long *gpfcon;
volatile unsigned long *gpfdat;
static int second_drv_open(struct inode *inode, struct file *file)
ssize_t second_drv_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
static struct file_operations sencod_drv_fops = ;
int major;
static int second_drv_init(void)
static void second_drv_exit(void)
module_init(second_drv_init);
module_exit(second_drv_exit);
module_license("gpl");
2.makefile
kern_dir = /home/stevenking/workspace/code/linux-2.6.39
all:
make -c $(kern_dir) m=`pwd` modules
clean:
make -c $(kern_dir) m=`pwd` modules clean
rm -rf modules.order
obj-m += second_drv.o
3.seconddrvtest.c測試程式
#include #include #include #include /* seconddrvtest
*/int main(int argc, char **argv)
while (1) }
return 0;
}
測試方法在第一篇裡面講過。不多說。 linux驅動之入門
首先通過第乙個程式簡單了解下驅動的框架 首先 開發環境 fedora 17 核心版本 3.9.10 檢視核心版本命令 uname r 更新核心命令 yum update 需重啟之後檢視核心才行 另外需要安裝編譯好的核心的標頭檔案和庫 yum install kernel devel arm開發板型號...
linux驅動入門之AD轉換驅動
需要用ad轉換,網上找來找去也沒找到合適的,自己寫了個,查詢方式的,後續更新中斷方式的。1.tq2440 adc sk.c include include include include include include 包含class create,device create,這些程式 includ...
linux驅動入門之觸控螢幕驅動
廢話不多說,直接上檔案 1.tq2440 ts sk.c include include include include include include include include include include include include include include include i...