Hi. I'm trying to send a message using RTX51, where the message is a pointer to a struct. I'm having trouble with type conversions, and the pointer never comes out correctly on the other side.
This is what i'd like to do:
//TASK1 SOME_STRUCT xdata myStruct; os_send_message(MBX_NUM, &myStruct, 255); ... //TASK2 SOME_STRUCT xdata * pStruct; os_wait(K_MBX+MBX_NUM, 255, pStruct); ...
Of course, this gives me all sorts of type conversion errors. To fix this, i've tried casting the variables going into and coming from the message functions. It gets rid of the type conversion errors, but still doesn't work correctly.
//TASK1 SOME_STRUCT xdata myStruct; os_send_message(MBX_NUM, (int)&myStruct, 255); ... //TASK2 SOME_STRUCT xdata * pStruct; os_wait(K_MBX+MBX_NUM, 255, (word xdata*)pStruct); ...
Does anybody know how I can correctly cast the arguments to make this work? Any other suggestions?
Got it working now. The send_message function needed to be cast as unsigned. It wasn't necessary to use the (U8 xdata*) cast, although that's probably just my specific situation. Good to know anyway for future reference.
Also, the os_wait function was passing back a pointer, which i neglected to dereference. The simple fix was to get the pointer, and then cast the actual dereferenced pointer into the desired struct pointer:
//TASK1 SOME_STRUCT xdata myStruct; os_send_message(MBX_NUM, (unsigned int)&myStruct, 255); ... //TASK2 SOME_STRUCT xdata * pStruct; unsigned int xdata * pTemp; os_wait(K_MBX+MBX_NUM, 255, pTemp); pStruct = (SOME_STRUCT xdata*)(*pTemp); ...
Thanks for the tips.