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

📄 flsim.c

📁 DOC文件系统驱动源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*******************************************************************************  *                                                                             *  *                         M-Systems Confidential                              *  *           Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2002        *  *                         All Rights Reserved                                 *  *                                                                             *  *******************************************************************************  *                                                                             *  *                         NOTICE OF M-SYSTEMS OEM                             *  *                         SOFTWARE LICENSE AGREEMENT                          *  *                                                                             *  *  THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE AGREEMENT       *  *  BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT FOR THE SPECIFIC    *  *  TERMS AND CONDITIONS OF USE, OR CONTACT M-SYSTEMS FOR LICENSE              *  *  ASSISTANCE:                                                                *  *  E-MAIL = info@m-sys.com                                                    *  *                                                                             *  ******************************************************************************* *                                                                             *  *                                                                             *  *                         Module: FLSIM                                       *  *                                                                             *  *  This module implements simulation of the DiskOnChip on RAM.                * *                                                                             *  *******************************************************************************//* * $Log:   V:/Flite/archives/OSAK/examples/drivers/VxWorks/flsim.c_V  $ * 
 *    Rev 1.7   16 May 2003 19:59:00   andrayk
 * TrueFFS-5.1.4
 *  *    Rev 1.5   12 Feb 2002 01:05:30   andreyk * TrueFFS-5.1 *//* * configuration *//*  * includes  */#include "flsim.h"/*  * Types  *//* * macros *//* 4KByte alignment of simDoc's memory (as required by flsocket.c) */#define FL_SIM_4KB_ALIGNMENT           (4 * 1024)/* * global vars *//* if no simDoc configuration specified, this one will be used by default */FLSimConf_t  flsimDefaultConf = FL_SIM_CONF_MDOC; /* FL_SIM_CONF_MPLUS *//* * static routines *//* simDoc's socket installation */static FLStatus  sim_install_socket (FLSim_t *simDoc);/* simDoc's dummy socket routines */static FLBoolean  sim_always_true (FLSocket vol);static FLBoolean  sim_always_false (FLSocket vol);static FLStatus   sim_always_ok (FLSocket vol);static void       sim_do_nothing (FLSocket vol);static void       sim_no_mapping (FLSocket vol, unsigned page);/* simDoc's standard MTD routines */static FLStatus    sim_identify (FLFlash vol);static FLStatus    sim_read (FLFlash vol, CardAddress addr, void FAR1 *buf,                     dword len, word mode);static FLStatus    sim_write (FLFlash vol, CardAddress addr, const void FAR1 * buf,                      dword len, word mode);static FLStatus    sim_erase (FLFlash vol, word block, word blocks);static void FAR0 * sim_map (FLFlash vol, CardAddress addr, int len);static FLStatus    sim_read_BBT (FLFlash vol, dword unit, dword units, byte multiplier,                          byte FAR1 *buf, FLBoolean reconstruct);/* access to PPP counters */static void       sim_clear_ppp (FLSim_t *simDoc, long page);static FLStatus   sim_chk_ppp (FLSim_t *simDoc, long page, char *ppp);/* simDoc's configuration */static FLStatus   sim_conf_sanity (FLSimConf_t *conf);/* calculate simDoc's memory requirements */static FLStatus   sim_alloc (FLSim_t *simDoc);/* simDoc's statistics */static void       sim_clear_stats (FLSim_t *simDoc);/* check if it's possible to write new data over existing one */static FLStatus   sim_chk_overwrite (const char *old, const char FAR1 *new, int len);/* * static vars *//* number of installed simDoc sockets */ static int  sim_sockets = 0;/* MTD-specific extention of struct FLFlash */static FLSim_t  sims [SOCKETS];/* simulated EDC/ECC checksum */static char   sim_dummy_edc [FL_SIM_MAX_ECC_SIZE] = {'E','D','C','E','C','C','e','d','c','e','c','c'};/* -------------------------------------------------------------------------- * *                                                                            * *                   f l s i m D e f a u l t C o n f i g                      * *                                                                            * * This routine defines default simDoc configuration.                         * *                                                                            * * Parameters:                                                                * *                                                                            * *      conf            : simDoc configuration                                * *                                                                            * * Returns:                                                                   * *                                                                            * *      0 on success, otherwise -1.                                           * *                                                                            * * -------------------------------------------------------------------------- */int  flsimDefaultConfig ( FLSimConf_t FAR1 * conf ){    if (conf == NULL)        return -1;    tffscpy( &flsimDefaultConf, conf, sizeof(FLSimConf_t) );    return 0;}/* -------------------------------------------------------------------------- * *                                                                            * *                      f l R e g i s t e r S i m S o c                       * *                                                                            * * Install all simDoc sockets.                                                * *                                                                            * * Parameters:                                                                * *                                                                            * *      conf            : simDoc configuration, or NULL for default           * *                                                                            * * Returns:                                                                   * *                                                                            * *      flOK on success, otherwise respective error code.                     * *                                                                            * * -------------------------------------------------------------------------- */FLStatus  flRegisterSimSoc ( FLSimConf_t FAR1 * conf ){    if ((noOfSockets >= SOCKETS) || (sim_sockets >= SOCKETS))        return flTooManyComponents;    /* if no simDoc configuration specified, use default one */    if (conf == NULL) {        DEBUG_PRINT(("FLSim: configuration isn't specified, using default.\n"));        conf = (FLSimConf_t FAR1 *) &flsimDefaultConf;    }    /* remember simDoc configuration locally */    tffscpy( &(sims[sim_sockets].conf), conf, sizeof(FLSimConf_t) );    /* install simDoc socket */    checkStatus(  sim_install_socket(&sims[sim_sockets]) );    return flOK;}/* -------------------------------------------------------------------------- *  *                                                                            * *                      f l R e g i s t e r S i m M T D                       * *                                                                            * * Registers this MTD for use                                                 * *                                                                            * * Returns:                                                                   * *                                                                            * *      flOK on success, otherwise respective error code                      * *                                                                            * * -------------------------------------------------------------------------- */FLStatus  flRegisterSimMTD ( void ){    /* if MTD table is full, abort */    if (doc_noOfMTDs >= MTDS) {        DEBUG_PRINT(("FLSim: MTD table is full.\n"));        return flTooManyComponents;    }    /* add simDoc's MTD to MTD table */    doc_mtdTable[doc_noOfMTDs++] = sim_identify;    return  flOK;}/* -------------------------------------------------------------------------- * *                                                                            * *                      s i m _ i n s t a l l _ s o c k e t                   * *                                                                            * * Install single simDoc socket.                                              * *                                                                            * * Parameters:                                                                * *                                                                            * *      simDoc   : simulated DiskOnChip                                       * *                                                                            * * Returns:                                                                   * *                                                                            * *      flOK on success, otherwise respective error code.                     * *                                                                            * * -------------------------------------------------------------------------- */static FLStatus  sim_install_socket ( FLSim_t * simDoc ){    FLSimConf_t * conf;    FLSocket      vol;    /* if socket table is full, abort */    if (noOfSockets >= SOCKETS) {        DEBUG_PRINT(("FLSim: Socket table is full.\n"));        return flTooManyComponents;    }    /* simDoc configuration */    conf = &simDoc->conf;    /* check simDoc configuration for sanity */    checkStatus( sim_conf_sanity (conf) );    /* create socket */    pVol = flSocketOf(noOfSockets);    vol.volNo = noOfSockets;    flSetWindowSize (&vol, 2);  /* 4 KBytes */    /* allocate memory to contain simDoc's "flash" and associated data structures */    if( sim_alloc(simDoc) != flOK ) {        DEBUG_PRINT(("FLSim: insufficeint memory.\n"));        return flNotEnoughMemory;    }    /* WARNING: 'vol.window.base' must be aligned at 4KB boundary */    vol.window.base = simDoc->flash;    /* clear MTD statistics */    sim_clear_stats (simDoc);    /* install simDoc's dummy socket routines */    vol.cardDetected                   = sim_always_true;    vol.VccOn                          = sim_do_nothing;    vol.VccOff                         = sim_do_nothing;    vol.initSocket                     = sim_always_ok;    vol.setWindow                      = sim_do_nothing;    vol.setMappingContext              = sim_no_mapping;    vol.getAndClearCardChangeIndicator = sim_always_false;    vol.writeProtected                 = sim_always_false;    vol.updateSocketParams             = NULL;#ifdef SOCKET_12_VOLTS    vol.VppOn                          = sim_always_ok;    vol.VppOff                         = sim_do_nothing;#endif#ifdef EXIT    vol.freeSocket                     = sim_do_nothing;#endif    /* simDoc socket has been created */    noOfSockets ++;    sim_sockets ++;    return  flOK;}/* -------------------------------------------------------------------------- *  *                                                                            * *                        s i m I d e n t i f y                               * *                                                                            * * Identify flash. This routine will be registered as the                     * * identification routine for this MTD.                                       * *                                                                            * * Parameters:                                                                * *                                                                            * *      vol             : pointer identifying drive                           * *                                                                            * * Returns:                                                                   * *                                                                            * *      flOK on success, otherwise respective error code                      * *                                                                            * * -------------------------------------------------------------------------- */      static FLStatus  sim_identify ( FLFlash vol ){    FLSocket * socket;    FLSim_t  * simDoc;    int        socNo;    socket = vol.socket;    socNo = flSocketNoOf (socket);    /* check if it's simDoc socket indeed */    if (socket->initSocket != sim_always_ok)         return flUnknownMedia;    /* attach MTD-specific data to struct FLFlash */    simDoc = &(sims[socNo]);    vol.mtdVars = (void *) simDoc;    /* get pointer to buffer (we assume SINGLE_BUFFER is not defined) */    simDoc->map_buffer = flBufferOf (socNo);    flSetWindowBusWidth (socket, 16);  /* use 16-bits */    flSetWindowSpeed (socket, 120);    /* 120 nsec.   */    (void) flMap (socket, 0);    /* install simDoc's MTD routines */    vol.write = sim_write;    vol.erase = sim_erase;

⌨️ 快捷键说明

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