XilinxProcessorIPLib/drivers/axipmon/src/xaxipmon.c
s32 XAxiPmon_SetMetrics(XAxiPmon *InstancePtr, u8 Slot, u8 Metrics,
						u8 CounterNum)
{
	u32 RegValue;
	u32 Mask;
	/*
	 * Assert the arguments.
	 */
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
	Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
	Xil_AssertNonvoid(Slot < XAPM_MAX_AGENTS);
	Xil_AssertNonvoid((Metrics <= XAPM_METRIC_SET_22) ||
			(Metrics == XAPM_METRIC_SET_30));
	Xil_AssertNonvoid(CounterNum < XAPM_MAX_COUNTERS);

	/* Find Mask value to force zero in counternum byte range */
	if ((CounterNum == 0U) || (CounterNum == 4U) || (CounterNum == 8U)) {
		Mask = 0xFFFFFF00U;
	}
	else if ((CounterNum == 1U) || (CounterNum == 5U) || (CounterNum == 9U)) {
		Mask = 0xFFFF00FFU;
	}
	else if ((CounterNum == 2U) || (CounterNum == 6U)) {
		Mask = 0xFF00FFFFU;
	}
	else {
		Mask = 0x00FFFFFFU;
	}

	if(CounterNum <= 3U) {
		RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
					    XAPM_MSR0_OFFSET);

		RegValue = RegValue & Mask;
		RegValue = RegValue | ((u32)Metrics << (CounterNum * (u8)8));
		RegValue = RegValue | ((u32)Slot << ((CounterNum * (u8)8) + (u8)5));
		XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
					(u32)XAPM_MSR0_OFFSET,RegValue);
	}
	else if((CounterNum >= 4U) && (CounterNum <= 7U)) {
		CounterNum = CounterNum - 4U;
		RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
					    (u32)XAPM_MSR1_OFFSET);

		RegValue = RegValue & Mask;
		RegValue = RegValue | ((u32)Metrics << (CounterNum * (u8)8));
		RegValue = RegValue | ((u32)Slot << ((CounterNum * (u8)8) + (u8)5));
		XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
					XAPM_MSR1_OFFSET,RegValue);
	}
	else {
		CounterNum = CounterNum - 8U;
		RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
					    XAPM_MSR2_OFFSET);

		RegValue = RegValue & Mask;
		RegValue = RegValue | ((u32)Metrics << (CounterNum * (u8)8));
		RegValue = RegValue | ((u32)Slot << ((CounterNum * (u8)8) + (u8)5));
		XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
					XAPM_MSR2_OFFSET,RegValue);
	}
	return XST_SUCCESS;
}
/****************************************************************************/
/**
*
* This function sets Metrics for specified Counter in the corresponding
* Metric Selector Register.
*
* @param	InstancePtr is a pointer to the XAxiPmon instance.
* @param	Slot is the slot ID for which specified counter has to
*		be connected.
* @param	Metrics is one of the Metric Sets. User has to use
*		XAPM_METRIC_SET_* macros in xaxipmon.h for this parameter
* @param	CounterNum is the Counter Number.
*		The valid values are 0 to 9.
*
* @return	XST_SUCCESS if Success
*		XST_FAILURE if Failure
*
* @note		None.
*
*****************************************************************************/
This function sets Metrics for specified Counter in the corresponding
Metric Selector Register.
This function sets Metrics for specified Counter in the corresponding Metric Selector Register .
s32 XAxiPmon_SetMetrics(XAxiPmon *InstancePtr, u8 Slot, u8 Metrics,
						u8 CounterNum)
{
	u32 RegValue;
	u32 Mask;
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
	Xil_AssertNonvoid(InstancePtr->Mode == XAPM_MODE_ADVANCED);
	Xil_AssertNonvoid(Slot < XAPM_MAX_AGENTS);
	Xil_AssertNonvoid((Metrics <= XAPM_METRIC_SET_22) ||
			(Metrics == XAPM_METRIC_SET_30));
	Xil_AssertNonvoid(CounterNum < XAPM_MAX_COUNTERS);
	if ((CounterNum == 0U) || (CounterNum == 4U) || (CounterNum == 8U)) {
		Mask = 0xFFFFFF00U;
	}
	else if ((CounterNum == 1U) || (CounterNum == 5U) || (CounterNum == 9U)) {
		Mask = 0xFFFF00FFU;
	}
	else if ((CounterNum == 2U) || (CounterNum == 6U)) {
		Mask = 0xFF00FFFFU;
	}
	else {
		Mask = 0x00FFFFFFU;
	}
	if(CounterNum <= 3U) {
		RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
					    XAPM_MSR0_OFFSET);
		RegValue = RegValue & Mask;
		RegValue = RegValue | ((u32)Metrics << (CounterNum * (u8)8));
		RegValue = RegValue | ((u32)Slot << ((CounterNum * (u8)8) + (u8)5));
		XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
					(u32)XAPM_MSR0_OFFSET,RegValue);
	}
	else if((CounterNum >= 4U) && (CounterNum <= 7U)) {
		CounterNum = CounterNum - 4U;
		RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
					    (u32)XAPM_MSR1_OFFSET);
		RegValue = RegValue & Mask;
		RegValue = RegValue | ((u32)Metrics << (CounterNum * (u8)8));
		RegValue = RegValue | ((u32)Slot << ((CounterNum * (u8)8) + (u8)5));
		XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
					XAPM_MSR1_OFFSET,RegValue);
	}
	else {
		CounterNum = CounterNum - 8U;
		RegValue = XAxiPmon_ReadReg(InstancePtr->Config.BaseAddress,
					    XAPM_MSR2_OFFSET);
		RegValue = RegValue & Mask;
		RegValue = RegValue | ((u32)Metrics << (CounterNum * (u8)8));
		RegValue = RegValue | ((u32)Slot << ((CounterNum * (u8)8) + (u8)5));
		XAxiPmon_WriteReg(InstancePtr->Config.BaseAddress,
					XAPM_MSR2_OFFSET,RegValue);
	}
	return XST_SUCCESS;
}
s32 XAxiPmon_SetMetrics ( XAxiPmon * InstancePtr , u8 Slot , u8 Metrics , u8 CounterNum ) { u32 RegValue ; u32 Mask ; Xil_AssertNonvoid ( InstancePtr != NULL ) ; Xil_AssertNonvoid ( InstancePtr -> IsReady == XIL_COMPONENT_IS_READY ) ; Xil_AssertNonvoid ( InstancePtr -> Mode == XAPM_MODE_ADVANCED ) ; Xil_AssertNonvoid ( Slot < XAPM_MAX_AGENTS ) ; Xil_AssertNonvoid ( ( Metrics <= XAPM_METRIC_SET_22 ) || ( Metrics == XAPM_METRIC_SET_30 ) ) ; Xil_AssertNonvoid ( CounterNum < XAPM_MAX_COUNTERS ) ; if ( ( CounterNum == 0U ) || ( CounterNum == 4U ) || ( CounterNum == 8U ) ) { Mask = 0xFFFFFF00U ; } else if ( ( CounterNum == 1U ) || ( CounterNum == 5U ) || ( CounterNum == 9U ) ) { Mask = 0xFFFF00FFU ; } else if ( ( CounterNum == 2U ) || ( CounterNum == 6U ) ) { Mask = 0xFF00FFFFU ; } else { Mask = 0x00FFFFFFU ; } if ( CounterNum <= 3U ) { RegValue = XAxiPmon_ReadReg ( InstancePtr -> Config . BaseAddress , XAPM_MSR0_OFFSET ) ; RegValue = RegValue & Mask ; RegValue = RegValue | ( ( u32 ) Metrics << ( CounterNum * ( u8 ) 8 ) ) ; RegValue = RegValue | ( ( u32 ) Slot << ( ( CounterNum * ( u8 ) 8 ) + ( u8 ) 5 ) ) ; XAxiPmon_WriteReg ( InstancePtr -> Config . BaseAddress , ( u32 ) XAPM_MSR0_OFFSET , RegValue ) ; } else if ( ( CounterNum >= 4U ) && ( CounterNum <= 7U ) ) { CounterNum = CounterNum - 4U ; RegValue = XAxiPmon_ReadReg ( InstancePtr -> Config . BaseAddress , ( u32 ) XAPM_MSR1_OFFSET ) ; RegValue = RegValue & Mask ; RegValue = RegValue | ( ( u32 ) Metrics << ( CounterNum * ( u8 ) 8 ) ) ; RegValue = RegValue | ( ( u32 ) Slot << ( ( CounterNum * ( u8 ) 8 ) + ( u8 ) 5 ) ) ; XAxiPmon_WriteReg ( InstancePtr -> Config . BaseAddress , XAPM_MSR1_OFFSET , RegValue ) ; } else { CounterNum = CounterNum - 8U ; RegValue = XAxiPmon_ReadReg ( InstancePtr -> Config . BaseAddress , XAPM_MSR2_OFFSET ) ; RegValue = RegValue & Mask ; RegValue = RegValue | ( ( u32 ) Metrics << ( CounterNum * ( u8 ) 8 ) ) ; RegValue = RegValue | ( ( u32 ) Slot << ( ( CounterNum * ( u8 ) 8 ) + ( u8 ) 5 ) ) ; XAxiPmon_WriteReg ( InstancePtr -> Config . BaseAddress , XAPM_MSR2_OFFSET , RegValue ) ; } return XST_SUCCESS ; }
This function sets Metrics for specified Counter in the corresponding
Metric Selector Register.
This function sets Metrics for specified Counter in the corresponding Metric Selector Register .
/*
	 * Assert the arguments.
	 */ /* Find Mask value to force zero in counternum byte range */