scugic
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Macros Groups Pages
xscugic_example.c File Reference

Overview

This file contains a design example using the Interrupt Controller driver (XScuGic) and hardware device.

Please reference other device driver examples to see more examples of how the intc and interrupts can be used by a software application.

MODIFICATION HISTORY:
Ver   Who  Date     Changes


1.00a drg 01/18/10 First release 5.0 mus 04/04/22 Updated example to support it on any CPU instance, for which example is compiled. It fixes CR#1126331. 5.0 adk 04/18/22 Replace infinite while loop with Xil_WaitForEventSet() API. adk 30/05/22 Fix typecast of the variable InterruptProcessed. adk 20/07/22 Update the Xil_WaitForEventSet() API arguments as per latest API. 5.1 mus 02/13/23 Support example for each core of APU/RPU clusters in VERSAL_NET SoC. 5.2 mus 07/27/23 Removed dependency on XPAR_CPU_ID. 5.2 ml 02/21/24 Fix compilation error reported by C++ compiler. 5.2 mus 04/13/24 Use interrupt wrapper APIs in case of SDT flow. 5.5 ml 02/05/25 Fixed compilation warnings and errors 5.6 ml 07/21/25 Fixed GCC warnings. 5.7 bdk 12/08/25 Updated comments to support SDT flow for Doxygen documentation. 5.7 ml 03/03/26 Extend PPI timer test to all supported platforms (GICv1/v2/v3) 5.7 asa 03/13/26 To fix logical issue in the API XScuGic_SoftwareIntr changes were made with regards to CPU ID and Cluster ID handling for Cortex-R52. These changes needed a change in the example for Cortex-R52 Software Interrupt handling.

#include <stdio.h>
#include <stdlib.h>
#include "xil_io.h"
#include "xil_exception.h"
#include "xparameters.h"
#include "xil_cache.h"
#include "xil_printf.h"
#include "xil_types.h"
#include "xscugic.h"
#include "xil_util.h"
#include "xinterrupt_wrap.h"
#include "xplatform_info.h"

Macros

#define XSCUGiC_DIST_BASEADDR   XPAR_XSCUGIC_0_BASEADDR
 Base address of the GIC distributor. More...
 
#define INTC_DEVICE_INT_ID   0x0E
 Interrupt ID used in this example. More...
 
#define XSCUGIC_SPI_CPU_MASK   (XSCUGIC_SPI_CPU0_MASK << XPAR_CPU_ID)
 CPU target mask for SPI interrupts. More...
 
#define XSCUGIC_SW_TIMEOUT_VAL   10000000U
 Software timeout value in clock cycles. More...
 

Functions

int ScuGicExample (void)
 Demonstrates XScuGic driver and hardware device operation. More...
 
int SetUpInterruptSystem (XScuGic *XScuGicInstancePtr)
 This function connects the interrupt handler of the interrupt controller to the processor. More...
 
void DeviceDriverHandler (void *CallbackRef)
 Simulates a device driver interrupt handler for the example. More...
 
int main (void)
 This is the main function for the Interrupt Controller example. More...
 

Variables

XScuGic InterruptController
 Instance of the Interrupt Controller. More...
 

Macro Definition Documentation

#define INTC_DEVICE_INT_ID   0x0E

Interrupt ID used in this example.

Referenced by ScuGicExample().

#define XSCUGiC_DIST_BASEADDR   XPAR_XSCUGIC_0_BASEADDR

Base address of the GIC distributor.

#define XSCUGIC_SPI_CPU_MASK   (XSCUGIC_SPI_CPU0_MASK << XPAR_CPU_ID)

CPU target mask for SPI interrupts.

#define XSCUGIC_SW_TIMEOUT_VAL   10000000U

Software timeout value in clock cycles.

Referenced by ScuGicExample().

Function Documentation

void DeviceDriverHandler ( void *  CallbackRef)

Simulates a device driver interrupt handler for the example.

This is typically a 2nd level handler that is called from the interrupt controller interrupt handler. This handler would typically perform device specific processing such as reading and writing the registers of the device to clear the interrupt condition and pass any data to an application using the device driver. Many drivers already provide this handler and the user is not required to create it.

Parameters
[in]CallbackRefis passed back to the device driver's interrupt handler by the XScuGic driver. It was given to the XScuGic driver in the XScuGic_Connect() function call. It is typically a pointer to the device driver instance variable. In this example, we do not care about the callback reference, so we passed it a 0 when connecting the handler to the XScuGic driver and we make no use of it here.

Referenced by ScuGicExample().

int main ( void  )

This is the main function for the Interrupt Controller example.

Returns
XST_SUCCESS to indicate success, otherwise XST_FAILURE.

References ScuGicExample().

int ScuGicExample ( void  )

Demonstrates XScuGic driver and hardware device operation.

This function is designed to work without any hardware devices to cause interrupts. It may not return if the interrupt controller is not properly connected to the processor in either software or hardware. This function relies on the fact that the interrupt controller hardware has come out of the reset state such that it will allow interrupts to be simulated by the software.

Returns
XST_SUCCESS to indicate success, otherwise XST_FAILURE
Note
In XSCT/classic flow, DeviceId is used to look up the device configuration.

References XScuGic_Config::CpuBaseAddress, DeviceDriverHandler(), INTC_DEVICE_INT_ID, SetUpInterruptSystem(), XScuGic_CfgInitialize(), XScuGic_Connect(), XScuGic_Enable(), XScuGic_LookupConfig(), XScuGic_SelfTest(), XScuGic_SoftwareIntr(), XSCUGIC_SPI_CPU0_MASK, and XSCUGIC_SW_TIMEOUT_VAL.

Referenced by main().

int SetUpInterruptSystem ( XScuGic *  XScuGicInstancePtr)

This function connects the interrupt handler of the interrupt controller to the processor.

This function is separate to allow it to be customized for each application. Each processor or RTOS may require unique processing to connect the interrupt handler.

Parameters
[in]XScuGicInstancePtris the instance of the interrupt controller that needs to be worked on.
Returns
XST_SUCCESS if successful, otherwise XST_FAILURE.

References XScuGic_InterruptHandler().

Referenced by ScuGicExample().

Variable Documentation

XScuGic InterruptController

Instance of the Interrupt Controller.