Message Queues


Olga Syrbachova <syrba4eva28@...>
 

Hi! I'm trying to create my own app. I decided to start by modifying a "synchronization" sample. In my app I want to have 2 threads and 1 queue, so one thread can send messages to this queue and another thread is reading messages from the queue. I didn't find any sample with queues and I'm not sure how exactly to make queues. And I don't understand what I should put in "data" here:

void producer_thread(void)
{
    struct data_item_type data;

    while (1) {
        /* create data item to send (e.g. measurement, timestamp, ...) */
        data = ...

        /* send data to consumers */
        while (k_msgq_put(&my_msgq, &data, K_NO_WAIT) != 0) {
            /* message queue is full: purge old data & try again */
            k_msgq_purge(&my_msgq);
        }

        /* data item was successfully added to message queue */
    }
}
Data is of type struct data_item_type and it has 3 items in the example on the website. Does it mean I have to initialize my data in this way for example:
data.field1 = 2; /* int = 2 */
data.field2 = 3; /* int = 3 */

I followed the tutorial on the website, but not all steps are clear to me. You can find my code on github: https://github.com/syrba4eva/Zephyr-RTOS/blob/main/main.c

Can you please suggest any sample with queues or tell me what I am doing wrong? Many thanks in advance.

Join users@lists.zephyrproject.org to automatically receive all group messages.