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: 
Highlighted
Visitor drinu8
Visitor
6,623 Views
Registered: ‎10-21-2015

Once I remove GPIO Interrupt handler, UARTlite Interrupt works, else it does not.

Hi,

 

Something weird is happening - with reference to the code below, when I comment the gpio handler (ihandler_gpo2), the interrupt of the uart (transmitting) is handled successfully, whilst when I uncomment the handler, the interrupt is not handled. In both modes, the data is transmitted via the FPGA. I tried commenting everything in the gpio handler, and leaving the function 'title' - similar to the prototype, but without a semicolon but to no avail. I am not sure what I am doing wrong.

 

Any help would be greatly appreciated as I have no idea why this is happening apart from that it's something that has to do with the gpio interrupts.

just FYI, I am using SDK, and the system debugger.

int main()
{
    init_peripherals(&gpio2, &uart0);

	xil_printf("1 - ");
	XUartLite_Recv(&uart0, recbuf, 2);
	xil_printf("2 - ");

	XUartLite_Send(&uart0, sendbuf, 2);
	xil_printf("3 - ");

	while ((TotalSentCount != 2)) {
	}
	xil_printf("4 - ");
	xil_printf("uart done\n\r");

    while(1)
    {
    	
	}

    return 0;
}

void init_peripherals(XGpio *Gpio2Ptr, XUartLite *UartLitePtr)
{
	// initialise GPIO
	status = XGpio_Initialize (&gpio0,gpio_id);
	status = status + XGpio_Initialize (&gpio1,gpio1_id);
	status = status + XGpio_Initialize (&gpio2,gpio2_id);
	initialise_check("GPIO", status);

	// data direction for gpio0 | 0 out, 1 input
	XGpio_SetDataDirection (&gpio2,2, (cb_data | cb_clk | cb_m_alrt | PLL_STAT | reset | hdr ) & (~(cb_s_alrt | DAC_dn | PLL_dn | LED | LEDs )));
	XGpio_SetDataDirection (&gpio2,1, 0);
	XGpio_DiscreteSet(&gpio2,2,cb_s_alrt);

	//UART initialisation
	status = XUartLite_Initialize (UartLitePtr, uart_id);
	status = status + XUartLite_SelfTest(UartLitePtr);
	initialise_check("UART", status);

	//interrupt initialisation
	status = XIntc_Initialize(&int_con, int_id);
	//connecting interrupt handlers
	status = status + XIntc_Connect(&int_con, int_uart_id,(XInterruptHandler)XUartLite_InterruptHandler, (void *)UartLitePtr);	//uart
	//status = status + XIntc_Connect(&int_con, int_cbus_id, (XInterruptHandler)ihandler_gpo2, (void *)Gpio2Ptr); 	// gpio

	//start interrupt
	status = status + XIntc_Start(&int_con, XIN_REAL_MODE);//XIN_SIMULATION_MODE XIN_REAL_MODE
	//XIntc_Enable(&int_con, int_cbus_id); // gpio
	XIntc_Enable(&int_con, int_uart_id); // uart
	initialise_check("Interrupts", status);

	//gpio interrupt enable
	XGpio_InterruptEnable(&gpio2, XGPIO_IR_CH2_MASK);//XGPIO_IR_CH2_MASK
	XGpio_InterruptGlobalEnable(&gpio2);
	XGpio_InterruptClear(&gpio2,0x02); // 0x02 - for channel 2

	//uart interrupt settings
	XUartLite_SetSendHandler(UartLitePtr, MySendHandler, UartLitePtr);
	XUartLite_SetRecvHandler(UartLitePtr, MyRecvHandler, UartLitePtr);
	XUartLite_EnableInterrupt(UartLitePtr);
	xil_printf("interrupt enabled");

	//register exception handler with interrupt controller table
	Xil_ExceptionInit();
	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,(Xil_ExceptionHandler)XIntc_InterruptHandler,	&int_con);
	Xil_ExceptionEnable();

}

void MySendHandler(void *CallBackRef, unsigned int EventData)
{
	TotalSentCount = EventData;
	xil_printf("datasent\n\r");
	XUartLite_ResetFifos (&uart0 );
}

void MyRecvHandler(void *CallBackRef, unsigned int EventData)
{
	TotalReceivedCount = EventData;
}

void ihandler_gpo2 (void *InstancePtr)
{
	u32 dataread;
	static u32 dataread_before = 0;

	dataread = XGpio_DiscreteRead(&gpio2,2);
	//xil_printf("data read is - %x \n\r", dataread);

	//if (((dataread & (0x1<pll_stat)) == 0) && ((dataread_before & (0x1<<pll_stat)) > 0))
	{
		// PLL Output is not locked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		// Do something :(
		//gpo0 = gpo0 & (~mb_clken);
		//XGpio_DiscreteWrite(&gpio1, 1, gpo0);
		//set a flag?
		//xil_printf("LTC6946 not locked");
	}
	//else
		if ((dataread & 0xFF) != (dataread_before & 0xFF))
		//checking whether there has been any change in the bus
		{
			if (((dataread & cb_m_alrt) == 0) && (rx != 1) && (tx != 1))
			{
				rx = 1; tx = 0;
				//xil_printf("rx=1\n\r");
			}
			if ((tx == 1) || (rx == 1))
			{
				cbus_handler(dataread & 0xFF, &gpio2, &cbusflags, &tx, &rx, &gpo2);
				//xil_printf("cbus\n\r");
			}
		}

	dataread_before = dataread;

	XGpio_InterruptClear(&gpio2,0x02); // 0x02 - for channel 2
    XIntc_Acknowledge(&int_con,int_cbus_id);
}


void initialise_check(char str[],
				u8 status)
{
	if (~status)
	{	xil_printf(" %20s - successful\n\r", str);	}
	else  {xil_printf(" %25s - ERROR\n\r", str); }
	xil_printf("-----------------------------------\n\r");
}

Best regards,

0 Kudos