示例#1
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;
}
示例#2
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;
}
void interrupt_handler_dispatcher(void* ptr) {
	// Ask the Interrupt Controller for a status of its interrupts
	uint32_t status = XIntc_GetIntrStatus(XPAR_INTC_0_BASEADDR);

	// Check what triggered the interrupt
	if (status & XPAR_FIT_TIMER_0_INTERRUPT_MASK) {
		// Let the timer know it got an interrupt!
//		if (interrupts_timer_handler) interrupts_timer_handler();

		// Then acknowledge it so it can interrupt again
		XIntc_AckIntr(XPAR_INTC_0_BASEADDR, XPAR_FIT_TIMER_0_INTERRUPT_MASK);
	} else if (status & XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK) {

		// ----------
		// Turn off all PB interrupts for now.
		XGpio_InterruptGlobalDisable(&gpPB);

		u32 currentButtonState = XGpio_DiscreteRead(&gpPB, 1);

		pb_interrupt_handler(currentButtonState);

//		XAC97_PlayAudio(XPAR_AXI_AC97_0_BASEADDR, sound_alienMove2.data, &sound_alienMove2.data[sound_alienMove2.numSamples]);

		// Ack the PB interrupt.
		XGpio_InterruptClear(&gpPB, 0xFFFFFFFF);
		// Re-enable PB interrupts.
		XGpio_InterruptGlobalEnable(&gpPB);
		// ------

		XIntc_AckIntr(XPAR_INTC_0_BASEADDR, XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK);
	} else if (status & XPAR_AXI_AC97_0_INTERRUPT_MASK) {

		fifo_interrupt_handler();

		XIntc_AckIntr(XPAR_INTC_0_BASEADDR, XPAR_AXI_AC97_0_INTERRUPT_MASK);
	}
}
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;
}
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");
}
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;
}
示例#7
0
//update bullets, move aliens, move motherhsip, make new alien bullet if less than 4 on screen
void timer_interrupt_handler(){

	//xil_printf("Interrupt Handler\n\r");
	//xil_printf("firstSound: %d\n\r",firstSound);
	if(globals_tankDeath == running){
			if(readyForSound){
				samples = explosionSamples;
				num_samples = explosionNumSamples;
				readyForSound = false;
			}
            XGpio_InterruptGlobalDisable(&gpPB); // Turn off all PB interrupts for now.
            if(first){
                  timer = 1;
                  first = false;
            }
  //perform tank animation-----------------------------------------------------------------------
            if(timer < EXPLODE_TIME){//explode for two seconds
                    if(!(timer % 2))
                            write_tank_explosion1();
                    else
                            write_tank_explosion2();
            }
            else{
            		//explosionSoundIndex = 0;
                    first = true;
                    timer = 1;
                    globals_tankDeath = stopped;
                    write_tank_black();
                    globals_setTankPosition(INITIAL_TANK_POSITION);
                    write_tank_to_memory();
                    XGpio_InterruptGlobalEnable(&gpPB);                 // Re-enable PB interrupts.
            }
	}
        //tank death animation isn't happening. Do other stuff
	else{

	    u32 currentButtonState = XGpio_DiscreteRead(&gpPB, 1);  // Get the current state of the buttons.
	    // allow user to use buttons, even multiple at once. All three at once don't move the tank but do shoot a bullet
	    if(!(timer % TANK_SPEED)){
			switch(currentButtonState){
			  case 8:
				moveTankLeft();
				break;
			  case 1:
				newTankBullet();
				if(readyForSound){
					samples = tankFireArray;
					num_samples = tankFireSamples;
					readyForSound = false;
				}
				break;
			  case 2:
				moveTankRight();
				break;
			  case 9:
				moveTankLeft();
				newTankBullet();
				if(readyForSound){
					samples = tankFireArray;
					num_samples = tankFireSamples;
					readyForSound = false;
				}
				break;
			  case 3:
				moveTankRight();
				newTankBullet();
				if(readyForSound){
					samples = tankFireArray;
					num_samples = tankFireSamples;
					readyForSound = false;
				}
				break;
			  case 11:
				newTankBullet();
				if(readyForSound){
					samples = tankFireArray;
					num_samples = tankFireSamples;
					readyForSound = false;
				}
				break;
			  case 4:
				  //volume up
				  break;
			  case 16:
				  //volume down
				  break;
			  default:
				break;
			}
	    }

	  //ensure random for mothership and alien bullets
	  srand(timer);

	//if mothership is present, move mothership-----------------------------------------------------
	  if(globals_mothershipState == ALIVE && !(timer % MOTHERSHIP_SPEED)){
                //assign new position for mothership
		mothershipPosition += MOTHERSHIP_MOVEMENT;
                //mothership at the edge? 
		if(mothershipPosition + MOTHERSHIP_WIDTH >= X_MAX-MOTHERSHIP_EDGE_CORRECTION){
			mothershipSpawnCounter = rand() % (MOTHERSHIP_MAX + 1 - MOTHERSHIP_MIN) + MOTHERSHIP_MIN;//create a new spawn timer
			globals_mothershipState = DEAD; //erase mothership
			write_mothership_black_to_memory();
			mothershipPosition = 0; //reset mothership position
		}
		else
			write_mothership_to_memory(); //if not at edge, move the ship on screen
			if(readyForSound){
				samples = mothershipSamples;
				num_samples = mothershipNumSamples;
				readyForSound = false;
			}
	  }


	//draw mothership if mothershipSpawnCounter reached---------------------------------------------
	  if(!(mothershipTimer % mothershipSpawnCounter)){
		globals_mothershipState = ALIVE; //set ship to alive
		mothershipTimer = 1;//initialize/reset timer
		write_mothership_to_memory(); //draw on screen
	  }

	//stall deleting alien long enough to see explosion---------------------------------------------
	  if(beginAlienExplosion){
                  //stall till explosion done
		  if(alienExplodeCounter < ALIEN_EXPLODE_TIME){
			  ++alienExplodeCounter;
		  }
		  if(alienExplodeCounter == ALIEN_EXPLODE_TIME){
			  write_alien_dead_to_memory(globals_alien); //erase explosion
			  alienExplodeCounter = 1; //reset timer
			  beginAlienExplosion = false; //end delay
		  }
	  }

//killed mother ship stuff-------------------------------------------------------------------------
	  if(beginMotherExplosion){

		  if(readyForSound){
			  samples = mothExplosionSamples;
			  num_samples = mothExplosionNumSamples;
			  readyForSound = false;
		  }
		  //draw 150 in place of mothership
		  write_mothership_hit_score_to_memory();
                  //delay long enough for user to see
		  if(alienExplodeCounter < MOTHERSHIP_EXPLODE_TIME){
			  ++alienExplodeCounter;
		  }
                  //delay limit reached
		  if(alienExplodeCounter == MOTHERSHIP_EXPLODE_TIME){
			  write_mothership_black_to_memory(); //erase score
			  alienExplodeCounter = 1; //reset counter
			  beginMotherExplosion = false; //no longer exploding
			  mothershipSpawnCounter = rand() % (MOTHERSHIP_MAX + 1 - MOTHERSHIP_MIN) + MOTHERSHIP_MIN;//make new spawn counter
			  mothershipPosition = 0;//reset position
		  }
	  }

	//move alien block----------------------------------------------------------------------------
		//if large amount of aliens are dead, move at fastest rate
	  if(dead_alien_count > DEATH_FOR_FASEST){
		  if(!(timer%ALIEN_SPEED3)){
			  moveAlienBlock();

			  if(readyForSound){
				  samples = alienSamples;
				  num_samples = alienNumSamples;
				  readyForSound = false;
			  }

		  }
	  }
		  //if medium amount dead, move at medium speed
	  else if(dead_alien_count > DEATH_FOR_MEDIUM){
		  if(!(timer%ALIEN_SPEED2)){
			  moveAlienBlock();

			  if(readyForSound){
				  samples = alienSamples;
				  num_samples = alienNumSamples;
				  readyForSound = false;
			  }

		  }
		  //otherwise move at slowest rate
	  }else{
		  if(!(timer%ALIEN_SPEED1)){
			  moveAlienBlock();

			  if(readyForSound){
				  samples = alienSamples;
				  num_samples = alienNumSamples;
				  readyForSound = false;
			  }

		  }
	  }

	//update bullets--------------------------------------------------------------------------------
	  if(!(timer % BULLET_SPEED)){
		  updateBullets();
	  }


	//create new alien bullet-----------------------------------------------------------------------
	  if(!(timer % (rand()%(ALIEN_BULLET_MAX+1-ALIEN_BULLET_MIN)+ALIEN_BULLET_MIN))){//new alien bullet from 2-5 seconds
		 newAlienBullet();
	  }

	//inc mothership timer. Cannot overflow under correct operation---------------------------------
	  if(globals_mothershipState == DEAD)
		  ++mothershipTimer;//mothership needs its own timer. Appears at unpredictable times

	}

//inc timers-------------------------------------------------------------------------------------
  if(timer == UINT16_MAX){ 
    timer = 1;//Reset timer to 1 so as not to mess up mod operations
  }else{
    ++timer;
  }

}
/**
* 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;
}
示例#9
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;
}
示例#10
0
void enableButtonInterrupt(void) {
	xil_printf("\r\nEnabling button interrupts...");
	XGpio_InterruptEnable(&pshBtns, lBtnChannel);
	XGpio_InterruptGlobalEnable(&pshBtns);
	xil_printf("done");
}
示例#11
0
文件: ac97_demo.c 项目: Angurboda/ABP
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;
}
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;
}
示例#13
0
int main()
{
    //init_platform();

    static XGpio pshBtns;
    static XIntc intCtrl;

    Xuint32 Count_Samples;
    Xuint32 Sample_L;
    Xuint32 Sample_R;

    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 (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

			while ((Count_Samples/8) < lNumSamples)
			{
				/*
				 * Block execution until next frame is ready
				 */
				AC97_Wait_For_New_Frame (AC97_BASEADDR);

				//<-------------------------------------------------------------
				// Play 2 different audio clips based on SW7. Use code below to
				// choose where in memory read the audio data from.
				// Also, display the playing time on the UART.
				// Hint: Use the variables "Counter_Examples" and #define lSampleRate


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


				//<-------------------------------------------------------------

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

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

		   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);

				//<-------------------------------------------------------------
				// Store 2 different audio clips based on SW7. Use code below to
				// choose to store where each audio clip will be stored at.
				// Also, display the recording time on the UART.
				// Hint: Use the variables "Counter_Examples" and #define lSampleRate

				/*
				 * Write audio data to memory
				 */
				XIo_Out32 (pAudioData_0 + Count_Samples, Sample_L);
				Count_Samples = Count_Samples +4;
				XIo_Out32 (pAudioData_0 + 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);
		   }

		   Xil_Out32(LED_BASEADDR, 0); //Turn off LED
    	   fsRunAction = 0;
    	}

    }

    //cleanup_platform();

    return 0;
}