📄 pieeprom.c
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "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 VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
*
* File: pieeprom.c
*
* Purpose: UI controlled EEPROM accessing functions
*
* Author: Tevin Chen
*
* Date: Jan 08, 2002
*
* Functions:
*
* Revision History:
*
*/
#if !defined(__NVRAM_H__)
#include "nvram.h"
#endif
#include "pieeprom.h"
#include "pidef.h"
/*--------------------- Static Definitions -------------------------*/
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
/*--------------------- Static Functions --------------------------*/
/*--------------------- Export Variables --------------------------*/
UINT8 g_abyNVRSwCache[NVR_SIZE_IPCONF + NVR_SIZE_FWUPDT + NVR_SW_CACHE_SIZE];
PUINT8 g_pu8NVRSwCache = g_abyNVRSwCache + (NVR_ADDR_DATA_AREA_START - NVR_ADDR_IPCONF);
/*--------------------- Export Macros -----------------------------*/
/*--------------------- Export Functions --------------------------*/
void NVRAM_vUpdateChecksum (UINT32 u32Size)
{
INT16 i16NvramBuf;
INT16 i16Checksum = 0;
UINT32 ui;
// align to 2-byte boundary
if ((u32Size % 2) != 0) {
NVRAM_bWriteU8(NVR_ADDR_DATA_AREA_START + u32Size, 0);
u32Size++;
}
for (ui = 0; ui < (u32Size / 2); ui++) {
NVRAM_bReadBlock(NVR_ADDR_DATA_AREA_START + ui*2, (PUINT8)&i16NvramBuf, 2);
i16Checksum += i16NvramBuf;
}
i16Checksum = (~i16Checksum) + 1;
NVRAM_bWriteBlock(NVR_ADDR_DATA_AREA_CHKSM, (PUINT8)(&i16Checksum), 2, FALSE);
}
BOOL NVRAM_bVerifyChecksum (UINT32 u32Size)
{
INT16 i16NvramBuf;
INT16 i16CalChecksum = 0;
UINT32 ui;
// if not 2-byte alignment, error
if ((u32Size % 2) != 0)
return FALSE;
u32Size += 2;
for (ui = 0; ui < (u32Size / 2); ui++) {
NVRAM_bReadBlock(NVR_ADDR_DATA_AREA_CHKSM + ui * 2, (PUINT8)&i16NvramBuf, 2);
i16CalChecksum += i16NvramBuf;
}
if (i16CalChecksum != 0)
return FALSE;
return TRUE;
}
void PIEEP_vGetCfgFromEep (UINT32 byAddr, UINT8 bySize, PUINT8 abyCfgBuf)
{
NVRAM_bReadBlock(byAddr, abyCfgBuf, bySize);
}
void PIEEP_vSetCfgIntoEep (PUINT8 abyCfgBuf, UINT32 byAddr, UINT8 bySize)
{
NVRAM_bWriteBlock(byAddr, abyCfgBuf, bySize, FALSE);
}
BOOL PIEEP_bCheckVerAndSig(void)
{
UINT8 byValue;
NVRAM_bReadU8(NVR_ADDR_SIGNATURE, &byValue);
if (byValue != EEP_VALUE_SIGNATURE)
return FALSE;
NVRAM_bReadU8(NVR_ADDR_CONTENT_VER, &byValue);
if (byValue != EEP_VALUE_CONTENT_VER)
return FALSE;
return TRUE;
}
void PIEEP_vSetVerAndSig(BOOL bWriteDefault)
{
if (bWriteDefault) {
// Set value to nvram software cache.
g_pu8NVRSwCache[NVR_ADDR_SIGNATURE - NVR_ADDR_DATA_AREA_START] = EEP_VALUE_SIGNATURE;
g_pu8NVRSwCache[NVR_ADDR_CONTENT_VER - NVR_ADDR_DATA_AREA_START] = EEP_VALUE_CONTENT_VER;
}
else {
NVRAM_bWriteU8(NVR_ADDR_SIGNATURE, EEP_VALUE_SIGNATURE);
NVRAM_bWriteU8(NVR_ADDR_CONTENT_VER, EEP_VALUE_CONTENT_VER);
NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -