⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flsim.c

📁 DOC文件系统驱动源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
                        checkStatus( sim_chk_overwrite(p2, sim_dummy_edc, conf->ecc_size) );                        memcpy (p2, sim_dummy_edc, conf->ecc_size);                     }                                /* write 2-byte sector flags */                    checkStatus( sim_chk_overwrite(p2 + conf->ecc_size,                                        sectorFlags, sizeof(sectorFlags)) );                    memcpy (p2 + conf->ecc_size, sectorFlags, sizeof(sectorFlags));                }                sector_boundary += SECTOR_SIZE;                p2              += extra_per_sector;            }            /* update MTD statistics */            simDoc->stats.pages_written ++;            simDoc->stats.bytes_written += bytes;            /* move on to next page */            offset  = 0;            len    -= bytes;            buf     = (char FAR1 *)buf + bytes;            p      += (conf->page_size + conf->page_extra_size);        }    }    return  flOK;}/* -------------------------------------------------------------------------- *  *                                                                            * *                         s i m _ e r a s e                                  * *                                                                            * * This is MTD standard "erase" routine.                                      * *                                                                            * * Parameters:                                                                * *                                                                            * *      vol      : pointer identifying drive                                  * *      block    : First block to erase.                                      * *      blocks   : Number of blocks to erase.                                 * *                                                                            * * Returns:                                                                   * *                                                                            * *      flOK on success, otherwise respective error code                      * *                                                                            * * -------------------------------------------------------------------------- */static FLStatus  sim_erase ( FLFlash  vol,                             word     block,                             word     blocks ){    FLSim_t     * simDoc;    FLSimConf_t * conf;    long          start_page;    long          pages;    char        * p;    int           i;    if( flWriteProtected(vol.socket) )        return flWriteProtect;    /* simDoc configuration */    simDoc = (FLSim_t *) vol.mtdVars;    conf = &simDoc->conf;    /* arguement sanity check */    if( ((block + blocks) * conf->block_size) > (conf->chips * conf->chip_size) ) {        DEBUG_PRINT(("FLSim: out-of-bound erase.\n"));        return flBadParameter;      }    /* erase respective pages and extra areas */    start_page = block  * (conf->block_size / conf->page_size);    pages      = blocks * (conf->block_size / conf->page_size);    p = simDoc->flash + (int)(start_page * (conf->page_size + conf->page_extra_size));    memset( p, -1, (size_t)(pages * (conf->page_size + conf->page_extra_size)) );    /* clear pages' PPP counters */    for (i = 0; i < pages; i++)        sim_clear_ppp (simDoc, start_page + i);    /* update MTD statistics */    simDoc->stats.blocks_erased++;    return  flOK;}/* -------------------------------------------------------------------------- *  *                                                                            * *                          s i m _ m a p                                     * *                                                                            * * This is standard MTD "map" routine.                                        * *                                                                            * * Parameters:                                                                * *                                                                            * *      vol       : pointer identifying drive                                 * *      addr      : flash address to be mapped                                * *      len       : number of bytes to map                                    * *                                                                            * * Returns:                                                                   * *                                                                            * *      Pointer to the buffer data was mapped to.                             * *                                                                            * * -------------------------------------------------------------------------- */static void FAR0 * sim_map ( FLFlash      vol,                              CardAddress  addr,                              int          len ){    FLSim_t   * simDoc;    FLStatus    status;    vol.socket->remapped = TRUE;    /* use simDoc's 'read' routine */    simDoc = (FLSim_t *) vol.mtdVars;    status = sim_read (&vol, addr, (void FAR1 *)simDoc->map_buffer, len, 0);    if (status != flOK) {        DEBUG_PRINT(("FLSim: attempt to map non-existing page(s).\n"));        return NULL;    }    return  ((void FAR0 *) simDoc->map_buffer);}/* -------------------------------------------------------------------------- *  *                                                                            *  *                         s i m _ r e a d _ B B T                            *  *                                                                            *  * Read fragment or entire Bad Block Table (BBT).                             *  *                                                                            *  * Parameters:                                                                *  *                                                                            *  *      vol         : pointer identifying drive                               * *      unit        : starting TL unit                                        * *      units       : total TL units                                          * *      multiplier  : simDoc blocks per one TL unit (or zero)                 * *      buf         : buffer to read BBT to                                   * *      reconstruct : ignored                                                 * *                                                                            *  * Returns:                                                                   *  *                                                                            *  *      error code if arguements are bad, otherwise flOK                      *  *                                                                            *  * -------------------------------------------------------------------------- */static FLStatus  sim_read_BBT ( FLFlash     vol,                                 dword       unit,                                 dword       units,                                byte        multiplier,                                byte FAR1 * buf,                                FLBoolean   reconstruct ){    FLSim_t * simDoc;    if (multiplier > 1) {        unit  *= multiplier;        units *= multiplier;            }    /* check arguements for sanity */    simDoc = (FLSim_t *) vol.mtdVars;    if( ((unit + units) * simDoc->conf.block_size) >                    (simDoc->conf.chips * simDoc->conf.chip_size) ) {        DEBUG_PRINT(("FLSim: out-of-bound BBT read.\n"));        return flBadParameter;      }    tffscpy (buf, simDoc->bbt + (int)unit, (int)units);    return flOK;}/* -------------------------------------------------------------------------- * *                                                                            * * Dummy routines required by FLSocket structure.                             * *                                                                            * * -------------------------------------------------------------------------- */      static FLBoolean  sim_always_true  ( FLSocket  vol )  { return  TRUE;  }      static FLBoolean  sim_always_false ( FLSocket  vol )  { return  FALSE; }static FLStatus   sim_always_ok    ( FLSocket  vol )  { return  flOK;  }static void       sim_do_nothing   ( FLSocket  vol )  { }static void       sim_no_mapping   ( FLSocket  vol, unsigned  page)  { }/* -------------------------------------------------------------------------- *  *                                                                            *  *                          s i m _ a l l o c                                 *  *                                                                            *  * Return the host base address of the "socket" window.                       *  *                                                                            *  * Parameters:                                                                *  *                                                                            *  *      simDoc  : simulated DiskOnChip                                        *  *                                                                            *  * Returns:                                                                   *  *                                                                            *  *      flOK if success otherwise respective error code                       *  *                                                                            *  * -------------------------------------------------------------------------- */static FLStatus sim_alloc ( FLSim_t * simDoc ){    FLSimConf_t * conf;    size_t        bytes_needed;              long          blocks;    long          pages;    long          tmp;    /* flash configuration */    conf = &simDoc->conf;    /* determine how much memory we will need */    bytes_needed = flsimMemNeeded( (FLSimConf_t FAR1 *)conf );    if (bytes_needed == 0)        return flBadParameter;    /* make sure we have enough memory for simDoc */    if (conf->mem_addr == NULL) {#ifdef FL_MALLOC        /* dynamic memory allocation requested */        conf->mem_addr = FL_MALLOC (bytes_needed);        if (conf->mem_addr == NULL)#endif            return flNotEnoughMemory;    }    else {        /* user provides memory to contain simDoc; check if it's large enough */          if (conf->mem_size < bytes_needed)            return flNotEnoughMemory;    }    /* align simDoc's memory at 4KByte boundary as required by flsocket.c */    tmp = pointerToPhysical (conf->mem_addr);    if( tmp & (FL_SIM_4KB_ALIGNMENT - 1) ) {           tmp = ((tmp / FL_SIM_4KB_ALIGNMENT) + 1) * FL_SIM_4KB_ALIGNMENT;        conf->mem_addr = physicalToPointer (tmp, needed /* ignored */, 0 /* ignored */);    }    /* total blocks and pages on this simDoc */    blocks = (conf->chips * conf->chip_size) / conf->block_size;    pages  = (conf->chips * conf->chip_size) / conf->page_size;    /* assign memory to simDoc's pages */    simDoc->flash = (char *) conf->mem_addr;    /* assign memory to simDoc's BBT (1 byte per block) */    simDoc->bbt = ((char *) simDoc->flash) +                           (int)(pages * (conf->page_size + conf->page_extra_size));    /* assign memory to pages' PPP counters (4 bits per page) */    simDoc->ppp_count = ((char *) simDoc->bbt) + (int)blocks;    /* assuming simDoc is "virgin", erase all pages and clear all PPP counters */    DEBUG_PRINT(("FLSim: assuming unformatted flash.\n"));    memset( simDoc->flash, -1, pages * (conf->page_size + conf->page_extra_size) );    memset( simDoc->ppp_count, 0, (pages / 2) + 1 );    /* assuming all simDoc's blocks are good */    memset( simDoc->bbt, -1, blocks );    return  flOK;}/* -------------------------------------------------------------------------- *  *                                                                            *  *                        s i m _ c l e a r _ p p p                           *  *                                                                            *  * Clear page's Partial Page Programming (PPP) counter.                       *  *                                                                            *  * Parameters:                                                                *  *                                                                            *  *      simDoc  : simulated DiskOnChip                                        *  *                                                                            *  *      page    : page #                                                      * *                                                                            *  * -------------------------------------------------------------------------- */static void  sim_clear_ppp ( FLSim_t * simDoc,                              long      page ){    char  ppp;    ppp = simDoc->ppp_count[(int)page / 2];    if (page & 1)  /* odd page; PPP count is in FLSim_t.ppp_count[], bits 7..4 */        ppp &= (char)0x0F;    else           /* even page; PPP count is in FLSim_t.ppp_count[], bits 3..0 */        ppp &= (char)0xF0;    simDoc->ppp_count[(int)page / 2] = ppp;}/* -------------------------------------------------------------------------- *  *                                                                            *  *                             s i m _ c h k _ p p p                          *  *                                                                            *  * Check if page's Partial Page Programming (PPP) counter is below limit. If  *  * it is, increment it, and return flOK; otherwise, return error.             *  *                                                                            * * Parameters:                                                                *  *                                                                            *  *      simDoc  : simulated DiskOnChip                                        *  *      page    : page #                                                      * *      ppp     : pointer to receive existing PPP count for this page         * *                                                                            *  * Returns:                                                                   *  *                                                                            *  *      flOK if PPP counter is below limit, otherwise error code              *  *                                                                            *  * -------------------------------------------------------------------------- */static FLStatus  sim_chk_ppp ( FLSim_t * simDoc,                                long      page,                               char *    ppp ){    char  cnt;    if (page & 1) {           /* odd page; PPP count is in FLSim_t.ppp_count[], bits 7..4 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -