UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor nganinho
Visitor
167 Views
Registered: ‎04-08-2019

GPIO interrupt can not work on Arty A7

I have below code for the application to test the interrupt of GPIO.

But it seem to be incorrect, the interrupt handler can not be start after button was pressed.

My question is that, below code is neccessary or not ? and what is it used for ?

We have already connected the interrupt source to the coressponded handler, then why we need to register as the Xil_exception level.

// Xil_ExceptionRegisterHandler(1,
// (Xil_ExceptionHandler)GPIO0_HANDLER, 0);

 

Full program:

#---------------------------------

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

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


#define UART_INT_CHANNEL 0
#define GPIO0_INT_CHANNEL 1
#define GPIO1_INT_CHANNEL 2

XGpio Gpio0; /* The Instance of the GPIO0 Driver */
XGpio Gpio1; /* The Instance of the GPIO1 Driver */

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

void UART_HANDLER(void *Callbackref);
void GPIO0_HANDLER(void *Callbackref);
void GPIO1_HANDLER(void *Callbackref);

void GPIO0_HANDLER(void *Callbackref)
{
xil_printf("Handler GPIO0 !! \r\n");
//write out GPIO0, LED 0101
XGpio_DiscreteWrite(&Gpio0, 1, 0x05);
//Write out GPIO1, LED RGB
XGpio_DiscreteWrite(&Gpio1, 1, 0xAA55);
}

int main(void)
{

//Added variables
int Status; // for status
//int Failed; // for status

// Start the GPIO module
//init, call Gpio instance and its ID. Here is GPIO 0
Status = XGpio_Initialize(&Gpio0, XPAR_GPIO_0_DEVICE_ID);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

//SelfTest for GPIO0
Status = XGpio_SelfTest(&Gpio0);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
xil_printf("Xgpio0 init done !! \r\n");

//init, call Gpio instance and its ID. Here is GPIO 1
Status = XGpio_Initialize(&Gpio1, XPAR_GPIO_1_DEVICE_ID);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}

//SelfTest for GPIO1
Status = XGpio_SelfTest(&Gpio1);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
xil_printf("Xgpio1 init done !! \r\n");

// Set the direction
//set direction for GPIO0 - LED as output, push button as input
XGpio_SetDataDirection(&Gpio0, 1, 0x0000 );
XGpio_SetDataDirection(&Gpio0, 2, 0xFFFF );
//set direction for GPIO1 - 12 RGB LED as output, 4 switches as input
XGpio_SetDataDirection(&Gpio1, 1, 0x00000 );
XGpio_SetDataDirection(&Gpio1, 2, 0xFFFFF );

 


// Start and setup for INTC module
//1. Init the Interrupt controller
Status = XIntc_Initialize(&Intc, 0);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
xil_printf("1. INTC init done !! \r\n");

//2. Connect the handlers
Status = XIntc_Connect(&Intc, GPIO0_INT_CHANNEL,
(XInterruptHandler) &GPIO0_HANDLER,
(void *) 0);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
xil_printf("2. Inct handler connection done !! \r\n");


//3. Enable the INTC
XIntc_Enable(&Intc, GPIO0_INT_CHANNEL);
XIntc_Enable(&Intc, GPIO1_INT_CHANNEL);

xil_printf("3. INTC enable done !! \r\n");


//4. Start the INTC
Status = XIntc_Start(&Intc, XIN_REAL_MODE);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
xil_printf("4. INTC start done !! \r\n");


// Enable interrupt for GPIO0
XGpio_InterruptEnable( &Gpio0, 0x0000);
xil_printf("GPIO0 interrupt enable done !! \r\n");
XGpio_InterruptGlobalEnable( &Gpio0 );
xil_printf("GPIO0 Global interrupt enable done !! \r\n");

 


Xil_ExceptionInit();
//
// Xil_ExceptionRegisterHandler(1,
// (Xil_ExceptionHandler)GPIO0_HANDLER, 0);
//
// /* Enable non-critical exceptions */
Xil_ExceptionEnable();


xil_printf("Waiting for interrupt... !! \r\n");
while(1) {

}

//return
return XST_SUCCESS;
}

#------------------------------------------------

System is built like below:system.png

 

Please share your idea if there is any mistake on my program.

Thank you!

Tags (3)
0 Kudos
2 Replies
Highlighted
Xilinx Employee
Xilinx Employee
90 Views
Registered: ‎07-12-2018

Re: GPIO interrupt can not work on Arty A7

Hi @nganinho 

ARM processors specific exception related APIs for cortex A53,A9 and R5 can be utilized for enabling/disabling IRQ, registering/removing handler for exceptions or initializing exception vector table with null handler.

Best Regards
Abhinay PS
------------------------------------------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give kudos to a post which you think is helpful and reply oriented.
-------------------------------------------------------------------------------------------------------------------------------

Visitor nganinho
Visitor
79 Views
Registered: ‎04-08-2019

Re: GPIO interrupt can not work on Arty A7


@abhinayp wrote:

Hi @nganinho 

ARM processors specific exception related APIs for cortex A53,A9 and R5 can be utilized for enabling/disabling IRQ, registering/removing handler for exceptions or initializing exception vector table with null handler.


Thank you for your reply.

It means that the interrupt program for Microblaze does not need that function. 

Is my understanding correct ?

0 Kudos