?? leddrv.c
字號:
/**************************************************************** Institue of Automation,Chinese Academy of Sciences* Beijing Hyesco Embedded System Co.,Ltd.* www.hyesco.com* File Name: leddrv.c* Description: PC14、PC15 Control* Author: ***************************************************************/#include <linux/module.h>#include <linux/config.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/fs.h>#include <linux/mm.h>#include <linux/poll.h>#include <linux/slab.h>#include <linux/ioport.h>#include <asm/uaccess.h>#include <asm/io.h>#include <linux/fcntl.h>#include <asm/arch/hardware.h>static int led_write(struct file *,const char *,int,loff_t *);//定義文件操作static struct file_operations led_fops={ write :(void(*))led_write,};//定義模塊名char led_name[]="leddrv"; //指定主設備號static int gmajor = 254;//注冊函數static int __init leddrv_init_module(void){ int retv; //注冊模塊 retv=register_chrdev(gmajor,led_name,&led_fops); if(retv<0) { printk("<1>Register Fail!\n"); return retv; } printk("<1>Led device OK!\n"); return 0;}//注銷函數static void __exit leddrv_cleanup(void){ int retv; //注銷模塊 retv=unregister_chrdev(gmajor,led_name); if(retv<0) { printk("<1>UnRegister Fail!\n"); return; } printk("<1>LEDDRV:GOOD-bye!\n");}static int led_write(struct file *led_file, const char *buf,int len,loff_t *loff){ unsigned int iopdata; AT91PS_SYS sys = (AT91PS_SYS) AT91C_VA_BASE_SYS; //設定PC14、PC15口為輸出 //PIO Enable Register sys->PIOC_PER=(unsigned int)(1<<14)|(unsigned int)(1<<15); //PIO Output Enable Register sys->PIOC_OER=(unsigned int)(1<<14)|(unsigned int)(1<<15); //PIO Output Write Register sys->PIOC_OWER=(unsigned int)(1<<14)|(unsigned int)(1<<15); //從用戶空間拷貝數據到內核空間 if(copy_from_user((char*)&iopdata,buf,len)) return -EFAULT; //PIO Output Data Register sys->PIOC_ODSR=iopdata; return len;}module_init(leddrv_init_module);module_exit(leddrv_cleanup);/*end of leddrv.c*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -