Create a task with multiple queues in FreeRTOS?

I'm having trouble sending multiple queues to a task in FreeRTOS.

I tried to create a structure to hold them as follows:

typedef struct { xQueueHandle buttonQueue; xQueueHandle OLEDQueue; } xQueues; 

and then send it to the task as follows:

 void vStartADCtasks( xQueueHandle xButtonQueuex, QueueHandle xOLEDQueue ) { xQueues xADCQueues = { xOLEDQueue, xButtonQueue }; xTaskCreate( vGetAltitude, "Get Altitude", 240, (void *) &xADCQueues, 2, NULL ); } 

and access to it, as in the task:

 static void vGetAltitude(void *pvParameters) { xQueues *xADCQueues = ( xQueues * ) pvParameters; xQueueHandle xOLEDQueue = xADCQueues->OLEDQueue; xQueueHandle xButtonQueue = xADCQueues->buttonQueue; 

but that will not work. Any tips? I suggest that my more general question is how to get around the queue between multiple .c files. i.e. create it and one file, but be able to use it in a task in another file?

+4
source share
1 answer

You have 3 errors. First, you changed the order of the queues when trying to initialize xADCQueues. Secondly, you must pass xADCQueues as the 4th argument to xTaskCreate. Thirdly, your xADCQueues structure is created on the stack, which means that after vStartADCtasks returns, this structure will be destroyed and overwritten.

Replace vStartADCtasks with this

 xQueues xADCQueues; void vStartADCtasks( xQueueHandle xOLEDQueue, xQueueHandle xButtonQueue ) { xADCQueues.buttonQueue = xButtonQueue; xADCQueues.OLEDQueue = xOLEDQueue; xTaskCreate( vGetAltitude, "Get Altitude", 240, (void *) &xADCQueues, 2, NULL ); } 

or don't create an xADCQueue at all, but just do the xButtonQueue and xOLEDQueue global variables. I don’t see anything wrong with doing it for embedded systems ... I know that they teach you at school to avoid global variables, but in this case it is useful to make the variables global and static, since they separate tasks.

+4
source

Source: https://habr.com/ru/post/1491774/


All Articles