驅動-按鍵-中斷模式
eint_drv.c
/*******驅動**************/
#include #include #include #include #include #include #include #include #include #include #include static struct class *eintdrv_class;
static struct class_device *eintdrv_class_dev;
volatile unsigned long *gpfcon;
volatile unsigned long *gpfdat;
volatile unsigned long *gpgcon;
volatile unsigned long *gpgdat;
/*宣告等待佇列頭,名字為button_waitq*/
static declare_wait_queue_head(button_waitq);
/* 中斷事件標誌, 中斷服務程式將它置1,eint_drv_read將它清0 */
static volatile int ev_press = 0;
struct pin_desc;
/* 鍵值: 按下時, 0x01, 0x02, 0x03, 0x04 */
/* 鍵值: 鬆開時, 0x81, 0x82, 0x83, 0x84 */
static unsigned char key_val;
struct pin_desc pins_desc[4] = ,
, ,,};
/* * 確定按鍵值
*/static irqreturn_t buttons_irq(int irq, void *dev_id)
else
/* 表示中斷發生了 */
ev_press=1;
/* 喚醒休眠的程序 */
wake_up_interruptible(&button_waitq);
return irq_retval(irq_handled);
}static int eint_drv_open(struct inode *inode, struct file *file)
ssize_t eint_drv_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
int eint_drv_close(struct inode *inode, struct file *file)
static struct file_operations sencod_drv_fops = ;
int major;
static int eint_drv_init(void)
static void eint_drv_exit(void)
module_init(eint_drv_init);
module_exit(eint_drv_exit);
module_license("gpl");
einttest.c
#include #include #include #include #include /* thirddrvtest
*/int main(int argc, char **argv)
while (1)
return 0;
}
makefile
kern_dir = /work/system/linux-2.6.22.6
all:
make -c $(kern_dir) m=`pwd` modules
clean:
make -c $(kern_dir) m=`pwd` modules clean
rm -rf modules.order
obj-m += eint_drv.o
中斷 按鍵中斷驅動程式
中斷處理 1 外設的處理速度一般慢於 cpu。2 cpu不能一直等待外部事件,所以裝置必須有一種方法來通知 cpu它的工作進度,這個方法就是中斷,外設與 cpu資訊互動的機制,提高 cpu利用率。處理之外還有查詢,但是查詢會一直占有 cpu資源,導致 cpu低利用率,好處是實現簡單。linux系統中...
fl2440按鍵中斷驅動
include include include include include include include include include include include copy to user include 核心時鐘 include atomic t include s3c2410 gpf...
3 按鍵輸入驅動(中斷方式)
1 配置中斷優先順序分組 2 根據硬體初始化gpio為上 下拉輸入 3 外部中斷初始化 4 編寫中斷服務函式 我是分割線 一 中斷優先順序分組一般選擇為2 nvic prioritygroupconfig nvic prioritygroup 2 設定nvic中斷分組2 2位搶占優先順序,2位響應優...