亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? managednandflash.c

?? at91sam9263操作NAND FLASH代碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* ----------------------------------------------------------------------------
 *         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 addressAddress,
    unsigned int dataAddress,
    const Pin pinChipEnable,
    const Pin pinReadyBusy)
{
    unsigned char error;
    unsigned char spare[NandCommon_MAXPAGESPARESIZE];
    unsigned int numBlocks;
    unsigned int pageSpareSize;
    const struct NandSpareScheme *scheme;
    unsigned int block;
    struct NandBlockStatus blockStatus;
    unsigned char badBlockMarker;
    unsigned int eraseCount, minEraseCount, maxEraseCount;

    trace_LOG(DEBUG, "ManagedNandFlash_Initialize()\n\r");

    // Initialize EccNandFlash
    error = EccNandFlash_Initialize(ECC(managed),
                                    model,
                                    commandAddress,
                                    addressAddress,
                                    dataAddress,
                                    pinChipEnable,
                                    pinReadyBusy);
    if (error) {

        return error;
    }

    // Retrieve model information
    numBlocks = NandFlashModel_GetDeviceSizeInBlocks(MODEL(managed));
    pageSpareSize = NandFlashModel_GetPageSpareSize(MODEL(managed));
    scheme = NandFlashModel_GetScheme(MODEL(managed));

    // Initialize block statuses
    // First, check if device is virgin
    if (IsDeviceVirgin(managed)) {

        trace_LOG(IMPORTANT, "Device is virgin, doing initial block scanning ...\n\r");

        // Perform initial scan of the device
        for (block=0; block < numBlocks; block++) {

            // Check if block is bad
            error = CheckBlock(managed, block);
            if (error == BADBLOCK) {

                // Mark block as bad
                trace_LOG(DEBUG, "Block #%d is bad\n\r", block);
                managed->blockStatuses[block].status = NandBlockStatus_BAD;
            }
            else if (error == GOODBLOCK) {

                // Mark block as free with erase count 0
                trace_LOG(DEBUG, "Block #%d is free\n\r", block);
                managed->blockStatuses[block].status = NandBlockStatus_FREE;
                managed->blockStatuses[block].eraseCount = 0;

                // Write status in spare of block first page
                error = WriteBlockStatus(managed, block);
                if (error) {

                    trace_LOG(trace_ERROR,
                              "ManagedNandFlash_Initialize: Failed to write spare area\n\r");
                    return error;
                }
            }
            else {

                trace_LOG(trace_ERROR,
                          "ManagedNandFlash_Initialize: Cannot scan device\n\r");
                return error;
            }
        }
    }
    else {

        trace_LOG(DEBUG, "Device is already managed, retrieving information ...\n\r");

        // Retrieve block statuses from their first page spare area
        // (find maximum and minimum wear at the same time)
        minEraseCount = 0xFFFFFFFF;
        maxEraseCount = 0;
        for (block=0; block < numBlocks; block++) {

            // Read spare of first page
            error = RawNandFlash_ReadPage(RAW(managed), block, 0, 0, spare);
            if (error) {

                trace_LOG(trace_ERROR,
                          "ManagedNandFlash_Initialize: Cannot retrieve info from block #%d\n\r",
                          block);
            }

            // Retrieve bad block marker and block status
            NandSpareScheme_ReadBadBlockMarker(scheme, spare, &badBlockMarker);
            NandSpareScheme_ReadExtra(scheme, spare, &blockStatus, 4, 0);

            // If they do not match, block must be bad
            if ((badBlockMarker != 0xFF) && (blockStatus.status != NandBlockStatus_BAD)) {

                trace_LOG(DEBUG, "Block #%d is bad\n\r", block);
                managed->blockStatuses[block].status = NandBlockStatus_BAD;
            }
            // Check that block status is not default (meaning block is not managed)
            else if (blockStatus.status == NandBlockStatus_DEFAULT) {

                ASSERT(0, "Block #%d is not managed\n\r", block);
            }
            // Otherwise block status is accurate
            else {

                trace_LOG(DEBUG, "Block #%03d : status = %2d | eraseCount = %d\n\r",
                          block, blockStatus.status, blockStatus.eraseCount);
                managed->blockStatuses[block] = blockStatus;

                // Check for min/max erase counts
                if (blockStatus.eraseCount < minEraseCount) {

                    minEraseCount = blockStatus.eraseCount;
                }
                if (blockStatus.eraseCount > maxEraseCount) {

                    maxEraseCount = blockStatus.eraseCount;
                }

                //// Clean block
                //// Release LIVE blocks
                //if (managed->blockStatuses[block].status == NandBlockStatus_LIVE) {
                //
                //    ManagedNandFlash_ReleaseBlock(managed, block);
                //}
                //// Erase DIRTY blocks
                //if (managed->blockStatuses[block].status == NandBlockStatus_DIRTY) {
                //
                //    ManagedNandFlash_EraseBlock(managed, block);
                //}
            }
        }

        // Display erase count information
        trace_LOG(IMPORTANT, "|--------|------------|--------|--------|--------|\n\r");
        trace_LOG(IMPORTANT, "|  Wear  |   Count    |  Free  |  Live  | Dirty  |\n\r");
        trace_LOG(IMPORTANT, "|--------|------------|--------|--------|--------|\n\r");

        for (eraseCount=minEraseCount; eraseCount <= maxEraseCount; eraseCount++) {

            unsigned int count = 0, live = 0, dirty = 0, free = 0;
            for (block=0; block < numBlocks; block++) {

                if ((managed->blockStatuses[block].eraseCount == eraseCount)
                    && (managed->blockStatuses[block].status != NandBlockStatus_BAD)) {

                    count++;
                
                    switch (managed->blockStatuses[block].status) {
                        case NandBlockStatus_LIVE: live++; break;
                        case NandBlockStatus_DIRTY: dirty++; break;
                        case NandBlockStatus_FREE: free++; break;
                    }
                }
            }

            if (count > 0) {
            
                trace_LOG(IMPORTANT, "|  %4d  |  %8d  |  %4d  |  %4d  |  %4d  |\n\r",
                          eraseCount, count, free, live, dirty);
            }
        }
        trace_LOG(IMPORTANT, "|--------|------------|--------|--------|--------|\n\r");
    }

    return 0;
}

//------------------------------------------------------------------------------
/// Allocates a FREE block of a managed nandflash and marks it as LIVE.
/// Returns 0 if successful; otherwise returns NandCommon_ERROR_WRONGSTATUS if
/// the block is not FREE.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区加勒比av| 99久久久久久| 色哟哟欧美精品| 5月丁香婷婷综合| 亚洲三级久久久| 久久精品999| 欧美日韩国产系列| 日韩毛片一二三区| 成人综合在线网站| 精品福利一区二区三区| 香蕉成人伊视频在线观看| 成人a区在线观看| 久久先锋影音av| 蜜臀av性久久久久av蜜臀妖精| 欧美日韩精品一区二区天天拍小说| 日本一区二区三区国色天香| 日韩 欧美一区二区三区| 欧美在线小视频| 一区二区三区视频在线看| 99re66热这里只有精品3直播| 国产片一区二区| 国产一区二区精品久久99| 2021久久国产精品不只是精品| 首页综合国产亚洲丝袜| 欧美精品在欧美一区二区少妇| 亚洲一区二区三区不卡国产欧美| 一本色道a无线码一区v| 日韩一区有码在线| 91色在线porny| 亚洲精品欧美专区| 99re6这里只有精品视频在线观看| 欧美经典三级视频一区二区三区| 国内精品不卡在线| 欧美国产视频在线| 成人毛片在线观看| 亚洲男人天堂一区| 在线观看视频一区二区欧美日韩| 亚洲男人天堂av网| 欧美日韩国产精选| 蜜臀av国产精品久久久久| 日韩美女视频在线| 国产不卡视频一区| 亚洲乱码国产乱码精品精的特点 | 国产精品久久久久一区二区三区| 成人综合日日夜夜| 亚洲精品综合在线| 欧美人与禽zozo性伦| 久久精品国产亚洲5555| 国产亚洲人成网站| eeuss鲁片一区二区三区| 一区二区三区久久| 欧美肥大bbwbbw高潮| 国产精品1区2区| 一区二区三区四区视频精品免费 | 色吧成人激情小说| 石原莉奈在线亚洲三区| 26uuuu精品一区二区| 99久久综合99久久综合网站| 亚洲愉拍自拍另类高清精品| 欧美一级爆毛片| 成人天堂资源www在线| 亚洲美女淫视频| 亚洲三级在线播放| 欧美日韩一区三区| 国产精品77777竹菊影视小说| 中文字幕在线观看不卡视频| 91精品国产福利在线观看 | 天堂成人免费av电影一区| 欧美成人三级在线| 色妞www精品视频| 蜜桃一区二区三区在线观看| 综合电影一区二区三区| 日韩欧美久久一区| 色婷婷综合久久久| 精品一区二区免费视频| 亚洲精品福利视频网站| 精品国产乱码久久| 欧美日韩精品欧美日韩精品| 国产精品一品二品| 日韩精品一二三区| ●精品国产综合乱码久久久久| 欧美成人vps| 欧美巨大另类极品videosbest | 国内精品在线播放| 亚洲综合精品久久| 日本一区二区电影| 欧美一级免费观看| 91免费在线播放| 国产乱码精品1区2区3区| 日韩高清国产一区在线| 亚洲乱码国产乱码精品精可以看| 久久午夜老司机| 欧美精品1区2区3区| 91美女精品福利| 成人ar影院免费观看视频| 激情欧美一区二区| 日韩国产一二三区| 亚洲午夜视频在线观看| 国产精品麻豆99久久久久久| 久久丝袜美腿综合| 精品日韩一区二区三区| 91麻豆精品国产91久久久资源速度| 91麻豆国产在线观看| www.在线欧美| 99久久久无码国产精品| 99国产精品99久久久久久| thepron国产精品| 成人蜜臀av电影| 成人黄色一级视频| 高清不卡一二三区| 成人av资源在线观看| 成人听书哪个软件好| 不卡av在线网| 91偷拍与自偷拍精品| 91美女精品福利| 欧美三级资源在线| 欧美精品自拍偷拍| 欧美一级黄色片| 日韩欧美在线影院| 久久久精品国产免费观看同学| 久久综合狠狠综合久久综合88| 精品少妇一区二区三区| 精品成人佐山爱一区二区| 久久婷婷色综合| 久久色.com| 亚洲人成人一区二区在线观看 | 国产精品久久久一本精品| 中文字幕亚洲区| 一区二区三区精密机械公司| 亚洲成a人v欧美综合天堂 | 午夜精品一区二区三区三上悠亚 | 亚洲情趣在线观看| 亚洲综合色丁香婷婷六月图片| 国产一区二区剧情av在线| 国产二区国产一区在线观看| 懂色av一区二区在线播放| 日本韩国精品在线| 91麻豆精品国产91久久久使用方法| 久久只精品国产| 伊人色综合久久天天| 美女视频网站久久| 99久久伊人网影院| 欧美一区二区大片| 国产精品毛片大码女人| 亚洲午夜久久久| 国产成人一级电影| 欧美性生活影院| 久久久精品国产99久久精品芒果| 亚洲欧美色综合| 蜜臂av日日欢夜夜爽一区| 福利一区福利二区| 51精品秘密在线观看| 国产欧美日韩在线| 日韩高清在线电影| 99国产精品久久久久| 欧美一区二区不卡视频| 中文字幕日韩一区二区| 日韩av中文字幕一区二区| 成人a区在线观看| 欧美成人vr18sexvr| 亚洲精品视频在线观看网站| 久久99热99| 欧美三级电影在线观看| 中文字幕不卡在线观看| 日韩精品成人一区二区三区 | 3atv一区二区三区| 自拍av一区二区三区| 国产一区二区三区在线观看精品| 91福利资源站| 亚洲欧美在线aaa| 国内成+人亚洲+欧美+综合在线| 欧美在线视频你懂得| 国产精品久久久久精k8| 国产乱码精品1区2区3区| 欧美一级片在线看| 亚洲成人你懂的| 在线欧美日韩国产| 最新热久久免费视频| 国产宾馆实践打屁股91| 精品国产伦一区二区三区观看体验 | 成人精品免费网站| 2020国产精品自拍| 精品一区二区免费在线观看| 91麻豆精品国产91久久久久| 亚洲一区二区三区在线| 色婷婷久久久久swag精品| 国产精品福利一区| 国产成人自拍在线| 久久久www免费人成精品| 久久国产精品免费| 日韩欧美在线综合网| 美女视频黄 久久| 日韩欧美在线一区二区三区| 久久精品国产成人一区二区三区| 欧美精选一区二区| 蜜臀久久99精品久久久画质超高清 | 日韩高清一级片| 91精品福利在线一区二区三区| 亚洲午夜视频在线观看| 欧美精品日韩综合在线|