/// Initialize Memory Pool with variable block size. /// \param[in] mem pointer to memory pool. /// \param[in] size size of a memory pool in bytes. /// \return 1 - success, 0 - failure. __WEAK uint32_t osRtxMemoryInit (void *mem, uint32_t size) { mem_head_t *head; mem_block_t *ptr; // Check parameters //lint -e{923} "cast from pointer to unsigned int" [MISRA Note 7] if ((mem == NULL) || (((uint32_t)mem & 7U) != 0U) || ((size & 7U) != 0U) || (size < (sizeof(mem_head_t) + (2U*sizeof(mem_block_t))))) { EvrRtxMemoryInit(mem, size, 0U); //lint -e{904} "Return statement before end of function" [MISRA Note 1] return 0U; } // Initialize memory pool header head = MemHeadPtr(mem); head->size = size; head->used = sizeof(mem_head_t) + sizeof(mem_block_t); // Initialize first and last block header ptr = MemBlockPtr(mem, sizeof(mem_head_t)); ptr->next = MemBlockPtr(mem, size - sizeof(mem_block_t)); ptr->next->next = NULL; ptr->next->info = sizeof(mem_head_t) + sizeof(mem_block_t); ptr->info = 0U; EvrRtxMemoryInit(mem, size, 1U); return 1U; }
/// Initialize Memory Pool with variable block size. /// \param[in] mem pointer to memory pool. /// \param[in] size size of a memory pool in bytes. /// \return 1 - success, 0 - failure. __WEAK uint32_t osRtxMemoryInit (void *mem, uint32_t size) { mem_head_t *head; mem_block_t *ptr; if ((mem == NULL) || ((uint32_t)mem & 7U) || (size & 7U) || (size < (sizeof(mem_head_t) + 2*sizeof(mem_block_t)))) { EvrRtxMemoryInit(mem, size, 0U); return 0U; } head = (mem_head_t *)mem; head->size = size; head->used = sizeof(mem_head_t) + sizeof(mem_block_t); ptr = (mem_block_t *)((uint32_t)mem + sizeof(mem_head_t)); ptr->next = (mem_block_t *)((uint32_t)mem + size - sizeof(mem_block_t)); ptr->next->next = NULL; ptr->info = 0U; EvrRtxMemoryInit(mem, size, 1U); return 1U; }