在组件的基础属性栏中将 width 设置为 4,确保 Direction

为 Input。在 Edge capture register 属性栏中,选中 Synchronously capture,
并将 Edge Type 设置为 FALLING。在 Interrupt 属性栏中,选中 Generate IRQ,
并将 IRQ Type 设置为 Edge。点击 Finish 完成 Button 组件的配置 

 

 

 

 

 

 

 

 

 

 

 1 #include <linux/kernel.h>
 2 #include <linux/module.h>
 3 #include <linux/init.h>
 4 #include <linux/interrupt.h>
 5 #include <asm/io.h>
 6 #include "../address_map_arm.h"
 7 #include "../interrupt_ID.h"
 8 void * LW_virtual; // Lightweight bridge base address
 9 volatile int *LEDR_ptr, *KEY_ptr; // virtual addresses
10 
11 irq_handler_t irq_handler(int irq, void *dev_id, struct pt_regs *regs)
12 {
13 *LEDR_ptr = *LEDR_ptr + 1;
14 // Clear the Edgecapture register (clears current interrupt)
15 *(KEY_ptr + 3) = 0xF;
16  return (irq_handler_t) IRQ_HANDLED;
17 }
18 static int __init initialize_pushbutton_handler(void)
19 {
20 int value;
21 // generate a virtual address for the FPGA lightweight bridge
22 LW_virtual = ioremap_nocache (LW_BRIDGE_BASE, LW_BRIDGE_SPAN);
23 
24 LEDR_ptr = LW_virtual + LEDR_BASE; // virtual address for LEDR port
25 *LEDR_ptr = 0x200; // turn on the leftmost light
26 
27 KEY_ptr = LW_virtual + KEY_BASE; // virtual address for KEY port
28 *(KEY_ptr + 3) = 0xF; // Clear the Edgecapture register
29 *(KEY_ptr + 2) = 0xF; // Enable IRQ generation for the 4 buttons
30 
31 // Register the interrupt handler.
32 value = request_irq (KEYS_IRQ, (irq_handler_t) irq_handler, IRQF_SHARED,
33 "pushbutton_irq_handler", (void *) (irq_handler));
34 return value;
35 }
36 static void __exit cleanup_pushbutton_handler(void)
37 {
38 *LEDR_ptr = 0; // Turn off LEDs and de-register irq handler
39 iounmap (LW_virtual);
40 free_irq (KEYS_IRQ, (void*) irq_handler);
41 }
42 module_init(initialize_pushbutton_handler);
43 module_exit(cleanup_pushbutton_handler);