📄 swecc.c
字号:
/*****************************************************************************/
/* */
/* PROJECT : AnyStore II */
/* MODULE : XSR BML */
/* NAME : SW Error Correction Code (Hamming Algorithm) */
/* FILE : SWEcc.cpp */
/* PURPOSE : Implementation of FIL */
/* Guarantee Data Intigrity */
/* */
/*---------------------------------------------------------------------------*/
/* */
/* COPYRIGHT 2003-2006, SAMSUNG ELECTRONICS CO., LTD. */
/* ALL RIGHTS RESERVED */
/* */
/* Permission is hereby granted to licenses of Samsung Electronics */
/* Co., Ltd. products to use or abstract this computer program only in */
/* accordance with the terms of the NAND FLASH MEMORY SOFTWARE LICENSE */
/* AGREEMENT for the sole purpose of implementing a product based on */
/* Samsung Electronics Co., Ltd. products. No other rights to reproduce, */
/* use, or disseminate this computer program, whether in part or in whole, */
/* are granted. */
/* */
/* Samsung Electronics Co., Ltd. makes no representation or warranties */
/* with respect to the performance of this computer program, and */
/* specifically disclaims any responsibility for any damages, */
/* special or consequential, connected with the use of this program. */
/* */
/*---------------------------------------------------------------------------*/
/* */
/* REVISION HISTORY */
/* */
/* - 27/DEC/2002 [Kwangyoon Lee] : first writing */
/* - 15/JUL/2003 [SeWook Na] : code modification */
/* - 10/AUG/2003 [Janghwan Kim] : add codes */
/* - 11/AUG/2003 [Janghwan Kim] : code optimization */
/* - 15/AUG/2003 [Janghwan Kim] : bug fix */
/* - 02/OCT/2003 [Janghwan Kim] : reorganization */
/* - 13/NOV/2003 [Chang JongBaek] : Rewriting with new algorithm */
/* - 26/NOV/2003 [JangHwan Kim] : Reoranization */
/* - 27/NOV/2003 [JangHwan Kim] : Add Gen, Comp function for Spare Array */
/* */
/*---------------------------------------------------------------------------*/
/* */
/* - Make ECC parity code of 512bytes and 3 bytes are represented */
/* And ECC compare & Correction code is also represented */
/* */
/*****************************************************************************/
#include "..\include\Def.h"
#include "..\include\swecc.h"
/*****************************************************************************/
/* Debug Configuration */
/*****************************************************************************/
/*
#undef ECC_DEBUG
#undef ECC_ERR_TRACE
#define ECC_RTL_PRINT(x) XSR_RTL_PRINT(x)
#if defined(ECC_DEBUG)
#define ECC_ERR_PRINT(x) XSR_RTL_PRINT(x)
#define ECC_DBG_PRINT(x) XSR_DBG_PRINT(x)
#else
#if defined(ECC_ERR_TRACE)
#define ECC_DBG_PRINT(x)
#define ECC_ERR_PRINT(x) XSR_RTL_PRINT(x)
#else
#define ECC_DBG_PRINT(x)
#define ECC_ERR_PRINT(x)
#endif
*/
/* #if defined(ECC_ERR_TRACE) */
//#endif /* #if defined(ECC_DEBUG) */
/*****************************************************************************/
/* */
/* NAME */
/* GenEccM */
/* DESCRIPTION */
/* This function generates 3 byte ECC for 512 byte data. */
/* (Software ECC) */
/* PARAMETERS */
/* pEcc */
/* The memory location for given ECC val */
/* pBuf */
/* The memory location for given data */
/* nBW */
/* Data Band Width of the device */
/* RETURN VALUES */
/* none */
/* */
/*****************************************************************************/
void ECC_GenM(U8 *pEcc, U32 *pBuf, U8 nBW)// nBW = 0(8bit), nBW = 1(16bit)
{
U32 nCnt, nTmp;
U32 nEcc = 0;
U32 nCol, nRow = 0;
U32 nCol4 = 0, nCol2 = 0, nCol1 = 0, nColT = 0;
U32 nXorT = 0;
U32 *pDat32 = pBuf;
for(nCnt = 0; nCnt < 16; nCnt++)
{
nCol = *pDat32++;
nTmp = *pDat32++; nCol ^= nTmp; nCol1 ^= nTmp;
nTmp = *pDat32++; nCol ^= nTmp; nCol2 ^= nTmp;
nTmp = *pDat32++; nCol ^= nTmp; nCol1 ^= nTmp; nCol2 ^= nTmp;
nTmp = *pDat32++; nCol ^= nTmp; nCol4 ^= nTmp;
nTmp = *pDat32++; nCol ^= nTmp; nCol1 ^= nTmp; nCol4 ^= nTmp;
nTmp = *pDat32++; nCol ^= nTmp; nCol2 ^= nTmp; nCol4 ^= nTmp;
nTmp = *pDat32++; nCol ^= nTmp; nCol1 ^= nTmp; nCol2 ^= nTmp; nCol4 ^= nTmp;
nColT ^= nCol;
nTmp = (nCol >> 16) ^ nCol;
nTmp = (nTmp >> 8) ^ nTmp;
nTmp = (nTmp >> 4) ^ nTmp;
nTmp = ((nTmp >> 2) ^ nTmp) & 0x03;
if ((nTmp == 0x01) || (nTmp == 0x02))
{
nRow ^= nCnt;
nXorT ^= 0x01;
}
}
if (nBW == BW_X08)
{
nTmp = (nCol4 >> 16) ^ nCol4; /********/
nTmp = (nTmp << 8) ^ nTmp; /* */
nTmp = (nTmp >> 4) ^ nTmp; /* p128 */
nTmp = (nTmp >> 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x200; /********/
nTmp = (nCol2 >> 16) ^ nCol2; /********/
nTmp = (nTmp >> 8) ^ nTmp; /* */
nTmp = (nTmp << 4) ^ nTmp; /* p64 */
nTmp = (nTmp << 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x80; /********/
nTmp = (nCol1 >> 16) ^ nCol1; /********/
nTmp = (nTmp >> 8) ^ nTmp; /* */
nTmp = (nTmp << 4) ^ nTmp; /* p32 */
nTmp = (nTmp >> 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x20; /********/
nTmp = (nColT & 0xFFFF0000); /********/
nTmp = (nTmp >> 16); /* */
nTmp = (nTmp >> 8) ^ nTmp; /* p16 */
nTmp = (nTmp >> 4) ^ nTmp; /* */
nTmp = (nTmp << 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x08; /********/
nTmp = (nColT & 0xFF00FF00); /********/
nTmp = (nTmp >> 16) ^ nTmp; /* */
nTmp = (nTmp >> 8); /* p8 */
nTmp = (nTmp >> 4) ^ nTmp; /* */
nTmp = (nTmp >> 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x02; /********/
nTmp = (nColT & 0xF0F0F0F0); /********/
nTmp = (nTmp << 16) ^ nTmp; /* */
nTmp = (nTmp >> 8) ^ nTmp; /* p4 */
nTmp = (nTmp << 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x800000; /********/
nTmp = (nColT & 0xCCCCCCCC); /********/
nTmp = (nTmp << 16) ^ nTmp; /* */
nTmp = (nTmp >> 8) ^ nTmp; /* p2 */
nTmp = (nTmp << 4) ^ nTmp; /* */
nTmp = (nTmp >> 2); /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x200000; /********/
nTmp = (nColT & 0xAAAAAAAA); /********/
nTmp = (nTmp << 16) ^ nTmp; /* */
nTmp = (nTmp >> 8) ^ nTmp; /* p1 */
nTmp = (nTmp >> 4) ^ nTmp; /* */
nTmp = (nTmp << 2) ^ nTmp; /* */
nEcc |= (nTmp & 0x80000); /********/
nEcc |= (nRow & 0x01) << 11; /* p256 */
nEcc |= (nRow & 0x02) << 12; /* p512 */
nEcc |= (nRow & 0x04) << 13; /* p1024*/
nEcc |= (nRow & 0x08) << 14; /* p2048*/
}
else /* BW_X16 */
{
nTmp = (nCol4 >> 16) ^ nCol4; /********/
nTmp = (nTmp >> 8) ^ nTmp; /* */
nTmp = (nTmp << 4) ^ nTmp; /* p128 */
nTmp = (nTmp << 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x80; /********/
nTmp = (nCol2 >> 16) ^ nCol2; /********/
nTmp = (nTmp >> 8) ^ nTmp; /* */
nTmp = (nTmp << 4) ^ nTmp; /* p64 */
nTmp = (nTmp >> 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x20; /********/
nTmp = (nCol1 >> 16) ^ nCol1; /********/
nTmp = (nTmp >> 8) ^ nTmp; /* */
nTmp = (nTmp >> 4) ^ nTmp; /* p32 */
nTmp = (nTmp << 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x08; /********/
nTmp = (nColT & 0xFFFF0000); /********/
nTmp = (nTmp >> 16); /* */
nTmp = (nTmp >> 8) ^ nTmp; /* p16 */
nTmp = (nTmp >> 4) ^ nTmp; /* */
nTmp = (nTmp >> 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x02; /********/
nTmp = (nColT & 0xFF00FF00); /********/
nTmp = (nTmp << 16) ^ nTmp; /* */
nTmp = (nTmp >> 8); /* p8 */
nTmp = (nTmp << 4) ^ nTmp; /* */
nTmp = (nTmp << 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x800000; /********/
nTmp = (nColT & 0xF0F0F0F0); /********/
nTmp = (nTmp << 16) ^ nTmp; /* */
nTmp = (nTmp >> 8) ^ nTmp; /* p4 */
nTmp = (nTmp >> 2) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x200000; /********/
nTmp = (nColT & 0xCCCCCCCC); /********/
nTmp = (nTmp << 16) ^ nTmp; /* */
nTmp = (nTmp >> 8) ^ nTmp; /* p2 */
nTmp = (nTmp >> 4) ^ nTmp; /* */
nEcc |= ((nTmp << 1) ^ nTmp) & 0x80000; /********/
nTmp = (nColT & 0xAAAAAAAA); /********/
nTmp = (nTmp << 16) ^ nTmp; /* */
nTmp = (nTmp >> 8) ^ nTmp; /* p1 */
nTmp = (nTmp >> 4) ^ nTmp; /* */
nTmp = (nTmp >> 2) ^ nTmp; /* */
nEcc |= (nTmp & 0x20000); /********/
nEcc |= (nRow & 0x01) << 9; /* p256 */
nEcc |= (nRow & 0x02) << 10; /* p512 */
nEcc |= (nRow & 0x04) << 11; /* p1024*/
nEcc |= (nRow & 0x08) << 12; /* p2048*/
}
if (nXorT)
{
nEcc |= (nEcc ^ 0x00AAAAAA) >> 1;
}
else
{
nEcc |= (nEcc >> 1);
}
nEcc = ~nEcc;
*(pEcc + 2) = (U8)(nEcc >> 16);
*(pEcc + 1) = (U8)(nEcc >> 8);
*(pEcc + 0) = (U8)(nEcc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -