?? norflashcfi.c
字號:
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "NorFlashAPI.h"
#include "norFlashAmd.h"
#include "norFlashIntel.h"
#include "NorFlashCommon.h"
#include <utility/trace.h>
#include <string.h>
//------------------------------------------------------------------------------
// Internal definitions
//------------------------------------------------------------------------------
#define DUMP_CFI
//------------------------------------------------------------------------------
// Local functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Dump the Common Flash Interface Definition Table.
/// \param pNorFlashCFI Pointer to an NorFlashCFI instance.
//------------------------------------------------------------------------------
void NorFlash_CFI_DumpConfigruation(struct NorFlashCFI *pNorFlashCFI)
{
unsigned char i;
trace_LOG(trace_DEBUG, "\n\r-I- Common Flash Interface Definition Table\n\r");
trace_LOG(trace_DEBUG, "-I- Addr. Data Description \n\r");
trace_LOG(trace_DEBUG, "-I- 0x10 %04Xh Query Unique ASCII string\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.queryUniqueString[0]);
trace_LOG(trace_DEBUG, "-I- 0x11 %04Xh \n\r",
pNorFlashCFI->norFlashCfiQueryInfo.queryUniqueString[1]);
trace_LOG(trace_DEBUG, "-I- 0x12 %04Xh \n\r",
pNorFlashCFI->norFlashCfiQueryInfo.queryUniqueString[2]);
trace_LOG(trace_DEBUG, "-I- 0x13 %04Xh Primary OEM Command Set\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.primaryCode);
trace_LOG(trace_DEBUG, "-I- 0x15 %04Xh Address for Primary Extended Table\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.primaryAddr);
trace_LOG(trace_DEBUG, "-I- 0x17 %04Xh Alternate OEM Command Set\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.alternateCode);
trace_LOG(trace_DEBUG, "-I- 0x19 %04Xh Address for Alternate OEM Extended Table\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.alternateAddr);
trace_LOG(trace_DEBUG, "-I- 0x1B %04Xh VCC min write/erase\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.minVcc);
trace_LOG(trace_DEBUG, "-I- 0x1C %04Xh VCC max write/erase\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.maxVcc);
trace_LOG(trace_DEBUG, "-I- 0x1D %04Xh VPP min voltage\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.minVpp);
trace_LOG(trace_DEBUG, "-I- 0x1E %04Xh VPP max voltage\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.maxVpp);
trace_LOG(trace_DEBUG, "-I- 0x1F %04Xh Typical timeout per single word write\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.minTimeOutWrite);
trace_LOG(trace_DEBUG, "-I- 0x20 %04Xh Typical timeout for Min. size buffer write\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.minTimeOutBuffer);
trace_LOG(trace_DEBUG, "-I- 0x21 %04Xh Typical timeout per individual block erase\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.minTimeOutBlockErase);
trace_LOG(trace_DEBUG, "-I- 0x22 %04Xh Typical timeout for full chip erase\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.minTimeOutChipErase);
trace_LOG(trace_DEBUG, "-I- 0x23 %04Xh Max. timeout for word write\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.maxTimeOutWrite);
trace_LOG(trace_DEBUG, "-I- 0x24 %04Xh Max. timeout for buffer write\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.maxTimeOutBuffer);
trace_LOG(trace_DEBUG, "-I- 0x25 %04Xh Max. timeout per individual block erase\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.maxTimeOutBlockErase);
trace_LOG(trace_DEBUG, "-I- 0x26 %04Xh Max. timeout for full chip erase\n\r",
pNorFlashCFI->norFlashCfiQueryInfo.maxTimeOutChipErase);
trace_LOG(trace_DEBUG, "-I- 0x27 %04Xh Device Size = 2N byte\n\r",
pNorFlashCFI->norFlashCfiDeviceGeometry.deviceSize);
trace_LOG(trace_DEBUG, "-I- 0x28 %04Xh Flash Device Interface description\n\r",
pNorFlashCFI->norFlashCfiDeviceGeometry.deviceInterface);
trace_LOG(trace_DEBUG, "-I- 0x2A %04Xh Max. number of byte in multi-byte write\n\r",
pNorFlashCFI->norFlashCfiDeviceGeometry.numMultiWrite);
trace_LOG(trace_DEBUG, "-I- 0x2C %04Xh Number of Erase Block Regions within device\n\r",
pNorFlashCFI->norFlashCfiDeviceGeometry.numEraseRegion);
for(i = 0; i < pNorFlashCFI->norFlashCfiDeviceGeometry.numEraseRegion; i++) {
trace_LOG(trace_DEBUG, "-I- 0x%2X %04Xh Number of Erase Blocks of identical size within region %x \n\r",
0x2D + i * 4, pNorFlashCFI->norFlashCfiDeviceGeometry.eraseRegionInfo[i].Y, i );
trace_LOG(trace_DEBUG, "-I- 0x%2X %04Xh (z) times 256 bytes within region %x \n\r",
0x2E + i * 4, pNorFlashCFI->norFlashCfiDeviceGeometry.eraseRegionInfo[i].Z, i );
}
}
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Returns the numbers of block in all Norflash regions.
/// \param pNorFlashInfo Pointer to a NorFlashInfo instance.
//------------------------------------------------------------------------------
unsigned int NorFlash_GetDeviceNumOfBlocks(
struct NorFlashInfo *pNorFlashInfo)
{
unsigned char i;
unsigned int blocks = 0;
unsigned short numBlockRegion;
numBlockRegion = pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.numEraseRegion;
for (i = 0; i < numBlockRegion; i++) {
blocks += (pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.eraseRegionInfo[i]).Y + 1;
}
return blocks;
}
//------------------------------------------------------------------------------
/// Returns the minimun block size in all Norflash regions.
/// \param pNorFlashInfo Pointer to a NorFlashInfo instance.
//------------------------------------------------------------------------------
unsigned int NorFlash_GetDeviceMinBlockSize(
struct NorFlashInfo *pNorFlashInfo)
{
unsigned char i;
unsigned short numBlockRegion;
unsigned long size ;
numBlockRegion = pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.numEraseRegion;
size = (pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.eraseRegionInfo[0].Z) * 256;
for (i = 1; i < numBlockRegion; i++) {
if (size > (pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.eraseRegionInfo[i].Z) * 256) {
size = (pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.eraseRegionInfo[i].Z) * 256 ;
}
}
return size;
}
//------------------------------------------------------------------------------
/// Returns the maximun block size in all Norflash regions.
/// \param pNorFlashInfo Pointer to a NorFlashInfo instance.
//------------------------------------------------------------------------------
unsigned int NorFlash_GetDeviceMaxBlockSize(
struct NorFlashInfo *pNorFlashInfo)
{
unsigned char i;
unsigned short numBlockRegion;
unsigned long size ;
numBlockRegion = pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.numEraseRegion;
size = (pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.eraseRegionInfo[0].Z) * 256;
for (i = 1; i < numBlockRegion; i++) {
if (size < (pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.eraseRegionInfo[i].Z) * 256) {
size = (pNorFlashInfo->cfiDescription.norFlashCfiDeviceGeometry.eraseRegionInfo[i].Z) * 256 ;
}
}
return size;
}
//------------------------------------------------------------------------------
/// Returns the block size in giving block number.
/// \param pNorFlashInfo Pointer to a NorFlashInfo instance.
/// \param sector Sector number.
//------------------------------------------------------------------------------
unsigned int NorFlash_GetDeviceBlockSize(
struct NorFlashInfo *pNorFlashInfo,
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -