示例#1
0
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;
}
void RecvHandler(void *CallBackRef, unsigned int EventData){
	u32 numBytesRx;

	XUartLite_DisableInterrupt(&UartLite);
	uart_callback(ReceiveBuffer[0]);
	XUartLite_EnableInterrupt(&UartLite);
	numBytesRx = XUartLite_Recv(&UartLite, ReceiveBuffer, UART_BUFFER_SIZE);
	//xil_printf("numBytesRx = %d\n", numBytesRx);
}
示例#3
0
文件: UART.c 项目: nicktamias/arty_d2
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;

}
示例#4
0
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;
}
示例#6
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);
    }
  }

}
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;
}
示例#8
0
/**
* 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;
}
示例#9
0
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;
}