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

📄 flsysvxw.c

📁 mDOC电子盘在VxWorks环境下的驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************/
/*                                                                            */
/*  Copyright (C), 1995-2006, msystems Ltd. All rights reserved.              */
/*                                                                            */
/*  Redistribution and use in source and binary forms, with or without        */
/*  modification, are permitted provided that the following conditions are    */
/*  met:                                                                      */
/*  1. Redistributions of source code must retain the above copyright notice, */
/*     this list of conditions and the following disclaimer.                  */
/*  2. Redistributions in binary form must reproduce the above copyright      */
/*     notice, this list of conditions and the following disclaimer in the    */
/*     documentation and/or other materials provided with the distribution.   */
/*  3. Neither the name of msystems nor the names of its contributors may be  */
/*     used to endorse or promote products derived from this software without */
/*     specific prior written permission.                                     */
/*                                                                            */
/*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
/*  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR             */
/*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      */
/*  OWNER OR CONTRIBUTORS 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.              */
/*                                                                            */
/******************************************************************************/
/*******************************************************************************
 *                                                                             *
 *                         Module: FLSYSVXW                                    * 
 *                                                                             * 
 *  This module implements VxWorks-to-TFFS bindings.                           *
 *                                                                             * 
 *******************************************************************************/




/*
 * $Log:   V:/PVCSDB/DiskOnChip/archives/Embedded/OS/VxWorks/1.0/examples/drivers/vxworks/system/flsysvxw.c-arc  $
 * 
 *    Rev 1.0   Aug 20 2006 14:11:24   Alexander.Geller
 * Initial revision.
 * 
 *    Rev 1.1   Aug 03 2004 20:24:46   andrayk
 * flDelayMsecs() commented out
 * 
 *    Rev 1.0   12 Aug 2003 01:58:14   andrayk
 * Initial revision.
 */




#include "flbase.h"
#include "fldrvvxw.h"




/*
 * configuration
 */

/* #define FL_SYS_MEM_CORRUPTION */    /* enable to catch heap corruption */




/*
 * global vars
 */

/* set to non-zero to yield the CPU during flash write/erase operations */
unsigned char  flDelay = 0;

/* pointer to routine which handles TrueFFS messages */
FLMsgHandler  tffsMsgHandler = NULL;

/* active zones for TrueFFS error/warning/flow messages */
int  tffsMsgErrZone  = FLZONE_FULL;
int  tffsMsgWarnZone = FLZONE_NONE;
int  tffsMsgFlowZone = FLZONE_NONE;

/* size of driver's internal diagnostic buffer (in KBytes) */
int  tffsMsgBufSize  = 8;




/*
 * static vars
 */

static int  flSysClkRate;             /* BSP's ticks-per-second setting */

static SEM_ID msgLogMutex;            /* mutex protecting message log */
static char * msgLogStart;            /* start of message log */
static char * msgLogCurrent;          
 
#ifdef FL_SYS_MEM_CORRUPTION

#define  FL_SYS_SENTINEL_STR_LEN  32
 
static char const sentinelStr[FL_SYS_SENTINEL_STR_LEN + 1] = 
                              "M-SystemsDynamicMemoryAllocation";
#endif




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *               f l S y s f u n I n i t                                  *
 *                                                                        *
 * Called from flInit().                                                  *
 *                                                                        *
 * ---------------------------------------------------------------------- */

void  flSysfunInit ( void )
{
    /* obtain BSP's ticks-per-second setting */

    flSysClkRate = sysClkRateGet ();

    /* if user hasn't installed custom message handler, install default one */

    if (tffsMsgHandler == NULL) {

        msgLogStart = NULL;

        if (tffsMsgBufSize > 0) {

            /* create mutex to protect message log */

            msgLogMutex = semMCreate (SEM_DELETE_SAFE | SEM_INVERSION_SAFE | SEM_Q_PRIORITY);

            if( msgLogMutex != (SEM_ID)0 ) {

                /* allocate message log of specified size */

                msgLogStart = FL_MALLOC (tffsMsgBufSize * 1024);

                msgLogCurrent = msgLogStart;
            }
        }

        tffsMsgHandler = tffsMsgSave;
    }
}




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *               f l S y s f u n I n i t                                  *
 *                                                                        *
 * Called from flExit().                                                  *
 *                                                                        *
 * ---------------------------------------------------------------------- */

void  flSysfunExit ( void )
{
   /* not used */
}




/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                 f l R a n d B y t e                                    * 
 *                                                                        * 
 * Generate random value in range 0..255.                                 * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        * 
 *      random value in range 0..255                                      * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

unsigned  flRandByte ( void )
{
    return (unsigned) (tickGet() & 0xff);
}





/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *              f l D e l a y M s e c s                                   * 
 *                                                                        *
 * Spin for specified number of milliseconds                              * 
 *                                                                        *
 * Parameters:                                                            * 
 *                                                                        * 
 *      millisec    : Number of milliseconds to spin                      * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */
 
#if 0
void  flDelayMsecs ( unsigned  millisec )
{
    register unsigned long  ticks;

    ticks = (unsigned long) ((millisec * flSysClkRate) / 500);

    if (ticks == 0)
        ticks++;

    ticks += tickGet ();

    /* spin specified number of milliseconds */

    while( tickGet() <= ticks )
        ;
}
#endif





/* ---------------------------------------------------------------------- * 
 *                                                                        * 
 *                 f l s l e e p                                          * 
 *                                                                        * 
 * This routine should be called during the flash erase operation to      * 
 * yield the CPU for a 'microsec' microseconds.                           * 
 *                                                                        * 
 * Parameters:                                                            * 
 *                                                                        * 
 *      microsec    : Number of microseconds to sleep                     * 
 *                                                                        * 
 * ---------------------------------------------------------------------- */

void  flsleep ( unsigned long  microsec )
{
    register int  ticks;

    if (flDelay != 0) {

        /* convert microsec to clock ticks */

        ticks = (((int)microsec * flSysClkRate) / 1000000);

        if (ticks <= 0)
            ticks = 1;

        /* yield CPU */

        taskDelay (ticks);
    }
}




/* ---------------------------------------------------------------------- * 
 *                                                                        *
 *                   f l c p y 8                                          * 
 *                                                                        *
 * 8-bit 'memcopy' routine.                                               * 
 *                                                                        *
 * Parameters:                                                            * 
 *                                                                        *
 *      dest            : pointer to the destination buffer               * 
 *      src             : pointer to the source buffer                    * 
 *      size            : number of bytes to copy                         * 
 *                                                                        * 
 * Returns:                                                               * 
 *                                                                        *
 *  arguement 'dest'                                                      *
 *                                                                        *
 * ---------------------------------------------------------------------- */

static void FAR0 *  flcpy8 ( void FAR0       * dest, 

⌨️ 快捷键说明

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