FlashDrv.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define FLASHDRV_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "FlashDrv.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#define FLASH_ADDR1 0x555
#define FLASH_ADDR2 0x2AA
#define FLASH_DELAY_TIME 20
#define FLASH_DELAY { ULONG t = FLASH_DELAY_TIME; while ( t-- ){} }
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
#if defined(__HITACHI__)
#pragma section Flash
#endif
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
ULONG GetFlashID8(ULONG addr)
{
VOLATILE BYTE *FlashAddr = (BYTE *)(addr & 0xFFF00000);
WORD ManuCode, DeviceCode;
// Entry Function
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0x90; FLASH_DELAY;
ManuCode = (WORD)(*(FlashAddr));
DeviceCode = (WORD)(*(FlashAddr + 1));
// Exit Function
*(FlashAddr + FLASH_ADDR1) = 0xF0; FLASH_DELAY;
return ( ManuCode << 16 | DeviceCode );
}
ULONG GetFlashID16(ULONG addr)
{
VOLATILE WORD *FlashAddr = (WORD *)(addr & 0xFFF00000);
WORD ManuCode, DeviceCode;
// Entry Function
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0x90; FLASH_DELAY;
ManuCode = *(FlashAddr);
DeviceCode = *(FlashAddr + 1);
// Exit Function
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0xF0; FLASH_DELAY;
return ( ManuCode << 16 | DeviceCode );
}
VOID SectorErase8(ULONG addr)
{
VOLATILE BYTE *FlashAddr = (BYTE *)(addr & 0xFFF00000);
VOLATILE BYTE *Address = (BYTE *)(addr & 0xFFFFFFFF);
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0x80; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(Address) = 0x30; FLASH_DELAY;
while ( *Address != 0xFF );
}
VOID SectorErase16(ULONG addr)
{
VOLATILE WORD *FlashAddr = (WORD *)(addr & 0xFFF00000);
VOLATILE WORD *Address = (WORD *)(addr & 0xFFFFFFFF);
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0x80; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(Address) = 0x30; FLASH_DELAY;
while ( *Address != 0xFFFF );
}
VOID ChipErase8(ULONG addr)
{
VOLATILE BYTE *FlashAddr = (BYTE *)(addr & 0xFFF00000);
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0x80; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0x10; FLASH_DELAY;
while ( *FlashAddr != 0xFF );
}
VOID ChipErase16(ULONG addr)
{
VOLATILE WORD *FlashAddr = (WORD *)(addr & 0xFFF00000);
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0x80; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0x10; FLASH_DELAY;
while ( *FlashAddr != 0xFFFF );
}
VOID WriteFlash8(ULONG addr, WORD data)
{
VOLATILE BYTE *FlashAddr = (BYTE *)(addr & 0xFFF00000);
VOLATILE BYTE *Address = (BYTE *)(addr & 0xFFFFFFFF);
BYTE *WriteData = (BYTE *)(&data);
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0xA0; FLASH_DELAY;
*(Address) = *WriteData; FLASH_DELAY;
while ( *Address != *WriteData );
Address += 1;
WriteData += 1;
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0xA0; FLASH_DELAY;
*(Address) = *WriteData; FLASH_DELAY;
while ( *Address != *WriteData );
}
VOID WriteFlash16(ULONG addr, WORD data)
{
VOLATILE WORD *FlashAddr = (WORD *)(addr & 0xFFF00000);
VOLATILE WORD *Address = (WORD *)(addr & 0xFFFFFFFF);
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR2) = 0x55; FLASH_DELAY;
*(FlashAddr + FLASH_ADDR1) = 0xA0; FLASH_DELAY;
*(Address) = data; FLASH_DELAY;
while ( *Address != data );
}
VOID UnlockSector16(ULONG addr)
{
VOLATILE WORD *FlashAddr = (WORD *)(addr & 0xFFF00000);
VOLATILE WORD *Address = (WORD *)(addr & 0xFFFFFFFF);
*(FlashAddr + FLASH_ADDR1) = 0xAA; FLASH_DELAY;
*(Address) = 0x70; FLASH_DELAY;
}
FlashDrv.h 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
#ifndef FLASHDRV_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define FLASHDRV_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
#define MANUFACT_AMD 0x0001
#define MANUFACT_SPANSION 0x0001
#define MANUFACT_ATMEL 0x001F
#define MANUFACT_EON 0x007F
#define MANUFACT_MXIC 0x00C2
#define MANUFACT_AMIC 0x0037
#define ID_AM29F080 0x000100D5
#define ID_AM29F800 0x00012258
#define ID_AM29F160 0x000122D8
#define ID_S29AL016 0x00012249
#define ID_S29GL064 0x0001227E
#define ID_AT49BV6416 0x001F00D6
#define ID_EN29LV320 0x007F22F9
#define ID_MX29LV160 0x00C22249
#define ID_MX29LV320 0x00C222A8
#define ID_MX29LV640 0x00C222CB
#define ID_A29L160 0x00372249
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
ULONG GetFlashID8(ULONG);
ULONG GetFlashID16(ULONG);
VOID SectorErase8(ULONG);
VOID SectorErase16(ULONG);
VOID ChipErase8(ULONG);
VOID ChipErase16(ULONG);
VOID WriteFlash8(ULONG, WORD);
VOID WriteFlash16(ULONG, WORD);
VOID UnlockSector16(ULONG);
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif
FlashLib.c 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define FLASHLIB_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <string.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XComm.h"
#include "XPrtEng.h"
#include "FlashDrv.h"
#include "FlashLib.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#if defined(DEFAULT_MCARD_MODEL)
#define FLASH_8BIT_START 0x00400000
#define FLASH_8BIT_END 0x007FFFFF
#endif
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
#if defined(__HITACHI__)
#pragma section Flash
#endif
/* Flash Organizations */
CONST STATIC _OrgDef OrgAM29F080[] =
{
{ 16, 64*1024 }, /* 16 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgAM29F800[] =
{
{ 1, 16*1024 }, /* 1 * 16 kBytes sectors */
{ 2, 8*1024 }, /* 2 * 8 kBytes sectors */
{ 1, 32*1024 }, /* 1 * 32 kBytes sectors */
{ 15, 64*1024 }, /* 15 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgAM29F160[] =
{
{ 1, 16*1024 }, /* 1 * 16 kBytes sectors */
{ 2, 8*1024 }, /* 2 * 8 kBytes sectors */
{ 1, 32*1024 }, /* 1 * 32 kBytes sectors */
{ 31, 64*1024 }, /* 31 * 64 kBytes sectors */
};
#if defined(AT91SAM9260)
CONST STATIC _OrgDef OrgS29AL016[] =
{
{ 1, 16*1024 }, /* 1 * 16 kBytes sectors */
{ 2, 8*1024 }, /* 2 * 8 kBytes sectors */
{ 1, 32*1024 }, /* 1 * 32 kBytes sectors */
{ 31, 64*1024 }, /* 31 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgS29GL064[] =
{
{ 8, 8*1024 }, /* 8 * 8 kBytes sectors */
{ 127, 64*1024 }, /* 127 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgAT49BV6416[] =
{
{ 8, 8*1024 }, /* 8 * 8 kBytes sectors */
{ 127, 64*1024 }, /* 127 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgEN29LV320[] =
{
{ 8, 8*1024 }, /* 8 * 8 kBytes sectors */
{ 63, 64*1024 }, /* 63 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgMX29LV160[] =
{
{ 1, 16*1024 }, /* 1 * 16 kBytes sectors */
{ 2, 8*1024 }, /* 2 * 8 kBytes sectors */
{ 1, 32*1024 }, /* 1 * 32 kBytes sectors */
{ 31, 64*1024 }, /* 31 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgMX29LV320[] =
{
{ 8, 8*1024 }, /* 8 * 8 kBytes sectors */
{ 63, 64*1024 }, /* 63 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgMX29LV640[] =
{
{ 8, 8*1024 }, /* 8 * 8 kBytes sectors */
{ 127, 64*1024 }, /* 127 * 64 kBytes sectors */
};
CONST STATIC _OrgDef OrgA29L160[] =
{
{ 1, 16*1024 }, /* 1 * 16 kBytes sectors */
{ 2, 8*1024 }, /* 2 * 8 kBytes sectors */
{ 1, 32*1024 }, /* 1 * 32 kBytes sectors */
{ 31, 64*1024 }, /* 31 * 64 kBytes sectors */
};
#endif
#if defined(AT91SAM9260)
CONST STATIC ULONG BankBase[] = { 0x10000000 };
#elif defined(SH7040)
CONST STATIC ULONG BankBase[] =
{
0x00000000, 0x00100000, 0x00200000, 0x00300000, 0x00400000, 0x00500000,
0x00600000, 0x00700000, 0x00800000, 0x00900000, 0x00A00000, 0x00B00000,
};
#elif defined(N3290)
CONST STATIC ULONG BankBase[] = { 0x10000000 };
#endif
#if defined(__HITACHI__)
#pragma section
#endif
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
STATIC _FlashInfo FlashInfo[MAX_FLASH_BANKS];
VOID InitialFlash(VOID)
{
_OrgDef *FlashOrg;
ULONG addr;
INT FlashBlocks;
INT bank, block, sector;
addr = BankBase[0];
/* Init: no FLASHes known */
for ( bank = 0 ; bank < MAX_FLASH_BANKS ; bank++ )
{
FlashInfo[bank].FlashID = GetFlashID(BankBase[bank], FALSE);
if ( FlashInfo[bank].FlashID == ID_AM29F080 )
{
FlashOrg = (_OrgDef *)OrgAM29F080;
FlashBlocks = sizeof(OrgAM29F080) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_AM29F800 )
{
FlashOrg = (_OrgDef *)OrgAM29F800;
FlashBlocks = sizeof(OrgAM29F800) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_AM29F160 )
{
FlashOrg = (_OrgDef *)OrgAM29F160;
FlashBlocks = sizeof(OrgAM29F160) / sizeof(_OrgDef);
}
#if defined(AT91SAM9260)
else if ( FlashInfo[bank].FlashID == ID_S29AL016 )
{
FlashOrg = (_OrgDef *)OrgS29AL016;
FlashBlocks = sizeof(OrgS29AL016) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_S29GL064 )
{
FlashOrg = (_OrgDef *)OrgS29GL064;
FlashBlocks = sizeof(OrgS29GL064) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_AT49BV6416 )
{
FlashOrg = (_OrgDef *)OrgAT49BV6416;
FlashBlocks = sizeof(OrgAT49BV6416) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_EN29LV320 )
{
FlashOrg = (_OrgDef *)OrgEN29LV320;
FlashBlocks = sizeof(OrgEN29LV320) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_MX29LV160 )
{
FlashOrg = (_OrgDef *)OrgMX29LV160;
FlashBlocks = sizeof(OrgMX29LV160) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_MX29LV320 )
{
FlashOrg = (_OrgDef *)OrgMX29LV320;
FlashBlocks = sizeof(OrgMX29LV320) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_MX29LV640 )
{
FlashOrg = (_OrgDef *)OrgMX29LV640;
FlashBlocks = sizeof(OrgMX29LV640) / sizeof(_OrgDef);
}
else if ( FlashInfo[bank].FlashID == ID_A29L160 )
{
FlashOrg = (_OrgDef *)OrgA29L160;
FlashBlocks = sizeof(OrgA29L160) / sizeof(_OrgDef);
}
#endif
else
{
FlashInfo[bank].FlashID = _NULL;
FlashBlocks = 0;
}
FlashInfo[bank].BankSize = 0;
FlashInfo[bank].Sector = 0;
FlashInfo[bank].Start[0] = BankBase[bank];
if ( addr > BankBase[bank] )
continue;
sector = 0;
for ( block = 0 ; block < FlashBlocks ; block++ )
{
FlashInfo[bank].BankSize += (FlashOrg + block)->number * (FlashOrg + block)->size;
FlashInfo[bank].Sector += (FlashOrg + block)->number;
for ( ; sector < FlashInfo[bank].Sector ; sector++ )
{
FlashInfo[bank].Start[sector + 1] =
FlashInfo[bank].Start[sector] + (FlashOrg + block)->size;
FlashInfo[bank].Size[sector] = (FlashOrg + block)->size;
}
}
addr = FlashInfo[bank].Start[0] + FlashInfo[bank].BankSize;
if ( FlashInfo[bank].FlashID == ID_A29L160 )
{
/* Unlock all sectors at reset */
for ( sector = 0 ; sector < FlashInfo[bank].Sector ; sector++ )
UnlockSector(FlashInfo[bank].Start[sector], FALSE);
}
}
}
VOID FlashInformation(VOID)
{
INT bank, sector;
for ( bank = 0 ; bank < MAX_FLASH_BANKS ; bank++ )
{
SendPrintf("\r\n BankSize = %d KB", FlashInfo[bank].BankSize / 1024);
SendPrintf("\r\n Sector = %d", FlashInfo[bank].Sector);
SendPrintf("\r\n FlashID = 0x%08X", FlashInfo[bank].FlashID);
SendPrintf("\r\n Start = ");
for ( sector = 0 ; sector <= FlashInfo[bank].Sector ; sector++ )
SendPrintf("0x%08X,", FlashInfo[bank].Start[sector]);
SendPrintf("\r\n Size = ");
for ( sector = 0 ; sector <= FlashInfo[bank].Sector ; sector++ )
SendPrintf("0x%08X,", FlashInfo[bank].Size[sector]);
SendPrintf("\r\n");
}
}
#if defined(__HITACHI__)
#pragma section Flash
#endif
_FlashInfo *GetFlashInfo(ULONG base)
{
_FlashInfo *info = _NULL;
INT i;
for ( i = 0 ; i < MAX_FLASH_BANKS ; i++ )
{
info = &FlashInfo[i];
if ( info->BankSize && base >= info->Start[0] && base < info->Start[0] + info->BankSize )
break;
}
return i == MAX_FLASH_BANKS ? _NULL : info;
}
INT SearchFlashSector(_FlashInfo *info, ULONG addr)
{
INT sector;
for ( sector = 0 ; sector < info->Sector ; sector++ )
{
if ( addr >= info->Start[sector] && addr < info->Start[sector] + info->Size[sector] )
return sector;
}
return _ERROR;
}
ULONG GetFlashID(ULONG addr, BOOL close)
{
INT FlashID;
INT imask;
if ( close )
{
WaitWorkJobEnd();
imask = DisableInterrupt(FLASH_IMASK);
}
#if defined(DEFAULT_MCARD_MODEL)
if ( addr >= FLASH_8BIT_START && addr <= FLASH_8BIT_END )
FlashID = GetFlashID8(addr);
else
#endif
FlashID = GetFlashID16(addr);
if ( close )
EnableInterrupt(imask);
return FlashID;
}
VOID SectorErase(ULONG addr, BOOL close)
{
INT imask;
if ( close )
{
WaitWorkJobEnd();
imask = DisableInterrupt(FLASH_IMASK);
}
#if defined(DEFAULT_MCARD_MODEL)
if ( addr >= FLASH_8BIT_START && addr <= FLASH_8BIT_END )
SectorErase8(addr);
else
#endif
SectorErase16(addr);
if ( close )
EnableInterrupt(imask);
}
VOID ChipErase(ULONG addr, BOOL close)
{
INT imask;
if ( close )
{
WaitWorkJobEnd();
imask = DisableInterrupt(FLASH_IMASK);
}
#if defined(DEFAULT_MCARD_MODEL)
if ( addr >= FLASH_8BIT_START && addr <= FLASH_8BIT_END )
ChipErase8(addr);
else
#endif
ChipErase16(addr);
if ( close )
EnableInterrupt(imask);
}
VOID WriteFlash(ULONG addr, WORD data, BOOL close)
{
INT imask;
#ifdef DEBUG_PRNT
sysprintf("Enter WriteFlash()...\n"); // ch_20211211
#endif
if ( close )
{
WaitWorkJobEnd();
imask = DisableInterrupt(FLASH_IMASK);
}
#if defined(DEFAULT_MCARD_MODEL)
if ( addr >= FLASH_8BIT_START && addr <= FLASH_8BIT_END )
WriteFlash8(addr, data);
else
#endif
WriteFlash16(addr, data);
if ( close )
EnableInterrupt(imask);
}
VOID UnlockSector(ULONG addr, BOOL close)
{
INT imask;
if ( close )
{
WaitWorkJobEnd();
imask = DisableInterrupt(FLASH_IMASK);
}
UnlockSector16(addr);
if ( close )
EnableInterrupt(imask);
}
FlashLib.h 。。。。。。。。。。。。。。。。。。。。。。。。。。。。
#ifndef FLASHLIB_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define FLASHLIB_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
#if defined(AT91SAM9260)
#define MAX_FLASH_BANKS ( sizeof(BankBase) / sizeof(ULONG) )
#define MAX_FLASH_SECT 136
#elif defined(SH7040)
#define MAX_FLASH_BANKS ( sizeof(BankBase) / sizeof(ULONG) )
#define MAX_FLASH_SECT 36
#elif defined(N3290)
#define MAX_FLASH_BANKS ( sizeof(BankBase) / sizeof(ULONG) )
#define MAX_FLASH_SECT 136
#endif
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
/* Flash Organization Structure */
typedef struct
{
ULONG number;
ULONG size;
}_OrgDef;
/* FLASH Info: contains chip specific data, per FLASH bank */
typedef struct
{
ULONG BankSize; /* total bank size in bytes */
USHORT Sector; /* number of erase units */
ULONG FlashID; /* device & manufacturer code */
ULONG Start[MAX_FLASH_SECT]; /* sector start addresses */
ULONG Size[MAX_FLASH_SECT]; /* sector size in bytes */
}_FlashInfo;
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
VOID InitialFlash(VOID);
VOID FlashInformation(VOID);
_FlashInfo *GetFlashInfo(ULONG);
INT SearchFlashSector(_FlashInfo *, ULONG);
ULONG GetFlashID(ULONG, BOOL);
VOID SectorErase(ULONG, BOOL);
VOID ChipErase(ULONG, BOOL);
VOID WriteFlash(ULONG, WORD, BOOL);
VOID UnlockSector(ULONG, BOOL);
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif