?? system.c
字號:
/*****************************************************************************/
/* */
/* PROJECT : PocketStoreII v1.0.0_build001 */
/* FILE : SYSTEM.c */
/* PURPOSE : This file implements Windows CE Block device driver interface */
/* for supporting BIN file system. */
/* */
/*---------------------------------------------------------------------------*/
/* */
/* COPYRIGHT 2003 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 */
/* */
/* - 20-JAN-2003 [SongHo Yoon]: first writing */
/* - 14-APR-2004 [Janghwan Kim]: PocketStoreII migration */
/* */
/*****************************************************************************/
#include <windows.h>
#include <bldver.h>
#include <windev.h>
#include <types.h>
#include <excpt.h>
#include <tchar.h>
#include <devload.h>
#include <diskio.h>
//#include <WMRTypes.h>
typedef UINT32 BOOL32;
#include <MkMBR.h>
//#include <PSII.h>
#include <VFLBuffer.h>
#include <VFL.h>
#include <FIL.h>
#include <HALWrapper.h>
#include "CacheBuf.h"
#include <BIBDRVINFO.h>
#if (CE_MAJOR_VER > 0x0003)
#include <storemgr.h>
#include <pm.h>
#endif //(CE_MAJOR_VER > 0x0003)
extern VOID GetNandInfo(NAND_INFO *pNandInfo);
NAND_INFO stNandInfo;
// by HMSEO,,, this definitions are have to matched with defined in WMRConfig.h ... Waring....
#define FALSE32 (BOOL32) 0
#define TRUE32 (BOOL32) 1
#define BYTES_PER_SECTOR 512
#define WMR_RETURN_VALUE(err, maj, min) (INT32)(((UINT32)((err) & 0x00000001) << 31) | \
((UINT32)((maj) & 0x00007FFF) << 16) | \
(UINT32)((min) & 0x0000FFFF))
// by HMSEO,,, because,,, driver can't know this settings....
/*****************************************************************************/
/* Debug Definitions */
/*****************************************************************************/
#define BIBDRV_ERR_MSG_ON 1
#define BIBDRV_LOG_MSG_ON 0
#define BIBDRV_INF_MSG_ON 0
#define BIBDRV_RTL_PRINT(x) RETAILMSG(1, x)
#if BIBDRV_ERR_MSG_ON
#define BIBDRV_ERR_PRINT(x) RETAILMSG(1, x)
#else
#define BIBDRV_ERR_PRINT(x)
#endif /* #if BIBDRV_ERR_MSG_ON */
#if BIBDRV_LOG_MSG_ON
#define BIBDRV_LOG_PRINT(x) RETAILMSG(1, x)
#else
#define BIBDRV_LOG_PRINT(x)
#endif /* #if BIBDRV_LOG_MSG_ON */
#if BIBDRV_INF_MSG_ON
#define BIBDRV_INF_PRINT(x) RETAILMSG(1, x)
#else
#define BIBDRV_INF_PRINT(x)
#endif /* #if BIBDRV_INF_MSG_ON */
/*****************************************************************************/
/* Global Variables */
/*****************************************************************************/
/* Debug Zones.
*/
#ifdef DEBUG
#define DBG_INIT 0x0001
#define DBG_OPEN 0x0002
#define DBG_READ 0x0004
#define DBG_WRITE 0x0008
#define DBG_CLOSE 0x0010
#define DBG_IOCTL 0x0020
#define DBG_THREAD 0x0040
#define DBG_EVENTS 0x0080
#define DBG_CRITSEC 0x0100
#define DBG_FLOW 0x0200
#define DBG_IR 0x0400
#define DBG_NOTHING 0x0800
#define DBG_ALLOC 0x1000
#define DBG_FUNCTION 0x2000
#define DBG_WARNING 0x4000
#define DBG_ERROR 0x8000
DBGPARAM dpCurSettings = {
TEXT("Serial"), { TEXT("Init"),
TEXT("Open"),
TEXT("Read"),
TEXT("Write"),
TEXT("Close"),
TEXT("Ioctl"),
TEXT("Error")},
0
};
#endif
/*****************************************************************************/
/* Imported variable declarations */
/*****************************************************************************/
/*****************************************************************************/
/* Imported function declarations */
/*****************************************************************************/
/*****************************************************************************/
/* Local #define */
/*****************************************************************************/
//#define _SUPPORT_HAL_WRAPPER_
#undef _BIBDRV_CACHING_SECTORS_
#undef _READ_PERFORMANCE_MEASUREMENT_
#undef _BIBDRV_SECTOR_ACCESS_STATISTIC_
//#undef _BIBDRV_MBR_DEBUG_
#define _BIBDRV_MBR_DEBUG_
/*****************************************************************************/
// Local constant definitions
/*****************************************************************************/
/*****************************************************************************/
// Local typedefs
/*****************************************************************************/
#if defined(_BIBDRV_SECTOR_ACCESS_STATISTIC_)
typedef struct _SEC_ACCESS_STATISTIC
{
UINT nSecNum;
UINT nSecHit;
} SEC_ACCESS_STATISTIC;
#endif //_BIBDRV_SECTOR_ACCESS_STATISTIC_
typedef struct _DISK
{
struct _DISK *pd_next;
CRITICAL_SECTION d_DiskCardCrit; // guard access to global state and card
HANDLE hDevice; // activate Handle
DISK_INFO d_DiskInfo; // for DISK_IOCTL_GET/SETINFO
DWORD d_OpenCount; // open ref count
LPWSTR d_ActivePath; // registry path to active key for this device
UINT nVol; // Volume Number
BOOL bIsBMLOpen; // if BML_Open operation successes,
// it's TRUE otherwize it's FALSE
UINT nBaseVsn; // start Virtual Sector Number of area,
// which is reserved for OS regions
#if defined(_BIBDRV_CACHING_SECTORS_)
UINT nNumOfSecCache;
BIBDRV_CACHEBUF *pCacheBuf; // pointer of CacheBuf for caching sectors.
#endif //(_BIBDRV_CACHING_SECTORS_)
#if defined(_BIBDRV_SECTOR_ACCESS_STATISTIC_)
SEC_ACCESS_STATISTIC *pSecHitStat;
#endif //(_BIBDRV_SECTOR_ACCESS_STATISTIC_)
} DISK, *PDISK;
/*****************************************************************************/
// Local variables
/*****************************************************************************/
static CRITICAL_SECTION gDiskCrit;
static PDISK gDiskList; // initialized to 0 in bss
/*****************************************************************************/
// Local function prototypes
/*****************************************************************************/
static HKEY OpenDriverKey(LPTSTR ActiveKey);
static BOOL GetFolderName(PDISK pDisk, LPWSTR FolderName, DWORD cBytes, DWORD *pcBytes);
static BOOL GetFSDName(PDISK pDisk, LPWSTR FSDName, DWORD cBytes, DWORD *pcBytes);
#if (CE_MAJOR_VER > 0x0003)
static BOOL GetDeviceInfo(PDISK pDisk, PSTORAGEDEVICEINFO psdi);
#endif //(CE_MAJOR_VER > 0x0003)
static VOID CloseDisk (PDISK pDisk);
static BOOL RequestReadSecToHAL (PDISK pDisk, UINT nSecNum, UCHAR *pBuf);
static DWORD DoDiskRead (PDISK pDisk, PVOID pData);
static DWORD GetDiskInfo (PDISK pDisk, PDISK_INFO pInfo);
static DWORD SetDiskInfo (PDISK pDisk, PDISK_INFO pInfo);
static PDISK CreateDiskObject (VOID);
static BOOL IsValidDisk (PDISK pDisk);
static BOOL InitializeNAND (PDISK pDisk);
static BOOL InitDisk (PDISK pDisk, LPTSTR ActiveKey);
/*****************************************************************************/
// Function definitions
/*****************************************************************************/
#if defined(_READ_PERFORMANCE_MEASUREMENT_)
#define WT_PRESCALER (0x00)
#define WT_CLK_DIVISION (0x01)
UINT nTotalBootTime = 0;
/*****************************************************************************/
/* */
/* NAME */
/* WatchTimerStart */
/* DESCRIPTION */
/* This function starts watchdog timer */
/* PARAMETERS */
/* none */
/* RETURN VALUES */
/* none */
/* NOTES */
/* This function should be called WatchTimerStop() with a pair */
/*****************************************************************************/
static void
WatchTimerStart(void)
{
WATCHreg *pstWDog = (WATCHreg *) WATCH_BASE;
pstWDog->rWTCON = (WT_PRESCALER << 8) | /* The prescaler value => 63 + 1 */
(0x00 << 6) | /* Reserved */
(0x00 << 5) | /* Timer enable or disable */
(WT_CLK_DIVISION << 3) | /* The clock division factor => 32 */
(0x00 << 2) | /* Disable bit of interrupt */
(0x00 << 1) | /* Reserved */
(0x00 << 0); /* Disable the reset function of timer */
pstWDog->rWTDAT = 0xFFFF;
pstWDog->rWTCNT = 0xFFFF;
pstWDog->rWTCON = (WT_PRESCALER << 8) | /* The prescaler value => 63 + 1 */
(0x00 << 6) | /* Reserved */
(0x01 << 5) | /* Timer enable or disable */
(WT_CLK_DIVISION << 3) | /* The clock division factor => 32 */
(0x00 << 2) | /* Disable bit of interrupt */
(0x00 << 1) | /* Reserved */
(0x00 << 0); /* Disable the reset function of timer */
}
/*****************************************************************************/
/* */
/* NAME */
/* WatchTimerStop */
/* DESCRIPTION */
/* This function stops watchdog timer */
/* PARAMETERS */
/* none */
/* RETURN VALUES */
/* none */
/* NOTES */
/* This function should be called WatchTimerStart() with a pair */
/*****************************************************************************/
static void
WatchTimerStop(void)
{
UINT Cnt, Dat;
UINT dwUnitCnt;
UINT dwPrescaler;
UINT dwWGPref;
WATCHreg *pstWDog = (WATCHreg *) WATCH_BASE;
UINT nMTime;
pstWDog->rWTCON = (WT_PRESCALER << 8) | /* The prescaler value => 63 + 1 */
(0x00 << 6) | /* Reserved */
(0x00 << 5) | /* Timer enable or disable */
(WT_CLK_DIVISION << 3) | /* The clock division factor => 32*/
(0x00 << 2) | /* Disable bit of interrupt */
(0x00 << 1) | /* Reserved */
(0x00 << 0); /* Disable the reset function of timer */
Cnt = pstWDog->rWTCNT;
Dat = pstWDog->rWTDAT;
dwPrescaler = (WT_PRESCALER + 1) * (16 << WT_CLK_DIVISION);
dwWGPref = S2410PCLK / dwPrescaler;
dwUnitCnt = 1000000000 / dwWGPref; // The count unit is NANO second.
nMTime = dwUnitCnt * (Dat - Cnt);
nTotalBootTime = nTotalBootTime + nMTime / 1000;
RETAILMSG(1, (TEXT(" Diff = %4d, %8d nsec, Total = %9d usec\r\n"),
Dat - Cnt, nMTime, nTotalBootTime));
}
#endif //(_READ_PERFORMANCE_MEASUREMENT_)
/*****************************************************************************/
/* */
/* NAME */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -