Ejemplo n.º 1
0
void Initialize()
{
    XGpio_Initialize(&Dips, XPAR_DIP_DEVICE_ID);
    XGpio_SetDataDirection(&Dips, 1, 0xff);

    XGpio_Initialize(&Btns, XPAR_BUTTON_DEVICE_ID);
    XGpio_SetDataDirection(&Btns, 1, 0xff);

    XIntc_Initialize(&intCtrl, XPAR_AXI_INTC_0_DEVICE_ID);

    XGpio_InterruptEnable(&Btns, 1);
    XGpio_InterruptGlobalEnable(&Btns);

    XGpio_InterruptEnable(&Dips, 1);
    XGpio_InterruptGlobalEnable(&Dips);

    XIntc_Enable(&intCtrl, XPAR_AXI_INTC_0_BUTTON_IP2INTC_IRPT_INTR);
    XIntc_Enable(&intCtrl, XPAR_AXI_INTC_0_DIP_IP2INTC_IRPT_INTR);

    XIntc_Connect(&intCtrl, XPAR_AXI_INTC_0_BUTTON_IP2INTC_IRPT_INTR,
        (XInterruptHandler)PushBtnHandler, (void *)0);
    XIntc_Connect(&intCtrl, XPAR_AXI_INTC_0_DIP_IP2INTC_IRPT_INTR,
        (XInterruptHandler)SwitchHandler,(void *)0);

    microblaze_enable_interrupts();

    microblaze_register_handler((XInterruptHandler)XIntc_InterruptHandler, (void *)&intCtrl);
    XIntc_Start(&intCtrl, XIN_REAL_MODE);
}
Ejemplo n.º 2
0
int IntcInitFunction(u16 DeviceId, XGpio *GpioInstancePtr)
{
	XScuGic_Config *IntcConfig;
	int status;

	// Interrupt controller initialisation
	IntcConfig = XScuGic_LookupConfig(DeviceId);
	status = XScuGic_CfgInitialize(&INTCInst, IntcConfig, IntcConfig->CpuBaseAddress);
	if(status != XST_SUCCESS) return XST_FAILURE;

	// Call to interrupt setup
	status = InterruptSystemSetup(&INTCInst);
	if(status != XST_SUCCESS) return XST_FAILURE;

	// Connect GPIO interrupt to handler
	status = XScuGic_Connect(&INTCInst,
					  	  	 INTC_GPIO_INTERRUPT_ID,
					  	  	 (Xil_ExceptionHandler)RF_INTr_Handler,
					  	  	 (void *)GpioInstancePtr);
	if(status != XST_SUCCESS) return XST_FAILURE;

	// Enable GPIO interrupts interrupt
	XGpio_InterruptEnable(GpioInstancePtr, 1);
	XGpio_InterruptGlobalEnable(GpioInstancePtr);

	// Enable GPIO and timer interrupts in the controller
	XScuGic_Enable(&INTCInst, INTC_GPIO_INTERRUPT_ID);

	return XST_SUCCESS;
}
Ejemplo n.º 3
0
void init_GPIO_BUTTONS(XGpio *InstancePtr, u16 Device_ID)
{
    int Status;
    XGpio_Config *Config;

    Config = XGpio_LookupConfig(Device_ID);

    Status = XGpio_CfgInitialize(InstancePtr, Config, Config->BaseAddress);

    // Initialise GPIO devices
    Status = XGpio_Initialize(InstancePtr, Device_ID);



    // Set GPIO direction  (output for LEDs and input for BTNS)


    XGpio_SetDataDirection(InstancePtr, 1, 0xFF);
    if(Status != XST_FAILURE) {
        xil_printf("BUTTONS initialized!\n \r");
    }

    XGpio_InterruptEnable(&ButtonsInstancePtr, 1);
    XGpio_InterruptGlobalEnable(&ButtonsInstancePtr);

    // Initialize interrupt controller
    //IntcInitFunction(INTCONTROLLER_DEVICE_ID, InstancePtr);


}
int main() {
    init_platform();

    // Initialize the GPIO peripherals.
	XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);
	// Set the push button peripheral to be inputs.
	XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);
	// Enable the global GPIO interrupt for push buttons.
	XGpio_InterruptGlobalEnable(&gpPB);
	// Enable all interrupts in the push button peripheral.
	XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF);

    interrupts_init();

    print("made it past interrupts_init\n\r");

    // apparently we don't need to init it, just HardReset
    XAC97_HardReset(XPAR_AXI_AC97_0_BASEADDR);
    XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_ExtendedAudioStat, 1);
    XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCM_DAC_Rate, AC97_PCM_RATE_11025_HZ);
    XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT);
    XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_MasterVol, AC97_VOL_MAX);
    XAC97_WriteReg(XPAR_AXI_AC97_0_BASEADDR, AC97_PCMOutVol, AC97_VOL_MAX);


    while (1);

    cleanup_platform();

    return 0;
}
Ejemplo n.º 5
0
void PushBtnHandler(void * CallBackRef)
{
    state1 = XGpio_DiscreteRead(&Btns, 1);
    pshBtn = 1;
    XGpio_InterruptDisable(&Btns, 1);
    Delay_50ms();
    XGpio_InterruptClear(&Btns, 1);
    XGpio_InterruptEnable(&Btns, 1);
}
Ejemplo n.º 6
0
int IntcInitFunction(u16 DeviceId, XTmrCtr *TmrInstancePtr, XGpio *GpioInstancePtr, XDmaPs *DmaPtr)
{
	XScuGic_Config *IntcConfig;
	int status;

	// Interrupt controller initialization
	IntcConfig = XScuGic_LookupConfig(DeviceId);
	status = XScuGic_CfgInitialize(&INTCInst, IntcConfig, IntcConfig->CpuBaseAddress);
	if(status != XST_SUCCESS) return XST_FAILURE;

	// Call to interrupt setup
	status = InterruptSystemSetup(&INTCInst);
	if(status != XST_SUCCESS) return XST_FAILURE;

	// Connect GPIO interrupt to handler
	status = XScuGic_Connect(&INTCInst,
					  	  	 INTC_GPIO_INTERRUPT_ID,
					  	  	 (Xil_ExceptionHandler)BTN_Intr_Handler,
					  	  	 (void *)GpioInstancePtr);
	if(status != XST_SUCCESS) return XST_FAILURE;


	// Connect timer interrupt to handler
	status = XScuGic_Connect(&INTCInst,
							 INTC_TMR_INTERRUPT_ID,
							 (Xil_ExceptionHandler)TMR_Intr_Handler,
							 (void *)TmrInstancePtr);
	if(status != XST_SUCCESS) return XST_FAILURE;


	// Enable GPIO interrupts interrupt
	XGpio_InterruptEnable(GpioInstancePtr, 1);
	XGpio_InterruptGlobalEnable(GpioInstancePtr);

	// Enable GPIO interrupts in the controller
	XScuGic_Enable(&INTCInst, INTC_GPIO_INTERRUPT_ID);


	// Enable  timer interrupts in the controller
	XScuGic_Enable(&INTCInst, INTC_TMR_INTERRUPT_ID);

	//Lab7 addition starts here
	// Connect DMA interrupt to handler
	XScuGic_Connect(&INTCInst,DMA_FAULT_INTR,(Xil_InterruptHandler)XDmaPs_FaultISR,(void *)DmaPtr);


	XScuGic_Connect(&INTCInst,DMA_DONE_INTR_0,(Xil_InterruptHandler)XDmaPs_DoneISR_0,(void *)DmaPtr);
	// Enable DMA interrupts in the controller
	XScuGic_Enable(&INTCInst, DMA_DONE_INTR_0);

	//Lab7 addition ends here

	return XST_SUCCESS;
}
Ejemplo n.º 7
0
int btn_method(){

  XStatus Status= XST_SUCCESS;

  if(btn_initialize()!=XST_SUCCESS)
	  return XST_FAILURE;

  Status = XIntc_Initialize(&intCtrl_Btn, INTC_DEVICE_ID);
	if ( Status != XST_SUCCESS )
	{
		if( Status == XST_DEVICE_NOT_FOUND )
		{
			xil_printf("Interrupt Controller: XST_DEVICE_NOT_FOUND...\r\n");
		}
		else
		{
			xil_printf("Interrupt Controller: A different error from XST_DEVICE_NOT_FOUND...\r\n");
		}
		xil_printf("Interrupt controller: driver failed to be initialized...\r\n");
		return XST_FAILURE;
	}
	xil_printf("Interrupt controller: driver initialized!\r\n");

  Status =  XIntc_Connect(&intCtrl_Btn, BTN_IR_ID, btn_handler, &Btn);
	if ( Status != XST_SUCCESS )
	{
		xil_printf("Failed to connect the application handlers to the interrupt controller...\r\n");
		return XST_FAILURE;
	}
	xil_printf("Connected to Interrupt Controller!\r\n");

  XIntc_Enable(&intCtrl_Btn, BTN_IR_ID);

  microblaze_register_handler((XInterruptHandler)XIntc_DeviceInterruptHandler,INTC_DEVICE_ID);//Because it is 0?

  microblaze_enable_interrupts();

  XGpio_InterruptEnable(&Btn,BTN_IR_MASK);

  XGpio_InterruptGlobalEnable(&Btn);


  Status = XIntc_Start(&intCtrl_Btn, XIN_REAL_MODE);
  if (Status != XST_SUCCESS) {
		xil_printf("Failed to start the interrupt controller...\r\n");
		return XST_FAILURE;
  }
  print("Interrupt controller Started!\n\r ");

 return XST_SUCCESS;
}
Ejemplo n.º 8
0
void Switch_INTr_Handler(void *InstancePtr)
{// Disable GPIO interrupts
	XGpio_InterruptDisable(&SwitchInst, SWITCH_INT);
	// Ignore additional button presses
	if ((XGpio_InterruptGetStatus(&SwitchInst) & SWITCH_INT) != SWITCH_INT) {
			return;
		}

	//DO SOMETHING HERE FOR THE INTERRUPT

    (void)XGpio_InterruptClear(&SwitchInst, SWITCH_INT);
    // Enable GPIO interrupts
    XGpio_InterruptEnable(&SwitchInst, SWITCH_INT);
}
Ejemplo n.º 9
0
void BTNS_Intr_Handler()
{
    //Xil_ExceptionDisable();
    XGpio_InterruptDisable(&ButtonsInstancePtr, GPIO_BTNS_ID);

    int btn_value = XGpio_DiscreteRead(&ButtonsInstancePtr, 1);
    if( btn_value == 0x1) {
        XGpio_DiscreteWrite(&LedsInstancePtr, 1, 0x5);
        xil_printf("Button pressed");
    }

    //Xil_ExceptionEnable();
    XGpio_InterruptEnable(&ButtonsInstancePtr, GPIO_BTNS_ID);
}
Ejemplo n.º 10
0
static void gpioInterruptHandler(void *CallBackRef)
{
	XGpio_InterruptDisable(&gpioInstance, XGPIO_IR_CH1_MASK);
	XGpio *gpio = (XGpio *) CallBackRef;
	int status = XGpio_InterruptGetStatus(gpio);
	if( status & XGPIO_IR_CH1_MASK )
	{
		XGpio_InterruptClear(&gpioInstance, XGPIO_IR_CH1_MASK);
		int gpioReg = XGpio_DiscreteRead(&gpioInstance, 1);
		if((gpioReg & RF_INTERRUPT_MASK) == 1)
			dataRec = true;
	}
	XGpio_InterruptEnable(&gpioInstance, XGPIO_IR_CH1_MASK);
}
Ejemplo n.º 11
0
//***************************************************************
//******************* INTERRUPT FUNCTIONS ***********************
//***************************************************************
void Interrupt_Init(void)
{
	//PUSH BUTTON INTERRUPT
	/* Code */
	XIntc_Initialize(&Intc, INTC_DEVICE_ID);
	XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
	XIntc_Connect(&Intc, INTR_ID, GpioIsr, &Gpio);
	
	/* Buttons are all inputs */
	XGpio_SetDataDirection(&Gpio, BUTTON_CHANNEL, GPIO_ALL_BUTTONS);
	
	XGpio_InterruptEnable(&Gpio, BUTTON_INTERRUPT);
	XGpio_InterruptGlobalEnable(&Gpio);
	
	/* Enable the Interrupt vector at the interrupt controller */
	XIntc_Enable(&Intc, INTR_ID);
	
	XExc_Init();
	
	/*****************************************************************
	* Initialize the PPC405 exception table and register the interrupt
	* controller handler with the exception table
	******************************************************************/
	XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT, (XExceptionHandler)XIntc_InterruptHandler, &Intc);
	/* Now Register Timer Interrupt */
	XExc_RegisterHandler(XEXC_ID_PIT_INT, (XExceptionHandler)TimerIsr, (void *)0);
	
		
	/* Enable non-critical exceptions in the PowerPC */
	XExc_mEnableExceptions(XEXC_NON_CRITICAL);
	
	/*******************************************************************
	* Start the interrput controller such that interrupts are recognized
	* and handled by the processor.
	********************************************************************/
	XIntc_Start(&Intc, XIN_REAL_MODE);
	
	//TIMER INTERRUPT
	/* Set Timer Interval (1 Sec) */
	XTime_PITSetInterval(0x0F000000);
	/* Automatically Restarts Timer */
	XTime_PITEnableAutoReload();
	/* Clear Timer Reg */
	XTime_TSRClearStatusBits(XREG_TSR_CLEAR_ALL);
	/* Clear Queued Timer Interrupts */
	XTime_PITClearInterrupt();
	/* Enable Interrupt */
	XTime_PITEnableInterrupt();	
}
Ejemplo n.º 12
0
int InterruptSystemSetup(XScuGic *XScuGicInstancePtr)
{
	// Enable interrupt
	XGpio_InterruptEnable(&SwitchInst, SWITCH_INT);
	XGpio_InterruptGlobalEnable(&SwitchInst);

	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
			 	 	 	 	 	 (Xil_ExceptionHandler)XScuGic_InterruptHandler,
			 	 	 	 	 	 XScuGicInstancePtr);
	Xil_ExceptionEnable();


	return XST_SUCCESS;

}
Ejemplo n.º 13
0
static void prvSetupHardware( void )
{
portBASE_TYPE xStatus;
const unsigned char ucSetToOutput = 0U;

	/* Initialize the GPIO for the LEDs. */
	xStatus = XGpio_Initialize( &xOutputGPIOInstance, XPAR_LEDS_4BITS_DEVICE_ID );
	if( xStatus == XST_SUCCESS )
	{
		/* All bits on this channel are going to be outputs (LEDs). */
		XGpio_SetDataDirection( &xOutputGPIOInstance, ulGPIOOutputChannel, ucSetToOutput );

		/* Start with all LEDs off. */
		ucGPIOState = 0U;
		XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ucGPIOState );
	}

	/* Initialise the GPIO for the button inputs. */
	if( xStatus == XST_SUCCESS )
	{
		xStatus = XGpio_Initialize( &xInputGPIOInstance, XPAR_PUSH_BUTTONS_4BITS_DEVICE_ID );
	}

	if( xStatus == XST_SUCCESS )
	{
		/* Install the handler defined in this task for the button input.
		*NOTE* The FreeRTOS defined xPortInstallInterruptHandler() API function
		must be used for this purpose. */
		xStatus = xPortInstallInterruptHandler( XPAR_MICROBLAZE_0_INTC_PUSH_BUTTONS_4BITS_IP2INTC_IRPT_INTR, prvButtonInputInterruptHandler, NULL );

		if( xStatus == pdPASS )
		{
			/* Set buttons to input. */
			XGpio_SetDataDirection( &xInputGPIOInstance, ulGPIOInputChannel, ~( ucSetToOutput ) );

			/* Enable the button input interrupts in the interrupt controller.
			*NOTE* The vPortEnableInterrupt() API function must be used for this
			purpose. */
			vPortEnableInterrupt( XPAR_MICROBLAZE_0_INTC_PUSH_BUTTONS_4BITS_IP2INTC_IRPT_INTR );

			/* Enable GPIO channel interrupts. */
			XGpio_InterruptEnable( &xInputGPIOInstance, ulGPIOInputChannel );
			XGpio_InterruptGlobalEnable( &xInputGPIOInstance );
		}
	}

	configASSERT( ( xStatus == pdPASS ) );
}
void GpioIsr(void *InstancePtr){
	XGpio *GpioPtr = (XGpio *)InstancePtr;
	u32 gpio_read;

	XGpio_InterruptDisable(GpioPtr, GPIO_INPUT_INTERRUPT);
	gpio_read = XGpio_DiscreteRead(GpioPtr, GPIO_INPUT_CHANNEL);

	if(gpio_read & GPIO_MASK_PB_U) pb_u_callback();
	if(gpio_read & GPIO_MASK_PB_M) pb_m_callback();
	if(gpio_read & GPIO_MASK_PB_D) pb_d_callback();

	(void)XGpio_InterruptClear(GpioPtr, GPIO_INPUT_INTERRUPT);
	XGpio_InterruptEnable(GpioPtr, GPIO_INPUT_INTERRUPT);

	return;
}
Ejemplo n.º 15
0
int interruptManager (unsigned int * framePointer0) {
	init_platform();
	// Initialize the GPIO peripherals.
	int success;

	// Used for CPU utilization. Uncomment if desired
	// XTmrCtr_Initialize(instPtr, 0);

	success = XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);
	// Set the push button peripheral to be inputs.
	XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);
	// Enable the global GPIO interrupt for push buttons.
	XGpio_InterruptGlobalEnable(&gpPB);
	// Enable all interrupts in the push button peripheral.
	XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF);

	// Reset the XAC97 Chip
	XAC97_HardReset(XPAR_AXI_AC97_0_BASEADDR);
	XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT);
	XAC97_mSetControl(AC97_ExtendedAudioStat, AC97_EXTENDED_AUDIO_CONTROL_VRA);
	setVolLevel(AC97_VOL_MAX);
	clearAllSounds();

	microblaze_register_handler(interrupt_handler_dispatcher, NULL);
	XIntc_EnableIntr(XPAR_INTC_0_BASEADDR,
			(XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK | XPAR_AXI_AC97_0_INTERRUPT_MASK));
	XIntc_MasterEnable(XPAR_INTC_0_BASEADDR);
	microblaze_enable_interrupts();

	// Uncomment for CPU utilization stats
	/*XTmrCtr Timer;
	XTmrCtr *instPtr = &Timer;
	XTmrCtr_Initialize(instPtr, 0);
	XTmrCtr_Start(instPtr, 0);*/
	while(!isEndOfGame()); // Program never ends.

	// Uncomment for CPU utilization stats
	/*XTmrCtr_Stop(instPtr, 0);
	int val = (int) XTmrCtr_GetValue(instPtr, 0);
	xil_printf("%d\n\r", val);*/
	clearAllSounds();
	XAC97_ClearFifos(XPAR_AXI_AC97_0_BASEADDR);
	drawGameOver();
	cleanup_platform();

	return 0;
}
Ejemplo n.º 16
0
int main (void) {
    init_platform();
    // Initialize the GPIO peripherals.
    XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);
    // Set the push button peripheral to be inputs.
    XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);
    // Enable the global GPIO interrupt for push buttons.
    XGpio_InterruptGlobalEnable(&gpPB);
    // Enable all interrupts in the push button peripheral.
    XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF);

    pit_init();
    pit_load_value(1000000); // init to 10 ms
    pit_enable_load();
    pit_enable_interrupts();
    pit_enable_count();


    microblaze_register_handler(interrupt_handler_dispatcher, NULL);
    XIntc_EnableIntr(XPAR_INTC_0_BASEADDR,
    		(XPAR_PIT_0_MYINTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK));
    XIntc_MasterEnable(XPAR_INTC_0_BASEADDR);

    microblaze_enable_interrupts();

    // Tell stdin that it gets zero! none! (as far as buffering goes)
    setvbuf(stdin, NULL, _IONBF, 0);

    while(1){
		// blocking call: wait until a character is present
		char input = getchar();

		// Handle the UART control of game
		uartControl_handle(input);
    }

    cleanup_platform();

    return 0;
}
Ejemplo n.º 17
0
static int SetupSdGpio(XGpio *sGpio) {
    int Status;

    // Initialize the GPIO driver. If an error occurs then exit.
    Status = XGpio_Initialize(sGpio, SD_GPIO_DEVICE_ID);
    if (Status != XST_SUCCESS) {
        xil_printf("Failed to initialize SD GPIO driver: %d\n\r", Status);
        return XST_FAILURE;
    }

    // Set the direction for all signals to be inputs.
    XGpio_SetDataDirection(sGpio, SD_GPIO_CHANNEL, SD_GPIO_CARD_PRESENT_MASK);
    XGpio_SetDataDirection(sGpio, 1, ~0);

    XGpio_InterruptEnable(sGpio, XGPIO_IR_CH1_MASK);
    XGpio_InterruptGlobalEnable(sGpio);

    XGpio_SelfTest(sGpio);

    // TODO: add Interrupt configuration code.

    return XST_SUCCESS;
}
int main (void) {
    init_platform();
    // Initialize the GPIO peripherals.
    int success = XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID);

    // Set the push button peripheral to be inputs.
    XGpio_SetDataDirection(&gpPB, 1, 0x0000001F);
    // Enable the global GPIO interrupt for push buttons.
    XGpio_InterruptGlobalEnable(&gpPB);
    // Enable all interrupts in the push button peripheral.
    XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF);

    microblaze_register_handler(interrupt_handler_dispatcher, NULL);
    custom_XIntc_EnableIntr(XPAR_INTC_0_BASEADDR,
                            (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK));
    custom_XIntc_MasterEnable(XPAR_INTC_0_BASEADDR);
    microblaze_enable_interrupts();

    while(1);  // Program never ends.

    cleanup_platform();

    return 0;
}
Ejemplo n.º 19
0
/**
* This function is the Interrupt Service Routine for the GPIO device.  It
* will be called by the processor whenever an interrupt is asserted by the
* device.
*
* This function will detect the push button on the board has changed state
* and then turn on or off the LED.
*
* @param	InstancePtr is the GPIO instance pointer to operate on.
*		It is a void pointer to meet the interface of an interrupt
*		processing function.
*
* @return	None.
*
* @note		None.
*
*****************************************************************************/
void GpioIsr(void *InstancePtr)
{
	XGpio *GpioPtr = (XGpio *)InstancePtr;
	u32 Led;
	u32 LedState;
	u32 Buttons;
	u32 ButtonFound;
	u32 ButtonsChanged = 0;
	static u32 PreviousButtons;

	/*
	 * Disable the interrupt
	 */
	XGpio_InterruptDisable(GpioPtr, BUTTON_INTERRUPT);

	/* Keep track of the number of interrupts that occur */

	InterruptCount++;

	/*
	 * There should not be any other interrupts occuring other than the
	 * the button changes
	 */
	if ((XGpio_InterruptGetStatus(GpioPtr) & BUTTON_INTERRUPT) !=
		BUTTON_INTERRUPT) {
		return;
	}


	/*
	 * Read state of push buttons and determine which ones changed
	 * states from the previous interrupt. Save a copy of the buttons
	 * for the next interrupt
	 */
	Buttons = XGpio_DiscreteRead(GpioPtr, BUTTON_CHANNEL);
	ButtonsChanged = Buttons ^ PreviousButtons;
	PreviousButtons = Buttons;

	/*
	 * Handle all button state changes that occurred since the last
	 * interrupt
	 */
	while (ButtonsChanged != 0) {
		/*
		 * Determine which button changed state and then get
		 * the current state of the associated LED
		 */
		 Led = MapButton2Led(ButtonsChanged, &ButtonFound);
		 LedState = XGpio_DiscreteRead(GpioPtr, LED_CHANNEL) & Led;

		 /*
		  * Clear the button that is being processed so that it is
		  * done and others can be handled also
		  */
		 ButtonsChanged &= ~ButtonFound;

		 /* Toggle the state of the LED */
		 if (LedState) {
			 XGpio_DiscreteClear(GpioPtr, LED_CHANNEL, Led);
		 } else {
			 XGpio_DiscreteSet(GpioPtr, LED_CHANNEL, Led);
		 }
	 }

	 /* Clear the interrupt such that it is no longer pending in the GPIO */

	 (void)XGpio_InterruptClear(GpioPtr, BUTTON_INTERRUPT);

	 /*
	  * Enable the interrupt
	  */
	 XGpio_InterruptEnable(GpioPtr, BUTTON_INTERRUPT);

}
Ejemplo n.º 20
0
XStatus GpioSetupIntrSystem(XIntc* IntcInstancePtr,
                            XGpio* InstancePtr,
                            Xuint16 DeviceId,
                            Xuint16 IntrId,
                            Xuint16 IntrMask)

{
    XStatus Result;

    GlobalIntrMask = IntrMask;
    
#ifndef TESTAPP_GEN
    /*
     * 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, INTC_DEVICE_ID);
    if (Result != XST_SUCCESS)
    {
        return Result;
    }
#endif
    
    /* Hook up simple interrupt service routine for TestApp*/

    Result = XIntc_Connect(IntcInstancePtr, IntrId,
                  (XInterruptHandler)GpioDriverHandler,
                  InstancePtr);
    
    /*
     * Enable the GPIO channel interrupts so that push button can be detected
     * and enable interrupts for the GPIO device
     */

    XGpio_InterruptEnable(InstancePtr, IntrMask);
    XGpio_InterruptGlobalEnable(InstancePtr);

    /* Enable the interrupt vector at the interrupt controller */
    XIntc_Enable(IntcInstancePtr, IntrId);

#ifndef TESTAPP_GEN
    /*
     * Initialize the PPC405 exception table and register the interrupt
     * controller handler with the exception table
     */
    XExc_Init();
    XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT,
                         (XExceptionHandler)XIntc_InterruptHandler,IntcInstancePtr);

    /* Enable non-critical exceptions in the PowerPC */
    XExc_mEnableExceptions(XEXC_NON_CRITICAL);

    /*
     * Start the interrupt controller such that interrupts are recognized
     * and handled by the processor.
     */
    Result = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE);
#endif
    
    if (Result != XST_SUCCESS)
    {
        return Result;
    }

    return XST_SUCCESS;
}
Ejemplo n.º 21
0
void GpioHandler(void *InstancePtr)
{
	/*
	Game System Interface (16 bits)
	#define GAME_TRUCK_IS_BASE_M		0x0001
	#define GAME_HAVE_FLAG_M			0x0002
	#define GAME_TRUCK_ALIVE_M			0x0004
	#define GAME_TRUCK_REGISTERED_M		0x0008
	#define GAME_TEAM_NUM_1_M			0x0010
	#define GAME_TEAM_NUM_0_M			0x0020
	#define GAME_STATE_1_M				0x0040		//stop, go, pause, win
	#define GAME_STATE_0_M				0x0080
	#define GAME_KILL_SHOT				0x0100
	#define GAME_PASS_SHOT				0x0200
	#define GAME_REVIVE_SHOT			0x0400
	#define GAME_HIT_ACK				0x0800
	#define GAME_MISS_ACK				0x1000
	#define HELIOS_ENABLE_GYRO			0x2000
	#define GAME_NOT_IN_PLAY			0x4000
	#define GAME_WAIT_TO_SHOOT			0x8000
	 */

	XGpio *GpioPtr = (XGpio *)InstancePtr;
	u32 gameSystem;
	//u32 gameSystemChanged = 0;
	static u32 gameSystemPrevious = 0;

	/*
	 * Disable the interrupt
	 */
	XGpio_InterruptDisable(GpioPtr, XGPIO_IR_CH2_MASK);

	/*
	 * There should not be any other interrupts occuring other than the
	 * the button changes
	 */
	if ((XGpio_InterruptGetStatus(GpioPtr) & XGPIO_IR_CH2_MASK) !=
			XGPIO_IR_CH2_MASK) {
		return;
	}

	/*
	 * Read state of push buttons and determine which ones changed
	 * states from the previous interrupt. Save a copy of the buttons
	 * for the next interrupt
	 */
	gameSystem = XGpio_DiscreteRead(GpioPtr, GAME_SYSTEM_GPIO_CHANNEL);
	//gameSystemChanged = gameSystem ^ gameSystemPrevious;


	if (((~gameSystemPrevious) & GAME_WAIT_TO_SHOOT) && (gameSystem & GAME_WAIT_TO_SHOOT)) {
		// Wait to shoot went from low to high
		XGpio_DiscreteClear(&Gpio, GAME_SYSTEM_GPIO_CHANNEL, CurrentShotType);
		CurrentShotType = 0;
	}

	/* Clear the interrupt such that it is no longer pending in the GPIO */

	(void)XGpio_InterruptClear(GpioPtr, XGPIO_IR_CH2_MASK);

	/*
	 * Enable the interrupt
	 */

	gameSystemPrevious = gameSystem;
	XGpio_InterruptEnable(GpioPtr, XGPIO_IR_CH2_MASK);
}
Ejemplo n.º 22
0
void enable_interrupt_gpio( cyg_uint32 mask )
{
    XGpio_InterruptEnable(&gpio_manager_device, mask);
}
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;
}
Ejemplo n.º 24
0
int main() {
	init_platform();

	static XGpio pshBtns;
	static XIntc intCtrl;

	Xuint32 Sample_L;
	Xuint32 Sample_R;

	pAudioData = (DDR2_BASEADDR + 0x02000000);
    pFFTData  = (pAudioData + lNumSamples);

	lBtnStateOld = 0x00000000;
	fsRunAction = 0;

	/*
	 *Initialize the driver structs for the Push button and interrupt cores.
	 *This allows the API functions to be used with these cores.
	 */
	XGpio_Initialize(&pshBtns, BTNS_DEVICE_ID);
	XIntc_Initialize(&intCtrl, INTC_DEVICE_ID);

	/*
	 * Connect the function PushBtnHandler to the interrupt controller so that
	 * it is called whenever the Push button GPIO core signals an interrupt.
	 */
	XIntc_Connect(&intCtrl, BTNS_IRPT_ID, PushBtnHandler, &pshBtns);

	/*
	 * Enable interrupts at the interrupt controller
	 */
	XIntc_Enable(&intCtrl, BTNS_IRPT_ID);

	/*
	 * Register the interrupt controller with the microblaze
	 * processor and then start the Interrupt controller so that it begins
	 * listening to the interrupt core for triggers.
	 */
	microblaze_register_handler(XIntc_DeviceInterruptHandler, INTC_DEVICE_ID);
	microblaze_enable_interrupts();
	XIntc_Start(&intCtrl, XIN_REAL_MODE);

	/*
	 * Enable the push button GPIO core to begin sending interrupts to the
	 * interrupt controller in response to changes in the button states
	 */
	XGpio_InterruptEnable(&pshBtns, lBtnChannel);
	XGpio_InterruptGlobalEnable(&pshBtns);

	/*
	 * Wait for AC97 to become ready
	 */
	while (!(AC97_Link_Is_Ready(AC97_BASEADDR)))
		;

	/*
	 * Set TAG to configure codec
	 */
	AC97_Set_Tag_And_Id(AC97_BASEADDR, 0xF800);

	/*
	 * Enable audio output and set volume
	 */
	AC97_Unmute(AC97_BASEADDR, AC97_MASTER_VOLUME_OFFSET);
	AC97_Unmute(AC97_BASEADDR, AC97_HEADPHONE_VOLUME_OFFSET);
	AC97_Unmute(AC97_BASEADDR, AC97_PCM_OUT_VOLUME_OFFSET);

	AC97_Set_Volume(AC97_BASEADDR, AC97_MASTER_VOLUME_OFFSET, BOTH_CHANNELS,
			VOLUME_MAX);
	AC97_Set_Volume(AC97_BASEADDR, AC97_HEADPHONE_VOLUME_OFFSET, BOTH_CHANNELS,
			VOLUME_MIN);
	AC97_Set_Volume(AC97_BASEADDR, AC97_PCM_OUT_VOLUME_OFFSET, BOTH_CHANNELS,
			VOLUME_MAX);

	while (1) {
		/**************************
		 * Play recorded sample
		 **************************/
		if (sampleMax != 0) {
			if (fsRunAction & bitPlay) {
				/*
				 * Set AC'97 codec TAG to send and receive data in the PCM slots
				 */
				AC97_Set_Tag_And_Id(AC97_BASEADDR, 0x9800);

				Count_Samples = 0;

				// Xil_Out32(LED_BASEADDR, bitPlayLED); //turn on LED
				int showLED = 0;
				while ((Count_Samples / 8) < lNumSamples) {
					/*
					 * Block execution until next frame is ready
					 */
					AC97_Wait_For_New_Frame(AC97_BASEADDR);

					/*
					 * Read audio data from memory
					 */
					Sample_L = XIo_In32 (pAudioData + Count_Samples);
					Count_Samples = Count_Samples + 4;
					Sample_R = XIo_In32 (pAudioData + Count_Samples);
					Count_Samples = Count_Samples + 4;

					/* our code */
					/* if(Count_Samples < 100) {  */
					//	printf("Left: %i",(int)Sample_L);
					//	printf("Right: %i",(int)Sample_R);
					/* } */
					if (showLED % 4000 == 0) {
						/*						middleLeft /= 8000;
						 middleRight /= 8000; */
						// Xil_Out32(LED_BASEADDR, Sample_L & AC97_META_MASK);
						// printf("Left: %d",(int)Sample_L);
						// printf("Right: %d",(int)Sample_R);
						setVolumeLEDs(Sample_L & AC97_DATA_MASK,
								Sample_R & AC97_DATA_MASK);
						/*						middleLeft = 0;
						 middleRight = 0;
						 } else {
						 middleLeft += Sample_L;
						 middleRight += Sample_R; */
					}

					/*
					 * Send audio data to codec
					 */XIo_Out32 ((AC97_BASEADDR + AC97_PCM_OUT_L_OFFSET), Sample_L);
					XIo_Out32 ((AC97_BASEADDR + AC97_PCM_OUT_R_OFFSET), Sample_R);
					showLED++;
				}

				Xil_Out32(LED_BASEADDR, 0); //Turn off LED
				fsRunAction = 0; //Forget any button presses that occurred
			}
		}
		/**************************
		 * Output a square wave
		 **************************/
		if (fsRunAction & bitGenWave) {
			//generate square on left, right and then both channels
			GenSquare(AC97_BASEADDR, LEFT_CHANNEL, 1000, 500);
			GenSquare(AC97_BASEADDR, RIGHT_CHANNEL, 1000, 500);
			GenSquare(AC97_BASEADDR, BOTH_CHANNELS, 1000, 500);
			fsRunAction = 0;
		}
		/**************************
		 * LEDTest
		 **************************/
		if (fsRunAction & bitLEDTest) {
			/*	Xil_Out32(LED_BASEADDR, volumeLED0);
			 sleepTimer(1000);
			 Xil_Out32(LED_BASEADDR, volumeLED1);
			 sleepTimer(1000);
			 Xil_Out32(LED_BASEADDR, volumeLED2);
			 sleepTimer(1000);
			 Xil_Out32(LED_BASEADDR, volumeLED3);
			 sleepTimer(1000);
			 Xil_Out32(LED_BASEADDR, volumeLED4);
			 sleepTimer(5000);
			 Xil_Out32(LED_BASEADDR, volumeLED5);
			 sleepTimer(5000);
			 Xil_Out32(LED_BASEADDR, volumeLED6);
			 sleepTimer(5000);
			 Xil_Out32(LED_BASEADDR, volumeLED7);
			 sleepTimer(5000);
			 Xil_Out32(LED_BASEADDR, 0);
			 Xil_Out32(LED_BASEADDR, allLEDs);
			 sleepTimer(5000);
			 Xil_Out32(LED_BASEADDR, 0);
			 fsRunAction = 0;*/
			Xil_Out32(LED_BASEADDR, volumeLED7);
		  	fftSample(pAudioData, lNumSamples, 0);
			Xil_Out32(LED_BASEADDR, 0);
//			fftSample(pFFTData, pAudioData, lNumSamples, 1);
//			addOriginMeta();
//			if (compareValues(pAudioData, pFFTData)) {
//				Xil_Out32(LED_BASEADDR, allLEDs);
//				sleepTimer(5000);
//				Xil_Out32(LED_BASEADDR, 0);
//				Xil_Out32(LED_BASEADDR, allLEDs);
//				sleepTimer(5000);
//				Xil_Out32(LED_BASEADDR, 0);
//			} else {
//				Xil_Out32(LED_BASEADDR, volumeLED0);
//				sleepTimer(1000);
//				Xil_Out32(LED_BASEADDR, volumeLED1);
//				sleepTimer(1000);
//				Xil_Out32(LED_BASEADDR, volumeLED2);
//				sleepTimer(1000);
//				Xil_Out32(LED_BASEADDR, volumeLED3);
//				sleepTimer(1000);
//				Xil_Out32(LED_BASEADDR, volumeLED4);
//			}
			fsRunAction = 0;

		}
		/**************************
		 * Record audio from input
		 **************************/
		if (fsRunAction & bitRec) {
			AC97_Set_Tag_And_Id(AC97_BASEADDR, 0xF800); //Set to configure

			/*
			 * Select input source, enable it, and then set the volume
			 */
			if (Xil_In32(SW_BASEADDR) & bitSw0) {
				AC97_Select_Input(AC97_BASEADDR, BOTH_CHANNELS,
						AC97_LINE_IN_SELECT);
				AC97_Unmute(AC97_BASEADDR, AC97_LINE_IN_VOLUME_OFFSET);
				AC97_Set_Volume(AC97_BASEADDR, AC97_LINE_IN_VOLUME_OFFSET,
						BOTH_CHANNELS, VOLUME_MAX);
			} else {
				AC97_Select_Input(AC97_BASEADDR, BOTH_CHANNELS, AC97_MIC_SELECT);
				AC97_Unmute(AC97_BASEADDR, AC97_MIC_VOLUME_OFFSET);
				AC97_Set_Volume(AC97_BASEADDR, AC97_MIC_VOLUME_OFFSET,
						BOTH_CHANNELS, VOLUME_MID);
			}
			//set record gain
			AC97_Set_Volume(AC97_BASEADDR, AC97_RECORD_GAIN_OFFSET,
					BOTH_CHANNELS, 0x00);

			AC97_Set_Tag_And_Id(AC97_BASEADDR, 0x9800); //Set to Send/Receive data

			Count_Samples = 0;

			Xil_Out32(LED_BASEADDR, bitRecLED); //Turn on LED

			middle = 0;
			sampleMax = MIN_UINT;
			countSamples = 0;
			sampleMin = MAX_UINT;
			while ((Count_Samples / 8) < lNumSamples) {
				AC97_Wait_For_New_Frame(AC97_BASEADDR);

				/*
				 * Read audio data from codec
				 */
				Sample_L = XIo_In32(AC97_BASEADDR + AC97_PCM_IN_L_OFFSET);
				Sample_R = XIo_In32(AC97_BASEADDR + AC97_PCM_IN_R_OFFSET);

				/*
				 * our code
				 */
				captureSampleReference(Sample_L & AC97_DATA_MASK,
						Sample_R & AC97_DATA_MASK);

				/*
				 * Write audio data to memory
				 */

				XIo_Out32 (pAudioData + Count_Samples, Sample_L);
				Count_Samples = Count_Samples + 4;
				XIo_Out32 (pAudioData + Count_Samples, Sample_R);
				Count_Samples = Count_Samples + 4;
			}

			//Set Tag and ID to configure the codec
			AC97_Set_Tag_And_Id(AC97_BASEADDR, 0xF800);

			/*
			 * Disable the input source
			 */
			if (Xil_In32(SW_BASEADDR) & bitSw0) {
				AC97_Mute(AC97_BASEADDR, AC97_LINE_IN_VOLUME_OFFSET);
			} else {
				AC97_Mute(AC97_BASEADDR, AC97_MIC_VOLUME_OFFSET);
			}
			middle = middle / countSamples;
			Xil_Out32(LED_BASEADDR, 0); //Turn off LED
			fsRunAction = 0;
		}

	}

	cleanup_platform();

	return 0;
}
Ejemplo n.º 25
0
void enableButtonInterrupt(void) {
	xil_printf("\r\nEnabling button interrupts...");
	XGpio_InterruptEnable(&pshBtns, lBtnChannel);
	XGpio_InterruptGlobalEnable(&pshBtns);
	xil_printf("done");
}
Ejemplo n.º 26
0
void BTN_Intr_Handler(void *InstancePtr)
{

	// Ignore additional button presses
		if ((XGpio_InterruptGetStatus(&BTNInst) & BTN_INT) !=
				BTN_INT) {
				return;

		// Disable GPIO interrupts
		XGpio_InterruptDisable(&BTNInst, BTN_INT);
				 }


		btn_value = XGpio_DiscreteRead(&BTNInst, 1);
		switch (btn_value){

					//Checking if BTNC was pressed. Action: Show Alex in the middle
					case 1:
						x=8;
						y=2;
						clear_OLED();
						show_alex(x,y);
					break;

					//Checking if BTND was pressed. Action: Check for boundary and move Alex down.
					case 2:
						if (y<3)
							{
								y=y+1;
								clear_OLED();
								show_alex(x,y);
							}
					break;

					//Checking if BTNL was pressed. Action: Check for boundary and move Alex left.
					case 4:
						if (x>0)
							{
								x=x-1;
								clear_OLED();
								show_alex(x,y);
							}
					break;

					//Checking if BTNR was pressed. Action: Check for boundary and move Alex right.
					case 8:
						if (x<15)
							{
								x=x+1;
								clear_OLED();
								show_alex(x,y);
							}
					break;

					//Checking if BTNU was pressed. Action: Check for boundary and move Alex up.
					case 16:
						if (y>0)
							{
								y=y-1;
								clear_OLED();
								show_alex(x,y);
							}
					break;

					default:
					break;
						}


		// Acknowledge GPIO interrupts
	    (void)XGpio_InterruptClear(&BTNInst, BTN_INT);
	    // Enable GPIO interrupts
	    XGpio_InterruptEnable(&BTNInst, BTN_INT);

}
Ejemplo n.º 27
0
/**
* This function is the Interrupt Service Routine for the GPIO device.
*
* This function will detect the push button on the board has changed state
* and then prepare data to be sent to the host upon receiving the Get
*
* @param	InstancePtr is the GPIO component to operate on. It is a void
*		pointer to meet the interface of an interrupt processing
* 		function.
*
* @return 	None.
*
* @note		None.
*
*****************************************************************************/
void GpioIsr(void *InstancePtr)
{
	XGpio *GpioPtr = (XGpio *)InstancePtr;
	u32 Buttons;
	u32 ButtonsChanged = 0;
	static u32 PreviousButtons;
	u8 Index = 0;
	static u8 State = 0;
	const u8 Position[] = {-4, -4, -4, 0, 4, 4, 4, 0, -4, -4};
	u8 TxBuf[4];


	/*
	 * Disable the interrupt
	 */
	XGpio_InterruptDisable(GpioPtr, BUTTON_INTERRUPT);


	/*
	 * There should not be any other interrupts occurring other than the
	 * the button changes.
	 */
	if ((XGpio_InterruptGetStatus(GpioPtr) & BUTTON_INTERRUPT) !=
		BUTTON_INTERRUPT) {
		return;
	}

	/*
	 * Read state of push buttons and determine which ones changed
	 * states from the previous interrupt. Save a copy of the buttons
	 * for the next interrupt.
	 */
	Buttons = (XGpio_DiscreteRead(GpioPtr, BUTTON_CHANNEL) & 0x1F) ;
	ButtonsChanged = Buttons ^ PreviousButtons;
	PreviousButtons = Buttons;

	/*
	 * Handle all button state changes that occurred since the last
	 * interrupt
	 */
	while (ButtonsChanged != 0) {

		/*
		 * Determine which button changed state and then get
		 * the current state of the associated LED
		 */
		if (ButtonsChanged & 0x1F){

				if (ButtonsChanged & EXIT_BUTTON){
					StopTest = TRUE;
					break;
				}
				TxBuf[1] = Position [State];
				TxBuf[2] = Position [State+2];
				++State;
				for (Index =0; Index < 5; Index++){
					XUsb_EpDataSend(&UsbInstance, 1,
						(unsigned char *)&TxBuf[0], 4);
				}

				if (State > 7)
					State = 0;
		}
		break;
	}

	/*
	 * Clear the interrupt such that it is no longer pending in the GPIO
	 */
	(void)XGpio_InterruptClear(GpioPtr, BUTTON_INTERRUPT);

	/*
	 * Enable the interrupt
	 */
	XGpio_InterruptEnable(GpioPtr, BUTTON_INTERRUPT);

}
Ejemplo n.º 28
0
/**
*
* This function sets up the interrupt system such that interrupts can occur
* for the USB and GPIO
*
* @param	Intc is the pointer to the Interrupt controller instance.
* @param	UsbInstancePtr is a pointer to the USB device instance.
* @param	Gpio is pointer to the GPIO instance.
*
* @return
*		- XST_SUCCESS if successful.
*		- XST_FAILURE. if it fails.
*
* @note		None.
*
*******************************************************************************/
static int SetupInterruptSystem(XUsb *UsbInstancePtr, XGpio *Gpio)
{
	int Status;

	/*
	 * Initialize the interrupt controller driver.
	 */
	Status = XIntc_Initialize(&Intc, INTC_DEVICE_ID);
	if (Status != XST_SUCCESS){
		return XST_FAILURE;
	}


	/*
	 * Connect a device driver handler that will be called when an interrupt
	 * for the USB device occurs.
	 */
	Status = XIntc_Connect(&Intc, USB_INTR,
			    (XInterruptHandler)XUsb_IntrHandler,
			    (void *)UsbInstancePtr);
	if (Status != XST_SUCCESS){
		return XST_FAILURE;
	}

	/*
	 * Connect a device driver handler that will be called when an interrupt
	 * for the GPIO device occurs.
	 */
	XIntc_Connect(&Intc, INTC_GPIO_INTERRUPT_ID,
			(XInterruptHandler)GpioIsr,(void *) Gpio);

	/*
	 * Start the interrupt controller such that interrupts are enabled for
	 * all devices that cause interrupts, specific real mode so that
	 * the USB can cause interrupts through the interrupt controller.
	 */
	Status = XIntc_Start(&Intc, XIN_REAL_MODE);
	if (Status != XST_SUCCESS){
		return XST_FAILURE;
	}

	/*
	 * Enable the GPIO channel interrupts so that push button can be
	 * detected and enable interrupts for the GPIO device
	 */
	XGpio_InterruptEnable(Gpio, BUTTON_INTERRUPT);
	XGpio_InterruptGlobalEnable(Gpio);

	/*
	 * Enable the interrupt for GPIO
	 */
	XIntc_Enable(&Intc, INTC_GPIO_INTERRUPT_ID);

	/*
	 * Enable the interrupt for the USB.
	 */
	XIntc_Enable(&Intc, USB_INTR);

	/*
	 * Initialize the exception table
	 */
	Xil_ExceptionInit();

	/*
	 * Register the interrupt controller handler with the exception table
	 */
	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
				(Xil_ExceptionHandler)XIntc_InterruptHandler,
				&Intc);

	/*
	 * Enable non-critical exceptions
	 */
	Xil_ExceptionEnable();

	return XST_SUCCESS;
}
Ejemplo n.º 29
0
void vApplicationSetupHardware( void )
{
	XScuGic * InterruptController = prvGetInterruptControllerInstance();
	int iPinNumberEMIO = 54;
	u32 uPinDirectionEMIO = 0x0;
	u32 uPinDirection = 0x1;
	print("##### Application Starts #####\n\r");
	print("\r\n");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-1 :AXI GPIO Initialization
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	u32 xStatus = XGpio_Initialize(&GPIOInstance_Ptr,XPAR_AXI_GPIO_0_DEVICE_ID);
	if(XST_SUCCESS != xStatus)
		print("GPIO INIT FAILED\n\r");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-2 :AXI GPIO Set the Direction
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XGpio_SetDataDirection(&GPIOInstance_Ptr, 1,1);
	//set up GPIO interrupt
	XGpio_InterruptEnable(&GPIOInstance_Ptr, 0x1);
	XGpio_InterruptGlobalEnable(&GPIOInstance_Ptr);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-3 :AXI Timer Initialization
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	xStatus = XTmrCtr_Initialize(&TimerInstancePtr, XPAR_AXI_TIMER_0_DEVICE_ID);
	if(XST_SUCCESS != xStatus)
		print("TIMER INIT FAILED \n\r");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-4 :Set Timer Handler
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XTmrCtr_SetHandler(&TimerInstancePtr, Timer_InterruptHandler, &TimerInstancePtr);
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-5 :Setting timer Reset Value
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XTmrCtr_SetResetValue(&TimerInstancePtr, 0, 0x0F000000);
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-6 :Setting timer Option (Interrupt Mode And Auto Reload )
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XTmrCtr_SetOptions(&TimerInstancePtr, XPAR_AXI_TIMER_0_DEVICE_ID, (XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION));
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-7 :PS GPIO Intialization
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
	if(GpioConfigPtr == NULL)
		print(" PS GPIO config lookup FAILED \n\r");
	xStatus = XGpioPs_CfgInitialize(&psGpioInstancePtr, GpioConfigPtr, GpioConfigPtr->BaseAddr);
	if(XST_SUCCESS != xStatus)
		print(" PS GPIO INIT FAILED \n\r");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-8 :PS GPIO pin setting to Output
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XGpioPs_SetDirectionPin(&psGpioInstancePtr, 54, uPinDirection);
	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, 54,1);
//	XGpioPs_SetDirectionPin(&psGpioInstancePtr, 8,uPinDirection);
//	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, 8, 1);
	print(" INITED MIO \n\r");
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-9 :EMIO PIN Setting to Input port
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	XGpioPs_SetDirectionPin(&psGpioInstancePtr,	iPinNumberEMIO, uPinDirectionEMIO);
	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, iPinNumberEMIO, 0);
	//XGpioPs_IntrEnable(&psGpioInstancePtr, XGPIOPS_BANK2, 0x1);
	// instance, bank, edge, rising, single edge
	XGpioPs_IntrEnablePin(&psGpioInstancePtr, iPinNumberEMIO);
	XGpioPs_SetIntrType(&psGpioInstancePtr, XGPIOPS_BANK2, 1, 1, 0);
	XGpioPs_SetCallbackHandler(&psGpioInstancePtr, (void *) &psGpioInstancePtr, EMIO_Button_InterruptHandler);

	print(" INITED FIRST EMIO \n\r");
	// EMIO output
	XGpioPs_SetDirectionPin(&psGpioInstancePtr, 55, uPinDirection);
	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, 55, 1);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Step-10 : SCUGIC interrupt controller Initialization
	//Registration of the Timer ISR
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	u32 Status = XScuGic_Connect(InterruptController,
							 XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR,
							 (Xil_ExceptionHandler)XTmrCtr_InterruptHandler,
							 (void *)&TimerInstancePtr);

	if (Status != XST_SUCCESS) {
		print(" Error connection timer interrupt \n \r");
	}

	Status = XScuGic_Connect(InterruptController,
							XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR,
							 (Xil_ExceptionHandler)Button_InterruptHandler,
							 (void *)&GPIOInstance_Ptr);
	if (Status != XST_SUCCESS) {
		print(" Error connection button interrupt \n \r");
	}

	/*
	 * Connect the device driver handler that will be called when an
	 * interrupt for the device occurs, the handler defined above performs
	 * the specific interrupt processing for the device.
	 */
	Status = XScuGic_Connect(InterruptController,
							XPS_GPIO_INT_ID,
							(Xil_ExceptionHandler)XGpioPs_IntrHandler,
							(void *)&psGpioInstancePtr);
	if (Status != XST_SUCCESS) {
		print(" Error connection button EMIO interrupt \n \r");
	}

	/*
	* Enable the interrupt for the device and then cause (simulate) an
	* interrupt so the handlers will be called
	*/
	XScuGic_Enable(InterruptController, XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR);
	XScuGic_Enable(InterruptController, XPS_GPIO_INT_ID);
	XScuGic_Enable(InterruptController, XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR);

	// turn off all LEDs
	XGpioPs_WritePin(&psGpioInstancePtr, iPinNumber, 0);
	XGpioPs_WritePin(&psGpioInstancePtr, 55, 0);

	print(" End of init \n\r");
}
Ejemplo n.º 30
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 SetupInterruptSystem()
{
	int Result;
	INTC *IntcInstancePtr = &Intc;

#ifdef XPAR_INTC_0_DEVICE_ID
	/*
	 * 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, INTC_DEVICE_ID);
	if (Result != XST_SUCCESS) {
		return Result;
	}

	/* Hook up interrupt service routine */
	XIntc_Connect(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID,
		      (Xil_ExceptionHandler)GpioIsr, &Gpio);

	/* Enable the interrupt vector at the interrupt controller */

	XIntc_Enable(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID);

	/*
	 * 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;
	}

#else
	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, INTC_GPIO_INTERRUPT_ID,
					0xA0, 0x3);

	/*
	 * Connect the interrupt handler that will be called when an
	 * interrupt occurs for the device.
	 */
	Result = XScuGic_Connect(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID,
				 (Xil_ExceptionHandler)GpioIsr, &Gpio);
	if (Result != XST_SUCCESS) {
		return Result;
	}

	/*
	 * Enable the interrupt for the GPIO device.
	 */
	XScuGic_Enable(IntcInstancePtr, INTC_GPIO_INTERRUPT_ID);
#endif

	/*
	 * Enable the GPIO channel interrupts so that push button can be
	 * detected and enable interrupts for the GPIO device
	 */
	XGpio_InterruptEnable(&Gpio, BUTTON_INTERRUPT);
	XGpio_InterruptGlobalEnable(&Gpio);

	/*
	 * 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();

	return XST_SUCCESS;
}