📄 640j3.h
字号:
/***************************************************
公司: 好易通科技有限公司
产品名: TETRA数字集群终端
CPU: OMAP5910
功能: 28F640J3C flash测试
作者: YuanLin
编写时间: 2004.12.31
修改时间: 2005.06.02
****************************************************/
#ifndef __640J3_H__
#define __640J3_H__
#include "type.h"
/* Status Macros */
#define mIsBlockLocked(A) ( ( A & BLOCK_LOCKED ) == BLOCK_LOCKED )
#define mIsProgramSuspended(A) ( ( A & PROGRAM_SUSPENDED ) == PROGRAM_SUSPENDED )
#define mIsVppLow(A) ( ( A & VPP_LOW ) == VPP_LOW )
#define mIsProgramError(A) ( ( A & PROGRAM_ERROR ) == PROGRAM_ERROR )
#define mIsEraseError(A) ( ( A & ERASE_ERROR ) == ERASE_ERROR )
#define mIsEraseSuspended(A) ( ( A & ERASE_SUSPENDED ) == ERASE_SUSPENDED )
#define mIsStatusReady(A) ( ( A & STATUS_READY ) == STATUS_READY )
#define mIsBlockstatLocked(A) ( ( A & BLOCKSTAT_LOCKED ) == BLOCKSTAT_LOCKED )
#define mIsBlockstatUnlocked(A) ( A == BLOCKSTAT_UNLOCKED )
#define mIsBlockstatLockedDown(A) ( ( A & BLOCKSTAT_LOCKEDDOWN ) == BLOCKSTAT_LOCKEDDOWN )
/* J3 specific constants */
#define DEVICE_ERASE_ALL_BLOCKS TRUE
#define DEVICE_ERASE_SUSPEND TRUE
#define DEVICE_EXTENDED_QUERY TRUE
#define DEVICE_GET_BLOCK_ADDRESS TRUE
#define DEVICE_LOCK_BLOCK TRUE
#define DEVICE_LOCK_PROTECTION TRUE
#define DEVICE_PAGE_MODE TRUE
#define DEVICE_PROGRAM_FLASH_BUFFERED TRUE
#define DEVICE_PROGRAM_PROTECTION TRUE
#define DEVICE_PROGRAM_SUSPEND TRUE
#define DEVICE_READ_BLOCK_STATUS TRUE
#define DEVICE_READ_PROTECTION TRUE
#define DEVICE_RESUME TRUE
#define DEVICE_UNLOCK_ALL_BLOCKS TRUE
#define DEVICE_CLEAR_STATUS FALSE
#define DEVICE_ERASE_BLOCK FALSE
#define DEVICE_GET_QUERY_ADDRESS FALSE
#define DEVICE_LOCK_DOWN_BLOCK FALSE
#define DEVICE_PROGRAM_FLASH FALSE
#define DEVICE_QUERY FALSE
#define DEVICE_READ_DEVICE_ID FALSE
#define DEVICE_READF FALSE
#define DEVICE_READ_FLASH FALSE
#define DEVICE_READ_STATUS FALSE
#define DEVICE_SEC_EXTENDED_QUERY FALSE
#define DEVICE_UNLOCK_BLOCK FALSE
#define DEVICE_WAIT_UNTIL_READY FALSE
#define DEVICE_WRITEF FALSE
/* TRUE means client will implement this function external to the template */
#define CLIENT_GET_FPTR TRUE
/* little endian */
#define BIG_ENDIAN_ARCHITECTURE FALSE
#define BLOCK_BASE_FLASH_ADDRESS (BASE_FLASH_ADDRESS + (BLOCK_NUMBYTES * 0)) + 8
/*Flash 空间的写入地址必须是4的整数倍? 难道是以4bits为单位?
*add by wzhui */
#define QUERY_START_OFFSET 0x10
#define BASE_FLASH_ADDRESS 0x0C400000 + 0x0000 // 0x0c400000 /* Flash first address */
#define PROGRAM_SETUP 0x0040//0040 /* Byte/Word program command */
#define READ_STATUS_REGISTER 0x0070//0070 /* Read status register command */
#define CLEAR_STATUS_REGISTER 0x0050//0050 /* Clear status register command */
#define READ_ID_CODES 0x0090//0090 /* Read ID code command */
#define READ_QUERY 0x0098//0098
#define BLOCK_ERASE 0x0020//0020 /* Erase Block 1st command */
#define CONFIRM 0x00D0//00D0 /* Erase Block 2nd command,block erase and program resumen and clear lock bit command */
#define READ_ARRAY 0x00ff//00ff /* Enter into read array mode command */
#define CONFIG_SETUP 0x0060//0060 /* Set or Clear 1st command */
/* Status Register Values */
#define BLOCK_LOCKED 0x0002
#define PROGRAM_SUSPENDED 0x0004
#define VPP_LOW 0x0008
#define PROGRAM_ERROR 0x0010
#define ERASE_ERROR 0x0020
#define ERASE_SUSPENDED 0x0040
#define STATUS_READY 0x0080
#define ERASE_TIMEOUT 1000 /* erase timer */
#define PROGRAM_TIMEOUT 8000
#define BLOCKSTAT_UNLOCKED 0x0
#define BLOCKSTAT_LOCKED 0x1
#define BLOCKSTAT_LOCKEDDOWN 0x3
#define PROTECTION_LOCK_LOCATION 0x0
#define TOTAL_NUMBLOCKS 0x40 /* 64 blocks */
#define BLOCK_NUMBYTES 0x4000 /* 1M bits = 0x4000 words is the memory of every block */
#define TOTAL_SIZE 0x800000 /* 64M bits = 0x800000 bytes is total memory of the flash */
#define TOTAL_SIZEWORD 0X400000 /* 64M bits = 0x400000 words is total memory of the flash */
#define BLOCK_MASK 0xFFFF /* 1M words is the address memory of every block */
#define OTP_NUMWORDS 0x9 /* 9 words 64bit memory map */
#define OTP_BASE 0x100 /* factory program use 256 bytes/program */
#define OTP_PROGRAM 0x00C0 /* Protection 1st command */
#define OTP_READ 0x0090 /* Read protection register */
#define OTP_LOCK 0xFFFD
#define LOCKDOWN_BIT_SET 0x002F
#define LOCK_BIT_SET 0x0001 /* Set 2nd command */
#define LOCK_BIT_CLEAR 0x00D0 /* Clear 2nd command */
#define BLOCK_SUSPEND 0x00B0
#define BLOCK_RESUME 0x00D0
#define BUFFER_SIZE 0x20 /* bytes */
#define WRITE_TO_BUFFER 0x00E8
#define SET_READ_CONFIG 0x0003
/* defined for all data widths. added to flash base address. contains A16..A1 */
#define STD_READ_MODE 0x0000
#define PAGE_READ_MODE 0x8000
/* device specific typedefs */
/* extended query structure */
typedef struct ExtQueryData
{
char ExtQueryStr[4]; /* 3 bytes + null */
BYTE MajorVersionNum; /* 1 byte */
BYTE MinorVersionNum; /* 1 bytes */
UINT32 OptionalFeature; /* 4 bytes */
BYTE AfterSuspendFunctions; /* 1 byte */
UINT16 BlockLockStatus; /* 2 bytes */
BYTE VccOptimum; /* 1 byte */
BYTE VppOptimum; /* 1 byte */
} extquery;
/* status return values */
enum Flash_CommandStat
{
StatCompleted, /* the function completed 0*/
StatTimeout, /* access to the device timed out 1*/
StatBadBlock, /* block # not valid for this device 2*/
StatBadAddress, /* address not valid for this device 3*/
StatBadOtp, /* otp loc not valid for this device 4*/
StatUnsupported /* this function is not supported 5*/
};
typedef struct Flash_QueryData
{
char QueryStr[4]; /* 3 bytes + null */
UINT16 VendorId; /* 2 bytes */
UINT16 ExtTablePtr; /* 2 bytes */
UINT16 AltVendorId; /* 2 bytes */
UINT16 SecExtTablePtr; /* 2 bytes */
BYTE VccMin; /* 1 byte */
BYTE VccMax; /* 1 byte */
BYTE VppMin; /* 1 byte */
BYTE VppMax; /* 1 byte */
BYTE TypicalProgTimeout; /* 1 byte */
BYTE TypicalBufferTimeout; /* 1 byte */
BYTE BlockEraseTimeout; /* 1 byte */
BYTE ChipEraseTimeout; /* 1 byte */
BYTE MaxSingleTimeout; /* 1 byte */
BYTE MaxBufferTimeout; /* 1 byte */
BYTE MaxBlockEraseTimeout; /* 1 byte */
BYTE MaxChipEraseTimeout; /* 1 byte */
BYTE DeviceSize; /* 1 byte */
UINT16 DeviceInterface; /* 2 bytes */
UINT16 MaxWriteBufferBytes; /* 2 bytes */
BYTE NumEraseBlocks; /* 1 byte */
UINT32 EraseBlockInformation; /* 4 bytes */
}Flash_query;
/* status structure */
typedef struct Flash_Stat
{
enum Flash_CommandStat Result; /* subroutine status */
volatile UINT16 SR; /* Flash status register value */
}Flash_Status;
typedef BYTE * BYTE_PTR; /* pointer to 8-bit unsigned integer */
// typedef UINT16 * UINT16_PTR; /* pointer to 16-bit unsigned integer */
typedef UINT32 * UINT32_PTR; /* pointer to 32-bit unsigned integer */
/****************************************************************************/
Flash_Status EraseBlock( UINT16 blocknum );
Flash_Status EraseBlock( UINT16 blocknum );
Flash_Status EraseSuspend( UINT16 blocknum );
Flash_Status ExtendedQuery( struct ExtQueryData *extquery );
Flash_Status Flash_Queryc ( struct Flash_QueryData *query );
Flash_Status GetQueryAddress ( UINT32 offset, UINT32_PTR address );
Flash_Status GetBlockAddress( UINT16 blocknum, UINT32_PTR address );
Flash_Status LockBlock( UINT16 blocknum );
Flash_Status LockProtection( void );
Flash_Status PageMode( UINT16 enable );
Flash_Status ProgramFlashBuffered( UINT32 address, BYTE_PTR buffer, UINT32 numbytes );
Flash_Status ProgramProtection( UINT32 location, UINT16 value );
Flash_Status ProgramSuspend( UINT16 blocknum );
Flash_Status ReadBlockStatus( UINT16 blocknum, UINT32_PTR blockstat );
Flash_Status ReadProtection( UINT32 location, UINT32_PTR value );
Flash_Status Resume( UINT16 blocknum );
Flash_Status UnlockAllBlocks( void );
Flash_Status ProgramFlash( UINT32 address, UINT16 item );
Flash_Status EraseAllBlocks( void );
BYTE WaitUntilReady( UINT16 timeout );
UINT16 ReadStatus( void );
void ClearStatus( void );
void WriteFlash( UINT32 address, UINT16 value );
UINT32 ReadFlash( UINT32 address );
UINT32 ReadDeviceID( UINT32 *mcode );
UINT32_PTR GetFptr( UINT32 address );
void Flash_wpoff(void);
void Flash_init (void);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -