驅動**
#include #include #include #include //file_operations
#include #include //request_mem_region
#include #include //class_create device_create
#define devname "ldm"
struct ldm_info ;
static struct ldm_info ldm;
#define gpm4con (*(volatile unsigned long*)(s5p_va_gpio2 + 0x02e0))
#define gpm4dat (*(volatile unsigned char*)(s5p_va_gpio2 + 0x02e4))
static void led_init(void)
//點燈,相應位為1,滅燈,0,亮燈
static void led_on(unsigned char led_stat)
static ssize_t ldm_write(struct file *filp, const char __user *buf, size_t size, loff_t *offset)
static int __init ldm_init(void)
//3 註冊裝置號,成功後可在/proc/devices看到註冊資訊
//從核心documentation/devices.txt中找乙個無人使用的裝置號
//核心中裝置號用dev_t表示,包含主裝置號和次裝置號,分別佔據不同的bit。mkdev,major,minor三個巨集用於合成和拆分裝置號
ldm.dev.dev = mkdev(40, 0);
ret = register_chrdev_region(ldm.dev.dev, 1, devname);
if (ret < 0)
} printk("dev number major=%d, minor=%d\n", major(ldm.dev.dev), minor(ldm.dev.dev));
//4 為fops填充操作方法
ldm.fops.write = ldm_write;
//5 註冊字元裝置
ret = cdev_add(&ldm.dev, ldm.dev.dev, 1);
if (ret < 0)
//6 硬體初始化
led_init();
//7 自動建立裝置結點
//在/sys/class下建立相應資料夾和資訊,包含裝置號資訊。根檔案系統中的mdev服務會自動根據這些資訊,建立裝置結點
ldm.cls = class_create(this_module, devname);
if (is_err(ldm.cls))
struct device *dev = device_create(ldm.cls, null, ldm.dev.dev, null, devname);
if (is_err(dev))
return 0;
err_device_create:
class_destroy(ldm.cls);
err_class_create:
cdev_del(&ldm.dev);
err_cdev_add:
unregister_chrdev_region(ldm.dev.dev, 1);
err_alloc_chrdev_region:
release_mem_region(0x110002e0, 8);
err_request_mem_region:
return ret;
}static void __exit ldm_exit(void)
module_init(ldm_init);
module_exit(ldm_exit);
module_license("gpl");
應用**
#include #include #include #include #define devname "/dev/ldm"
int main(int argc, char **argv)
int fd = open(devname, o_rdwr);
if (fd < 0)
size_t led_status = atoi(argv[1]);
write(fd, &led_status, 1);
close(fd);
return 0;
}
4412驅動 key 按鍵驅動
key driver.c include include include include include include include include include include include static struct class keydrv class static struct cl...
fs4412開發板led驅動
閱讀實驗手冊第16章 led 驅動開發實驗 p275下 fs4412 led.c,fs4412 led.h,test.c 檔案 1.系統呼叫函式 test.c的main函式中,while 1 函式。函式如下 函式分析 1 函式引數中的file指標對應於應用程式傳遞的檔案描述符fd,這和傳遞open方...
4412驅動 等待佇列
定義等待佇列 wait queue head t button waitq 初始化等待佇列頭 init waitqueue head button waitq 定義並初始化等待佇列頭 相當於上面兩句合併 static declare wait queue head button waitq 定義並初...