/* ----------------------------------------------------------------------------
* 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 "ManagedNandFlash.h"
#include "NandSpareScheme.h"
#include "NandFlashModel.h"
#include "RawNandFlash.h"
#include <utility/trace.h>
#include <utility/assert.h>
#include <string.h>
//------------------------------------------------------------------------------
// Internal definitions
//------------------------------------------------------------------------------
// Customn trace levels for the current file
#define DEBUG trace_DEBUG
#define INFO trace_INFO
#define IMPORTANT trace_FATAL
// Casts
#define ECC(managed) ((struct EccNandFlash *) managed)
#define RAW(managed) ((struct RawNandFlash *) managed)
#define MODEL(managed) ((struct NandFlashModel *) managed)
// Values returned by the CheckBlock() function
#define BADBLOCK 255
#define GOODBLOCK 254
//------------------------------------------------------------------------------
// Internal functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Returns 1 if a nandflash device is virgin (i.e. has never been used as a
/// managed nandflash); otherwise return 0.
/// \param managed Pointer to a ManagedNandFlash instance.
//------------------------------------------------------------------------------
static unsigned char IsDeviceVirgin(const struct ManagedNandFlash *managed)
{
struct NandBlockStatus blockStatus;
const struct NandSpareScheme *scheme = NandFlashModel_GetScheme(MODEL(managed));
unsigned char spare[NandCommon_MAXPAGESPARESIZE];
unsigned char badBlockMarker;
unsigned char error;
// Read spare area of page #0
error = RawNandFlash_ReadPage(RAW(managed), 0, 0, 0, spare);
ASSERT(!error, "ManagedNandFlash_IsDeviceVirgin: Failed to read page #0\n\r");
// Retrieve bad block marker and block status from spare area
NandSpareScheme_ReadBadBlockMarker(scheme, spare, &badBlockMarker);
NandSpareScheme_ReadExtra(scheme, spare, &blockStatus, 4, 0);
// Check if block is marked as bad
if (badBlockMarker != 0xFF) {
// Device is not virgin, since page #0 is guaranteed to be good
return 0;
}
// If device is not virgin, then block status will be set to either
// FREE, DIRTY or LIVE
else if (blockStatus.status != NandBlockStatus_DEFAULT) {
// Device is not virgin
return 0;
}
return 1;
}
//------------------------------------------------------------------------------
/// Returns BADBLOCK if the given block of a nandflash device is bad; returns
/// GOODBLOCK if the block is good; or returns a NandCommon_ERROR code.
/// \param managed Pointer to a ManagedNandFlash instance.
/// \param block Number of block to check.
//------------------------------------------------------------------------------
static unsigned char CheckBlock(
const struct ManagedNandFlash *managed,
unsigned short block)
{
unsigned char spare[NandCommon_MAXPAGESPARESIZE];
unsigned char error;
unsigned int i;
unsigned char pageSpareSize = NandFlashModel_GetPageSpareSize(MODEL(managed));
// Read spare area of first page of block
error = RawNandFlash_ReadPage(RAW(managed), block, 0, 0, spare);
if (error) {
trace_LOG(trace_ERROR, "CheckBlock: Cannot read page #0 of block #%d\n\r", block);
return error;
}
// Make sure it is all 0xFF
for (i=0; i < pageSpareSize; i++) {
if (spare[i] != 0xFF) {
return BADBLOCK;
}
}
// Read spare area of second page of block
error = RawNandFlash_ReadPage(RAW(managed), block, 1, 0, spare);
if (error) {
trace_LOG(trace_ERROR, "CheckBlock: Cannot read page #1 of block #%d\n\r", block);
return error;
}
// Make sure it is all 0xFF
for (i=0; i < pageSpareSize; i++) {
if (spare[i] != 0xFF) {
return BADBLOCK;
}
}
return GOODBLOCK;
}
//------------------------------------------------------------------------------
/// Physically writes the status of a block inside its first page spare area.
/// Returns 0 if successful; otherwise returns a NandCommon_ERROR_xx code.
/// \param managed Pointer to a ManagedNandFlash instance.
/// \param block Block number.
//------------------------------------------------------------------------------
static unsigned char WriteBlockStatus(
const struct ManagedNandFlash *managed,
unsigned short block)
{
unsigned char spare[NandCommon_MAXPAGESPARESIZE];
memset(spare, 0xFF, NandCommon_MAXPAGESPARESIZE);
NandSpareScheme_WriteExtra(NandFlashModel_GetScheme(MODEL(managed)),
spare,
&(managed->blockStatuses[block]),
4,
0);
return RawNandFlash_WritePage(RAW(managed), block, 0, 0, spare);
}
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Initializes a ManagedNandFlash instance. Scans the device to retrieve or
/// create block status information.
/// \param managed Pointer to a ManagedNandFlash instance.
/// \param model Pointer to the underlying nand chip model. Can be 0.
/// \param commandAddress Address at which commands are sent.
/// \param addressAddress Address at which addresses are sent.
/// \param dataAddress Address at which data is sent.
/// \param pinChipEnable Pin controlling the CE signal of the NandFlash.
/// \param pinReadyBusy Pin used to monitor the ready/busy signal of the Nand.
//------------------------------------------------------------------------------
unsigned char ManagedNandFlash_Initialize(
struct ManagedNandFlash *managed,
const struct NandFlashModel *model,
unsigned int commandAddress,
unsigned int addressAdd
没有合适的资源?快使用搜索试试~ 我知道了~
at91sam9261裸机lcd+led+nandflash调试程序集合
共150个文件
lst:40个
o:40个
h:26个
3星 · 超过75%的资源 需积分: 12 33 下载量 74 浏览量
2009-08-14
14:45:41
上传
评论 2
收藏 934KB RAR 举报
温馨提示
适合mcuzone的开发板,在iar软件,使用x-link调试工具,将lcd led nandflash的单独程序整合在一起进行调试。sdarm为单片16位,16M。
资源推荐
资源详情
资源评论
收起资源包目录
at91sam9261裸机lcd+led+nandflash调试程序集合 (150个子文件)
at91sam9261-ek.cspy.bat 3KB
at91sam9261_sram.bin 59KB
ManagedNandFlash.c 28KB
RawNandFlash.c 27KB
MappedNandFlash.c 23KB
TranslatedNandFlash.c 23KB
main.c 19KB
lcd.c 18KB
SkipBlockNandFlash.c 16KB
board_memories.c 15KB
111lcd.c 15KB
pio_it.c 13KB
NandFlashModel.c 13KB
pio.c 12KB
hamming.c 12KB
EccNandFlash.c 8KB
NandSpareScheme.c 8KB
NandFlashModelList.c 7KB
board_lowlevel.c 7KB
dbgu.c 6KB
rtt.c 4KB
aic.c 4KB
math.c 3KB
style.css 2KB
at91sam9261-ek.dbgdt 6KB
at91sam9261-ek.dep 42KB
at91sam9261-ek.dni 751B
at91sam9261-ek.ewd 34KB
at91sam9261-ek.ewp 49KB
basic-nandflash-project.eww 423B
AT91SAM9261.h 257KB
bmp_logo.h 160KB
lcd.h 108KB
lcd_lut.h 24KB
board.h 18KB
pio.h 7KB
NandFlashModel.h 6KB
trace.h 5KB
NandCommon.h 5KB
ManagedNandFlash.h 5KB
RawNandFlash.h 4KB
NandSpareScheme.h 4KB
SkipBlockNandFlash.h 4KB
MappedNandFlash.h 4KB
TranslatedNandFlash.h 4KB
assert.h 4KB
111lcd.h 3KB
aic.h 3KB
dbgu.h 3KB
hamming.h 3KB
EccNandFlash.h 3KB
NandFlashModelList.h 3KB
pio_it.h 3KB
rtt.h 3KB
board_memories.h 2KB
math.h 2KB
readme.html 3KB
sdram.icf 2KB
sram.icf 2KB
header.jpg 37KB
lcd.lst 385KB
ManagedNandFlash.lst 141KB
ManagedNandFlash.lst 141KB
main.lst 130KB
MappedNandFlash.lst 114KB
MappedNandFlash.lst 114KB
RawNandFlash.lst 106KB
RawNandFlash.lst 106KB
TranslatedNandFlash.lst 96KB
TranslatedNandFlash.lst 95KB
SkipBlockNandFlash.lst 65KB
SkipBlockNandFlash.lst 65KB
board_memories.lst 53KB
board_memories.lst 52KB
main.lst 49KB
NandFlashModel.lst 43KB
NandFlashModel.lst 43KB
hamming.lst 41KB
hamming.lst 41KB
pio_it.lst 36KB
pio_it.lst 36KB
pio.lst 36KB
pio.lst 36KB
EccNandFlash.lst 33KB
EccNandFlash.lst 33KB
NandSpareScheme.lst 27KB
NandSpareScheme.lst 27KB
NandFlashModelList.lst 26KB
NandFlashModelList.lst 26KB
board_lowlevel.lst 24KB
board_lowlevel.lst 22KB
dbgu.lst 20KB
dbgu.lst 20KB
board_cstartup_iar.lst 17KB
board_cstartup_iar.lst 17KB
rtt.lst 17KB
aic.lst 11KB
aic.lst 11KB
math.lst 11KB
math.lst 11KB
共 150 条
- 1
- 2
资源评论
- zyzktp2013-01-21这个毫无价值,IAR中本来就有完整代码,而且这个编译还有错误, 另外说一下,评论另一个还网页出错了.
- 代码很单纯,复杂的是人。2013-10-22本来的官方例程,没有用.
- xzxzwr2013-03-02这个毫无价值
- oQianXiao123452014-05-14编译还有错误
shengming810615
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功