Returning a Memory Block to a Partition
The application code must return an allocated memory block back to the proper partition when finished. You do this by calling OSMemPut() as shown in the listing below. The code assumes that the partition was already created.
Returning a Memory Block to a Partition
OS_MEM MyPartition; (1)
CPU_INT08U *MyDataBlkPtr;
void MyTask (void *p_arg)
{
OS_ERR err;
:
while (DEF_ON) {
:
OSMemPut((OS_MEM *)&MyPartition, (2)
(void *)MyDataBlkPtr, (3)
(OS_ERR *)&err);
if (err == OS_ERR_NONE) { (4)
/* You properly returned the memory block to the partition */
}
:
:
}
}(1) The memory partition control block must be accessible by all tasks or ISRs that will be using the partition.
(2) You simply call OSMemPut() to return the memory block back to the memory partition. Note that there is no check to see whether the proper memory block is being returned to the proper partition (assuming you have multiple different partitions). It is therefore important to be careful (as is necessary when designing embedded systems).
(3) You pass the pointer to the data area that is allocated so that it can be returned to the pool. Note that a “void *” is assumed.
(4) You would examine the returned error code to ensure that the call was successful.