XilinxProcessorIPLib/drivers/nandps/src/xnandps.c
static int XNandPs_EccCorrect(u8 *Buf, u8 *EccCalc, u8 *EccCode)
{
	u8 BitPos;
	u32 BytePos;
	u16 EccOdd, EccEven;
	u16 ReadEccLow, ReadEccHigh;
	u16 CalcEccLow, CalcEccHigh;

	/*
	 * Lower 12 bits of ECC Read
	 */
	ReadEccLow = (EccCode[0] | (EccCode[1] << 8)) & 0xfff;
	/*
	 * Upper 12 bits of ECC Read
	 */
	ReadEccHigh = ((EccCode[1] >> 4) | (EccCode[2] << 4)) & 0xfff;

	/*
	 * Lower 12 bits of ECC calculated
	 */
	CalcEccLow = (EccCalc[0] | (EccCalc[1] << 8)) & 0xfff;
	/*
	 * Upper 12 bits of ECC Calculated
	 */
	CalcEccHigh = ((EccCalc[1] >> 4) | (EccCalc[2] << 4)) & 0xfff;

	EccOdd = ReadEccLow ^ CalcEccLow;
	EccEven = ReadEccHigh ^ CalcEccHigh;

	/*
	 * No Error
	 */
	if ((EccOdd == 0) && (EccEven == 0)) {
		return XST_SUCCESS;
	}

	/*
	 * Single bit error, correct it
	 */
	if (EccOdd == (~EccEven & 0xfff)) {
		BytePos = (EccOdd >> 3) & XNANDPS_ECC_CORRECT_BYTE_MASK;
		BitPos = EccOdd & XNANDPS_ECC_CORRECT_BIT_MASK;
		/*
		 * Toggling error bit
		 */
		Buf[BytePos] ^= (1 << BitPos);
		return XST_SUCCESS;
	}

	/*
	 * Parity error
	 */
	if (OneHot((EccOdd | EccEven)) == XST_SUCCESS) {
		return XST_SUCCESS;
	}

	/*
	 * Multiple bit errors
	 */
	return XST_FAILURE;
}
/*****************************************************************************/
/**
*
* This function corrects the ECC errors.
*
* @param	Buf is the buffer which holds the data read from the page.
* @param	EccCalc is the calculated ECC value.
* @param	EccCode is the ECC read from the spare area.
*
* @return
*		- XST_SUCCESS if the ECC error is corrected.
*		- XST_FAILURE if the ECC error is not corrected.
*
* @note		None
*
******************************************************************************/
This function corrects the ECC errors.
This function corrects the ECC errors .
static int XNandPs_EccCorrect(u8 *Buf, u8 *EccCalc, u8 *EccCode)
{
	u8 BitPos;
	u32 BytePos;
	u16 EccOdd, EccEven;
	u16 ReadEccLow, ReadEccHigh;
	u16 CalcEccLow, CalcEccHigh;
	ReadEccLow = (EccCode[0] | (EccCode[1] << 8)) & 0xfff;
	ReadEccHigh = ((EccCode[1] >> 4) | (EccCode[2] << 4)) & 0xfff;
	CalcEccLow = (EccCalc[0] | (EccCalc[1] << 8)) & 0xfff;
	CalcEccHigh = ((EccCalc[1] >> 4) | (EccCalc[2] << 4)) & 0xfff;
	EccOdd = ReadEccLow ^ CalcEccLow;
	EccEven = ReadEccHigh ^ CalcEccHigh;
	if ((EccOdd == 0) && (EccEven == 0)) {
		return XST_SUCCESS;
	}
	if (EccOdd == (~EccEven & 0xfff)) {
		BytePos = (EccOdd >> 3) & XNANDPS_ECC_CORRECT_BYTE_MASK;
		BitPos = EccOdd & XNANDPS_ECC_CORRECT_BIT_MASK;
		Buf[BytePos] ^= (1 << BitPos);
		return XST_SUCCESS;
	}
	if (OneHot((EccOdd | EccEven)) == XST_SUCCESS) {
		return XST_SUCCESS;
	}
	return XST_FAILURE;
}
static int XNandPs_EccCorrect ( u8 * Buf , u8 * EccCalc , u8 * EccCode ) { u8 BitPos ; u32 BytePos ; u16 EccOdd , EccEven ; u16 ReadEccLow , ReadEccHigh ; u16 CalcEccLow , CalcEccHigh ; ReadEccLow = ( EccCode [ 0 ] | ( EccCode [ 1 ] << 8 ) ) & 0xfff ; ReadEccHigh = ( ( EccCode [ 1 ] >> 4 ) | ( EccCode [ 2 ] << 4 ) ) & 0xfff ; CalcEccLow = ( EccCalc [ 0 ] | ( EccCalc [ 1 ] << 8 ) ) & 0xfff ; CalcEccHigh = ( ( EccCalc [ 1 ] >> 4 ) | ( EccCalc [ 2 ] << 4 ) ) & 0xfff ; EccOdd = ReadEccLow ^ CalcEccLow ; EccEven = ReadEccHigh ^ CalcEccHigh ; if ( ( EccOdd == 0 ) && ( EccEven == 0 ) ) { return XST_SUCCESS ; } if ( EccOdd == ( ~ EccEven & 0xfff ) ) { BytePos = ( EccOdd >> 3 ) & XNANDPS_ECC_CORRECT_BYTE_MASK ; BitPos = EccOdd & XNANDPS_ECC_CORRECT_BIT_MASK ; Buf [ BytePos ] ^= ( 1 << BitPos ) ; return XST_SUCCESS ; } if ( OneHot ( ( EccOdd | EccEven ) ) == XST_SUCCESS ) { return XST_SUCCESS ; } return XST_FAILURE ; }
This function corrects the ECC errors.
This function corrects the ECC errors .
/*
	 * Lower 12 bits of ECC Read
	 */ /*
	 * Upper 12 bits of ECC Read
	 */ /*
	 * Lower 12 bits of ECC calculated
	 */ /*
	 * Upper 12 bits of ECC Calculated
	 */ /*
	 * No Error
	 */ /*
	 * Single bit error, correct it
	 */ /*
		 * Toggling error bit
		 */ /*
	 * Parity error
	 */ /*
	 * Multiple bit errors
	 */