iomodule
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
xiomodule_intr_example.c File Reference

Overview

This file contains a design example using the IO Module driver (XIOModule) and hardware device using interrupt mode.This example tests the internal interrupts in the IO Module.

This file can be used as a standalone example or by the TestAppGen utility to include a test of IOModule interrupts.

Note

None

MODIFICATION HISTORY:
Ver   Who  Date     Changes


1.00a sa 07/15/11 First release 2.4 ms 01/23/17 Added xil_printf statement in main function to ensure that "Successfully ran" and "Failed" strings are available in all examples. This is a fix for CR-965028. 2.16 ml 12/07/23 Make TimerExpired as a static variable. 2.19 ml 04/18/25 Added support for system device-tree flow.

#include "xparameters.h"
#include "xstatus.h"
#include "xiomodule.h"
#include "xil_exception.h"
#include "xil_printf.h"

Macros

#define IOMODULE_DEVICE_ID   XPAR_IOMODULE_0_BASEADDR
 Device base address for SDT build. More...
 
#define MAX_INTR_COUNT   3
 Maximum interrupt count before timer is stopped. More...
 
#define MIN_TIMER_BITS   8
 Minimum number of timer bits for the example. More...
 
#define RESET_VALUE   ((1 << MIN_TIMER_BITS) - 1)
 Timer reset value derived from MIN_TIMER_BITS. More...
 

Functions

XStatus IOModuleIntrExample (XIOModule *IOModuleInstancePtr, u32 DeviceId)
 This function does a minimal test on the IO Module device and driver as a design example. More...
 
void IOModuleHandler (void *CallBackRef, u8 Timer)
 This function is the handler which performs processing for the IO module. More...
 
void IOModuleSetupIntrSystem (void)
 This function initializes and enables exception handling for interrupts in the processor. More...
 
void IOModuleDisableIntr (XIOModule *IOModuleInstancePtr)
 This function disables the interrupts for the IO Module. More...
 
int main (void)
 This is the main function for the IO Module example. More...
 

Macro Definition Documentation

#define IOMODULE_DEVICE_ID   XPAR_IOMODULE_0_BASEADDR

Device base address for SDT build.

Referenced by main().

#define MAX_INTR_COUNT   3

Maximum interrupt count before timer is stopped.

Referenced by IOModuleHandler(), and IOModuleIntrExample().

#define MIN_TIMER_BITS   8

Minimum number of timer bits for the example.

Referenced by IOModuleIntrExample().

#define RESET_VALUE   ((1 << MIN_TIMER_BITS) - 1)

Timer reset value derived from MIN_TIMER_BITS.

Referenced by IOModuleIntrExample().

Function Documentation

void IOModuleDisableIntr ( XIOModule *  IOModuleInstancePtr)

This function disables the interrupts for the IO Module.

Parameters
[in]IOModuleInstancePtris a reference to the IO Module driver Instance.

References XIOModule_Disable().

Referenced by IOModuleIntrExample().

void IOModuleHandler ( void *  CallBackRef,
u8  Timer 
)

This function is the handler which performs processing for the IO module.

It is called from an interrupt context such that the amount of processing performed should be minimized. It is called when an interrupt occurs if interrupts are enabled.

This handler provides an example of how to handle Programmable Interval Timer interrupts but is application specific.

Parameters
[in]CallBackRefis a pointer to the callback function
[in]Timeris the number of the interrupt this handler is associated with.

References MAX_INTR_COUNT, XIOModule_IsExpired(), and XIOModule_Timer_SetOptions().

Referenced by IOModuleIntrExample().

XStatus IOModuleIntrExample ( XIOModule *  IOModuleInstancePtr,
u32  DeviceId 
)

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.

Parameters
[in]IOModuleInstancePtris a pointer to the IO Module driver Instance
[in]DeviceIdis the XPAR_<IOModule_instance>_DEVICE_ID value from xparameters.h
Returns
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.

References XIOModule::CfgPtr, IOModuleDisableIntr(), IOModuleHandler(), IOModuleSetupIntrSystem(), MAX_INTR_COUNT, MIN_TIMER_BITS, XIOModule_Config::PitPrescaler, XIOModule_Config::PitReadable, XIOModule_Config::PitSize, XIOModule_Config::PitUsed, RESET_VALUE, XIOModule_Enable(), XIOModule_Initialize(), XIOModule_SelfTest(), XIOModule_SetHandler(), XIOModule_SetResetValue(), XIOModule_Timer_SetOptions(), XIOModule_Timer_Start(), and XIOModule_Timer_Stop().

Referenced by main().

static void IOModuleSetupIntrSystem ( void  )

This function initializes and enables exception handling for interrupts in the processor.

References XIOModule_DeviceInterruptHandler().

Referenced by IOModuleInterruptSetup(), and IOModuleIntrExample().

int main ( void  )

This is the main function for the IO Module example.

This function is not included if the example is generated from the TestAppGen test tool.

Returns
XST_SUCCESS to indicate success, otherwise XST_FAILURE.

References IOMODULE_DEVICE_ID, and IOModuleIntrExample().