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

📄 sysnvram.c

📁 Vxworks的bsp软件开发包(基于wrPpmc74xx)
💻 C
字号:
/* sysNvRam.c - NVRAM driver *//* Copyright 1984-2002 Wind River Systems, Inc. *//*modification history--------------------01b,15dec01,g_h  Fixe bug in sysNvRamGet that cause the VTS to fail01a,22jun01,g_h  created.*//*DESCRIPTIONThis library contains routines to manipulate NvRAM on Flash memory.The macros NV_RAM_ADRS and NV_RAM_SIZE must be defined to indicate theaddress and size of the Flash memory.INCLUDES: amd29LV800TMem.h*/#include "vxWorks.h"#include "config.h"#include "memLib.h"#include "stdlib.h"#include "amd29LV800TMem.h"#include "amd29LV800TMem.c"/***************************************************************************    ** sysNvRamGet - get the contents of non-volatile RAM** This routine copies the contents of non-volatile memory into a specified* string.  The string will be terminated with an EOS.** INTERNAL* The board has no NVRAM, so we've implemented some pseudo-NVRAM* in the flash.** RETURNS: OK or ERROR** SEE ALSO: sysNvRamSet()*/STATUS sysNvRamGet    (    char *	string,		/* where to copy flash memory      */    int		strLen,		/* maximum number of bytes to copy */    int		offset		/* byte offset into flash memory   */    )    {    char * pNvRam;    char * pString;    int	   i;    offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */    /* Check that the string is entirely within the NVRAM */    if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))        return ERROR;           pNvRam  = (char *)(NV_RAM_ADRS + offset);    pString =  (char *)string;    for (i = 0; i < strLen; i++)        *pString++ = *pNvRam++;    *pString = EOS;       /* force EOS onto nvram string */    /*      * It seems that the generic boot-line code expects this function to check     * the contents and report any errors. The default boot line is only used if     * this function returns ERROR. So, we return ERROR if the NvRam block contine     * only 0xFF character (= erased flash).     */    for (pNvRam = (char*)NV_RAM_ADRS; pNvRam < (char*)(NV_RAM_ADRS + NV_RAM_SIZE); pNvRam++)        {        if (*pNvRam != 0xFF)           return (OK);        }    return (ERROR);    }/***************************************************************************** sysNvRamSet - write data to non-volatile RAM** This routine copies the provided string to the non-volatile memory.** INTERNAL* The board has no NVRAM, so we've implemented some pseudo-NVRAM* in the flash.* The "NVRAM" is a small region at the very top of flash memory, and can* thus be read using normal memory accesses. However, to write the data we* have to read the entire top sector, modify its contents, erase the top* sector, and then reprogram it.** RETURNS: OK or ERROR** SEE ALSO: sysNvRamGet()*/STATUS sysNvRamSet    (    char *	string,		/* string to be copied into flash memory */    int		strLen,		/* maximum number of bytes to copy       */    int		offset		/* byte offset into flash memory         */    )    {    UINT32   blockOffs;    char   * pBlock;    char   * pTmpBuf;    offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */    /* Check that the string will fit entirely into the NVRAM */    if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))        return ERROR;    /* see if contents are actually changing */    if (bcmp ((char *) (NV_RAM_ADRS + offset), string, strLen) == 0)	return OK;    /* Allocate a temporary buffer for the operation */    pTmpBuf = (char *)malloc (FLASH_SECTOR_SIZE);    if ( pTmpBuf == NULL )        return ERROR;    pBlock = (UINT8 *)((UINT32)(NV_RAM_ADRS + offset) & ~(FLASH_SECTOR_SIZE-1));    /* Copy current contents of flash (entire sector) to the buffer */    memcpy (pTmpBuf,(void*)pBlock,FLASH_SECTOR_SIZE);    /* Now erase the flash sector */    amd29LV800TEraseSector ((volatile UINT8 *)pBlock);    blockOffs = (NV_RAM_ADRS + offset) & (FLASH_SECTOR_SIZE-1);    /* Overwrite buffer contents with specified string */    memcpy ((void*)(pTmpBuf + blockOffs),string,strLen);    /* Now program the flash sector */    amd29LV800TWrite ((volatile UINT8 *)pBlock, pTmpBuf, FLASH_SECTOR_SIZE);    /* We could verify the programming here, but there's big trouble if       it didn't work, so we won't bother. */    free (pTmpBuf);    return OK;    }

⌨️ 快捷键说明

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