📄 gflash.h
字号:
#ifndef __GFLASHLIB_H__
#define __GFLASHLIB_H__
/* ==========================================================================*/
/* Data type definitions */
/* #define GFLASH_DEBUG 1 */
#define AMD_GFLASH_S29 1
/* Some macro defintions */
#ifndef TRUE
#define TRUE (1 == 1)
#define FALSE (1 == 0)
#endif
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifndef ON
#define ON 1
#define OFF 0
#endif
#ifndef BOOL
#define BOOL unsigned int
#endif
#ifndef FL_RET
#define FL_RET unsigned int
#endif
#ifndef FL_DEV_ID
#define FL_DEV_ID unsigned char
#endif
#ifndef FL_PART_ID
#define FL_PART_ID unsigned short
#endif
#ifndef UINT8
#define UINT8 unsigned char
#endif
#ifndef UINT16
#define UINT16 unsigned short
#endif
#ifndef UINT32
#define UINT32 unsigned int
#endif
#ifndef UINT64
#define UINT64 unsigned long long int
#endif
#ifndef VUINT8
#define VUINT8 volatile unsigned char
#endif
#ifndef VUINT16
#define VUINT16 volatile unsigned short
#endif
#ifndef VUINT32
#define VUINT32 volatile unsigned int
#endif
#ifndef VUINT64
#define VUINT64 volatile unsigned long long int
#endif
#if 0
#define REGISTER
#else
#define REGISTER register
#endif
/* ==========================================================================*/
/* Configuration */
#define OS_VXWORKS 0
#define OS_PSOS 1
#define OS_NONE 2
#ifdef USE_OWN_SEM
#define OS_USED OS_VXWORKS
/* #define USE_OWN_SEM */
#if (OS_USED==OS_VXWORKS)
#include <VxWorks.h>
#include <semLib.h>
#define GFLASH_SEMID SEM_ID
#define gFlash_IsSemSet(id) ((id!=NULL)?1:0);
#define gFlash_SemCreate(s,id) id=semBSmCreate(SEM_Q_FIFO,SEM_FULL)
#define gFlash_SemTake(id) semTake(id,WAIT_FOREVER)
#define gFlash_SemGive(id) semGive(id)
#elif (OS_USED==OS_PSOS)
#include <psos.h>
#define GFLASH_SEMID UINT32
#define gFlash_IsSemSet(id) (id?1:0);
#define gFlash_SemCreate(s,id) sm_create(s, 1, SM_FIFO, &(id))
#define gFlash_SemTake(id) sm_p(id,SM_WAIT, 0)
#define gFlash_SemGive(id) sm_v(id)
#else
#define GFLASH_SEMID int
#define gFlash_SemCreate(s,id) id=0
#define gFlash_IsSemSet(id) 0
#define gFlash_SemTake(id)
#define gFlash_SemGive(id)
#endif
#endif
/* Use my rtc lib */
#if 0
#define DEF_RTCLIB
#endif
/* Provide Erase Suspend/Resume */
#if 0
#define HAVE_SUS_RES
#endif
/* Enable blank check */
#if 0
#define ENABLE_BLANKCHECK
#endif
/* Debug output is allowed.*/
#if 0
#define GFLASH_DEBUG
#endif
/* 64-bit supported .*/
#if 0
#define GFLASH_UINT64_USED
#endif
#ifdef GFLASH_UINT64_USED
#define FL_RWTYPE UINT64
#else
#define FL_RWTYPE UINT32
#endif
#ifdef GFLASH_UINT64_USED
extern void sysLongLongMove (UINT32 dst, UINT32 src);
#endif
/* redirect fl_printf */
extern int printf (const char *, ...);
#define fl_printf printf
/* ==========================================================================*/
/* API prototypes and some constants' defs */
/* Some constants */
#define MAX_BANK_NO 8
#define MAX_PART_NO 8
#define MAX_REGS_NO 4
#define MAX_CFI_BTBL (29+4*MAX_REGS_NO)
#define MAX_CFI_PTBL 14 /* Primary Q table */
/* Command sets we supported. */
#define CMDID_INTEL_BCS 0x00000000U
#define CMDID_INTEL_ECS 0x00000001U
#define CMDID_AMD_BCS 0x00000002U
#define CMDID_AMD_ECS 0x00000003U
#define CMDID_SST_BCS 0x00000004U
#define CMDID_SST_ECS 0x00000005U
#define CMDID_UNKNOWN 0xFFFFFFFFU
/* Error code definitions */
#define FL_ERR_NONE 0x00
/* for gFlash_Init().*/
#define FL_ERR_INVALIDID 0x01 /* Cannot Get ID: (VID<<16)|DID = 0xFFFFFFFF */
#define FL_ERR_UNSUPPORTEDCMDSET 0x02 /* Unknown cmd set */
#define FL_ERR_NOTREGISTERED 0x03 /* Cannot find the ID in register table */
#define FL_ERR_TOOMANYBANK 0x04 /* Too many banks (Valid bank: 0~7) */
#define FL_ERR_PART_NOTINIT 0x05 /* The PART not init'd ! */
#define FL_ERR_PART_SIZETOOBIG 0x06
#define FL_ERR_PART_TOOMANYPART 0x07
#define FL_ERR_LIB_NOTINIT 0x0A /* The lib has not been init'd successfully. */
#define FL_ERR_ADDRINVALID 0x0B /* Addr is out of range. */
#define FL_ERR_TIMEOUT 0x0C /* Timeout */
#define FL_ERR_BLANKCHKFAIL 0x0D /* Blank check error */
#define FL_ERR_INVALIDBUSWIDTH 0x0E /* Invalid Bus Width, Valid value: 8/16/32 */
#define FL_ERR_PROG 0x0F /* Used for Intel Flash (SR & 0x7E)!=0 */
/* 060309 lyf add */
#define FL_ERR_NOMEM 0x10 /* malloc failed */
/* end 060309 */
#define FL_INVALID_PARTID 0xFFFF
/*
* structures
*/
typedef struct tagFlashConf
{
UINT32 BaseAddr; /* Base address of this bank */
UINT8 PortSizePerChip; /* Port size per chip,in unit of byte */
UINT8 ChipCount; /* Chip count */
UINT16 Options; /* For Expansion */
}FlashConf;
typedef struct tagEBlockInfo
{
UINT32 Size; /* # of bytes in this Erase Block */
UINT32 Count; /* # of this kind of Erase Block */
}EBlockInfo;
/* In a PART, all blocks' size are the same. */
typedef struct tagPartInfo
{
UINT32 PartSize; /* # of bytes in this partition */
UINT32 Offset; /* Offset to the Flash Base */
UINT32 BlkSize; /* Block size */
UINT32 Base; /* Absolute addr: Flash Base + Offset */
}PartInfo;
typedef struct tagFlashInfo
{
UINT8 PortSizePerChip; /* Port size per chip,in unit of byte */
UINT8 ChipCount; /* Chip count */
UINT32 BaseAddr; /* Base address of this bank */
UINT32 DeviceSize; /* Total size of this bank(in unit of bytes)*/
UINT8 RegCnt; /* # of Erase Block Regions within device */
EBlockInfo EBlk[MAX_REGS_NO]; /* Erase Block Region information */
UINT32 CmdType; /* Cmd Type */
UINT16 VendorID; /* Vendor ID */
UINT16 DeviceID; /* Device ID */
UINT32 MaxBytesEachWrite; /* Max number of bytes in multi-byte program */
UINT32 Features; /* Features supported */
UINT8 CfiBasQTbl[MAX_CFI_BTBL]; /* Basic CFI Query Table */
UINT8 CfiPriQTbl[MAX_CFI_PTBL]; /* Primary CFI Query Table */
}FlashInfo;
/* Exported functions */
FL_DEV_ID gFlash_OpenDevice(FlashConf *pConf,UINT8 *RetVal);
FL_PART_ID gFlash_CreatePart(FL_DEV_ID devID,UINT32 uiOffset,UINT32 uiBlkSize,UINT8 ucBlkNum,UINT8 *RetVal);
FL_RET gFlash_GetPartBase(FL_PART_ID flPartID,UINT32 *uiBase);
FL_RET gFlash_GetPartSize(FL_PART_ID flPartID,UINT32 *uiSize);
FL_RET gFlash_Read (FL_PART_ID flPartID, UINT32 uiStart, UINT8 *Buffer, UINT32 uiLen);
FL_RET gFlash_Write(FL_PART_ID flPartID, UINT32 uiStart, UINT8 *Buffer, UINT32 uiLen);
FL_RET gFlash_Erase(FL_PART_ID flPartID, UINT32 uiAddr);
FL_RET gFlash_EraseAll(FL_PART_ID flPartID);
#ifdef HAVE_SUS_RES
FL_RET gFlash_EraseSuspend(FL_PART_ID flPartID);
FL_RET gFlash_EraseResume(FL_PART_ID flPartID);
#endif
FL_RET gFlash_Lock(FL_PART_ID flPartID,UINT32 uiAddr);
FL_RET gFlash_LockAll(FL_PART_ID flPartID);
FL_RET gFlash_Unlock(FL_PART_ID flPartID,UINT32 uiAddr);
FL_RET gFlash_UnlockAll(FL_PART_ID flPartID);
FL_RET gFlash_GetDeviceInfo(FL_DEV_ID flDevID,FlashInfo *pInfo);
void gFlash_GetLibVersion(UINT8 *Major,UINT8 *Minor);
#ifdef ENABLE_BLANKCHECK
FL_RET gFlash_BlankCheck(FL_PART_ID flPartID,UINT32 uiAddr,UINT32 uiLen);
FL_RET gFlash_BlankCheckAll(FL_PART_ID flPartID);
#endif
#if 0
void gFlash_SelfTest(FL_PART_ID flPartID,UINT8 ucOption);
#endif
/* 060309 lyf add */
FL_RET gFlashPartWrite (FL_PART_ID flPartID, unsigned char * buffer,
unsigned long uiLen, unsigned long offset,
int * count, int fBypassUnlock);
FL_RET gFlashPartRead (FL_PART_ID flPartID, unsigned char * buffer,
unsigned long uiLen, unsigned long offset);
/* end 060309 */
#endif /* __GFLASHLIB_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -