• 0

Arty A7 GPIO interrupt handler callbackref incorrect


hdx

Question

Hello,

I have a project where I am using an MC33972 to trigger an GPIO interrupt when state changes. The problem I am facing currently is that when the interrupt is triggered, the callbackref to the gpio handler is receiving an incorrect instance. Whenever the handler is triggered the application crash and get stuck due to that the callbackref I receive is belonging to the INTC instanceptr and not the XGPIO instanceptr, so when calling XGpio_InterruptGetStatus(gpio_ptr); the application fails on the asserts as they are incorrect and not belonging to the XGPIO but instead INTC.

Has anybody had similar problem before or encountered similar problem?

This is my initialization for the interrupt:

XStatus init_interrupt(XGpio *InstancePtr)
{
	xil_printf("\r\n********Initializing GPIO interrupts...********\r\n");
	int status;

	XGpio_InterruptClear(InstancePtr, 0xFFFFFFFF);

	status = XIntc_Initialize(&intc, INTC_DEVICE_ID);
	if (status != XST_SUCCESS)
	{
		xil_printf("XIntc_Initialize failed\n\r");
		return status;
	}
	usleep(100);

	status = XIntc_Connect(&intc, XPAR_INTC_0_GPIO_0_VEC_ID, (XInterruptHandler)InterruptHandler, (void *)InstancePtr);
	if (status != XST_SUCCESS)
	{
		xil_printf("XIntc_Connect failed\n\r");
		return status;
	}

	usleep(100);
	XIntc_Enable(&intc, XPAR_INTC_0_GPIO_0_VEC_ID);

	usleep(100);
	XIntc_Start(&intc, XIN_REAL_MODE);

	Xil_ExceptionInit();
	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_M_AXI_I_EXCEPTION, (XExceptionHandler)INTC_HANDLER, &intc);
	Xil_ExceptionEnable();

	XGpio_InterruptGlobalEnable(InstancePtr);
	usleep(100);
  
	XGpio_InterruptEnable(InstancePtr, XGPIO_IR_CH1_MASK); // #TODO! interrupt stops the XSPI somehow
 	usleep(100);
  
	xil_printf(" - Successfully initialized GPIO interrupt!\r\n");
	xil_printf("*******************************************\r\n");
	return status;
}

void InterruptHandler(void *CallbackRef)
{
	//XGpio *ptr = CallbackRef;
	//xil_printf("Interrupt! base address =  0x%X .... 0x%X\r\n", ptr->BaseAddress, ptr->InterruptPresent);
	u32 mask = XGpio_InterruptGetStatus(gpio);
	if(mask == 1)
	{
		//Do something here...
	}
	else
	{
		//Do something here...
	}

	XGpio_InterruptClear(CallbackRef, 0xFFFFFFFFF);
	XIntc_Acknowledge(&intc, XPAR_INTC_0_GPIO_0_VEC_ID);
}

 

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now