📄 blocktable.c
字号:
/**
* BlockTable.c
* These functions are to read and write Block Table data in the flash memory.
*/
#include "BlockTable.h"
#include "Device.h"
#include "SectorInfo.h"
/**
* dms_BlockTableReadTable
* reads awBlockCount number of block table entries in a sector and
* stores a copy of them in the provided array of block table structures.
*
* Prerequisites:
* dms_SectorInfoDefineArchitecture()
* Uses:
* dms_SectorInfoGetBlockTableAddress()
* dms_DeviceRead()
* Used By:
* dms_SectorCleanup()
*/
DMS_STATUS dms_BlockTableReadTable(WORD awSectorIndex, BLOCK_TABLE_ENTRY *apBlockTable, WORD awBlockCount){
DMS_STATUS eStatus;
DWORD dwAddress;
dwAddress = dms_SectorInfoGetBlockTableAddress(awSectorIndex);
eStatus = dms_DeviceRead(dwAddress,(WORD)((WORD)sizeof(BLOCK_TABLE_ENTRY) * (WORD)awBlockCount),(BYTE*)apBlockTable);
if (eStatus != No_Error){
return eStatus;
}
return No_Error;
}
/**
* dms_BlockTableReadEntry
* reads a single block table entry and stores it into a
* pre-allocated structure.
*
* Prerequisites:
* dms_SectorInfoDefineArchitecture()
* Uses:
* dms_SectorInfoGetBlockTableAddress()
* dms_DeviceRead()
* Used By:
* dms_SectorInitialize()
*/
DMS_STATUS dms_BlockTableReadEntry(WORD awSectorIndex, WORD awSectorBlockIndex, BLOCK_TABLE_ENTRY *apEntry){
DMS_STATUS eStatus;
DWORD dwAddress;
dwAddress = dms_SectorInfoGetBlockTableAddress(awSectorIndex) + sizeof(BLOCK_TABLE_ENTRY) * awSectorBlockIndex;
eStatus = dms_DeviceRead(dwAddress,sizeof(BLOCK_TABLE_ENTRY),(BYTE*)apEntry);
if (eStatus != No_Error){
return eStatus;
}
return No_Error;
}
/**
* dms_BlockTableWriteBlockStatus()
* Writes the provided block status into the requested block.
*
* Prerequisites:
* dms_SectorInfoDefineArchitecture()
* Uses:
* dms_SectorInfoGetBlockTableAddress()
* dms_DeviceWrite()
* Used By:
* dms_CellInitialize()
* dms_CellWrite()
* dms_BlockWrite()
* dms_SectorInitialize()
* dms_SectorCleanup()
*/
DMS_STATUS dms_BlockTableWriteBlockStatus(WORD awSectorIndex,WORD awSectorBlockIndex,DMS_BLOCK_STATUS aeBlockStatus){
DMS_STATUS eStatus;
BYTE bBlockStatus;
DWORD dwAddress;
bBlockStatus = (BYTE) aeBlockStatus;
dwAddress = dms_SectorInfoGetBlockTableAddress(awSectorIndex) + sizeof(BLOCK_TABLE_ENTRY) * awSectorBlockIndex
+ offsetof(BLOCK_TABLE_ENTRY,bBlockStatus);
eStatus = dms_DeviceWrite(dwAddress,sizeof(BYTE),(BYTE*)&bBlockStatus);
if (eStatus != No_Error){
return eStatus;
}
return No_Error;
}
/**
* dms_BlockTableWriteCellStatus()
* Writes the provided cell status into the requested block.
*
* Prerequisites:
* dms_SectorInfoDefineArchitecture()
* Uses:
* dms_SectorInfoGetBlockTableAddress()
* dms_DeviceWrite()
* Used By:
* dms_CellWrite()
* dms_BlockWrite()
*/
DMS_STATUS dms_BlockTableWriteCellStatus(WORD awSectorIndex, WORD awSectorBlockIndex, DMS_CELL_STATUS aeCellStatus){
DMS_STATUS eStatus;
BYTE bCellStatus;
DWORD dwAddress;
bCellStatus = (BYTE) aeCellStatus;
dwAddress = dms_SectorInfoGetBlockTableAddress(awSectorIndex) + sizeof(BLOCK_TABLE_ENTRY) * awSectorBlockIndex
+ offsetof(BLOCK_TABLE_ENTRY,bCellStatus);
eStatus = dms_DeviceWrite(dwAddress,sizeof(BYTE),(BYTE*)&bCellStatus);
if (eStatus != No_Error){
return eStatus;
}
return No_Error;
}
/**
* dms_BlockTableWriteCellIndex()
* Writes the provided cell index into the requested block.
*
* Prerequisites:
* dms_SectorInfoDefineArchitecture()
* Uses:
* dms_SectorInfoGetBlockTableAddress()
* dms_DeviceWrite()
* Used By:
* dms_BlockWrite()
*/
DMS_STATUS dms_BlockTableWriteCellIndex(WORD awSectorIndex, WORD awSectorBlockIndex, WORD awCellIndex){
DMS_STATUS eStatus;
DWORD dwAddress;
dwAddress = dms_SectorInfoGetBlockTableAddress(awSectorIndex) + sizeof(BLOCK_TABLE_ENTRY) * awSectorBlockIndex
+ offsetof(BLOCK_TABLE_ENTRY,wCellIndex);
eStatus = dms_DeviceWrite(dwAddress,sizeof(WORD),(BYTE*)&awCellIndex);
if (eStatus != No_Error){
return eStatus;
}
return No_Error;
}
/**
* dms_BlockTableWriteBlockIndex()
* Writes the provided block index into the requested block.
*
* Prerequisites:
* dms_SectorInfoDefineArchitecture()
* Uses:
* dms_SectorInfoGetBlockTableAddress()
* dms_DeviceWrite()
* Used By:
* dms_BlockWrite()
*/
DMS_STATUS dms_BlockTableWriteBlockIndex(WORD awSectorIndex, WORD awSectorBlockIndex, WORD awBlockIndex){
DMS_STATUS eStatus;
DWORD dwAddress;
dwAddress = dms_SectorInfoGetBlockTableAddress(awSectorIndex) + sizeof(BLOCK_TABLE_ENTRY) * awSectorBlockIndex
+ offsetof(BLOCK_TABLE_ENTRY,wBlockIndex);
eStatus = dms_DeviceWrite(dwAddress,sizeof(WORD),(BYTE*)&awBlockIndex);
if (eStatus != No_Error){
return eStatus;
}
return No_Error;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -