📄 db_fs.c
字号:
#if defined(WIN32)
pu8buffer[3]=0x3f;
#else
pu8buffer[0]=0x3f;
#endif
FMgr_Write(stTableInfo.u8BankID, stTableInfo.u16Address+(stTableInfo.u8ItemSize*u16record_idx), pu8buffer, DB_POOL_ITEM_HEADER);
}
/*******************************************************************************************/
void _datapool_del_record(EN_DB_TABLE_TYPE enTable, u8 u8sub_id, u16 u16record_idx)
{
if(u16record_idx>=0x0fff || u8sub_id>=0x0f)
return;
_bit_search_table(enTable, u8sub_id, &stTableInfo);
u32buffer = 0;
FMgr_Write(stTableInfo.u8BankID, stTableInfo.u16Address+(stTableInfo.u8ItemSize*u16record_idx), (u8*)&u32buffer, DB_POOL_ITEM_HEADER);
}
/*******************************************************************************************/
void _datapool_get_available(EN_DB_TABLE_TYPE enTable, u8* pu8sub_id, u16* pu16record_index)
{
*pu8sub_id = au8last_available_sub_id[enTable];
_bit_search_table( enTable, au8last_available_sub_id[enTable], &stTableInfo);
// find a bank that has avaliable data
while(1)
{
*pu16record_index = FMgr_Search( stTableInfo.u8BankID,
stTableInfo.u16Address,
stTableInfo.u8ItemSize,
stTableInfo.u16NumOfItem,
DATAPOOL_FLAG_MASK,
DATAPOOL_AVALIABLE_FLAG);
if(*pu16record_index!=stTableInfo.u16NumOfItem)
{
break;
}
(*pu8sub_id)++;
if( _bit_search_table( enTable, *pu8sub_id, &stTableInfo)==FALSE )
{
*pu8sub_id=0;
}
if( *pu8sub_id==au8last_available_sub_id[enTable])
{
break;
}
_bit_search_table( enTable, *pu8sub_id, &stTableInfo);
}
// can't find avaliable, garbage recycle
if(*pu16record_index==stTableInfo.u16NumOfItem)
{
while(1)
{
// find next bank that has dirty data
(*pu8sub_id)++;
if( _bit_search_table( enTable, *pu8sub_id, &stTableInfo)==FALSE )
{
(*pu8sub_id)=0;
_bit_search_table( enTable, *pu8sub_id, &stTableInfo);
}
if( FMgr_CheckAvailable(stTableInfo.u8BankID)==FALSE )
{
break;
}
*pu16record_index = FMgr_Search( stTableInfo.u8BankID,
stTableInfo.u16Address,
stTableInfo.u8ItemSize,
stTableInfo.u16NumOfItem,
DATAPOOL_FLAG_MASK,
DATAPOOL_DEL_FLAG);
if(*pu16record_index!=stTableInfo.u16NumOfItem)
break;
if( *pu8sub_id==au8last_available_sub_id[enTable])
{
FS_DBG(( "ERROR: No more avaliable data pool!!!\n"));
return;
}
}
_garbage_recycle(stTableInfo.u8BankID);
FMgr_WriteBank(stTableInfo.u8BankID);
*pu16record_index = FMgr_Search( stTableInfo.u8BankID,
stTableInfo.u16Address,
stTableInfo.u8ItemSize,
stTableInfo.u16NumOfItem,
DATAPOOL_FLAG_MASK,
DATAPOOL_AVALIABLE_FLAG);
}
au8last_available_sub_id[enTable] = *pu8sub_id;
}
/*******************************************************************************************/
#ifndef DB_ACCELERATE_CMD
static u8 u8datapool_current_sub_id;
static u16 u16datapool_current_record_idx;
static u16 u16datapool_remainder_item;
/*******************************************************************************************/
void _datapool_ready_to_get_next_valid_data(EN_DB_TABLE_TYPE enTable)
{
u8datapool_current_sub_id = 0;
u16datapool_current_record_idx = 0;
_bit_search_table(enTable, u8datapool_current_sub_id, &stTableInfo);
}
/*******************************************************************************************/
bool8 _datapool_get_next_valid_data(EN_DB_TABLE_TYPE enTable, u16* pu16logi_idx, u8* pu8sub_id, u16* pu16record_idx)
{
do
{
u16datapool_remainder_item = stTableInfo.u16NumOfItem-u16datapool_current_record_idx;
u16temp
= FMgr_Search( stTableInfo.u8BankID,
stTableInfo.u16Address+(u16datapool_current_record_idx*stTableInfo.u8ItemSize),
stTableInfo.u8ItemSize,
u16datapool_remainder_item,
DATAPOOL_FLAG_MASK,
DATAPOOL_DATA_FLAG);
if( u16temp==u16datapool_remainder_item )
{
u16datapool_current_record_idx=0;
}
else
{
u16datapool_current_record_idx+=u16temp;
FMgr_Read(stTableInfo.u8BankID,
stTableInfo.u16Address+(u16datapool_current_record_idx*stTableInfo.u8ItemSize),
(u8*)&u32buffer, DB_POOL_ITEM_HEADER);
*pu16logi_idx = u32buffer&0x0000ffff;
*pu8sub_id = u8datapool_current_sub_id;
*pu16record_idx = u16datapool_current_record_idx;
u16datapool_current_record_idx++;
return TRUE;
}
u8datapool_current_sub_id++;
}
while(_bit_search_table(enTable, u8datapool_current_sub_id, &stTableInfo)==TRUE);
return FALSE;
}
#endif
/*******************************************************************************************/
void _datapool_dump(EN_DB_TABLE_TYPE enTable, u8 u8sub_id, u16 u16offset)
{
_bit_search_table( enTable, u8sub_id, &stTableInfo);
FS_DBG(( "\nDump DataPool %hx-%hx:\n", enTable, u8sub_id));
#if (DB_DRAM_IMAGE==0)
FMgr_ReadBank(stTableInfo.u8BankID);
DVB_DramDump(DB_CACHE_DRAM_START+stTableInfo.u16Address+u16offset, 0x400);
#else
DVB_DramDump(DB_CACHE_DRAM_START+(stTableInfo.u8BankID-1)*0x10000+stTableInfo.u16Address, 0x400);
#endif
}
/*******************************************************************************************/
// DATAPOOL========================================================================================
// INFO ALLOCATION TABLE (IAT)=====================================================================
void _iat_dump(u8 u8type) // 0:sat, 1:tp, 2:srv
{
switch(u8type)
{
default:
case EN_SRV_TABLE:
u32temp = DB_DRAM_IAT_SRV;
u16temp = MAX_NUM_OF_SRV*DB_IAT_ITEM_SIZE;
break;
case EN_TP_TABLE:
u32temp = DB_DRAM_IAT_TP;
u16temp = MAX_NUM_OF_TP*DB_IAT_ITEM_SIZE;
break;
case EN_SAT_TABLE:
u32temp = DB_DRAM_IAT_SAT;
u16temp = MAX_NUM_OF_SAT*DB_IAT_ITEM_SIZE;
break;
case EN_GENERAL_FILE:
u32temp = DB_DRAM_IAT_FILE;
u16temp = MAX_NUM_OF_FILE_BLOCK*DB_IAT_ITEM_SIZE;
break;
}
FS_DBG(( "\nDump IAT %hx:\n", u8type));
DVB_DramDump(u32temp,u16temp);
}
/*******************************************************************************************/
void _iat_get(EN_DB_TABLE_TYPE enTable, u16 u16logi_idx, u8* pu8sub_id, u16* pu16record_idx)
{
switch(enTable)
{
case EN_SRV_TABLE:
u32temp = DB_DRAM_IAT_SRV;
break;
case EN_TP_TABLE:
u32temp = DB_DRAM_IAT_TP;
break;
case EN_SAT_TABLE:
u32temp = DB_DRAM_IAT_SAT;
break;
case EN_GENERAL_FILE:
u32temp = DB_DRAM_IAT_FILE;
break;
default:
break;
}
u32temp+=(u16logi_idx*DB_IAT_ITEM_SIZE);
DVB_DramRead(u32temp & 0xfffffffc, (u8*)&u32buffer, 4);
#if defined(WIN32)
if( (u32temp&0x00000003)==0)
#else
if( (u32temp&0x00000003)!=0)
#endif
u32buffer = u32buffer & 0x0000ffff;
else
u32buffer = u32buffer>>16;
*pu8sub_id = u32buffer>>12;
*pu16record_idx = u32buffer&0x0fff;
}
/*******************************************************************************************/
void _iat_set(EN_DB_TABLE_TYPE enTable, u16 u16logi_idx, u8 u8sub_id, u16 u16record_idx)
{
u32 u32temp2;
switch(enTable)
{
case EN_SRV_TABLE:
u32temp = DB_DRAM_IAT_SRV;
break;
case EN_TP_TABLE:
u32temp = DB_DRAM_IAT_TP;
break;
case EN_SAT_TABLE:
u32temp = DB_DRAM_IAT_SAT;
break;
case EN_GENERAL_FILE:
u32temp = DB_DRAM_IAT_FILE;
break;
default:
break;
}
u32temp+=(u16logi_idx*DB_IAT_ITEM_SIZE);
DVB_DramRead( u32temp&0xfffffffc, (u8*)&u32buffer, 4);
#if defined(WIN32)
if( (u32temp&0x00000003)==0)
#else
if( (u32temp&0x00000003)!=0)
#endif
{
u16temp = u8sub_id&0x0f;
u32buffer = (u32buffer & 0xffff0000)+(u16temp<<12)+(u16record_idx&0x0fff);
}
else
{
u16temp = u8sub_id&0x0f;
u32temp2 = (u16temp<<12)+(u16record_idx&0x0fff);
u32buffer = (u32temp2<<16)+(u32buffer&0x0000ffff);
}
DVB_DramWrite( u32temp&0xfffffffc, (u8*)&u32buffer, 4);
}
/*******************************************************************************************/
u16 _iat_get_available(EN_DB_TABLE_TYPE enTable)
{
switch(enTable)
{
default:
case EN_SRV_TABLE:
u32temp = DB_DRAM_IAT_SRV;
u16temp = MAX_NUM_OF_SRV;
break;
case EN_TP_TABLE:
u32temp = DB_DRAM_IAT_TP;
u16temp = MAX_NUM_OF_TP;
break;
case EN_SAT_TABLE:
u32temp = DB_DRAM_IAT_SAT;
u16temp = MAX_NUM_OF_SAT;
break;
case EN_GENERAL_FILE:
u32temp = DB_DRAM_IAT_FILE;
u16temp = MAX_NUM_OF_FILE_BLOCK;
break;
}
return DVB_DramSearch(u32temp, DB_IAT_ITEM_SIZE, u16temp, IAT_SUB_ID_MASK, IAT_AVAILABLE_FLAG, TRUE);
}
/*******************************************************************************************/
void _iat_clean(void)
{
DVB_DramSet( DB_DRAM_IAT,0xff, DB_IAT_SIZE);
}
/*******************************************************************************************/
#ifdef DB_ACCELERATE_CMD
bool8 _iat_init(void)
{
EN_DB_TABLE_TYPE enTable;
u8 u8sub_id;
u16 u16NumOfRecord;
FS_DBG(( "build IAT from data poll...\n"));
DVB_DramSet( DB_DRAM_IAT,0xff, DB_IAT_SIZE);
for( enTable=0; enTable<MAX_TABLE_NUMBER; enTable++)
{
if(enTable==EN_RELATION_TABLE)
continue;
u8sub_id = 0;
while(_bit_search_table(enTable, u8sub_id, &stTableInfo)==TRUE)
{
switch(enTable)
{
case EN_SRV_TABLE:
u8temp = DB_SRV_POOL_ITEM_SIZE; // record size
u16NumOfRecord = DB_SRV_NUM_IN_ONE_BANK; // record number
u32temp = DB_DRAM_IAT_SRV; // IAT address
u16temp = MAX_NUM_OF_SRV; // IAT number
break;
case EN_TP_TABLE:
u8temp = DB_TP_POOL_ITEM_SIZE; // record size
u16NumOfRecord = DB_TP_NUM_IN_ONE_BANK; // record number
u32temp = DB_DRAM_IAT_TP; // IAT address
u16temp = MAX_NUM_OF_TP; // IAT number
break;
case EN_SAT_TABLE:
u8temp = DB_SAT_POOL_ITEM_SIZE; // record size
u16NumOfRecord = DB_SAT_NUM_IN_ONE_BANK; // record number
u32temp = DB_DRAM_IAT_SAT; // IAT address
u16temp = MAX_NUM_OF_SAT; // IAT number
break;
case EN_GENERAL_FILE:
u8temp = DB_FILE_POOL_ITEM_SIZE; // record size
u16NumOfRecord = DB_FILE_BLOCK_NUM_IN_ONE_BANK; // record number
u32temp = DB_DRAM_IAT_FILE; // IAT address
u16temp = MAX_NUM_OF_FILE_BLOCK; // IAT number
break;
default:
return FALSE;
}
u32buffer = (DB_CACHE_DRAM_START+(stTableInfo.u8BankID-1)*0x10000+stTableInfo.u16Address); // datapool address
u16temp = DVB_DramBuildIAT(u32buffer, u8temp, u16NumOfRecord, u32temp, u16temp, u8sub_id );
if(u16temp==u16NumOfRecord)
{ // success
}
else if(u16temp>u16NumOfRecord)
{ // fatal error
FS_MSG(( "fatal error when building IAT!\n"));
return FALSE;
}
else
{ // duplicate data
FS_DBG(( "del duplicate data!\n"));
_datapool_del_record( enTable, u8sub_id, u16temp);
}
u8sub_id++;
}
}
FS_DBG(( "IAT ok\n"));
return TRUE;
}
#endif
/*******************************************************************************************/
#ifndef DB_ACCELERATE_CMD
bool8 _iat_init(void)
{
EN_DB_TABLE_TYPE enTable;
u16 u16logi_idx, u16test_logi_idx;
u8 u8sub_id, u8test_sub_id;
u16 u16record_idx;
FS_DBG(( "build srv/tp/sat IAT from data poll...\n"));
DVB_DramSet( DB_DRAM_IAT,0xff, DB_IAT_SIZE);
for( enTable=0; enTable<MAX_TABLE_NUMBER; enTable++)
{
if(enTable==EN_RELATION_TABLE)
continue;
_datapool_ready_to_get_next_valid_data(enTable);
while( _datapool_get_next_valid_data(enTable, &u16logi_idx, &u8sub_id, &u16record_idx)==TRUE )
{
_iat_get(enTable, u16logi_idx, &u8test_sub_id, &u16test_logi_idx);
if(u8test_sub_id!=0x0f)
{
FS_DBG(( "del duplicate data!\n"));
_datapool_del_record( enTable, u8sub_id, u16record_idx);
}
else
{
_iat_set(enTable, u16logi_idx, u8sub_id, u16record_idx);
}
}
}
FS_DBG(( "IAT ok\n"));
return TRUE;
}
#endif
/*******************************************************************************************/
// INFO ALLOCATION TABLE (IAT)=====================================================================
// RELATION TABLE==================================================================================
static u8 u8relation_bid;
void _relation_clean(void)
{
_bit_search_table(EN_RELATION_TABLE, 0, &stTableInfo);
u8relation_bid = stTableInfo.u8BankID;
DVB_DramSet( DB_DRAM_RELATION,0xff, DB_RELATION_SIZE);
// db_clean will save relation when add "Other" sat on deleted bank.
// b8relation_update = TRUE;
}
/*******************************************************************************************/
void _relation_init(void)
{
_bit_search_table(EN_RELATION_TABLE, 0, &stTableInfo);
u8relation_bid = stTableInfo.u8BankID;
// load relation table
#if (DB_DRAM_IMAGE==0)
FMgr_ReadBank(u8relation_bid);
DVB_DramCopy(DB_DRAM_RELATION, DB_CACHE_DRAM_START+BANK_DATA_START_ADDRESS, DB_RELATION_SIZE);
#endif
}
/*******************************************************************************************/
void DBFS_SaveRelation(void) // _relation_save()
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
if(b8relation_update==FALSE)
{
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return;
}
#if (DB_DRAM_IMAGE==0)
FMgr_ReadBank(u8relation_bid);
DVB_DramCopy(DB_CACHE_DRAM_START+BANK_DATA_START_ADDRESS, DB_DRAM_RELATION, DB_RELATION_SIZE);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -