All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: roland Tollenaar <rolandtollenaar@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Hello world with questions
Date: Thu, 22 Feb 2007 16:37:10 +0100	[thread overview]
Message-ID: <45DDB8A6.9090703@domain.hid> (raw)
In-Reply-To: <bc4264770702220523r6af8f8at6d709a0e9079bd6c@domain.hid>

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

roland Tollenaar wrote:
> Hi,
> 
> I have copy-pasted the trivial app into the body of this mail. To
> understand what is
> going on I have sprinkled and garnished it with questions.
> 
> 
> [These are standard headers I presume]
> #include <stdio.h>
> #include <signal.h>
> #include <unistd.h>
> #include <sys/mman.h>

Jep.

> 
> 
> [These are xenomai headers. What libraries must be linked in with them?]
> #include <native/task.h>
> #include <native/timer.h>

-lnative, see examples.

> 
> [I see this macro is called later as an argument. What is its function?]
> RT_TASK demo_task;

It's a type in fact. Actually, this is bad style, derived from the
original RTAI API mess. I think we should establish something like
rt_task_t etc. on the long-term for the Xenomai native skin, keeping the
current names only for legacy code (Philippe?).

> 
> /* NOTE: error handling omitted. */
> 
> void demo(void *arg)
> {
> 
>           RTIME now, previous;
> 
>     /*
>      * Arguments: &task (NULL=self),
>      *            start time,
>      *            period (here: 1 s)
>      */
>     rt_task_set_periodic(NULL, TM_NOW, 1000000000);
> 
>     previous = rt_timer_read();
> 
>     while (1) {
>         rt_task_wait_period(NULL);
>         now = rt_timer_read();
> 
>         /*
>          * NOTE: printf may have unexpected impact on the timing of
>          *       your program. It is used here in the critical loop
>          *       only for demonstration purposes.
>          */
>         printf("Time since last turn: %ld.%06ld ms\n",
>                (long)(now - previous) / 1000000,
>                (long)(now - previous) % 1000000);
>                previous = now;
>     }
> }
> 
> 
> [The purpose of this function eludes me ?]
> void catch_signal(int sig)
> {
> }

POSIX signal handling (not Xenomai-related): makes pause() below return
when some of the caught signals arrive.

> 
> int main(int argc, char* argv[])
> {
> 
> [What is happening here?]
>     signal(SIGTERM, catch_signal);
>     signal(SIGINT, catch_signal);

# man signal

> 
> [Does this mean I cannot access global variables if this program is
> running in a thread? That would be a disastrous limitation!]
>     /* Avoids memory swapping for this program */
>     mlockall(MCL_CURRENT|MCL_FUTURE);

??? There is no such limitation. It's the plain thread programming model
like with normal pthreads.

# man mlockall

> 
>     /*
>      * Arguments: &task,
>      *            name,
>      *            stack size (0=default),
>      *            priority,
>      *            mode (FPU, start suspended, ...)
>      */
> [I presume this sets the function "demo" as a real-time task?]
>     rt_task_create(&demo_task, "trivial", 0, 99, 0);

No, it just creates that task object, the function is set below.

> 
>     /*
>      * Arguments: &task,
>      *            task function,
>      *            function argument
>      */
>     rt_task_start(&demo_task, &demo, NULL);
> [Is RTASK a task label? What happens if there are more than 1 task to
> run in separate threads?]

RT_TASK is the type of a task /descriptor/ (like a file descriptor or
pthread_t). You can have more tasks by playing with more descriptors.

> 
> [How is the loop broken to get to this part of the program?]
>     pause();

see above

> 
>     rt_task_delete(&demo_task);
> }
> 
> 
> Kindly,
> 
> Roland.
> 

HTH,
Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

  reply	other threads:[~2007-02-22 15:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-22 13:23 [Xenomai-help] Hello world with questions roland Tollenaar
2007-02-22 15:37 ` Jan Kiszka [this message]
2007-02-22 20:34   ` Roland Tollenaar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45DDB8A6.9090703@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=rolandtollenaar@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.