我在RK3568平台上申请了GPIO作为中断代码如下:
无法将中断绑定在其他CPU上
第一种方法:echo 2>/proc/irg/78/smp_affinity
这种方法试了提示sh: write error: Input/output error
第二种方法:
#include <linux/irq.h>
#include <linux/cpumask.h>
void bind_irq_to_cpu0(unsigned int irq) {
cpumask_var_t cpumask;
if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
return;
cpumask_set_cpu(0, cpumask);
irq_set_affinity(irq, cpumask);
free_cpumask_var(cpumask);
}
请问有懂得大佬吗?讲一下。
&{/} {
button_interrupt: button_interrupt {
status = "okay";
compatible = "button_interrupt";
pinctrl-names = "default";
pinctrl-0 = <&button_interrupt_pin>;
interrupt-parent = <&gpio0>;
interrupts = <RK_PB0 IRQ_TYPE_LEVEL_LOW>;
interrupt-affinity = <&cpu3>;
button-gpios = <&gpio0 RK_PB0 GPIO_ACTIVE_HIGH>;
};
};
&{/pinctrl} {
button_interrupt {
button_interrupt_pin: button_interrupt_pin {
rockchip,pins = <0 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
};
/*获取按键 设备树节点*/
button_device_node = of_find_node_by_path("/button_interrupt");
if(NULL == button_device_node)
{
printk("of_find_node_by_path error!");
return -1;
}
/*获取按键使用的GPIO*/
button_GPIO_number = of_get_named_gpio(button_device_node ,"button-gpios", 0);
if(!button_GPIO_number)
{
printk("of_get_named_gpio error");
return -1;
}
printk("button_GPIO_number = %d \n", button_GPIO_number);
/*申请GPIO , 记得释放*/
error = gpio_request(button_GPIO_number, "button_gpios");
if(error < 0)
{
printk("gpio_request error");
gpio_free(button_GPIO_number);
return -1;
}
error = gpio_direction_input(button_GPIO_number);//设置引脚为输入模式
/*获取中断号*/
interrupt_number = irq_of_parse_and_map(button_device_node, 0);
printk("\n irq_of_parse_and_map = %d \n",interrupt_number);
/*申请中断, 记得释放*/
error = request_irq(interrupt_number,button_irq_hander,IRQF_TRIGGER_FALLING,"button_interrupt",NULL);
if(error != 0)
{
printk("request_irq error");
free_irq(interrupt_number, NULL);
return -1;
}