Issue with mailboxes and pointers
Posted: Tue Nov 10, 2015 8:02 pm
Hallo everyone,
I have a pretty stupid question, but unfortunately I now have a big knot of pointers in my head and can not figure the answer out. Maybe you can help me before I spend even more time on this stupid problem.
So the situation is this: I want to use a mailbox to communicate between a console command and a worker thread, where the user via console creates a number of tests and the thread asynchronously executes one by one. The tests are defined as structs containing a few floats and the messages in the mailbox are then pointers to these structs. Thats the idea, but I found the whole thing does not work (the received pointer contains nonsense), so I must have messed up some pointing somewhere. I think the issue might be with the init, what kind of buffer structure does that command need?
The code looks like this:
Definitions:
Init after system init:
Console command posting a message:
Worker thread getting a message and looking at its content:
Thanks in advance,
Thomas
I have a pretty stupid question, but unfortunately I now have a big knot of pointers in my head and can not figure the answer out. Maybe you can help me before I spend even more time on this stupid problem.
So the situation is this: I want to use a mailbox to communicate between a console command and a worker thread, where the user via console creates a number of tests and the thread asynchronously executes one by one. The tests are defined as structs containing a few floats and the messages in the mailbox are then pointers to these structs. Thats the idea, but I found the whole thing does not work (the received pointer contains nonsense), so I must have messed up some pointing somewhere. I think the issue might be with the init, what kind of buffer structure does that command need?
The code looks like this:
Definitions:
Code: Select all
typedef struct
{
float test_voltage;
float test_current;
float first_pulse_length;
uint8_t charging_voltage;
}test_data_t;
#define MAX_SEQUENTIAL_TESTS 1024
mailbox_t test_mailbox;
test_data_t test_data[MAX_SEQUENTIAL_TESTS];Init after system init:
Code: Select all
chMBObjectInit(&test_mailbox, (msg_t*)&test_data, MAX_SEQUENTIAL_TESTS);Console command posting a message:
Code: Select all
MB_status = chMBPost(&test_mailbox, (msg_t)&new_test_data, TIME_IMMEDIATE); // put new test data into the mailboxWorker thread getting a message and looking at its content:
Code: Select all
chMBFetch(&test_mailbox, &struct_pointer, TIME_INFINITE); // try to get a message containing a new test config, waits until one is available
running_test = *(test_data_t*)struct_pointer;Thanks in advance,
Thomas