nvram.c

来自「ge公司的dv4av4信号处理板的bsp源代码」· C语言 代码 · 共 208 行

C
208
字号
/***************************************************************************
*
*  $RCSfile: nvRam.c $
*
*  Copyright 2001 by Dy 4 Systems, Inc.  All Rights Reserved.
*
*  $Revision: 1.6 $
*
*  $Name: AV4-ISP-R1.2-1 AV4-ISP-R1.2-0 $  $State: Developmental $  $Locker: $
*
*  $Source: L:/SWRND/champAV2/src/vx/src/drv/mem/rcs/nvRam.c $
*
*  RCS Project Name:
*
*  CSC:
*
*  Target:
*
*  Description:
* These functions are only used for saving the boot string in flash.
*
*  Usage:
*
*  $Log: nvRam.c $
*  Revision 1.6  2005/05/11 18:06:25Z  jpeiffer
*  Modified so that "bootChange" works on ABCD on CAV4
*  Revision 1.5  2005/03/09 18:57:25  ltsui
*  CAV4 node A does not access bootLine in nvram.
*  Revision 1.4  2004/07/14 19:12:23Z  mzhao
*  Fix bug: bootChange from BCD try's to updated flash and throws an exception. Changing bootline parameters on node B-D has no effect.
*  Revision 1.3  2003/10/21 18:37:50  dsessler
*  replaced AVII_ with CHAMP_
*  Revision 1.2  2002/03/27 20:02:13  dsessler
*
****************************************************************************/

/* includes */

#include "drv/mem/memDev.h"

#ifdef CAV4_BOARD

#include "bslInt.h"

/*
 * The following flags are used to communicate between the processor with flash
 * and the processor performing the "bootChange"
 */
#define BOOT_CHANGE_FLAG_OFFSET        0xFFFC
#define BOOT_CHANGE_FLAG_GOOD          0xAACEAACE
#define BOOT_CHANGE_FLAG_BAD           0xBAADBAAD
#define BOOT_CHANGE_FLAG_CLEAR         0xFFFFFFFF
#endif

/******************************************************************************
* sysNvRamGet - get the contents of non-volatile RAM
*
* For processor A, this function reads the boot string from a file in flash
* memory.  If the file is not found or any other read error is detected, this
* function returns an error code, and copies DEFAULT_BOOT_LINE to the 
* destination area.  DEFAULT_BOOT_LINE may not contain the correct parameters
* for all installations, but it is syntactically correct, and will prevent
* other, more severe errors from occurring while giving the user a chance
* to modify the boot line.
*
* For other processors, this function returns a good status.  In this case,
* sysHwInit has computed a boot line and already deposited it in the target
* area.
*
* NOTE: This routine uses flash memory, since there is no NVRAM on the
* Champ card.
*
* RETURNS: The return value from the flash read file operation.
*
* SEE ALSO: sysNvRamSet()
* NOMANUAL
*/

STATUS sysNvRamGet
    (
    char *string,    /* where to copy flash    */
    int strLen,      /* maximum number of bytes to copy   */
    int offset       /* byte offset into vxWorks flash directory */
    )
    {
    STATUS retVal;
#ifndef CAV4_BOARD    
    char tempString[NV_RAM_SIZE];
    
    /**  Processor A:  get boot parameters from flash memory  **/
    
    if (bslProcId == 0)
        {
         
        if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))
            return (ERROR);

        retVal = bslFlashReadFileRaw(CHAMP_FLASH_VXWORKS, tempString, NV_RAM_SIZE);

        bcopy (tempString+offset, string, strLen);

        /* If error, use default boot string */
        if (retVal != BSL_ERROR_NONE)
            {
            retVal = ERROR;
            strcpy (string, DEFAULT_BOOT_LINE);
            }
        }      

    /**  Other processors:  boot params are already in memory at 0x4200 per sysHwInit  **/
          
    else
#endif
        {
        retVal = OK;
        }
    
    
    return (retVal);
    }
      


/*******************************************************************************
*
* sysNvRamSet - write to non-volatile RAM
*
* This routine simulates a non-volatile RAM write by copying the input string
* into a file within flash memory.  This function is only valid when called 
* from processor A.  
*
* NOTE: This routine uses flash memory, since there is no NVRAM on the
* champ card.
*
* RETURNS: The return value of the flash write operation.
*
* SEE ALSO: sysNvRamGet(), sysFlashSet()
* NOMANUAL
*/

STATUS sysNvRamSet
    (
    char *string,     /* string to be copied into flash */
    int strLen,       /* maximum number of bytes to copy           */
    int offset        /* byte offset into vxWorks flash directory  */
    )
    {
    STATUS retVal;
#ifndef CAV4_BOARD    
    char tempString[NV_RAM_SIZE];

    if (bslProcId == 0)
    {    
	    if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))
	        return (ERROR);
	
	    retVal = bslFlashReadFileRaw(CHAMP_FLASH_VXWORKS, tempString, NV_RAM_SIZE);
	
	    bcopy(string, tempString+offset, strLen);
	
	    retVal = bslFlashWriteFile (CHAMP_FLASH_VXWORKS, tempString, NV_RAM_SIZE, 0);
	
	    if (retVal != BSL_ERROR_NONE)
	        retVal = ERROR;
     }
     else
#endif
     {
#ifndef CAV4_BOARD
        printf("\nUse bootChange ('other' parameter) on node A to change node B-D 'file' parameter\n***Changing bootline parameters here has no effect***\n");
#else
        volatile int *p;
        int          timeout = 10;

        printf( "\n  Writing boot parameters to flash...             " );

        /*
         * Clear handshake flag, then interrupt processor A to perform flash write
         * of boot parameters */
        p = (volatile int *)(BOOT_CHANGE_FLAG_OFFSET + bslProcGetMemAddr( PROC_ID_A ));
         /* Signal processor A to perform NVRAM write */
         *p = BOOT_CHANGE_FLAG_CLEAR;
         bslIntIpiGen( PROC_ID_A, INT_ID_IPI5 );  /* INT_ID_IPI5 */

         /* Wait for status of flash write as set by processor A */
         do
         {
            taskDelay( sysClkRateGet() / 2 );
            bslPpcCacheInv( (void *)p, sizeof( *p ) );
         } while ( ( *p != BOOT_CHANGE_FLAG_GOOD ) &&
                   ( *p != BOOT_CHANGE_FLAG_BAD ) &&
                   ( timeout-- > 0 ) );

         /* Print status of flash update */
         if ( *p == BOOT_CHANGE_FLAG_GOOD )
            printf( "done.\n\n" );
         else if ( *p == BOOT_CHANGE_FLAG_BAD )
            printf( "failed.\n\n" );
         else
            printf( "timed out.\n\n" );
#endif
         
        retVal = OK;     	
     }
    
    return (retVal);	
    }

⌨️ 快捷键说明

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