Zynq处理器GPIO中断

问题描述

我正在完成有关vitis上的zynq处理器的任务。

由于有很多代码,除了一部分,我无法附加所有代码。 我希望有人已经完成了这个项目。

#include "xparameters.h"
#include "xgpio.h"
#include "xtmrctr.h"
#include "xscugic.h"
#include "xil_exception.h"
#include "xil_printf.h"

// Parameter definitions
#define INTC_DEVICE_ID      XPAR_PS7_SCUGIC_0_DEVICE_ID
#define TMR_DEVICE_ID       XPAR_TMRCTR_0_DEVICE_ID
#define BTNS_DEVICE_ID      XPAR_AXI_GPIO_0_DEVICE_ID
#define LEDS_DEVICE_ID      XPAR_AXI_GPIO_1_DEVICE_ID
#define INTC_GPIO_INTERRUPT_ID XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR
#define INTC_TMR_INTERRUPT_ID XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR

#define BTN_INT             XGPIO_IR_CH1_MASK
#define TMR_LOAD            0xF8000000

XGpio LEDInst,BTNInst;
XScuGic INTCInst;
XTmrCtr TMRInst;
static int led_data;
static int btn_value;
static int tmr_count;

//----------------------------------------------------
// PROTOTYPE FUNCTIONS
//----------------------------------------------------
static void BTN_Intr_Handler(void *baseaddr_p);
static void TMR_Intr_Handler(void *baseaddr_p);
static int InterruptSystemSetup(XScuGic *XScuGicInstancePtr);
static int IntcInitFunction(u16 DeviceId,XTmrCtr *TmrInstancePtr,XGpio *GpioInstancePtr);

//----------------------------------------------------
// INTERRUPT HANDLER FUNCTIONS
// - called by the timer,button interrupt,performs
// - LED flashing
//----------------------------------------------------


void BTN_Intr_Handler(void *InstancePtr)
{
    // Disable GPIO interrupts
    XGpio_InterruptDisable(&BTNInst,BTN_INT);
    // Ignore additional button presses
    if ((XGpio_InterruptGetStatus(&BTNInst) & BTN_INT) !=
            BTN_INT) {
            return;
        }
    btn_value = XGpio_DiscreteRead(&BTNInst,1);
    // Increment counter based on button value
    // Reset if centre button pressed
    if(btn_value != 1) led_data = led_data + btn_value;
    else led_data = 0;
    XGpio_DiscreteWrite(&LEDInst,1,led_data);
    (void)XGpio_InterruptClear(&BTNInst,BTN_INT);
    // Enable GPIO interrupts
    XGpio_InterruptEnable(&BTNInst,BTN_INT);
}

因此,它基本上是在处理由按钮生成的中断。这是我从谷歌搜索获得的代码。我不明白的是

// Disable GPIO interrupts
XGpio_InterruptDisable(&BTNInst,BTN_INT);
    // Ignore additional button presses
if ((XGpio_InterruptGetStatus(&BTNInst) & BTN_INT) !=BTN_INT){
        return;
    }

这部分。我认为第一个函数XGpio_interruptdisable将禁用该按钮生成的进一步中断。但是我不明白为什么国家存在。我们已经禁用了中断,但是为什么我们需要额外的步骤?

它说“忽略其他按钮的按下”,但实际上,没有上面的代码,它可以正常工作。

您能告诉我为什么上面的代码存在吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...