xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) { /* NOTE: The baud rate used by this driver is determined by the hardware parameterization of the UART Lite peripheral, and the baud value passed to this function has no effect. */ ( void ) ulWantedBaud; /* Create the queues used to hold Rx and Tx characters. */ xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* Only initialise the UART if the queues were created correctly. */ if( ( xRxedChars != NULL ) && ( xCharsForTx != NULL ) ) { XUartLite_Initialize( &xUART, XPAR_RS232_UART_1_DEVICE_ID ); XUartLite_ResetFifos( &xUART ); XUartLite_DisableInterrupt( &xUART ); if( xPortInstallInterruptHandler( XPAR_XPS_INTC_0_RS232_UART_1_INTERRUPT_INTR, ( XInterruptHandler )vSerialISR, (void *)&xUART ) == pdPASS ) { /* xPortInstallInterruptHandler() could fail if vPortSetupInterruptController() has not been called prior to this function. */ XUartLite_EnableInterrupt( &xUART ); } } /* There is only one port so the handle is not used. */ return ( xComPortHandle ) 0; }
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) { portBASE_TYPE xStatus; /* The standard demo header file requires a baud rate to be passed into this function. However, in this case the baud rate is configured when the hardware is generated, leaving the ulWantedBaud parameter redundant. */ ( void ) ulWantedBaud; /* Create the queue used to hold Rx characters. */ xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* If the queue was created correctly, then setup the serial port hardware. */ if( xRxedChars != NULL ) { xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID ); if( xStatus == XST_SUCCESS ) { /* Complete initialisation of the UART and its associated interrupts. */ XUartLite_ResetFifos( &xUartLiteInstance ); /* Install the handlers that the standard Xilinx library interrupt service routine will call when Rx and Tx events occur respectively. */ XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL ); XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL ); /* Install the standard Xilinx library interrupt handler itself. *NOTE* The xPortInstallInterruptHandler() API function must be used for this purpose. */ xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance ); /* Enable the interrupt in the peripheral. */ XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress ); /* Enable the interrupt in the interrupt controller. *NOTE* The vPortEnableInterrupt() API function must be used for this purpose. */ vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID ); } configASSERT( xStatus == pdPASS ); } /* This demo file only supports a single port but something must be returned to comply with the standard demo header file. */ return ( xComPortHandle ) 0; }
int UART_Init(XUartLite *UART_Inst_Ptr_1, u16 Uart_1_Dev_ID, XUartLite *UART_Inst_Ptr_2, u16 Uart_2_Dev_ID) { int Status; /* Initialize the UART drivers so that they are ready to use. */ Status = XUartLite_Initialize(UART_Inst_Ptr_1, Uart_1_Dev_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } Status = XUartLite_Initialize(UART_Inst_Ptr_2, Uart_2_Dev_ID); 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(UART_Inst_Ptr_1, SendHandler_UART_1, UART_Inst_Ptr_1); XUartLite_SetRecvHandler(UART_Inst_Ptr_1, RecvHandler_UART_1, UART_Inst_Ptr_1); XUartLite_SetSendHandler(UART_Inst_Ptr_2, SendHandler_UART_2, UART_Inst_Ptr_2); XUartLite_SetRecvHandler(UART_Inst_Ptr_2, RecvHandler_UART_2, UART_Inst_Ptr_2); /* * Enable the interrupt of the UartLite so that interrupts will occur. */ XUartLite_EnableInterrupt(UART_Inst_Ptr_1); XUartLite_EnableInterrupt(UART_Inst_Ptr_2); return XST_SUCCESS; }
int init_axi_uart(){ int Status; // Initialize the UartLite driver so that it is ready to use. Status = XUartLite_Initialize(&uart_device, UART_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } // Perform a self-test to ensure that the hardware was built correctly. Status = XUartLite_SelfTest(&uart_device); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }
/** * * 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. * * * @param DeviceId is the XPAR_<uartlite_instance>_DEVICE_ID value from * xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ****************************************************************************/ int UartLiteSelfTestExample(u16 DeviceId) { int Status; /* * Initialize the UartLite driver so that it is 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; } return XST_SUCCESS; }
void InitInterrupts() { // Initialize wireless uart XUartLite_Initialize(&(wireless.uart), XPAR_WIRELESS_UART_DEVICE_ID); XUartLite_ResetFifos(&(wireless.uart)); Wireless_Init(&wireless); // Initialize gameboard uart XUartLite_Initialize(&gameboard_uart, XPAR_GAMEBOARD_UART_DEVICE_ID); XUartLite_ResetFifos(&gameboard_uart); // Initialize the interrupt controller XIntc_Initialize(&InterruptController, XPAR_INTC_0_DEVICE_ID); // Connect the wireless uart to the interrupt controller XIntc_Connect(&InterruptController, XPAR_XPS_INTC_0_WIRELESS_UART_INTERRUPT_INTR, (XInterruptHandler)XUartLite_InterruptHandler, (void *)&(wireless.uart)); // Connect the gameboard uart to the interrupt controller XIntc_Connect(&InterruptController, XPAR_XPS_INTC_0_GAMEBOARD_UART_INTERRUPT_INTR, (XInterruptHandler)XUartLite_InterruptHandler, (void *)&gameboard_uart); //XIntc_Connect(&InterruptController, XPAR_INTC_0_GPIO_0_VEC_ID, // (Xil_ExceptionHandler)GpioHandler, &Gpio); XIntc_Start(&InterruptController, XIN_REAL_MODE); // Enable interrupts for serial controllers XIntc_Enable(&InterruptController, XPAR_XPS_INTC_0_WIRELESS_UART_INTERRUPT_INTR); XIntc_Enable(&InterruptController, XPAR_XPS_INTC_0_GAMEBOARD_UART_INTERRUPT_INTR); // Enable interrupts for the GPIO //XIntc_Enable(&InterruptController, XPAR_INTC_0_GPIO_0_VEC_ID); Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XIntc_InterruptHandler, &InterruptController); Xil_ExceptionEnable(); // Set up send/receive handlers for wireless uart XUartLite_SetSendHandler(&(wireless.uart), WirelessSendHandler, &(wireless.uart)); XUartLite_SetRecvHandler(&(wireless.uart), WirelessRecvHandler, &(wireless.uart)); //XUartLite_SetRecvHandler(&(wireless.uart), WirelessRecvHandlerNonBlocking, &(wireless.uart)); Wireless_Debug("Wireless should be set up now"); // Set up send/receive handlers for gameboard uart XUartLite_SetSendHandler(&gameboard_uart, GameboardSendHandler, &gameboard_uart); XUartLite_SetRecvHandler(&gameboard_uart, GameboardRecvHandler, &gameboard_uart); XUartLite_EnableInterrupt(&(wireless.uart)); XUartLite_EnableInterrupt(&gameboard_uart); // Enable interrupts for GPIO //XGpio_InterruptEnable(&Gpio, XGPIO_IR_CH2_MASK); //XGpio_InterruptGlobalEnable(&Gpio); // Set up PIT XExceptionHandler pithandler = &my_pitHandler; XExc_RegisterHandler(XEXC_ID_PIT_INT, pithandler, 0); XTime_PITEnableAutoReload(); // PIT should be set to 1ms XTime_PITSetInterval(300000); XExc_mEnableExceptions(XEXC_ALL); XTime_PITEnableInterrupt(); XTime_PITClearInterrupt(); }
/** * * 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 main() { // -- INITIALIZATIONS -- // volatile u32 *ddr_addr = (volatile u32 *) XPAR_S6DDR_0_S0_AXI_BASEADDR; frame_merge_Initialize (&Merge_IP, XPAR_FRAME_MERGE_0_BASEADDR); volatile int *hdmi_addr = (int *) XPAR_HDMI_OUT_0_BASEADDR; u32 pixel_value = 0x0; XStatus status; int i, j; int k; int DELAY = 10000; char input; status = XUtil_MemoryTest32((u32 *) ddr_addr, NUM_TEST_WORDS, TEST_VECTOR, XUT_ALLMEMTESTS); if (XST_SUCCESS != status) { printf("Error - Memory self test failed. Exiting...\r\n"); return -1; } status = XUartLite_Initialize(&UartLite, XPAR_UARTLITE_1_DEVICE_ID); if (XST_SUCCESS != status) { printf("Error - UartLite self test failed. Exiting...\r\n"); return -1; } // Initialize HDMI-OUT IP Block hdmi_addr[0] = 1280; // hdmi_addr[0] corresponds to slv_reg2 --> Set Stride hdmi_addr[1] = (int)(ddr_addr + COMPFRAME_OFFSET); // Display Comp Frame hdmi_addr[2] = 0; // Ensure Go signal is low printf ("Setup of HDMI-OUT complete\n"); // -- FRAME INIT OPERATIONS -- // Initialize DrawFrame - image to draw on top of VideoFrame for (j = 0; j < VRES; j++) { for (i = 0; i < HRES; i++) { if(i >= BOX_X0 && i < BOX_X1 && j >= BOX_Y0 && j < BOX_Y1) { pixel_value = YELLOW; // Yellow box } else { pixel_value = WHITE; // in a white frame } ddr_addr[DRAWFRAME_OFFSET + j * HRES + i] = pixel_value; } } // Initialize VideoFrame (input video, simulate as columns of solid colour (Blue/Red/Green) from left to right) for (j = 0; j < VRES; j++) { for (i = 0; i < HRES/3; i++) { pixel_value = BLUE; ddr_addr[VIDEOFRAME_OFFSET + j * HRES + i] = pixel_value; } for (i = HRES/3; i < 2*HRES/3; i++) { pixel_value = RED; ddr_addr[VIDEOFRAME_OFFSET + j * HRES + i] = pixel_value; } for (i = 2*HRES/3; i < HRES; i++) { pixel_value = GREEN; ddr_addr[VIDEOFRAME_OFFSET + j * HRES + i] = pixel_value; } } // Initialize CompositeFrame (output video = VideoFrame + DrawFrame. Initialize as black) for (j = 0; j < VRES; j++) { for (i = 0; i < HRES; i++) { pixel_value = BLACK; ddr_addr[COMPFRAME_OFFSET + j * HRES + i] = pixel_value; } } printf ("Frame Initialization complete!\n"); // -- MERGE OPERATIONS -- frame_merge_sw (ddr_addr, (int)(DRAWFRAME_OFFSET), (int)(VIDEOFRAME_OFFSET), (int)(COMPFRAME_OFFSET), HRES, VRES); // Enable HDMI-OUT once merging is finished hdmi_addr[2] = 1; printf ("Frame Merge complete!\n"); printf ("Enter (0/1/2) for (draw/video/composite) frames:\n"); // Allow user to switch between draw, video, and comp frames // to output to screen input = 0; while(1) { XUartLite_Recv(&UartLite, &input, 1); // Recv 1 byte (char) and store into buffer switch (input) { case '0': // DrawFrame hdmi_addr[1] = (int)(ddr_addr + DRAWFRAME_OFFSET); break; case '1': // VideoFrame hdmi_addr[1] = (int)(ddr_addr + VIDEOFRAME_OFFSET); break; case '2': // CompFrame hdmi_addr[1] = (int)(ddr_addr + COMPFRAME_OFFSET); break; default: hdmi_addr[1] = (int)(ddr_addr + COMPFRAME_OFFSET); break; } } printf("Exiting\n\r"); 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); } } }
void wlan_mac_util_init( u32 type, u32 eth_dev_num ){ int Status; u32 i; u32 gpio_read; u32 queue_len; u64 timestamp; u32 log_size; tx_frame_info* tx_mpdu; // Initialize callbacks eth_rx_callback = (function_ptr_t)nullCallback; mpdu_rx_callback = (function_ptr_t)nullCallback; fcs_bad_rx_callback = (function_ptr_t)nullCallback; mpdu_tx_done_callback = (function_ptr_t)nullCallback; pb_u_callback = (function_ptr_t)nullCallback; pb_m_callback = (function_ptr_t)nullCallback; pb_d_callback = (function_ptr_t)nullCallback; uart_callback = (function_ptr_t)nullCallback; ipc_rx_callback = (function_ptr_t)nullCallback; check_queue_callback = (function_ptr_t)nullCallback; mpdu_tx_accept_callback = (function_ptr_t)nullCallback; wlan_mac_ipc_init(); for(i=0;i < NUM_TX_PKT_BUFS; i++){ tx_mpdu = (tx_frame_info*)TX_PKT_BUF_TO_ADDR(i); tx_mpdu->state = TX_MPDU_STATE_EMPTY; } tx_pkt_buf = 0; #ifdef _DEBUG_ xil_printf("locking tx_pkt_buf = %d\n", tx_pkt_buf); #endif if(lock_pkt_buf_tx(tx_pkt_buf) != PKT_BUF_MUTEX_SUCCESS){ warp_printf(PL_ERROR,"Error: unable to lock pkt_buf %d\n",tx_pkt_buf); } tx_mpdu = (tx_frame_info*)TX_PKT_BUF_TO_ADDR(tx_pkt_buf); tx_mpdu->state = TX_MPDU_STATE_TX_PENDING; //Initialize the central DMA (CDMA) driver XAxiCdma_Config *cdma_cfg_ptr; cdma_cfg_ptr = XAxiCdma_LookupConfig(XPAR_AXI_CDMA_0_DEVICE_ID); Status = XAxiCdma_CfgInitialize(&cdma_inst, cdma_cfg_ptr, cdma_cfg_ptr->BaseAddress); if (Status != XST_SUCCESS) { warp_printf(PL_ERROR,"Error initializing CDMA: %d\n", Status); } XAxiCdma_IntrDisable(&cdma_inst, XAXICDMA_XR_IRQ_ALL_MASK); Status = XGpio_Initialize(&Gpio, GPIO_DEVICE_ID); gpio_timestamp_initialize(); if (Status != XST_SUCCESS) { warp_printf(PL_ERROR, "Error initializing GPIO\n"); return; } Status = XUartLite_Initialize(&UartLite, UARTLITE_DEVICE_ID); if (Status != XST_SUCCESS) { warp_printf(PL_ERROR, "Error initializing XUartLite\n"); return; } gpio_read = XGpio_DiscreteRead(&Gpio, GPIO_INPUT_CHANNEL); if(gpio_read&GPIO_MASK_DRAM_INIT_DONE){ xil_printf("DRAM SODIMM Detected\n"); if(memory_test()==0){ queue_dram_present(1); dram_present = 1; } else { queue_dram_present(0); dram_present = 0; } } else { queue_dram_present(0); dram_present = 0; timestamp = get_usec_timestamp(); while((get_usec_timestamp() - timestamp) < 100000){ if((XGpio_DiscreteRead(&Gpio, GPIO_INPUT_CHANNEL)&GPIO_MASK_DRAM_INIT_DONE)){ xil_printf("DRAM SODIMM Detected\n"); if(memory_test()==0){ queue_dram_present(1); dram_present = 1; } else { queue_dram_present(0); dram_present = 0; } break; } } } queue_len = queue_init(); if( dram_present ) { //The event_list lives in DRAM immediately following the queue payloads. if(MAX_EVENT_LOG == -1){ log_size = (DDR3_SIZE - queue_len); } else { log_size = min( (DDR3_SIZE - queue_len), MAX_EVENT_LOG ); } event_log_init( (void*)(DDR3_BASEADDR + queue_len), log_size ); } else { log_size = 0; } #ifdef USE_WARPNET_WLAN_EXP // Communicate the log size to WARPNet node_info_set_event_log_size( log_size ); #endif wlan_eth_init(); //Set direction of GPIO channels XGpio_SetDataDirection(&Gpio, GPIO_INPUT_CHANNEL, 0xFFFFFFFF); XGpio_SetDataDirection(&Gpio, GPIO_OUTPUT_CHANNEL, 0); Status = XTmrCtr_Initialize(&TimerCounterInst, TMRCTR_DEVICE_ID); if (Status != XST_SUCCESS) { xil_printf("XTmrCtr failed to initialize\n"); return; } //Set the handler for Timer XTmrCtr_SetHandler(&TimerCounterInst, timer_handler, &TimerCounterInst); //Enable interrupt of timer and auto-reload so it continues repeatedly XTmrCtr_SetOptions(&TimerCounterInst, TIMER_CNTR_FAST, XTC_DOWN_COUNT_OPTION | XTC_INT_MODE_OPTION); XTmrCtr_SetOptions(&TimerCounterInst, TIMER_CNTR_SLOW, XTC_DOWN_COUNT_OPTION | XTC_INT_MODE_OPTION); timer_running[TIMER_CNTR_FAST] = 0; timer_running[TIMER_CNTR_SLOW] = 0; // Get the type of node from the input parameter hw_info.type = type; hw_info.wn_exp_eth_device = eth_dev_num; #ifdef USE_WARPNET_WLAN_EXP // We cannot initialize WARPNet until after the lower CPU sends all the HW information to us through the IPC call warpnet_initialized = 0; #endif wlan_mac_ltg_sched_init(); }
int main() { /********************** TouchSensor Setup *********************/ Status = TouchSensor_Initialize(&touchSensor, XPAR_TOUCHSENSOR_0_DEVICE_ID); if (Status != XST_SUCCESS) { // printf("TouchSensor initialisation error\n\r\r"); } TouchSensorButtons_InitializeManager(&Manager, &touchSensor, &PrintTouchCoordinates); button_t GameboardGridButton; Button_SetGridDim(&GameboardGridButton, SQUARE_DIM, SQUARE_DIM, BOARD_OFFSET_X, BOARD_OFFSET_Y, BOARD_SIZE, BOARD_SIZE); Button_AssignHandler(&GameboardGridButton, &HandleGameboardTouch); TouchSensorButtons_RegisterButton(&Manager, &GameboardGridButton); TouchSensorButtons_EnableButton(&GameboardGridButton); button_t WhiteModeButton; Button_SetGridDim(&WhiteModeButton, 50, 50, 300, 10 , 3, 1); Button_AssignHandler(&WhiteModeButton, &HandleWhiteModeTouch); TouchSensorButtons_RegisterButton(&Manager, &WhiteModeButton); TouchSensorButtons_EnableButton(&WhiteModeButton); button_t BlackModeButton; Button_SetGridDim(&BlackModeButton, 50, 50, 300, 75, 3, 1); Button_AssignHandler(&BlackModeButton, &HandleBlackModeTouch); TouchSensorButtons_RegisterButton(&Manager, &BlackModeButton); TouchSensorButtons_EnableButton(&BlackModeButton); button_t ResetButton; Button_SetRectDim(&ResetButton, 100, 50, 325, 200); Button_AssignHandler(&ResetButton, &HandleResetTouch); TouchSensorButtons_RegisterButton(&Manager, &ResetButton); TouchSensorButtons_EnableButton(&ResetButton); /********************** BoardCount Accelerator Setup********************/ initialize_accelerator(&board_count_accelerator, XPAR_GENERATE_BOARD_COUNTS_TOP_0_S_AXI_CTRL_BASEADDR); /********************** TFT Setup *********************/ blackScreen(); TFT_Initialize(&tft, XPAR_TFT_PERHIPHERAL_0_DEVICE_ID); TFT_SetImageAddress(&tft, XPAR_MCB_DDR2_S0_AXI_BASEADDR); TFT_SetBrightness(&tft, 7); TFT_TurnOn(&tft); //Render Buttons //TouchSensorButtons_RenderButton(&MyCircle, GREEN, &tft); //TouchSensorButtons_RenderButton(&MyRect, RED, &tft); TouchSensorButtons_RenderButton(&GameboardGridButton, BLUE, &tft); TouchSensorButtons_RenderButton(&ResetButton, ORANGE, &tft); TouchSensorButtons_RenderButton(&WhiteModeButton, WHITE, &tft); TouchSensorButtons_RenderButton(&BlackModeButton, RED, &tft); Gameboard.TftPtr = &tft; /********************** UART Setup *********************/ Status = XUartLite_Initialize(&Uart, XPAR_UARTLITE_1_DEVICE_ID); if (Status != XST_SUCCESS) { printf("XUartLite initialization error\n\r"); } XUartLite_SetRecvHandler(&Uart, (XUartLite_Handler) &RecvUartCommand, &Uart); /********************** Interrupt Controller Setup *********************/ /* * Initialize the interrupt controller driver so that it's ready to use, * using the device ID that is generated in xparameters.h */ Status = XIntc_Initialize(&InterruptController, XPAR_AXI_INTC_0_DEVICE_ID); if (Status != XST_SUCCESS) { //printf("Interrupt controller initialization error\n\r"); } /* * Connect the device driver handler that will be called when an interrupt * for the device occurs, the device driver handler performs the specific * interrupt processing for the device */ Status = XIntc_Connect(&InterruptController, XPAR_AXI_INTC_0_TOUCHSENSOR_0_INTERRUPT_INTR, (XInterruptHandler)TouchSensorButtons_InterruptHandler, &Manager); if (Status != XST_SUCCESS) { //printf("Interrupt controller connect error\n\r"); } Status = XIntc_Connect(&InterruptController, XPAR_AXI_INTC_0_RS232_UART_1_INTERRUPT_INTR, (XInterruptHandler)XUartLite_InterruptHandler, &Uart); if (Status != XST_SUCCESS) { printf("Interrupt controller connect to Uart error\n\r"); } Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Status != XST_SUCCESS) { //printf("Interrupt controller start error\n\r"); } XIntc_Enable(&InterruptController, XPAR_AXI_INTC_0_TOUCHSENSOR_0_INTERRUPT_INTR); XIntc_Enable(&InterruptController, XPAR_AXI_INTC_0_RS232_UART_1_INTERRUPT_INTR); XUartLite_ResetFifos(&Uart); XUartLite_EnableInterrupt(&Uart); AI_PLAYER ai = default_ai(); PLAYER Player1, Player2; Player1.num = P1; Player2.num = P2; Gameboard_Initialize(&Gameboard,human,fpga); microblaze_enable_interrupts(); while (1) { PLAYER Curr_P, Opp_P; //Workaround to enable multiple resets on turn 0. if (Gameboard.MoveBufferSize == -1) Gameboard.MoveBufferSize++; int CurrentMove = Gameboard.MoveBufferSize; player_mode_t CurrentPlayerMode = (CurrentMove % 2) ? Gameboard.WhiteMode : Gameboard.BlackMode; Curr_P = (CurrentMove % 2) ? Player1 : Player2; Opp_P = (CurrentMove % 2) ? Player2 : Player1; switch (CurrentPlayerMode){ case human: TouchSensorButtons_EnableButton(&GameboardGridButton); break; case fpga: TouchSensorButtons_DisableButton(&GameboardGridButton); HandleAiMove(ai, Gameboard.master_board, Curr_P, Opp_P); break; case uart: TouchSensorButtons_DisableButton(&GameboardGridButton); if(Gameboard.MoveBufferSize > 0){ SendUartCommand(&Uart, Gameboard.MoveBuffer[Gameboard.MoveBufferSize-1].X, Gameboard.MoveBuffer[Gameboard.MoveBufferSize-1].Y); } break; default: TouchSensorButtons_EnableButton(&GameboardGridButton); break; } /* if (check_board_full(Gameboard.master_board)) { //printf("Gameboard full\n\r"); break; } */ if (check_board_win(Gameboard.master_board, Curr_P)) { xil_printf("Player %s won\n\r", (Curr_P.num == P1) ? "white" : "black"); //Spin waiting on reset while(Gameboard.MoveBufferSize != -1); } while(CurrentMove == Gameboard.MoveBufferSize); } return 0; }
int main(){ w3_node_init(); // Write some code here that gives a user instructions for controlling your transceiver. // --- Enable/disable transmitter // --- Enable/disable receiver // --- Enable/disable/reset CFO Correction // --- Enable/disable/reset timing correction // --- Select output of DAC (to view signals at various stages in your design) // --- Modify all filter coefficients (both for CFO and timing synchronization) for tuning //Set up the UART XUartLite_Initialize(&UartLite, XPAR_UARTLITE_0_DEVICE_ID); //Set up the Radio - For details about these calls, see http://warp.rice.edu/svn/WARP/PlatformSupport/CustomPeripherals/pcores/radio_controller_v3_00_b/doc/html/api/index.html // Configure TX enable, RX enable, and Rx HP filter for software control radio_controller_setCtrlSource(RC_BASEADDR, RC_RFA, (RC_REG0_TXEN_CTRLSRC|RC_REG0_RXEN_CTRLSRC|RC_REG0_RXHP_CTRLSRC), RC_CTRLSRC_REG); // Configure TX low-pass filter response to have a corner frequency of 18 MHz: radio_controller_setRadioParam(RC_BASEADDR, RC_RFA, RC_PARAMID_TXLPF_BW, 0x01); //Enable software Tx Gain control: radio_controller_setRadioParam(RC_BASEADDR, RC_RFA,RC_PARAMID_TXGAINS_SPI_CTRL_EN, 0x01); //Enable software Rx Gain control: radio_controller_setRadioParam(RC_BASEADDR, RC_RFA,RC_PARAMID_RXGAINS_SPI_CTRL_EN, 0x01); //Initialize the baseband Tx gain to its max value (0 dB) radio_controller_setRadioParam(RC_BASEADDR, RC_RFA,RC_PARAMID_TXGAIN_BB, 0x00); //Initialize the RF Tx gain radio_controller_setRadioParam(RC_BASEADDR, RC_RFA, RC_PARAMID_TXGAIN_RF, TxGain); // Configure receive HPF cutoff of 30kHz (DC block) radio_controller_setRadioParam(RC_BASEADDR, RC_RFA, RC_PARAMID_RXHPF_HIGH_CUTOFF_EN, 0x01); //14MHz Low Pass Filter on RX (our max freq is 10MHz + 2.25MHz) // 0: 7.5MHz<br>1: 9.5MHz<br>2: 14MHz<br>3: 18MHz radio_controller_setRadioParam(RC_BASEADDR, RC_RFA, RC_PARAMID_RXLPF_BW, 0x03); //Initialize the Rx RF Gain (1:0dB, 2:15dB , 3:30dB ) radio_controller_setRadioParam(RC_BASEADDR, RC_RFA,RC_PARAMID_RXGAIN_RF, RxCoarseGain); //Initialize the Rx baseband Gain radio_controller_setRadioParam(RC_BASEADDR, RC_RFA, RC_PARAMID_RXGAIN_BB, RxFineGain); // Enable the receiver by default // Set center frequency (i.e. choose the WiFi channel) radio_controller_setCenterFrequency(RC_BASEADDR , RC_RFA, RC_24GHZ, wifiChannel); //DECLERATION OF VARIABLES int x = 0; //Variable used for reading UART Xuint32 dataIn; //Variable used to temporarily store data read from memory using the XIO_In32() function Xuint32 dataOut; //Variable used to temporarily store data to write to memory using the XIO_Out32() function XIo_Out32(Delay,43); //Write the desired value for the PA delay radio_controller_RxEnable(RC_BASEADDR, RC_RFB); //Turn on Receiver RFB radio_controller_TxEnable(RC_BASEADDR, RC_RFA); //Turn on Transmitter RFA dataIn = XIo_In32(Delay); //Read in first delay for sanity check xil_printf("first delay: %d \n \r", dataIn); //Print to terminal for user to look at XIo_Out32(Controls,0x80000000); //Turn On LTE signal while(1){ x = XUartLite_RecvByte(STDIN_BASEADDRESS); //Input from UART ////TURN TRAINING ON//// if(x=='t'){ XIo_Out32(Controls,0x04000000); //Turn Off Signal, DPD, learning, and reset XIo_Out32(Controls,0xF0000000); //Turn On LTE, DPD, and Training xil_printf("Training Activated \n \r"); } ////COMMANDS TO LOOK AT AND CHANGE DELAY//// if(x=='d'){ //Read current delay dataIn = XIo_In32(Delay); xil_printf("Current Delay: %d \n \r", dataIn); } if(x=='e'){ //Increase delay radio_controller_TxRxDisable(RC_BASEADDR, RC_RFA|RC_RFB); //Turn off TX and RX RFB XIo_Out32(Controls,0x04000000); //Turn Off LTE, DPD, Training, and Reset dataIn = XIo_In32(Delay); //Read current delay dataOut = dataIn + 1; //step by 1 XIo_Out32(Delay,dataOut); //Write to delay dataIn = XIo_In32(Delay); //Read current delay xil_printf("New Delay: %d \n \r", dataIn); radio_controller_RxEnable(RC_BASEADDR, RC_RFB); //Turn on Receiver RFB radio_controller_TxEnable(RC_BASEADDR, RC_RFA); //Turn on Transmitter RFA XIo_Out32(Controls,0xF0000000); //Turn On LTE, DPD, and Training } if(x=='c'){ //Decrease delay radio_controller_TxRxDisable(RC_BASEADDR, RC_RFA|RC_RFB); //Turn off TX and RX RFB XIo_Out32(Controls,0x04000000); //Turn Off LTE, DPD, Training, and Reset dataIn = XIo_In32(Delay); //Read current delay dataOut = dataIn - 1; //step by 1 XIo_Out32(Delay,dataOut); //Write to delay dataIn = XIo_In32(Delay); //Read current delay xil_printf("New Delay: %d \n \r", dataIn); radio_controller_RxEnable(RC_BASEADDR, RC_RFB); //Turn on Receiver RFB radio_controller_TxEnable(RC_BASEADDR, RC_RFA); //Turn on Transmitter RFA XIo_Out32(Controls,0xF0000000); //Turn On LTE, DPD, and Training } ////REPORT ALL ALPHAS FROM TRAINING//// if(x=='l'){ int i = 0; for(i = 0;i<Alpha_depth;i=i+4 ){ dataIn = XIo_In32(Alpha_memory+i); //Read alpha xil_printf("%08x, address: %08x \n \r", dataIn, Alpha_memory+i); } } ////COMMANDS FOR CHANGING ALPHA MANUALLY/// if(x=='a'){ //Switch to Manual Alpha XIo_Out32(Controls,0x04000000); //Turn Off Signal, DPD, learning, and reset XIo_Out32(Controls,0xC8000000); //Turn On LTE, DPD, and manual alpha dataIn = XIo_In32(Alpha_user); //Read current user defined alpha xil_printf("Current Alpha: %08x \n \r", dataIn); } if(x=='q'){ //Increase Manual Alpha Real dataIn = XIo_In32(Alpha_user); //Read current user defined alpha dataOut = dataIn + 0x01000000; //step by 2^-6 = 0.015625 XIo_Out32(Alpha_user,dataOut); //Write to user defined alpha dataIn = XIo_In32(Alpha_user); //Read current user defined alpha xil_printf("New Alpha: %08x \n \r", dataIn); } if(x=='z'){ //Decrease Manual Alpha Real dataIn = XIo_In32(Alpha_user); //Read current user defined alpha dataOut = dataIn - 0x01000000; //step by -2^-6 = -0.015625 XIo_Out32(Alpha_user,dataOut); //Write to user defined alpha dataIn = XIo_In32(Alpha_user); //Read current user defined alpha xil_printf("New Alpha: %08x \n \r", dataIn); } if(x=='w'){ //Increase Manual Alpha Imag dataIn = XIo_In32(Alpha_user); //Read current user defined alpha dataOut = dataIn + 0x00000100; //step by 2^-6 = 0.015625 XIo_Out32(Alpha_user,dataOut); //Write to user defined alpha dataIn = XIo_In32(Alpha_user); //Read current user defined alpha xil_printf("New Alpha: %08x \n \r", dataIn); } if(x=='x'){ //Decrease Manual Alpha Imag dataIn = XIo_In32(Alpha_user); //Read current user defined alpha dataOut = dataIn - 0x00000100; //step by -2^-6 = -0.015625 XIo_Out32(Alpha_user,dataOut); //Write to user defined alpha dataIn = XIo_In32(Alpha_user); //Read current user defined alpha xil_printf("New Alpha: %08x \n \r", dataIn); } } }