📄 c2635.c
字号:
Step 8: Decision between direct and single value programming
Step 9: Unlock Bypass Reset
*******************************************************************************/
ReturnType FlashProgram(udword udMode, udword udAddrOff, udword udNrOfElementsInArray, void *pArray ) {
ReturnType rRetVal = Flash_Success; /* Return Value: Initially optimistic */
ReturnType rProtStatus; /* Protection Status of a block */
uCPUBusType *ucpArrayPointer; /* Use an uCPUBusType to access the array */
udword udLastOff; /* Holds the last offset to be programmed */
uBlockType ublFirstBlock; /* The block where start to program */
uBlockType ublLastBlock; /* The last block to be programmed */
uBlockType ublCurBlock; /* Current block */
if (udMode > 1)
return Flash_FunctionNotSupported;
/* Step 1: Check if the data to be programmed are within the Flash memory space */
udLastOff = udAddrOff + udNrOfElementsInArray - 1;
if( udLastOff >= FLASH_SIZE )
return Flash_AddressInvalid;
/* Step 2: Determine first and last block to program */
for (ublFirstBlock=0; ublFirstBlock < NUM_BLOCKS-1;ublFirstBlock++)
if (udAddrOff < BlockOffset[ublFirstBlock+1])
break;
for (ublLastBlock=ublFirstBlock; ublLastBlock < NUM_BLOCKS-1;ublLastBlock++)
if (udLastOff < BlockOffset[ublLastBlock+1])
break;
/* Step 3: Check protection status for the blocks to be programmed */
for (ublCurBlock = ublFirstBlock; ublCurBlock <= ublLastBlock; ublCurBlock++){
if ( (rProtStatus = FlashCheckBlockProtection(ublCurBlock)) != Flash_BlockUnprotected ){
rRetVal = Flash_BlockProtected;
if (ublCurBlock == ublFirstBlock){
eiErrorInfo.udGeneralInfo[0] = udAddrOff;
return rRetVal;
} else {
eiErrorInfo.udGeneralInfo[0] = BlockOffset[ublCurBlock];
udLastOff = BlockOffset[ublCurBlock]-1;
} /* EndIf ublCurBlock */
} /* EndIf rProtStatus */
} /* Next ublCurBlock */
/* Step 4: Issue the Unlock Bypass command */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x00AA) ); /* 1st cycle */
FlashWrite( ConvAddr(0x002AA), (uCPUBusType)CMD(0x0055) ); /* 2nd cycle */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x0020) ); /* 3nd cycle */
ucpArrayPointer = (uCPUBusType *)pArray;
/* Step 5: Unlock Bypass Program command */
while( udAddrOff <= udLastOff ){
FlashWrite( ANY_ADDR, CMD(0x00A0) ); /* 1st cycle */
FlashWrite( udAddrOff, *ucpArrayPointer ); /* 2nd Cycle */
/* Step 6: Wait until Program/Erase Controller has completed */
if( FlashDataToggle() != Flash_Success){
/* Step 7: Return to Read Mode */
FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x00F0) ); /* Use single instruction cycle method */
rRetVal=Flash_ProgramFailed;
eiErrorInfo.udGeneralInfo[0] = udAddrOff;
break; /* exit while cycle */
} /* EndIf */
/* Step 8: Decision between direct and single value programming */
if (udMode == 0) /* Decision between direct and single value programming */
ucpArrayPointer++;
udAddrOff++;
} /* EndWhile */
/* Step 9: Unlock Bypass Reset */
FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x0090) ); /* 1st cycle */
FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x0000) ); /* 2st cycle */
return rRetVal;
} /* EndFunction FlashProgram */
/*******************************************************************************
Function: ReturnType FlashReadCfi( uword uwCfiFunc, uCPUBusType *ucpCfiValue )
Arguments: uwCfiFunc is set to the offset of the CFI parameter to be read.
The CFI value read from offset uwCfiFunc is passed back to the calling
function by *ucpCfiValue.
Return Value: The function returns the following conditions:
Flash_Success
Flash_CfiFailed
Description: This function checks whether the flash CFI is present and operable,
then reads the CFI value at the specified offset. The CFI value requested is
then passed back to the calling function.
Pseudo Code:
Step 1: Send the Read CFI Instruction
Step 2: Check that the CFI interface is operable
Step 3: If CFI is operable read the required CFI value
Step 4: Return the flash to Read Array mode
*******************************************************************************/
ReturnType FlashReadCfi( uword uwCfiFunc, uCPUBusType *ucpCfiValue ) {
ReturnType rRetVal = Flash_Success; /* Holds the return value */
udword udCfiAddr; /* Holds CFI address */
/* Step 1: Send the Read CFI Instruction */
FlashWrite( ConvAddr(0x55), (uCPUBusType)CMD(0x0098) );
/* Step 2: Check that the CFI interface is operable */
if( ((FlashRead( ShAddr(0x00000010) ) & CMD(0x00FF) ) != CMD(0x0051)) ||
((FlashRead( ShAddr(0x00000011) ) & CMD(0x00FF) ) != CMD(0x0052)) ||
((FlashRead( ShAddr(0x00000012) ) & CMD(0x00FF) ) != CMD(0x0059)) )
rRetVal = Flash_CfiFailed;
else {
/* Step 3: Read the required CFI Info */
udCfiAddr = (udword)uwCfiFunc;
*ucpCfiValue = FlashRead( ShAddr((udCfiAddr & 0x000000FF)) );
} /* EndIf */
FlashReset(); /* Step 4: Return to Read Array mode */
return rRetVal;
} /* EndFunction FlashReadCfi */
/*******************************************************************************
Function: ReturnType FlashReadDeviceId( uCPUBusType *ucpDeviceId )
Arguments: - *ucpDeviceId = <return value> The function returns the Device Code.
The device code for the part is:
M29W640G 0x227E
Note: In case a common response of more flash chips is not identical the real
read value will be given (Flash_ResponseUnclear)
Return Value: The function returns the following conditions:
Flash_Success
Flash_ResponseUnclear
Description: This function can be used to read the device code of the flash.
Pseudo Code:
Step 1: Send the Auto Select instruction
Step 2: Read the DeviceId
Step 3: Return the device to Read Array mode
Step 4: Check flash response (more flashes could give different results)
*******************************************************************************/
ReturnType FlashReadDeviceId( uCPUBusType *ucpDeviceId ) {
/* Step 1: Send the AutoSelect command */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x00AA) ); /* 1st Cycle */
FlashWrite( ConvAddr(0x002AA), (uCPUBusType)CMD(0x0055) ); /* 2nd Cycle */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x0090) ); /* 3rd Cycle */
/* Step 2: Read the DeviceId */
*ucpDeviceId = FlashRead(ShAddr(0x1)); /* A0 = 1, A1 = 0 */
/* Step 3: Return to Read Array Mode */
FlashReset();
/* Step 4: Check flash response (more flashes could give different results) */
return FlashResponseIntegrityCheck( ucpDeviceId );
} /* EndFunction FlashReadDeviceId */
/*******************************************************************************
Function: ReturnType FlashReadExtendedBlockVerifyCode( uCPUBusType *ucpVerifyCode )
Arguments: - *ucpVerifyCode = <return value>
The function returns the Extended Memory Block Verify Code.
The Extended Memory Block Verify Code for the part are:
M29W128G
0x80 (factory locked)
0x00 (not factory locked)
Note: In case a common response of more flash chips is not identical the real
read value will be given (Flash_ResponseUnclear)
Return Value: The function returns the following conditions:
Flash_Success
Flash_ResponseUnclear
Description: This function can be used to read the Extended Memory Block Verify Code.
The verify code is used to specify if the Extended Memory Block was locked/not locked
by the manufacturer.
Pseudo Code:
Step 1: Send the Auto Select instruction
Step 2: Read the Extended Memory Block Verify Code
Step 3: Return the device to Read Array mode
Step 4: Check flash response (more flashes could give different results)
*******************************************************************************/
ReturnType FlashReadExtendedBlockVerifyCode( uCPUBusType *ucpVerifyCode ) {
/* Step 1: Send the AutoSelect command */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x00AA) ); /* 1st Cycle */
FlashWrite( ConvAddr(0x002AA), (uCPUBusType)CMD(0x0055) ); /* 2nd Cycle */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x0090) ); /* 3rd Cycle */
/* Step 2: Read the Extended Memory Block Verify Code */
*ucpVerifyCode = FlashRead(ShAddr(0x3)); /* A0 = 1, A1 = 1 */
/* Step 3: Return to Read Array Mode */
FlashReset();
/* Step 4: Check flash response (more flashes could give different results) */
return FlashResponseIntegrityCheck( ucpVerifyCode );
} /* EndFunction FlashReadExtendedBlockVerifyCode */
/*******************************************************************************
Function: ReturnType FlashReadManufacturerCode( uCPUBusType *ucpManufacturerCode )
Arguments: - *ucpManufacturerCode = <return value> The function returns
the manufacture code (for ST = 0x0020).
In case a common response of more flash chips is not identical the real
read value will be given (Flash_ResponseUnclear)
Return Value: The function returns the following conditions:
Flash_Success
Flash_ResponseUnclear
Description: This function can be used to read the manufacture code of the flash.
Pseudo Code:
Step 1: Send the Auto Select instruction
Step 2: Read the Manufacturer Code
Step 3: Return the device to Read Array mode
Step 4: Check flash response (more flashes could give different results)
*******************************************************************************/
ReturnType FlashReadManufacturerCode( uCPUBusType *ucpManufacturerCode ) {
/* Step 1: Send the AutoSelect command */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x00AA) ); /* 1st Cycle */
FlashWrite( ConvAddr(0x002AA), (uCPUBusType)CMD(0x0055) ); /* 2nd Cycle */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x0090) ); /* 3rd Cycle */
/* Step 2: Read the DeviceId */
*ucpManufacturerCode = FlashRead( ShAddr(0x0) ); /* A0 = 0, A1 = 0 */
/* Step 3: Return to Read Array Mode */
FlashReset();
/* Step 4: Check flash response (more flashes could give different results) */
return FlashResponseIntegrityCheck( ucpManufacturerCode );
} /* EndFunction FlashReadManufacturerCode */
/*******************************************************************************
Function: ReturnType FlashReadMultipleDeviceId(uword uwDeviceIdNr,
uCPUBusType *ucpDeviceId )
Arguments:
uwDeviceIdNr, specify which Device ID to return.
*ucpDeviceId, after the execution the variable contains:
-> The specified device ID of a single device if all flash chips give
an identical result
-> The complete response of all devices in any other situation.
Description:
This function can be used to read the device code of the flash chips, in the
case they are identical.
Return Value:
Flash_Success = if the Device ID(s) are equal or there is a single flash chip
Flash_ResponseUnclear = if the Device Ids are different.
Notes: With A1=1 and A2=0 the device codes for the parts are:
M29W128F 0x227E
Pseudo Code:
Step 1: Select the correct address to read the required device ID
Step 2: Send the Auto Select instruction
Step 3: Read the DeviceId
Step 4: Return to Read Array Mode
Step 5: Check flash response (more flashes could give different results)
*******************************************************************************/
ReturnType FlashReadMultipleDeviceId(uword uwDeviceIdNr, uCPUBusType *ucpDeviceId ) {
uword uwRequiredDeviceIdAddr;
/* Step 1: Select the correct address to read the required device ID */
switch (uwDeviceIdNr) {
case 0:
uwRequiredDeviceIdAddr=0x0001;
break;
case 1:
uwRequiredDeviceIdAddr=0x000E;
break;
case 2:
uwRequiredDeviceIdAddr=0x000F;
break;
default:
eiErrorInfo.sprRetVal = FlashSpec_InvalidDeviceIdNr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -