/** * * This function does a minimal test on the UartLite device and driver as a * design example. The purpose of this function is to illustrate * how to use the XUartLite component. * * This function sends data and expects to receive the same data through the * UartLite. The user must provide a physical loopback such that data which is * transmitted will be received. * * This function uses interrupt driver mode of the UartLite device. The calls * to the UartLite driver in the handlers should only use the non-blocking * calls. * * @param DeviceId is the Device ID of the UartLite Device and is the * XPAR_<uartlite_instance>_DEVICE_ID value from xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note * * This function contains an infinite loop such that if interrupts are not * working it may never return. * ****************************************************************************/ int UartLiteIntrExample(u16 DeviceId) { int Status; int Index; /* * Initialize the UartLite driver so that it's ready to use. */ Status = XUartLite_Initialize(&UartLite, DeviceId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XUartLite_SelfTest(&UartLite); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect the UartLite to the interrupt subsystem such that interrupts can * occur. This function is application specific. */ Status = SetupInterruptSystem(&UartLite); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the handlers for the UartLite that will be called from the * interrupt context when data has been sent and received, specify a * pointer to the UartLite driver instance as the callback reference so * that the handlers are able to access the instance data. */ XUartLite_SetSendHandler(&UartLite, SendHandler, &UartLite); XUartLite_SetRecvHandler(&UartLite, RecvHandler, &UartLite); /* * Enable the interrupt of the UartLite so that interrupts will occur. */ XUartLite_EnableInterrupt(&UartLite); /* * Initialize the send buffer bytes with a pattern to send and the * the receive buffer bytes to zero to allow the receive data to be * verified. */ for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) { SendBuffer[Index] = Index; ReceiveBuffer[Index] = 0; } /* * Start receiving data before sending it since there is a loopback. */ XUartLite_Recv(&UartLite, ReceiveBuffer, TEST_BUFFER_SIZE); /* * Send the buffer using the UartLite. */ XUartLite_Send(&UartLite, SendBuffer, TEST_BUFFER_SIZE); /* * Wait for the entire buffer to be received, letting the interrupt * processing work in the background, this function may get locked * up in this loop if the interrupts are not working correctly. */ while ((TotalReceivedCount != TEST_BUFFER_SIZE) || (TotalSentCount != TEST_BUFFER_SIZE)) { } /* * Verify the entire receive buffer was successfully received. */ for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) { if (ReceiveBuffer[Index] != SendBuffer[Index]) { return XST_FAILURE; } } return XST_SUCCESS; }
int interrupt_init(){ int Result; Result = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); if (Result != XST_SUCCESS) { return Result; } Result = XIntc_Connect(&InterruptController, INTC_GPIO_INTERRUPT_ID, (XInterruptHandler)GpioIsr, &Gpio); if (Result != XST_SUCCESS) { warp_printf(PL_ERROR,"Failed to connect GPIO to XIntc\n"); return Result; } Result = XIntc_Connect(&InterruptController, UARTLITE_INT_IRQ_ID, (XInterruptHandler)XUartLite_InterruptHandler, &UartLite); if (Result != XST_SUCCESS) { warp_printf(PL_ERROR,"Failed to connect XUartLite to XIntc\n"); return Result; } //Connect Timer to Interrupt Controller Result = XIntc_Connect(&InterruptController, TMRCTR_INTERRUPT_ID, (XInterruptHandler)XTmrCtr_CustomInterruptHandler, &TimerCounterInst); //Result = XIntc_Connect(&InterruptController, TMRCTR_DEVICE_ID, (XInterruptHandler)timer_handler, &TimerCounterInst); if (Result != XST_SUCCESS) { xil_printf("Failed to connect XTmrCtr to XIntC\n"); return -1; } wlan_lib_setup_mailbox_interrupt(&InterruptController); wlan_eth_setup_interrupt(&InterruptController); Result = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Result != XST_SUCCESS) { warp_printf(PL_ERROR,"Failed to start XIntc\n"); return Result; } XIntc_Enable(&InterruptController, INTC_GPIO_INTERRUPT_ID); XIntc_Enable(&InterruptController, UARTLITE_INT_IRQ_ID); XIntc_Enable(&InterruptController, TMRCTR_INTERRUPT_ID); Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,(Xil_ExceptionHandler)XIntc_InterruptHandler, &InterruptController); /* Enable non-critical exceptions */ Xil_ExceptionEnable(); XGpio_InterruptEnable(&Gpio, GPIO_INPUT_INTERRUPT); XGpio_InterruptGlobalEnable(&Gpio); XUartLite_SetSendHandler(&UartLite, SendHandler, &UartLite); XUartLite_SetRecvHandler(&UartLite, RecvHandler, &UartLite); XUartLite_EnableInterrupt(&UartLite); XUartLite_Recv(&UartLite, ReceiveBuffer, UART_BUFFER_SIZE); return 0; }
int main(void) { LOG_INFO("UART CTP FE echo test\n"); init_platform(); tx_buffer = cbuffer_new(); rx_buffer = cbuffer_new(); int Status; u16 DeviceId = UARTLITE_DEVICE_ID; /* * Initialize the UartLite driver so that it's ready to use. */ Status = XUartLite_Initialize(&UartLite, DeviceId); if (Status != XST_SUCCESS) { LOG_ERROR ("Error: could not initialize UART\n"); return XST_FAILURE; } XUartLite_ResetFifos(&UartLite); /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XUartLite_SelfTest(&UartLite); if (Status != XST_SUCCESS) { LOG_ERROR ("Error: self test failed\n"); return XST_FAILURE; } /* * Connect the UartLite to the interrupt subsystem such that interrupts can * occur. This function is application specific. */ Status = SetupInterruptSystem(&UartLite); if (Status != XST_SUCCESS) { LOG_ERROR ("Error: could not setup interrupts\n"); return XST_FAILURE; } /* * Setup the handlers for the UartLite that will be called from the * interrupt context when data has been sent and received, specify a * pointer to the UartLite driver instance as the callback reference so * that the handlers are able to access the instance data. */ XUartLite_SetSendHandler(&UartLite, SendHandler, &UartLite); XUartLite_SetRecvHandler(&UartLite, RecvHandler, &UartLite); /* * Enable the interrupt of the UartLite so that interrupts will occur. */ XUartLite_EnableInterrupt(&UartLite); // bootstrap the READ LOG_DEBUG("Bootstrapping READ\n"); XUartLite_Recv(&UartLite, (u8*)&rx_tmp_buffer, sizeof(uint32_t)); LOG_INFO("Starting loop\n"); /* LOG_DEBUG("Sending 'wtf!'\n"); currently_sending = 1; char help[4] = "wtf!"; unsigned int ret = XUartLite_Send(&UartLite, (u8*)help, 4); LOG_DEBUG("WTF send complete return: %x\n", ret); */ /* echo received data forever */ unsigned int heartbeat = 0; while (1) { if (heartbeat++ % (1 << 8)) { //LOG_DEBUG("bump %x\n", heartbeat); } while (cbuffer_size(rx_buffer) && cbuffer_freespace(tx_buffer)) { uint32_t data = cbuffer_pop_front(rx_buffer); //LOG_DEBUG("Echoing data word %x\n", data); cbuffer_push_back(tx_buffer, data); } if (!currently_sending && cbuffer_size(tx_buffer)) { LOG_DEBUG("\nREINT SEND\n"); currently_sending = 1; /* if (XUartLite_IsSending(&UartLite)) { LOG_DEBUG("UART STAT: sending\n"); } else { LOG_DEBUG("UART STAT: idle\n"); } */ unsigned int to_send = cbuffer_contiguous_data_size(tx_buffer) * sizeof(uint32_t); u8* output_ptr = (u8*)&(tx_buffer->data[tx_buffer->pos]); //LOG_DEBUG("REINIT %x\n", to_send); //LOG_DEBUG("SENDADDR %x\n", output_ptr); XUartLite_Send(&UartLite, output_ptr, to_send); } } }
/** * This function sets up the interrupt system for the example. The processing * contained in this funtion assumes the hardware system was built with * and interrupt controller. * * @param None. * * @return A status indicating XST_SUCCESS or a value that is contained in * xstatus.h. * * @note None. * *****************************************************************************/ int BT2_SetupInterruptSystem(PmodBT2* InstancePtr, u32 interruptID, void* receiveHandlerFunction, void* sendHandlerFunction) { int Result; #ifdef XPAR_XINTC_NUM_INSTANCES INTC *IntcInstancePtr = &InstancePtr->intc; /* * 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, interruptID); if (Result != XST_SUCCESS) { return Result; } /* Hook up interrupt service routine */ XIntc_Connect(IntcInstancePtr, interruptID, (Xil_ExceptionHandler)XUartLite_InterruptHandler, &InstancePtr->BT2Uart); /* Enable the interrupt vector at the interrupt controller */ XIntc_Enable(IntcInstancePtr, interruptID); /* * 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; } XUartLite_SetRecvHandler(&InstancePtr->BT2Uart, (XUartLite_Handler)receiveHandlerFunction, InstancePtr); XUartLite_SetSendHandler(&InstancePtr->BT2Uart, (XUartLite_Handler)sendHandlerFunction, 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(); XUartLite_EnableInterrupt(&InstancePtr->BT2Uart); #endif #ifdef XPAR_SCUGIC_0_DEVICE_ID INTC *IntcInstancePtr = &InstancePtr->intc; 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; } XScuGic_SetPriorityTriggerType(IntcInstancePtr, interruptID, 0xA0, 0x3); /* * Connect the interrupt handler that will be called when an * interrupt occurs for the device. */ Result = XScuGic_Connect(IntcInstancePtr, interruptID, (Xil_ExceptionHandler)XUartLite_InterruptHandler, &InstancePtr->BT2Uart); if (Result != XST_SUCCESS) { return Result; } /* * Enable the interrupt for the GPIO device. */ XScuGic_Enable(IntcInstancePtr, interruptID); XUartLite_SetRecvHandler(&InstancePtr->BT2Uart, (XUartLite_Handler)receiveHandlerFunction, InstancePtr); XUartLite_SetSendHandler(&InstancePtr->BT2Uart, (XUartLite_Handler)sendHandlerFunction, 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(); XUartLite_EnableInterrupt(&InstancePtr->GPSUart); #endif return XST_SUCCESS; }