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

📄 nor.h

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on
// your install media.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004,	Motorola Inc. All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004-2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//-----------------------------------------------------------------------------
//
// Header: nor.h
//
// Provides flash library common definitions.
//
// NOTES:
// Manufacturer specific low level flash driver interface.
// *******************************************************
// Any low level driver must support at least the following:
// 1. IsFlashSupported
// 3. Program
// 4. EraseBlock
// Set non supported function pointers to NULL.
// NOTES:
// 1. ll driver must enclose the Program, EraseSector & erase chip functions
// within RelocateStart and RelocateEnd to facilitate relocation of these 
// functions out of flash. 
//
// 2. The FUNCTIONS MUST BE ADDED IN LINKORDER.TXT in order to force the 
// function link order.
//
// 3. The above functions MUST BE SELF-CONTAINED, for relocation purposes.
// Any functions used by these functions must also be within RelocateStart 
// and RelocateEnd and added in linkorder.txt.
//
// 4. Flash must be restored to read mode before ll driver functions exit.
//
// The ll driver must use as min of OS services as possible so as to enable
// The NOR flash library to be used where there is no OS services available, 
// and for relocation. OS service calls should be enclosed within
// #ifdef USE_OS_SERVICES blocks.
//
//------------------------------------------------------------------------------
#ifndef	__MX27_NORFLASH_NOR_H__
#define	__MX27_NORFLASH_NOR_H_

#ifdef __cplusplus
extern "C" {
#endif

//------------------------------------------------------------------------------
// Defines
#define ZONE_HAL            1

#ifndef ZONE_INFO
#define ZONE_INFO           0
#else
#endif

#ifndef ZONE_FUNCTION
#define ZONE_FUNCTION       0
#else
#endif

#ifndef ZONE_ERROR
#define ZONE_ERROR          1
#else
#endif

// Low level flash driver debug defines
#define ZONE_HAL_INFO       (ZONE_HAL && ZONE_INFO)
#define ZONE_HAL_FUNCTION   (ZONE_HAL && ZONE_FUNCTION)
#define ZONE_HAL_ERROR      (ZONE_ERROR)

#ifdef DEBUG
#define PROGRESSMSG         DEBUGMSG
#else
#define PROGRESSMSG         RETAILMSG
#endif

// Polling timeout const
#define CHECK_STATUS_TIMEOUT    0x00FFFFFF

// Basic read/write macros.
#define WRITE_ULONG(ptr, ul)    *(volatile ULONG *)(ptr) = (ULONG)(ul)
#define READ_ULONG(ptr)         (*(volatile ULONG *)(ptr))
#define WRITE_USHORT(ptr, us)   *(volatile USHORT *)(ptr) = (USHORT)(us)
#define READ_USHORT(ptr)        (*(volatile USHORT *)(ptr))
#define WRITE_UCHAR(ptr, uc)    *(volatile UCHAR *)(ptr) = (UCHAR)(uc)
#define READ_UCHAR(ptr)         (*(volatile UCHAR *)(ptr))

// Flash read/write macros
// For 16 bits mode devices
#define WR_FLASH_16(paired, ptr, val) \
    do { \
        if (paired) \
            WRITE_ULONG(ptr, (ULONG)val); \
        else \
            WRITE_USHORT(ptr, (USHORT)val); \
    } while (0)
    
#define WR_FLASH_REG_16(paired, ptr, cmd) \
    do { \
        if (paired) \
            WRITE_ULONG(ptr, (ULONG)((cmd << 16) | cmd) ); \
        else \
            WRITE_USHORT(ptr, (USHORT)cmd); \
    } while (0)
    
#define WR_FLASH_REG_INDEXED16(paired, ptr, offset, cmd) \
    do { \
        if (paired) \
            WRITE_ULONG((ULONG *)ptr + offset, (ULONG)((cmd << 16) | cmd)); \
        else \
            WRITE_USHORT((USHORT *)ptr + offset, (USHORT)cmd); \
    } while (0)
    
#define CHECK_FLASH_STATUS_16(paired, ptr, stat) \
    (paired ? ((READ_ULONG(ptr) & ((stat << 16) | stat)) == ((stat << 16) | stat)) : \
    ((READ_USHORT(ptr) & stat) == stat))
    
#define CHECK_FLASH_STATUS_INDEXED16(paired, ptr, offset, stat) \
    (paired ? ((READ_ULONG((ULONG *)ptr + offset) & ((stat << 16) | stat)) == ((stat << 16) | stat)) : \
    ((READ_USHORT((USHORT *)ptr + offset) & stat) == stat))

#define RD_FLASH_16(paired, ptr) \
    (paired ? READ_ULONG(ptr) : READ_USHORT(ptr))
    
#define RD_FLASH_INDEXED16(paired, ptr, offset) \
    (paired ? READ_ULONG((ULONG *)ptr + offset) : READ_USHORT((USHORT *)ptr + offset))


// For 8 bits mode devices
#define WR_FLASH_08(paired, ptr, val) \
    do { \
        if (paired) \
            WRITE_USHORT(ptr, (USHORT)val); \
        else \
            WRITE_UCHAR(ptr, (UCHAR)val); \
    } while (0)
    
#define WR_FLASH_REG_08(paired, ptr, cmd) \
    do { \
        if (paired) \
            WRITE_USHORT(ptr, (USHORT)((cmd << 16) | cmd)); \
        else \
            WRITE_UCHAR(ptr, (UCHAR)cmd); \
    } while (0)
    
#define WR_FLASH_REG_INDEXED08(paired, ptr, offset, cmd) \
    do { \
        if (paired) \
            WRITE_USHORT(((USHORT *)ptr + offset), (USHORT)((cmd << 16) | cmd)); \
        else \
            WRITE_UCHAR(((UCHAR *)ptr + offset), (UCHAR)cmd); \
    } while (0)
    
#define CHECK_FLASH_STATUS_08(paired, ptr, stat) \
    (paired ? ((READ_USHORT(ptr) & ((stat << 16) | stat)) == ((stat << 16) | stat)) : \
    ((READ_UCHAR(ptr) & stat) == stat))

#define CHECK_FLASH_STATUS_INDEXED08(paired, ptr, offset, stat) \
    (paired ? ((READ_USHORT((USHORT *)(ptr) + offset) & ((stat << 16) | stat)) == ((stat << 16) | stat)) : \
    ((READ_UCHAR((UCHAR *)(ptr) + offset) & stat) == stat))

#define RD_FLASH_08(paired, ptr) \
    (paired ? READ_USHORT(ptr) : READ_UCHAR(ptr))
    
#define RD_FLASH_INDEXED08(paired, ptr, offset) \
    (paired ? READ_USHORT((USHORT *)(ptr) + offset) : READ_UCHAR((UCHAR *)(ptr) + (offset)))

// Others
#define CREATE_MASK_16(bIsPaired, flag) \
    (bIsPaired ? ((flag << 16) | flag) : flag)
    
#define UPPER_16(flag) (flag << 16)

#define CREATE_MASK_08(bIsPaired, flag) \
    (bIsPaired ? ((flag << 8) | flag) : flag)

#define UPPER_08(flag) (flag << 8)

// Common Flash Memory Interface query command and data.  
// CFI Query
// *********
// puts the device into compact flash memory interface query mode 
// note: the device must be reset to exit this mode
#define CFI_QUERY_ADDR                      0x55
#define CFI_QUERY_DATA                      0x98

#define CFI_DATA_QUERY_ID_Q                 0x0051          // ASCII 'Q'.
#define CFI_DATA_QUERY_ID_R                 0x0052          // ASCII 'R'.
#define CFI_DATA_QUERY_ID_Y                 0x0059          // ASCII 'Y'.

#define CFI_DATA_PET_ID_P                   0x0050          // ASCII 'P'.
#define CFI_DATA_PET_ID_R                   0x0052          // ASCII 'R'.
#define CFI_DATA_PET_ID_I                   0x0049          // ASCII 'I'.

#define CFI_DATA_AET_ID_P                   0x0030          // ASCII 'A'.
#define CFI_DATA_AET_ID_R                   0x003A          // ASCII 'L'.
#define CFI_DATA_AET_ID_I                   0x0054          // ASCII 'T'.

// CFI Geometry
#define CFI_ERASE_BLOCK_SIZE_MULTP          256

// CFI device interface values
#define CFI_DEV_INTF_x8_ASYNC               0x0000
#define CFI_DEV_INTF_x16_ASYNC              0x0001
#define CFI_DEV_INTF_x8x16_ASYNC            0x0002
#define CFI_DEV_INTF_x32_ASYNC              0x0003
#define CFI_DEV_INTF_x16x32_ASYNC           0x0005

// Common Flash Memory Interface query structure offsets.  
// CFI query identification
// ************************
#define CFI_QS_OFFSET_QRY_ID                0x10
#define CFI_QS_OFFSET_QRY_ID_Q              CFI_QS_OFFSET_QRY_ID
#define CFI_QS_OFFSET_QRY_ID_R              (CFI_QS_OFFSET_QRY_ID_Q + 1)
#define CFI_QS_OFFSET_QRY_ID_Y              (CFI_QS_OFFSET_QRY_ID_R + 1)
#define CFI_QS_OFFSET_PRI_OEM_CMD_SET_ID    0x13
#define CFI_QS_OFFSET_PRI_EXT_TABLE         0x15
#define CFI_QS_OFFSET_ALT_OEM_CMD_SET_ID    0x17
#define CFI_QS_OFFSET_ALT_EXT_TABLE         0x19

// CFI system interface
// ********************
#define CFI_QS_OFFSET_SYSINTF               0x1B

// CFI device geometry 
// *******************
#define CFI_QS_OFFSET_DEVGEOM               0x27

// CFI Vendor-Specific Query table
#define CFI_QS_OFFSET_QRY_ID_Q              CFI_QS_OFFSET_QRY_ID
#define CFI_QS_OFFSET_QRY_ID_R              (CFI_QS_OFFSET_QRY_ID_Q + 1)
#define CFI_QS_OFFSET_QRY_ID_Y              (CFI_QS_OFFSET_QRY_ID_R + 1)

//------------------------------------------------------------------------------
// Types
#pragma pack(1)
// Flash query ID
typedef struct _FLASH_QUERY_ID_STRING {
    CHAR ID[3];
    USHORT PriOEMCmdSetID;  
    USHORT PriExtTableAddr;  
    USHORT AltOEMCmdSetID;  
    USHORT AltExtTableAddr;  
} CFI_FLASH_QUERY_ID_STRING, *PCFI_FLASH_QUERY_ID_STRING;

// Flash-system interface characteristics.
typedef struct _FLASH_SYSINTERFACE_INFO {
    UCHAR VccMinProgV;				        // Vcc logic supply minimum program/erase voltage.
    UCHAR VccMaxProgV;				        // Vcc logic supply maximum program/erase voltage.
    UCHAR VppMinProgV;				        // Vpp logic supply minimum program/erase voltage.
    UCHAR VppMaxProgV;				        // Vpp logic supply maximum program/erase voltage.
    struct {
        UCHAR SnglWordProgTO_us;	        // Typical single word program time-out (in us).
        UCHAR WriteBuffTO_us;		        // Typical buffer write time-out (in us).
        UCHAR BlockEraseTO_ms;		        // Typical block erase time-out (in ms).
        UCHAR ChipEraseTO_ms;		        // Typical full-chip erase time-out (in ms).
    } Typical;
    struct {
        UCHAR SnglWordProgTO_us;	        // Max single word program time-out (in us).
        UCHAR WriteBuffTO_us;		        // Max buffer write time-out (in us).
        UCHAR BlockEraseTO_ms;		        // Max block erase time-out (in ms).
        UCHAR ChipEraseTO_ms;		        // Max full-chip erase time-out (in ms).
    } Max;
} CFI_FLASH_SYSINTERFACE_INFO, *PCFI_FLASH_SYSINTERFACE_INFO;

// Flash geometry characteristics.
#define CFI_ERASE_REGIONS_MAX       8
typedef struct _FLASH_GEOMETRY_INFO {
    UCHAR   DevSize;				        // Flash size (n = 2^n bytes).
    USHORT  DevInterface;			        // Interface type (8/16).
    USHORT  WriteBuffSize;			        // Write buffer size (n = 2^n bytes).
    UCHAR   NumEraseBlockRegions;           // Number of erase block regions.
    struct {
        USHORT  NumIdentEraseBlocks;	    // Number of identical-sized erase blocks. 0 based.
        USHORT  EraseBlockSize;             // Multiply 256 to get size of an erase block.
    } EraseBlockInfo[CFI_ERASE_REGIONS_MAX];
} CFI_FLASH_GEOMETRY_INFO, *PCFI_FLASH_GEOMETRY_INFO;

// Flash ID information
typedef struct _NOR_FLASH_ID_DESC {
    USHORT ManufacturerID;                  // Manufacturer ID
    USHORT DeviceID[3];                     // Device ID
    ULONG SiliconID[4];                     // Unique silicon device ID, max 128 bit
} NOR_FLASH_ID_DESC, *PNOR_FLASH_ID_DESC;
    
// Flash Memory information
typedef struct _NOR_FLASH_DESC {
    BOOL PairedFlash;
    ULONG FlashBase;
    ULONG DeviceWidth;
    NOR_FLASH_ID_DESC FlashID;
    CFI_FLASH_QUERY_ID_STRING QryIDStr;     // Flash query ID string
    CFI_FLASH_SYSINTERFACE_INFO SysInt;	    // Flash-system interface information.
    CFI_FLASH_GEOMETRY_INFO Geometry;	    // Flash geometry information.
} NOR_FLASH_DESC, *PNOR_FLASH_DESC;
#pragma pack()

// Manufacturer specific low level flash driver interface.
// *******************************************************
typedef struct _NOR_FLASH_DRIVER {
    void (*RelocateBegin)(void);
    BOOL (*IsFlashSupported)(NOR_FLASH_DESC *pFlashDesc);
    BOOL (*Program)(NOR_FLASH_DESC *pFlashDesc, ULONG ulStartAddress, UCHAR *pData, ULONG ulSize, BOOL bIgnore0to1);
    BOOL (*EraseSector)(NOR_FLASH_DESC *pFlashDesc, ULONG ulSectorAddress);
    BOOL (*EraseChip)(NOR_FLASH_DESC *pFlashDesc);
    void (*RelocateEnd)(void);
    BOOL (*LockSector)(NOR_FLASH_DESC *pFlashDesc, ULONG ulSectorAddress);
    BOOL (*UnlockSector)(NOR_FLASH_DESC *pFlashDesc, ULONG ulSectorAddress);
    BOOL (*IsSectorLocked)(NOR_FLASH_DESC *pFlashDesc, ULONG ulSectorAddress);
    WCHAR *lpszName;
} NOR_FLASH_DRIVER, *PNOR_FLASH_DRIVER;

//------------------------------------------------------------------------------
// Functions
BOOL NORLibInit(ULONG ulFlashBase, ULONG ulRelocateBase, ULONG ulRelocSize);
BOOL NORProgram(ULONG ulStartAddress, UCHAR *pData, ULONG ulLen, BOOL bIgnore0to1);
ULONG NORErase(ULONG ulStartAddress, ULONG ulLen);
BOOL NOREraseChip(void);
BOOL NORLockSector(ULONG ulStartAddress);
BOOL NORUnlockSector(ULONG ulStartAddress);
BOOL NORIsAddrLocked(ULONG ulStartAddress);
BOOL NORGetGeometry(CFI_FLASH_GEOMETRY_INFO *pGeometry);
BOOL NORGetDeviceWidth(BOOL *pbIsPaired, ULONG *pulDeviceWidth);
BOOL NORGetFlashID(NOR_FLASH_ID_DESC *pFlashID);
void NORShowProgress(BOOL bEnable, ULONG ulBytePerStep);
ULONG NORGetRelocateCodeSize(void);
BOOL NORVerifyData(ULONG ulStartAddress, UCHAR *pData, ULONG ulSize);

#ifdef __cplusplus
    }
#endif

#endif // __MX27_NORFLASH_NOR_H_

⌨️ 快捷键说明

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