GPIO按鍵控制中斷以及LED亮滅(zc702)

  1. 在vivado-->Block design下加入IP:AXI GPIO以及ZYNQ7。自動連接房蝉。

  2. 打開ZYNQ7的PL-PS中斷接口瓤球。

  1. AXI GPIO設(shè)置如下突梦,注意勾選下方的中斷使能。

  1. 將AXI GPIO和ZYNQ7 PS的中斷接口相連笛辟。
  1. 生成比特流功氨,Export to hardware,Launch SDK.

  2. 連接硬件,SDK上方手幢,Xilinx Tools捷凄,Program FPGA。

  3. 創(chuàng)建Porject方法和打開串口客戶端的方法和前一篇文章相同围来。

使用計數(shù)方式控制LED

/***************************** Include Files *********************************/

#include "xparameters.h"
#include "xgpio.h"
#include "xil_exception.h"

#ifdef XPAR_INTC_0_DEVICE_ID
 #include "xintc.h"
 #include <stdio.h>
#else
 #include "xscugic.h"
 #include "xil_printf.h"
#endif

#define LED 0x0F
/************************** Constant Definitions *****************************/
#ifndef TESTAPP_GEN
/*
 * The following constants map to the XPAR parameters created in the
 * xparameters.h file. They are defined here such that a user can easily
 * change all the needed parameters in one place.
 */
#define GPIO_DEVICE_ID      XPAR_GPIO_0_DEVICE_ID
#define GPIO_CHANNEL1       1

#ifdef XPAR_INTC_0_DEVICE_ID
 #define INTC_GPIO_INTERRUPT_ID XPAR_INTC_0_GPIO_0_VEC_ID
 #define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
#else
 #define INTC_GPIO_INTERRUPT_ID XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR
 #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#endif /* XPAR_INTC_0_DEVICE_ID */

/*
 * The following constants define the positions of the buttons and LEDs each
 * channel of the GPIO
 */
#define GPIO_ALL_LEDS       0xFFFF
#define GPIO_ALL_BUTTONS    0xFFFF

/*
 * The following constants define the GPIO channel that is used for the buttons
 * and the LEDs. They allow the channels to be reversed easily.
 */
#define BUTTON_CHANNEL   1  /* Channel 1 of the GPIO Device */
#define LED_CHANNEL  2  /* Channel 2 of the GPIO Device */
#define BUTTON_INTERRUPT XGPIO_IR_CH1_MASK  /* Channel 1 Interrupt Mask */

/*
 * The following constant determines which buttons must be pressed at the same
 * time to cause interrupt processing to stop and start
 */
#define INTERRUPT_CONTROL_VALUE 0x7

/*
 * The following constant is used to wait after an LED is turned on to make
 * sure that it is visible to the human eye.  This constant might need to be
 * tuned for faster or slower processor speeds.
 */
#define LED_DELAY   1000000

#endif /* TESTAPP_GEN */

#define INTR_DELAY  0x00FFFFFF

#ifdef XPAR_INTC_0_DEVICE_ID
 #define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
 #define INTC       XIntc
 #define INTC_HANDLER   XIntc_InterruptHandler
#else
 #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
 #define INTC       XScuGic
 #define INTC_HANDLER   XScuGic_InterruptHandler
#endif /* XPAR_INTC_0_DEVICE_ID */

/************************** Function Prototypes ******************************/
void GpioHandler(void *CallBackRef);

int GpioIntrExample(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 DeviceId, u16 IntrId,
            u16 IntrMask, u32 *DataRead);

int GpioSetupIntrSystem(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 DeviceId, u16 IntrId, u16 IntrMask);

void GpioDisableIntr(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 IntrId, u16 IntrMask);

/************************** Variable Definitions *****************************/

/*
 * The following are declared globally so they are zeroed and so they are
 * easily accessible from a debugger
 */
XGpio Gpio; /* The Instance of the GPIO Driver */

INTC Intc; /* The Instance of the Interrupt Controller Driver */


static u16 GlobalIntrMask; /* GPIO channel mask that is needed by
                * the Interrupt Handler */

static volatile u32 IntrFlag; /* Interrupt Handler Flag */

/****************************************************************************/
/**
* This function is the main function of the GPIO example.  It is responsible
* for initializing the GPIO device, setting up interrupts and providing a
* foreground loop such that interrupt can occur in the background.
*
* @param    None.
*
* @return
*       - XST_SUCCESS to indicate success.
*       - XST_FAILURE to indicate failure.
*
* @note     None.
*
*****************************************************************************/
#ifndef TESTAPP_GEN
int count_flag=0;
int main(void)
{
    int Status;
    u32 DataRead;

      print(" Press button to Generate Interrupt\r\n");

      Status = GpioIntrExample(&Intc, &Gpio,
                   GPIO_DEVICE_ID,
                   INTC_GPIO_INTERRUPT_ID,
                   GPIO_CHANNEL1, &DataRead);

    if (Status == 0 ){
        if(DataRead == 0)
            print("No button pressed. \r\n");
        else
            print("Successfully ran Gpio Interrupt Tapp Example\r\n");
    } else {
         print("Gpio Interrupt Tapp Example Failed.\r\n");
         return XST_FAILURE;
    }
    while(1);
    return XST_SUCCESS;
}
#endif

/******************************************************************************/
/**
*
* This is the entry function from the TestAppGen tool generated application
* which tests the interrupts when enabled in the GPIO
*
* @param    IntcInstancePtr is a reference to the Interrupt Controller
*       driver Instance
* @param    InstancePtr is a reference to the GPIO driver Instance
* @param    DeviceId is the XPAR_<GPIO_instance>_DEVICE_ID value from
*       xparameters.h
* @param    IntrId is XPAR_<INTC_instance>_<GPIO_instance>_IP2INTC_IRPT_INTR
*       value from xparameters.h
* @param    IntrMask is the GPIO channel mask
* @param    DataRead is the pointer where the data read from GPIO Input is
*       returned
*
* @return
*       - XST_SUCCESS if the Test is successful
*       - XST_FAILURE if the test is not successful
*
* @note     None.
*
******************************************************************************/
int GpioIntrExample(INTC *IntcInstancePtr, XGpio* InstancePtr, u16 DeviceId,
            u16 IntrId, u16 IntrMask, u32 *DataRead)
{
    int Status;
    u32 delay;

    /* Initialize the GPIO driver. If an error occurs then exit */
    Status = XGpio_Initialize(InstancePtr, DeviceId);
    XGpio_SetDataDirection(&Gpio, LED_CHANNEL, ~LED);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    Status = GpioSetupIntrSystem(IntcInstancePtr, InstancePtr, DeviceId,
                    IntrId, IntrMask);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    IntrFlag = 0;
    delay = 0;

//  while(!IntrFlag && (delay < INTR_DELAY)) {
    while(1) {
        delay++;
    }

    GpioDisableIntr(IntcInstancePtr, InstancePtr, IntrId, IntrMask);

    *DataRead = IntrFlag;

    return Status;
}


/******************************************************************************/
/**
*
* This function performs the GPIO set up for Interrupts
*
* @param    IntcInstancePtr is a reference to the Interrupt Controller
*       driver Instance
* @param    InstancePtr is a reference to the GPIO driver Instance
* @param    DeviceId is the XPAR_<GPIO_instance>_DEVICE_ID value from
*       xparameters.h
* @param    IntrId is XPAR_<INTC_instance>_<GPIO_instance>_IP2INTC_IRPT_INTR
*       value from xparameters.h
* @param    IntrMask is the GPIO channel mask
*
* @return   XST_SUCCESS if the Test is successful, otherwise XST_FAILURE
*
* @note     None.
*
******************************************************************************/
int GpioSetupIntrSystem(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 DeviceId, u16 IntrId, u16 IntrMask)
{
    int Result;

    GlobalIntrMask = IntrMask;

#ifdef XPAR_INTC_0_DEVICE_ID

#ifndef TESTAPP_GEN
    /*
     * Initialize the interrupt controller driver so that it's ready to use.
     * specify the device ID that was generated in xparameters.h
     */
    Result = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID);
    if (Result != XST_SUCCESS) {
        return Result;
    }
#endif /* TESTAPP_GEN */

    /* Hook up interrupt service routine */
    XIntc_Connect(IntcInstancePtr, IntrId,
              (Xil_ExceptionHandler)GpioHandler, InstancePtr);

    /* Enable the interrupt vector at the interrupt controller */
    XIntc_Enable(IntcInstancePtr, IntrId);

