/** * This function will un-mask a interrupt. * @param vector the interrupt number */ void rt_hw_interrupt_umask(int vector) { XIntc_Enable(&int_ctl,vector); }
/** * * This function sets up the interrupt system so interrupts can occur for the * System Monitor/ADC. The function is application-specific since the actual * system may or may not have an interrupt controller. The System Monitor/ADC * device could be directly connected to a processor without an interrupt * controller. The user should modify this function to fit the application. * * @param IntcInstancePtr is a pointer to the Interrupt Controller * driver Instance. * @param SysMonPtr is a pointer to the driver instance for the System * Monitor device which is going to be connected to the interrupt * controller. * @param IntrId is XPAR_<INTC_instance>_<SYSMON_ADC_instance>_VEC_ID * value from xparameters.h. * * @return XST_SUCCESS if successful, or XST_FAILURE. * * @note None. * * ****************************************************************************/ static int SysMonSetupInterruptSystem(XIntc* IntcInstancePtr, XSysMon *SysMonPtr, u16 IntrId ) { int Status; #ifndef TESTAPP_GEN /* * Initialize the interrupt controller driver so that it's ready to use. */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Connect the 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 = XIntc_Connect(IntcInstancePtr, IntrId, (XInterruptHandler) SysMonInterruptHandler, SysMonPtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller so interrupts are enabled for all * devices that cause interrupts. Specify real mode so that the System * Monitor/ACD device can cause interrupts through the interrupt * controller. */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Enable the interrupt for the System Monitor/ADC device. */ XIntc_Enable(IntcInstancePtr, IntrId); #ifndef TESTAPP_GEN /* * 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, IntcInstancePtr); /* * Enable exceptions. */ Xil_ExceptionEnable(); #endif /* TESTAPP_GEN */ return XST_SUCCESS; }
/** * This function sets up the interrupt system such that interrupts caused by * Hot-Plug-Detect (HPD) events and pulses are handled. This function is * application-specific for systems that have an interrupt controller connected * to the processor. The user should modify this function to fit the * application. * * @param InstancePtr is a pointer to the XDp instance. * @param IntcPtr is a pointer to the interrupt instance. * @param IntrId is the unique device ID of the interrupt controller. * @param DpIntrId is the interrupt ID of the DisplayPort TX connection to * the interrupt controller. * @param HpdEventHandler is a pointer to the handler called when an HPD * event occurs. * @param HpdPulseHandler is a pointer to the handler called when an HPD * pulse occurs. * * @return * - XST_SUCCESS if the interrupt system was successfully set up. * - XST_FAILURE otherwise. * * @note An interrupt controller must be present in the system, connected * to the processor and the DisplayPort TX core. * *******************************************************************************/ static u32 Dptx_SetupInterruptHandler(XDp *InstancePtr, INTC *IntcPtr, u16 IntrId, u16 DpIntrId, XDp_IntrHandler HpdEventHandler, XDp_IntrHandler HpdPulseHandler) { u32 Status; /* Set the HPD interrupt handlers. */ XDp_TxSetHpdEventHandler(InstancePtr, HpdEventHandler, InstancePtr); XDp_TxSetHpdPulseHandler(InstancePtr, HpdPulseHandler, InstancePtr); /* Initialize interrupt controller driver. */ #ifdef XPAR_INTC_0_DEVICE_ID Status = XIntc_Initialize(IntcPtr, IntrId); if (Status != XST_SUCCESS) { return XST_FAILURE; } #else XScuGic_Config *IntcConfig; IntcConfig = XScuGic_LookupConfig(IntrId); Status = XScuGic_CfgInitialize(IntcPtr, IntcConfig, IntcConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } XScuGic_SetPriorityTriggerType(IntcPtr, DpIntrId, 0xA0, 0x1); #endif /* XPAR_INTC_0_DEVICE_ID */ /* 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. */ #ifdef XPAR_INTC_0_DEVICE_ID Status = XIntc_Connect(IntcPtr, DpIntrId, (XInterruptHandler)XDp_InterruptHandler, InstancePtr); #else Status = XScuGic_Connect(IntcPtr, DpIntrId, (Xil_InterruptHandler)XDp_InterruptHandler, InstancePtr); #endif /* XPAR_INTC_0_DEVICE_ID */ if (Status != XST_SUCCESS) { return XST_FAILURE; } /* Start the interrupt controller. */ #ifdef XPAR_INTC_0_DEVICE_ID Status = XIntc_Start(IntcPtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } XIntc_Enable(IntcPtr, DpIntrId); #else XScuGic_Enable(IntcPtr, DpIntrId); #endif /* XPAR_INTC_0_DEVICE_ID */ /* Initialize the exception table. */ Xil_ExceptionInit(); /* Register the interrupt controller handler with the exception table. */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)INTC_HANDLER, IntcPtr); /* Enable exceptions. */ Xil_ExceptionEnable(); return XST_SUCCESS; }
static int SetupIntrSystem(XIntc *IntcInstancePtr, XAxiCdma *InstancePtr, u32 IntrId) { int Status; #ifndef TESTAPP_GEN /* * Initialize the interrupt controller driver */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { xdbg_printf(XDBG_DEBUG_ERROR, "Interrupt controller intialization failed %d\r\n",Status); return XST_FAILURE; } #endif /* * Connect the driver interrupt handler to intc. * It will call the example callback upon transfer completion */ Status = XIntc_Connect(IntcInstancePtr, IntrId, (XInterruptHandler)XAxiCdma_IntrHandler, (void *)InstancePtr); if (Status != XST_SUCCESS) { xdbg_printf(XDBG_DEBUG_ERROR, "Interrupt handler registration failed %d\r\n", Status); return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts. Specify real mode so that the DMA * engine can generate interrupts through the interrupt controller */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Enable the interrupt for the DMA engine */ XIntc_Enable(IntcInstancePtr, IntrId); #ifndef TESTAPP_GEN Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XIntc_InterruptHandler, (void *)IntcInstancePtr); Xil_ExceptionEnable(); #endif /* TESTAPP_GEN */ return XST_SUCCESS; }
/** * * This function setups the interrupt system such that interrupts can occur * for the EmacLite device. This function is application specific since the * actual system may or may not have an interrupt controller. The EmacLite * could be directly connected to a processor without an interrupt controller. * The user should modify this function to fit the application. * * @param IntcInstancePtr is a pointer to the instance of the Intc. * @param EmacLiteInstPtr is a pointer to the instance of the EmacLite. * @param EmacLiteIntrId is the interrupt ID and is typically * XPAR_<INTC_instance>_<EMACLITE_instance>_VEC_ID * value from xparameters.h * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ******************************************************************************/ static int EmacLiteSetupIntrSystem(XIntc *IntcInstancePtr, XEmacLite *EmacLiteInstPtr, u16 EmacLiteIntrId) { int Status; #ifndef TESTAPP_GEN /* * Initialize the interrupt controller driver so that it is ready to * use. */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Connect a 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(IntcInstancePtr, EmacLiteIntrId, XEmacLite_InterruptHandler, (void *)(EmacLiteInstPtr)); if (Status != XST_SUCCESS) { return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specific real mode so that * the EmacLite can cause interrupts thru the interrupt controller. */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Enable the interrupt for the EmacLite in the Interrupt controller. */ XIntc_Enable(IntcInstancePtr, EmacLiteIntrId); #ifndef TESTAPP_GEN /* * 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, IntcInstancePtr); /* * Enable non-critical exceptions. */ Xil_ExceptionEnable(); #endif /* TESTAPP_GEN */ return XST_SUCCESS; }
/** * * This function setups the interrupt system such that interrupts can occur * for the EmacLite device. This function is application specific since the * actual system may or may not have an interrupt controller. The EmacLite * could be directly connected to a processor without an interrupt controller. * The user should modify this function to fit the application. * * @param IntcInstancePtr is a pointer to the instance of the Intc. * @param EmacLiteInstPtr is a pointer to the instance of the EmacLite. * @param EmacLiteIntrId is the interrupt ID and is typically * XPAR_<INTC_instance>_<EMACLITE_instance>_VEC_ID * value from xparameters.h * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ******************************************************************************/ static int EmacLiteSetupIntrSystem(INTC *IntcInstancePtr, XEmacLite *EmacLiteInstPtr, u16 EmacLiteIntrId) { int Status; #ifdef XPAR_INTC_0_DEVICE_ID #ifndef TESTAPP_GEN /* * Initialize the interrupt controller driver so that it is ready to * use. */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Connect a 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(IntcInstancePtr, EmacLiteIntrId, XEmacLite_InterruptHandler, (void *)(EmacLiteInstPtr)); if (Status != XST_SUCCESS) { return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specific real mode so that * the EmacLite can cause interrupts thru the interrupt controller. */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Enable the interrupt for the EmacLite in the Interrupt controller. */ XIntc_Enable(IntcInstancePtr, EmacLiteIntrId); #else /* SCUGIC */ #ifndef TESTAPP_GEN 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; } Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, IntcConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif XScuGic_SetPriorityTriggerType(IntcInstancePtr, EmacLiteIntrId, 0xA0, 0x3); /* * Connect the interrupt handler that will be called when an * interrupt occurs for the device. */ Status = XScuGic_Connect(IntcInstancePtr, EmacLiteIntrId, (Xil_ExceptionHandler)XEmacLite_InterruptHandler, EmacLiteInstPtr); if (Status != XST_SUCCESS) { return Status; } /* * Enable the interrupt for the Can device. */ XScuGic_Enable(IntcInstancePtr, EmacLiteIntrId); #endif #ifndef TESTAPP_GEN /* * Initialize the exception table. */ Xil_ExceptionInit(); /* * Register the interrupt controller handler with the exception table. */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler) INTC_HANDLER, IntcInstancePtr); /* * Enable non-critical exceptions. */ Xil_ExceptionEnable(); #endif /* TESTAPP_GEN */ return XST_SUCCESS; }
/* TMP3_SetupInterruptSystem() ** ** Parameters: ** InstancePtr: PmodTMP3 object to get data from ** interruptDeviceID: Device ID of the interrupt controller ** interruptID: The vector ID of the TMP3 I2C interrupt ** ** Return Value: ** A status indicating XST_SUCCESS or a value that is contained in ** xstatus.h. ** ** Errors: ** none ** ** Description: ** This function sets up the interrupt system for the example. The processing ** contained in this function assumes the hardware system was built with ** and interrupt controller. ** *****************************************************************************/ int TMP3_SetupInterruptSystem(PmodTMP3* InstancePtr, u32 interruptDeviceID, u32 interruptID, void* SendHandler, void* ReceiveHandler) { 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, interruptDeviceID); if (Result != XST_SUCCESS) { return Result; } /* Hook up interrupt service routine */ XIntc_Connect(IntcInstancePtr, interruptID, (Xil_ExceptionHandler)XIic_InterruptHandler, &InstancePtr->TMP3Iic); /* 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; } XIic_SetSendHandler(&InstancePtr->TMP3Iic, InstancePtr, (XIic_Handler)SendHandler); XIic_SetRecvHandler(&InstancePtr->TMP3Iic, InstancePtr, (XIic_Handler)ReceiveHandler); /* * 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(); #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(interruptDeviceID); 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)XIic_InterruptHandler, &InstancePtr->TMP3Iic); if (Result != XST_SUCCESS) { return Result; } /* * Enable the interrupt for the device. */ XScuGic_Enable(IntcInstancePtr, interruptID); XIic_SetSendHandler(&InstancePtr->TMP3Iic, InstancePtr, (XIic_Handler)SendHandler); XIic_SetRecvHandler(&InstancePtr->TMP3Iic, InstancePtr, (XIic_Handler)ReceiveHandler); XIic_SetStatusHandler(&InstancePtr->TMP3Iic, InstancePtr, (XIic_Handler)StatusHandler); /* * 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(); #endif return XST_SUCCESS; }
void enable_ps2_int() { XIntc *intcp; intcp = &intc; XIntc_Enable(intcp, XPAR_XPS_INTC_0_PS2CORE_0_PS2_INTERRUPT_INTR); }
void enable_display_timer(void) { XIntc *intcp; intcp = &intc; XIntc_Enable(intcp, XPAR_XPS_INTC_0_XPS_TIMER_1_INTERRUPT_INTR); }
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; }
/** * This function setups the interrupt system such that interrupts can occur * for the timer counter. This function is application specific since the actual * system may or may not have an interrupt controller. The timer counter could * be directly connected to a processor without an interrupt controller. The * user should modify this function to fit the application. * * @param IntcInstancePtr is a pointer to the Interrupt Controller * driver Instance. * @param TmrCtrInstancePtr is a pointer to the XTmrCtr driver Instance. * @param DeviceId is the XPAR_<TmrCtr_instance>_DEVICE_ID value from * xparameters.h. * @param IntrId is XPAR_<INTC_instance>_<TmrCtr_instance>_VEC_ID * value from xparameters.h. * @param TmrCtrNumber is the number of the timer to which this * handler is associated with. * * @return XST_SUCCESS if the Test is successful, otherwise XST_FAILURE. * * @note This function contains an infinite loop such that if interrupts * are not working it may never return. * ******************************************************************************/ static int TmrCtrSetupIntrSystem(INTC* IntcInstancePtr, XTmrCtr* TmrCtrInstancePtr, u16 DeviceId, u16 IntrId, u8 TmrCtrNumber) { int Status; #ifdef XPAR_INTC_0_DEVICE_ID #ifndef TESTAPP_GEN /* * Initialize the interrupt controller driver so that * it's ready to use, specify the device ID that is generated in * xparameters.h */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Connect a 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(IntcInstancePtr, IntrId, (XInterruptHandler)XTmrCtr_InterruptHandler, (void *)TmrCtrInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specific real mode so that * the timer counter can cause interrupts thru the interrupt controller. */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Enable the interrupt for the timer counter */ XIntc_Enable(IntcInstancePtr, IntrId); #else #ifndef TESTAPP_GEN 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; } Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, IntcConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* TESTAPP_GEN */ XScuGic_SetPriorityTriggerType(IntcInstancePtr, IntrId, 0xA0, 0x3); /* * Connect the interrupt handler that will be called when an * interrupt occurs for the device. */ Status = XScuGic_Connect(IntcInstancePtr, IntrId, (Xil_ExceptionHandler)XTmrCtr_InterruptHandler, TmrCtrInstancePtr); if (Status != XST_SUCCESS) { return Status; } /* * Enable the interrupt for the Timer device. */ XScuGic_Enable(IntcInstancePtr, IntrId); #endif /* XPAR_INTC_0_DEVICE_ID */ #ifndef TESTAPP_GEN /* * Initialize the exception table. */ Xil_ExceptionInit(); /* * Register the interrupt controller handler with the exception table. */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler) INTC_HANDLER, IntcInstancePtr); /* * Enable non-critical exceptions. */ Xil_ExceptionEnable(); #endif return XST_SUCCESS; }
int interrupt_init(){ int Result; Result = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); if (Result != XST_SUCCESS) { return Result; } Result = XIntc_Connect(&InterruptController, INTC_GPIO_INTERRUPT_ID, (XInterruptHandler)GpioIsr, &Gpio); if (Result != XST_SUCCESS) { warp_printf(PL_ERROR,"Failed to connect GPIO to XIntc\n"); return Result; } Result = XIntc_Connect(&InterruptController, UARTLITE_INT_IRQ_ID, (XInterruptHandler)XUartLite_InterruptHandler, &UartLite); if (Result != XST_SUCCESS) { warp_printf(PL_ERROR,"Failed to connect XUartLite to XIntc\n"); return Result; } //Connect Timer to Interrupt Controller Result = XIntc_Connect(&InterruptController, TMRCTR_INTERRUPT_ID, (XInterruptHandler)XTmrCtr_CustomInterruptHandler, &TimerCounterInst); //Result = XIntc_Connect(&InterruptController, TMRCTR_DEVICE_ID, (XInterruptHandler)timer_handler, &TimerCounterInst); if (Result != XST_SUCCESS) { xil_printf("Failed to connect XTmrCtr to XIntC\n"); return -1; } wlan_lib_setup_mailbox_interrupt(&InterruptController); wlan_eth_setup_interrupt(&InterruptController); Result = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Result != XST_SUCCESS) { warp_printf(PL_ERROR,"Failed to start XIntc\n"); return Result; } XIntc_Enable(&InterruptController, INTC_GPIO_INTERRUPT_ID); XIntc_Enable(&InterruptController, UARTLITE_INT_IRQ_ID); XIntc_Enable(&InterruptController, TMRCTR_INTERRUPT_ID); Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,(Xil_ExceptionHandler)XIntc_InterruptHandler, &InterruptController); /* Enable non-critical exceptions */ Xil_ExceptionEnable(); XGpio_InterruptEnable(&Gpio, GPIO_INPUT_INTERRUPT); XGpio_InterruptGlobalEnable(&Gpio); XUartLite_SetSendHandler(&UartLite, SendHandler, &UartLite); XUartLite_SetRecvHandler(&UartLite, RecvHandler, &UartLite); XUartLite_EnableInterrupt(&UartLite); XUartLite_Recv(&UartLite, ReceiveBuffer, UART_BUFFER_SIZE); return 0; }
int main() { //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; }
/**************************************************************************** * * FUNCTION: * * main * * DESCRIPTION: * * This is the entry point for the example. The embedded system automatically * calls main. * * ARGUMENTS: * * None. * * RETURN VALUE: * * None. * * NOTES: * * None. * ****************************************************************************/ int main() { XStatus Status; int PreviousCount = 0; /* Using printf with the UART Lite assumes that the layer 0 device * driver was selected for the UART Lite in the XPS and the standard * I/O peripheral in XPS was set to the UART Lite */printf("\n\rStarting the Application\n\r"); /*************************** GPIO Setup *******************************/ /* The second GPIO example uses the higher level (layer 1) driver to * blink the LEDs, First initialize the GPIO component */ Status = XGpio_Initialize(&Gpio, XPAR_AXI_GPIO_0_DEVICE_ID); if (Status != XST_SUCCESS) { printf("GPIO initialization error\n\r\r"); } /* Set the direction for all signals to be inputs except the LED * outputs */ XGpio_SetDataDirection(&Gpio, 1, ~LED); /************************* Timer Setup ********************************/ /* Initialize the timer counter so that it's ready to use, * specify the device ID that is generated in xparameters.h */ Status = XTmrCtr_Initialize(&TimerCounter, XPAR_AXI_TIMER_0_DEVICE_ID); if (Status != XST_SUCCESS) { printf("Timer counter initialization error\n\r\r"); } /* Perform a self-test to ensure that the hardware was built * correctly, use the 1st timer in the device (0) */ Status = XTmrCtr_SelfTest(&TimerCounter, TIMER_COUNTER_0); if (Status != XST_SUCCESS) { printf("Timer counter self-test error\n\r"); } /* Setup the handler for the timer counter that will be called from the * interrupt context when the timer expires, specify a pointer to the * timer counter driver instance as the callback reference so the handler * is able to access the instance data */ XTmrCtr_SetHandler(&TimerCounter, TimerCounterHandler, &TimerCounter); /* Enable the interrupt of the timer counter so interrupts will occur * and use auto reload mode such that the timer counter will reload * itself automatically and continue repeatedly, without this option * it would expire once only */ XTmrCtr_SetOptions(&TimerCounter, TIMER_COUNTER_0, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION); /* Set a reset value for the timer counter such that it will expire * earlier than letting it roll over from 0, the reset value is loaded * into the timer counter when it is started */ XTmrCtr_SetResetValue(&TimerCounter, TIMER_COUNTER_0, resetTime /*RESET_VALUE*/); /* Start the timer counter such that it's incrementing */ XTmrCtr_Start(&TimerCounter, TIMER_COUNTER_0); /********************** 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_AXI_TIMER_0_INTERRUPT_INTR, // we don't know what this is, but it's probably 0 (XInterruptHandler) XTmrCtr_InterruptHandler, &TimerCounter); if (Status != XST_SUCCESS) { printf("Interrupt controller connect error\n\r"); } /* * Start the interrupt controller so interrupts are enabled for all * devices that cause interrupts. Specify real mode so that the timer * counter can cause interrupts through the interrupt controller. */ Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Status != XST_SUCCESS) { printf("Interrupt controller start error\n\r"); } /* Enable the interrupt for the timer counter and enable interrupts in * the microblaze processor */ XIntc_Enable(&InterruptController, XPAR_AXI_INTC_0_AXI_TIMER_0_INTERRUPT_INTR); microblaze_enable_interrupts(); /********************** Application Processing *********************/ /* Insert foreground processing here, interrupts will handle * processing in the background */ while (1) { char get = (char)*(volatile int *)(XPAR_RS232_UART_1_BASEADDR); if (get >= ' ' && get <= '~') break; } // stop the timer microblaze_disable_interrupts(); // break out of the while look /* The application should not ever execute the following code, but it is * present to indicate if the application does exit because of an error */printf("Exiting the Application\n\r"); }
/** * * This function connects the interrupt handler of the interrupt controller to * the processor. This function is seperate to allow it to be customized for * each application. Each processor or RTOS may require unique processing to * connect the interrupt handler. * * @param None. * * @return None. * * @note None. * ****************************************************************************/ int setUpInterruptSystem() { int Status; /* * Initialize the interrupt controller driver so that it is ready to * use. */ Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built * correctly. */ Status = XIntc_SelfTest(&InterruptController); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect a 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, INTC_DEVICE_INT_ID, (XInterruptHandler)hwTimerISR, (void *)0); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specify simulation mode so that * an interrupt can be caused by software rather than a real hardware * interrupt. */ Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the device and then cause (simulate) an * interrupt so the handlers will be called. */ XIntc_Enable(&InterruptController, INTC_DEVICE_INT_ID); /* * 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, &InterruptController); /* * Enable exceptions. */ Xil_ExceptionEnable(); return XST_SUCCESS; }
/** * * This function setups the interrupt system such that interrupts can occur * for the FIFO device. This function is application specific since the * actual system may or may not have an interrupt controller. The FIFO * could be directly connected to a processor without an interrupt controller. * The user should modify this function to fit the application. * * @param InstancePtr contains a pointer to the instance of the FIFO * component which is going to be connected to the interrupt * controller. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ****************************************************************************/ int SetupInterruptSystem(INTC *IntcInstancePtr, XLlFifo *InstancePtr, u16 FifoIntrId) { int Status; #ifdef XPAR_INTC_0_DEVICE_ID /* * Initialize the interrupt controller driver so that it is ready to * use. */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect a 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(IntcInstancePtr, FifoIntrId, (XInterruptHandler)FifoHandler, (void *)InstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specific real mode so that * the FIFO can cause interrupts through the interrupt controller. */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the AXI FIFO device. */ XIntc_Enable(IntcInstancePtr, FifoIntrId); #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; } Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, IntcConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } XScuGic_SetPriorityTriggerType(IntcInstancePtr, FifoIntrId, 0xA0, 0x3); /* * 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(IntcInstancePtr, FifoIntrId, (Xil_InterruptHandler)FifoHandler, InstancePtr); if (Status != XST_SUCCESS) { return Status; } XScuGic_Enable(IntcInstancePtr, FifoIntrId); #endif /* * Initialize the exception table. */ Xil_ExceptionInit(); /* * Register the interrupt controller handler with the exception table. */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)INTC_HANDLER, (void *)IntcInstancePtr);; /* * Enable exceptions. */ Xil_ExceptionEnable(); return XST_SUCCESS; }
/** * * This function sets up the interrupt system so interrupts can occur for the * CAN. This function is application-specific since the actual system may or * may not have an interrupt controller. The CAN could be directly connected * to a processor without an interrupt controller. The user should modify this * function to fit the application. * * @para InstancePtr is a pointer to the instance of the CAN * which is going to be connected to the interrupt controller. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ****************************************************************************/ static int SetupInterruptSystem(XCan *InstancePtr) { static INTC InterruptController; int Status; #ifdef XPAR_INTC_0_DEVICE_ID /* * Initialize the interrupt controller driver so that it's ready to use. * INTC_DEVICE_ID specifies the XINTC device ID that is generated in * xparameters.h. */ Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * 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, CAN_INTR_VEC_ID, (XInterruptHandler)XCan_IntrHandler, InstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the interrupt controller so interrupts are enabled for all * devices that cause interrupts. Specify real mode so that the CAN * can cause interrupts through the interrupt controller. */ Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the CAN. */ XIntc_Enable(&InterruptController, CAN_INTR_VEC_ID); #else /* SCUGIC */ 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; } Status = XScuGic_CfgInitialize(&InterruptController, IntcConfig, IntcConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } XScuGic_SetPriorityTriggerType(&InterruptController, CAN_INTR_VEC_ID, 0xA0, 0x3); /* * Connect the interrupt handler that will be called when an * interrupt occurs for the device. */ Status = XScuGic_Connect(&InterruptController, CAN_INTR_VEC_ID, (Xil_ExceptionHandler)XCan_IntrHandler, InstancePtr); if (Status != XST_SUCCESS) { return Status; } /* * Enable the interrupt for the Can device. */ XScuGic_Enable(&InterruptController, CAN_INTR_VEC_ID); #endif /* * Initialize the exception table. */ Xil_ExceptionInit(); /* * Register the interrupt controller handler with the exception table. */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)INTC_HANDLER, &InterruptController); /* * Enable exceptions. */ Xil_ExceptionEnable(); return XST_SUCCESS; }
/** * * This function performs the GPIO set up for Interrupts * * @param IntcInstancePtr is a reference to the Interrupt Controller * driver Instance * @param InstancePtr is a reference to the GPIO driver Instance * @param DeviceId is the XPAR_<GPIO_instance>_DEVICE_ID value from * xparameters.h * @param IntrId is XPAR_<INTC_instance>_<GPIO_instance>_IP2INTC_IRPT_INTR * value from xparameters.h * @param IntrMask is the GPIO channel mask * * @return XST_SUCCESS if the Test is successful, otherwise XST_FAILURE * * @note None. * ******************************************************************************/ int GpioSetupIntrSystem(XIntc* IntcInstancePtr, XGpio* InstancePtr, u16 DeviceId, u16 IntrId, u16 IntrMask) { int 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 exception table and register the interrupt * controller handler with the exception table */ Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XIntc_InterruptHandler, IntcInstancePtr); /* Enable non-critical exceptions */ Xil_ExceptionEnable(); /* * 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; }
int do_init(void) { int status; // status from Xilinx Lib calls // initialize the Nexys4IO and Pmod544IO hardware and drivers // rotary encoder is set to increment from 0 by DUTY_CYCLE_CHANGE status = NX4IO_initialize(NX4IO_BASEADDR); if (status != XST_SUCCESS) { return XST_FAILURE; } status = PMDIO_initialize(PMDIO_BASEADDR); if (status != XST_SUCCESS) { return XST_FAILURE; } // successful initialization. Set the rotary encoder // to increment from 0 by DUTY_CYCLE_CHANGE counts per rotation PMDIO_ROT_init(DUTY_CYCLE_CHANGE, true); PMDIO_ROT_clear(); // initialize the GPIO instances status = XGpio_Initialize(&GPIOInst0, GPIO_0_DEVICE_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } status = XGpio_Initialize(&GPIOInst1, GPIO_1_DEVICE_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } // GPIO_0 channel 1 is an 8-bit input port. bit[7:1] = reserved, bit[0] = PWM output (for duty cycle calculation) // GPIO_0 channel 2 is an 8-bit output port. bit[7:1] = reserved, bit[0] = FIT clock XGpio_SetDataDirection(&GPIOInst0, GPIO_0_INPUT_CHANNEL, 0xFF); XGpio_SetDataDirection(&GPIOInst0, GPIO_0_OUTPUT_CHANNEL, 0xFE); // GPIO_1 channel 1 is a 32-bit input port - used to pass hw_detect 'high' count to application // GPIO_1 channel 2 is an 8-bit output port - used to pass hw_detect 'low' count to application XGpio_SetDataDirection(&GPIOInst1, GPIO_1_HIGH_COUNT, 0xFFFFFFFF); XGpio_SetDataDirection(&GPIOInst1, GPIO_1_LOW_COUNT, 0xFFFFFFFF); // initialize the PWM timer/counter instance but do not start it // do not enable PWM interrupts. Clock frequency is the AXI clock frequency status = PWM_Initialize(&PWMTimerInst, PWM_TIMER_DEVICE_ID, false, AXI_CLOCK_FREQ_HZ); if (status != XST_SUCCESS) { return XST_FAILURE; } // initialize the interrupt controller status = XIntc_Initialize(&IntrptCtlrInst, INTC_DEVICE_ID); if (status != XST_SUCCESS) { return XST_FAILURE; } // connect the fixed interval timer (FIT) handler to the interrupt status = XIntc_Connect(&IntrptCtlrInst, FIT_INTERRUPT_ID, (XInterruptHandler)FIT_Handler, (void *)0); if (status != XST_SUCCESS) { return XST_FAILURE; } // start the interrupt controller such that interrupts are enabled for // all devices that cause interrupts status = XIntc_Start(&IntrptCtlrInst, XIN_REAL_MODE); if (status != XST_SUCCESS) { return XST_FAILURE; } // enable the FIT interrupt XIntc_Enable(&IntrptCtlrInst, FIT_INTERRUPT_ID); // set the duty cycles for RGB1. The channels will be enabled/disabled // in the FIT interrupt handler. Red and Blue make purple NX4IO_RGBLED_setDutyCycle(RGB1, 64, 0, 64); NX4IO_RGBLED_setChnlEn(RGB1, false, false, false); return XST_SUCCESS; }
/** * This function setups the interrupt system such that interrupts can occur * for the timer counter. This function is application specific since the actual * system may or may not have an interrupt controller. The timer counter could * be directly connected to a processor without an interrupt controller. The * user should modify this function to fit the application. * * @param IntcInstancePtr is a pointer to the Interrupt Controller * driver Instance. * @param TmrCtrInstancePtr is a pointer to the XTmrCtr driver Instance. * @param DeviceId is the XPAR_<TmrCtr_instance>_DEVICE_ID value from * xparameters.h. * @param IntrId is XPAR_<INTC_instance>_<TmrCtr_instance>_VEC_ID * value from xparameters.h. * @param TmrCtrNumber is the number of the timer to which this * handler is associated with. * * @return XST_SUCCESS if the Test is successful, otherwise XST_FAILURE. * * @note This function contains an infinite loop such that if interrupts * are not working it may never return. * ******************************************************************************/ static int TmrCtrSetupIntrSystem(XIntc* IntcInstancePtr, XTmrCtr* TmrCtrInstancePtr, u16 DeviceId, u16 IntrId, u8 TmrCtrNumber) { int Status; #ifndef TESTAPP_GEN /* * Initialize the interrupt controller driver so that * it's ready to use, specify the device ID that is generated in * xparameters.h */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Connect a 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(IntcInstancePtr, IntrId, (XInterruptHandler)XTmrCtr_InterruptHandler, (void *)TmrCtrInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specific real mode so that * the timer counter can cause interrupts thru the interrupt controller. */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Enable the interrupt for the timer counter */ XIntc_Enable(IntcInstancePtr, IntrId); #ifndef TESTAPP_GEN /* * 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, IntcInstancePtr); /* * Enable non-critical exceptions. */ Xil_ExceptionEnable(); #endif return XST_SUCCESS; }
/** * * 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; }
/** * * This function setups the interrupt system such that interrupts can occur * for the UartLite device. This function is application specific since the * actual system may or may not have an interrupt controller. The UartLite * could be directly connected to a processor without an interrupt controller. * The user should modify this function to fit the application. * * @param UartLitePtr contains a pointer to the instance of the UartLite * component which is going to be connected to the interrupt * controller. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ****************************************************************************/ int SetupInterruptSystem(XUartLite *UartLitePtr) { int Status; /* * Initialize the interrupt controller driver so that it is ready to * use. */ Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect a 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, UARTLITE_INT_IRQ_ID, (XInterruptHandler)XUartLite_InterruptHandler, (void *)UartLitePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specific real mode so that * the UartLite can cause interrupts through the interrupt controller. */ Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the UartLite device. */ XIntc_Enable(&InterruptController, UARTLITE_INT_IRQ_ID); /* * 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, &InterruptController); /* * Enable exceptions. */ Xil_ExceptionEnable(); return XST_SUCCESS; }
/** * 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; }
/***** * do_init() - initialize the system * * This function is executed once at start-up and after a reset. It initializes * the peripherals and registers the interrupt handlers *****/ XStatus do_init(void) { XStatus Status; // status from Xilinx Lib calls // initialize the N3EIF hardware and driver // rotary encoder is set to increment duty cycle from 0 by 5 w/ // no negative counts N3EIF_init(N3EIF_BASEADDR); ROT_init(DUTY_CYCLE_CHANGE, true); ROT_clear(); // initialize the GPIO instance Status = XGpio_Initialize(&GPIOInst, GPIO_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } // GPIO channel 1 is an 8-bit output port that your application can // use. None of the bits are used by this program XGpio_SetDataDirection(&GPIOInst, GPIO_OUTPUT_CHANNEL, 0xF0); XGpio_DiscreteWrite(&GPIOInst, GPIO_OUTPUT_CHANNEL, gpio_port); // initialize the PWM timer/counter instance but do not start it // do not enable PWM interrupts Status = PWM_Initialize(&PWMTimerInst, PWM_TIMER_DEVICE_ID, false); if (Status != XST_SUCCESS) { return XST_FAILURE; } //Initialize LIGHTSENSOR peripheral Status = LIGHTSENSOR_Init(LIGHTSENSOR_BASEADDR); if (Status != XST_SUCCESS) { return XST_FAILURE; } // initialize the interrupt controller Status = XIntc_Initialize(&IntrptCtlrInst,INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } // connect the fixed interval timer (FIT) handler to the interrupt Status = XIntc_Connect(&IntrptCtlrInst, FIT_INTERRUPT_ID, (XInterruptHandler)FIT_Handler, (void *)0); if (Status != XST_SUCCESS) { return XST_FAILURE; } // start the interrupt controller such that interrupts are enabled for // all devices that cause interrupts, specifically real mode so that // the the FIT can cause interrupts thru the interrupt controller. Status = XIntc_Start(&IntrptCtlrInst, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } // start the lightsensor Status = LIGHTSENSOR_Start(LIGHTSENSOR_BASEADDR); if (Status != XST_SUCCESS) { return XST_FAILURE; } // enable the FIT interrupt XIntc_Enable(&IntrptCtlrInst, FIT_INTERRUPT_ID); return XST_SUCCESS; }
/** * * This function setups the interrupt system such that interrupts can occur * for the Spi device. This function is application specific since the actual * system may or may not have an interrupt controller. The Spi device could be * directly connected to a processor without an interrupt controller. The * user should modify this function to fit the application. * * @param SpiPtr is a pointer to the instance of the Spi device. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None * ******************************************************************************/ static int SetupInterruptSystem(XSpi *SpiPtr) { int Status; /* * Initialize the interrupt controller driver so that it's ready to use * specify the device ID that is generated in xparameters.h. */ Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect a 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, SPI_INTR_ID, (XInterruptHandler)XSpi_InterruptHandler, (void *)SpiPtr); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specify real mode so that the SPI * can cause interrupts through the interrupt controller. */ Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the SPI. */ XIntc_Enable(&InterruptController, SPI_INTR_ID); /* * 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, &InterruptController); /* * Enable non-critical exceptions. */ Xil_ExceptionEnable(); return XST_SUCCESS; }
/** * * This function setups the interrupt system such that interrupts can occur * for the UART. This function is application specific since the actual * system may or may not have an interrupt controller. The UART could be * directly connected to a processor without an interrupt controller. The * user should modify this function to fit the application. * * @param IntcInstancePtr is a pointer to the instance of the INTC component. * @param UartInstancePtr is a pointer to the instance of the UART component. * @param UartIntrId is the interrupt Id and is typically * XPAR_<INTC_instance>_<UARTNS550_instance>_IP2INTC_IRPT_INTR * value from xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE * * * @note None * *******************************************************************************/ static XStatus UartNs550SetupIntrSystem(XIntc *IntcInstancePtr, XUartNs550 *UartInstancePtr, Xuint16 UartIntrId) { XStatus Status; #ifndef TESTAPP_GEN /* * Initialize the interrupt controller driver so that it is ready to use. */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Connect a 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(IntcInstancePtr, UartIntrId, (XInterruptHandler)XUartNs550_InterruptHandler, (void *)UartInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specific real mode so that * the UART can cause interrupts thru the interrupt controller. */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Enable the interrupt for the UartNs550. */ XIntc_Enable(IntcInstancePtr, UartIntrId); #ifndef TESTAPP_GEN /* * Initialize the PPC exception table. */ XExc_Init(); /* * Register the interrupt controller handler with the exception table. */ XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT, (XExceptionHandler)XIntc_InterruptHandler, IntcInstancePtr); /* * Enable non-critical exceptions. */ XExc_mEnableExceptions(XEXC_NON_CRITICAL); #endif /* TESTAPP_GEN */ return XST_SUCCESS; }
/** * * This function setups the interrupt system so interrupts can occur for the * TEMAC. This function is application-specific since the actual system may or * may not have an interrupt controller. The TEMAC could be directly connected * to a processor without an interrupt controller. The user should modify this * function to fit the application. * * @param IntcInstancePtr is a pointer to the instance of the Intc component. * @param TemacInstancePtr is a pointer to the instance of the Temac * component. * @param TemacIntrId is the Interrupt ID and is typically * XPAR_<INTC_instance>_<TEMAC_instance>_IP2INTC_IRPT_INTR * value from xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ******************************************************************************/ static int TemacSetupIntrSystem(XIntc *IntcInstancePtr, XLlTemac *TemacInstancePtr, XLlDma *DmaInstancePtr, u16 TemacIntrId, u16 DmaRxIntrId, u16 DmaTxIntrId) { XLlDma_BdRing * TxRingPtr = &XLlDma_GetTxRing(DmaInstancePtr); XLlDma_BdRing * RxRingPtr = &XLlDma_GetRxRing(DmaInstancePtr); int Status; #ifndef TESTAPP_GEN /* * Initialize the interrupt controller and connect the ISR */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { TemacUtilErrorTrap("Unable to intialize the interrupt controller"); return XST_FAILURE; } #endif Status = XIntc_Connect(IntcInstancePtr, TemacIntrId, (XInterruptHandler) TemacErrorHandler, TemacInstancePtr); Status |= XIntc_Connect(IntcInstancePtr, DmaTxIntrId, (XInterruptHandler) TxIntrHandler, TxRingPtr); Status |= XIntc_Connect(IntcInstancePtr, DmaRxIntrId, (XInterruptHandler) RxIntrHandler, RxRingPtr); if (Status != XST_SUCCESS) { TemacUtilErrorTrap("Unable to connect ISR to interrupt controller"); return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { TemacUtilErrorTrap("Error starting intc"); return XST_FAILURE; } #endif /* * Enable interrupts from the hardware */ XIntc_Enable(IntcInstancePtr, TemacIntrId); XIntc_Enable(IntcInstancePtr, DmaTxIntrId); XIntc_Enable(IntcInstancePtr, DmaRxIntrId); #ifndef TESTAPP_GEN #ifdef __PPC__ /* * Initialize the PPC exception table */ XExc_Init(); /* * Register the interrupt controller with the exception table */ XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT, (XExceptionHandler) XIntc_InterruptHandler, IntcInstancePtr); /* * Enable non-critical exceptions */ XExc_mEnableExceptions(XEXC_NON_CRITICAL); #else /* * Connect the interrupt controller interrupt handler to the hardware * interrupt handling logic in the microblaze processor. */ microblaze_register_handler((XInterruptHandler) XIntc_InterruptHandler, IntcInstancePtr); /* * Enable interrupts in the Microblaze */ microblaze_enable_interrupts(); #endif #endif return XST_SUCCESS; }
int main() { int i; int prekidac; init_platform(); XStatus Status; //Set Terminal count for my_timer //XIo_Out32(XPAR_MY_TIMER_0_BASEADDR + 0x0, 0x5F5E100); // Run my_timer XIo_Out32(XPAR_MY_TIMER_0_BASEADDR + 0x4, 0x2); Status = XIntc_Initialize (&Intc, XPAR_INTC_0_DEVICE_ID); if (Status != XST_SUCCESS) xil_printf ("\r\nInterrupt controller initialization failure"); else xil_printf("\r\nInterrupt controller initialized"); // Connect my_timer_interrupt_handler Status = XIntc_Connect (&Intc, XPAR_INTC_0_DEVICE_ID, (XInterruptHandler) my_timer_interrupt_handler,(void *)0); if (Status != XST_SUCCESS) xil_printf ("\r\nRegistering MY_TIMER Interrupt Failed"); else xil_printf("\r\nMY_TIMER Interrupt registered"); //start the interrupt controller in real mode Status = XIntc_Start(&Intc, XIN_REAL_MODE); //enable interrupt controller XIntc_Enable (&Intc, XPAR_INTC_0_DEVICE_ID); microblaze_enable_interrupts(); unsigned char string_s[] = "LPRS 2 BRATE\n"; VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x00, 0x0);// direct mode 0 VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x04, 0x3);// display_mode 1 VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x08, 0x1);// show frame 2 VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x0C, 0x1);// font size 3 VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x10, 0xFF0000);// foreground 4 crvena VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x14, 0x00FF00);// foreground 4 green VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x18, 0x0000FF);// foreground 4 plava VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x1c, 0xffff00);// foreground 4 zuta VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x20, 0x000000);// background color crna VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x24, 0xFF0000);// frame color 6 xil_printf("Hello World\n\r"); clear_text_screen(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR); clear_graphics_screen(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR); for(i=0;i<1200;i++){ set_cursor(i); print_char(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR, 0, '2'); } /* set_cursor(0); print_char(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR, 0, '2'); set_cursor(1); print_char(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR, 1, 'G'); set_cursor(2); print_char(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR, 2, 'B'); set_cursor(3); print_char(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR, 3, 'Y'); set_cursor(6); print_string(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR, 2, string_s, 12); set_cursor(45); unsigned char znak = '2'; if(znak >= 0x40){ znak -= 0x40; } VGA_PERIPH_MEM_mWriteMemory(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + TEXT_MEM_OFF + 4*4, znak); for(i=64;i<76;i++){ set_cursor(i); print_char(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR, 2, string_s[i-64]); }*/ while (1){ prekidac = Xil_In8(XPAR_MY_PERIPHERAL_0_BASEADDR);//iscitavanje prekidaca //xil_printf("0x%08x\r\n", prekidac); /* value3 = XIo_In32(XPAR_MY_TIMER_0_BASEADDR + 0x0); value1 = XIo_In32(XPAR_MY_TIMER_0_BASEADDR + 0x4); value2 = XIo_In32(XPAR_MY_TIMER_0_BASEADDR + 0x8); xil_printf("\n\rvalue1 = %x, value2 = %x, value3 = %x.", value1, value2, value3); */ } cleanup_platform(); return 0; }
/* * * This function setups the interrupt system so interrupts can occur for the * DMA, it assumes INTC component exists in the hardware system. * * @param IntcInstancePtr is a pointer to the instance of the INTC. * @param AxiDmaPtr is a pointer to the instance of the DMA engine * @param TxIntrId is the TX channel Interrupt ID. * @param RxIntrId is the RX channel Interrupt ID. * * @return * - XST_SUCCESS if successful, * - XST_FAILURE.if not succesful * * @note None. * ******************************************************************************/ static int SetupIntrSystem(INTC * IntcInstancePtr, XAxiDma * AxiDmaPtr, u16 TxIntrId, u16 RxIntrId) { int Status; #ifdef XPAR_INTC_0_DEVICE_ID /* Initialize the interrupt controller and connect the ISRs */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { xil_printf("Failed init intc\r\n"); return XST_FAILURE; } Status = XIntc_Connect(IntcInstancePtr, TxIntrId, (XInterruptHandler) TxIntrHandler, AxiDmaPtr); if (Status != XST_SUCCESS) { xil_printf("Failed tx connect intc\r\n"); return XST_FAILURE; } Status = XIntc_Connect(IntcInstancePtr, RxIntrId, (XInterruptHandler) RxIntrHandler, AxiDmaPtr); if (Status != XST_SUCCESS) { xil_printf("Failed rx connect intc\r\n"); return XST_FAILURE; } /* Start the interrupt controller */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { xil_printf("Failed to start intc\r\n"); return XST_FAILURE; } XIntc_Enable(IntcInstancePtr, TxIntrId); XIntc_Enable(IntcInstancePtr, RxIntrId); #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; } Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, IntcConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } XScuGic_SetPriorityTriggerType(IntcInstancePtr, TxIntrId, 0xA0, 0x3); XScuGic_SetPriorityTriggerType(IntcInstancePtr, RxIntrId, 0xA0, 0x3); /* * 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(IntcInstancePtr, TxIntrId, (Xil_InterruptHandler)TxIntrHandler, AxiDmaPtr); if (Status != XST_SUCCESS) { return Status; } Status = XScuGic_Connect(IntcInstancePtr, RxIntrId, (Xil_InterruptHandler)RxIntrHandler, AxiDmaPtr); if (Status != XST_SUCCESS) { return Status; } XScuGic_Enable(IntcInstancePtr, TxIntrId); XScuGic_Enable(IntcInstancePtr, RxIntrId); #endif /* Enable interrupts from the hardware */ Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)INTC_HANDLER, (void *)IntcInstancePtr); Xil_ExceptionEnable(); return XST_SUCCESS; }
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; }