/* Allocates the desired number of bytes on the heap. It can be used instead of the compiler specific malloc() function. Note that free-ing of allocated memory is not supported to prevent memory fragmentation.  */
void* TbxHeapAllocate(size_t size)
/* Allocates the desired number of bytes on the heap. It can be used instead of the compiler specific malloc() function. Note that free-ing of allocated memory is not supported to prevent memory fragmentation.  */
void* TbxHeapAllocate(size_t size)
{
  static uint8_t   tbxHeapBuffer[TBX_CONF_HEAP_SIZE];
  void           * result = NULL;
  TBX_ASSERT(size > 0U);
  if (size > 0U)
  {
    size_t sizeWanted = (size + (sizeof(void *) - 1U)) & ~(sizeof(void *) - 1U);
    TbxCriticalSectionEnter();
    size_t sizeAvailable = TBX_CONF_HEAP_SIZE - tbxHeapAllocated;
    if (sizeAvailable >= sizeWanted)
    {
      result = &tbxHeapBuffer[tbxHeapAllocated];
      tbxHeapAllocated += sizeWanted;
    }
    TbxCriticalSectionExit();
  }
  return result;
}