lib/sw_services/xilsem/examples/xsem_cram_example.c
void PrintErrReport(u32 IntialCorErrCnt)
{
	XStatus Status = 0U;
	XSemCfrStatus CfrStatusInfo = {0};
	u32 TempA = 0U;
	u32 TempB = 0U;
	u32 CorErrCount = 0U;
	u32 ErrIndex = 0U;
	u32 ErrBitLoc = 0U;
	u32 ErrQwordLoc = 0U;
	u32 ErrFarLoc = 0U;
	u32 ErrRowLoc = 0U;

	xil_printf("-----------------------------------------------------\n\r");
	xil_printf("-----------------Print Report------------------------\n\r");
	xil_printf("-----------------------------------------------------\n\r");

	/*Check error is detected and corrected*/
	(void)XSem_CmdCfrGetStatus(&CfrStatusInfo);
	TempA = (CRAM_STATUS_COR_ERR_MASK |
			CRAM_STATUS_CRC_ERR_MASK |
			CRAM_STATUS_UNCOR_ERR_MASK);
	Status = CfrStatusInfo.Status & TempA;

	if (Status == CRAM_STATUS_UNCOR_ERR_MASK) {

		xil_printf("[SUCCESS] UnCorrectable error detected \n\r");

		/*Check Error count increased as expected or not*/
		Status = ApiChkErrorCount(IntialCorErrCnt, 0U);
		if (Status == XST_SUCCESS){
			xil_printf("[SUCCESS] No increase in Error Count\n\r");
		} else {
			xil_printf("[FAILURE] Unexpected increase in" \
				" Error Count\n\r");
		}

		/*Check Event notification*/
		if(EventCnt_UnCorEcc == 1U && EventCnt_Crc == 0U &&
			EventCnt_CorEcc == 0U && EventCnt_IntErr == 0U){
			xil_printf("[SUCCESS] Received Uncorrectable error" \
				" event notification\n\r");
			EventCnt_UnCorEcc = 0U;
		} else {
			xil_printf("[FAILURE] No Uncorrectable error event" \
				" notification received\n\r");
		}

	} else if (Status == CRAM_STATUS_CRC_ERR_MASK) {

		xil_printf("[SUCCESS] CRC error detected \n\r");

		/*Check Error count increased as expected or not*/
		Status = ApiChkErrorCount(IntialCorErrCnt, 0U);
		if (Status == XST_SUCCESS){
			xil_printf("[SUCCESS] No increase in Error Count\n\r");
		} else {
			xil_printf("[FAILURE] Unexpected increase in" \
				" Error Count\n\r");
		}

		/*Check Event notification*/
		if(EventCnt_UnCorEcc == 0U && EventCnt_Crc == 1U &&
			EventCnt_CorEcc == 0U && EventCnt_IntErr == 0U){
			xil_printf("[SUCCESS] Received CRC error" \
				" event notification\n\r");
			EventCnt_Crc = 0U;
		} else {
			xil_printf("[FAILURE] No CRC error event" \
				" notification received\n\r");
		}

	} else if(Status == CRAM_STATUS_COR_ERR_MASK) {

		xil_printf("[SUCCESS] Correctable error detected \n\r");

		Status = CfrStatusInfo.Status & CRAM_STATUS_ECC_COR_DONE_MASK;
		/*To print and check Corrected Error count*/
		if (Status == CRAM_STATUS_ECC_COR_DONE_MASK) {

			xil_printf("[SUCCESS] Correction Done \n\r");

			CorErrCount = CfrStatusInfo.ErrCorCnt;
			xil_printf("Total Corrected Error count = %d\n\r", \
					CorErrCount);

			/*Check Error count increased as expected or not*/
			Status = ApiChkErrorCount(IntialCorErrCnt, 1U);
			if (Status == XST_SUCCESS){
				xil_printf("[SUCCESS] Error Count increased" \
					" by 1 as expected\n\r");
			} else {
				xil_printf("[FAILURE] XilSEM failed to" \
					" increase error count\n\r");
			}
		}

		/*Check Event notification*/
		if(EventCnt_UnCorEcc == 0U && EventCnt_Crc == 0U &&
			EventCnt_CorEcc == 1U && EventCnt_IntErr == 0U){
			xil_printf("[SUCCESS] Received Correctable error" \
				" event notification\n\r");
			EventCnt_CorEcc = 0U;
		} else {
			xil_printf("[FAILURE] No Correctable error event" \
				" notification received\n\r");
		}

		/*To print error location details*/
		ErrIndex = (CorErrCount % 7U);
		if(ErrIndex != 0U){
			--ErrIndex;
		} else{
			ErrIndex = 6U;
		}

		TempA = CfrStatusInfo.ErrAddrL[ErrIndex];
		TempB = CfrStatusInfo.ErrAddrH[ErrIndex];

		/* bit is at 22:16 bits of SEM_CRAMERR_ADDRL0 reg */
		ErrBitLoc 	= (TempA & 0x7F0000) >> 16;
		/* Qword is at 27:23 bits of SEM_CRAMERR_ADDRL0 reg */
		ErrQwordLoc = (TempA & 0xF800000) >> 23;
		/* Frame  is at 19:0 bits of SEM_CRAMERR_ADDRH0 reg */
		ErrFarLoc 	= (TempB & 0x7FFFFF);
		/* Frame  is at 26:23 bits of SEM_CRAMERR_ADDRH0 reg */
		ErrRowLoc 	= (TempB & 0x7800000) >> 23;

		xil_printf("Error is located in Row = %d, FAR = 0x%06x,"
			" Qword = %d, Bit = %d\n\r", ErrRowLoc, ErrFarLoc, \
			ErrQwordLoc, ErrBitLoc);

	} else {
		xil_printf("[FAILURE] XilSEM failed to detect error," \
			" Status = 0x%08x\n\r", CfrStatusInfo.Status);
	}

}
/******************************************************************************
 * @brief	Verifies and Prints error report
 *
 * @param[in]	IntialCorErrCnt : Error count before error injection
 *
 *****************************************************************************/
@brief       Verifies and Prints error report
@param[in]   IntialCorErrCnt : Error count before error injection
@brief Verifies and Prints error report @param [ in ] IntialCorErrCnt : Error count before error injection
void PrintErrReport(u32 IntialCorErrCnt)
{
	XStatus Status = 0U;
	XSemCfrStatus CfrStatusInfo = {0};
	u32 TempA = 0U;
	u32 TempB = 0U;
	u32 CorErrCount = 0U;
	u32 ErrIndex = 0U;
	u32 ErrBitLoc = 0U;
	u32 ErrQwordLoc = 0U;
	u32 ErrFarLoc = 0U;
	u32 ErrRowLoc = 0U;
	xil_printf("-----------------------------------------------------\n\r");
	xil_printf("-----------------Print Report------------------------\n\r");
	xil_printf("-----------------------------------------------------\n\r");
	(void)XSem_CmdCfrGetStatus(&CfrStatusInfo);
	TempA = (CRAM_STATUS_COR_ERR_MASK |
			CRAM_STATUS_CRC_ERR_MASK |
			CRAM_STATUS_UNCOR_ERR_MASK);
	Status = CfrStatusInfo.Status & TempA;
	if (Status == CRAM_STATUS_UNCOR_ERR_MASK) {
		xil_printf("[SUCCESS] UnCorrectable error detected \n\r");
		Status = ApiChkErrorCount(IntialCorErrCnt, 0U);
		if (Status == XST_SUCCESS){
			xil_printf("[SUCCESS] No increase in Error Count\n\r");
		} else {
			xil_printf("[FAILURE] Unexpected increase in" \
				" Error Count\n\r");
		}
		if(EventCnt_UnCorEcc == 1U && EventCnt_Crc == 0U &&
			EventCnt_CorEcc == 0U && EventCnt_IntErr == 0U){
			xil_printf("[SUCCESS] Received Uncorrectable error" \
				" event notification\n\r");
			EventCnt_UnCorEcc = 0U;
		} else {
			xil_printf("[FAILURE] No Uncorrectable error event" \
				" notification received\n\r");
		}
	} else if (Status == CRAM_STATUS_CRC_ERR_MASK) {
		xil_printf("[SUCCESS] CRC error detected \n\r");
		Status = ApiChkErrorCount(IntialCorErrCnt, 0U);
		if (Status == XST_SUCCESS){
			xil_printf("[SUCCESS] No increase in Error Count\n\r");
		} else {
			xil_printf("[FAILURE] Unexpected increase in" \
				" Error Count\n\r");
		}
		if(EventCnt_UnCorEcc == 0U && EventCnt_Crc == 1U &&
			EventCnt_CorEcc == 0U && EventCnt_IntErr == 0U){
			xil_printf("[SUCCESS] Received CRC error" \
				" event notification\n\r");
			EventCnt_Crc = 0U;
		} else {
			xil_printf("[FAILURE] No CRC error event" \
				" notification received\n\r");
		}
	} else if(Status == CRAM_STATUS_COR_ERR_MASK) {
		xil_printf("[SUCCESS] Correctable error detected \n\r");
		Status = CfrStatusInfo.Status & CRAM_STATUS_ECC_COR_DONE_MASK;
		if (Status == CRAM_STATUS_ECC_COR_DONE_MASK) {
			xil_printf("[SUCCESS] Correction Done \n\r");
			CorErrCount = CfrStatusInfo.ErrCorCnt;
			xil_printf("Total Corrected Error count = %d\n\r", \
					CorErrCount);
			Status = ApiChkErrorCount(IntialCorErrCnt, 1U);
			if (Status == XST_SUCCESS){
				xil_printf("[SUCCESS] Error Count increased" \
					" by 1 as expected\n\r");
			} else {
				xil_printf("[FAILURE] XilSEM failed to" \
					" increase error count\n\r");
			}
		}
		if(EventCnt_UnCorEcc == 0U && EventCnt_Crc == 0U &&
			EventCnt_CorEcc == 1U && EventCnt_IntErr == 0U){
			xil_printf("[SUCCESS] Received Correctable error" \
				" event notification\n\r");
			EventCnt_CorEcc = 0U;
		} else {
			xil_printf("[FAILURE] No Correctable error event" \
				" notification received\n\r");
		}
		ErrIndex = (CorErrCount % 7U);
		if(ErrIndex != 0U){
			--ErrIndex;
		} else{
			ErrIndex = 6U;
		}
		TempA = CfrStatusInfo.ErrAddrL[ErrIndex];
		TempB = CfrStatusInfo.ErrAddrH[ErrIndex];
		ErrBitLoc 	= (TempA & 0x7F0000) >> 16;
		ErrQwordLoc = (TempA & 0xF800000) >> 23;
		ErrFarLoc 	= (TempB & 0x7FFFFF);
		ErrRowLoc 	= (TempB & 0x7800000) >> 23;
		xil_printf("Error is located in Row = %d, FAR = 0x%06x,"
			" Qword = %d, Bit = %d\n\r", ErrRowLoc, ErrFarLoc, \
			ErrQwordLoc, ErrBitLoc);
	} else {
		xil_printf("[FAILURE] XilSEM failed to detect error," \
			" Status = 0x%08x\n\r", CfrStatusInfo.Status);
	}
}
void PrintErrReport ( u32 IntialCorErrCnt ) { XStatus Status = 0U ; XSemCfrStatus CfrStatusInfo = { 0 } ; u32 TempA = 0U ; u32 TempB = 0U ; u32 CorErrCount = 0U ; u32 ErrIndex = 0U ; u32 ErrBitLoc = 0U ; u32 ErrQwordLoc = 0U ; u32 ErrFarLoc = 0U ; u32 ErrRowLoc = 0U ; xil_printf ( " \n \r " ) ; xil_printf ( " \n \r " ) ; xil_printf ( " \n \r " ) ; ( void ) XSem_CmdCfrGetStatus ( & CfrStatusInfo ) ; TempA = ( CRAM_STATUS_COR_ERR_MASK | CRAM_STATUS_CRC_ERR_MASK | CRAM_STATUS_UNCOR_ERR_MASK ) ; Status = CfrStatusInfo . Status & TempA ; if ( Status == CRAM_STATUS_UNCOR_ERR_MASK ) { xil_printf ( " \n \r " ) ; Status = ApiChkErrorCount ( IntialCorErrCnt , 0U ) ; if ( Status == XST_SUCCESS ) { xil_printf ( " \n \r " ) ; } else { xil_printf ( " " " \n \r " ) ; } if ( EventCnt_UnCorEcc == 1U && EventCnt_Crc == 0U && EventCnt_CorEcc == 0U && EventCnt_IntErr == 0U ) { xil_printf ( " " " \n \r " ) ; EventCnt_UnCorEcc = 0U ; } else { xil_printf ( " " " \n \r " ) ; } } else if ( Status == CRAM_STATUS_CRC_ERR_MASK ) { xil_printf ( " \n \r " ) ; Status = ApiChkErrorCount ( IntialCorErrCnt , 0U ) ; if ( Status == XST_SUCCESS ) { xil_printf ( " \n \r " ) ; } else { xil_printf ( " " " \n \r " ) ; } if ( EventCnt_UnCorEcc == 0U && EventCnt_Crc == 1U && EventCnt_CorEcc == 0U && EventCnt_IntErr == 0U ) { xil_printf ( " " " \n \r " ) ; EventCnt_Crc = 0U ; } else { xil_printf ( " " " \n \r " ) ; } } else if ( Status == CRAM_STATUS_COR_ERR_MASK ) { xil_printf ( " \n \r " ) ; Status = CfrStatusInfo . Status & CRAM_STATUS_ECC_COR_DONE_MASK ; if ( Status == CRAM_STATUS_ECC_COR_DONE_MASK ) { xil_printf ( " \n \r " ) ; CorErrCount = CfrStatusInfo . ErrCorCnt ; xil_printf ( " \n \r " , CorErrCount ) ; Status = ApiChkErrorCount ( IntialCorErrCnt , 1U ) ; if ( Status == XST_SUCCESS ) { xil_printf ( " " " \n \r " ) ; } else { xil_printf ( " " " \n \r " ) ; } } if ( EventCnt_UnCorEcc == 0U && EventCnt_Crc == 0U && EventCnt_CorEcc == 1U && EventCnt_IntErr == 0U ) { xil_printf ( " " " \n \r " ) ; EventCnt_CorEcc = 0U ; } else { xil_printf ( " " " \n \r " ) ; } ErrIndex = ( CorErrCount % 7U ) ; if ( ErrIndex != 0U ) { -- ErrIndex ; } else { ErrIndex = 6U ; } TempA = CfrStatusInfo . ErrAddrL [ ErrIndex ] ; TempB = CfrStatusInfo . ErrAddrH [ ErrIndex ] ; ErrBitLoc = ( TempA & 0x7F0000 ) >> 16 ; ErrQwordLoc = ( TempA & 0xF800000 ) >> 23 ; ErrFarLoc = ( TempB & 0x7FFFFF ) ; ErrRowLoc = ( TempB & 0x7800000 ) >> 23 ; xil_printf ( " " " \n \r " , ErrRowLoc , ErrFarLoc , ErrQwordLoc , ErrBitLoc ) ; } else { xil_printf ( " " " \n \r " , CfrStatusInfo . Status ) ; } }
@brief       Verifies and Prints error report
 @param[in]   IntialCorErrCnt : Error count before error injection
@brief Verifies and Prints error report @param [ in ] IntialCorErrCnt : Error count before error injection
/*Check error is detected and corrected*/ /*Check Error count increased as expected or not*/ /*Check Event notification*/ /*Check Error count increased as expected or not*/ /*Check Event notification*/ /*To print and check Corrected Error count*/ /*Check Error count increased as expected or not*/ /*Check Event notification*/ /*To print error location details*/ /* bit is at 22:16 bits of SEM_CRAMERR_ADDRL0 reg */ /* Qword is at 27:23 bits of SEM_CRAMERR_ADDRL0 reg */ /* Frame  is at 19:0 bits of SEM_CRAMERR_ADDRH0 reg */ /* Frame  is at 26:23 bits of SEM_CRAMERR_ADDRH0 reg */