📄 dbmflash2.c
字号:
if (FlashDbmP->DbChanged == TRUE)
{
HwdFlashErase(FlashDbmP->FlashSection2);
SwapFlashSections();
FlashDbmP->DbChanged = FALSE;
}
exit:;
}
/*****************************************************************************
FUNCTION NAME: DbmCacheFlashDbMsg
DESCRIPTION:
This routine handles the cache data base message. When this message
is received the entire data base is read from flash and written to
cache.
PARAMETERS:
MsgDataP - Pointer to message structure
RETURNED VALUES:
None
*****************************************************************************/
void DbmCacheFlashDbMsg(void *MsgDataP)
{
DbmCacheMsgT *RxMsgP;
/* Cast pointer to cache command struct */
RxMsgP = (DbmCacheMsgT *) MsgDataP;
/* Load the cache the from flash */
CacheDb();
/* Send response message back to sender of write command */
ExeMsgSend(RxMsgP->RspInfo.TaskId, RxMsgP->RspInfo.MailboxId,
RxMsgP->RspInfo.MsgId, NULL, 0);
}
/*****************************************************************************
FUNCTION NAME: DbmBlkReadFlashDbMsg
DESCRIPTION:
This routine handles the read block data base message.
Since a block data base does not have a cache, when this
message is received data is read directly from flash. This
routine calculates a flash read address from the data base
id and the requested offset. Also, since the data base
size is stored in the first four bytes of the flash section,
the flash read address is incremented by four to take the
data base size into account. Then the number of bytes to
read specified in the message are read from flash.
PARAMETERS:
MsgDataP - Pointer to message structure
RETURNED VALUES:
None
*****************************************************************************/
void DbmBlkReadFlashDbMsg(void *MsgDataP)
{
DbmBlkReadMsgT *RxMsgP;
DbmBlkReadRspMsgT *RspMsgP;
uint8 *FlashDataP;
HwdFlashSectionTypeT FlashSection;
uint16 NumBytes = 0;
/* Cast pointer to read message struct */
RxMsgP = (DbmBlkReadMsgT *) MsgDataP;
/* Determine the flash section to be read */
switch(RxMsgP->DataBaseId)
{
case DBM_DS_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_DS;
break;
case DBM_PRL1_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_PRL1;
break;
case DBM_PRL2_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_PRL2;
break;
case DBM_VREC1_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_VREC1;
break;
case DBM_VREC2_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_VREC2;
break;
case DBM_VMEM1_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_VMEM1;
break;
case DBM_VMEM2_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_VMEM2;
break;
default:
MonFault(MON_DBM_FAULT_UNIT, DBM_BLK_DB_ID_ERR,
RxMsgP->DataBaseId, MON_CONTINUE);
/* Even though the flash section requested is invalid,
a response message must be generated. So use this
flash section for the read */
FlashSection = HWD_FLASH_BLK_DATA_BASE_DS;
break;
}
/* Allocate memory buffer for response message */
RspMsgP = (DbmBlkReadRspMsgT *) ExeMsgBufferGet(sizeof(DbmBlkReadRspMsgT));
/* Range check DB offset for read */
if (RxMsgP->Offset + sizeof(BlkDbSizeT) > HwdFlashSectionSize(FlashSection))
{
MonFault(MON_DBM_FAULT_UNIT, DBM_BLK_DB_READ_ERR,
RxMsgP->Offset + sizeof(BlkDbSizeT) + RxMsgP->NumBytes, MON_CONTINUE);
/* Error detected so exit */
goto exit;
}
/* Fill in response message data base id, data base length, offset and num bytes */
RspMsgP->DataBaseId = RxMsgP->DataBaseId;
/* Read the data base size from flash and fill in the Rsp msg field */
HwdFlashRead(FlashSection, 0, (uint8 *)&(RspMsgP->DataBaseSize),
sizeof(RspMsgP->DataBaseSize));
/* Check if the data base size had previously been written. A value of 0xffffffff
would indicate the flash is erased, so set the data base size to 0.*/
if (RspMsgP->DataBaseSize == 0xffffffff)
{
/* Set the data base size to 0 */
RspMsgP->DataBaseSize = 0;
/* Read no data */
NumBytes = 0;
}
else
{
/* Set the number of bytes requested */
NumBytes = RxMsgP->NumBytes;
/* Guard against reads beyond the end of the data base */
if (NumBytes + RxMsgP->Offset > RspMsgP->DataBaseSize)
{
/* Limit the number of bytes read to the amount remaining at the end of the
data base if this read would have read beyond the end of this data base. */
if (RxMsgP->Offset > RspMsgP->DataBaseSize)
NumBytes = 0;
else
NumBytes = (uint16)(RspMsgP->DataBaseSize - RxMsgP->Offset);
}
}
/* Set the offset from the received message */
RspMsgP->Offset = RxMsgP->Offset;
/* Set the number of bytes */
RspMsgP->NumBytes = NumBytes;
/* Calculate pointer to requested data in flash */
FlashDataP = (uint8 *) ((uint32)HwdFlashSectionAddress(FlashSection) +
RspMsgP->Offset + sizeof(BlkDbSizeT));
/* Move data from flash memory to caller application memory buffer */
SysMemcpy(RxMsgP->DataP, FlashDataP, NumBytes);
exit:;
/* Send response message back to message originator */
ExeMsgSend(RxMsgP->RspInfo.TaskId, RxMsgP->RspInfo.MailboxId,
RxMsgP->RspInfo.MsgId, (void *) RspMsgP, sizeof(DbmBlkReadRspMsgT));
}
/*****************************************************************************
FUNCTION NAME: DbmBlkWriteFlashDbMsg
DESCRIPTION:
This routine handles the write block data base message. When this
message is received, if the message type is data then data from the
message is written to flash. The address is calculated based on the
offset contained in the message and the associated flash section's
base address. Then the amount of data specified by the message is
written to the data base address.
PARAMETERS:
MsgDataP - Pointer to message structure
RETURNED VALUES:
None
*****************************************************************************/
void DbmBlkWriteFlashDbMsg(void *MsgDataP)
{
DbmBlkWriteMsgT *RxMsgP;
DbmBlkWriteRspMsgT *RspMsgP;
DbmAckTypeT AckType;
HwdFlashSectionTypeT FlashSection;
uint32 Index;
uint32 FlashOffset;
uint32 FlashSectionSize;
uint16 Data;
uint16 NumBytes;
uint8 *DataPtr;
uint8 ByteData;
/* Set ack type */
AckType = DBM_ACK_TYPE;
/* Cast pointer to msg struct */
RxMsgP = (DbmBlkWriteMsgT *) MsgDataP;
/* Determine the flash section to be programmed */
switch(RxMsgP->DataBaseId)
{
case DBM_DS_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_DS;
break;
case DBM_PRL1_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_PRL1;
break;
case DBM_PRL2_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_PRL2;
break;
case DBM_VREC1_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_VREC1;
break;
case DBM_VREC2_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_VREC2;
break;
case DBM_VMEM1_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_VMEM1;
break;
case DBM_VMEM2_DATA_BASE:
FlashSection = HWD_FLASH_BLK_DATA_BASE_VMEM2;
break;
default:
MonFault(MON_DBM_FAULT_UNIT, DBM_BLK_DB_ID_ERR,
RxMsgP->DataBaseId, MON_CONTINUE);
/* Set ack type */
AckType = DBM_NACK_TYPE;
goto exit;
}
/* Check if init or data message */
if (RxMsgP->MsgType == DBM_PROG_INIT_TYPE)
{
/* Erase the flash section */
HwdFlashErase(FlashSection);
/* The data base size is in the offset field for init type messages */
/* If the data base size is larger than what is allocated
for this particular data base then monfault */
if (RxMsgP->Offset + sizeof(BlkDbSizeT) > HwdFlashSectionSize(FlashSection))
{
MonFault(MON_DBM_FAULT_UNIT, DBM_BLK_DB_WRITE_ERR, RxMsgP->Offset + sizeof(BlkDbSizeT),
MON_CONTINUE);
/* Set ack type */
AckType = DBM_NACK_TYPE;
goto exit;
}
/* The data base's first 32 bit word is the
data base size. The data base size is
returned with each block data base read
response message. */
/* Write the lower word of the data base size to the
first word in flash */
HwdFlashProgram16(FlashSection, 0x00, (uint16)(RxMsgP->Offset & 0xffff));
/*
Write the upper word of the data base size to the
second word in flash
*/
HwdFlashProgram16(FlashSection, 0x01, (uint16)(RxMsgP->Offset >> 16) & 0xffff);
}
else
{
/* Calculate the flash offset */
FlashOffset = (RxMsgP->Offset + sizeof(BlkDbSizeT))/2;
/* Set the number of bytes to read and point to the write data */
NumBytes = RxMsgP->NumBytes;
DataPtr = (uint8 *)RxMsgP->Data;
/* Check if the byte offset is odd */
if (RxMsgP->Offset & 0x01)
{
/* Its odd. Read the byte at the corresponding even byte offset */
HwdFlashRead(FlashSection, FlashOffset * 2, &ByteData, 1);
/*
Create a word with the byte just read and the first message
byte to be written to the data base
*/
Data = ByteData | (*DataPtr++ << 8);
/* Program the flash with the word */
HwdFlashProgram16(FlashSection, FlashOffset, Data);
/* One fewer byte to be programmed into flash */
NumBytes--;
/* Increment the flash offset to the next word location */
FlashOffset++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -