XilinxProcessorIPLib/drivers/rfdc/examples/xrfdc_intr_example.c
int RFdcFabricRateExample(u16 RFdcDeviceId)
{
	int Status;
	u16 Tile = 0U;
	u16 Block = 0U;
	XRFdc_Config *ConfigPtr;
	XRFdc *RFdcInstPtr = &RFdcInst;
	u32 SetFabricRate;
	u32 GetFabricRate;
	int ret = 0;
	InterruptOccured = 0;
#ifndef __BAREMETAL__
	struct metal_device metal_dev_stim;
	struct metal_device metal_dev_cap;
	int irq;
#else
	int irq = RFDC_IRQ_VECT_ID;
#endif

	struct metal_init_params init_param = METAL_INIT_DEFAULTS;

	if (metal_init(&init_param)) {
		printf("ERROR: Failed to run metal initialization\r\n");
		return XRFDC_FAILURE;
	}

	/* Initialize the RFdc driver. */
	ConfigPtr = XRFdc_LookupConfig(RFdcDeviceId);
	if (ConfigPtr == NULL) {
		return XRFDC_FAILURE;
	}
#ifdef __BAREMETAL__
	deviceptr = &metal_dev_rfdc;
#endif
	Status = XRFdc_RegisterMetal(RFdcInstPtr, RFdcDeviceId, &deviceptr);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}

	Status = XRFdc_CfgInitialize(RFdcInstPtr, ConfigPtr);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}

#ifdef XPS_BOARD_ZCU111
printf("\n Configuring the Clock \r\n");
	LMK04208ClockConfig(I2CBUS, LMK04208_CKin);
	LMX2594ClockConfig(I2CBUS, 3932160);
#endif

	/*
	 * Setup the handler for the RFdc that will be called from the
	 * interrupt context when an RFdc interrupt occurs, specify a pointer to
	 * the RFdc driver instance as the callback reference so the handler is
	 * able to access the instance data
	 */
	XRFdc_SetStatusHandler(RFdcInstPtr, RFdcInstPtr,
				 (XRFdc_StatusHandler) RFdcHandler);

	Status = XRFdc_IntrEnable(RFdcInstPtr, XRFDC_ADC_TILE, Tile, Block,
						XRFDC_IXR_FIFOUSRDAT_MASK);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}

	GetFabricRate = 0;
	SetFabricRate = 0x1;
	Status = XRFdc_SetFabRdVldWords(RFdcInstPtr, Tile, Block,
					SetFabricRate);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}
	Status = XRFdc_GetFabRdVldWords(RFdcInstPtr, XRFDC_ADC_TILE, Tile, Block,
					&GetFabricRate);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}
	Status = CompareFabricRate(SetFabricRate, GetFabricRate);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}

	/* Get interrupt ID from RFDC metal device */
	irq = (intptr_t)RFdcInstPtr->device->irq_info;
	if (irq < 0) {
		printf("ERROR: Failed to request interrupt for %s.\r\n",
			  RFdcInstPtr->device->name);
		return XRFDC_FAILURE;
	}

#ifdef __BAREMETAL__
	ret = metal_xlnx_irq_init();
	if (ret) {
		printf("\n failed to initialise interrupt handler \r\n");
	}

   ret = metal_register_generic_device(&metal_dev_stim);
   if (ret) {
      printf("\n failed to register stim block \r\n");
   } else {
      printf("registered stim block.\r\n");
   }

   ret = metal_register_generic_device(&metal_dev_cap);
   if (ret) {
      printf("\n failed to register cap block \r\n");
   } else {
      printf("registered cap block.\r\n");
   }
