XilinxProcessorIPLib/drivers/xadcps/examples/xadcps_intr_example.c
int XAdcIntrExample(XScuGic *IntcInstancePtr, XAdcPs *XAdcInstPtr,
			u16 XAdcDeviceId, u16 XAdcIntrId, int *Temp)
{
	int Status;
	XAdcPs_Config *ConfigPtr;
	u16 TempData;
	u16 VccpauxData;
	u32 IntrStatus;

	/*
	 * Initialize the XAdc driver.
	 */
	ConfigPtr = XAdcPs_LookupConfig(XAdcDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	XAdcPs_CfgInitialize(XAdcInstPtr, ConfigPtr, ConfigPtr->BaseAddress);

	/*
	 * Self Test the XADC/ADC device.
	 */
	Status = XAdcPs_SelfTest(XAdcInstPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Set XADC in default mode so that alarms are inactive
	 */
	XAdcPs_SetSequencerMode(XAdcInstPtr, XADCPS_SEQ_MODE_SAFE);

	/* Disable all alarms */
	XAdcPs_SetAlarmEnables(XAdcInstPtr,0x0000);

	/*
	 * Set up Alarm threshold registers for the on-chip temperature and
	 * VCCPAUX High limit and lower limit so that the alarms occur.
	 */
	TempData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_TEMP);
	XAdcPs_SetAlarmThreshold(XAdcInstPtr, XADCPS_ATR_TEMP_UPPER,(TempData-0x07FF));
	XAdcPs_SetAlarmThreshold(XAdcInstPtr, XADCPS_ATR_TEMP_LOWER,(TempData+0x07FF));

	VccpauxData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCPAUX);
	XAdcPs_SetAlarmThreshold(XAdcInstPtr, XADCPS_ATR_VCCPAUX_UPPER,(VccpauxData-0x07FF));
	XAdcPs_SetAlarmThreshold(XAdcInstPtr, XADCPS_ATR_VCCPAUX_LOWER,(VccpauxData+0x07FF));

	/*
	 * Setup the interrupt system.
	 */
	Status = XAdcSetupInterruptSystem(IntcInstancePtr,
					    XAdcInstPtr,
					    XAdcIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Clear any bits set in the Interrupt Status Register.
	 */
	IntrStatus = XAdcPs_IntrGetStatus(XAdcInstPtr);
	XAdcPs_IntrClear(XAdcInstPtr, IntrStatus);


	/*
	 * Enable Alarm 0 interrupt for on-chip temperature and Alarm 5
	 * interrupt for on-chip VCCPAUX.
	 */
	XAdcPs_IntrEnable(XAdcInstPtr,
			(XADCPS_INTX_ALM5_MASK | XADCPS_INTX_ALM0_MASK));

	/*
	 * Enable Alarm 0 for on-chip temperature and Alarm 5 for on-chip
	 * VCCPAUX in the Configuration Register 1.
	 */
	XAdcPs_SetAlarmEnables(XAdcInstPtr, (XADCPS_CFR1_ALM_VCCPAUX_MASK
											| XADCPS_CFR1_ALM_TEMP_MASK));


	XAdcPs_SetSequencerMode(XAdcInstPtr, XADCPS_SEQ_MODE_INDEPENDENT);


	/*
	 * Wait until an Alarm 0 or Alarm 2 interrupt occurs.
	 */
	while (1) {
		if (TemperatureIntr == TRUE) {
			/*
			 * Alarm 0 - Temperature alarm interrupt has occurred.
			 * The required processing should be put here.
			 */
			break;
		}
		if (VccpauxIntr == TRUE) {
					/*
					 * Alarm 5 - VccPAUX alarm interrupt has occurred.
					 * The required processing should be put here.
					 */
					break;
		}

	}


	/* Set back the ADC in default mode */

	XAdcPs_SetSequencerMode(XAdcInstPtr, XADCPS_SEQ_MODE_SAFE);

	return XST_SUCCESS;
}
/****************************************************************************/
/**
*
* This function runs a test on the XADC/ADC device using the
* driver APIs.
*
* The function does the following tasks:
*	- Initiate the XADC/ADC device driver instance
*	- Run self-test on the device
*	- Reset the device
*	- Set up alarms for on-chip temperature and VCCPAUX
*	- Set up sequence registers to continuously monitor on-chip temperature
*	and VCCPAUX
*	- Setup interrupt system
*	- Enable interrupts
*	- Set up configuration registers to start the sequence
*	- Wait until temperature alarm interrupt or VCCPAUX alarm interrupt
*	occurs
*
* @param	IntcInstancePtr is a pointer to the Interrupt Controller
*		driver Instance.
* @param	XAdcInstPtr is a pointer to the XAdcPs driver Instance.
* @param	XAdcDeviceId is the XPAR_<SYSMON_ADC_instance>_DEVICE_ID value
*		from xparameters.h.
* @param	XAdcIntrId is
*		XPAR_<INTC_instance>_<SYSMON_ADC_instance>_VEC_ID value from
*		xparameters.h
* @param	Temp is an output parameter, it is a pointer through which the
*		current temperature value is returned to the main function.
*
* @return
*		- XST_SUCCESS if the example has completed successfully.
*		- XST_FAILURE if the example has failed.
*
* @note		This function may never return if no interrupt occurs.
*
****************************************************************************/
This function runs a test on the XADC/ADC device using the
driver APIs.

The function does the following tasks:
Initiate the XADC/ADC device driver instance
Run self-test on the device
Reset the device
Set up alarms for on-chip temperature and VCCPAUX
Set up sequence registers to continuously monitor on-chip temperature
and VCCPAUX
Setup interrupt system
Enable interrupts
Set up configuration registers to start the sequence
Wait until temperature alarm interrupt or VCCPAUX alarm interrupt
occurs
This function runs a test on the XADC / ADC device using the driver APIs . The function does the following tasks : Initiate the XADC / ADC device driver instance Run self - test on the device Reset the device Set up alarms for on - chip temperature and VCCPAUX Set up sequence registers to continuously monitor on - chip temperature and VCCPAUX Setup interrupt system Enable interrupts Set up configuration registers to start the sequence Wait until temperature alarm interrupt or VCCPAUX alarm interrupt occurs
int XAdcIntrExample(XScuGic *IntcInstancePtr, XAdcPs *XAdcInstPtr,
			u16 XAdcDeviceId, u16 XAdcIntrId, int *Temp)
{
	int Status;
	XAdcPs_Config *ConfigPtr;
	u16 TempData;
	u16 VccpauxData;
	u32 IntrStatus;
	ConfigPtr = XAdcPs_LookupConfig(XAdcDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	XAdcPs_CfgInitialize(XAdcInstPtr, ConfigPtr, ConfigPtr->BaseAddress);
	Status = XAdcPs_SelfTest(XAdcInstPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XAdcPs_SetSequencerMode(XAdcInstPtr, XADCPS_SEQ_MODE_SAFE);
	XAdcPs_SetAlarmEnables(XAdcInstPtr,0x0000);
	TempData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_TEMP);
	XAdcPs_SetAlarmThreshold(XAdcInstPtr, XADCPS_ATR_TEMP_UPPER,(TempData-0x07FF));
	XAdcPs_SetAlarmThreshold(XAdcInstPtr, XADCPS_ATR_TEMP_LOWER,(TempData+0x07FF));
	VccpauxData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCPAUX);
	XAdcPs_SetAlarmThreshold(XAdcInstPtr, XADCPS_ATR_VCCPAUX_UPPER,(VccpauxData-0x07FF));
	XAdcPs_SetAlarmThreshold(XAdcInstPtr, XADCPS_ATR_VCCPAUX_LOWER,(VccpauxData+0x07FF));
	Status = XAdcSetupInterruptSystem(IntcInstancePtr,
					    XAdcInstPtr,
					    XAdcIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	IntrStatus = XAdcPs_IntrGetStatus(XAdcInstPtr);
	XAdcPs_IntrClear(XAdcInstPtr, IntrStatus);
	XAdcPs_IntrEnable(XAdcInstPtr,
			(XADCPS_INTX_ALM5_MASK | XADCPS_INTX_ALM0_MASK));
	XAdcPs_SetAlarmEnables(XAdcInstPtr, (XADCPS_CFR1_ALM_VCCPAUX_MASK
											| XADCPS_CFR1_ALM_TEMP_MASK));
	XAdcPs_SetSequencerMode(XAdcInstPtr, XADCPS_SEQ_MODE_INDEPENDENT);
	while (1) {
		if (TemperatureIntr == TRUE) {
			break;
		}
		if (VccpauxIntr == TRUE) {
					break;
		}
	}
	XAdcPs_SetSequencerMode(XAdcInstPtr, XADCPS_SEQ_MODE_SAFE);
	return XST_SUCCESS;
}
int XAdcIntrExample ( XScuGic * IntcInstancePtr , XAdcPs * XAdcInstPtr , u16 XAdcDeviceId , u16 XAdcIntrId , int * Temp ) { int Status ; XAdcPs_Config * ConfigPtr ; u16 TempData ; u16 VccpauxData ; u32 IntrStatus ; ConfigPtr = XAdcPs_LookupConfig ( XAdcDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } XAdcPs_CfgInitialize ( XAdcInstPtr , ConfigPtr , ConfigPtr -> BaseAddress ) ; Status = XAdcPs_SelfTest ( XAdcInstPtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XAdcPs_SetSequencerMode ( XAdcInstPtr , XADCPS_SEQ_MODE_SAFE ) ; XAdcPs_SetAlarmEnables ( XAdcInstPtr , 0x0000 ) ; TempData = XAdcPs_GetAdcData ( XAdcInstPtr , XADCPS_CH_TEMP ) ; XAdcPs_SetAlarmThreshold ( XAdcInstPtr , XADCPS_ATR_TEMP_UPPER , ( TempData - 0x07FF ) ) ; XAdcPs_SetAlarmThreshold ( XAdcInstPtr , XADCPS_ATR_TEMP_LOWER , ( TempData + 0x07FF ) ) ; VccpauxData = XAdcPs_GetAdcData ( XAdcInstPtr , XADCPS_CH_VCCPAUX ) ; XAdcPs_SetAlarmThreshold ( XAdcInstPtr , XADCPS_ATR_VCCPAUX_UPPER , ( VccpauxData - 0x07FF ) ) ; XAdcPs_SetAlarmThreshold ( XAdcInstPtr , XADCPS_ATR_VCCPAUX_LOWER , ( VccpauxData + 0x07FF ) ) ; Status = XAdcSetupInterruptSystem ( IntcInstancePtr , XAdcInstPtr , XAdcIntrId ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } IntrStatus = XAdcPs_IntrGetStatus ( XAdcInstPtr ) ; XAdcPs_IntrClear ( XAdcInstPtr , IntrStatus ) ; XAdcPs_IntrEnable ( XAdcInstPtr , ( XADCPS_INTX_ALM5_MASK | XADCPS_INTX_ALM0_MASK ) ) ; XAdcPs_SetAlarmEnables ( XAdcInstPtr , ( XADCPS_CFR1_ALM_VCCPAUX_MASK | XADCPS_CFR1_ALM_TEMP_MASK ) ) ; XAdcPs_SetSequencerMode ( XAdcInstPtr , XADCPS_SEQ_MODE_INDEPENDENT ) ; while ( 1 ) { if ( TemperatureIntr == TRUE ) { break ; } if ( VccpauxIntr == TRUE ) { break ; } } XAdcPs_SetSequencerMode ( XAdcInstPtr , XADCPS_SEQ_MODE_SAFE ) ; return XST_SUCCESS ; }
This function runs a test on the XADC/ADC device using the
driver APIs.
This function runs a test on the XADC / ADC device using the driver APIs .
/*
	 * Initialize the XAdc driver.
	 */ /*
	 * Self Test the XADC/ADC device.
	 */ /*
	 * Set XADC in default mode so that alarms are inactive
	 */ /* Disable all alarms */ /*
	 * Set up Alarm threshold registers for the on-chip temperature and
	 * VCCPAUX High limit and lower limit so that the alarms occur.
	 */ /*
	 * Setup the interrupt system.
	 */ /*
	 * Clear any bits set in the Interrupt Status Register.
	 */ /*
	 * Enable Alarm 0 interrupt for on-chip temperature and Alarm 5
	 * interrupt for on-chip VCCPAUX.
	 */ /*
	 * Enable Alarm 0 for on-chip temperature and Alarm 5 for on-chip
	 * VCCPAUX in the Configuration Register 1.
	 */ /*
	 * Wait until an Alarm 0 or Alarm 2 interrupt occurs.
	 */ /*
			 * Alarm 0 - Temperature alarm interrupt has occurred.
			 * The required processing should be put here.
			 */ /*
					 * Alarm 5 - VccPAUX alarm interrupt has occurred.
					 * The required processing should be put here.
					 */ /* Set back the ADC in default mode */