I want to send a mail item from Thread X to Thread Y. In that mail I want either Thread X or Thread Z's address, so that Thread Y knows where to send responses/data back to.
I wanted to include Thread X's or Z's osMailIdQ inside of the structure I'm mailing over to Thread Y. That way, when mail comes in, I can just use the rsvp address to send responses back to if needed.
This causes a hard fault.
typedef struct { uint16_t id[10]; uint8_t len; osMailQId target_address; }mailStruct; ... mail = (mailStruct*)osMailAlloc(ThreadY_request_mbox, osWaitForever); bundle->id[0]=1; bundle->id[1]=4; bundle->id[2]=2; bundle->len=3; bundle->target_address = ThreadX_data_mbox; //causes hard fault osMailPut(ThreadY_request_mbox, bundle);
I'm not sure why it's causing a fault. Maybe for the same reason that the debugger always shows 0x0000000 for the mail box id? Maybe because in some parts of the OS like create thread osMailIdQ is a const? Precompiler stuff?
I have no idea. But I'd like to be able to get mail in from a thread and be able to dynamically know where to send it back to without having to use a switch of MailPut(X) MailPut(Y), MailPut(Z), etc.
Anyone?
I'm curious here.
You allocate an object that you typecast as type mailStruct* and assigns to a pointer named "mail".
Then you suddenly starts to assign values using a pointer "bundle"? Shouldn't you use your pointer "mail"?
Next thing - where is your code that makes sure that your osMailAlloc() actually allocates a struct that is (at least) the size of a mailStruct?
IF osMailAlloc() allocates a too small struct, then your initial assigns to id[0], id[1], ... may succeed while the assign to target_address will be outside of the allocated struct.
Oh nm. Really messed up things happen when you forget to osMailCreate() for all mailboxes.
It should have been obvious that they debugged as 0x0000000, that they were never initialized. Oddly enough ->id[0]=1; didn't cause an error.
Yea, I was reaming from what I have in code to be clearer for forums, forgot to hit them all.
The best bugs are the quickly found :)