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

📄 strata.h

📁 CIRRUS 93XX系列windows mobile 6.0 BSP
💻 H
字号:
//**********************************************************************
//                                                                      
// Filename: strata.h
//                                                                      
// Description: Flash media driver (FMD) interface for Intel StrataFlash 
//              memory chips.
//
// Notes: As noted, this media driver works on behalf of the FAL to directly
//        access the underlying FLASH hardware.  Consquently, this module 
//        needs to be linked with FAL.LIB to produce the device driver 
//        named FLASHDRV.DLL.  It may also be used directly in a boot loader
//        image.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus 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 
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved                       
//                                                                      
//**********************************************************************

#ifndef _STRATA_H_
#define _STRATA_H_

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

// Flash read/write macros.
// We assume the StrataFlash part is in 16-bit mode (as opposed to 8-bit mode).
#define WRITE_FLASH(ptr, val) (g_bPairedFlash ? WRITE_ULONG(ptr, (ULONG)val) : WRITE_USHORT(ptr, (USHORT)val))
#define READ_FLASH(ptr)       (g_bPairedFlash ? READ_ULONG(ptr) : READ_USHORT(ptr))
#define READ_FLASH_INDEXED(ptr, offset)       (g_bPairedFlash ? READ_ULONG((volatile ULONG *)ptr + offset) : READ_USHORT((volatile USHORT *)ptr + offset))
// Write a command to the flash part.
#define WRITE_COMMAND(ptr, cmd) (g_bPairedFlash ? WRITE_ULONG(ptr, (ULONG)((cmd << 16) | cmd)) : WRITE_USHORT(ptr, (USHORT)cmd))
// Check for expected status.
#define CHECK_STATUS(ptr, stat) (g_bPairedFlash ? ((READ_ULONG(ptr) & ((stat << 16) | stat)) == ((stat << 16) | stat)) : ((READ_USHORT(ptr) & stat) == stat))
#define CHECK_STATUS_INDEXED(ptr, offset, stat) (g_bPairedFlash ? ((READ_ULONG((volatile ULONG *)ptr + offset) & ((stat << 16) | stat)) == ((stat << 16) | stat)) : ((READ_USHORT((volatile USHORT *)ptr + offset) & stat) == stat))
// Is specified address block-aligned?
#define IS_BLOCK_ALIGNED(ptr)   (((ULONG)ptr % g_FMDInfo.BlockSize) ? FALSE : TRUE)



//
// AMD  flash commands and status definitions.
//
// Commands.
#define AMD_SETUP_ADDR1                         0x555
#define AMD_SETUP_ADDR2                         0x2AA
#define AMD_VENDORID_ADDR                       0
#define AMD_DEVICEID_ADDR1                      1
#define AMD_DEVICEID_ADDR2                      0x0e
#define AMD_DEVICEID_ADDR3                      0x0f
#define AMD_QUERY_ADDR                          0x55

#define AMD_SETUP_CODE1                         0xAA
#define AMD_SETUP_CODE2                         0x55
#define AMD_SETUP_ERASE                         0x80

#define AMD_READ_ID                             0x90
#define AMD_READ_QUERY                      0x98
#define AMD_WP_STATE                          0x90
#define AMD_RESET                                 0xF0
#define AMD_PROGRAM                            0xA0
#define AMD_BLOCK_ERASE                     0x30

#define AMD_SECTOR_ERASE_TIMER                  0x08

#define FLASH_ERR_OK              0x00  // No error - operation complete
#define FLASH_ERR_INVALID         0x01  // Invalid FLASH address
#define FLASH_ERR_ERASE           0x02  // Error trying to erase
#define FLASH_ERR_LOCK            0x03  // Error trying to lock/unlock
#define FLASH_ERR_PROGRAM         0x04  // Error trying to program
#define FLASH_ERR_PROTOCOL        0x05  // Generic error
#define FLASH_ERR_PROTECT         0x06  // Device/region is write-protected
#define FLASH_ERR_NOT_INIT        0x07  // FLASH info not yet initialized
#define FLASH_ERR_HWR             0x08  // Hardware (configuration?) problem
#define FLASH_ERR_ERASE_SUSPEND   0x09  // Device is in erase suspend mode
#define FLASH_ERR_PROGRAM_SUSPEND 0x0a  // Device is in in program suspend mode
#define FLASH_ERR_DRV_VERIFY      0x0b  // Driver failed to verify data
#define FLASH_ERR_DRV_TIMEOUT     0x0c  // Driver timed out waiting for device
#define FLASH_ERR_DRV_WRONG_PART  0x0d  // Driver does not support device
#define FLASH_ERR_LOW_VOLTAGE     0x0e  // Not enough juice to complete job



