📄 c2635.c
字号:
return Flash_SpecificError;
} /* EndSwitch */
/* Step 2: Send the Auto Select instruction */
FlashWrite( ConvAddr(0x0555), CMD(0x00AA) );
/* 1st Cycle */
FlashWrite( ConvAddr(0x02AA), CMD(0x0055) );
/* 12nd Cycle */
FlashWrite( ConvAddr(0x0555), CMD(0x0090) );
/* 13rd Cycle */
/* Step 3: Read the DeviceId */
*ucpDeviceId = FlashRead ( ShAddr(uwRequiredDeviceIdAddr) );
/* Step 4: Return to Read Array Mode */
FlashReset();
/* Step 5: Check flash response (more flashes could give different results) */
return FlashResponseIntegrityCheck( ucpDeviceId );
} /* EndFunction FlashReadMultipleDeviceId */
/*******************************************************************************
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 */
/*******************************************************************************
Function: ReturnType FlashResume( void )
Arguments: none
Return Value: The function returns the following conditions:
Flash_Success
Description: This function resume a suspended operation.
Pseudo Code:
Step 1: Send the Erase resume command to the device
*******************************************************************************/
ReturnType FlashResume( void ) {
/* Step 1: Send the Erase Resume command */
FlashWrite( ANY_ADDR,CMD(0x0030) );
return Flash_Success;
} /* EndFunction FlashResume */
/*******************************************************************************
Function: ReturnType FlashSingleProgram( udword udAddrOff, uCPUBusType ucVal )
Arguments: udAddrOff is the offset in the flash to write to.
ucVal is the value to be written
Return Value: The function returns the following conditions:
Flash_Success
Flash_AddressInvalid
Flash_BlockProtected
Flash_ProgramFailed
Description: This function is used to write a single element to the flash.
Pseudo Code:
Step 1: Check the offset range is valid
Step 2: Check if the start block is protected
Step 3: Program sequence command
Step 4: Follow Data Toggle Flow Chart until Program/Erase Controller has
completed
Step 5: Return to Read Mode (if an error occurred)
*******************************************************************************/
ReturnType FlashSingleProgram( udword udAddrOff, uCPUBusType ucVal) {
uBlockType ublCurBlock;
/* Step 1: Check the offset and range are valid */
if( udAddrOff >= FLASH_SIZE )
return Flash_AddressInvalid;
/* compute the start block */
for (ublCurBlock=0; ublCurBlock < NUM_BLOCKS-1;ublCurBlock++)
if (udAddrOff < BlockOffset[ublCurBlock+1])
break;
/* Step 2: Check if the start block is protected */
if (FlashCheckBlockProtection(ublCurBlock)== Flash_BlockProtected) {
return Flash_BlockProtected;
} /* EndIf */
/*Step 3: Program sequence command */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x00AA) ); /* 1st cycle */
FlashWrite( ConvAddr(0x002AA), (uCPUBusType)CMD(0x0055) ); /* 2nd cycle */
FlashWrite( ConvAddr(0x00555), (uCPUBusType)CMD(0x00A0) ); /* Program command */
FlashWrite( udAddrOff,ucVal ); /* Program val */
/* Step 4: Follow Data Toggle Flow Chart until Program/Erase Controller
has completed */
/* See Data Toggle Flow Chart of the Data Sheet */
if( FlashDataToggle() != Flash_Success) {
/* Step 5: Return to Read Mode (if an error occurred) */
FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x00F0) ); /* Use single instruction cycle method */
return Flash_ProgramFailed ;
} /* EndIf */
return Flash_Success;
} /* EndFunction FlashSingleProgram */
/*******************************************************************************
Function: ReturnType FlashSuspend( void )
Arguments: none
Return Value: The function returns the following conditions:
Flash_Success
Description: This function suspends an operation.
Pseudo Code:
Step 1: Send the Erase suspend command to the device
*******************************************************************************/
ReturnType FlashSuspend( void ) {
/* Step 1: Send the Erase Suspend command */
FlashWrite( ANY_ADDR,CMD(0x00B0) );
return Flash_Success;
} /* EndFunction FlashSuspend */
/*******************************************************************************
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: void FlashWrite( udword udAddrOff, uCPUBusType ucVal )
Arguments: udAddrOff is double-word offset in the flash to write to.
ucVal is the value to be written
Return Value: None
Description: This function is used to write a uCPUBusType to the flash.
*******************************************************************************/
void FlashWrite( udword udAddrOff, uCPUBusType ucVal ) {
/* Write ucVal to the double-word offset in flash */
BASE_ADDR[udAddrOff] = ucVal;
} /* EndFunction FlashWrite */
/*******************************************************************************
Function: ReturnType FlashWriteProgramBuffer( udword udMode,udword udAddrOff,
udword udNrOfElementsInArray, void *pArray )
Arguments: udMode changes between programming modes
udAddrOff must be 32Word/64Byte aligned, is the address offset into the flash to be programmed
udNrOfElementsInArray holds the number of elements (uCPUBusType) in the array.
it must be between 1 to 16(16bit Mode) or 32(8bit Mode)
pArray is a void pointer to the array with the contents to be programmed.
Return Value: The function returns the following conditions:
Flash_Success successful operation
Flash_AddressInvalid program range outside device or udAddrOff is not 16Word/32Byte aligned
Flash_BlockProtected block to program is protected
Flash_ProgramFailed any other failure
Description: This function is used to program an array into the flash. It does
not erase the flash first and will not produce proper results, if the block(s)
are not erased first.
Any errors are returned without any further attempts to program other addresses
of the device. The function returns Flash_Success when all addresses have
successfully been programmed.
Note: Two program modes are available:
- udMode = 0, Normal Program Mode
The number of elements (udNumberOfElementsInArray) contained in pArray
are programmed directly to the flash starting with udAddrOff.
- udMode = 1, Single Value Program Mode
Only the first value of the pArray will be programmed to the flash
starting from udAddrOff.
Pseudo Code:
Step 1: Check whether the data to be programmed are within the
Flash memory
Step 2: Determine first and last block to program
Step 3: Check protection status for the blocks to be programmed
Step 4: Issue Write to Program Buffer command and Write Content to buffer
*******************************************************************************/
ReturnType FlashWriteProgramBuffer(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;
if (udAddrOff & ConvAddr(0x1F) != 0x0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -