This commit is contained in:
pvvx 2017-03-03 20:16:46 +03:00
parent 5e40d9d461
commit 6278f73e47
20 changed files with 2557 additions and 2579 deletions

View file

@ -381,8 +381,7 @@ typedef struct HeapRegion
* terminated by a HeapRegions_t structure that has a size of 0. The region
* with the lowest start address must appear first in the array.
*/
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions );
static void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions );
/*
* Map to the memory management routines required for the port.

View file

@ -202,24 +202,22 @@ HeapRegion_t xHeapRegions[] =
#endif
/*-----------------------------------------------------------*/
#if 1
/*
Dump xBlock list
*/
void dump_mem_block_list()
void dump_mem_block_list(void)
{
if(pxEnd == NULL) vPortDefineHeapRegions( xHeapRegions );
#if CONFIG_DEBUG_LOG > 1
// if(pxEnd == NULL) vPortDefineHeapRegions( xHeapRegions ); // test code start
BlockLink_t *pxBlock = &xStart;
int count = 0;
DBG_8195A("RAM Heap Memory List:\n");
while(pxBlock->pxNextFreeBlock != NULL)
{
DBG_8195A(" [%d]=%p, %d\n", count++, pxBlock, pxBlock->xBlockSize);
pxBlock = pxBlock->pxNextFreeBlock;
DBG_8195A("RAM Free Heap Memory List:\n");
for(pxBlock = pxBlock->pxNextFreeBlock; pxBlock->pxNextFreeBlock != NULL; pxBlock = pxBlock->pxNextFreeBlock) {
DBG_8195A(" [%d]=%p, %d\n", ++count, pxBlock, pxBlock->xBlockSize);
}
}
#endif
}
void *pvPortMalloc( size_t xWantedSize )
{
@ -228,7 +226,6 @@ void *pvReturn = NULL;
/* Realtek test code start */
if(pxEnd == NULL) vPortDefineHeapRegions( xHeapRegions );
/* Realtek test code end */
/* The heap must be initialised before the first call to
@ -343,11 +340,14 @@ void *pvReturn = NULL;
{
mtCOVERAGE_TEST_MARKER();
}
traceMALLOC( pvReturn, xWantedSize );
}
( void ) xTaskResumeAll();
if(pvReturn == NULL) {
DBG_RAM_HEAP_WARN("ram_alloc(%d): freeSpace(%d)!\n", xWantedSize, xFreeBytesRemaining);
} else {
// DBG_RAM_HEAP_INFO("ram_alloc:%p[%d]\n", pvReturn , xWantedSize);
}
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
{
if( pvReturn == NULL )
@ -410,6 +410,7 @@ BlockLink_t *pxLink;
{
mtCOVERAGE_TEST_MARKER();
}
// DBG_RAM_HEAP_INFO("ram_free:%p[%d]\n", pv , pxLink->xBlockSize);
}
}
@ -511,7 +512,7 @@ uint8_t *puc;
}
/*-----------------------------------------------------------*/
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
static void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
{
BlockLink_t *pxFirstFreeBlockInRegion = NULL, *pxPreviousFreeBlock;
uint8_t *pucAlignedHeap;

View file

@ -3488,6 +3488,14 @@ TCB_t *pxTCB;
#endif /* portCRITICAL_NESTING_IN_TCB */
/*-----------------------------------------------------------*/
char * sprintf_pcTaskName(char * buf, char * name)
{
int len = sprintf(buf, name);
if(len < configMAX_TASK_NAME_LEN) {
memset(buf + len, ' ', configMAX_TASK_NAME_LEN - len);
}
return buf + configMAX_TASK_NAME_LEN;
}
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )
@ -3559,8 +3567,9 @@ TCB_t *pxTCB;
cStatus = 0x00;
break;
}
pcWriteBuffer = sprintf_pcTaskName( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName);
sprintf( pcWriteBuffer, "%s\t\t%c\t%u\t%u\t%u\r\n", pxTaskStatusArray[ x ].pcTaskName, cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );
sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );
pcWriteBuffer += strlen( pcWriteBuffer );
}
@ -3654,12 +3663,7 @@ TCB_t *pxTCB;
else
ulDeltaRunTimeCounter = portCONFIGURE_STATS_PEROID_VALUE*ulStatsAsPercentage/100;
#endif
int cnt = sprintf( pcWriteBuffer, "%s", pxTaskStatusArray[ x ].pcTaskName);
pcWriteBuffer += cnt;
while(cnt < configMAX_TASK_NAME_LEN) {
cnt++;
*pcWriteBuffer++ = ' ';
}
pcWriteBuffer = sprintf_pcTaskName( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName);
if( ulStatsAsPercentage > 0UL )
{
#ifdef portLU_PRINTF_SPECIFIER_REQUIRED

View file

@ -40,10 +40,10 @@ typedef struct Heap
void tcm_heap_init(void);
/// Allocate a chunk of memory of \a size bytes from the heap
void *tcm_heap_allocmem(int size);
// void *tcm_heap_allocmem(int size);
/// Free a chunk of memory of \a size bytes from the heap
void tcm_heap_freemem(void *mem, int size);
// void tcm_heap_freemem(void *mem, int size);
int tcm_heap_freeSpace(void);

View file

@ -24,7 +24,7 @@ __attribute__((section(".tcm.heap")))
HEAP_DEFINE_BUF(tcm_heap, TCM_HEAP_SIZE);
//unsigned char tcm_heap[TCM_HEAP_SIZE];
static int g_heap_inited=0;
static int g_heap_inited = 0;
static _lock tcm_lock;
extern void vPortSetExtFree( void (*free)( void *p ), uint32_t upper, uint32_t lower );
@ -55,28 +55,38 @@ void tcm_heap_init(void)
void tcm_heap_dump(void)
{
if(!g_heap_inited) tcm_heap_init();
#if CONFIG_DEBUG_LOG > 1
MemChunk *chunk, *prev;
struct Heap* h = &g_tcm_heap;
DBG_8195A("TCM Free List:\n");
int count = 0;
int free_mem;
DBG_8195A("TCM Free Heap Memory List:\n");
for (chunk = h->FreeList; chunk; chunk = chunk->next) {
DBG_8195A(" [%d]=%p, %d\n", ++count, chunk, chunk->size);
}
/*
for (prev = (MemChunk *)&h->FreeList, chunk = h->FreeList;
chunk;
prev = chunk, chunk = chunk->next)
{
DBG_8195A(" prev %x, chunk %x, size %d\n", prev, chunk, chunk->size);
DBG_8195A(" [%d]=%p, %d\n", ++count, chunk, chunk->size);
}
// DBG_8195A(" end %x\n", tcm_heap);
*/
#endif
}
void *tcm_heap_allocmem(int size)
static void *tcm_heap_allocmem(int size)
{
MemChunk *chunk, *prev;
struct Heap* h = &g_tcm_heap;
_irqL irqL;
DBG_TCM_INFO("allocmem(%d)\n", size);
rtw_enter_critical(&tcm_lock, &irqL);
if(!g_heap_inited) tcm_heap_init();
if(!g_heap_inited) tcm_heap_init();
/* Round size up to the allocation granularity */
size = ROUND_UP2(size, sizeof(MemChunk));
@ -98,46 +108,28 @@ void *tcm_heap_allocmem(int size)
{
/* Just remove this chunk from the free list */
prev->next = chunk->next;
#ifdef _DEBUG
memset(chunk, ALLOC_FILL_CODE, size);
#endif
rtw_exit_critical(&tcm_lock, &irqL);
//printf("----ALLOC1-----\n\r");
// tcm_heap_dump();
//printf("--------------\n\r");
return (void *)chunk;
}
else
{
/* Allocate from the END of an existing chunk */
chunk->size -= size;
#ifdef _DEBUG
memset((uint8_t *)chunk + chunk->size, ALLOC_FILL_CODE, size);
#endif
rtw_exit_critical(&tcm_lock, &irqL);
//printf("----ALLOC2-----\n\r");
// tcm_heap_dump();
//printf("--------------\n\r");
return (void *)((uint8_t *)chunk + chunk->size);
chunk = (MemChunk *)((uint8_t *)chunk + chunk->size);
}
#ifdef _DEBUG
memset(chunk, ALLOC_FILL_CODE, size);
#endif
rtw_exit_critical(&tcm_lock, &irqL);
DBG_TCM_HEAP_INFO("tcm_alloc:%p[%d]\n", chunk, size);
return (void *)chunk;
}
}
rtw_exit_critical(&tcm_lock, &irqL);
//printf("----ALLOC3-----\n\r");
DBG_TCM_WARN(ANSI_COLOR_MAGENTA "allocmem(%d): freeSpace(%d)!\n" ANSI_COLOR_RESET, size, tcm_heap_freeSpace());
// if (likely(ConfigDebugErr & _DBG_TCM_HEAP_)) {
// tcm_heap_dump();
// }
// tcm_heap_dump();
//printf("--------------\n\r");
DBG_TCM_HEAP_WARN("tcm_alloc(%d) - freeSpace(%d)!\n", size, tcm_heap_freeSpace());
return NULL; /* fail */
}
void tcm_heap_freemem(void *mem, int size)
static void tcm_heap_freemem(void *mem, int size)
{
MemChunk *prev;
//ASSERT(mem);
@ -146,7 +138,7 @@ void tcm_heap_freemem(void *mem, int size)
rtw_enter_critical(&tcm_lock, &irqL);
if(!g_heap_inited) tcm_heap_init();
// if(!g_heap_inited) tcm_heap_init();
#ifdef _DEBUG
memset(mem, FREE_FILL_CODE, size);
@ -216,10 +208,7 @@ void tcm_heap_freemem(void *mem, int size)
}
rtw_exit_critical(&tcm_lock, &irqL);
//printf("---FREE %x--\n\r", mem);
//tcm_heap_dump();
//printf("--------------\n\r");
DBG_TCM_HEAP_INFO("tcm_free:%p[%d]\n", mem, size);
}
int tcm_heap_freeSpace(void)
@ -293,7 +282,8 @@ void tcm_heap_free(void *mem)
}
}
#if 0
//----------- Tests -------------
static void alloc_test(int size, int test_len)
{
//Simple test
@ -352,5 +342,6 @@ int tcm_heap_testRun(void)
return 0;
}
#endif // tests
#endif