?? norflashintel.c
字號:
volatile unsigned int busAddress;
unsigned char done = 0;
unsigned char busWidth;
busWidth = NorFlash_GetDataBusWidth(pNorFlashInfo);
intel_Reset(pNorFlashInfo, address);
busAddress = NorFlash_GetAddressInChip(pNorFlashInfo, address);
// Check if the data already have been erased.
ReadRawData(busWidth, busAddress, (unsigned char*)&datain);
if((datain & data)!= data) {
return NorCommon_ERROR_CANNOTWRITE;
}
// Word programming operations are initiated by writing the Word Program Setup command to the device.
WriteCommand(busWidth, busAddress, INTEL_CMD_PROGRAM_WORD);
// This is followed by a second write to the device with the address and data to be programmed.
WriteRawData(busWidth, busAddress, (unsigned char*)&data);
// Status register polling
do {
status = intel_ReadStatus(pNorFlashInfo,address);
// Check if the device is ready.
if ((status & INTEL_STATUS_DWS) == INTEL_STATUS_DWS ) {
// check if VPP within acceptable limits during program or erase operation.
if ((status & INTEL_STATUS_VPPS) == INTEL_STATUS_VPPS ) {
return NorCommon_ERROR_CANNOTWRITE;
}
// Check if the erase block operation is completed.
if ((status & INTEL_STATUS_PS) == INTEL_STATUS_PS ) {
return NorCommon_ERROR_CANNOTWRITE;
}
// check if Block locked during program or erase, operation aborted.
else if ((status & INTEL_STATUS_BLS) == INTEL_STATUS_BLS ) {
return NorCommon_ERROR_CANNOTWRITE;
}
else {
done = 1;
}
}
} while (!done);
intel_ClearStatus(pNorFlashInfo);
intel_Reset(pNorFlashInfo, address);
return 0;
}
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// It implements a RESET command.
/// \param pNorFlashInfo Pointer to an struct NorFlashInfo instance.
//------------------------------------------------------------------------------
void INTEL_Reset(struct NorFlashInfo *pNorFlashInfo, unsigned int address)
{
intel_Reset(pNorFlashInfo, address);
}
//------------------------------------------------------------------------------
/// The Read Device Identifier command instructs the device to output manufacturer
/// code.
/// \param pNorFlashInfo Pointer to an struct NorFlashInfo instance.
//------------------------------------------------------------------------------
unsigned int INTEL_ReadManufactoryId(struct NorFlashInfo *pNorFlashInfo)
{
return intel_ReadIdentification(pNorFlashInfo, INTEL_MANU_ID);
}
//------------------------------------------------------------------------------
/// The Read Device Identifier command instructs the device to output device id.
/// \param pNorFlashInfo Pointer to an struct NorFlashInfo instance.
//------------------------------------------------------------------------------
unsigned int INTEL_ReadDeviceID(struct NorFlashInfo *pNorFlashInfo)
{
return intel_ReadIdentification(pNorFlashInfo, INTEL_DEVIDE_ID);
}
//------------------------------------------------------------------------------
/// Erases the specified block of the device. Returns 0 if the operation was
/// successful; otherwise returns an error code.
/// \param pNorFlashInfo Pointer to an struct NorFlashInfo instance.
/// \param address Address offset to be erase.
//------------------------------------------------------------------------------
unsigned char INTEL_EraseSector(
struct NorFlashInfo *pNorFlashInfo,
unsigned int address)
{
unsigned int status;
unsigned int busAddress;
unsigned char busWidth;
unsigned char done = 0;
busWidth = NorFlash_GetDataBusWidth(pNorFlashInfo);
// Check the lock status is locked.
status = intel_GetBlockLockStatus(pNorFlashInfo, address);
if(( status & INTEL_LOCKSTATUS_LOCKED ) == INTEL_LOCKSTATUS_LOCKED){
intel_UnlockSector(pNorFlashInfo, address);
}
// Clear the status register first.
intel_ClearStatus(pNorFlashInfo);
busAddress = NorFlash_GetAddressInChip(pNorFlashInfo,address);
// Block erase operations are initiated by writing the Block Erase Setup command to the address of the block to be erased.
WriteCommand(busWidth, busAddress, INTEL_CMD_BLOCK_ERASE_1);
// Next, the Block Erase Confirm command is written to the address of the block to be erased.
WriteCommand(busWidth, busAddress, INTEL_CMD_BLOCK_ERASE_2);
// Status register polling
do {
status = intel_ReadStatus(pNorFlashInfo,address);
// Check if the device is ready.
if ((status & INTEL_STATUS_DWS) == INTEL_STATUS_DWS ) {
// Check if the erase block operation is completed.
if ((status & INTEL_STATUS_ES) == 0 ) {
done = 1;
}
else {
// check if VPP within acceptable limits during program or erase operation.
if ((status & INTEL_STATUS_VPPS) == INTEL_STATUS_VPPS ) {
return NorCommon_ERROR_CANNOTERASE;
}
// check if Block locked during program or erase, operation aborted.
else if ((status & INTEL_STATUS_BLS) == INTEL_STATUS_BLS ) {
return NorCommon_ERROR_CANNOTERASE;
}
}
}
} while (!done);
intel_Reset(pNorFlashInfo, 0);
return 0;
}
//------------------------------------------------------------------------------
/// Erases all the block of the device. Returns 0 if the operation was successful;
/// otherwise returns an error code.
/// \param pNorFlashInfo Pointer to an struct NorFlashInfo instance.
//------------------------------------------------------------------------------
unsigned char INTEL_EraseChip(struct NorFlashInfo *pNorFlashInfo)
{
// Interl flash have no independent Chip-erase command.
unsigned int i;
unsigned int sectors;
sectors = NorFlash_GetDeviceNumOfBlocks(pNorFlashInfo);
for (i = 0; i < sectors; i++) {
if (INTEL_EraseSector(pNorFlashInfo, NorFlash_GetDeviceSectorAddress(pNorFlashInfo, i))) {
return NorCommon_ERROR_CANNOTERASE;
}
}
return 0;
}
//------------------------------------------------------------------------------
/// Sends data to the struct NorFlashInfo chip from the provided buffer.
/// \param pNorFlashInfo Pointer to an struct NorFlashInfo instance.
/// \param address Start address offset to be wrote.
/// \param buffer Buffer where the data is stored.
/// \param size Number of bytes that will be written.
//------------------------------------------------------------------------------
unsigned char INTEL_Write_Data(
struct NorFlashInfo *pNorFlashInfo,
unsigned int address,
unsigned char *buffer,
unsigned int size)
{
unsigned int i;
unsigned char busWidth;
busWidth = pNorFlashInfo->deviceChipWidth;
if (busWidth == FLASH_CHIP_WIDTH_8BITS ){
for(i=0; i < size; i++) {
if(intel_Program(pNorFlashInfo, address, buffer[i])) {
return NorCommon_ERROR_CANNOTWRITE;
}
address ++;
}
}
else if( busWidth == FLASH_CHIP_WIDTH_16BITS ){
unsigned short *buffer16 = (unsigned short *) buffer;
size >>= 1;
for(i=0; i < size; i++) {
if(intel_Program(pNorFlashInfo, address, buffer16[i])){
return NorCommon_ERROR_CANNOTWRITE;
}
address+= 2;
}
}
else if(busWidth == FLASH_CHIP_WIDTH_32BITS ){
unsigned int *buffer32 = (unsigned int *) buffer;
size >>= 2;
for(i=0; i < size; i++) {
if(intel_Program(pNorFlashInfo, address, buffer32[i])){
return NorCommon_ERROR_CANNOTWRITE;
}
address+= 4;
}
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -