📄 dbmeeprm.c
字号:
FUNCTION NAME: DbmFlushEepromDbMsg
DESCRIPTION:
This routine handles the flush data base message. When this message
is received the changed portions of the RAM data base is written to
to the EEPROM.
PARAMETERS:
None
RETURNED VALUES:
None
*****************************************************************************/
void DbmFlushEepromDbMsg(void *MsgDataP)
{
DbmFlushMsgT *RxMsgP;
uint32 Index;
/* Cast pointer to flush command struct */
RxMsgP = (DbmFlushMsgT *) MsgDataP;
/* Set DB pointers and constants */
SetDbPointers();
/* Check if the RAM data base has been cached. If not cached exit */
if (!DbCached)
{
MonFault(MON_DBM_FAULT_UNIT, DBM_NOT_CACHED_ERR, 0, MON_CONTINUE);
goto exit;
}
/* Scan the RAM data base, if an element has changed flush it from
the cache data base to the EEPROM. */
for (Index = 0; Index < DbTotalSize; Index++)
{
if (CheckDbChanged(Index))
{
/* Write to EEPROM, if error is true then return at once */
if (WriteEeprom(Index, DataBaseP + Index, RxMsgP->DataBaseId))
goto exit;
/* Set data base changed array */
SetDbChanged(Index, CACHE_OK);
}
}
/* Send response message back to sended of write command */
ExeMsgSend(RxMsgP->RspInfo.TaskId, RxMsgP->RspInfo.MailboxId,
RxMsgP->RspInfo.MsgId, NULL, 0);
exit:;
}
/*****************************************************************************
FUNCTION NAME: DbmCacheEepromDbMsg
DESCRIPTION:
This routine handles the cache data base message. When this message
is received the entire data base from the EEPROM is read and placed
into the RAM cache data base.
PARAMETERS:
None
RETURNED VALUES:
None
*****************************************************************************/
void DbmCacheEepromDbMsg(void *MsgDataP)
{
DbmCacheMsgT *RxMsgP;
/* Cast pointer to cache command struct */
RxMsgP = (DbmCacheMsgT *) MsgDataP;
/* Cache the RAM data base from the EEPROM */
CacheDb();
/* Send response message back to sended of write command */
ExeMsgSend(RxMsgP->RspInfo.TaskId, RxMsgP->RspInfo.MailboxId,
RxMsgP->RspInfo.MsgId, NULL, 0);
}
/*****************************************************************************
FUNCTION NAME: CacheDb
DESCRIPTION:
This routine reads the entire data base from the EEPROM and writes
it to the RAM cache data base.
PARAMETERS:
None
RETURNED VALUES:
None
*****************************************************************************/
static void CacheDb(void)
{
uint8 *DbCacheP;
uint32 Address;
uint16 BytesRemaining;
uint16 NumBytes;
/* Set DB pointers and constants */
SetDbPointers();
/*
Read entire data base from EEPROM and into RAM data base cache.
The eeprom is divided into "n" banks. The maximum amount of data
that can be read in a single read operation is one bank. If the
data base size spans more than a single bank then the read
operation must be split into multiple reads. During the read
if an error is returned then return at once.
*/
BytesRemaining = DbTotalSize;
DbCacheP = DataBaseP;
Address = 0;
do {
/* Calculate how many bytes to read */
NumBytes = (BytesRemaining > DBM_EEPROM_BANK_SIZE) ?
DBM_EEPROM_BANK_SIZE:DbTotalSize % DBM_EEPROM_BANK_SIZE;
/* Read the eeprom, if an error is returned then return */
if (ReadEeprom(Address, DbCacheP, NumBytes, DBM_RF_DATA_BASE))
return;
/* Increment the address from which the eeprom is read */
Address += DBM_EEPROM_BANK_SIZE;
/* Increment the address to which the eeprom data is written */
DbCacheP += NumBytes;
/* Decrement the number of bytes left to read by how much was read */
BytesRemaining -= NumBytes;
} while (BytesRemaining);
/* Set DB changed array to cache ok state */
SysMemset(DbChangedP, CACHE_OK, DbChangedSize);
/* Set DB cached flag */
DbCached = TRUE;
}
/*****************************************************************************
FUNCTION NAME: ReadEeprom
DESCRIPTION:
This routine reads data bytes from the physical serial EEPROM chip
which is connected to the I2C interface. This routine returns a
PASS/FAILED indicator on the read operation.
PARAMETERS:
Address - EEPROM byte address
DataPtr - Pointer to where to place the data
NumBytes - Number of bytes to read
DataBaseId - Data base id (CP or RF)
RETURNED VALUES:
bool - Returns FALSE for passed and TRUE for failed
*****************************************************************************/
static bool ReadEeprom(uint32 Address, uint8* DataPtr, uint16 NumBytes,
DbmDataBaseIdT DataBaseId)
{
bool I2cStatus;
bool ReadStatus = FALSE;
/* Obtain control of the I2C interface and register this task's id and
signal flag as the user. This operation prevents other tasks from
using the I2C interface until this task is done with it. */
HwdI2cLock(EXE_DBM_ID, EEPROM_RD_DONE_SIGNAL);
/* Start read operation from the EEPROM on the I2C interface */
HwdI2cRead(Address, DataPtr, NumBytes, DeviceNum);
/* Wait for the I2C LISR to signal that the EEPROM read is complete.
Include a time out just in case the EEPROM does not respond. */
ExeEventWait(EXE_DBM_ID, EXE_SIGNAL_TRUE, EXE_MESSAGE_FALSE,
ExeCalMsec(EEPROM_READ_TIMEOUT));
/* Get HW status of I2C interface */
I2cStatus = HwdI2cStatus();
/* Release the I2C interface so another task can use it */
HwdI2cUnlock();
/* Check if I2C error occurred, if so EEPROM not reponding */
if (I2cStatus)
{
MonFault(MON_DBM_FAULT_UNIT, DBM_NOT_RESPONDING_ERR, DataBaseId,
MON_CONTINUE);
ReadStatus = TRUE;
}
return ReadStatus;
}
/*****************************************************************************
FUNCTION NAME: WriteEeprom
DESCRIPTION:
This routine writes a single data byte to the physical serial EEPROM
chip which is connected to the I2C interface. This routine returns a
PASS/FAILED indicator on the write operation.
PARAMETERS:
Address - EEPROM byte address
DataPtr - Pointer to where to get the data
DataBaseId - Data base id (CP or RF)
RETURNED VALUES:
bool - Returns FALSE for passed and TRUE for failed
*****************************************************************************/
static bool WriteEeprom(uint32 Address, uint8* DataPtr, DbmDataBaseIdT DataBaseId)
{
bool I2cStatus;
bool WriteStatus = FALSE;
/* Obtain control of the I2C interface and register this task's id and
signal flag as the user. This operation prevents other tasks from
using the I2C interface until this task is done with it. */
HwdI2cLock(EXE_DBM_ID, EEPROM_RD_DONE_SIGNAL);
/* Start write operation to the EEPROM on the I2C interface */
HwdI2cWrite(Address, DataPtr, DeviceNum);
/* Wait for 10 msec for write to complete */
ExeEventWait(EXE_DBM_ID, EXE_SIGNAL_FALSE, EXE_MESSAGE_FALSE,
ExeCalMsec(EEPROM_WRITE_TIMEOUT));
/* Get HW status of I2C interface */
I2cStatus = HwdI2cStatus();
/* Release the I2C interface so another task can use it */
HwdI2cUnlock();
/* Check if I2C error occurred, if so EEPROM not reponding */
if (I2cStatus)
{
MonFault(MON_DBM_FAULT_UNIT, DBM_NOT_RESPONDING_ERR, DataBaseId,
MON_CONTINUE);
WriteStatus = TRUE;
}
return WriteStatus;
}
/*****************************************************************************
FUNCTION NAME: SetDbChanged
DESCRIPTION:
This routine sets a bit in the changed data base array indicating
that a byte in the RAM cache data base has changed.
PARAMETERS:
Address - Data base byte address
Action - Set or clear the bit in data base changed array
RETURNED VALUES:
None.
*****************************************************************************/
static void SetDbChanged(uint32 Address, uint32 Action)
{
uint32 DbByte;
uint32 DbBit;
/* Calculate byte and bit address based on data base byte address */
DbByte = Address >> 3; /* Divide by 8 */
DbBit = Address & 0x07; /* Mod 8 */
/* Check action and then set or clear bit in data base changed array */
if (Action == CACHE_CHANGED)
DbChangedP[DbByte] |= (0x01 << DbBit); /* Set the bit */
else
DbChangedP[DbByte] &= ~(0x01 << DbBit); /* Clear the bit */
}
/*****************************************************************************
FUNCTION NAME: CheckDbChanged
DESCRIPTION:
This routine checks a bit in the changed data base array indicating
that a byte in the RAM cache data base has changed.
PARAMETERS:
Address - Data base byte address
RETURNED VALUES:
bool - TRUE data base byte has changed
FALSE data base byte has not changed
*****************************************************************************/
static bool CheckDbChanged(uint32 Address)
{
uint32 DbByte;
uint32 DbBit;
/* Calculate byte and bit address based on data base byte address */
DbByte = Address >> 3; /* Divide by 8 */
DbBit = Address & 0x07; /* Mod 8 */
/* Check bit in data base changed array */
return (bool) ((DbChangedP[DbByte] >> DbBit) & 0x01);
}
/*****************************************************************************
FUNCTION NAME: SetDbPointers
DESCRIPTION:
This routine sets data base pointers and constants based on which
data base (EEPROM device 1 or 2) was set in the DBM message command.
PARAMETERS:
None
RETURNED VALUES:
None.
*****************************************************************************/
static void SetDbPointers(void)
{
SegIndexP = &SegIndex[0];
SegLengthP = &SegLength[0];
DataBaseP = &DataBase[0];
DbChangedP = &DbChanged[0];
DbTotalSize = DB_TOTAL_SIZE;
DbChangedSize = DB_CHANGED_SIZE;
DbMaxSeg = DBM_MAX_SEG_DB_2;
DeviceNum = HWD_I2C_EEPROM_DEVICE_2;
}
/*****************************************************************************
* $Log: dbmeeprm.c $
* Revision 1.1 2003/11/07 18:55:27 xuhua
* Initial revision
* Revision 1.1 2003/10/21 16:01:58 hanxiao99
* Initial revision
* Revision 1.1 2003/10/08 14:40:47 hanxiao99
* Initial revision
* Revision 1.1 2003/09/03 14:52:36 hanxiao99
* Initial revision
* Revision 1.1 2003/07/31 05:21:10 javese
* Initial revision
* Revision 1.2 2002/10/24 01:39:38 Bing
* Check in for Greg
* Revision 1.1 2002/10/03 17:32:47 fpeng
* Initial revision
* Revision 1.3 2002/05/29 08:51:36 mshaver
* Added VIA Technologies copyright.
* Revision 1.2 2001/02/05 11:45:23 robertk
* Merge changes from version used in PS sandbox into CBP4 baseline.
* Revision 1.1 2000/10/06 13:40:18 mshaver
* Initial revision
* Revision 1.1 2000/10/06 18:26:47Z mshaver
* Initial revision
* Revision 1.1 2000/10/24 21:02:26Z fpeng
* Initial revision
* Revision 1.10 2000/09/15 16:39:02Z mmalopy
* - RF EEPROM device constants, SegLength[] array, and SegIndex[]
* array modified to support new RF segments defined with common AFC
* parameters..
* Revision 1.9 2000/09/12 17:36:29Z mmalopy
* - RF EEPROM device constants, SegLength[] array, and SegIndex[]
* array modified to support new RF segments.
* Revision 1.8 2000/06/30 18:51:44Z mshaver
* Fold changes from rev 1.7.1.2 into the baseline
* Revision 1.7.1.2 2000/06/30 17:56:18Z mshaver
* Changed CacheDb to allow a variable number of eeprom banks
* to be read into the cache instead of assuming just 2 banks.
* Revision 1.7.1.1 2000/06/01 15:33:24Z mshaver
* Duplicate revision
* Revision 1.7 2000/06/01 15:33:24Z bcolford
* Added CP database sections for Amps related baseband configuration
* parameters and Amps related Dspv configuration paramaters. Also
* added a section in the RF database for Amps related radio
* configuration parameters.
* Revision 1.6.2.3 2000/05/19 22:59:27Z bcolford
* Move RF related AMPS calibration values to the RF database.
* Define a new section for baseband related AMPS calibration values
* and define a new section for AMPS related DSP calibration values.
* Revision 1.6.2.2 2000/05/15 20:56:28Z bcolford
* Revision 1.6.2.1 2000/01/29 02:19:24Z bcolford
* Duplicate revision
* Revision 1.6 2000/01/29 02:19:24Z etarolli
* Updated flash and eeprom DB code so they are similar
* Revision 1.5 2000/01/28 21:39:04Z bcolford
* Added segment sizes and segment indexes for all the new HWD RF
* related segments.
* Revision 1.4 2000/01/19 21:20:13Z etarolli
* Updated DBM segment sizes for HWD
* Revision 1.3 2000/01/19 20:25:52Z mshaver
* Fold in changes into the baseline
* Revision 1.2.1.2 1999/12/22 21:14:42Z mshaver
* Changed public function prototype names to include 'Eeprom'
* in order to differentiate from the 'Flash' routines
* Revision 1.2.1.1 1999/12/02 18:31:54Z mshaver
* Duplicate revision
* Revision 1.2 1999/12/02 18:31:54Z cdma
* Updated comments for CBP3.0
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -