Passing a structure of data over the FreeRTOS queue issue
Posted: Fri Oct 22, 2021 9:29 am
Hello. I would like to ask 2 questions regarding the FreeRTOS queues:
1. Is it possible to pass an array of uint8_t values ?
I have tried the following:
And in my BLE_parser_task:
I pass the data to the queue:
I dont think I can extract the data in my ble_parser_task , when I try to print the first element of array, the CPU crashes and restart. Can someone give me an idea what is happening?
2. I have tried a different approch and I pass the structure of the data to the queue which contains my uint8_t* data and data length.
The problem is, inside my ble_parser_task, I am not able to read back the array information. I think I have an idea of what might be happening - the stack memory is cleared.
Inside the ble_parser_task, I am reading completely different information that I pass (I cannot read 1,2,3,4,5). I only know 1 possible solution - declare the data_to_send2 as global. This ensures that the stack memory will not get cleared. But I do not think this is the most approriate solution, can someone suggest me alternative ways?
1. Is it possible to pass an array of uint8_t values ?
I have tried the following:
Code: Select all
ble_parser_queue = xQueueCreate(10, sizeof(uint8_t*));
xTaskCreate(BLE_parser_task,"BLE_parser_task",10000,NULL,1,NULL);
Code: Select all
static void BLE_parser_task(void *argument)
{
uint8_t* data_received;
for(;;)
{
if (xQueueReceive(ble_parser_queue, &data_received, 0) == pdTRUE) {
printf("data_received[0] = %u\n",data_received[0]);
}
else{
printf("no data received yet \n");
}
vTaskDelay(1000/portTICK_RATE_MS);
}
}
Code: Select all
uint8_t test_data[5] = {1,2,3,4,5};
xQueueSend(ble_parser_queue, &test_data, 10);
2. I have tried a different approch and I pass the structure of the data to the queue which contains my uint8_t* data and data length.
The problem is, inside my ble_parser_task, I am not able to read back the array information. I think I have an idea of what might be happening - the stack memory is cleared.
Code: Select all
struct ble_message_s{
uint8_t* payload;
uint8_t length;
};
uint8_t data_to_send2[5] = {1,2,3,4,5};
ble_message_s message;
message.payload = data_to_send2;
message.length = sizeof(data_to_send2);
xQueueSend(ble_parser_queue,&message, 10);