CooCox CoOS User's Guide
CooCox CoOS User's Guide
CooCox CoOS User's Guide
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
6.5.5 CoGetMemoryBuffer()<br />
Function Prototype:<br />
void* CoGetMemoryBuffer<br />
(<br />
OS_MMID mmID<br />
);<br />
Description:<br />
Obtain a memory block from a certain memory partition.<br />
Parameters:<br />
[IN] mmID<br />
The ID of the memory partition<br />
Returns:<br />
NULL, Failed to allocate.<br />
Others, Allocate successfully and return the initial address pointer of the<br />
memory block.<br />
Example usage:<br />
#include "CCRTOS.h"<br />
OS_MMID mmc;<br />
void TaskN (void *pdata)<br />
{<br />
int *ptr;<br />
...<br />
/* Get a memory block from memory partition */<br />
/* mmc: Created by other task */<br />
ptr = (int* )CoGetMemoryBuffer(mmc);<br />
if (ptr == NULL)<br />
{<br />
printf("Assign buffer fail !\n");<br />
}<br />
else<br />
{<br />
...<br />
/* Process assigned buffer here */<br />
...<br />
/* Free assigned buffer to memory partition */<br />
CoFreeMemoryBuffer(mmc, (void* )ptr);<br />
}<br />
...<br />
}<br />
Note:<br />
None<br />
73