Still having trouble with my own incompetence.
So I want to pass data from one thread to another. There for I have declared a Mailbox and initialized it.
Code: Select all
/*
* Initialize Mailbox
*/
mailbox_t Output_Queue;
msg_t Output_buf[128];
chMBObjectInit(&(Output_Queue), Output_buf, 128);
The data is stored in a stuct, which i allocate from a MemPool. The MemPool should also be correct initialized:
Code: Select all
memory_pool_t Output_Msg_Pool;
OutputMessage* Pool_Buffer[128] __attribute__((aligned(sizeof(stkalign_t))));
/*
* Initialize Memory Pool for Output-Message Objects and add all Buffer-Elements
* to the Memory Pool
*/
chPoolObjectInit(&(Output_Msg_Pool), sizeof(OutputMessage), NULL);
for(i = 0; i < 128; i++)
chPoolFree(&(Output_Msg_Pool), &(Pool_Buffer[i]));
The struct now is passed as Pointer through the Mailbox to the receiving thread:
Code: Select all
OutputMessage *om;
om = (OutputMessage*)chPoolAlloc(&(Output_Msg_Pool));
//Initialize Data.
chMBPost(&(VCOM.Output_Queue), (msg_t)om, TIME_IMMEDIATE);
However, when I now want to get the Pointer out, I dont get the right Value....
Code: Select all
OutputMessage *current;
chMBFetch(&(Output_Queue), (msg_t*)current, TIME_IMMEDIATE);
The value of *current isn't the right address of the struct, which I wanted to pass.
I'm pretty sure that the mechanism should work this way somehow, but I'm apparently not bright enough to figure out by myself, how to correctly pass this struct.
Does anyone know what I'm doing wrong?
I've already tried different ways of retrieving the Mailbox-Payload:
Code: Select all
OutputMessage current;
chMBFetch(&(VCOM.Output_Queue), (msg_t*)¤t, TIME_IMMEDIATE);
doesn't work either.
I hope someone can help me with this.
All answers are appreciated.
Methanbombe