• HPS 访问 FPGA 方法之五—— 通过FPGA 中断访问


    在组件的基础属性栏中将 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);

     

     

  • 相关阅读:
    sql中内连接和外连接的区别
    javascript优化--08模式(代码复用)01
    javascript优化--07模式(对象)02
    javascript优化--06模式(对象)01
    HTML-Audio/Video
    javascript优化--05模式(函数)
    javascript优化--04高质量编码
    javascript优化--03高质量编码
    javascript优化--02高质量编码
    Unicode编码
  • 原文地址:https://www.cnblogs.com/DoreenLiu/p/14109680.html
Copyright © 2020-2023  润新知