Application code can request a memory block from a partition by calling OSMemGet()
as shown in Listing 17-3. The the listing below. The code assumes that the partition was already created.
Listing 17-3 Obtaining a memory block from a partition
L17-3(1) The
Code Block | ||
---|---|---|
| ||
OS_MEM MyPartition; (1)
CPU_INT08U *MyDataBlkPtr;
void MyTask (void *p_arg)
{
OS_ERR err;
:
while (DEF_ON) {
:
MyDataBlkPtr = (CPU_INT08U *)OSMemGet((OS_MEM *)&MyPartition, (2)
(OS_ERR *)&err);
if (err == OS_ERR_NONE) { (3)
/* You have a memory block from the partition */
}
:
:
}
} |
Panel | ||
---|---|---|
| ||
(1) The memory partition control block must be accessible by all tasks or ISRs that will be using the partition. |
...
(2) |
...
Simply call |
...
to obtain a memory block from the desired partition. A pointer to the allocated memory block is returned. This is similar |
...
to |
...
(3) |
...
It is important to examine the returned error code to ensure that there are free memory blocks and that the application can start putting content in the memory blocks. |