框架入口原始檔: led_drv.c led_dev.c
可根據入口原始檔,再按著框架到核心走一遍
核心版本:linux_2.6.22.6 硬體平台:jz2440
以下是驅動框架:
以下是驅動** led_dev.c:
#include #include以下是驅動**led_drv.c:#include
#include
#include
#include
#include
#include
#include
#include
#include
//定義乙個資源結構體
static
struct resource led_drv_resource=,
[1] =
};static
void led_platform_release(struct device *dev)
{}//
定義乙個 device_platform 結構體
static
struct platform_device led_dev_platform =,
};static
int led_device_init(void
)static
void led_device_exit(void
)module_init(led_device_init);
module_exit(led_device_exit);
module_license(
"gpl
");
#include #include以下是編譯驅動的makefile:#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//引腳定義
static unsigned long *gpfcon;
static unsigned long *gpfdat;
static
intpin;
//為裝置定義乙個類
static
struct
class *led_platform_class;
//定義主裝置號
static
intmajor;
static ssize_t led_drv_write(struct file *file, const
char __user *buf, size_t count, loff_t *ppos)
static
int led_drv_open(struct inode *inode, struct file *file)
static
struct file_operations led_fops =;
static
int probe_led(struct platform_device *pfdrv)
static
int remove_led(struct platform_device *pfdrv)
static
struct platform_driver led_platform =
};static
int led_drv_init(void
)static
void led_drv_exit(void
)module_init(led_drv_init);
module_exit(led_drv_exit);
module_license(
"gpl
");
ker_dir=/work/systems/kernel/linux-2/linux-2.6.22.6all:
make -c $(ker_dir) m=`pwd` modules
clean:
make -c $(ker_dir) m=`pwd` modules clean
rm -fr modules.order
obj-m +=led_dev.o
obj-m += led_drv.o
平台裝置驅動框架一
platform driver.c include include module license gpl int hello probe struct platform device dev int hello remove struct platform device dev struct pla...
platform裝置驅動框架
這裡簡單總結下platform匯流排的裝置驅動 的框架。1 建立資料夾platform 2 在資料夾下編寫裝置檔案device.c include include include include include include module author wjb module license dua...
字元裝置驅動框架
字元裝置驅動框架 一 linux軟體系統的層次關係 乙個應用程式操作底層驅動程式的過程 1 應用程式使用庫提供的 open函式開啟某乙個裝置檔案。2.庫根據 open函式傳入的引數執行 swi 軟體中斷 指令,這會引起 cpu異常,進入核心。3 核心的異常處理函式根據這些引數找到相應的驅動程式,返回...