📄 64m_16e.c
字号:
0x2C8000L, /* Block 89:2C8000 - 2CFFFF(32kword) */
0x2D0000L, /* Block 90:2D0000 - 2D7FFF(32kword) */
0x2D8000L, /* Block 91:2D8000 - 2DFFFF(32kword) */
0x2E0000L, /* Block 92:2E0000 - 2E7FFF(32kword) */
0x2E8000L, /* Block 93:2E8000 - 2EFFFF(32kword) */
0x2F0000L, /* Block 94:2F0000 - 2F7FFF(32kword) */
0x2F8000L, /* Block 95:2F8000 - 2FFFFF(32kword) */
0x300000L, /* Block 96:300000 - 307FFF(32kword) */
0x308000L, /* Block 97:308000 - 30FFFF(32kword) */
0x310000L, /* Block 98:310000 - 317FFF(32kword) */
0x318000L, /* Block 99:318000 - 31FFFF(32kword) */
0x320000L, /* Block 100:320000 - 327FFF(32kword) */
0x328000L, /* Block 101:328000 - 32FFFF(32kword) */
0x330000L, /* Block 102:330000 - 337FFF(32kword) */
0x338000L, /* Block 103:338000 - 33FFFF(32kword) */
0x340000L, /* Block 104:340000 - 347FFF(32kword) */
0x348000L, /* Block 105:348000 - 34FFFF(32kword) */
0x350000L, /* Block 106:350000 - 357FFF(32kword) */
0x358000L, /* Block 107:358000 - 35FFFF(32kword) */
0x360000L, /* Block 108:360000 - 367FFF(32kword) */
0x368000L, /* Block 109:368000 - 36FFFF(32kword) */
0x370000L, /* Block 110:370000 - 377FFF(32kword) */
0x378000L, /* Block 111:378000 - 37FFFF(32kword) */
0x380000L, /* Block 112:380000 - 387FFF(32kword) */
0x388000L, /* Block 113:388000 - 38FFFF(32kword) */
0x390000L, /* Block 114:390000 - 397FFF(32kword) */
0x398000L, /* Block 115:398000 - 39FFFF(32kword) */
0x3A0000L, /* Block 116:3A0000 - 3A7FFF(32kword) */
0x3A8000L, /* Block 117:3A8000 - 3AFFFF(32kword) */
0x3B0000L, /* Block 118:3B0000 - 3B7FFF(32kword) */
0x3B8000L, /* Block 119:3B8000 - 3BFFFF(32kword) */
0x3C0000L, /* Block 120:3C0000 - 3C7FFF(32kword) */
0x3C8000L, /* Block 121:3C8000 - 3CFFFF(32kword) */
0x3D0000L, /* Block 122:3D0000 - 3D7FFF(32kword) */
0x3D8000L, /* Block 123:3D8000 - 3DFFFF(32kword) */
0x3E0000L, /* Block 124:3E0000 - 3E7FFF(32kword) */
0x3E8000L, /* Block 125:3E8000 - 3EFFFF(32kword) */
0x3F0000L, /* Block 126:3F0000 - 3F7FFF(32kword) */
0x3F8000L, /* Block 127:3F8000 - 3F8FFF( 4kword) */
0x3F9000L, /* Block 128:3F9000 - 3F9FFF( 4kword) */
0x3FA000L, /* Block 129:3FA000 - 3FAFFF( 4kword) */
0x3FB000L, /* Block 130:3FB000 - 3FBFFF( 4kword) */
0x3FC000L, /* Block 131:3FC000 - 3FCFFF( 4kword) */
0x3FD000L, /* Block 132:3FD000 - 3FDFFF( 4kword) */
0x3FE000L, /* Block 133:3FE000 - 3FEFFF( 4kword) */
0x3FF000L /* Block 134:3FF000 - 3FFFFF( 4kword) */
};
#endif
/* Specify Erase Block Number */
static const unsigned short nBlocks = sizeof( BlockOfs)/sizeof( BlockOfs[0]);
/*==========================================================================*/
/* In case of using Software Lock Release(WP#="L"),
Please reject comment below and various SW_LOCK_RELEASE. */
/*#define SW_LOCK_RELEASE*/
/*==========================================================================*/
/*****************************************************************************
* FmErase() Block Erase
* ---------------------------------------------------------------------------
* Declaration int FmErase(unsigned short *pEraseStart,
* unsigned char BlockNum)
* ---------------------------------------------------------------------------
* Description The block number to erase is specified.
* When the maximum block number +1 is specified, it erase to
* the last block in an order from block 0.
* ---------------------------------------------------------------------------
* Parameter unsigned short *pEraseStart; Erase strat address
* unsigned char BlockNum; Erase block number
* ---------------------------------------------------------------------------
* Return Value int Errflg;
* TRUE : Erase normal stop
* FALSE: Erase abnormal stop
* ---------------------------------------------------------------------------
* No Related Function
* ---------------------------------------------------------------------------
* Version Ver. 0.10.00 '01/06/04 First Release
* Ver. 0.20.00 '01/08/20 In Error Determination
* if ((*pEraseStart & 0x20) == 0x20) {
* -> if ((*pEraseStart & 0x38) != 0x00) {
* Ver. 0.30.00 '02/03/07 Add Software Lock Release
* Ver. 0.30.01 '02/12/16 Change bit range Byte to Word
* Ver. 0.40.00 '03/03/07 Change specify block number, commnt
*****************************************************************************/
int FmErase(unsigned short *pEraseStart,unsigned char BlockNum)
{
unsigned short ABBlockNum; /* All Blocks Erase */
#ifdef SW_LOCK_RELEASE
unsigned char BlockAddress; /* Block Address */
#endif
int Errflg = TRUE; /* Error Flag */
unsigned short *pCopyEraseStart; /* Erase Start Address */
pCopyEraseStart = pEraseStart;
if(BlockNum < nBlocks){
/*=== Erase of One Block ===*/
/***** Block Address to Erase *****/
pEraseStart = pEraseStart + BlockOfs[BlockNum];
#ifdef SW_LOCK_RELEASE
/* A15 - A21 get */
BlockAddress =
(unsigned char)(((unsigned long)pEraseStart&0x007f0000)>>16);
*pEraseStart = 0x60;
*pEraseStart = BlockAddress; /* A15 - A21 get */
*pEraseStart = 0xac;
*pEraseStart = (~BlockAddress)&0x7f; /* #A15 - #A21 get */
*pEraseStart = 0x7b;
#endif
/***** Output of Block Erase Command *****/
*pEraseStart = 0x20; /* 1st Bus Cycle */
*pEraseStart = 0xd0; /* 2nd Bus Cycle */
/***** Status Polling *****/
while((*pEraseStart & 0x80) != 0x80); /* Check of Sratus Data */
if ((*pEraseStart & 0x38) != 0x00) { /* Check of Error */
Errflg = FALSE; /* Set of Error Flag */
*pEraseStart = 0x50; /* Clear Status */
}
}else{
/*=== Erase of All Blocks ===*/
for(ABBlockNum = 0;ABBlockNum < nBlocks;ABBlockNum++){
/***** Block Address to Erase(Erase Start Address+Offset) *****/
pEraseStart = pCopyEraseStart + BlockOfs[ABBlockNum];
#ifdef SW_LOCK_RELEASE
/* A15 - A21 get */
BlockAddress =
(unsigned char)(((unsigned long)pEraseStart&0x007f0000)>>16);
*pEraseStart = 0x60;
*pEraseStart = BlockAddress; /* A15 - A21 get */
*pEraseStart = 0xac;
*pEraseStart = (~BlockAddress)&0x7f; /* #A15 - #21 get */
*pEraseStart = 0x7b;
#endif
/***** Output of Block Erase Comand *****/
*pEraseStart = 0x20; /* 1st Bus Cycle */
*pEraseStart = 0xd0; /* 2nd Bus Cycle */
/***** Status Polling *****/
while((*pEraseStart & 0x80) != 0x80); /* Check of Status Data */
if ((*pEraseStart & 0x38) != 0x00) { /* Check of Error */
Errflg = FALSE; /* Set of Error Flag */
*pEraseStart = 0x50; /* Clear Status */
break;
}
}
}
/***** Completion of Erase *****/
*pCopyEraseStart = 0xff; /* Output of Read Array Command */
return Errflg;
}
/*****************************************************************************
* FmEraseAllUnlockedBlocks() Erase All Unlocked Blocks
* ---------------------------------------------------------------------------
* Declaration int FmEraseAllUnlockedBlocks(unsigned short *pEraseStart)
* ---------------------------------------------------------------------------
* Description Erase of all unlocked blocks of Flash Memory(Chip Erase)
* ---------------------------------------------------------------------------
* Parameter unsigned short *pEraseStart; Start address of Flash Memory
* ---------------------------------------------------------------------------
* Return Value int Errflg;
* TRUE : Erase normal stop
* FALSE: Erase abnormal stop
* ---------------------------------------------------------------------------
* No Related Function
* ---------------------------------------------------------------------------
* Version Ver. 0.10.00 '03/03/07 First release
*****************************************************************************/
int FmEraseAllUnlockedBlocks(unsigned short *pEraseStart)
{
int Errflg = TRUE; /* Error Flag */
/***** Output of Erase of All Blocks Command *****/
*pEraseStart = 0xa7; /* 1st Bus Cycle */
*pEraseStart = 0xd0; /* 2nd Bus Cycle */
/***** Status Polling *****/
while((*pEraseStart & 0x80) != 0x80); /* Check of Status Data */
if ((*pEraseStart & 0x38) != 0x00) { /* Check of Error */
Errflg = FALSE; /* Set of Error Flag */
*pEraseStart = 0x50; /* Clear Status */
}
/***** Completion of Erase *****/
*pEraseStart = 0xff; /* Output of Read Array Command */
return Errflg;
}
/*****************************************************************************
* FmWordProgram() Word Program
* ---------------------------------------------------------------------------
* Declaration int FmWordProgram(unsigned short *pProgStart,
* unsigned short *pProgStop,
* unsigned short *pDataStart)
* ---------------------------------------------------------------------------
* Description Execute word program
* ---------------------------------------------------------------------------
* Parameter unsigned short *pProgStart; Program start address
* unsigned short *pProgStop; Program end address
* unsigned short *pDataStart; Start address of the data to be programed
* ---------------------------------------------------------------------------
* Return Value int Errflg;
* TRUE : Program normal stop
* FALSE: Program abnormal stop
* ---------------------------------------------------------------------------
* No Related Function
* ---------------------------------------------------------------------------
* Version Ver. 0.10.00 '01/06/04 First release
* Ver. 0.20.00 '01/08/20 In Error Determination
* if ((*pEraseStart & 0x10) == 0x10) {
* -> if ((*pEraseStart & 0x38) != 0x00) {
* Ver. 0.30.00 '02/03/07 Add Software Lock Release
* Ver. 0.40.00 '03/03/07 Change some comments
*****************************************************************************/
int FmWordProgram(unsigned short *pProgStart,unsigned short *pProgStop,
unsigned short *pDataStart)
{
int Errflg = TRUE; /* Error Flag */
unsigned short *pCopyProgStart; /* Program Start Address */
#ifdef SW_LOCK_RELEASE
unsigned char BlockAddress;
#endif
pCopyProgStart = pProgStart;
/*==== Loop until the Stop Address of the Program ====*/
while(pProgStart <= pProgStop){
#ifdef SW_LOCK_RELEASE
/* A15 - A21 get */
BlockAddress =
(unsigned char)(((unsigned long)pProgStart&0x007f0000)>>16);
*pProgStart = 0x60;
*pProgStart = BlockAddress; /* A15 - A21 get */
*pProgStart = 0xac;
*pProgStart = (~BlockAddress)&0x7f; /* #A15 - #21 get */
*pProgStart = 0x7b;
#endif
*pProgStart = 0x40; /* Output of Word Program Command */
*pProgStart = *pDataStart; /* Output of Program Data */
/***** Status Polling *****/
while((*pProgStart & 0x80) != 0x80);/* Status Data Confirmation */
if ((*pProgStart & 0x38) != 0x00) { /* Check of Error */
Errflg = FALSE; /* Set of Error Flag */
*pProgStart = 0x50; /* Clear Status */
break;
}
/***** Pointer Increment *****/
pProgStart++; /* Program Address+1 */
pDataStart++; /* Program Start Address of the Data+1 */
}/* End of while(pProgStart <= ...) */
/***** Completion of Word Program *****/
*pCopyProgStart = 0xff; /* Output of Read Array Command */
return Errflg;
}
/*****************************************************************************
* FmPageProgram() Page Program
* ---------------------------------------------------------------------------
* Declaration int FmPageProgram(unsigned short *pProgStart,
* unsigned short *pProgStop,
* unsigned short *pDataStart)
* ---------------------------------------------------------------------------
* Description Execute page program of Flash Memory
* Please specify the number of program data as a 128-word multiple
* ---------------------------------------------------------------------------
* Parameter unsigned short *pProgStart; Program start address
* unsigned short *pProgStop; Program stop address
* unsigned short *pDataStart; Start address of the data to be programed
* ---------------------------------------------------------------------------
* Return Value int Errflg;
* TRUE : Program normal stop
* FALSE: Program abnormal stop
* ---------------------------------------------------------------------------
* No Related Function
* ---------------------------------------------------------------------------
* Version Ver. 0.10.00 '01/06/04 First release
* Ver. 0.20.00 '01/08/20 In error determination
* if ((*pEraseStart & 0x10) == 0x10) {
* -> if ((*pEraseStart & 0x38) != 0x00) {
* Ver. 0.30.00 '02/03/07 Add software lock release
* Ver. 0.40.00 '03/03/07 Change some comments
*****************************************************************************/
int FmPageProgram(unsigned short *pProgStart,unsigned short *pProgStop,
unsigned short *pDataStart)
{
int Errflg = TRUE; /* Error Flag */
unsigned short *pProgStatus; /* Program Start Address */
int DataNum; /* Data Counter for Data Output Loop */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -