1

I have an issue using Keil rtx message queue. I have two following threads: send_thread and receive_thread.

Pseudo code:

send_thread
{
int16_t array1[20];
int16_t array2[20];
int16_t array3[20];

int16_t *common_array[3]

common_array[0] = array1;
common_array[1] = array2;
common_array[2] = array3;

osMessagePut(MsgBox, (uint32_t)common_array, osWaitForever);
}

receive_thread
{
int16_t receive_array1[20];
int16_t receive_array2[20];
int16_t receive_array3[20];

int16_t *receive_common_array[3]

MsgBox_status = osMessageGet(MsgBox, osWaitForever);

//now here I want to copy all arrays from send_thread to received_arrays.

receive_common_array = MsgBox_status.value.p;  //here I should copy the received adress to a new pointer, but I have received just void* variable, so I can't assign like that

memmove(receive_array1, receive_common_array[0], 20);
memmove(receive_array2, receive_common_array[1], 20);
memmove(receive_array3, receive_common_array[2], 20);

}

So the question is what is wrong or how I should implement it? I have debuged the adresses, I get the same one. The difference is that in send_thread the sending variable is pointer to array of pointers, but in receive_thread there is only void* and I can't access any value in that.

Any suggestions are welcome.

MantasD
  • 11
  • 3
  • Are you getting a compiler error? Or a run-time error? Maybe you just need to cast the void * like `receive_common_array = (int16_t **)MsgBox_status.value.p` – kkrambo Mar 06 '16 at 02:07
  • Read the description of the Mail Queue and how it differs from the Message Queue. The Message Queue passes a copy of the item whereas the Mail Queue passes a pointer to the item. In your implementation it seems like you are passing a copy of the pointer so that you can use that pointer to make a copy of the original item. This defeats the purpose of using a Message Queue because the original item must be kept around until the copy is made by the receiver. Use a Mail Queue if you want to pass a pointer. Or pass a copy of all 60 bytes if you want to use a Message Queue. – kkrambo Mar 06 '16 at 02:21
  • I have tried to us Mail Queue, but the situations remain the same. If I am trying to assign receive_common_array = MsgBox_status.value.p I get the error as: "array type int16_t *[3] is not assignable". Also tried to fix this with casting, but without any luck. – MantasD Mar 06 '16 at 09:05
  • Why pseudo-code? If you are having a problem with *real code* that is what you should post. `array type int16_t *[3] is not assignable` should appear in your question *not* a comment after thought. We cannot reasonably reference information in a temorary comment in an answer, and it is in any case important *diagnostic information* you chose to omit. – Clifford Mar 06 '16 at 11:24
  • The error is nonetheless nothing to do with RTX or message queues - it is a simple C syntax error; you cannot *assign* an array - it is not a first class data type. You must use `memcpy()` for example. – Clifford Mar 06 '16 at 11:30

0 Answers0