#endif
	ret =  metal_irq_register(irq,
				(metal_irq_handler)XRFdc_IntrHandler,
						RFdcInstPtr);
	if (ret) {
		printf("\n failed to register interrupt handler \r\n");
	} else {
		printf("registered IPI interrupt.\r\n");
	}

	metal_irq_enable(irq);

	device_stim = &metal_dev_stim;
	ret = metal_device_open(BUS_NAME, STIM_DEV_NAME, &device_stim);
	if (ret) {
		printf("ERROR: Failed to open device stimulus_gen_axi_s.\r\n");
		return XRFDC_FAILURE;
	}

	/* Map Stimulus device IO region */
	io_stim = metal_device_io_region(device_stim, 0);
	if (!io_stim) {
		printf("ERROR: Failed to map Stimulus regio for %s.\r\n",
			  device_stim->name);
		return XRFDC_FAILURE;
	}

	device_cap = &metal_dev_cap;
	ret = metal_device_open(BUS_NAME, CAP_DEV_NAME, &device_cap);
	if (ret) {
		printf("ERROR: Failed to open device data_capture_axi_s.\r\n");
		return XRFDC_FAILURE;
	}

	/* Map Data Capture device IO region */
	io_cap = metal_device_io_region(device_cap, 0);
	if (!io_cap) {
		printf("ERROR: Failed to map Capture regio for %s.\r\n",
			  device_cap->name);
		return XRFDC_FAILURE;
	}

	/*
	 * Below writes are not generic, they are design specific.
	 * This may not be expected to work as it is with user specific design.
	 * These register writes are related to Stimulus and Capture blocks
	 * which will be used to generate some random data and Capture the
	 * output data respectively.
	 * Following register writes will be used for Configuring
	 * to start FIFO on DAC/Stim gen and ADC/Capture
	 */
	XRFdc_Out32(io_stim, 0x50, 0x8000);
	XRFdc_Out32(io_cap, 0x50, 0x8000);

#ifdef __BAREMETAL__
	if (init_irq()) {
		xil_printf("Failed to initialize interrupt\r\n");
	}
#endif

	printf("Waiting for Interrupt\r\n");
	/* Wait till interrupt occurs */
	while (InterruptOccured == 0);

	return XRFDC_SUCCESS;
}
/****************************************************************************/
/**
*
* This function runs a test on the RFSoC data converter device using the
* driver APIs.
* This function does the following tasks:
*	- Initialize the RFdc device driver instance
*	- Set the Fabric Rate.
*	- Get the Fabric Rate.
*	- Compare Set and Get Rates
*
* @param	RFdcDeviceId is the XPAR_<XRFDC_instance>_DEVICE_ID value
*		from xparameters.h.
*
* @return
*		- XRFDC_SUCCESS if the example has completed successfully.
*		- XRFDC_FAILURE if the example has failed.
*
* @note   	None
*
****************************************************************************/
This function runs a test on the RFSoC data converter device using the
driver APIs.
This function does the following tasks:
Initialize the RFdc device driver instance
Set the Fabric Rate.
Get the Fabric Rate.
Compare Set and Get Rates
This function runs a test on the RFSoC data converter device using the driver APIs . This function does the following tasks : Initialize the RFdc device driver instance Set the Fabric Rate . Get the Fabric Rate . Compare Set and Get Rates
int RFdcFabricRateExample(u16 RFdcDeviceId)
{
	int Status;
	u16 Tile = 0U;
	u16 Block = 0U;
	XRFdc_Config *ConfigPtr;
	XRFdc *RFdcInstPtr = &RFdcInst;
	u32 SetFabricRate;
	u32 GetFabricRate;
	int ret = 0;
	InterruptOccured = 0;
#ifndef __BAREMETAL__
	struct metal_device metal_dev_stim;
	struct metal_device metal_dev_cap;
	int irq;
#else
	int irq = RFDC_IRQ_VECT_ID;
#endif
	struct metal_init_params init_param = METAL_INIT_DEFAULTS;
	if (metal_init(&init_param)) {
		printf("ERROR: Failed to run metal initialization\r\n");
		return XRFDC_FAILURE;
	}
	ConfigPtr = XRFdc_LookupConfig(RFdcDeviceId);
	if (ConfigPtr == NULL) {
		return XRFDC_FAILURE;
	}
#ifdef __BAREMETAL__
	deviceptr = &metal_dev_rfdc;
#endif
	Status = XRFdc_RegisterMetal(RFdcInstPtr, RFdcDeviceId, &deviceptr);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}
	Status = XRFdc_CfgInitialize(RFdcInstPtr, ConfigPtr);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}
#ifdef XPS_BOARD_ZCU111
printf("\n Configuring the Clock \r\n");
	LMK04208ClockConfig(I2CBUS, LMK04208_CKin);
	LMX2594ClockConfig(I2CBUS, 3932160);
#endif
	XRFdc_SetStatusHandler(RFdcInstPtr, RFdcInstPtr,
				 (XRFdc_StatusHandler) RFdcHandler);
	Status = XRFdc_IntrEnable(RFdcInstPtr, XRFDC_ADC_TILE, Tile, Block,
						XRFDC_IXR_FIFOUSRDAT_MASK);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}
	GetFabricRate = 0;
	SetFabricRate = 0x1;
	Status = XRFdc_SetFabRdVldWords(RFdcInstPtr, Tile, Block,
					SetFabricRate);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}
	Status = XRFdc_GetFabRdVldWords(RFdcInstPtr, XRFDC_ADC_TILE, Tile, Block,
					&GetFabricRate);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}
	Status = CompareFabricRate(SetFabricRate, GetFabricRate);
	if (Status != XRFDC_SUCCESS) {
		return XRFDC_FAILURE;
	}
	irq = (intptr_t)RFdcInstPtr->device->irq_info;
	if (irq < 0) {
		printf("ERROR: Failed to request interrupt for %s.\r\n",
			  RFdcInstPtr->device->name);
		return XRFDC_FAILURE;
	}
#ifdef __BAREMETAL__
	ret = metal_xlnx_irq_init();
	if (ret) {
		printf("\n failed to initialise interrupt handler \r\n");
	}
   ret = metal_register_generic_device(&metal_dev_stim);
   if (ret) {
      printf("\n failed to register stim block \r\n");
   } else {
      printf("registered stim block.\r\n");
   }
   ret = metal_register_generic_device(&metal_dev_cap);
   if (ret) {
      printf("\n failed to register cap block \r\n");
   } else {
      printf("registered cap block.\r\n");
   }
#endif
	ret =  metal_irq_register(irq,
				(metal_irq_handler)XRFdc_IntrHandler,
						RFdcInstPtr);
	if (ret) {
		printf("\n failed to register interrupt handler \r\n");
	} else {
		printf("registered IPI interrupt.\r\n");
	}
	metal_irq_enable(irq);
	device_stim = &metal_dev_stim;
	ret = metal_device_open(BUS_NAME, STIM_DEV_NAME, &device_stim);
	if (ret) {
		printf("ERROR: Failed to open device stimulus_gen_axi_s.\r\n");
		return XRFDC_FAILURE;
	}
	io_stim = metal_device_io_region(device_stim, 0);
	if (!io_stim) {
		printf("ERROR: Failed to map Stimulus regio for %s.\r\n",
			  device_stim->name);
		return XRFDC_FAILURE;
	}
	device_cap = &metal_dev_cap;
	ret = metal_device_open(BUS_NAME, CAP_DEV_NAME, &device_cap);
	if (ret) {
		printf("ERROR: Failed to open device data_capture_axi_s.\r\n");
		return XRFDC_FAILURE;
	}
	io_cap = metal_device_io_region(device_cap, 0);
	if (!io_cap) {
		printf("ERROR: Failed to map Capture regio for %s.\r\n",
			  device_cap->name);
		return XRFDC_FAILURE;
	}
	XRFdc_Out32(io_stim, 0x50, 0x8000);
	XRFdc_Out32(io_cap, 0x50, 0x8000);
#ifdef __BAREMETAL__
	if (init_irq()) {
		xil_printf("Failed to initialize interrupt\r\n");
	}
#endif
	printf("Waiting for Interrupt\r\n");
	while (InterruptOccured == 0);
	return XRFDC_SUCCESS;
}
int RFdcFabricRateExample ( u16 RFdcDeviceId ) { int Status ; u16 Tile = 0U ; u16 Block = 0U ; XRFdc_Config * ConfigPtr ; XRFdc * RFdcInstPtr = & RFdcInst ; u32 SetFabricRate ; u32 GetFabricRate ; int ret = 0 ; InterruptOccured = 0 ; #ifndef __BAREMETAL__ struct metal_device metal_dev_stim ; struct metal_device metal_dev_cap ; int irq ; #else int irq = RFDC_IRQ_VECT_ID ; #endif struct metal_init_params init_param = METAL_INIT_DEFAULTS ; if ( metal_init ( & init_param ) ) { printf ( " \r \n " ) ; return XRFDC_FAILURE ; } ConfigPtr = XRFdc_LookupConfig ( RFdcDeviceId ) ; if ( ConfigPtr == NULL ) { return XRFDC_FAILURE ; } #ifdef __BAREMETAL__ deviceptr = & metal_dev_rfdc ; #endif Status = XRFdc_RegisterMetal ( RFdcInstPtr , RFdcDeviceId , & deviceptr ) ; if ( Status != XRFDC_SUCCESS ) { return XRFDC_FAILURE ; } Status = XRFdc_CfgInitialize ( RFdcInstPtr , ConfigPtr ) ; if ( Status != XRFDC_SUCCESS ) { return XRFDC_FAILURE ; } #ifdef XPS_BOARD_ZCU111 printf ( " \n \r \n " ) ; LMK04208ClockConfig ( I2CBUS , LMK04208_CKin ) ; LMX2594ClockConfig ( I2CBUS , 3932160 ) ; #endif XRFdc_SetStatusHandler ( RFdcInstPtr , RFdcInstPtr , ( XRFdc_StatusHandler ) RFdcHandler ) ; Status = XRFdc_IntrEnable ( RFdcInstPtr , XRFDC_ADC_TILE , Tile , Block , XRFDC_IXR_FIFOUSRDAT_MASK ) ; if ( Status != XRFDC_SUCCESS ) { return XRFDC_FAILURE ; } GetFabricRate = 0 ; SetFabricRate = 0x1 ; Status = XRFdc_SetFabRdVldWords ( RFdcInstPtr , Tile , Block , SetFabricRate ) ; if ( Status != XRFDC_SUCCESS ) { return XRFDC_FAILURE ; } Status = XRFdc_GetFabRdVldWords ( RFdcInstPtr , XRFDC_ADC_TILE , Tile , Block , & GetFabricRate ) ; if ( Status != XRFDC_SUCCESS ) { return XRFDC_FAILURE ; } Status = CompareFabricRate ( SetFabricRate , GetFabricRate ) ; if ( Status != XRFDC_SUCCESS ) { return XRFDC_FAILURE ; } irq = ( intptr_t ) RFdcInstPtr -> device -> irq_info ; if ( irq < 0 ) { printf ( " \r \n " , RFdcInstPtr -> device -> name ) ; return XRFDC_FAILURE ; } #ifdef __BAREMETAL__ ret = metal_xlnx_irq_init ( ) ; if ( ret ) { printf ( " \n \r \n " ) ; } ret = metal_register_generic_device ( & metal_dev_stim ) ; if ( ret ) { printf ( " \n \r \n " ) ; } else { printf ( " \r \n " ) ; } ret = metal_register_generic_device ( & metal_dev_cap ) ; if ( ret ) { printf ( " \n \r \n " ) ; } else { printf ( " \r \n " ) ; } #endif ret = metal_irq_register ( irq , ( metal_irq_handler ) XRFdc_IntrHandler , RFdcInstPtr ) ; if ( ret ) { printf ( " \n \r \n " ) ; } else { printf ( " \r \n " ) ; } metal_irq_enable ( irq ) ; device_stim = & metal_dev_stim ; ret = metal_device_open ( BUS_NAME , STIM_DEV_NAME , & device_stim ) ; if ( ret ) { printf ( " \r \n " ) ; return XRFDC_FAILURE ; } io_stim = metal_device_io_region ( device_stim , 0 ) ; if ( ! io_stim ) { printf ( " \r \n " , device_stim -> name ) ; return XRFDC_FAILURE ; } device_cap = & metal_dev_cap ; ret = metal_device_open ( BUS_NAME , CAP_DEV_NAME , & device_cap ) ; if ( ret ) { printf ( " \r \n " ) ; return XRFDC_FAILURE ; } io_cap = metal_device_io_region ( device_cap , 0 ) ; if ( ! io_cap ) { printf ( " \r \n " , device_cap -> name ) ; return XRFDC_FAILURE ; } XRFdc_Out32 ( io_stim , 0x50 , 0x8000 ) ; XRFdc_Out32 ( io_cap , 0x50 , 0x8000 ) ; #ifdef __BAREMETAL__ if ( init_irq ( ) ) { xil_printf ( " \r \n " ) ; } #endif printf ( " \r \n " ) ; while ( InterruptOccured == 0 ) ; return XRFDC_SUCCESS ; }
This function runs a test on the RFSoC data converter device using the
driver APIs.
This function runs a test on the RFSoC data converter device using the driver APIs .
/* Initialize the RFdc driver. */ /*
	 * Setup the handler for the RFdc that will be called from the
	 * interrupt context when an RFdc interrupt occurs, specify a pointer to
	 * the RFdc driver instance as the callback reference so the handler is
	 * able to access the instance data
	 */ /* Get interrupt ID from RFDC metal device */ /* Map Stimulus device IO region */ /* Map Data Capture device IO region */ /*
	 * Below writes are not generic, they are design specific.
	 * This may not be expected to work as it is with user specific design.
	 * These register writes are related to Stimulus and Capture blocks
	 * which will be used to generate some random data and Capture the
	 * output data respectively.
	 * Following register writes will be used for Configuring
	 * to start FIFO on DAC/Stim gen and ADC/Capture
	 */ /* Wait till interrupt occurs */