XilinxProcessorIPLib/drivers/sysmon/examples/xsysmon_intr_example.c
int SysMonIntrExample(INTC* IntcInstancePtr, XSysMon* SysMonInstPtr,
			u16 SysMonDeviceId, u16 SysMonIntrId, int *Temp)
{
	int Status;
	XSysMon_Config *ConfigPtr;
	u16 TempData;
	u16 VccauxData;
	u32 IntrStatus;

	/*
	 * Initialize the SysMon driver.
	 */
	ConfigPtr = XSysMon_LookupConfig(SysMonDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	XSysMon_CfgInitialize(SysMonInstPtr, ConfigPtr, ConfigPtr->BaseAddress);

	/*
	 * Self Test the System Monitor/ADC device.
	 */
	Status = XSysMon_SelfTest(SysMonInstPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Disable the Channel Sequencer before configuring the Sequence
	 * registers.
	 */
	XSysMon_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_SAFE);

	/*
	 * Setup the Averaging to be done for the channels in the
	 * Configuration 0 register as 16 samples:
	 */
	XSysMon_SetAvg(SysMonInstPtr, XSM_AVG_16_SAMPLES);

	/*
	 * Setup the Sequence register for 1st Auxiliary channel
	 * Setting is:
	 *	- Add acquisition time by 6 ADCCLK cycles.
	 *	- Bipolar Mode
	 *
	 * Setup the Sequence register for 16th Auxiliary channel
	 * Setting is:
	 *	- Add acquisition time by 6 ADCCLK cycles.
	 *	- Unipolar Mode
	 */
	Status = XSysMon_SetSeqInputMode(SysMonInstPtr, XSM_SEQ_CH_AUX00);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	Status = XSysMon_SetSeqAcqTime(SysMonInstPtr, XSM_SEQ_CH_AUX15 |
						XSM_SEQ_CH_AUX00);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable the averaging on the following channels in the Sequencer
	 * registers:
	 * 	- On-chip Temperature
	 * 	- On-chip VCCAUX supply sensor
	 * 	- 1st Auxiliary Channel
	 * 	- 16th Auxiliary Channel
	 */
	Status =  XSysMon_SetSeqAvgEnables(SysMonInstPtr, XSM_SEQ_CH_TEMP |
						XSM_SEQ_CH_VCCAUX |
						XSM_SEQ_CH_AUX00 |
						XSM_SEQ_CH_AUX15);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable the following channels in the Sequencer registers:
	 * 	- On-chip Temperature
	 * 	- On-chip VCCAUX supply sensor
	 * 	- 1st Auxiliary Channel
	 * 	- 16th Auxiliary Channel
	 */
	Status =  XSysMon_SetSeqChEnables(SysMonInstPtr, XSM_SEQ_CH_TEMP |
						XSM_SEQ_CH_VCCAUX |
						XSM_SEQ_CH_AUX00 |
						XSM_SEQ_CH_AUX15);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Set the ADCCLK frequency equal to 1/32 of System clock for the System
	 * Monitor/ADC in the Configuration Register 2.
	 */
	XSysMon_SetAdcClkDivisor(SysMonInstPtr, 32);


	/*
	 * Enable the Channel Sequencer in continuous sequencer cycling mode.
	 */
	XSysMon_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_CONTINPASS);

	/*
	 * Wait till the End of Sequence occurs
	 */
	XSysMon_GetStatus(SysMonInstPtr); /* Clear the old status */
	while ((XSysMon_GetStatus(SysMonInstPtr) & XSM_SR_EOS_MASK) !=
			XSM_SR_EOS_MASK);

	/*
	 * Read the ADC converted Data from the data registers for on-chip
	 * temperature and on-chip VCCAUX voltage.
	 */
	TempData = XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_TEMP);
	VccauxData = XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_VCCAUX);

	/*
	 * Convert the ADC data into temperature
	 */
	*Temp = XSysMon_RawToTemperature(TempData);

	/*
	 * Disable all the alarms in the Configuration Register 1.
	 */
	XSysMon_SetAlarmEnables(SysMonInstPtr, 0x0);


	/*
	 * Set up Alarm threshold registers for the on-chip temperature and
	 * VCCAUX High limit and lower limit so that the alarms DONOT occur.
	 */
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_TEMP_UPPER, 0xFFFF);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_TEMP_LOWER, 0xFFFF);

	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCAUX_UPPER, 0xFFFF);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCAUX_LOWER, 0x0);

	/*
	 * Setup the interrupt system.
	 */
	Status = SysMonSetupInterruptSystem(IntcInstancePtr,
					    SysMonInstPtr,
					    SysMonIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Clear any bits set in the Interrupt Status Register.
	 */
	IntrStatus = XSysMon_IntrGetStatus(SysMonInstPtr);
	XSysMon_IntrClear(SysMonInstPtr, IntrStatus);


	/*
	 * Enable Alarm 0 interrupt for on-chip temperature and Alarm 2
	 * interrupt for on-chip VCCAUX.
	 */
	XSysMon_IntrEnable(SysMonInstPtr,
				XSM_IPIXR_TEMP_MASK |
				XSM_IPIXR_VCCAUX_MASK);

	/*
	 * Enable global interrupt of System Monitor.
	 */
	XSysMon_IntrGlobalEnable(SysMonInstPtr);

	/*
	 * Set up Alarm threshold registers for
	 * On-chip Temperature High limit
	 * On-chip Temperature Low limit
	 * VCCAUX High limit
	 * VCCAUX Low limit
	 */
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_TEMP_UPPER,
						TempData - 0x007F);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_TEMP_LOWER,
						TempData - 0x007F);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCAUX_UPPER,
						VccauxData - 0x007F);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCAUX_LOWER,
						VccauxData + 0x007F);


	/*
	 * Enable Alarm 0 for on-chip temperature and Alarm 2 for on-chip
	 * VCCAUX in the Configuration Register 1.
	 */
	XSysMon_SetAlarmEnables(SysMonInstPtr, (XSM_CFR1_ALM_VCCAUX_MASK |
						XSM_CFR1_ALM_TEMP_MASK));


	/*
	 * 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 (VccauxIntr == TRUE) {
			/*
			 * Alarm 2 - VCCAUX alarm interrupt has occurred.
			 * The required processing should be put here.
			 */
			break;
		}
	}

	/*
	 * Disable global interrupt of System Monitor.
	 */
	XSysMon_IntrGlobalDisable(SysMonInstPtr);

	return XST_SUCCESS;
}
/****************************************************************************/
/**
*
* This function runs a test on the System Monitor/ADC device using the
* driver APIs.
*
* The function does the following tasks:
*	- Initiate the System Monitor/ADC device driver instance
*	- Run self-test on the device
*	- Reset the device
*	- Set up alarms for on-chip temperature and VCCAUX
*	- Set up sequence registers to continuously monitor on-chip temperature
*	and VCCAUX
*	- Setup interrupt system
*	- Enable interrupts
*	- Set up configuration registers to start the sequence
*	- Wait until temperature alarm interrupt or VCCAUX alarm interrupt
*	occurs
*
* @param	IntcInstancePtr is a pointer to the Interrupt Controller
*		driver Instance.
* @param	SysMonInstPtr is a pointer to the XSysMon driver Instance.
* @param	SysMonDeviceId is the XPAR_<SYSMON_ADC_instance>_DEVICE_ID value
*		from xparameters.h.
* @param	SysMonIntrId 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 System Monitor/ADC device using the
driver APIs.

The function does the following tasks:
Initiate the System Monitor/ADC device driver instance
Run self-test on the device
Reset the device
Set up alarms for on-chip temperature and VCCAUX
Set up sequence registers to continuously monitor on-chip temperature
and VCCAUX
Setup interrupt system
Enable interrupts
Set up configuration registers to start the sequence
Wait until temperature alarm interrupt or VCCAUX alarm interrupt
occurs
This function runs a test on the System Monitor / ADC device using the driver APIs . The function does the following tasks : Initiate the System Monitor / ADC device driver instance Run self - test on the device Reset the device Set up alarms for on - chip temperature and VCCAUX Set up sequence registers to continuously monitor on - chip temperature and VCCAUX Setup interrupt system Enable interrupts Set up configuration registers to start the sequence Wait until temperature alarm interrupt or VCCAUX alarm interrupt occurs
int SysMonIntrExample(INTC* IntcInstancePtr, XSysMon* SysMonInstPtr,
			u16 SysMonDeviceId, u16 SysMonIntrId, int *Temp)
{
	int Status;
	XSysMon_Config *ConfigPtr;
	u16 TempData;
	u16 VccauxData;
	u32 IntrStatus;
	ConfigPtr = XSysMon_LookupConfig(SysMonDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	XSysMon_CfgInitialize(SysMonInstPtr, ConfigPtr, ConfigPtr->BaseAddress);
	Status = XSysMon_SelfTest(SysMonInstPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XSysMon_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_SAFE);
	XSysMon_SetAvg(SysMonInstPtr, XSM_AVG_16_SAMPLES);
	Status = XSysMon_SetSeqInputMode(SysMonInstPtr, XSM_SEQ_CH_AUX00);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XSysMon_SetSeqAcqTime(SysMonInstPtr, XSM_SEQ_CH_AUX15 |
						XSM_SEQ_CH_AUX00);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status =  XSysMon_SetSeqAvgEnables(SysMonInstPtr, XSM_SEQ_CH_TEMP |
						XSM_SEQ_CH_VCCAUX |
						XSM_SEQ_CH_AUX00 |
						XSM_SEQ_CH_AUX15);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status =  XSysMon_SetSeqChEnables(SysMonInstPtr, XSM_SEQ_CH_TEMP |
						XSM_SEQ_CH_VCCAUX |
						XSM_SEQ_CH_AUX00 |
						XSM_SEQ_CH_AUX15);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XSysMon_SetAdcClkDivisor(SysMonInstPtr, 32);
	XSysMon_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_CONTINPASS);
	XSysMon_GetStatus(SysMonInstPtr); 
	while ((XSysMon_GetStatus(SysMonInstPtr) & XSM_SR_EOS_MASK) !=
			XSM_SR_EOS_MASK);
	TempData = XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_TEMP);
	VccauxData = XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_VCCAUX);
	*Temp = XSysMon_RawToTemperature(TempData);
	XSysMon_SetAlarmEnables(SysMonInstPtr, 0x0);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_TEMP_UPPER, 0xFFFF);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_TEMP_LOWER, 0xFFFF);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCAUX_UPPER, 0xFFFF);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCAUX_LOWER, 0x0);
	Status = SysMonSetupInterruptSystem(IntcInstancePtr,
					    SysMonInstPtr,
					    SysMonIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	IntrStatus = XSysMon_IntrGetStatus(SysMonInstPtr);
	XSysMon_IntrClear(SysMonInstPtr, IntrStatus);
	XSysMon_IntrEnable(SysMonInstPtr,
				XSM_IPIXR_TEMP_MASK |
				XSM_IPIXR_VCCAUX_MASK);
	XSysMon_IntrGlobalEnable(SysMonInstPtr);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_TEMP_UPPER,
						TempData - 0x007F);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_TEMP_LOWER,
						TempData - 0x007F);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCAUX_UPPER,
						VccauxData - 0x007F);
	XSysMon_SetAlarmThreshold(SysMonInstPtr, XSM_ATR_VCCAUX_LOWER,
						VccauxData + 0x007F);
	XSysMon_SetAlarmEnables(SysMonInstPtr, (XSM_CFR1_ALM_VCCAUX_MASK |
						XSM_CFR1_ALM_TEMP_MASK));
	while (1) {
		if (TemperatureIntr == TRUE) {
			break;
		}
		if (VccauxIntr == TRUE) {
			break;
		}
	}
	XSysMon_IntrGlobalDisable(SysMonInstPtr);
	return XST_SUCCESS;
}
int SysMonIntrExample ( INTC * IntcInstancePtr , XSysMon * SysMonInstPtr , u16 SysMonDeviceId , u16 SysMonIntrId , int * Temp ) { int Status ; XSysMon_Config * ConfigPtr ; u16 TempData ; u16 VccauxData ; u32 IntrStatus ; ConfigPtr = XSysMon_LookupConfig ( SysMonDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } XSysMon_CfgInitialize ( SysMonInstPtr , ConfigPtr , ConfigPtr -> BaseAddress ) ; Status = XSysMon_SelfTest ( SysMonInstPtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XSysMon_SetSequencerMode ( SysMonInstPtr , XSM_SEQ_MODE_SAFE ) ; XSysMon_SetAvg ( SysMonInstPtr , XSM_AVG_16_SAMPLES ) ; Status = XSysMon_SetSeqInputMode ( SysMonInstPtr , XSM_SEQ_CH_AUX00 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XSysMon_SetSeqAcqTime ( SysMonInstPtr , XSM_SEQ_CH_AUX15 | XSM_SEQ_CH_AUX00 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XSysMon_SetSeqAvgEnables ( SysMonInstPtr , XSM_SEQ_CH_TEMP | XSM_SEQ_CH_VCCAUX | XSM_SEQ_CH_AUX00 | XSM_SEQ_CH_AUX15 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XSysMon_SetSeqChEnables ( SysMonInstPtr , XSM_SEQ_CH_TEMP | XSM_SEQ_CH_VCCAUX | XSM_SEQ_CH_AUX00 | XSM_SEQ_CH_AUX15 ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XSysMon_SetAdcClkDivisor ( SysMonInstPtr , 32 ) ; XSysMon_SetSequencerMode ( SysMonInstPtr , XSM_SEQ_MODE_CONTINPASS ) ; XSysMon_GetStatus ( SysMonInstPtr ) ; while ( ( XSysMon_GetStatus ( SysMonInstPtr ) & XSM_SR_EOS_MASK ) != XSM_SR_EOS_MASK ) ; TempData = XSysMon_GetAdcData ( SysMonInstPtr , XSM_CH_TEMP ) ; VccauxData = XSysMon_GetAdcData ( SysMonInstPtr , XSM_CH_VCCAUX ) ; * Temp = XSysMon_RawToTemperature ( TempData ) ; XSysMon_SetAlarmEnables ( SysMonInstPtr , 0x0 ) ; XSysMon_SetAlarmThreshold ( SysMonInstPtr , XSM_ATR_TEMP_UPPER , 0xFFFF ) ; XSysMon_SetAlarmThreshold ( SysMonInstPtr , XSM_ATR_TEMP_LOWER , 0xFFFF ) ; XSysMon_SetAlarmThreshold ( SysMonInstPtr , XSM_ATR_VCCAUX_UPPER , 0xFFFF ) ; XSysMon_SetAlarmThreshold ( SysMonInstPtr , XSM_ATR_VCCAUX_LOWER , 0x0 ) ; Status = SysMonSetupInterruptSystem ( IntcInstancePtr , SysMonInstPtr , SysMonIntrId ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } IntrStatus = XSysMon_IntrGetStatus ( SysMonInstPtr ) ; XSysMon_IntrClear ( SysMonInstPtr , IntrStatus ) ; XSysMon_IntrEnable ( SysMonInstPtr , XSM_IPIXR_TEMP_MASK | XSM_IPIXR_VCCAUX_MASK ) ; XSysMon_IntrGlobalEnable ( SysMonInstPtr ) ; XSysMon_SetAlarmThreshold ( SysMonInstPtr , XSM_ATR_TEMP_UPPER , TempData - 0x007F ) ; XSysMon_SetAlarmThreshold ( SysMonInstPtr , XSM_ATR_TEMP_LOWER , TempData - 0x007F ) ; XSysMon_SetAlarmThreshold ( SysMonInstPtr , XSM_ATR_VCCAUX_UPPER , VccauxData - 0x007F ) ; XSysMon_SetAlarmThreshold ( SysMonInstPtr , XSM_ATR_VCCAUX_LOWER , VccauxData + 0x007F ) ; XSysMon_SetAlarmEnables ( SysMonInstPtr , ( XSM_CFR1_ALM_VCCAUX_MASK | XSM_CFR1_ALM_TEMP_MASK ) ) ; while ( 1 ) { if ( TemperatureIntr == TRUE ) { break ; } if ( VccauxIntr == TRUE ) { break ; } } XSysMon_IntrGlobalDisable ( SysMonInstPtr ) ; return XST_SUCCESS ; }
This function runs a test on the System Monitor/ADC device using the
driver APIs.
This function runs a test on the System Monitor / ADC device using the driver APIs .
/*
	 * Initialize the SysMon driver.
	 */ /*
	 * Self Test the System Monitor/ADC device.
	 */ /*
	 * Disable the Channel Sequencer before configuring the Sequence
	 * registers.
	 */ /*
	 * Setup the Averaging to be done for the channels in the
	 * Configuration 0 register as 16 samples:
	 */ /*
	 * Setup the Sequence register for 1st Auxiliary channel
	 * Setting is:
	 *	- Add acquisition time by 6 ADCCLK cycles.
	 *	- Bipolar Mode
	 *
	 * Setup the Sequence register for 16th Auxiliary channel
	 * Setting is:
	 *	- Add acquisition time by 6 ADCCLK cycles.
	 *	- Unipolar Mode
	 */ /*
	 * Enable the averaging on the following channels in the Sequencer
	 * registers:
	 * 	- On-chip Temperature
	 * 	- On-chip VCCAUX supply sensor
	 * 	- 1st Auxiliary Channel
	 * 	- 16th Auxiliary Channel
	 */ /*
	 * Enable the following channels in the Sequencer registers:
	 * 	- On-chip Temperature
	 * 	- On-chip VCCAUX supply sensor
	 * 	- 1st Auxiliary Channel
	 * 	- 16th Auxiliary Channel
	 */ /*
	 * Set the ADCCLK frequency equal to 1/32 of System clock for the System
	 * Monitor/ADC in the Configuration Register 2.
	 */ /*
	 * Enable the Channel Sequencer in continuous sequencer cycling mode.
	 */ /*
	 * Wait till the End of Sequence occurs
	 */ /* Clear the old status */ /*
	 * Read the ADC converted Data from the data registers for on-chip
	 * temperature and on-chip VCCAUX voltage.
	 */ /*
	 * Convert the ADC data into temperature
	 */ /*
	 * Disable all the alarms in the Configuration Register 1.
	 */ /*
	 * Set up Alarm threshold registers for the on-chip temperature and
	 * VCCAUX High limit and lower limit so that the alarms DONOT occur.
	 */ /*
	 * Setup the interrupt system.
	 */ /*
	 * Clear any bits set in the Interrupt Status Register.
	 */ /*
	 * Enable Alarm 0 interrupt for on-chip temperature and Alarm 2
	 * interrupt for on-chip VCCAUX.
	 */ /*
	 * Enable global interrupt of System Monitor.
	 */ /*
	 * Set up Alarm threshold registers for
	 * On-chip Temperature High limit
	 * On-chip Temperature Low limit
	 * VCCAUX High limit
	 * VCCAUX Low limit
	 */ /*
	 * Enable Alarm 0 for on-chip temperature and Alarm 2 for on-chip
	 * VCCAUX 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 2 - VCCAUX alarm interrupt has occurred.
			 * The required processing should be put here.
			 */ /*
	 * Disable global interrupt of System Monitor.
	 */