//
// Intel 28F320 flash commands and status definitions.
//
// Commands.
#define READ_QUERY_CMD			0x0098
#define READ_IDENT_CMD			0x0090
#define READ_ARRAY_CMD			0x00FF
#define BYTEWORD_PROGRAM_CMD    0x0040
#define CLEAR_STATUS_CMD        0x0050
#define READ_STATUS_CMD			0x0070
#define BLOCK_LOCK_CMD          0x0060
#define BLOCK_PROCEED_CMD		0x00D0
#define BLOCK_SETLOCK_CMD		0x0001
#define BLOCK_ERASE_CMD			0x0020
#define BUFFER_WRITE_CMD		0x00E8


#define COMMAND_RETRY_MAX       20																																									 
// Status.
#define STATUS_READY_MASK		0x0080
#define STATUS_ERROR			0x0010

// Flash CFI query structure offsets.
#define QS_MFGCODE_OFFSET		0x0
#define QS_DEVCODE_OFFSET		0x1
#define QS_IDSTRING_OFFSET		0x10
#define QS_SYSINTF_OFFSET		0x1B
#define QS_DEVGEOM_OFFSET		0x27

#define REGION_SIZE_MULT		256
#define SECTOR_SIZE             512     // Number of data bytes in a sector

#define MFGCODE_INTEL             0x0089	// Intel's flash manufacturing code.
#define MFGCODE_MICRON          0x002c // Micron's flash manufacturing code.
#define MFGCODE_AMD                0x0001	// AMD's flash manufacturing code.


#define IDSTRING_Q				0x0051	// ASCII 'Q'.
#define IDSTRING_R				0x0052  // ASCII 'R'.
#define IDSTRING_Y				0x0059	// ASCII 'Y'.

#pragma pack(1)
// 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;
} FLASH_SYSINTERFACE_INFO, *PFLASH_INTERFACE_INFO;

//
#define IntelRegionNUM    4
typedef struct RegionInfo {
   	USHORT              blocks;
	USHORT               block_size;
} RegionInfo_t;

typedef struct SysRegionInfo {
   	DWORD              blocks;
	DWORD               block_size;
} SysRegionInfo_t;
// Flash geometry characteristics.

//The data in this structure is read from hardware, so don't change the relationsheep of every member.
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 NumEraseBlocks;			// Number of flash blocks in an erase region.

	union{
		struct {
			USHORT NumIdentEraseBlocks;		// Number of identical-sized erase blocks (number of blocks).
			USHORT EraseRegionSize;         // Size of an erase region.
		};
		RegionInfo_t FlashRegionInfo[IntelRegionNUM];
	};
} FLASH_GEOMETRY_INFO, *PFLASH_GEOMETRY_INFO;

#pragma pack()
// All flash information.
typedef struct _FMD_FLASH_INFO
{
	ULONG BaseAddress;				// Flash base address.(file system use)
	ULONG FlashLength;				// Length of flash to be managed.(file system use)

	ULONG ChipBaseAddress;				// Flash base address.
	ULONG ChipFlashLength;				// Length of flash to be managed.

	BOOL  bIsTop;
	DWORD				gdwCurEraseRegion;
	DWORD				gdwCurEraseBlock;

	ULONG BlockSize;				// Block size (computed from CFI data).
	ULONG TotalFlashBlocks;			// Number of flash blocks.
	USHORT UnusedBytesPerBlock;		// Remaining bytes in each block.
	USHORT SectorsPerBlock;			// Number of sectors per block.
    FLASH_SYSINTERFACE_INFO SysInt;	// Flash-system interface information.
    FLASH_GEOMETRY_INFO Geometry;	// Flash geometry information.
} FMD_FLASH_INFO, *PFMD_FLASH_INFO;


#endif	//_STRATA_H_.

⌨️ 快捷键说明

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