📄 dvb_mem.c
字号:
MAX_MEMORY_ALLOCATE = u32aMaxMemoryAllocate[mem_type];
if (CT_OS_WaitOnSemaphore(&semDVB_MEM, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
memset (u8Name, 0x00, sizeof (u8Name));
switch (mem_type)
{
case EIT_MEMPOOL_TYPE:
strcpy (u8Name, "EIT Pool");
break;
case BIG_MEMPOOL_TYPE:
strcpy (u8Name, "BIG Pool");
break;
case GEN_MEMPOOL_TYPE:
strcpy (u8Name, "GEN Pool");
break;
default:
strcpy (u8Name, "Def Pool");
break;
}
MEM_DBG(("\n[%d] %s Start Addrss[0x%x]\n", mem_type, u8Name, (int)pu8BufferPool));
for ( i=0; i<MAX_MEMORY_ALLOCATE;i++)
{
u32AllocGroup = i/MAX_NUM_IN_A_GROUP;
u32AllocBitNo = i%MAX_NUM_IN_A_GROUP;
if (au32Used[u32AllocGroup]&au32UsedMask[u32AllocBitNo])
// if ( au32Used[i]==TRUE )
{
u32UsedCount ++;
u32UsedMem += au32Length[i];
if (au32Length[i] > u32MaxUsedSize)
{
u32MaxUsedSize = au32Length[i];
}
}
else
//if (au32Length[i] == 0)
{
if (au32Length[i] > u32MaxFreeSize)
{
u32MaxFreeSize = au32Length[i];
}
u32NoUsedCount ++;
}
}
MEM_DBG(("Total[0x%08x] Used[0x%08x] Free[0x%08x] M_Used[0x%08x] M_Free[0x%08x] No:MAX[%ld] Used[%d] Free[%d]\n",
(unsigned int)u32BufferSize, (unsigned int)u32UsedMem, (unsigned int)(u32BufferSize-u32UsedMem),
(unsigned int)u32MaxUsedSize, (unsigned int)u32MaxFreeSize,
MAX_MEMORY_ALLOCATE, (unsigned int)u32UsedCount, (unsigned int)u32NoUsedCount));
MEM_DBG(("\n"));
CT_OS_FreeSemaphore(&semDVB_MEM);
}
#endif /* end #if (!defined (CT_OS_MEM_ENABLE) || defined (DRAM_FRAME_DIGEST_BUFFER_USED)) */
#ifdef CT_OS_MEM_ENABLE
void os_mem_printinfo (EN_MEMPOOL_TYPE mem_type)
{
u8 pool_name[CTOS_MAX_NAME];
void * start_address;
u32 pool_size;
u32 u32available;
u32 tasks_suspended;
EN_CTOS_STATUS enStatus = EN_CTOS_SUCCESS;
CTOS_MEM_POOL *pstMemPool = NULL;
if (b8MemInialized != TRUE)
{
return;
}
if (mem_type >= MAX_MEMPOOL_TYPE)
{
return;
}
if (CT_OS_WaitOnSemaphore(&semDVB_MEM, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
MEM_MSG(("{os_mem_printinfo} wait semaphore fail\n"));
return;
}
if (!ab8Initialized [mem_type])
{
CT_OS_FreeSemaphore (&semDVB_MEM);
return;
}
pstMemPool = apstMemPool[mem_type]; /* pool structure */
if (!pstMemPool)
{
CT_OS_FreeSemaphore (&semDVB_MEM);
return;
}
memset (pool_name, 0x00, CTOS_MAX_NAME);
enStatus = CT_OS_GetMemPoolStatus (pstMemPool, pool_name, &start_address,
&pool_size, &u32available, &tasks_suspended);
if (enStatus != EN_CTOS_SUCCESS)
{
MEM_MSG(("{DVB_MEM_PrintInfo} Get stFiltMemoryPool information fail\n"));
CT_OS_FreeSemaphore (&semDVB_MEM);
return;
}
else
{
MEM_MSG(("name[%s] add[0x%x] size[0x%x] avail[0x%x] task[%d]\n",
(char*) pool_name, (int)start_address, (int)pool_size, (int)u32available, (int)tasks_suspended));
}
CT_OS_FreeSemaphore (&semDVB_MEM);
return;
}
#endif
bool8 DVB_MEM_DigestPool_Set (bool8 b8Used)
{
/*
if b8Used = TRUE =>
this Digest buffer is used by memory pool and now is not in Digest Mode
if b8Used = FALSE =>
this Digest buffer is not used by memory pool and is uded by JPU
*/
#if (defined (ADD_BIG_POOL) && defined (DRAM_FRAME_DIGEST_BUFFER_USED) && defined (CT_OS_MEM_ENABLE))
bool8 b8Result = FALSE;
EN_MEMPOOL_TYPE mem_type = BIG_MEMPOOL_TYPE;
if (CT_OS_WaitOnSemaphore(&semDVB_MEM, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
MEM_MSG(("{DVB_MEM_DigestPool_Set} wait semaphore fail\n"));
return FALSE;
}
if (b8Used == TRUE)
{
if (ab8Initialized [mem_type])
{
/* already in used */
CT_OS_FreeSemaphore(&semDVB_MEM);
return FALSE;
}
else
{
b8Result = memory_pool_create (mem_type, au8BIGPool,
DRAM_FRAME_DIGEST_BUFFER_SIZE);
if (b8Result)
{
CT_OS_FreeSemaphore(&semDVB_MEM);
return TRUE;
}
else
{
/* create fail */
CT_OS_FreeSemaphore(&semDVB_MEM);
return FALSE;
}
}
}
else
{
/* now is in digest mode and need to delete the big pool */
b8Result = os_mem_pool_delete (mem_type);
CT_OS_FreeSemaphore(&semDVB_MEM);
return b8Result;
}
#else
/* do nothing */
return TRUE;
#endif
}
void DVB_MEM_PrintInfo (EN_MEMPOOL_TYPE mem_type)
{
#ifdef CT_OS_MEM_ENABLE
if (mem_type == BIG_MEMPOOL_TYPE)
{
#if 0 //#ifdef DRAM_FRAME_DIGEST_BUFFER_USED
return (ctk_mem_printinfo (mem_type));
#else
return (os_mem_printinfo (mem_type));
#endif
}
else
{
return (os_mem_printinfo (mem_type));
}
#else
return (ctk_mem_printinfo (mem_type));
#endif /* end #ifdef CT_OS_MEM_ENABLE */
}
#if (!defined (CT_OS_MEM_ENABLE) || defined (DRAM_FRAME_DIGEST_BUFFER_USED))
void ctk_mem_printusedinfo (EN_MEMPOOL_TYPE mem_type)
{
u32 i =0 ;
u8 u8Name[10];
u32 u32UsedMem = 0;
u32 u32UsedCount = 0;
u32 *au32Start = NULL;
u32 *au32Length = NULL;
u32 *au32Used = NULL;
u8 *pu8BufferPool = NULL;
u32 u32BufferSize = 0;
u32 MAX_MEMORY_ALLOCATE = 0;
u32 u32AllocGroup = 0, u32AllocBitNo = 0;
if (mem_type >= MAX_MEMPOOL_TYPE)
{
return;
}
if (CT_OS_WaitOnSemaphore(&semDVB_MEM, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
return;
}
au32Start = pau32Start[mem_type];
au32Length = pau32Length[mem_type];
au32Used = pau32Used[mem_type];
pu8BufferPool = pau8BufferPool[mem_type];
u32BufferSize = au32BufferSize[mem_type];
MAX_MEMORY_ALLOCATE = u32aMaxMemoryAllocate[mem_type];
memset (u8Name, 0x00, sizeof (u8Name));
switch (mem_type)
{
case EIT_MEMPOOL_TYPE:
strcpy (u8Name, "EIT Pool");
break;
case BIG_MEMPOOL_TYPE:
strcpy (u8Name, "BIG Pool");
break;
case GEN_MEMPOOL_TYPE:
strcpy (u8Name, "GEN Pool");
break;
default:
strcpy (u8Name, "Def Pool");
break;
}
MEM_DBG(("mem_type[%d] u16Biggest[%d]\n", mem_type, u16Biggest[mem_type]));
#ifdef DEBUG_MSG
MEM_DBG((" # Start End Length Gen Status\n"));
for (i = 0; i < u16Biggest[mem_type] + 1; i++)
// for (i = 0; i < MAX_MEMORY_ALLOCATE; i++)
#else
MEM_DBG((" # Start End Length Status\n"));
// for (i=0; i<MAX_MEMORY_ALLOCATE;i++)
for (i=0; i<u16Biggest[mem_type] + 1; i++)
#endif /* end #ifdef DEBUG_MSG */
{
#ifdef DEBUG_MSG
MEM_DBG(("%03x 0x%08X 0x%08X %10d %4d ",
i, (int)(au32Start[i] + pau8BufferPool[mem_type]), (int)(au32Start[i]+ pau8BufferPool[mem_type] + au32Length[i]),
(int)au32Length[i], (int)u16adebug [i]));
#else
MEM_DBG(("%03x 0x%08X 0x%08X %10ld ",
(int)i, (unsigned int)(au32Start[i] + pau8BufferPool[mem_type]), (unsigned int)(au32Start[i] + pau8BufferPool[mem_type] + au32Length[i]),
au32Length[i]));
#endif /* end #ifdef DEBUG_MSG */
u32AllocGroup = i/MAX_NUM_IN_A_GROUP;
u32AllocBitNo = i%MAX_NUM_IN_A_GROUP;
// if ( ab8Used[i]==TRUE )
if (au32Used[u32AllocGroup]&au32UsedMask[u32AllocBitNo])
{
u32UsedCount ++;
u32UsedMem += au32Length[i];
MEM_DBG(("Used\n"));
}
else
{
MEM_DBG(("Free\n"));
}
}
MEM_DBG(("Total[0x%08x] Used[0x%08x] Free[0x%08x] No:Max[%d] Used[%d]\n",
(unsigned int)u32BufferSize, (unsigned int)u32UsedMem, (unsigned int)(u32BufferSize-u32UsedMem),
(int)MAX_MEMORY_ALLOCATE, (unsigned int)u32UsedCount));
MEM_DBG(("\n"));
{
u32 j = 0;
u32 u32AllocGroup = 0, u32AllocBitNo = 0;
u32AllocGroup = i/MAX_NUM_IN_A_GROUP;
u32AllocBitNo = i%MAX_NUM_IN_A_GROUP;
for (j = 0; j < u32AllocGroup; j ++)
{
MEM_DBG(("[%ld][0x%04x]\n", j, (unsigned int)(au32Used[j])));
}
}
CT_OS_FreeSemaphore(&semDVB_MEM);
}
#endif /* end #if (!defined (CT_OS_MEM_ENABLE) || defined (DRAM_FRAME_DIGEST_BUFFER_USED)) */
#ifdef CT_OS_MEM_ENABLE
void os_mem_printusedinfo (EN_MEMPOOL_TYPE mem_type)
{
#ifdef DEBUG_MSG
u32 i =0 ;
#endif /* end #ifdef DEBUG_MSG */
u8 pool_name[CTOS_MAX_NAME];
void * start_address;
u32 pool_size;
u32 u32available;
u32 tasks_suspended;
CT_STATUS enStatus = EN_CTOS_SUCCESS;
CTOS_MEM_POOL *pstMemPool = NULL;
if (b8MemInialized != TRUE)
{
return;
}
if (mem_type >= MAX_MEMPOOL_TYPE)
{
return;
}
if (CT_OS_WaitOnSemaphore(&semDVB_MEM, CTOS_WAIT)!= EN_CTOS_SUCCESS)
{
MEM_MSG(("{DVB_MEM_PrintUsedInfo} wait semaphore fail\n"));
return;
}
if (!ab8Initialized [mem_type])
{
CT_OS_FreeSemaphore(&semDVB_MEM);
return;
}
pstMemPool = apstMemPool[mem_type]; /* pool structure */
if (!pstMemPool)
{
CT_OS_FreeSemaphore(&semDVB_MEM);
return;
}
memset (pool_name, 0x00, CTOS_MAX_NAME);
enStatus = CT_OS_GetMemPoolStatus (pstMemPool, pool_name, &start_address,
&pool_size, &u32available, &tasks_suspended);
if (enStatus != EN_CTOS_SUCCESS)
{
MEM_MSG(("{DVB_MEM_PrintUsedInfo} Get stFiltMemoryPool information fail\n"));
CT_OS_FreeSemaphore(&semDVB_MEM);
return;
}
else
{
MEM_DBG(("name[%s] add[0x%x] size[0x%x] avail[0x%x] task[%d]\n",
(char*) pool_name, (int)start_address, (int)pool_size, (int)u32available, (int)tasks_suspended));
}
#ifdef DEBUG_MSG
if (mem_type == gDebugPoolType)
{
MEM_DBG((" # Where\n"));
for (i = 0; i < u16Biggest[mem_type] + 1; i++)
{
MEM_DBG(("[%5d][%4d]\n", (int)i, (int)u16adebug[i]));
}
}
#endif
CT_OS_FreeSemaphore(&semDVB_MEM);
return;
}
#endif
void DVB_MEM_PrintUsedInfo (EN_MEMPOOL_TYPE mem_type)
{
#ifdef CT_OS_MEM_ENABLE
if (mem_type == BIG_MEMPOOL_TYPE)
{
#if 0 //#ifdef DRAM_FRAME_DIGEST_BUFFER_USED
return (ctk_mem_printusedinfo (mem_type));
#else
return (os_mem_printusedinfo (mem_type));
#endif
}
else
{
return (os_mem_printusedinfo (mem_type));
}
#else
return (ctk_mem_printusedinfo (mem_type));
#endif /* end #ifdef CT_OS_MEM_ENABLE */
}
/*******************************************************************************************/
void DVB_MEM_PoolInfo(void)
{
u8 i = 0;
for (i = 0; i < MAX_MEMPOOL_TYPE; i ++)
{
DVB_MEM_PrintInfo (i);
}
}
void DVB_MEM_EITPoolDebug (void)
{
#ifndef DEBUG_EIT
return;
#else
u16 i = 0;
for (i = 0; i < GEN_MAX_MEMORY_ALLOCATE; i ++)
{
MEM_DBG(("[%d] [0x%x]\n", i, u16aEventID[i]));
}
#endif /* end #ifndef DEBUG_EIT */
}
/*******************************************************************************************/
void DVB_MEM_Dump(u32 u32address, u32 u32length)
{
u32 u32PageCount;
u32 u32ByteCount;
u32 u32PageStartAddr;
u32 u32PageEndAddr;
u32 u32CharStartAddr;
u32 u32CharEndAddr;
u32 u32CurrentAddr;
if (u32length==0)
{
u32length = 0x40;
}
u32CharStartAddr = u32address ;
u32PageStartAddr = u32CharStartAddr & 0xFFFFFFF0L ;
u32CharEndAddr = u32CharStartAddr + u32length ;
u32PageEndAddr = (u32CharEndAddr + 15)&0xFFFFFFF0L ;
u32CurrentAddr = u32PageStartAddr;
MEM_MSG(("\n"));
for(u32PageCount=u32PageStartAddr; u32PageCount<u32PageEndAddr; u32PageCount=u32PageCount+16)
{
MEM_MSG(("%08lX : ",u32PageCount ));
for(u32ByteCount=0;u32ByteCount<16;u32ByteCount++)
{
if( (u32CurrentAddr < u32CharStartAddr) || (u32CharEndAddr <=u32CurrentAddr) )
{
MEM_MSG((" "));
}
else
{
MEM_MSG(("%02X ", *((u8 *)u32CurrentAddr) ));
}
u32CurrentAddr++ ;
}
MEM_MSG(("| "));
u32CurrentAddr -= 16 ;
for(u32ByteCount=0;u32ByteCount<16;u32ByteCount++)
{
if( (u32CurrentAddr < u32CharStartAddr) || (u32CharEndAddr <=u32CurrentAddr) )
{
MEM_MSG((" "));
}
else
{
if( (32 <= *((u8 *)u32CurrentAddr)) && ((*((u8 *)u32CurrentAddr)) <= 126) )
{
MEM_MSG(("%c",*((u8 *)u32CurrentAddr) ));
}
else
{
MEM_MSG(("."));
}
}
u32CurrentAddr++ ;
}
MEM_MSG(("\n"));
}
MEM_MSG(("\n"));
}
/*******************************************************************************************/
void DVB_MEM_Write(u32 u32address, u32 u32Value)
{
u32* pu32Addr = NULL;
MEM_MSG(("\n [%08lX] : ", u32address));
if ((u32address&0x03)!=0)
{
MEM_MSG(("Address Fail\n"));
return;
}
pu32Addr = (u32*)u32address;
*pu32Addr = u32Value;
MEM_MSG(("%08lX\n", *pu32Addr));
}
/*******************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -