I have multiple tasks that all write to a screen. Obviously without controlling who can write to the screen when I'll have problems. I thought the easiest way to do this was with queueing.
I have a global QueueHandle
. In my int main(void)
function I create a queue of size 10 (large enough for my needs) with an item size of that equal to my struct
which holds all the data.
struct screenData {
uint8_t string;
uint8_t line;
} data;
In the tasks which need to write to the screen they send to the queue:
struct screenData * toSend;
data.string = "TEST";
data.line = 0;
toSend = &data;
xQueueSend ( xQueue, ( void * ) &toSend , xTicksToWait );
In the task which updates the screen it reads from the queue and puts it on the screen:
struct screenData * data;
xQueueReceive( xQueue, &( data ), xTicksToWait );
I then access the data like so: data->string;
etc...
However, as far as I understand it, this passes the address of the struct. Which means if I update data
, the data held in the struct will be different.
What I want to do is have a queue which I can add to where the data sent is of the type screenData
, and it'll read each incoming screenData
to put a message on the screen.
Essentially, should I just be sending the whole struct to the queue? In which case, is this the best use of the queue? Or is there a better way to buffer data?
Thanks