This is a follow up question to my post from yesterday. Free RTOS Version 8.2.1
The hardware receives data through an USB interface. After application begins the RTOS, this is the first memory buffer allotted:
m_ucUsbInputBufferTemp = (UINT8*)pvPortMalloc(ucNumMsgs*MAX_USB_MESSAGE_SIZE);
Soon after this memory is allotted, there are non-zero characters in the heap memory.
Here is where the garbage begins to appear inside pvPortMalloc:
if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
{
/* This block is to be split into two. Create a new
block following the number of bytes requested. The void
cast is used to prevent byte alignment warnings from the
compiler. */
pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
configASSERT( ( ( ( uint32_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 );
/* Calculate the sizes of two blocks split from the
single block. */
pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
**pxBlock->xBlockSize = xWantedSize;**
** /* Insert the new block into the list of free blocks. /*
** prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );**
}
I have highlighted in bold when the non-zero chars come in. The last 4 problem chars show up when stepping inside prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
Inside prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
more non-zero chars happen during:
if( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock )
{
if( pxIterator->pxNextFreeBlock != pxEnd )
{
/* Form one big block from the two blocks. /
pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize;
pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock;
}
else
** {*
** pxBlockToInsert->pxNextFreeBlock = pxEnd;**
** }**
}