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

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

?? translatednandflash.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 "TranslatedNandFlash.h"
#include <utility/trace.h>
#include <utility/assert.h>
#include <utility/math.h>

#include <string.h>

//------------------------------------------------------------------------------
//         Internal definitions
//------------------------------------------------------------------------------

/// Custom trace levels for the current file.
#define DEBUG                       trace_DEBUG
#define INFO                        trace_INFO
#define IMPORTANT                   trace_FATAL

/// Casts
#define MAPPED(translated)          ((struct MappedNandFlash *) translated)
#define MANAGED(translated)         ((struct ManagedNandFlash *) translated)
#define ECC(translated)             ((struct EccNandFlash *) translated)
#define RAW(translated)             ((struct RawNandFlash *) translated)
#define MODEL(translated)           ((struct NandFlashModel *) translated)

/// Minimum number of blocks that should be kept unallocated
#define MINNUMUNALLOCATEDBLOCKS     32

/// Maximum allowed erase count difference
#define MAXERASEDIFFERENCE          5

//------------------------------------------------------------------------------
//         Internal functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Returns 1 if there are enough free blocks to perform a single block
/// allocation; otherwise returns 0.
/// \param translated  Pointer to a TranslatedNandFlash instance.
//------------------------------------------------------------------------------
static unsigned char BlockCanBeAllocated(
    const struct TranslatedNandFlash *translated)
{
    unsigned short count;

    // Count number of free and dirty blocks (unallocated blocks)
    count = ManagedNandFlash_CountBlocks(MANAGED(translated), NandBlockStatus_DIRTY)
            + ManagedNandFlash_CountBlocks(MANAGED(translated), NandBlockStatus_FREE);

    // Check that count is greater than minimum number of unallocated blocks
    if (count > MINNUMUNALLOCATEDBLOCKS) {

        return 1;
    }
    else {

        return 0;
    }
}

//------------------------------------------------------------------------------
/// Returns 1 if the given page inside the currently written block is clean (has
/// not been written yet); otherwise returns 0.
/// \param translated  Pointer to a TranslatedNandFlash instance.
/// \param page  Page number.
//------------------------------------------------------------------------------
static unsigned char PageIsClean(
    const struct TranslatedNandFlash *translated,
    unsigned short page)
{
    ASSERT(page < NandFlashModel_GetBlockSizeInPages(MODEL(translated)),
           "PageIsClean: Page out-of-bounds\n\r");

    return ((translated->currentBlockPageStatuses[page / 8] >> (page % 8)) & 1) == 0;
}

//------------------------------------------------------------------------------
/// Marks the given page as being dirty (i.e. written).
/// \param translated  Pointer to a TranslatedNandFlash instance.
/// \param page  Page number.
//------------------------------------------------------------------------------
static void MarkPageDirty(
    struct TranslatedNandFlash *translated,
    unsigned short page)
{
    ASSERT(page < NandFlashModel_GetBlockSizeInPages(MODEL(translated)),
           "PageIsClean: Page out-of-bounds\n\r");

    translated->currentBlockPageStatuses[page / 8] |= 1 << (page % 8);
}

//------------------------------------------------------------------------------
/// Marks all pages as being clean.
/// \param translated  Pointer to a TranslatedNandFlash instance.
//------------------------------------------------------------------------------
static void MarkAllPagesClean(struct TranslatedNandFlash *translated)
{
    memset(translated->currentBlockPageStatuses, 0,
           sizeof(translated->currentBlockPageStatuses));
}

//------------------------------------------------------------------------------
/// Allocates the best-fitting physical block for the given logical block.
/// Returns 0 if successful; otherwise returns NandCommon_ERROR_NOBLOCKFOUND if
/// there are no more free blocks, or a NandCommon_ERROR code.
/// \param translated  Pointer to a TranslatedNandFlash instance.
/// \param block  Logical block number.
//------------------------------------------------------------------------------
static unsigned char AllocateBlock(
    struct TranslatedNandFlash *translated,
    unsigned short block)
{
    unsigned short freeBlock, liveBlock;
    unsigned char error;
    signed int eraseDifference;

    trace_LOG(DEBUG, "Allocating a new block\n\r");

    // Find youngest free block and youngest live block
    if (ManagedNandFlash_FindYoungestBlock(MANAGED(translated),
                                           NandBlockStatus_FREE,
                                           &freeBlock)) {

        trace_LOG(trace_ERROR, "AllocateBlock: Could not find a free block\n\r");
        return NandCommon_ERROR_NOBLOCKFOUND;
    }

    // If this is the last free block, save the logical mapping in it and
    // clean dirty blocks
    trace_LOG(DEBUG, "Number of FREE blocks: %d\n\r",
              ManagedNandFlash_CountBlocks(MANAGED(translated), NandBlockStatus_FREE));
    if (ManagedNandFlash_CountBlocks(MANAGED(translated),
                                     NandBlockStatus_FREE) == 1) {

        // Save mapping and clean dirty blocks
        trace_LOG(DEBUG, "Last FREE block, cleaning up ...\n\r");

        error = MappedNandFlash_SaveLogicalMapping(MAPPED(translated), freeBlock);
        if (error) {

            trace_LOG(trace_ERROR, "AllocateBlock: Failed to save mapping\n\r");
            return error;
        }
        error = ManagedNandFlash_EraseDirtyBlocks(MANAGED(translated));
        if (error) {

            trace_LOG(trace_ERROR, "AllocatedBlock: Failed to erase dirty blocks\n\r");
            return error;
        }

        // Allocate new block
        return AllocateBlock(translated, block);
    }

    // Find youngest LIVE block to check the erase count difference
    if (!ManagedNandFlash_FindYoungestBlock(MANAGED(translated),
                                            NandBlockStatus_LIVE,
                                            &liveBlock)) {

        // Calculate erase count difference
        trace_LOG(DEBUG, "Free block erase count = %d\n\r", MANAGED(translated)->blockStatuses[freeBlock].eraseCount);
        trace_LOG(DEBUG, "Live block erase count = %d\n\r", MANAGED(translated)->blockStatuses[liveBlock].eraseCount);
        eraseDifference = abs(MANAGED(translated)->blockStatuses[freeBlock].eraseCount
                              - MANAGED(translated)->blockStatuses[liveBlock].eraseCount);

        // Check if it is too big
        if (eraseDifference > MAXERASEDIFFERENCE) {

            trace_LOG(IMPORTANT, "Erase difference too big, switching blocks\n\r");
            MappedNandFlash_Map(
                MAPPED(translated),
                MappedNandFlash_PhysicalToLogical(
                    MAPPED(translated),
                    liveBlock),
                freeBlock);
            ManagedNandFlash_CopyBlock(MANAGED(translated),
                                       liveBlock,
                                       freeBlock);

            // Allocate a new block
            return AllocateBlock(translated, block);
        }
    }

    // Map block
    trace_LOG(DEBUG, "Allocating PB#%d for LB#%d\n\r", freeBlock, block);
    MappedNandFlash_Map(MAPPED(translated), block, freeBlock);

    return 0;
}

//------------------------------------------------------------------------------
//         Exported functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Initializes a TranslatedNandFlash instance.
/// Returns 0 if successful; otherwise returns a NandCommon_ERROR_xxx code.
/// \param translated  Pointer to a TranslatedNandFlash 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 TranslatedNandFlash_Initialize(
    struct TranslatedNandFlash *translated,
    const struct NandFlashModel *model,
    unsigned int commandAddress,
    unsigned int addressAddress,
    unsigned int dataAddress,
    const Pin pinChipEnable,
    const Pin pinReadyBusy)
{
    translated->currentLogicalBlock = -1;
    translated->previousPhysicalBlock = -1;
    MarkAllPagesClean(translated);

    // Initialize MappedNandFlash
    return MappedNandFlash_Initialize(MAPPED(translated),
                                      model,
                                      commandAddress,
                                      addressAddress,
                                      dataAddress,
                                      pinChipEnable,
                                      pinReadyBusy);
}

//------------------------------------------------------------------------------
/// Reads the data and/or the spare area of a page on a translated nandflash.
/// If the block is not currently mapped but could be (i.e. there are available
/// physical blocks), then the data/spare is filled with 0xFF.
/// Returns 0 if successful; otherwise returns NandCommon_ERROR_NOMOREBLOCKS
/// if no more block can be allocated, or a NandCommon_ERROR code.
/// \param translated  Pointer to a TranslatedNandFlash instance.
/// \param block  Logical block number.
/// \param page  Number of page to read inside logical block.
/// \param data  Data area buffer, can be 0.
/// \param spare  Spare area buffer, can be 0.
//------------------------------------------------------------------------------
unsigned char TranslatedNandFlash_ReadPage(
    const struct TranslatedNandFlash *translated,
    unsigned short block,
    unsigned short page,
    void *data,
    void *spare)
{
    unsigned char error;

    trace_LOG(INFO, "TranslatedNandFlash_ReadPage(B#%d:P#%d)\n\r", block, page);

    // If the page to read is in the current block, there is a previous physical
    // block and the page is clean -> read the page in the old block since the
    // new one does not contain meaningful data

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品久久影院| 国产麻豆一精品一av一免费| 老色鬼精品视频在线观看播放| 国产成人免费在线观看| 欧美日韩久久久一区| 国产精品嫩草影院com| 日本aⅴ亚洲精品中文乱码| 91网页版在线| 中文字幕av一区二区三区| 美女精品一区二区| 91传媒视频在线播放| 国产精品不卡一区| 国产精品中文欧美| 精品国产一区二区精华| 天天综合色天天| 欧美性受xxxx| 亚洲欧美国产三级| 99久久婷婷国产精品综合| 久久精品一级爱片| 久草这里只有精品视频| 91精品啪在线观看国产60岁| 亚洲午夜久久久久久久久电影网 | 欧美亚一区二区| 中文字幕一区二区三区在线观看| 狠狠狠色丁香婷婷综合激情| 中文字幕成人网| 久久99久久精品欧美| 91精品一区二区三区在线观看| 亚洲国产精品综合小说图片区| 91美女片黄在线观看91美女| 国产精品麻豆99久久久久久| 高清成人免费视频| 国产精品麻豆一区二区| 99久久精品免费精品国产| 国产精品免费看片| 成人动漫精品一区二区| 中文字幕制服丝袜一区二区三区 | 蜜臀久久久99精品久久久久久| 欧美日韩中文字幕一区二区| 亚洲电影第三页| 欧美精品成人一区二区三区四区| 亚洲va韩国va欧美va精品| 欧美高清性hdvideosex| 日本午夜精品视频在线观看| 精品国产免费视频| 国产91丝袜在线18| 亚洲精品国产一区二区三区四区在线| 色婷婷国产精品综合在线观看| 亚洲一区免费观看| 日韩欧美第一区| 国产激情精品久久久第一区二区| 国产精品毛片无遮挡高清| 一本一本大道香蕉久在线精品| 亚洲一二三级电影| 精品福利二区三区| 99国产精品视频免费观看| 亚洲一区二区欧美日韩| 欧美一区二区三区在线| 国产成人免费视频一区| 亚洲精品免费在线| 欧美一级片免费看| 在线不卡a资源高清| 国产综合色产在线精品| 亚洲欧美视频在线观看视频| 91精品国产综合久久福利软件| 国产精品自拍在线| 一个色综合网站| 欧美mv日韩mv| 91搞黄在线观看| 狠狠色丁香久久婷婷综合_中| 亚洲欧洲99久久| 日韩一区二区三区av| 99精品桃花视频在线观看| 日本强好片久久久久久aaa| 国产精品久久久久久久久搜平片| 欧美精品v国产精品v日韩精品| 成人免费黄色大片| 蜜臀99久久精品久久久久久软件| 成人免费视频在线观看| 日韩免费视频一区二区| 91官网在线免费观看| 国产精品1区二区.| 奇米色一区二区| 亚洲精品国产视频| 久久久久久久久久久久久久久99 | 亚洲一区二区三区激情| 国产色综合久久| 日韩一区二区三区观看| 欧美午夜精品久久久久久孕妇| 国产麻豆9l精品三级站| 日韩精品久久理论片| 亚洲免费av在线| 国产精品欧美极品| 久久一区二区三区国产精品| 欧美美女一区二区在线观看| 91亚洲精品久久久蜜桃| 国产成人精品三级| 91福利视频久久久久| 国产精品123区| 国产在线观看免费一区| 麻豆精品新av中文字幕| 亚洲成人一区二区| 亚洲视频图片小说| 国产精品电影一区二区| 国产欧美精品一区| 久久精品人人做人人爽人人| 欧美一卡在线观看| 欧美一级片在线看| 欧美一区二区三区四区久久| 欧美日韩一区 二区 三区 久久精品 | 风间由美中文字幕在线看视频国产欧美| 日韩黄色免费电影| 视频一区视频二区中文| 亚洲一二三四区| 亚洲成人在线免费| 午夜伊人狠狠久久| 亚洲va韩国va欧美va精品| 午夜视频一区在线观看| 香蕉久久一区二区不卡无毒影院| 亚洲丶国产丶欧美一区二区三区| 亚洲国产成人高清精品| 偷拍一区二区三区四区| 天堂蜜桃91精品| 美女久久久精品| 国产麻豆精品久久一二三| 国产a级毛片一区| 不卡一二三区首页| 色视频一区二区| 欧美日本在线视频| 日韩欧美一二三四区| 久久久久久亚洲综合影院红桃| 国产亚洲女人久久久久毛片| 国产精品视频yy9299一区| 亚洲精品自拍动漫在线| 日韩中文字幕1| 国产激情视频一区二区在线观看| 成人免费视频一区| 欧美在线一二三四区| 9191精品国产综合久久久久久| 日韩无一区二区| 国产精品久久久久久久久久免费看| 亚洲欧洲综合另类| 日韩精品成人一区二区三区| 狠狠狠色丁香婷婷综合久久五月| voyeur盗摄精品| 欧美视频精品在线观看| 精品sm在线观看| 一区二区不卡在线播放| 日本韩国一区二区三区| 欧美一级欧美三级在线观看 | 国产aⅴ综合色| 欧美亚洲综合另类| 久久久国产精品午夜一区ai换脸| 亚洲欧洲无码一区二区三区| 免费高清成人在线| 9色porny自拍视频一区二区| 欧美一区二区视频在线观看2022| 国产日韩欧美制服另类| 日韩综合小视频| 99麻豆久久久国产精品免费优播| 欧美一区二区视频免费观看| 中文字幕中文字幕一区| 国模套图日韩精品一区二区 | 国产成人精品亚洲日本在线桃色| 欧美中文一区二区三区| 久久综合色一综合色88| 亚洲国产视频在线| 国产91精品欧美| 日韩欧美成人一区二区| 亚洲激情自拍视频| 国产精品一二三四五| 91精品久久久久久久久99蜜臂| 国产精品第四页| 国产成人高清在线| 欧美电影免费观看高清完整版在 | 久久精品一区二区| 性感美女久久精品| 91亚洲精品一区二区乱码| 精品国免费一区二区三区| 午夜久久福利影院| 在线看日韩精品电影| 欧美激情一区二区三区全黄| 久久国产免费看| 欧美日韩国产一区二区三区地区| 亚洲人午夜精品天堂一二香蕉| 国产福利91精品一区二区三区| 欧美一级精品大片| 视频在线观看一区二区三区| 在线观看日韩av先锋影音电影院| 最新国产成人在线观看| 高清beeg欧美| 国产女主播一区| 国产盗摄精品一区二区三区在线 | 亚洲精品成人少妇| 9i在线看片成人免费| 国产精品久久久久久久久图文区 | 中文字幕亚洲电影| proumb性欧美在线观看| 亚洲欧美在线视频观看| 91麻豆自制传媒国产之光|