📄 eeprom.c
字号:
//-----------------------------------------------------------------------------
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on
// your install media.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// FREESCALE SEMICONDUCTOR, INC.
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// File: bspeeprom.c
//
// BSP EEPROM access routines via CS8900 interface.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <halether.h>
#include "bsp.h"
//------------------------------------------------------------------------------
// External Variables
// CS8900 EEPROM access routines from OAL common\arm\freescale\zeus
BOOL CS8900ReadEEPROM(UINT16 EEPROMAddress, UINT16 *pwVal);
BOOL CS8900WriteEEPROM(UINT16 EEPROMAddress, UINT16 data);
BOOL CS8900EEPROMDetect(BYTE *pAddress);
BOOL CS8900EEPROMResetCfgValid(BOOL bReset);
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
// Function pointers to the support library functions of the
// currently installed debug ethernet controller.
//
static PFN_EDBG_READ_EEPROM pfnEDbgReadEEPROM;
static PFN_EDBG_WRITE_EEPROM pfnEDbgWriteEEPROM;
static BOOL gbEEPROMPresent;
//------------------------------------------------------------------------------
// Local Functions
//-----------------------------------------------------------------------------
//
// Function: BSPEEPROMInit
//
// Function detects for a EEPROM on board, and initialize the EEPROM device
// to be used.
//
// Parameters:
// pAddress
// [in] Ptr to CS8900 IO address base.
//
// Returns:
// FALSE if EEPROM is not detected.
//
//-----------------------------------------------------------------------------
BOOL BSPEEPROMInit(BYTE *pAddress)
{
PBYTE pBaseIOAddress = NULL;
UINT32 i;
UINT16 resetCfg[EEPPOM_RESET_CFG_WORDS] = EEPROM_DEFAULT_RESET_CFG;
UINT16 *pResetCfg;
OALMSG(OAL_FUNC, (TEXT("+BSPEEPROMInit(0x%08x)\r\n"), pAddress));
pBaseIOAddress = (PBYTE)OALPAtoVA((UINT32)pAddress, FALSE);
gbEEPROMPresent = CS8900EEPROMDetect(pBaseIOAddress);
if(!gbEEPROMPresent)
{
OALMSG(OAL_ERROR, (TEXT("+BSPEEPROMInit: No CS8900 eeprom detected\r\n")));
goto cleanup;
}
pfnEDbgReadEEPROM = CS8900ReadEEPROM;
pfnEDbgWriteEEPROM = CS8900WriteEEPROM;
if(!CS8900EEPROMResetCfgValid(FALSE))
{
// Invalid reset configuration. Write a default one into EEPROM
pResetCfg = resetCfg;
for(i = 0; i < EEPPOM_RESET_CFG_WORDS; i++, pResetCfg++)
{
if(!pfnEDbgWriteEEPROM(i, *pResetCfg))
{
OALMSG(OAL_ERROR, (TEXT("ERROR: Failed to initialize reset configuration.\r\n")));
goto cleanup;
}
}
}
cleanup:
OALMSG(OAL_FUNC, (TEXT("-BSPEEPROMInit(%d)\r\n"), gbEEPROMPresent));
return gbEEPROMPresent;
}
//-----------------------------------------------------------------------------
//
// Function: BSPEEPROMWriteUserData
//
// Writes non reset configuration user specified data to EEPROM. Does not
// allow overwriting of the reset configuration area in EEPROM.
//
// Parameters:
// offset
// [in] Offset from start of user data area.
//
// pData
// [in] Ptr to the user data buffer.
//
// numWords
// [in] Length of data in words.
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL BSPEEPROMWriteUserData(UINT16 offset, UINT16 *pwData, UINT32 numWords)
{
UINT32 i;
BOOL success = FALSE;
OALMSG(OAL_FUNC, (TEXT("+BSPEEPROMWriteUserData(%04x %08x %08x)\r\n"),
offset, pwData, numWords));
if( (!gbEEPROMPresent) || (numWords > EEPROM_USER_DATA_MAX_WORDS) ||
(offset >= EEPROM_USER_DATA_MAX_WORDS) )
{
OALMSG(OAL_ERROR, (TEXT("BSPEEPROMWriteUserData: invalid param.\r\n")));
goto cleanup;
}
// Force offset to location beyond reset configuration block
offset += EEPPOM_RESET_CFG_WORDS;
for(i = 0; i < numWords; i++, offset++, pwData++)
{
if(!pfnEDbgWriteEEPROM(offset, *pwData))
{
OALMSG(OAL_ERROR, (TEXT("BSPEEPROMWriteUserData: write(%d) failed.\r\n"), i));
goto cleanup;
}
}
success = TRUE;
cleanup:
OALMSG(OAL_FUNC, (TEXT("-BSPEEPROMWriteUserData(%d)\r\n"), success));
return success;
}
//-----------------------------------------------------------------------------
//
// Function: BSPEEPROMReadUserData
//
// Reads non reset configuration user specified data to EEPROM. Does not
// read the reset configuration area in EEPROM.
//
// Parameters:
// offset
// [in] Offset from start of user data area.
//
// pData
// [out] Ptr to the user data buffer store.
//
// numWords
// [in] Length of data in words.
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL BSPEEPROMReadUserData(UINT16 offset, UINT16 *pwData, UINT32 numWords)
{
UINT32 i;
BOOL success = FALSE;
OALMSG(OAL_FUNC, (TEXT("+BSPEEPROMReadUserData(%04x %08x %08x)\r\n"),
offset, pwData, numWords));
if( (!gbEEPROMPresent) || (numWords > EEPROM_USER_DATA_MAX_WORDS) ||
(offset >= EEPROM_USER_DATA_MAX_WORDS) )
{
OALMSG(OAL_ERROR, (TEXT("BSPEEPROMReadUserData: Invalid param\r\n")));
goto cleanup;
}
// Force offset to location beyond reset configuration block
offset += EEPPOM_RESET_CFG_WORDS;
for(i = 0; i < numWords; i++, offset++, pwData++)
{
if(!pfnEDbgReadEEPROM(offset, pwData))
{
OALMSG(OAL_ERROR, (TEXT("BSPEEPROMReadUserData: Read(%d) failed\r\n"), i));
goto cleanup;
}
}
success = TRUE;
cleanup:
OALMSG(OAL_FUNC, (TEXT("-BSPEEPROMReadUserData(%d)\r\n"), success));
return success;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -