* [Xenomai-help] Hello world with questions
@ 2007-02-22 13:23 roland Tollenaar
2007-02-22 15:37 ` Jan Kiszka
0 siblings, 1 reply; 3+ messages in thread
From: roland Tollenaar @ 2007-02-22 13:23 UTC (permalink / raw)
To: xenomai
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>
[These are xenomai headers. What libraries must be linked in with them?]
#include <native/task.h>
#include <native/timer.h>
[I see this macro is called later as an argument. What is its function?]
RT_TASK demo_task;
/* 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)
{
}
int main(int argc, char* argv[])
{
[What is happening here?]
signal(SIGTERM, catch_signal);
signal(SIGINT, catch_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);
/*
* 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);
/*
* 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?]
[How is the loop broken to get to this part of the program?]
pause();
rt_task_delete(&demo_task);
}
Kindly,
Roland.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai-help] Hello world with questions
2007-02-22 13:23 [Xenomai-help] Hello world with questions roland Tollenaar
@ 2007-02-22 15:37 ` Jan Kiszka
2007-02-22 20:34 ` Roland Tollenaar
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2007-02-22 15:37 UTC (permalink / raw)
To: roland Tollenaar; +Cc: xenomai
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai-help] Hello world with questions
2007-02-22 15:37 ` Jan Kiszka
@ 2007-02-22 20:34 ` Roland Tollenaar
0 siblings, 0 replies; 3+ messages in thread
From: Roland Tollenaar @ 2007-02-22 20:34 UTC (permalink / raw)
To: Jan Kiszka; +Cc: xenomai
Hi,
Thanks. Will go through this and hopefully slowly start making sense of it.
Roland
Jan Kiszka wrote:
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-02-22 20:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-22 13:23 [Xenomai-help] Hello world with questions roland Tollenaar
2007-02-22 15:37 ` Jan Kiszka
2007-02-22 20:34 ` Roland Tollenaar
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.