XilinxProcessorIPLib/drivers/sysmonpsu/examples/xsysmonpsu_polled_example.c
int SysMonPsuPolledPrintfExample(u16 SysMonDeviceId)
{
	int Status;
	XSysMonPsu_Config *ConfigPtr;
	u32 TempRawData;
	u32 Supply3RawData;
	u32 Supply1RawData;
	float TempData;
	float Supply3Data;
	float Supply1Data;
	float MaxData;
	float MinData;
	u64 IntrStatus;
	XSysMonPsu *SysMonInstPtr = &SysMonInst;

	printf("\r\nEntering the SysMon Polled Example. \r\n");

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

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

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


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


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


	/*
	 * Enable the averaging on the following channels in the Sequencer
	 * registers:
	 * 	- On-chip Temperature, Supply 1/Supply 3  supply sensors
	  *	- Calibration Channel
	 */
	Status =  XSysMonPsu_SetSeqAvgEnables(SysMonInstPtr, XSYSMONPSU_SEQ_CH0_TEMP_MASK |
			XSYSMONPSU_SEQ_CH0_SUP1_MASK |
			XSYSMONPSU_SEQ_CH0_SUP3_MASK |
			XSYSMONPSU_SEQ_CH0_CALIBRTN_MASK, XSYSMON_TYPE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable the following channels in the Sequencer registers:
	 * 	- On-chip Temperature, Supply 1/Supply 3 supply sensors
	 *	- Calibration Channel
	 */
	Status =  XSysMonPsu_SetSeqChEnables(SysMonInstPtr, XSYSMONPSU_SEQ_CH0_TEMP_MASK |
			XSYSMONPSU_SEQ_CH0_SUP1_MASK |
			XSYSMONPSU_SEQ_CH0_SUP3_MASK |
			XSYSMONPSU_SEQ_CH0_CALIBRTN_MASK, XSYSMON_TYPE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

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

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

	/* Wait till the End of Sequence occurs */
	while ((XSysMonPsu_IntrGetStatus(SysMonInstPtr) & ((u64)XSYSMONPSU_ISR_1_EOS_MASK<< 32)) !=
			((u64)XSYSMONPSU_ISR_1_EOS_MASK<< 32));

	/*
	 * Read the on-chip Temperature Data (Current/Maximum/Minimum)
	 * from the ADC data registers.
	 */
	TempRawData = XSysMonPsu_GetAdcData(SysMonInstPtr, XSM_CH_TEMP, XSYSMON_TYPE);
	TempData = XSysMonPsu_RawToTemperature_OnChip(TempRawData);
	printf("\r\nThe Current Temperature is %0d.%03d Centigrades.\r\n",
				(int)(TempData), SysMonPsuFractionToInt(TempData));


	TempRawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr, XSM_MAX_TEMP, XSYSMON_TYPE);
	MaxData = XSysMonPsu_RawToTemperature_OnChip(TempRawData);
	printf("The Maximum Temperature is %0d.%03d Centigrades. \r\n",
				(int)(MaxData), SysMonPsuFractionToInt(MaxData));

	TempRawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr, XSM_MIN_TEMP, XSYSMON_TYPE);
	MinData = XSysMonPsu_RawToTemperature_OnChip(TempRawData);
	printf("The Minimum Temperature is %0d.%03d Centigrades. \r\n",
				(int)(MinData), SysMonPsuFractionToInt(MinData));

	/*
	 * Read the Supply 1 Votage Data (Current/Maximum/Minimum) from the
	 * ADC data registers.
	 */
	Supply1RawData = XSysMonPsu_GetAdcData(SysMonInstPtr, XSM_CH_SUPPLY1, XSYSMON_TYPE);
	Supply1Data = XSysMonPsu_RawToVoltage(Supply1RawData);
	printf("\r\nThe Current Supply 1 is %0d.%03d Volts. \r\n",
			(int)(Supply1Data), SysMonPsuFractionToInt(Supply1Data));

	Supply1RawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr,
							XSM_MAX_SUPPLY1, XSYSMON_TYPE);
	MaxData = XSysMonPsu_RawToVoltage(Supply1RawData);
	printf("The Maximum Supply 1 is %0d.%03d Volts. \r\n",
			(int)(MaxData), SysMonPsuFractionToInt(MaxData));

	Supply1RawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr,
							XSM_MIN_SUPPLY1, XSYSMON_TYPE);
	MinData = XSysMonPsu_RawToVoltage(Supply1RawData);
	printf("The Minimum Supply 1 is %0d.%03d Volts. \r\n",
			(int)(MinData), SysMonPsuFractionToInt(MinData));

	/*
	 * Read the Supply 3 Votage Data (Current/Maximum/Minimum) from the
	 * ADC data registers.
	 */
	Supply3RawData = XSysMonPsu_GetAdcData(SysMonInstPtr, XSM_CH_SUPPLY3, XSYSMON_TYPE);
	Supply3Data = XSysMonPsu_RawToVoltage(Supply3RawData);
	printf("\r\nThe Current Supply 3 is %0d.%03d Volts. \r\n",
			(int)(Supply3Data), SysMonPsuFractionToInt(Supply3Data));

	Supply3RawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr,
							XSM_MAX_SUPPLY3, XSYSMON_TYPE);
	MaxData = XSysMonPsu_RawToVoltage(Supply3RawData);
	printf("The Maximum Supply 3 is %0d.%03d Volts. \r\n",
				(int)(MaxData), SysMonPsuFractionToInt(MaxData));


	Supply3RawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr,
							XSM_MIN_SUPPLY3, XSYSMON_TYPE);
	MinData = XSysMonPsu_RawToVoltage(Supply3RawData);
	printf("The Minimum Supply 3 is %0d.%03d Volts. \r\n\r\n",
				(int)(MinData), SysMonPsuFractionToInt(MinData));

	printf("Exiting the SysMon Polled Example. \r\n");

	return XST_SUCCESS;
}
/****************************************************************************/
/**
*
* This function runs a test on the System Monitor device using the
* driver APIs.
* This function does the following tasks:
*	- Initiate the System Monitor device driver instance
*	- Run self-test on the device
*	- Setup the sequence registers to continuously monitor on-chip
*	temperature, Supply 1 and Supply 3
*	- Setup configuration registers to start the sequence
*	- Read the latest on-chip temperature, Supply 1 and Supply 3
*
* @param	SysMonDeviceId is the XPAR_<SYSMON_instance>_DEVICE_ID value
*		from xparameters.h.
*
* @return
*		- XST_SUCCESS if the example has completed successfully.
*		- XST_FAILURE if the example has failed.
*
* @note   	None
*
****************************************************************************/
This function runs a test on the System Monitor device using the
driver APIs.
This function does the following tasks:
Initiate the System Monitor device driver instance
Run self-test on the device
Setup the sequence registers to continuously monitor on-chip
temperature, Supply 1 and Supply 3
Setup configuration registers to start the sequence
Read the latest on-chip temperature, Supply 1 and Supply 3
This function runs a test on the System Monitor device using the driver APIs . This function does the following tasks : Initiate the System Monitor device driver instance Run self - test on the device Setup the sequence registers to continuously monitor on - chip temperature Supply 1 and Supply 3 Setup configuration registers to start the sequence Read the latest on - chip temperature Supply 1 and Supply 3
int SysMonPsuPolledPrintfExample(u16 SysMonDeviceId)
{
	int Status;
	XSysMonPsu_Config *ConfigPtr;
	u32 TempRawData;
	u32 Supply3RawData;
	u32 Supply1RawData;
	float TempData;
	float Supply3Data;
	float Supply1Data;
	float MaxData;
	float MinData;
	u64 IntrStatus;
	XSysMonPsu *SysMonInstPtr = &SysMonInst;
	printf("\r\nEntering the SysMon Polled Example. \r\n");
	ConfigPtr = XSysMonPsu_LookupConfig(SysMonDeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	XSysMonPsu_CfgInitialize(SysMonInstPtr, ConfigPtr,
				ConfigPtr->BaseAddress);
	Status = XSysMonPsu_SelfTest(SysMonInstPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XSysMonPsu_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_SAFE, XSYSMON_TYPE);
	XSysMonPsu_SetAlarmEnables(SysMonInstPtr, 0x0, XSYSMON_TYPE);
	XSysMonPsu_SetAvg(SysMonInstPtr, XSM_AVG_16_SAMPLES, XSYSMON_TYPE);
	Status =  XSysMonPsu_SetSeqAvgEnables(SysMonInstPtr, XSYSMONPSU_SEQ_CH0_TEMP_MASK |
			XSYSMONPSU_SEQ_CH0_SUP1_MASK |
			XSYSMONPSU_SEQ_CH0_SUP3_MASK |
			XSYSMONPSU_SEQ_CH0_CALIBRTN_MASK, XSYSMON_TYPE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status =  XSysMonPsu_SetSeqChEnables(SysMonInstPtr, XSYSMONPSU_SEQ_CH0_TEMP_MASK |
			XSYSMONPSU_SEQ_CH0_SUP1_MASK |
			XSYSMONPSU_SEQ_CH0_SUP3_MASK |
			XSYSMONPSU_SEQ_CH0_CALIBRTN_MASK, XSYSMON_TYPE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	IntrStatus = XSysMonPsu_IntrGetStatus(SysMonInstPtr);
	XSysMonPsu_IntrClear(SysMonInstPtr, IntrStatus);
	XSysMonPsu_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_CONTINPASS, XSYSMON_TYPE);
	while ((XSysMonPsu_IntrGetStatus(SysMonInstPtr) & ((u64)XSYSMONPSU_ISR_1_EOS_MASK<< 32)) !=
			((u64)XSYSMONPSU_ISR_1_EOS_MASK<< 32));
	TempRawData = XSysMonPsu_GetAdcData(SysMonInstPtr, XSM_CH_TEMP, XSYSMON_TYPE);
	TempData = XSysMonPsu_RawToTemperature_OnChip(TempRawData);
	printf("\r\nThe Current Temperature is %0d.%03d Centigrades.\r\n",
				(int)(TempData), SysMonPsuFractionToInt(TempData));
	TempRawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr, XSM_MAX_TEMP, XSYSMON_TYPE);
	MaxData = XSysMonPsu_RawToTemperature_OnChip(TempRawData);
	printf("The Maximum Temperature is %0d.%03d Centigrades. \r\n",
				(int)(MaxData), SysMonPsuFractionToInt(MaxData));
	TempRawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr, XSM_MIN_TEMP, XSYSMON_TYPE);
	MinData = XSysMonPsu_RawToTemperature_OnChip(TempRawData);
	printf("The Minimum Temperature is %0d.%03d Centigrades. \r\n",
				(int)(MinData), SysMonPsuFractionToInt(MinData));
	Supply1RawData = XSysMonPsu_GetAdcData(SysMonInstPtr, XSM_CH_SUPPLY1, XSYSMON_TYPE);
	Supply1Data = XSysMonPsu_RawToVoltage(Supply1RawData);
	printf("\r\nThe Current Supply 1 is %0d.%03d Volts. \r\n",
			(int)(Supply1Data), SysMonPsuFractionToInt(Supply1Data));
	Supply1RawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr,
							XSM_MAX_SUPPLY1, XSYSMON_TYPE);
	MaxData = XSysMonPsu_RawToVoltage(Supply1RawData);
	printf("The Maximum Supply 1 is %0d.%03d Volts. \r\n",
			(int)(MaxData), SysMonPsuFractionToInt(MaxData));
	Supply1RawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr,
							XSM_MIN_SUPPLY1, XSYSMON_TYPE);
	MinData = XSysMonPsu_RawToVoltage(Supply1RawData);
	printf("The Minimum Supply 1 is %0d.%03d Volts. \r\n",
			(int)(MinData), SysMonPsuFractionToInt(MinData));
	Supply3RawData = XSysMonPsu_GetAdcData(SysMonInstPtr, XSM_CH_SUPPLY3, XSYSMON_TYPE);
	Supply3Data = XSysMonPsu_RawToVoltage(Supply3RawData);
	printf("\r\nThe Current Supply 3 is %0d.%03d Volts. \r\n",
			(int)(Supply3Data), SysMonPsuFractionToInt(Supply3Data));
	Supply3RawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr,
							XSM_MAX_SUPPLY3, XSYSMON_TYPE);
	MaxData = XSysMonPsu_RawToVoltage(Supply3RawData);
	printf("The Maximum Supply 3 is %0d.%03d Volts. \r\n",
				(int)(MaxData), SysMonPsuFractionToInt(MaxData));
	Supply3RawData = XSysMonPsu_GetMinMaxMeasurement(SysMonInstPtr,
							XSM_MIN_SUPPLY3, XSYSMON_TYPE);
	MinData = XSysMonPsu_RawToVoltage(Supply3RawData);
	printf("The Minimum Supply 3 is %0d.%03d Volts. \r\n\r\n",
				(int)(MinData), SysMonPsuFractionToInt(MinData));
	printf("Exiting the SysMon Polled Example. \r\n");
	return XST_SUCCESS;
}
int SysMonPsuPolledPrintfExample ( u16 SysMonDeviceId ) { int Status ; XSysMonPsu_Config * ConfigPtr ; u32 TempRawData ; u32 Supply3RawData ; u32 Supply1RawData ; float TempData ; float Supply3Data ; float Supply1Data ; float MaxData ; float MinData ; u64 IntrStatus ; XSysMonPsu * SysMonInstPtr = & SysMonInst ; printf ( " \r \n \r \n " ) ; ConfigPtr = XSysMonPsu_LookupConfig ( SysMonDeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } XSysMonPsu_CfgInitialize ( SysMonInstPtr , ConfigPtr , ConfigPtr -> BaseAddress ) ; Status = XSysMonPsu_SelfTest ( SysMonInstPtr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XSysMonPsu_SetSequencerMode ( SysMonInstPtr , XSM_SEQ_MODE_SAFE , XSYSMON_TYPE ) ; XSysMonPsu_SetAlarmEnables ( SysMonInstPtr , 0x0 , XSYSMON_TYPE ) ; XSysMonPsu_SetAvg ( SysMonInstPtr , XSM_AVG_16_SAMPLES , XSYSMON_TYPE ) ; Status = XSysMonPsu_SetSeqAvgEnables ( SysMonInstPtr , XSYSMONPSU_SEQ_CH0_TEMP_MASK | XSYSMONPSU_SEQ_CH0_SUP1_MASK | XSYSMONPSU_SEQ_CH0_SUP3_MASK | XSYSMONPSU_SEQ_CH0_CALIBRTN_MASK , XSYSMON_TYPE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XSysMonPsu_SetSeqChEnables ( SysMonInstPtr , XSYSMONPSU_SEQ_CH0_TEMP_MASK | XSYSMONPSU_SEQ_CH0_SUP1_MASK | XSYSMONPSU_SEQ_CH0_SUP3_MASK | XSYSMONPSU_SEQ_CH0_CALIBRTN_MASK , XSYSMON_TYPE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } IntrStatus = XSysMonPsu_IntrGetStatus ( SysMonInstPtr ) ; XSysMonPsu_IntrClear ( SysMonInstPtr , IntrStatus ) ; XSysMonPsu_SetSequencerMode ( SysMonInstPtr , XSM_SEQ_MODE_CONTINPASS , XSYSMON_TYPE ) ; while ( ( XSysMonPsu_IntrGetStatus ( SysMonInstPtr ) & ( ( u64 ) XSYSMONPSU_ISR_1_EOS_MASK << 32 ) ) != ( ( u64 ) XSYSMONPSU_ISR_1_EOS_MASK << 32 ) ) ; TempRawData = XSysMonPsu_GetAdcData ( SysMonInstPtr , XSM_CH_TEMP , XSYSMON_TYPE ) ; TempData = XSysMonPsu_RawToTemperature_OnChip ( TempRawData ) ; printf ( " \r \n \r \n " , ( int ) ( TempData ) , SysMonPsuFractionToInt ( TempData ) ) ; TempRawData = XSysMonPsu_GetMinMaxMeasurement ( SysMonInstPtr , XSM_MAX_TEMP , XSYSMON_TYPE ) ; MaxData = XSysMonPsu_RawToTemperature_OnChip ( TempRawData ) ; printf ( " \r \n " , ( int ) ( MaxData ) , SysMonPsuFractionToInt ( MaxData ) ) ; TempRawData = XSysMonPsu_GetMinMaxMeasurement ( SysMonInstPtr , XSM_MIN_TEMP , XSYSMON_TYPE ) ; MinData = XSysMonPsu_RawToTemperature_OnChip ( TempRawData ) ; printf ( " \r \n " , ( int ) ( MinData ) , SysMonPsuFractionToInt ( MinData ) ) ; Supply1RawData = XSysMonPsu_GetAdcData ( SysMonInstPtr , XSM_CH_SUPPLY1 , XSYSMON_TYPE ) ; Supply1Data = XSysMonPsu_RawToVoltage ( Supply1RawData ) ; printf ( " \r \n \r \n " , ( int ) ( Supply1Data ) , SysMonPsuFractionToInt ( Supply1Data ) ) ; Supply1RawData = XSysMonPsu_GetMinMaxMeasurement ( SysMonInstPtr , XSM_MAX_SUPPLY1 , XSYSMON_TYPE ) ; MaxData = XSysMonPsu_RawToVoltage ( Supply1RawData ) ; printf ( " \r \n " , ( int ) ( MaxData ) , SysMonPsuFractionToInt ( MaxData ) ) ; Supply1RawData = XSysMonPsu_GetMinMaxMeasurement ( SysMonInstPtr , XSM_MIN_SUPPLY1 , XSYSMON_TYPE ) ; MinData = XSysMonPsu_RawToVoltage ( Supply1RawData ) ; printf ( " \r \n " , ( int ) ( MinData ) , SysMonPsuFractionToInt ( MinData ) ) ; Supply3RawData = XSysMonPsu_GetAdcData ( SysMonInstPtr , XSM_CH_SUPPLY3 , XSYSMON_TYPE ) ; Supply3Data = XSysMonPsu_RawToVoltage ( Supply3RawData ) ; printf ( " \r \n \r \n " , ( int ) ( Supply3Data ) , SysMonPsuFractionToInt ( Supply3Data ) ) ; Supply3RawData = XSysMonPsu_GetMinMaxMeasurement ( SysMonInstPtr , XSM_MAX_SUPPLY3 , XSYSMON_TYPE ) ; MaxData = XSysMonPsu_RawToVoltage ( Supply3RawData ) ; printf ( " \r \n " , ( int ) ( MaxData ) , SysMonPsuFractionToInt ( MaxData ) ) ; Supply3RawData = XSysMonPsu_GetMinMaxMeasurement ( SysMonInstPtr , XSM_MIN_SUPPLY3 , XSYSMON_TYPE ) ; MinData = XSysMonPsu_RawToVoltage ( Supply3RawData ) ; printf ( " \r \n \r \n " , ( int ) ( MinData ) , SysMonPsuFractionToInt ( MinData ) ) ; printf ( " \r \n " ) ; return XST_SUCCESS ; }
This function runs a test on the System Monitor device using the
driver APIs.
This function runs a test on the System Monitor device using the driver APIs .
/* Initialize the SysMon driver. */ /* Self Test the System Monitor device */ /*
	 * Disable the Channel Sequencer before configuring the Sequence
	 * registers.
	 */ /* Disable all the alarms in the Configuration Register 1. */ /*
	 * Setup the Averaging to be done for the channels in the
	 * Configuration 0 register as 16 samples:
	 */ /*
	 * Enable the averaging on the following channels in the Sequencer
	 * registers:
	 * 	- On-chip Temperature, Supply 1/Supply 3  supply sensors
	  *	- Calibration Channel
	 */ /*
	 * Enable the following channels in the Sequencer registers:
	 * 	- On-chip Temperature, Supply 1/Supply 3 supply sensors
	 *	- Calibration Channel
	 */ /* Clear any bits set in the Interrupt Status Register. */ /* Enable the Channel Sequencer in continuous sequencer cycling mode. */ /* Wait till the End of Sequence occurs */ /*
	 * Read the on-chip Temperature Data (Current/Maximum/Minimum)
	 * from the ADC data registers.
	 */ /*
	 * Read the Supply 1 Votage Data (Current/Maximum/Minimum) from the
	 * ADC data registers.
	 */ /*
	 * Read the Supply 3 Votage Data (Current/Maximum/Minimum) from the
	 * ADC data registers.
	 */