ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

专题1-按键驱动程序设计-第2课-Linux中断处理

2022-06-26 21:01:56  阅读:137  来源: 互联网

标签:aston 驱动程序 Linux tq2440 按键 key linux home 040


1、中断处理流程

中断专题:11. 基于ARM Cortex-A9中断详解 (qq.com)

 

 

2、中断注册函数

 

 

 

3、tq2440写的一个按键中断程序

有一个编译报错:

make -C /home/aston/040-linux-tq2440/linux-tq2440/ M=/home/aston/040-linux-tq2440/key_driver modules CROSS_COMPILE=arm-linux- ARCH=arm
make[1]: Entering directory `/home/aston/040-linux-tq2440/linux-tq2440'
  CC [M]  /home/aston/040-linux-tq2440/key_driver/key.o
/home/aston/040-linux-tq2440/key_driver/key.c:58: error: expected identifier or '(' before 'do'
/home/aston/040-linux-tq2440/key_driver/key.c:58: error: expected identifier or '(' before 'while'
/home/aston/040-linux-tq2440/key_driver/key.c:65: warning: function declaration isn't a prototype
/home/aston/040-linux-tq2440/key_driver/key.c: In function '__inittest':
/home/aston/040-linux-tq2440/key_driver/key.c:70: error: 'key_init' undeclared (first use in this function)
/home/aston/040-linux-tq2440/key_driver/key.c:70: error: (Each undeclared identifier is reported only once
/home/aston/040-linux-tq2440/key_driver/key.c:70: error: for each function it appears in.)
make[2]: *** [/home/aston/040-linux-tq2440/key_driver/key.o] Error 1
make[1]: *** [_module_/home/aston/040-linux-tq2440/key_driver] Error 2
make[1]: Leaving directory `/home/aston/040-linux-tq2440/linux-tq2440'
make: *** [all] Error 2
root@ubuntu:/home/aston/040-linux-tq2440/key_driver# 

对应的key.c

#include <linux/module.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/miscdevice.h>

/**************引入中断框架**************/
#define GPFCON 0X56000050
irqreturn_t key_int(int irq, void *dev_id)
{
    /*1、检查是否发生了中断
    **2、清除中断
    **3、打印按键值
    */
    printk("key down\n");
    return 0;
}
void key_hw_init(void)
{
    unsigned int *gpio_config;
    unsigned short data;
    gpio_config=ioremap(GPFCON,4);
    data=readw(gpio_config);//读了4节,读出来再写进去
    data &= ~0b11;
    data |=0x10;
    writew(data,gpio_config);//将引脚配置成中断
}
/************************************/
int key_open(struct inode *node, struct file *filp)
{
    return 0;
}
struct file_operations key_fops={
    .open=key_open,
};

struct miscdevice key_miscdev = {
    .minor = 200,
    .name  = "key",
    .fops = &key_fops,
};

static int button_init()
{
    misc_register(&key_miscdev);//按键下降沿触发中断
    key_hw_init();
    request_irq(IRQ_EINT0,key_int, IRQF_TRIGGER_FALLING,"key",0);
}
static void button_exit()
{
    misc_deregister(&key_miscdev);
    //free_irq(IRQ_EINT0, 0);
}
MODULE_LICENSE("GPL");
module_init(button_init);//为甚改成key_init就报错
module_exit(button_exit);

只要把button_init button_exit都改成key_init编译就立马报错。为什么???

Makefile

obj-m:=key.o
KDIR:= /home/aston/040-linux-tq2440/linux-tq2440/
all:
    make -C $(KDIR) M=$(PWD) modules CROSS_COMPILE=arm-linux- ARCH=arm
clean:
    rm -rf *.ko *.o *.mod.o *.mod.c *.symvers *.bak *.order

 

标签:aston,驱动程序,Linux,tq2440,按键,key,linux,home,040
来源: https://www.cnblogs.com/luckdog0623/p/16414335.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有