Re: Message Queues


Olga Syrbachova <syrba4eva28@...>
 

I have found msgdev.c under samples/scheduler/kernel/metairq_dispatch/src. And according to this example I'm quite sure my code is right. I have updated it here https://github.com/syrba4eva/Zephyr-RTOS/blob/main/main.c

But I still have some errors when I try

ol@ol-H270M-DS3H:~/zephyrproject/zephyr$ west build -b qemu_x86 samples/synchronization --pristine
...
expected declaration specifiers or '...' before '&' token
   40 | k_msgq_init(&my_msgq, my_msgq_buffer, sizeof(struct data_item_type), 10);
      |             ^
/home/ol/zephyrproject/zephyr/samples/synchronization/src/main.c:40:23: error: expected declaration specifiers or '...' before 'my_msgq_buffer'
   40 | k_msgq_init(&my_msgq, my_msgq_buffer, sizeof(struct data_item_type), 10);
      |                       ^~~~~~~~~~~~~~
/home/ol/zephyrproject/zephyr/samples/synchronization/src/main.c:40:39: error: expected declaration specifiers or '...' before 'sizeof'
   40 | k_msgq_init(&my_msgq, my_msgq_buffer, sizeof(struct data_item_type), 10);
      |                                       ^~~~~~
/home/ol/zephyrproject/zephyr/samples/synchronization/src/main.c:40:70: error: expected declaration specifiers or '...' before numeric constant
   40 | k_msgq_init(&my_msgq, my_msgq_buffer, sizeof(struct data_item_type), 10);
      |                                                                      ^~
/home/ol/zephyrproject/zephyr/samples/synchronization/src/main.c: In function 'threadA':
/home/ol/zephyrproject/zephyr/samples/synchronization/src/main.c:62:21: error: storage size of 'data' isn't known
   62 |  struct data_item_t data;
      |                     ^~~~
/home/ol/zephyrproject/zephyr/samples/synchronization/src/main.c:62:21: warning: unused variable 'data' [-Wunused-variable]
[54/118] Building C object zephyr/arch.../arch__x86__core.dir/ia32/thread.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/ol/zephyrproject/zephyr/build

And I still have this question: is it the right way to build my own application by modifying a "synchronization" sample? I'm doing it right under $HOME/zephyrproject/zephyr/samples/synchronization/src. Or should I create a new file in another directory?


On Thu, 25 Mar 2021 at 19:45, Olga Syrbachova <syrba4eva28@...> wrote:
Thank you very much for your reply! Unfortunately I can't find samples/scheduler/metairq_dispatch neither on the website of zephyrproject nor on  GIT. Could you please tell me where I can find  msgdev.c?

And also I would like to know if it's the right way to build my own application by modifying a "synchronization" sample? I'm doing it right under $HOME/zephyrproject/zephyr/samples/synchronization/src. Or should I create a new file in another directory?

Many thanks in advance!

On Thu, 25 Mar 2021 at 07:52, Kim Boendergaard <kim.boendergaard@...> wrote:

Consider having a look at msgdev.c in samples/scheduler/metairq_dispatch

 

I think that clearly answer your questions

 

Best regards,

Kim Bøndergaard | Software Tech Lead, Esco Medical
Phone: +45 51 54 39 61

 

From: users@... <users@...> On Behalf Of Olga Syrbachova
Sent: Wednesday, 24 March 2021 15.29
To: users@...
Subject: [Zephyr-users] Message Queues

 

EXTERNAL — Use caution when opening link(s) or attachment(s)


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.



[The information contained in this email (including any attachments) is confidential and is intended solely for the use of the named addressee. Any unauthorized use, disclosure, reproduction, copying, distribution, or other form of unauthorized dissemination of the contents is expressly prohibited. If you have received this communication in error, please notify the sender immediately by email and delete the original message. Opinions, conclusions and other information in this message represent the opinion of the sender and do not necessarily represent or reflect the views and opinions of Esco Group companies.]


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