您尚未登录。

#1 Re: 全志 SOC » 求教V3S外部中断 无法进入中断函数问题 » 2023-01-02 19:34:07

结帖,原因未知,后面采用5.2的linux内核,解决了该问题!

#2 全志 SOC » 求教V3S外部中断 无法进入中断函数问题 » 2023-01-02 12:22:15

supertyc01
回复: 1

这是晕哥帖子的代码
https://whycan.com/t_1261.html

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/input-polldev.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>

#define GPIO 192     //PG0
#define GPIO_INT_NAME  "pg1_int"

#define GPIO_HIGH gpio_get_value(GPIO)
#define GPIO_LOW (gpio_get_value(GPIO) == 0)
short int irq_any_gpio    = 0;
int count =0;

enum { falling, rising } type; 
static irqreturn_t r_irq_handler(int irq, void *dev_id)
 {
    count++;
    printk(KERN_DEBUG "interrupt received (irq: %d)\n", irq);
	if (irq == gpio_to_irq(GPIO)) 
    {

        type = GPIO_LOW ? falling : rising;

        if(type == falling)
        {
            printk("gpio pin is low\n");    
        }
        else
            printk("gpio pin is high\n");

    }

    return IRQ_HANDLED;
}

void r_int_config(void) {

   if (gpio_request(GPIO, GPIO_INT_NAME )) 
   {
      printk("GPIO request failure: %s\n", GPIO_INT_NAME );
      return;
   }

    if(gpio_direction_input(GPIO) < 0)
    {
        printk("can't set greenkey-gpio!\r\n");
    }

   if ( (irq_any_gpio = gpio_to_irq(GPIO)) < 0 ) {
      printk("GPIO to IRQ mapping failure %s\n",GPIO_INT_NAME );
      return;
   }

   printk(KERN_NOTICE "Mapped int %d\n", irq_any_gpio);

   if (request_irq(irq_any_gpio,(irq_handler_t ) r_irq_handler, IRQF_TRIGGER_FALLING , GPIO_INT_NAME, NULL)) 
   {
      printk("Irq Request failure\n");
      return;
   }

   return;
}

void r_int_release(void) {

   free_irq(gpio_to_irq(GPIO), NULL);
    gpio_free(GPIO);;
   return;
}

int init_module1(void)
{
        printk("<1>Hello World\n"); 
    r_int_config();
        return 0;
}

module_init(init_module1);    // Do some better naming
module_exit(r_int_release);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("whycan");

查看也确认中断号申请成功了。

# cat /proc/interrupts
           CPU0
 19:       1158     GIC-0  27 Level     arch_timer
 21:          0     GIC-0  50 Level     sun4i_timer0
 22:         94     GIC-0  92 Level     sunxi-mmc
 23:          1     GIC-0 103 Level     musb-hdrc.1.auto
 24:          0     GIC-0  72 Level     1c20400.rtc
 30:        403     GIC-0  32 Level     ttyS0
 33:       6275     GIC-0 114 Level     1c30000.ethernet
 67:          0  sunxi_pio_edge  33 Edge      pg1_int
IPI0:          0  CPU wakeup interrupts
IPI1:          0  Timer broadcast interrupts
IPI2:          0  Rescheduling interrupts
IPI3:          0  Function call interrupts
IPI4:          0  CPU stop interrupts
IPI5:          0  IRQ work interrupts
IPI6:          0  completion interrupts
Err:          0
#

就是不知道为啥进不了中断服务函数.....求各位高手指点...谢谢!

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn