FreeNand_Ecc

dllmain

dllmain.cpp

File5.42 KB0 downloads1/12/2026

Technical details

Type
File
Format
CPP
Size
5.42 KB
Added
1/12/2026
Downloads
0

About this file

File dllmain in CPP format, 5.42 KB. Catalog path: NandDLL_C_Source / Nand_Ecc. File details, compatibility and download access.

from catalog

Содержимое файла

Кодировка: windows-1251
// dllmain.cpp : ¶ЁТе DLL У¦УГіМРтµДИлїЪµгЎЈ
#include "stdafx.h"
#include "Nand_Ecc.h"

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

NAND_PARAM_STRUCT NandParam;  // Courrent IC Parameter information 
							  //¶ЁТеТ»ёцИ«ѕЦµДРѕЖ¬ІОКэ±дБїЈ¬РѕЖ¬µДІОКэЦµґУЦчіМРтґ«Ил
unsigned int iBlockIndex[4];  //¶а»ъ±аіМК±·Ц±рґ¦Ан
 /***************************************************************************************************************
 * єЇКэ№¦ДЬЈєЦ»КЗґтїЄDLLОДјюК±µчУГТ»ґОЈ¬їЙФЪґЛЅшРРИ«ѕЦ±дБїіхКј»Ї
 ***************************************************************************************************************/

extern "C" USER_NAND_API int SetNandParam(NAND_PARAM_STRUCT * pNandParam)
{
	NandParam = *pNandParam;  // this is Chip's Params input from APP.
	//Add Init your code here

	return 0;//must return 0 , error when other value returned
}
/***************************************************************************************************************
* єЇКэ№¦ДЬЈєГїґОРґИлТ»ёцКэѕЭїйЈЁBLOCKЈ©З°µчУГ
*
* unsigned char *pBlockBuff : ФґКэѕЭЦёХл  size: (NandParam.PageSize + NandParam.SpareSize)*NandParam.PagePerBlock
*       unsigned char *pBBT ЈєBBT УГ»§ЧФ¶ЁТе»µїй±нЦёХл, size: Н¬ЙП
*unsigned int iCourrentBlockЈєµ±З°ТЄРґИлµДїйЛчТэєЕ   
*       unsigned int iDeviceЈєµ±З°µчУГєЇКэµДЙи±ёєЕЈ¬¶а»ъ±аіМК±ЦµОЄ 0-3,µҐ»ъ±аіМК±КјЦХОЄ0
******************************************************************************************************************/

extern "C" USER_NAND_API int PreProcessBlock(unsigned char * pBlockBuff, unsigned char * pBBT, unsigned int iCourrentBlock, unsigned int iDevice)
{
	unsigned int iPage,i;
	unsigned char ECCCode[3];
	unsigned char * pPage;
	unsigned char * pSpare;
	iBlockIndex[iDevice&0x03] = iCourrentBlock;  //±ЈґжПлТЄРґИлµДїйєЕ
	//if (iCourrentBlock == 0)
	//{  //АэЈєИз№ыДгПлФЪµЪ0їй·ЕИлРтБРєЕ add serials code here

	//}
	pSpare = pBlockBuff;
	pSpare += NandParam.PageSize;   //ponit to spare of the  first page
	pPage = pBlockBuff;             //ponit to data of the  first page
	for (iPage = 0; iPage < NandParam.PagePerBlock; iPage++)// cal ECC of all pages
	{
		/**************************************************************************************
		*  Spare Area in NAND FLASH  Note: this example just for 512 bytes + 16 bytes
		***************************************************************************************
		*  0-4th bytes   |   5th     |       6-8th       |   9-12      |    13-15th       |
		*    reserved    | Bad Mark  | ECC0 | ECC1 |ECC2 |  Reserved   |ECC0 | ECC1 |ECC2 |
		***************************************************************************************/
		for (i = 0; i < NandParam.SpareSize; i++)pSpare[i] = 0

Similar and related files