?? c2312.c
字號(hào):
if( (ucVal2&CMD(0x0040)) == (ucVal1&CMD(0x0040)) ) /* DQ6 == NO Toggle */
return Flash_Success;
/* Step 7: Else return Flash_ToggleFailed */
else {
/* DQ6 == Toggle here means fail */
eiErrorInfo.sprRetVal=FlashSpec_ToggleFailed;
return Flash_SpecificError;
} /* EndInf */
} /* EndWhile */
return Flash_OperationTimeOut; /*if exit from while loop then time out exceeded */
} /* EndFunction FlashDataToggle */
/*****************************************************************************************
Function: ReturnType FlashDoubleProgram( udword udAddrOff, uCPUBusType ucVal1,
uCPUBusType ucVal2 )
Arguments:
udAddrOff is an address offset into pair to be programmed
ucValue1 is the value to be programmed at the first address offset of pair
ucValue2 is the value to be programmed the second address offset of pair
Return Value:
The function returns the following conditions:
Flash_Success
Flash_AddressInvalid
Flash_BlockProtected
Flash_ProgramFailed
Description:
This function is used to program two uCPUBusType value into two addresses which differ
only for the bit A0 (LSB). It uses double-word program command. It does not
erase the flash first and no error is returned in case of double programming.
Once the program command has completed the function checks the Status
Register for errors. The function returns Flash_Success if the addresses
have successfully been programmed.
Note: 1) VPP must be set to VPPH. (Other limitations are indicated in the data sheet).
2) This procedure is available both in 16-bit and 8-bit mode.
Pseudo Code:
Step 1: Check the offset range is valid
Step 2: Check that the block(s) to be programmed are not protected
Step 3: Program the data
Step 4: Follow Data Toggle Flow Chart until Program/Erase Controller has
completed
Step 5: Return to Read Mode (if an error occurred)
*******************************************************************************/
ReturnType FlashDoubleProgram( udword udAddrOff, uCPUBusType ucVal1, uCPUBusType ucVal2 ) {
uBlockType ublCurBlock;
ReturnType rRetVal = Flash_Success; /* Return Value: Initially optimistic */
udword udFirstAddrOff; /* first address offset */
/* Step 1: Check that 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 */
udFirstAddrOff = udAddrOff & (~0x1); /* calculate first address offset*/
/* Step 3: Program the data */
FlashWrite( ConvAddr(0x555), (uCPUBusType)CMD(0x50) );/* Program Command */
FlashWrite( udFirstAddrOff, ucVal1 );
FlashWrite( udFirstAddrOff + 1, ucVal2 );
/* Step 4: Follow Data Toggle Flow Chart until Program/Erase Controller
has completed */
/* See Data Toggle Flow Chart of the Data Sheet */
if( FlashDataToggle(udFirstAddrOff) != 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 FlashDoubleProgram */
/*******************************************************************************
Function: void FlashEnterExtendedBlock (void);
Arguments: None
Return Value: None
Description: This function is used to send the Enter Extended block command to
the device
Pseudo Code:
Step 1: Send the Enter Extended Block command to the device
*******************************************************************************/
void FlashEnterExtendedBlock( void ) {
/* Step 1: Send the Unlock Bypass command */
FlashWrite( ConvAddr(0x0555), (uCPUBusType)CMD(0x00AA) ); /* 1st Cycle */
FlashWrite( ConvAddr(0x02AA), (uCPUBusType)CMD(0x0055) ); /* 2nd Cycle */
FlashWrite( ConvAddr(0x0555), (uCPUBusType)CMD(0x0088) ); /* 3rd Cycle */
} /* EndFunction FlashEnterExtendedBlock */
#ifdef VERBOSE
/*******************************************************************************
Function: byte *FlashErrorStr( ReturnType rErrNum );
Arguments: rErrNum is the error number returned from other Flash Routines
Return Value: A pointer to a string with the error message
Description: This function is used to generate a text string describing the
error from the flash. Call with the return value from other flash routines.
Pseudo Code:
Step 1: Return the correct string.
*******************************************************************************/
byte *FlashErrorStr( ReturnType rErrNum ) {
switch(rErrNum) {
case Flash_Success:
return "Flash - Success";
case Flash_FunctionNotSupported:
return "Flash - Function not supported";
case Flash_AddressInvalid:
return "Flash - Address is out of Range";
case Flash_BlockEraseFailed:
return "Flash - Block Erase failed";
case Flash_BlockNrInvalid:
return "Flash - Block Number is out of Range";
case Flash_BlockProtected:
return "Flash - Block is protected";
case Flash_BlockProtectFailed:
return "Flash - Block Protection failed";
case Flash_BlockProtectionUnclear:
return "Flash - Block Protection Status is unclear";
case Flash_BlockUnprotected:
return "Flash - Block is unprotected";
case Flash_CfiFailed:
return "Flash - CFI Interface failed";
case Flash_ChipEraseFailed:
return "Flash - Chip Erase failed";
case Flash_ChipUnprotectFailed:
return "Flash - Chip Unprotect failed";
case Flash_GroupProtectFailed:
return "Flash - Group Protect Failed";
case Flash_NoInformationAvailable:
return "Flash - No Information Available";
case Flash_OperationOngoing:
return "Flash - Operation ongoing";
case Flash_OperationTimeOut:
return "Flash - Operation TimeOut";
case Flash_ProgramFailed:
return "Flash - Program failed";
case Flash_ResponseUnclear:
return "Flash - Response unclear";
case Flash_SpecificError:
switch (eiErrorInfo.sprRetVal) {
case FlashSpec_MpuTooSlow:
return "Flash - Flash MPU too slow";
case FlashSpec_TooManyBlocks:
return "Flash - Too many Blocks";
case FlashSpec_ToggleFailed:
return "Flash - Toggle failed";
default:
return "Flash - Undefined Specific Error";
} /* EndSwitch eiErrorInfo */
case Flash_WrongType:
return "Flash - Wrong Type";
default:
return "Flash - Undefined Error Value";
} /* EndSwitch */
} /* EndFunction FlashErrorString */
#endif /* VERBOSE Definition */
/*******************************************************************************
Function: void FlashExitExtendedBlock (void);
Arguments: None
Return Value: None
Description: This function is used to send the Exit Extended Block to the device
Pseudo Code:
Step 1: Send the Exit Extended Block command to the device
*******************************************************************************/
void FlashExitExtendedBlock( void ){
/* Step 1: Send the Exit Extended Block command to the device */
FlashWrite( ConvAddr(0x0555), (uCPUBusType)CMD(0x00AA) ); /* 1st Cycle */
FlashWrite( ConvAddr(0x02AA), (uCPUBusType)CMD(0x0055) ); /* 2nd Cycle */
FlashWrite( ConvAddr(0x0555), (uCPUBusType)CMD(0x0090) ); /* 3rd Cycle */
FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x0000) );/* 4th Cycle */
} /* EndFunction FlashExitExtendedBlock */
/*******************************************************************************
Function: ReturnType FlashGroupProtect( uBlockType ublBlockNr )
Arguments:
ublBlockNr holds a block number in the group to protect
Description:
This function protects a group in the flash chip using
the In-System Protection procedure as described in the data sheet.
NOTE : This procedure required a high voltage level on Reset/Blocks Temporary
Unprotect pin !RP, else the function will return Flash_BlockProtectFailed.
For more datails see flow-chart in the Datasheet.
Return Value: The function returns the following conditions:
Flash_Success
Flash_BlockNrInvalid
Flash_BlockProtectFailed
Pseudo Code:
Step 1: Check for invalid block
Step 2: Set-up phase
Step 3: Protect phase
Step 4: Verify phase
Step 5: if verified return Flash_Success
Step 6:if not verified and if attempts number is < 25, repeat from step 2,
else return Flash_GroupProtectFailed
*******************************************************************************/
ReturnType FlashGroupProtect( uBlockType ublBlockNr) {
word wAttempt= 0;
uCPUBusType ucReadData;
/* Step 1: Check for invalid block. */
if( ublBlockNr >= NUM_BLOCKS ) /* Check specified blocks <= NUM_BLOCKS */
return Flash_BlockNrInvalid;
/* Step 2: set-up phase */
FlashWrite( (BlockOffset[ublBlockNr] | ShAddr(0x00000002)), CMD(0x0060) );
do {
/* Step 3: protect phase */
FlashWrite( (BlockOffset[ublBlockNr] | ShAddr(0x00000002)), CMD(0x0060) );
FlashPause(100);
/* Step 4: verify phase */
FlashWrite( (BlockOffset[ublBlockNr] | ShAddr(0x00000002)), CMD(0x0040) );
FlashPause(4);
ucReadData = FlashRead( BlockOffset[ublBlockNr] | ShAddr(0x00000002) );
/* Step 5: if verified return Flash_Success */
if ( ucReadData == CMD(0x0001) ){
FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x00F0) ); /* Use single instruction cycle method */
return Flash_Success;
} /* EndIf */
} while (++wAttempt < 25);
/* Step 6: if not verified and if attempts number is < 25, repeat step from step 2,
else return Flash_GroupProtectFailed */
FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x00F0) ); /* Use single instruction cycle method */
return Flash_GroupProtectFailed;
} /* EndFunction FlashGroupProtect */
/*******************************************************************************
Function:ReturnType FlashMultipleBlockErase(uBlockType ublNumBlocks,uBlockType
*ublpBlock,ReturnType *rpResults)
Arguments: ublNumBlocks holds the number of blocks in the array ubBlock
ublpBlocks is an array containing the blocks to be erased.
rpResults is an array that it holds the results of every single block
erase.
Every elements of rpResults will be filled with below values:
Flash_Success
Flash_BlockEraseFailed
Flash_BlockProtected
If a time-out occurs because the MPU is too slow then the function returns
Flash_MpuTooSlow
Return Value: The function returns the following conditions:
Flash_Success
Flash_BlockEraseFailed
Flash_BlockNrInvalid
Flash_OperationTimeOut
Flash_SpecificError : if a no standard error occour.In this case the
field sprRetVal of the global variable eiErrorInfo will be filled
with Flash_MpuTooSlow when any blocks are not erased because DQ3
the MPU is too slow.
Description: This function erases up to ublNumBlocks in the flash. The blocks
can be listed in any order. The function does not return until the blocks are
erased. If any blocks are protected or invalid none of the blocks are erased,
in this casse the function return Flash_BlockEraseFailed.
During the Erase Cycle the Data Toggle Flow Chart of the Data Sheet is
followed. The polling bit, DQ7, is not used.
Pseudo Code:
Step 1: Check for invalid block
Step 2: Check if some blocks are protected
Step 3: Write Block Erase command
Step 4: Check for time-out blocks
Step 5: Wait for the timer bit to be set.
Step 6: Follow Data Toggle Flow Chart until Program/Erase Controller has
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -