⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otp.c

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************/
/*                                                                           */
/* PROJECT : PocketStoreII                                                   */
/* FILE    : OTP.c                                                           */
/* PURPOSE : the routine get Unique ID from NAND flash memory                */
/*                                                                           */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/*               COPYRIGHT 2006 SAMSUNG ELECTRONICS CO., LTD.                */
/*                          ALL RIGHTS RESERVED                              */
/*                                                                           */
/*   Permission is hereby granted to licensees of Samsung Electronics        */
/*   Co., Ltd. products to use or abstract this computer program 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                                                          */
/*                                                                           */
/*   03-FEB-2006 [Hyunsoo Cho] : OTP functions for user application          */
/*   03-JAN-2007 [koogi Cho] : 1st block OTP added, the page number of 		 */
/*   							OTP user area changed          				 */
/*                                                                           */
/*****************************************************************************/
/*****************************************************************************/
/* Header File Include                                                       */
/*****************************************************************************/
#include <windows.h>
#include <XSR.h>
#include <HalWrapper.h>

/*****************************************************************************/
/* Global Variable Declaration                                               */
/*****************************************************************************/
#define USER_OTP_PAGE_NUM	50

/*****************************************************************************/
/* Debug Definitions                                                         */
/*****************************************************************************/
#define OTP_RTL_PRINT(x)           PSII_RTL_PRINT(x)

#if GETUID_ERR_MSG_ON
#define OTP_ERR_PRINT(x)           PSII_RTL_PRINT(x)
#else
#define OTP_ERR_PRINT(x)        
#endif /* #if GETUID_ERR_MSG_ON */

#if OTP_LOG_MSG_ON
#define OTP_LOG_PRINT(x)           PSII_DBG_PRINT(x)
#else
#define OTP_LOG_PRINT(x)        
#endif  /* #if OTP_LOG_MSG_ON */

#if OTP_INF_MSG_ON
#define OTP_INF_PRINT(x)           PSII_DBG_PRINT(x)
#else
#define OTP_INF_PRINT(x)        
#endif  /* #if OTP_INF_MSG_ON */


/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      OndOTPRead                                                           */
/*                                                                           */
/* DESCRIPTION                                                               */
/*      Read data in OTP block                                               */
/*                                                                           */
/* PARAMETERS                                                                */
/*      nPsn                                                                 */
/*          Sector index to be read                                          */
/*      pData                                                                */
/*          Memory buffer to be written                                      */
/*                                                                           */
/* RETURN VALUES                                                             */
/*      If it successes, it returns TRUE. otherwize it returns FALSE         */
/*                                                                           */
/* NOTES                                                                     */
/*      We only read 1 sector of OTP main area of the OneNAND                */
/*      pData should be pointer that points 512Bytes                         */
/*                                                                           */
/*****************************************************************************/
BOOL
OndOTPRead( UINT32 nPsn, UCHAR* pData )
{
	INT32	nErr;
	UINT32  nVol = 0;
	UINT32	nScts = 0;
    UINT32  nResult = 0;
    UINT32  nFlag;
    BMLPacket	stPacket;
	
	OTP_LOG_PRINT( (TEXT("[OTP: IN] ++OndOTPRead()\r\n")));
	
	nFlag = LLD_FLAG_SYNC_OP;
	if ( nPsn >= 4*USER_OTP_PAGE_NUM )
	{
		nFlag = nFlag | LLD_FLAG_ECC_OFF;
	}
	else
	{
		nFlag = nFlag | LLD_FLAG_ECC_ON;
	}
	
	if ( pData == NULL )
	{
		OTP_ERR_PRINT((L"[OTP:ERR]  Invalid pointer (Null pointer)\r\n"));
		return FALSE32;
	}
	
	nScts = 1;			// fixed to 1 sector

    do {
    	
        /* ONLD_Read */
        stPacket.nVol       = nVol;
        stPacket.nCtrlCode  = PS_HAL_LLD_OTP_READ;
        stPacket.nVbn       = 0;      // Not used
        stPacket.nVsn       = nPsn;
        stPacket.nNumOfScts = nScts;
        stPacket.nOpFlag    = nFlag;
        stPacket.pMBuf      = pData;
        stPacket.pSBuf      = NULL;
        stPacket.pstMEBArg	= 0;				// by kathy
    
        nErr = KernelIoControl(IOCTL_POCKETSTOREII_CMD,  /* IO Control Code  */
                        &stPacket,              /* Input buffer     */
                        sizeof(BMLPacket),
                        NULL,                   /* Output buffer    */
                        0, 
                        (LPDWORD)(&nResult));
        if (nErr != TRUE)
        {
            OTP_ERR_PRINT( (TEXT("[OTP:ERR]  KernelIoControl() failure. ERR Code=%x\r\n"), nResult) );
            return FALSE32;
        }
    
    } while(0);

    OTP_LOG_PRINT( (TEXT("[OTP:OUT]  -- OndOTPRead\r\n")) );

    return TRUE32;
}


/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      OndOTPWrite                                                          */
/*                                                                           */
/* DESCRIPTION                                                               */
/*      Write data in OTP block                                              */
/*                                                                           */
/* PARAMETERS                                                                */
/*      nPsn                                                                 */
/*          Sector index to be write                                         */
/*      pData                                                                */
/*          Memory buffer to be read                                         */
/*                                                                           */
/* RETURN VALUES                                                             */
/*      If it successes, it returns TRUE. otherwize it returns FALSE         */
/*                                                                           */
/* NOTES                                                                     */
/*      We only write 1 sector of OTP main area of the OneNAND               */
/*      pData should be pointer that points 512Bytes                         */
/*                                                                           */
/*****************************************************************************/
BOOL
OndOTPWrite( UINT nPsn, UCHAR* pData )
{
	INT32   nErr;
	UINT32  nVol = 0;
	UINT32	nScts = 0;
    UINT32  nResult = 0;
    BMLPacket	stPacket;

	OTP_LOG_PRINT( (TEXT("[OTP: IN] ++OndOTPWrite()\r\n")));
	
	if ( nPsn >= 4*USER_OTP_PAGE_NUM )
	{
		OTP_ERR_PRINT( (TEXT("[OTP:ERR]  Invalid nPsn (Not in OTP user area)\r\n")) );
		return FALSE32;
	}

	if ( pData == NULL )
	{
		OTP_ERR_PRINT((L"[OTP:ERR]  Invalid pointer (Null pointer)\r\n"));
		return FALSE32;
	}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -