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

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

?? rawnandflash.c

?? IAR5.2下 AT91SAM9260 ARM 對 MCP2515 控制源化碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
    unsigned short destPage)
{
    unsigned short numPages = NandFlashModel_GetBlockSizeInPages(MODEL(raw));
    unsigned int sourceRow = sourceBlock * numPages + sourcePage;
    unsigned int destRow = destBlock * numPages + destPage;
    unsigned char error = 0;

    ASSERT((sourcePage & 1) == (destPage & 1),
           "CopyPage: Source and destination page must have the same parity.\n\r");

    trace_LOG(DEBUG, "CopyPage(B#%d:P#%d -> B#%d:P#%d)\n\r",
              sourceBlock, sourcePage, destBlock, destPage);

    // Use the copy-back facility if available
    if (NandFlashModel_SupportsCopyBack(MODEL(raw))) {

        // Start operation
        ENABLE_CE(raw);

        // Start copy-back read
        WRITE_COMMAND(raw, COMMAND_COPYBACK_READ_1);
        WriteColumnAddress(raw, 0);
        WriteRowAddress(raw, sourceRow);
        WRITE_COMMAND(raw, COMMAND_COPYBACK_READ_2);
        WaitReady(raw);

        // Start copy-back write
        WRITE_COMMAND(raw, COMMAND_COPYBACK_PROGRAM_1);
        WriteColumnAddress(raw, 0);
        WriteRowAddress(raw, destRow);
        WRITE_COMMAND(raw, COMMAND_COPYBACK_PROGRAM_2);
        WaitReady(raw);

        // Check status
        if (!IsOperationComplete(raw)) {
            trace_LOG(trace_ERROR, "CopyPage: Failed to copy page.\n\r");
            error = NandCommon_ERROR_CANNOTCOPY;
        }

        // Finish operation
        DISABLE_CE(raw);
    }
    else {

        // Software copy
        unsigned char data[NandCommon_MAXPAGEDATASIZE];
        unsigned char spare[NandCommon_MAXPAGESPARESIZE];
        if (RawNandFlash_ReadPage(raw, sourceBlock, sourcePage, data, spare)) {

            trace_LOG(trace_ERROR, "CopyPage: Failed to read page to copy\n\r");
            error = NandCommon_ERROR_CANNOTREAD;
        }
        else if (RawNandFlash_WritePage(raw, destBlock, destPage, data, spare)) {

            trace_LOG(trace_ERROR, "CopyPage: Failed to write dest. page\n\r");
            error = NandCommon_ERROR_CANNOTWRITE;
        }
    }

    return error;
}

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

//------------------------------------------------------------------------------
/// Initializes a RawNandFlash instance based on the given model and physical
/// interface. If no model is provided, then the function tries to autodetect
/// it.
/// Returns 0 if initialization is successful; otherwise returns
/// NandCommon_ERROR_UNKNOWNMODEL.
/// \param raw  Pointer to a RawNandFlash 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 RawNandFlash_Initialize(
    struct RawNandFlash *raw,
    const struct NandFlashModel *model,
    unsigned int commandAddress,
    unsigned int addressAddress,
    unsigned int dataAddress,
    const Pin pinChipEnable,
    const Pin pinReadyBusy)
{
    trace_LOG(DEBUG, "RawNandFlash_Initialize()\r\n");

    // Initialize fields
    raw->commandAddress = commandAddress;
    raw->addressAddress = addressAddress;
    raw->dataAddress = dataAddress;
    raw->pinChipEnable = pinChipEnable;
    raw->pinReadyBusy = pinReadyBusy;

    // Reset
    RawNandFlash_Reset(raw);

    // If model is not provided, autodetect it
    if (!model) {

        trace_LOG(DEBUG, "No model provided, trying autodetection ...\n\r");
        if (NandFlashModel_Find(nandFlashModelList,
                                NandFlashModelList_SIZE,
                                RawNandFlash_ReadId(raw),
                                &(raw->model))) {

            trace_LOG(trace_ERROR,
                      "RawNandFlash_Initialize: Could not autodetect chip.\n\r");
            return NandCommon_ERROR_UNKNOWNMODEL;
        }
    }
    else {

        // Copy provided model
        raw->model = *model;
    }

    return 0;
}

//------------------------------------------------------------------------------
/// Resets a NandFlash device.
/// \param raw  Pointer to a RawNandFlash instance.
//------------------------------------------------------------------------------
void RawNandFlash_Reset(const struct RawNandFlash *raw)
{
    trace_LOG(DEBUG, "RawNandFlash_Reset()\n\r");

    ENABLE_CE(raw);
    WRITE_COMMAND(raw, COMMAND_RESET);
    WaitReady(raw);
    DISABLE_CE(raw);
}

//------------------------------------------------------------------------------
/// Reads and returns the identifiers of a NandFlash chip.
/// \param raw  Pointer to a RawNandFlash instance.
/// \return id1|(id2<<8)|(id3<<16)|(id4<<24)
//------------------------------------------------------------------------------
unsigned int RawNandFlash_ReadId(const struct RawNandFlash *raw)
{
    unsigned int chipId;

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

    ENABLE_CE(raw);
    WRITE_COMMAND(raw, COMMAND_READID);
    WRITE_ADDRESS(raw, 0);
    chipId  = READ_DATA8(raw);
    chipId |= READ_DATA8(raw) << 8;
    chipId |= READ_DATA8(raw) << 16;
    chipId |= READ_DATA8(raw) << 24;
    DISABLE_CE(raw);

    return chipId;
}

//------------------------------------------------------------------------------
/// Erases the specified block of the device, retrying several time if it fails.
/// Returns 0 if successful; otherwise returns NandCommon_ERROR_BADBLOCK.
/// \param raw  Pointer to a RawNandFlash instance.
/// \param block  Number of the physical block to erase.
//------------------------------------------------------------------------------
unsigned char RawNandFlash_EraseBlock(
    const struct RawNandFlash *raw,
    unsigned short block)
{
    unsigned char numTries = NUMERASETRIES;

    trace_LOG(DEBUG, "RawNandFlash_EraseBlock(B#%d)\n\r", block);

    while (numTries > 0) {

        if (!EraseBlock(raw, block)) {

            return 0;
        }
        numTries--;
    }

    trace_LOG(trace_ERROR, "RawNandFlash_EraseBlock: Failed to erase block after %d tries\n\r", NUMERASETRIES);
    return NandCommon_ERROR_BADBLOCK;
}

//------------------------------------------------------------------------------
/// Reads the data and/or the spare areas of a page of a NandFlash into the
/// provided buffers. If a buffer pointer is 0, the corresponding area is not
/// read.
/// Returns 0 if the operation has been successful; otherwise returns 1.
/// \param raw  Pointer to a RawNandFlash instance.
/// \param block  Number of the block where the page to read resides.
/// \param page  Number of the page to read inside the given block.
/// \param data  Buffer where the data area will be stored.
/// \param spare  Buffer where the spare area will be stored.
//------------------------------------------------------------------------------
unsigned char RawNandFlash_ReadPage(
    const struct RawNandFlash *raw,
    unsigned short block,
    unsigned short page,
    void *data,
    void *spare)
{
    unsigned char hasSmallBlocks = NandFlashModel_HasSmallBlocks(MODEL(raw));
    unsigned int pageDataSize = NandFlashModel_GetPageDataSize(MODEL(raw));
    unsigned int pageSpareSize = NandFlashModel_GetPageSpareSize(MODEL(raw));
    unsigned int rowAddress;

    ASSERT(data || spare, "RawNandFlash_ReadPage: At least one area must be read\n\r");
    trace_LOG(DEBUG, "RawNandFlash_ReadPage(B#%d:P#%d)\r\n", block, page);

    // Calculate actual address of the page
    rowAddress = block * NandFlashModel_GetBlockSizeInPages(MODEL(raw)) + page;

    // Start operation
    ENABLE_CE(raw);

    // Use either small blocks or large blocks data area read
    if (hasSmallBlocks) {

        WRITE_COMMAND(raw, COMMAND_READ_A);
        WriteColumnAddress(raw, 0);
        WriteRowAddress(raw, rowAddress);
    }
    else {
    
        WRITE_COMMAND(raw, COMMAND_READ_1);
        WriteColumnAddress(raw, 0);
        WriteRowAddress(raw, rowAddress);
        WRITE_COMMAND(raw, COMMAND_READ_2);
    }

    // Wait for the nand to be ready
    WaitReady(raw);

    // Read data area if needed
    if (data) {
        WRITE_COMMAND(raw, COMMAND_READ_1);
        ReadData(raw, (unsigned char *) data, pageDataSize);
    }

    // Use either small/large blocks spare area read
    if (hasSmallBlocks) {

        WRITE_COMMAND(raw, COMMAND_READ_C);
        WriteColumnAddress(raw, 0);
        WriteRowAddress(raw, rowAddress);
        WaitReady(raw);
    }
    else {

        WRITE_COMMAND(raw, COMMAND_RANDOM_OUT);
        WriteColumnAddress(raw, pageDataSize);
        WRITE_COMMAND(raw, COMMAND_RANDOM_OUT_2);
    }
    WaitReady(raw);

    // Read spare area if needed
    if (spare) {
        WRITE_COMMAND(raw, COMMAND_READ_1);
        ReadData(raw, (unsigned char *) spare, pageSpareSize);
    }

    // Disable CE
    DISABLE_CE(raw);

    return 0;
}

//------------------------------------------------------------------------------
/// Writes the data and/or the spare area of a page on a NandFlash chip. If one
/// of the buffer pointer is 0, the corresponding area is not written. Retries
/// several time if there is an error.
/// Returns 0 if the write operation is successful; otherwise returns
/// NandCommon_ERROR_BADBLOCK.
/// \param raw  Pointer to a RawNandFlash instance.
/// \param block  Number of the block where the page to write resides.
/// \param page  Number of the page to write inside the given block.
/// \param data  Buffer containing the data area.
/// \param spare  Buffer containing the spare area.
//------------------------------------------------------------------------------
unsigned char RawNandFlash_WritePage(
    const struct RawNandFlash *raw,
    unsigned short block,
    unsigned short page,
    void *data,
    void *spare)
{
    unsigned char numTries = NUMWRITETRIES;

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

    while (numTries > 0) {

        if (!WritePage(raw, block, page, data, spare)) {

            return 0;
        }
        numTries--;
    }

    trace_LOG(trace_ERROR, "RawNandFlash_WritePage: Failed to write page after %d tries\n\r", NUMWRITETRIES);
    return NandCommon_ERROR_BADBLOCK;
}

//------------------------------------------------------------------------------
/// Copy the data in a page of the NandFlash device to an other page on that
/// same chip. Both pages must have be even or odd; it is not possible to copy
/// and even page to an odd page and vice-versa. Several retries are attempted
/// if errors are encountered.
/// Returns 0 if the operation is successful; otherwise returns
/// NandCommon_ERROR_BADBLOCK indicating that the destination block is bad.
/// \param raw  Pointer to a RawNandFlash instance.
/// \param sourceBlock  Source block number.
/// \param sourcePage  Source page number inside the source block.
/// \param destBlock  Destination block number.
/// \param destPage  Destination page number inside the destination block.
//------------------------------------------------------------------------------
unsigned char RawNandFlash_CopyPage(
    const struct RawNandFlash *raw,
    unsigned short sourceBlock,
    unsigned short sourcePage,
    unsigned short destBlock,
    unsigned short destPage)
{
    unsigned char numTries = NUMCOPYTRIES;

    trace_LOG(DEBUG, "RawNandFlash_CopyPage(B#%d:P#%d -> B#%d:P#%d)\n\r",
              sourceBlock, sourcePage, destBlock, destPage);

    while (numTries) {

        if (!CopyPage(raw, sourceBlock, sourcePage, destBlock, destPage)) {

            return 0;
        }
        numTries--;
    }

    trace_LOG(trace_ERROR, "RawNandFlash_CopyPage: Failed to copy page after %d tries\n\r", NUMCOPYTRIES);
    return NandCommon_ERROR_BADBLOCK;
}

//------------------------------------------------------------------------------
/// Copies the data of one whole block of a NandFlash device to another block.
/// Returns 0 if successful; otherwise returns NandCommon_ERROR_BADBLOCK.
/// \param raw  Pointer to a RawNandFlash instance.
/// \param sourceBlock  Source block number.
/// \param destBlock  Destination block number.
//------------------------------------------------------------------------------
unsigned char RawNandFlash_CopyBlock(
    const struct RawNandFlash *raw,
    unsigned short sourceBlock,
    unsigned short destBlock)
{
    unsigned short numPages = NandFlashModel_GetBlockSizeInPages(MODEL(raw));
    unsigned int i;

    ASSERT(sourceBlock != destBlock,
           "RawNandFlash_CopyBlock: Source block must be different from dest block\n\r");
    trace_LOG(DEBUG, "RawNandFlash_CopyBlock(B#%d->B#%d)\n\r",
              sourceBlock, destBlock);

    // Copy all pages
    for (i=0; i < numPages; i++) {

        if (RawNandFlash_CopyPage(raw, sourceBlock, i, destBlock, i)) {

            trace_LOG(trace_ERROR,
                      "RawNandFlash_CopyBlock: Failed to copy page %u\n\r",
                      i);
            return NandCommon_ERROR_BADBLOCK;
        }
    }

    return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区精品久久| bt欧美亚洲午夜电影天堂| 精品国产123| 国产综合一区二区| 国产精品美女久久久久久久久久久| 成人涩涩免费视频| 亚洲视频每日更新| 欧美日韩精品欧美日韩精品一 | 国产一区二区女| 日本一区二区三区免费乱视频| 不卡高清视频专区| 亚洲狠狠爱一区二区三区| 91精品国产综合久久小美女| 狠狠色狠狠色合久久伊人| 国产人成亚洲第一网站在线播放| av电影在线观看完整版一区二区| 亚洲免费观看高清在线观看| 欧美日韩精品福利| 久久电影网电视剧免费观看| 中文无字幕一区二区三区| 一本到不卡免费一区二区| 亚洲超丰满肉感bbw| 亚洲精品在线电影| 91在线码无精品| 日韩高清一级片| 国产午夜精品福利| 欧美性做爰猛烈叫床潮| 久久99久久久久| 国产精品夫妻自拍| 欧美酷刑日本凌虐凌虐| 国产在线不卡视频| 一区二区三区视频在线观看| 日韩你懂的在线观看| av在线不卡网| 日本视频一区二区三区| 亚洲国产电影在线观看| 欧美美女喷水视频| 国产999精品久久久久久绿帽| 亚洲自拍偷拍网站| 久久亚洲免费视频| 欧美日韩在线三级| 国产福利一区二区三区视频| 亚洲主播在线播放| 久久久久99精品一区| 在线免费不卡视频| 国产精品一区二区免费不卡| 亚洲一区免费视频| 国产日本欧美一区二区| 在线播放中文一区| a级精品国产片在线观看| 蜜臀av性久久久久蜜臀aⅴ| 最好看的中文字幕久久| 欧美一区2区视频在线观看| 99久久免费精品高清特色大片| 免费观看在线色综合| 亚洲免费高清视频在线| 久久综合色8888| 欧美日韩一区高清| eeuss鲁片一区二区三区在线看| 日本不卡高清视频| 夜夜亚洲天天久久| 国产精品日韩精品欧美在线| 日韩你懂的在线播放| 欧美日韩一级二级三级| 91女神在线视频| 国产剧情av麻豆香蕉精品| 丝袜亚洲另类欧美| 亚洲美女区一区| 国产欧美1区2区3区| 日韩欧美激情一区| 精品视频一区二区不卡| 99国产精品国产精品久久| 久久91精品国产91久久小草| 国产精品久久久久影院色老大| 欧美一级片在线| 欧洲一区二区三区免费视频| 国产精品影视在线| 日韩国产一区二| 亚洲一区二区三区小说| 国产日韩欧美a| 欧美一级免费观看| 色狠狠色狠狠综合| 国产成人av资源| 蜜桃精品视频在线| 亚洲综合色噜噜狠狠| 国产精品久久久99| 久久夜色精品国产欧美乱极品| 欧美日本视频在线| 成人h版在线观看| 丰满白嫩尤物一区二区| 久久国产精品一区二区| 天天操天天综合网| 一区二区三区久久久| 色综合中文字幕| 成人h精品动漫一区二区三区| 国产精品一区二区不卡| 国产又黄又大久久| 日韩成人午夜精品| 亚洲综合另类小说| 色综合久久久久综合体桃花网| 日韩va欧美va亚洲va久久| 一区二区三区日本| 一区二区中文字幕在线| 日本精品一级二级| 久久久久久黄色| 成人18视频在线播放| 亚洲天堂网中文字| 色婷婷国产精品久久包臀 | 成人av午夜电影| 亚洲桃色在线一区| av一区二区三区黑人| 亚洲福利视频一区二区| 欧美在线影院一区二区| 日韩高清不卡在线| 久久品道一品道久久精品| 豆国产96在线|亚洲| 中文字幕精品综合| 91在线精品一区二区| 亚洲美女精品一区| 日韩丝袜美女视频| 国产成人av电影在线观看| 国产精品夫妻自拍| 在线不卡免费欧美| 国产精品亚洲一区二区三区在线 | 精品一区二区久久久| 久久久久高清精品| 成人国产精品免费| 青青青伊人色综合久久| 亚洲欧洲另类国产综合| 成人性视频网站| 一区二区三区中文字幕精品精品| 欧美精品乱人伦久久久久久| 国产精品一二三| 一区二区三区在线视频免费观看| 欧美一区二区大片| 波多野结衣亚洲一区| 亚洲国产wwwccc36天堂| 久久在线免费观看| 日本电影欧美片| 五月天亚洲婷婷| 中文字幕在线观看不卡| 欧美一区二区日韩| 成人av在线网站| 美日韩一区二区| 亚洲欧洲精品成人久久奇米网| 欧美午夜在线一二页| 不卡在线观看av| 美日韩黄色大片| 亚洲私人黄色宅男| 欧美xxxxxxxx| 欧美在线观看18| 国产成人鲁色资源国产91色综| 亚洲精品日韩一| 久久综合九色综合97_久久久| 欧美亚洲丝袜传媒另类| 国产一区二区不卡老阿姨| 成人免费在线视频| 精品久久久久久无| 欧美日韩卡一卡二| jizzjizzjizz欧美| 国内欧美视频一区二区| 国产精品美女久久久久aⅴ| 精品免费视频一区二区| 欧美在线一区二区三区| 成人国产精品免费观看视频| 久久99久久精品欧美| 五月天中文字幕一区二区| 自拍偷在线精品自拍偷无码专区| 国产欧美日韩精品一区| 欧美一区二区三区小说| 91成人免费在线视频| 国产一区二区调教| 日韩和欧美一区二区三区| 一区二区三区四区av| 亚洲欧洲精品一区二区三区不卡| 久久久久久久久久久99999| 69久久夜色精品国产69蝌蚪网| 91丝袜国产在线播放| 国产盗摄一区二区三区| 久久精品国产99国产| 午夜精品久久久久久久久久| 亚洲乱码中文字幕| 国产偷国产偷精品高清尤物 | 国产高清视频一区| 美女性感视频久久| 亚洲18女电影在线观看| 一区二区三区视频在线观看| 亚洲欧美激情一区二区| 国产喂奶挤奶一区二区三区| 欧美草草影院在线视频| 91麻豆精品国产91久久久久久久久| 91国偷自产一区二区开放时间| av在线这里只有精品| av在线综合网| 99久久er热在这里只有精品15| 国产91精品精华液一区二区三区| 国产精品123区| 91在线观看视频| 91年精品国产| 色菇凉天天综合网|