All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Native message queue and synchronisation
@ 2009-08-17 15:03 Berruer Sébastien
  2009-08-19 16:09 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 13+ messages in thread
From: Berruer Sébastien @ 2009-08-17 15:03 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 4402 bytes --]

Hello,

I'm trying to make some basic test code using the native API of Xenomai. I declare two tasks (a consumer and a producer) and one queue from the main.
 - the producer get the system time and pass it throw a named queue
 - the consumer is supposed to block on the queue, waiting until the value is available in the queue

I issue a problem around the call to rt_queue_read().
 - when I run the actual code, the application hangs. As if, there were no means for mesure_task to write in the queue.
 - if I comment the sleep in the mesure_task and uncomment the one in display_task, the sleep is long enough (!) for data to be written and so, the call is issued correctly.

The parameter TM_INFINITE seems to be the cause. I can't figure why because, in the documentation, it's supposed to be rescheduled if there is no message yet.

I include my code and hope you can point me out what I am doing wrong.
I'm running a kernel 2.6.28 with Xenomai 2.4.8 on an ARM architecture (PXA255).

Best regards,





#include <stdlib.h>
#include <sys/mman.h>
#include <native/queue.h>
#include <native/task.h>
#include <native/timer.h>

#define ONE_BILLION     1000000000
#define ONE_MILLION     1000000
#define LOOP_NB         10
#define LOOP_DELAY      2 * ONE_BILLION

char queue_name[] = "exchange_data";

void display(void* cookie)
{
        RT_QUEUE disp_q;
        RTIME disp;
        int err, ret;

        err = rt_queue_bind(&disp_q, queue_name, TM_INFINITE);
        if(err) {
                perror("Unable to find the queue");
                return;
        }

        /*put a delay to be sure that other task write something*/
        /*rt_task_sleep(LOOP_DELAY);*/

        ret = rt_queue_read(&disp_q, (void*)&disp, sizeof(RTIME), TM_INFINITE);
        if(ret < 0)
                perror("Error reading");
        else
                printf("Value read from the queue: %lli\n", disp);

        err = rt_queue_unbind(&disp_q);
        if(err != 0) {
                perror("Unable to release the queue");
                return;
        }

        return;
}

void mesure(void* cookie)
{
        RTIME date;
        RT_QUEUE mes_q;
        int err, ret;

        err = rt_queue_bind(&mes_q, queue_name, TM_INFINITE);
        if(err) {
                perror("Unable to find the queue");
                return;
        }

        /*put a delay to be sure that other task block on queue*/
        rt_task_sleep(LOOP_DELAY);

        date = rt_timer_read();

        ret = rt_queue_write(&mes_q, (void*)&date, sizeof(RTIME), Q_NORMAL);
        if(ret < 0)
                perror("Error writing");

        err = rt_queue_unbind(&mes_q);
        if(err != 0) {
                perror("Unable to release the queue");
                return;
        }

        return;
}

int main(int argc, char* argv[])
{
        RT_QUEUE queue;
        RT_TASK display_task, mesure_task;
        int err;

        mlockall(MCL_CURRENT|MCL_FUTURE);

        err = rt_queue_create(&queue, queue_name, sizeof(int), Q_UNLIMITED, Q_FIFO|Q_SHARED);
        if(err) {
                perror("Unable to create the queue");
                exit(EXIT_FAILURE);
        }

        err = rt_task_create(&display_task, "display task", 0, 0, T_FPU|T_JOINABLE);
        err = rt_task_create(&mesure_task, "mesure task", 10, 0, T_FPU|T_JOINABLE);
        if(err) {
                perror("Unable to create a task");
                exit(EXIT_FAILURE);
        }

        err = rt_task_start(&display_task, &display, NULL);
        err = rt_task_start(&mesure_task, &mesure, NULL);
        if(err) {
                perror("Unable to start a task");
                exit(EXIT_FAILURE);
        }

        /*wait for terminaison of tasks*/
        rt_task_join(&mesure_task);
        rt_task_join(&display_task);

        /*delete all previously allocated ressources*/
        err = rt_task_delete(&display_task);
        err = rt_task_delete(&mesure_task);

        err = rt_queue_delete(&queue);

        exit(EXIT_SUCCESS);
}

=================================
| BERRUER Sébastien             |
| Trainee at Altran Ouest       |
| Centre d'Affaires Alphasis    |
| 35760 Saint-Grégoire - FRANCE |
| Tel: 06-76-35-29-55           |
=================================












[-- Attachment #2: Type: text/html, Size: 9053 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-08-25 15:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-17 15:03 [Xenomai-help] Native message queue and synchronisation Berruer Sébastien
2009-08-19 16:09 ` Gilles Chanteperdrix
2009-08-20  7:13   ` [Xenomai-help] RE : " Berruer Sébastien
2009-08-21  9:02     ` Gilles Chanteperdrix
2009-08-21 14:13       ` Berruer Sébastien
2009-08-21 14:18         ` Gilles Chanteperdrix
2009-08-21 22:23         ` Gilles Chanteperdrix
2009-08-24  9:17           ` Berruer Sébastien
2009-08-24  9:36             ` Gilles Chanteperdrix
2009-08-25  7:26               ` Berruer Sébastien
2009-08-25  8:12                 ` Gilles Chanteperdrix
2009-08-25 14:53                   ` [Xenomai-help] RE : " Berruer Sébastien
2009-08-25 15:19                     ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.