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

📄 nvram.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 C
字号:
/**********************************************************************
 *
 *   Copyright (c) 2003-2005, Dy 4 Systems All rights reserved.
 *   This Source Code is the Property of Dy 4 Systems Inc. and can
 *   only be used in accordance with Source Code License
 *   Agreement of Dy 4 Systems Inc. dba (doing business as) 
 *   CURTISS-WRIGHT CONTROLS EMBEDDED COMPUTING, "CWCEC". 
 *
 **********************************************************************/

/* Copyright 1984-1996 Wind River Systems, Inc. */

/***************************************************************************
*
*  Filename: nvRam.c  
*
*  Project Name: 182 BSP 
*
*  Target:  182/183/145  
*
*  Description: Non-volatile RAM library 
*
*  Usage:      
*
*  Initial revision 
*
*  Modification History
*  --------------------
*  01c,28mar05,aak  correct register descr, include bsp.h (CR#2774)
*  01b,02nov04,tis - added support for CCA-145
*                  - make sure to unprotect the NVRAM when sysNvRamSet is called
*  01a,16sep04,mb  PT 2180: replaced obsolete macros NV_RAM_SIZE
*                 by CPU_NVRAM_SIZE and NV_RAM_ADRS by CPU_NVRAM_BASE_ADRS 
*
****************************************************************************/

#include "copyright_wrs.h"
#include "vxWorks.h"
#include "string.h"

#include "D:\Tornado2.2ppc\target\config\cwv183\h\drv\dy4\bsp.h"

STATUS sysNvRamProtectUnprotect(BOOL protect) ;
/******************************************************************************
*
* sysNvRamGet - get the contents of non-volatile RAM
*
* This routine copies the contents of non-volatile memory into a specified
* string.  The string is terminated with an EOS.
*
* RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
*
* SEE ALSO: sysNvRamSet()
*/

STATUS sysNvRamGet
    (
    char *string,    /* where to copy non-volatile RAM    */
    int strLen,      /* maximum number of bytes to get   */
    int offset       /* byte offset into non-volatile RAM */
    )
{
    offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = NV_BOOT_OFFSET */
    if ((offset < 0) || (strLen < 0) || ((offset + strLen) > (CPU_NVRAM_SIZE)))
	{
        return (ERROR);
	}

    bcopyBytes((char*)(CPU_NVRAM_BASE_ADRS + sysProcId*NV_RAM_OFFSET + offset), string, strLen);

    string [strLen] = EOS;

    return (OK);

}


/*******************************************************************************
*
* sysNvRamSet - write to non-volatile RAM
*
* This routine copies a specified string into non-volatile RAM.
*
* RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
*
* SEE ALSO: sysNvRamGet()
*/

STATUS sysNvRamSet
    (
    char *string,     /* string to be copied into non-volatile RAM */
    int strLen,       /* maximum number of bytes to copy           */
    int offset        /* byte offset into non-volatile RAM         */
    )
{
#if (defined (CCA_145) || defined (VME_183))  
   UINT8 value;
   
   /* Get the current status of the NVRAM write protect bit*/
   value = *((UINT8 *) FPGA_WR_PROT_CTRL);
   if (!(value & FPGA_WR_PROT_CTRL_NVRAM))
 /* Make sure that NvRam is write enabled */
   sysNvRamProtectUnprotect (0);
#endif

    offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = NV_BOOT_OFFSET */

    if ((offset < 0) || (strLen < 0) || ((offset + strLen) > CPU_NVRAM_SIZE))
        return (ERROR);

    bcopyBytes (string, (char*)(CPU_NVRAM_BASE_ADRS + sysProcId*NV_RAM_OFFSET + offset), strLen);

#if (defined (CCA_145) || defined (VME_183))  
 /* Make sure to restore the NVRAM write protect bit to its original status*/
  *((UINT8 *) FPGA_WR_PROT_CTRL) = value;
#endif
    return (OK);
}


/******************************************************************************
*
* sysNvRamProtectUnprotect - Can set the nvRam to be Read/Write or Read Only
*
* This routine will set the protection of the nvRAM to the value passed in in
* the protect parameter (0 - write enabled, 1 - write protected). NvRam
* defaults to write enabled.
*
* RETURNS: OK, or ERROR if protect parameter is invalid
*
* SEE ALSO: sysNvRamGet(), sysNvRamSet()
*/

STATUS sysNvRamProtectUnprotect
	(
	BOOL protect
	)
{

	UINT8 value;

#if (defined(CCA_145) || defined( VME_183))


	if ((protect < 0) || (protect > 1))
		{
		return (ERROR);
		}

	/* Read current contents of FPGA Write Protect Control Register */
	
	value = *((UINT8 *) FPGA_WR_PROT_CTRL);
	
	/* Set the NVRAM_WP bit (bit 1) to the  passed in value. */
	
	if (protect)
		{
		value &= ~FPGA_WR_PROT_CTRL_NVRAM;
		}
	else
		{
		value |= FPGA_WR_PROT_CTRL_NVRAM;
		}
		
	/* Write back the new value to the Write Protect CR */
	
	*((UINT8 *) FPGA_WR_PROT_CTRL) = value;
	
	return (OK);
#else
	if ((protect < 0) || (protect > 1))
        {
		return (ERROR);
	}

	/* Read current contents of EPLD Reset Register */
	value = epldRead(EPLD_RESET_REG);
	
	/* Set the NVRAM_WP bit to the  passed in value. */
	
	if (protect)
	{
		value |= EPLD_NVRAM_WP;
	}
	else
	{
		value &= ~EPLD_NVRAM_WP;
	}
		
	/* Write back the new value to the Reset register */
	epldWrite(EPLD_RESET_REG, value);
	
	return (OK);

#endif
}

⌨️ 快捷键说明

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