/** * * This function is an example of how to use the IO Module driver component * (XIOModule) and the hardware device. This function is designed to work * without external hardware devices to cause interrupts. It may not return if * the IO Module is not properly connected to the processor in either software * or hardware. * * @param DeviceId is device ID of the IO Module Device, typically * XPAR_<IOMODULE_instance>_DEVICE_ID value from xparameters.h * * @return XST_SUCCESS to indicate success, otherwise XST_FAILURE * * @note None. * ******************************************************************************/ XStatus IOModuleExample(u16 DeviceId) { XStatus Status; /* * Initialize the IO Module driver so that it is ready to use. */ Status = XIOModule_Initialize(&IOModule, DeviceId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XIOModule_SelfTest(&IOModule); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the Interrupt System. */ Status = SetUpInterruptSystem(&IOModule); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Generate the interrupts. */ Status = XOModule_GenerateIntr(&IOModule); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Wait for the interrupts to be processed, if no interrupt occurs this * loop will wait forever. */ while (1) { /* * If the interrupts occurred which is indicated by the global * variable which is set in the device driver handler, then * stop waiting */ if (InterruptProcessed) { break; } } return XST_SUCCESS; }
/** * * This function is used by the TestAppGen generated application to setup * the IO Module interrupts. * * @param IOModuleInstancePtr is the reference to the IO Module instance. * @param DeviceId is device ID of the IO Module Device , typically * XPAR_<IOMODULE_instance>_DEVICE_ID value from xparameters.h * * @return XST_SUCCESS to indicate success, otherwise XST_FAILURE * * @note None. * ******************************************************************************/ XStatus IOModuleInterruptSetup(XIOModule *IOModuleInstancePtr, u16 DeviceId) { XStatus Status; /* * Initialize the IO Module driver so that it is ready to use. */ Status = XIOModule_Initialize(IOModuleInstancePtr, DeviceId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XIOModule_SelfTest(IOModuleInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Initialize and enable interrupts in the processor. */ IOModuleSetupIntrSystem(IOModuleInstancePtr); /* * Start the IO Module such that interrupts are enabled for all * internal interrupts. */ Status = XIOModule_Start(IOModuleInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }
/** * This function does a minimal test on the IO Module device and driver as a * design example. The purpose of this function is to illustrate how to use the * IO Module component. It initializes the Programmable Interval Timers and * then sets it up in compare mode with auto reload such that a periodic * interrupt is generated. * * This function uses interrupt driven mode of the IO Module. * * @param IOModuleInstancePtr is a pointer to the IO Module driver * Instance * @param DeviceId is the XPAR_<IOModule_instance>_DEVICE_ID value from * xparameters.h * * @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. * *****************************************************************************/ XStatus IOModuleIntrExample(XIOModule *IOModuleInstancePtr, u16 DeviceId) { int Status; u8 Timer; XIOModule_Config *CfgPtr = IOModuleInstancePtr->CfgPtr; /* * Initialize the IO Module so that it's ready to use, specify the device * ID that is generated in xparameters.h */ Status = XIOModule_Initialize(IOModuleInstancePtr, DeviceId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XIOModule_SelfTest(IOModuleInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Initialize and enable interrupts in the processor. */ IOModuleSetupIntrSystem(IOModuleInstancePtr); /* * Setup the handler for the IO Module handler that will be called from * the interrupt context when an interrupt occurs, specify a pointer to * the IO Module driver instance as the callback reference so the * handler is able to access the instance data. */ XIOModule_SetHandler(IOModuleInstancePtr, IOModuleHandler, IOModuleInstancePtr); for (Timer = 0; Timer < XTC_DEVICE_TIMER_COUNT; Timer++) { /* * Skip unused timers,timers with prescaler (since they may * have very long expiration times), timers without readable * counters, and timers with small size (since the counter * may not change when sampled). */ if (! (CfgPtr->PitUsed[Timer] && CfgPtr->PitPrescaler[Timer] == XTC_PRESCALER_NONE && CfgPtr->PitReadable[Timer] && CfgPtr->PitSize[Timer] > MIN_TIMER_BITS)) { TimerExpired[Timer] = MAX_INTR_COUNT; continue; } /* * Use auto reload mode such that the Programmable Interval Timers will * reload automatically and continue repeatedly, without this option * they would expire once only */ XIOModule_Timer_SetOptions(IOModuleInstancePtr, Timer, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION); /* * Set a reset value for the Programmable Interval Timers such that * they will expire earlier than letting them roll over from 0, the * reset value is loaded into the Programmable Interval Timers when * they are started. */ XIOModule_SetResetValue(IOModuleInstancePtr, Timer, RESET_VALUE); /* * Enable the interrupt for the Programmable Interval Timers. */ XIOModule_Enable(IOModuleInstancePtr, Timer + XIN_IOMODULE_PIT_1_INTERRUPT_INTR); /* * Start the Programmable Interval Timers such that they are * decrementing by default, then wait for them to timeout a number of * times. */ XIOModule_Timer_Start(IOModuleInstancePtr, Timer); } while (1) { int TotalExpiredCount = 0; /* * Wait for the Programmable Interval Timers to expire as indicated by * the shared variable which the handler will increment, and stop each * timer when it has reached the expected number of times. */ for (Timer = 0; Timer < XTC_DEVICE_TIMER_COUNT; Timer++) { if (TimerExpired[Timer] >= MAX_INTR_COUNT) XIOModule_Timer_Stop(IOModuleInstancePtr, Timer); TotalExpiredCount += TimerExpired[Timer]; } /* * If all timers have expired the expected number of times, then stop * this example. */ if (TotalExpiredCount == MAX_INTR_COUNT * XTC_DEVICE_TIMER_COUNT) { break; } } IOModuleDisableIntr(IOModuleInstancePtr); return XST_SUCCESS; }