📄 c2374.c
字号:
/* Step 3: Wait until Program/Erase Controller has completed */
if (FlashDataToggle(udAddrOff) != Flash_Success)
rRetVal = Flash_ProgramFailed;
/* Step 4: Return to read Array mode */
FlashReset();
return rRetVal;
} /* EndFunction FlashQuadProgram */
#endif /*defined(USE_M29W320EB_8) | defined(USE_M29W320ET_8) */
/*******************************************************************************
Function: uCPUBusType FlashRead( udword udAddrOff )
Arguments: udAddrOff is the offset into the flash to read from.
Return Value: The uCPUBusType content at the address offset.
Description: This function is used to read a uCPUBusType from the flash.
On many microprocessor systems a macro can be used instead, increasing the
speed of the flash routines. For example:
#define FlashRead( udAddrOff ) ( BASE_ADDR[udAddrOff] )
A function is used here instead to allow the user to expand it if necessary.
Pseudo Code:
Step 1: Return the value at double-word offset udAddrOff
*******************************************************************************/
uCPUBusType FlashRead( udword udAddrOff ) {
/* Step 1 Return the value at double-word offset udAddrOff */
return BASE_ADDR[udAddrOff];
} /* EndFunction FlashRead */
/*******************************************************************************
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:
M29W320EB 0x2257
M29W320ET 0x2256
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:
M29W320EB/T
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: void FlashReset( void )
Arguments: none
Return Value: Flash_Success
Description: This function places the flash in the Read Array mode described
in the Data Sheet. In this mode the flash can be read as normal memory.
All of the other functions leave the flash in the Read Array mode so this is
not strictly necessary. It is provided for completeness and in case of
problems.
Pseudo Code:
Step 1: write command sequence (see Instructions Table of the Data Sheet)
*******************************************************************************/
ReturnType FlashReset( void ) {
/* Step 1: write command sequence */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x00AA) ); /* 1st Cycle */
FlashWrite( ConvAddr(0x002AA), (uCPUBusType)CMD(0x0055) ); /* 2nd Cycle */
FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x00F0) ); /* 3rd Cycle: write 0x00F0 to ANY address */
return Flash_Success;
} /* EndFunction FlashReset */
/*******************************************************************************
Function: ReturnType FlashResponseIntegrityCheck(uCPUBusType *ucpFlashResponse)
Arguments: - ucpFlashResponse <parameter> + <return value>
The function returns a unique value in case one flash or an
array of flashes return all the same value (Consistent Response = Flash_Success).
In case an array of flashes returns different values the function returns the
received response without any changes (Inconsistent Response = Flash_ResponseUnclear).
Return Value: The function returns the following conditions:
Flash_Success
Flash_ResponseUnclear
Description: This function is used to create one response in multi flash
environments, instead of giving multiple answers of the single flash
devices.
For example: Using a 32bit CPU and two 16bit Flash devices, the device Id
would be directly read: 00170017h, because each device gives an answer
within the range of the databus. In order to give a simple response
like 00000017h in all possible configurations, this subroutine is used.
In case the two devices give different results for the device Id, the
answer would then be: 00150017h. This allows debugging and helps to
discover multiple flash configuration problems.
Pseudo Code:
Step 1: Extract the first single flash response
Step 2: Compare all next possible flash responses with the first one
Step 3a: Return all flash responses in case of different values
Step 3b: Return only the first single flash response in case of matching values
*******************************************************************************/
ReturnType FlashResponseIntegrityCheck(uCPUBusType *ucpFlashResponse) {
ubyte a;
union {
uCPUBusType ucFlashResponse;
ubyte ubBytes[sizeof(uCPUBusType)];
} FullResponse;
union {
uCPUBusType ucSingleResponse;
ubyte ubBytes[FLASH_BIT_DEPTH/8];
} SingleResponse;
SingleResponse.ucSingleResponse = 0;
FullResponse.ucFlashResponse = *ucpFlashResponse;
/* Step 1: Extract the first single flash response */
memcpy(SingleResponse.ubBytes, FullResponse.ubBytes, FLASH_BIT_DEPTH/8);
/* Step 2: Compare all next possible flash responses with the first one */
for (a = 0; a < sizeof(uCPUBusType); a += FLASH_BIT_DEPTH/8) {
if (memcmp (&FullResponse.ubBytes[a], SingleResponse.ubBytes, FLASH_BIT_DEPTH/8) != 0)
/* Step 3a: Return all flash responses in case of different values */
return Flash_ResponseUnclear;
} /* Next a */
/* Step 3b: Return only the first single flash response in case of matching values */
*ucpFlashResponse = SingleResponse.ucSingleResponse;
return Flash_Success;
} /* EndFunction FlashResponseIntegrityCheck */
/************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -