Page 1 of 1

Post queue by copy, not reference (aka xQueueSend in freertos)

Posted: Tue Nov 23, 2021 3:11 am
by zealott
Hi,

Any thoughts on the best way to provide a thread-safe way to mimic xQueueSend / xQueueReceive in FreeRTOS?
It copies the message itself, not just a reference as NB Queue functions.

Thanks

Re: Post queue by copy, not reference (aka xQueueSend in freertos)

Posted: Tue Nov 23, 2021 9:36 am
by pbreed
Use the fifo class, allocate a poolbuffer, copy the data into post to the fifo...
free it on the other end...


#include <buffers.h>
#include <nbrtos.h>

OS_FIFO TheFifo;

//Sending....
PoolPtr pp=GetBuffer();
if((pp) && (messag_len<ETHER_BUFFER_SIZE))
{
memcpy(pp->pData,message,message_len);
pp->usedsize=message_len;
TheFifo.Post(pp);
pp=0; //Make it null so it wont get freed
}
if (pp) FreeBuffeR(pp);


//Receiving:
PoolPtr pp=(PoolPtr) TheFifo.Pend();
if(pp)
{
int len=pp->usedsize;
//Copy out if you want.. or just use the buffer...
//Remember to free it when done
memcpy(destination,pp->pData,len);
FreeBuffer(pp);
}


Something like that...
This code was just typed in, it was not compiled ot tested, could have errors...

Re: Post queue by copy, not reference (aka xQueueSend in freertos)

Posted: Wed Nov 24, 2021 12:03 am
by zealott
Brilliant! thanks Paul