#ifndef TESTAPP_GEN
    /*
     * Start the interrupt controller such that interrupts are recognized
     * and handled by the processor
     */
    Result = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE);
    if (Result != XST_SUCCESS) {
        return Result;
    }
#endif /* TESTAPP_GEN */

#else /* !XPAR_INTC_0_DEVICE_ID */

#ifndef TESTAPP_GEN
    XScuGic_Config *IntcConfig;

    /*
     * Initialize the interrupt controller driver so that it is ready to
     * use.
     */
    IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
    if (NULL == IntcConfig) {
        return XST_FAILURE;
    }

    Result = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,
                    IntcConfig->CpuBaseAddress);
    if (Result != XST_SUCCESS) {
        return XST_FAILURE;
    }
#endif /* TESTAPP_GEN */

    XScuGic_SetPriorityTriggerType(IntcInstancePtr, IntrId,
                    0xA0, 0x3);

    /*
     * Connect the interrupt handler that will be called when an
     * interrupt occurs for the device.
     */
    Result = XScuGic_Connect(IntcInstancePtr, IntrId,
                 (Xil_ExceptionHandler)GpioHandler, InstancePtr);
    if (Result != XST_SUCCESS) {
        return Result;
    }

    /* Enable the interrupt for the GPIO device.*/
    XScuGic_Enable(IntcInstancePtr, IntrId);
#endif /* XPAR_INTC_0_DEVICE_ID */

    /*
     * Enable the GPIO channel interrupts so that push button can be
     * detected and enable interrupts for the GPIO device
     */
    XGpio_InterruptEnable(InstancePtr, IntrMask);
    XGpio_InterruptGlobalEnable(InstancePtr);

    /*
     * Initialize the exception table and register the interrupt
     * controller handler with the exception table
     */
    Xil_ExceptionInit();

    Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
             (Xil_ExceptionHandler)INTC_HANDLER, IntcInstancePtr);

    /* Enable non-critical exceptions */
    Xil_ExceptionEnable();

    return XST_SUCCESS;
}

/******************************************************************************/
/**
*
* This is the interrupt handler routine for the GPIO for this example.
*
* @param    CallbackRef is the Callback reference for the handler.
*
* @return   None.
*
* @note     None.
*
******************************************************************************/
void GpioHandler(void *CallbackRef)
{
    XGpio *GpioPtr = (XGpio *)CallbackRef;

    IntrFlag = 1;
    count_flag=count_flag+1;
    if(count_flag%2==1){
        print("Successfully\r\n");
        /* Set the LED to High */
        XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, LED);
        printf("led on \n");
    }
    else{
        XGpio_DiscreteClear(&Gpio, LED_CHANNEL, LED);
        printf("led off \n");
    }
    /* Clear the Interrupt */
    XGpio_InterruptClear(GpioPtr, GlobalIntrMask);

}

/******************************************************************************/
/**
*
* This function disables the interrupts for the GPIO
*
* @param    IntcInstancePtr is a pointer to the Interrupt Controller
*       driver Instance
* @param    InstancePtr is a pointer to the GPIO driver Instance
* @param    IntrId is XPAR_<INTC_instance>_<GPIO_instance>_VEC
*       value from xparameters.h
* @param    IntrMask is the GPIO channel mask
*
* @return   None
*
* @note     None.
*
******************************************************************************/
void GpioDisableIntr(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 IntrId, u16 IntrMask)
{
    XGpio_InterruptDisable(InstancePtr, IntrMask);
#ifdef XPAR_INTC_0_DEVICE_ID
    XIntc_Disable(IntcInstancePtr, IntrId);
#else
    /* Disconnect the interrupt */
    XScuGic_Disable(IntcInstancePtr, IntrId);
    XScuGic_Disconnect(IntcInstancePtr, IntrId);
#endif
    return;
}

使用讀取按鍵值的方式控制LED


/***************************** Include Files *********************************/

#include "xparameters.h"
#include "xgpio.h"
#include "xil_exception.h"

#ifdef XPAR_INTC_0_DEVICE_ID
 #include "xintc.h"
 #include <stdio.h>
#else
 #include "xscugic.h"
 #include "xil_printf.h"
#endif

#define LED 0x0F
/************************** Constant Definitions *****************************/
#ifndef TESTAPP_GEN
/*
 * The following constants map to the XPAR parameters created in the
 * xparameters.h file. They are defined here such that a user can easily
 * change all the needed parameters in one place.
 */
#define GPIO_DEVICE_ID      XPAR_GPIO_0_DEVICE_ID
#define GPIO_CHANNEL1       1

#ifdef XPAR_INTC_0_DEVICE_ID
 #define INTC_GPIO_INTERRUPT_ID XPAR_INTC_0_GPIO_0_VEC_ID
 #define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
#else
 #define INTC_GPIO_INTERRUPT_ID XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR
 #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#endif /* XPAR_INTC_0_DEVICE_ID */

/*
 * The following constants define the positions of the buttons and LEDs each
 * channel of the GPIO
 */
#define GPIO_ALL_LEDS       0xFFFF
#define GPIO_ALL_BUTTONS    0xFFFF

/*
 * The following constants define the GPIO channel that is used for the buttons
 * and the LEDs. They allow the channels to be reversed easily.
 */
#define BUTTON_CHANNEL   1  /* Channel 1 of the GPIO Device */
#define LED_CHANNEL  2  /* Channel 2 of the GPIO Device */
#define BUTTON_INTERRUPT XGPIO_IR_CH1_MASK  /* Channel 1 Interrupt Mask */

/*
 * The following constant determines which buttons must be pressed at the same
 * time to cause interrupt processing to stop and start
 */
#define INTERRUPT_CONTROL_VALUE 0x7

/*
 * The following constant is used to wait after an LED is turned on to make
 * sure that it is visible to the human eye.  This constant might need to be
 * tuned for faster or slower processor speeds.
 */
#define LED_DELAY   1000000

#endif /* TESTAPP_GEN */

#define INTR_DELAY  0x00FFFFFF

#ifdef XPAR_INTC_0_DEVICE_ID
 #define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
 #define INTC       XIntc
 #define INTC_HANDLER   XIntc_InterruptHandler
#else
 #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
 #define INTC       XScuGic
 #define INTC_HANDLER   XScuGic_InterruptHandler
#endif /* XPAR_INTC_0_DEVICE_ID */

/************************** Function Prototypes ******************************/
void GpioHandler(void *CallBackRef);

int GpioIntrExample(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 DeviceId, u16 IntrId,
            u16 IntrMask, u32 *DataRead);

int GpioSetupIntrSystem(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 DeviceId, u16 IntrId, u16 IntrMask);

void GpioDisableIntr(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 IntrId, u16 IntrMask);

/************************** Variable Definitions *****************************/

/*
 * The following are declared globally so they are zeroed and so they are
 * easily accessible from a debugger
 */
XGpio Gpio; /* The Instance of the GPIO Driver */

INTC Intc; /* The Instance of the Interrupt Controller Driver */


static u16 GlobalIntrMask; /* GPIO channel mask that is needed by
                * the Interrupt Handler */

static volatile u32 IntrFlag; /* Interrupt Handler Flag */

/****************************************************************************/
/**
* This function is the main function of the GPIO example.  It is responsible
* for initializing the GPIO device, setting up interrupts and providing a
* foreground loop such that interrupt can occur in the background.
*
* @param    None.
*
* @return
*       - XST_SUCCESS to indicate success.
*       - XST_FAILURE to indicate failure.
*
* @note     None.
*
*****************************************************************************/
#ifndef TESTAPP_GEN
int main(void)
{
    int Status;
    u32 DataRead;

      print(" Press button to Generate Interrupt\r\n");

      Status = GpioIntrExample(&Intc, &Gpio,
                   GPIO_DEVICE_ID,
                   INTC_GPIO_INTERRUPT_ID,
                   GPIO_CHANNEL1, &DataRead);
      XGpio_SetDataDirection(&Gpio, LED_CHANNEL, ~LED);
    if (Status == 0 ){
        if(DataRead == 0)
            print("No button pressed. \r\n");
        else
            print("Successfully ran Gpio Interrupt Tapp Example\r\n");
    } else {
         print("Gpio Interrupt Tapp Example Failed.\r\n");
         return XST_FAILURE;
    }
    while(1);
    return XST_SUCCESS;
}
#endif

/******************************************************************************/
/**
*
* This is the entry function from the TestAppGen tool generated application
* which tests the interrupts when enabled in the GPIO
*
* @param    IntcInstancePtr is a reference to the Interrupt Controller
*       driver Instance
* @param    InstancePtr is a reference to the GPIO driver Instance
* @param    DeviceId is the XPAR_<GPIO_instance>_DEVICE_ID value from
*       xparameters.h
* @param    IntrId is XPAR_<INTC_instance>_<GPIO_instance>_IP2INTC_IRPT_INTR
*       value from xparameters.h
* @param    IntrMask is the GPIO channel mask
* @param    DataRead is the pointer where the data read from GPIO Input is
*       returned
*
* @return
*       - XST_SUCCESS if the Test is successful
*       - XST_FAILURE if the test is not successful
*
* @note     None.
*
******************************************************************************/
int GpioIntrExample(INTC *IntcInstancePtr, XGpio* InstancePtr, u16 DeviceId,
            u16 IntrId, u16 IntrMask, u32 *DataRead)
{
    int Status;
    u32 delay;

    /* Initialize the GPIO driver. If an error occurs then exit */
    Status = XGpio_Initialize(InstancePtr, DeviceId);
    XGpio_SetDataDirection(&Gpio, LED_CHANNEL, ~LED);
    XGpio_SetDataDirection(&Gpio, BUTTON_CHANNEL, 0x3);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    Status = GpioSetupIntrSystem(IntcInstancePtr, InstancePtr, DeviceId,
                    IntrId, IntrMask);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    IntrFlag = 0;
    delay = 0;

//  while(!IntrFlag && (delay < INTR_DELAY)) {
    while(1) {
        delay++;
    }

    GpioDisableIntr(IntcInstancePtr, InstancePtr, IntrId, IntrMask);

    *DataRead = IntrFlag;

    return Status;
}


/******************************************************************************/
/**
*
* This function performs the GPIO set up for Interrupts
*
* @param    IntcInstancePtr is a reference to the Interrupt Controller
*       driver Instance
* @param    InstancePtr is a reference to the GPIO driver Instance
* @param    DeviceId is the XPAR_<GPIO_instance>_DEVICE_ID value from
*       xparameters.h
* @param    IntrId is XPAR_<INTC_instance>_<GPIO_instance>_IP2INTC_IRPT_INTR
*       value from xparameters.h
* @param    IntrMask is the GPIO channel mask
*
* @return   XST_SUCCESS if the Test is successful, otherwise XST_FAILURE
*
* @note     None.
*
******************************************************************************/
int GpioSetupIntrSystem(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 DeviceId, u16 IntrId, u16 IntrMask)
{
    int Result;

    GlobalIntrMask = IntrMask;

#ifdef XPAR_INTC_0_DEVICE_ID

#ifndef TESTAPP_GEN
    /*
     * Initialize the interrupt controller driver so that it's ready to use.
     * specify the device ID that was generated in xparameters.h
     */
    Result = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID);
    if (Result != XST_SUCCESS) {
        return Result;
    }
#endif /* TESTAPP_GEN */

    /* Hook up interrupt service routine */
    XIntc_Connect(IntcInstancePtr, IntrId,
              (Xil_ExceptionHandler)GpioHandler, InstancePtr);

    /* Enable the interrupt vector at the interrupt controller */
    XIntc_Enable(IntcInstancePtr, IntrId);

#ifndef TESTAPP_GEN
    /*
     * Start the interrupt controller such that interrupts are recognized
     * and handled by the processor
     */
    Result = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE);
    if (Result != XST_SUCCESS) {
        return Result;
    }
#endif /* TESTAPP_GEN */

#else /* !XPAR_INTC_0_DEVICE_ID */

#ifndef TESTAPP_GEN
    XScuGic_Config *IntcConfig;

    /*
     * Initialize the interrupt controller driver so that it is ready to
     * use.
     */
    IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
    if (NULL == IntcConfig) {
        return XST_FAILURE;
    }

    Result = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,
                    IntcConfig->CpuBaseAddress);
    if (Result != XST_SUCCESS) {
        return XST_FAILURE;
    }
#endif /* TESTAPP_GEN */

    XScuGic_SetPriorityTriggerType(IntcInstancePtr, IntrId,
                    0xA0, 0x3);

    /*
     * Connect the interrupt handler that will be called when an
     * interrupt occurs for the device.
     */
    Result = XScuGic_Connect(IntcInstancePtr, IntrId,
                 (Xil_ExceptionHandler)GpioHandler, InstancePtr);
    if (Result != XST_SUCCESS) {
        return Result;
    }

    /* Enable the interrupt for the GPIO device.*/
    XScuGic_Enable(IntcInstancePtr, IntrId);
#endif /* XPAR_INTC_0_DEVICE_ID */

    /*
     * Enable the GPIO channel interrupts so that push button can be
     * detected and enable interrupts for the GPIO device
     */
    XGpio_InterruptEnable(InstancePtr, IntrMask);
    XGpio_InterruptGlobalEnable(InstancePtr);

    /*
     * Initialize the exception table and register the interrupt
     * controller handler with the exception table
     */
    Xil_ExceptionInit();

    Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
             (Xil_ExceptionHandler)INTC_HANDLER, IntcInstancePtr);

    /* Enable non-critical exceptions */
    Xil_ExceptionEnable();

    return XST_SUCCESS;
}

/******************************************************************************/
/**
*
* This is the interrupt handler routine for the GPIO for this example.
*
* @param    CallbackRef is the Callback reference for the handler.
*
* @return   None.
*
* @note     None.
*
******************************************************************************/
void GpioHandler(void *CallbackRef)
{
    XGpio *GpioPtr = (XGpio *)CallbackRef;
    int num = 0;
    int led_num=0;
    IntrFlag = 1;
    printf("1\r\n");
    num = XGpio_DiscreteRead(&Gpio, BUTTON_CHANNEL);
    if(num){
        led_num=0xFF;
    }
    else{
        led_num=0;
    }
    XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, led_num);

    /* Clear the Interrupt */
    XGpio_InterruptClear(GpioPtr, GlobalIntrMask);

}

/******************************************************************************/
/**
*
* This function disables the interrupts for the GPIO
*
* @param    IntcInstancePtr is a pointer to the Interrupt Controller
*       driver Instance
* @param    InstancePtr is a pointer to the GPIO driver Instance
* @param    IntrId is XPAR_<INTC_instance>_<GPIO_instance>_VEC
*       value from xparameters.h
* @param    IntrMask is the GPIO channel mask
*
* @return   None
*
* @note     None.
*
******************************************************************************/
void GpioDisableIntr(INTC *IntcInstancePtr, XGpio *InstancePtr,
            u16 IntrId, u16 IntrMask)
{
    XGpio_InterruptDisable(InstancePtr, IntrMask);
#ifdef XPAR_INTC_0_DEVICE_ID
    XIntc_Disable(IntcInstancePtr, IntrId);
#else
    /* Disconnect the interrupt */
    XScuGic_Disable(IntcInstancePtr, IntrId);
    XScuGic_Disconnect(IntcInstancePtr, IntrId);
#endif
    return;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末跺涤,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子监透,更是在濱河造成了極大的恐慌桶错,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件胀蛮,死亡現(xiàn)場離奇詭異院刁,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)粪狼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進(jìn)店門退腥,熙熙樓的掌柜王于貴愁眉苦臉地迎上來任岸,“玉大人,你說我怎么就攤上這事狡刘∠砬保” “怎么了?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵颓帝,是天一觀的道長米碰。 經(jīng)常有香客問我,道長购城,這世上最難降的妖魔是什么吕座? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮瘪板,結(jié)果婚禮上吴趴,老公的妹妹穿的比我還像新娘。我一直安慰自己侮攀,他們只是感情好锣枝,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著兰英,像睡著了一般撇叁。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上畦贸,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天陨闹,我揣著相機(jī)與錄音,去河邊找鬼薄坏。 笑死趋厉,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的胶坠。 我是一名探鬼主播君账,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼沈善!你這毒婦竟也來了乡数?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤闻牡,失蹤者是張志新(化名)和其女友劉穎瞳脓,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體澈侠,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡劫侧,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片烧栋。...
    茶點(diǎn)故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡写妥,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出审姓,到底是詐尸還是另有隱情珍特,我是刑警寧澤,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布魔吐,位于F島的核電站扎筒,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏酬姆。R本人自食惡果不足惜嗜桌,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望辞色。 院中可真熱鬧骨宠,春花似錦、人聲如沸相满。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽立美。三九已至匿又,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間建蹄,已是汗流浹背碌更。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留躲撰,地道東北人。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓击费,卻偏偏與公主長得像拢蛋,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子蔫巩,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,843評論 2 354

推薦閱讀更多精彩內(nèi)容