Memory pools 3.0
Posted: Wed Oct 22, 2014 1:27 am
Hi,
I'm trying to get the mem pool working on 3.0, but I must be missing something
Here's my code
chPoolAllocI always returns NULL.
I'm trying to get the mem pool working on 3.0, but I must be missing something
Here's my code
Code: Select all
typedef struct {
void* location;
size_t size;
} samples_message_t __attribute__ ((aligned (sizeof(stkalign_t))));
MEMORYPOOL_DECL(samples_pool, sizeof(samples_message_t), NULL);
void setupIPC(void)
{
chPoolObjectInit(&samples_pool, sizeof(samples_message_t), NULL);
chMBObjectInit(&knockMb, buf1, sizeof(buf1)/sizeof(msg_t));
chMBObjectInit(&sensorsMb, buf2, sizeof(buf2)/sizeof(msg_t));
}
void allocSendSamplesI(mailbox_t* mb, void * buffer, size_t size)
{
samples_message_t* info = chPoolAllocI(&samples_pool);
if (info == NULL) return;
info->location = buffer;
info->size = size;
chMBPostI(mb, (msg_t)info);
}
bool recvFreeSamples(mailbox_t* mb, void ** buffer, size_t * size)
{
msg_t msg;
samples_message_t data;
if(chMBFetch(mb, &msg, TIME_IMMEDIATE) != MSG_OK)
return false;
if ((samples_message_t*)msg == NULL) return false;
data = *(samples_message_t*)msg;
chPoolFree(&samples_pool, (void*)msg);
if (data.location == NULL) return false;
*buffer = data.location;
*size = data.size;
return true;
}
chPoolAllocI always returns NULL.