📄 db_fs.c
字号:
_garbage_recycle(u8relation_bid);
FMgr_WriteBank(u8relation_bid);
b8relation_update = FALSE;
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
u16 DBFS_InfoCounter(EN_DB_TABLE_TYPE enTable)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return 0;
}
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;
}
#if defined(WIN32)
u16temp -= DVB_DramCount(u32temp, DB_IAT_ITEM_SIZE, u16temp, 0x0000ffff, 0x0000ffff);
#else
u16temp -= DVB_DramCount(u32temp, DB_IAT_ITEM_SIZE, u16temp, 0xffff0000, 0xffff0000);
#endif
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return u16temp;
}
/*******************************************************************************************/
//Marlin 20060504 Modify
void DBFS_RelationGetSrv(u16 u16rel_idx, DB_SrvRel* pu8buffer)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
DVB_DramRead(DB_DRAM_RELATION_SRV+DB_RELATION_SRV_ITEM_SIZE*u16rel_idx, (u8*)pu8buffer, DB_RELATION_SRV_ITEM_SIZE);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
void DBFS_RelationGetTp(u16 u16rel_idx, DB_TpRel* pu8buffer)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
DVB_DramRead(DB_DRAM_RELATION_TP+DB_RELATION_TP_ITEM_SIZE*u16rel_idx, (u8*)pu8buffer, DB_RELATION_TP_ITEM_SIZE);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
//Marlin 20060504 Modify
void DBFS_RelationGetNet(u16 u16rel_idx, DB_SatRel* pu8buffer)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
DVB_DramRead(DB_DRAM_RELATION_SAT+DB_RELATION_SAT_ITEM_SIZE*u16rel_idx, (u8*)pu8buffer, DB_RELATION_SAT_ITEM_SIZE);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
//Marlin 20060504 Modify
void DBFS_RelationSetSrv(u16 u16rel_idx, DB_SrvRel* pu8buffer)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
DVB_DramWrite(DB_DRAM_RELATION_SRV+DB_RELATION_SRV_ITEM_SIZE*u16rel_idx, (u8*)pu8buffer, DB_RELATION_SRV_ITEM_SIZE);
b8relation_update = TRUE;
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
void DBFS_RelationSetTp(u16 u16rel_idx, DB_TpRel* pu8buffer)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
DVB_DramWrite(DB_DRAM_RELATION_TP+DB_RELATION_TP_ITEM_SIZE*u16rel_idx, (u8*)pu8buffer, DB_RELATION_TP_ITEM_SIZE);
b8relation_update = TRUE;
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
//Marlin 20060504 Modify
void DBFS_RelationSetNet(u16 u16rel_idx, DB_SatRel* pu8buffer)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
DVB_DramWrite(DB_DRAM_RELATION_SAT+DB_RELATION_SAT_ITEM_SIZE*u16rel_idx, (u8*)pu8buffer, DB_RELATION_SAT_ITEM_SIZE);
b8relation_update = TRUE;
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
void _relation_dump(u8 u8type) // 0:sat, 1:tp, 2:srv
{
switch(u8type)
{
default:
case EN_SRV_TABLE:
u32temp = DB_DRAM_RELATION_SRV;
u16temp = MAX_NUM_OF_SRV*DB_RELATION_SRV_ITEM_SIZE;
break;
case EN_TP_TABLE:
u32temp = DB_DRAM_RELATION_TP;
u16temp = MAX_NUM_OF_TP*DB_RELATION_TP_ITEM_SIZE;
break;
case EN_SAT_TABLE:
u32temp = DB_DRAM_RELATION_SAT;
u16temp = MAX_NUM_OF_SAT*DB_RELATION_SAT_ITEM_SIZE;
break;
}
FS_DBG(( "\nDump Relation %hx:\n", u8type));
DVB_DramDump(u32temp,u16temp);
}
/*******************************************************************************************/
// RELATION TABLE==================================================================================
// DBFS============================================================================================
bool8 DBFS_Init(void)
{
bool8 b8InitResult = FALSE;
b8InitResult = FMgr_Init();
_datapool_init();
if( _iat_init()==FALSE )
{
b8InitResult = FALSE;
}
_relation_init();
if (CT_OS_CreateSemaphore(&stDBFSSemaphore, "DBFSSEM", 1, EN_CTOS_SUSPEND_FIFO) != EN_CTOS_SUCCESS)
{
b8InitResult = FALSE;;
}
return b8InitResult;
}
/*******************************************************************************************/
void DBFS_Clean(void)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
FMgr_DeleteAll();
_datapool_clean();
_iat_clean();
_relation_clean();
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
static u8 u8DBFS_sub_id;
static u16 u16DBFS_record_index;
static u8 u8DBFS_data_length;
/*******************************************************************************************/
bool8 DBFS_InfoCheckAvailable(EN_DB_TABLE_TYPE enTable, u16 u16logic_index)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return FALSE;
}
_iat_get(enTable, u16logic_index, &u8DBFS_sub_id, &u16DBFS_record_index);
if(u16DBFS_record_index==0x0fff||u8DBFS_sub_id==0x0f)
{
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return FALSE;
}
else
{
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return TRUE;
}
}
/*******************************************************************************************/
void DBFS_InfoDestroy(EN_DB_TABLE_TYPE enTable, u16 u16logic_index)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
_iat_get(enTable, u16logic_index, &u8DBFS_sub_id, &u16DBFS_record_index);
_datapool_del_record( enTable, u8DBFS_sub_id, u16DBFS_record_index);
_iat_set(enTable, u16logic_index, 0xff, 0xffff);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
void DBFS_InfoRead(EN_DB_TABLE_TYPE enTable, u16 u16logic_index, u8* pu8buffer)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
switch(enTable)
{
default:
case EN_SRV_TABLE:
u8DBFS_data_length = DB_SRV_INFO_ITEM_SIZE;
break;
case EN_TP_TABLE:
u8DBFS_data_length = DB_TP_INFO_ITEM_SIZE;
break;
case EN_SAT_TABLE:
u8DBFS_data_length = DB_SAT_INFO_ITEM_SIZE;
break;
case EN_GENERAL_FILE:
u8DBFS_data_length = DB_FILE_BLOCK_SIZE;
break;
}
_iat_get(enTable, u16logic_index, &u8DBFS_sub_id, &u16DBFS_record_index);
if(u8DBFS_sub_id==0x0f||u16DBFS_record_index==0x0fff)
{
memset(pu8buffer, 0xff, u8DBFS_data_length);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return;
}
_datapool_read_record( enTable, u8DBFS_sub_id, u16DBFS_record_index, pu8buffer, u8DBFS_data_length);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
void DBFS_InfoWrite(EN_DB_TABLE_TYPE enTable, u16 u16logic_index, u8* pu8buffer)
{
u8 u8old_sub_id;
u16 u16old_record_index;
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
switch(enTable)
{
default:
case EN_SRV_TABLE:
u8DBFS_data_length = DB_SRV_INFO_ITEM_SIZE;
break;
case EN_TP_TABLE:
u8DBFS_data_length = DB_TP_INFO_ITEM_SIZE;
break;
case EN_SAT_TABLE:
u8DBFS_data_length = DB_SAT_INFO_ITEM_SIZE;
break;
case EN_GENERAL_FILE:
u8DBFS_data_length = DB_FILE_BLOCK_SIZE;
break;
}
// find avaliable record in data pool
_datapool_get_available(enTable, &u8DBFS_sub_id, &u16DBFS_record_index);
// write to datapool
*(u32*)au8DBFS_record_buffer = u16logic_index;
memcpy(au8DBFS_record_buffer+DB_POOL_ITEM_HEADER, pu8buffer, u8DBFS_data_length);
_datapool_write_record( enTable, u8DBFS_sub_id, u16DBFS_record_index, au8DBFS_record_buffer, u8DBFS_data_length+DB_POOL_ITEM_HEADER);
// reserve old record info.
_iat_get(enTable, u16logic_index, &u8old_sub_id, &u16old_record_index);
// update Info Allocation Table
_iat_set(enTable, u16logic_index, u8DBFS_sub_id, u16DBFS_record_index);
// delete old record
_datapool_del_record( enTable, u8old_sub_id, u16old_record_index);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
}
/*******************************************************************************************/
u16 DBFS_InfoNew(EN_DB_TABLE_TYPE enTable, u8* pu8buffer)
{
u16 u16logic_index;
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return 0;
}
switch(enTable)
{
default:
case EN_SRV_TABLE:
u8DBFS_data_length = DB_SRV_INFO_ITEM_SIZE;
break;
case EN_TP_TABLE:
u8DBFS_data_length = DB_TP_INFO_ITEM_SIZE;
break;
case EN_SAT_TABLE:
u8DBFS_data_length = DB_SAT_INFO_ITEM_SIZE;
break;
case EN_GENERAL_FILE:
u8DBFS_data_length = DB_FILE_BLOCK_SIZE;
break;
}
// find avaliable entry in allocation table
u16logic_index = _iat_get_available(enTable);
// find avaliable record in data pool
_datapool_get_available( enTable, &u8DBFS_sub_id, &u16DBFS_record_index);
// update Info Allocation Table
_iat_set( enTable, u16logic_index, u8DBFS_sub_id, u16DBFS_record_index);
// write to datapool
*(u32*)au8DBFS_record_buffer = u16logic_index;
memcpy(au8DBFS_record_buffer+DB_POOL_ITEM_HEADER, pu8buffer, u8DBFS_data_length);
_datapool_write_record( enTable, u8DBFS_sub_id, u16DBFS_record_index, au8DBFS_record_buffer, u8DBFS_data_length+DB_POOL_ITEM_HEADER);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return u16logic_index;
}
/*******************************************************************************************/
bool8 DBFS_GetTableInfo(EN_DB_TABLE_TYPE enTable, u8 u8SubID, u8 *pu8BankID, u32 *pu32Address, u32 *pu32Length)
{
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return FALSE;
}
if(_bit_search_table(enTable, u8SubID, &stTableInfo) == FALSE)
{
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return FALSE;
}
*pu8BankID = stTableInfo.u8BankID;
*pu32Address = (u32)stTableInfo.u16Address;
*pu32Length = (u32)(stTableInfo.u8ItemSize * stTableInfo.u16NumOfItem);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return TRUE;
}
/*******************************************************************************************/
/* The receive function call it before database initialize, of course FMgr is not initial yet. */
bool8 DBFS_GetTableData(EN_DB_TABLE_TYPE enTable, u8 u8SubID, u8 *pu8buffer)
{
u8 u8BankIdx, u8DBBankID, u8BankID;
// Wait Semaphore
if (CT_OS_WaitOnSemaphore(&stDBFSSemaphore, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return FALSE;
}
if(_bit_search_table(enTable, u8SubID, &stTableInfo) == FALSE)
{
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return FALSE;
}
for(u8BankIdx = 0; u8BankIdx < DB_TOTAL_BANK; u8BankIdx++)
{
u8BankID = u8DVB_DBStartBank + DB_START_BANK_ID + u8BankIdx;
DVB_FlashRead(u8BankID, BANK_ID_ADDRESS, &u8DBBankID, 1);
if(u8DBBankID != stTableInfo.u8BankID)
{
continue;
}
DVB_FlashRead(u8BankID, stTableInfo.u16Address, pu8buffer,
stTableInfo.u8ItemSize * stTableInfo.u16NumOfItem);
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return TRUE;
}
// Free Semaphore
CT_OS_FreeSemaphore(&stDBFSSemaphore);
return FALSE;
}
// DBFS============================================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -