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

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

?? managednandflash.c

?? IAR5.2下 AT91SAM9260 ARM 對 MCP2515 控制源化碼
?? 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;
    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));
    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 #%u 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 #%u 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 #%u\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 #%u 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 #%u is not managed\n\r", block);
            }
            // Otherwise block status is accurate
            else {

                trace_LOG(DEBUG, "Block #%03u : status = %2u | eraseCount = %u\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, "|  %4u  |  %8u  |  %4u  |  %4u  |  %4u  |\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人网站| 精品成人免费观看| 丁香啪啪综合成人亚洲小说| 日本一不卡视频| 亚洲自拍偷拍欧美| 亚洲特级片在线| 国产精品美女久久久久av爽李琼| 91精品国产综合久久福利| 欧美三级在线播放| 亚洲精品在线一区二区| 91精品婷婷国产综合久久竹菊| 一本大道av一区二区在线播放| 国产成人精品午夜视频免费| 国产精品456| 成人综合婷婷国产精品久久免费| 国产精品亚洲一区二区三区妖精 | 久久综合色天天久久综合图片| 337p亚洲精品色噜噜噜| 欧美一区二区视频观看视频| 日韩欧美高清一区| 久久久久久久久岛国免费| 久久一留热品黄| 精品国产百合女同互慰| 国产精品白丝在线| 国产精品久久久久永久免费观看| 国产欧美日产一区| 有坂深雪av一区二区精品| 亚洲午夜日本在线观看| 日本视频中文字幕一区二区三区| 首页欧美精品中文字幕| 久久99国产精品尤物| 不卡影院免费观看| 在线观看亚洲a| 久久久www成人免费无遮挡大片| 国产亚洲精品资源在线26u| 亚洲欧美日韩国产一区二区三区| 亚洲一区日韩精品中文字幕| 久草中文综合在线| 欧美性色综合网| 中文字幕免费不卡| 秋霞影院一区二区| av一区二区久久| 久久久亚洲精品一区二区三区| 亚洲男帅同性gay1069| 麻豆国产欧美一区二区三区| 91麻豆精品一区二区三区| 日韩精品一区国产麻豆| 亚洲国产美女搞黄色| av午夜一区麻豆| 久久精品亚洲国产奇米99| 日韩国产欧美在线观看| 97精品视频在线观看自产线路二| 欧美不卡激情三级在线观看| 亚洲大片一区二区三区| 91福利视频网站| 亚洲视频一区二区在线| 国产精品一二三在| www成人在线观看| 久久精品国产一区二区三| 5月丁香婷婷综合| 青娱乐精品视频| 欧美日韩一区二区三区在线 | 日韩三级视频在线看| 日日欢夜夜爽一区| 欧美一区二区网站| 蜜臀久久99精品久久久久宅男| 欧美高清一级片在线| 偷窥少妇高潮呻吟av久久免费| 在线观看不卡视频| 日韩成人av影视| 26uuu国产电影一区二区| 国产在线精品免费| 国产精品久久久久婷婷二区次| 成人福利在线看| 亚洲一级二级三级| 日韩精品一区二区三区swag | 制服.丝袜.亚洲.中文.综合| 久久国产精品无码网站| 国产精品视频一二三区| 欧美亚洲动漫制服丝袜| 免费高清不卡av| 国产女人aaa级久久久级| 99r国产精品| 蜜臀av一级做a爰片久久| 国产亚洲综合色| 日本精品视频一区二区| 毛片一区二区三区| 亚洲天堂久久久久久久| 在线电影院国产精品| 国产精品18久久久久久vr| 国产精品女主播在线观看| 欧美性一二三区| 国产一区二区三区香蕉| 中文字幕一区二区三区在线不卡 | 欧美人狂配大交3d怪物一区 | 国产一区二区三区四| 夜色激情一区二区| 国产欧美日本一区二区三区| 91精品国产欧美一区二区| 不卡的电影网站| 久久99日本精品| 亚洲超丰满肉感bbw| 国产欧美日本一区二区三区| 欧美一区二区三区在线观看| 色av一区二区| 成人午夜私人影院| 久久97超碰国产精品超碰| 日韩精品一二三四| 不卡视频在线观看| 丁香桃色午夜亚洲一区二区三区| 青娱乐精品在线视频| 午夜精品久久久| 亚洲永久精品大片| 亚洲综合成人网| 亚洲国产欧美日韩另类综合| 一区二区三区视频在线观看| 亚洲欧洲韩国日本视频| 中文字幕在线不卡| 亚洲三级在线免费| 一片黄亚洲嫩模| 亚洲一级在线观看| 日本女优在线视频一区二区| 亚洲午夜一区二区| 日韩极品在线观看| 国产在线观看一区二区| 国产精品888| 色综合久久久久| 欧美日本在线视频| 欧美刺激脚交jootjob| 国产免费久久精品| 尤物视频一区二区| 青草国产精品久久久久久| 极品少妇一区二区| www.久久久久久久久| 日韩一级完整毛片| 欧美日韩成人综合在线一区二区| 色94色欧美sute亚洲13| 91丨九色丨蝌蚪丨老版| 91美女在线看| 91精品国产色综合久久不卡蜜臀| 一本到不卡免费一区二区| 国产精品888| 久久疯狂做爰流白浆xx| 亚洲视频资源在线| 久久九九国产精品| 丝袜美腿一区二区三区| 欧美专区日韩专区| 伊人夜夜躁av伊人久久| 色综合久久中文字幕综合网| 亚洲免费伊人电影| 欧美三级日韩在线| 日本视频中文字幕一区二区三区| 欧美一区二区福利视频| 精品一二线国产| 欧美国产97人人爽人人喊| av在线播放不卡| 午夜精品久久久久久久久久| 欧美一区二区免费视频| 国产又黄又大久久| 国产精品久久久久影院色老大| 91视视频在线观看入口直接观看www | 欧美日本一区二区三区| 裸体一区二区三区| 国产精品理伦片| 国产黑丝在线一区二区三区| 久久伊人中文字幕| 激情综合色综合久久| 国产香蕉久久精品综合网| 国产a久久麻豆| 成人欧美一区二区三区视频网页 | 亚洲同性同志一二三专区| 91麻豆6部合集magnet| 亚洲第一福利一区| 欧美一级淫片007| 国产一区二区在线观看免费| 久久久.com| 在线视频你懂得一区| 日本视频一区二区三区| 精品久久久久久久久久久久包黑料 | 欧洲av在线精品| 麻豆91免费观看| 国产精品国产馆在线真实露脸| 欧美最新大片在线看| 久久av老司机精品网站导航| 亚洲欧洲精品一区二区三区| 欧美另类变人与禽xxxxx| 国产馆精品极品| 午夜免费久久看| 中文字幕av一区二区三区| 欧美日韩国产综合草草| 风间由美性色一区二区三区| 亚洲精品一卡二卡| 国产亚洲福利社区一区| 欧美日韩一区在线观看| av成人动漫在线观看| 久久99精品久久久久婷婷| 亚洲高清久久久| 亚洲青青青在线视频| 国产精品国产自产拍高清av| 精品国产区一区|