From: Philippe Gerum <rpm@xenomai.org>
To: Bachman Kharazmi <bahkha@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] pipe example
Date: Sun, 16 Sep 2007 00:10:09 +0200 [thread overview]
Message-ID: <1189894209.25006.193.camel@domain.hid> (raw)
In-Reply-To: <1ce16a2c0709151255r52e63d66s7d626390c9d97f97@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 2100 bytes --]
On Sat, 2007-09-15 at 21:55 +0200, Bachman Kharazmi wrote:
> Hi Philippe,
>
> I'm testing the snippet example code from:
> http://svn.gna.org/viewcvs/xenomai/trunk/ksrc/skins/native/snippets/pipe.c?rev=525&view=markup
> without touching the code at all.
Redirected to xenomai-help. Please always use the mailing list for such
questions.
>
> But there seem to be issues during compile :/
> sandbox:/home/bkw/code/driver_v5# make
> gcc -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -D__XENO__
> -L/usr/xenomai/lib -lpthread -lnative -lrtdm -Xlinker -rpath -Xlinker
> /usr/xenomai/lib simpledriver_v5.c -o simpledriver_v5
> simpledriver_v5.c:47: error: expected '=', ',', ';', 'asm' or
> '__attribute__' before 'task_desc'
> simpledriver_v5.c: In function 'task_body':
> simpledriver_v5.c:51: error: 'RT_PIPE_MSG' undeclared (first use in
> this function)
> simpledriver_v5.c:51: error: (Each undeclared identifier is reported only once
> simpledriver_v5.c:51: error: for each function it appears in.)
> simpledriver_v5.c:51: error: 'msgout' undeclared (first use in this function)
> simpledriver_v5.c:51: error: 'msgin' undeclared (first use in this function)
> simpledriver_v5.c:69: warning: passing argument 1 of 'strcpy' makes
> pointer from integer without a cast
> simpledriver_v5.c:74: error: 'msg' undeclared (first use in this function)
> simpledriver_v5.c: At top level:
> simpledriver_v5.c:81: error: expected '=', ',', ';', 'asm' or
> '__attribute__' before 'init_module'
> simpledriver_v5.c: In function 'cleanup_module':
> simpledriver_v5.c:106: error: 'task_desc' undeclared (first use in
> this function)
> make: *** [simpledriver_v5] Error 1
>
> Is the purpose that the example code should be more or less compilable?
>
No, as you can see, it looks like a boilerplate, basically because...it
is a boilerplate.
Here is a compilable one, made of two separate items: a kernel module,
and a userland program, both communicating through a message pipe.
Finding what this example does and how to compile it is left to your
interpretation.
> thanks,
> Bachman
--
Philippe.
[-- Attachment #2: rwpipe.c --]
[-- Type: text/x-csrc, Size: 421 bytes --]
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <native/task.h>
int main (int argc, char *argv[])
{
int fd, count;
char c = 'x';
fd = open("/proc/xenomai/registry/native/pipes/data_pipe", O_RDWR);
if (fd < 0) {
perror("open");
return 1;
}
while (read(fd,&count,sizeof(count)) == sizeof(count)) {
printf("Count: %d\n", count);
write(fd,&c,sizeof(c));
}
close(fd);
return 0;
}
[-- Attachment #3: module.c --]
[-- Type: text/x-csrc, Size: 2429 bytes --]
/*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xenomai; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include <native/task.h>
#include <native/pipe.h>
#define TASK_PRIO 99 /* Highest RT priority */
#define TASK_MODE T_CPU(0) /* Bound to CPU #0 */
#define TASK_STKSZ 4096 /* Stack size (in bytes) */
static RT_TASK task_desc;
static RT_PIPE pipe_desc;
int task_period_ns = 1000000000;
module_param(task_period_ns,int,0444);
MODULE_PARM_DESC(task_period_ns, "period in ns (default: 1s)");
static void demo_task(void *cookie)
{
int err, count;
char c;
err = rt_task_set_periodic(NULL, TM_NOW,
rt_timer_ns2ticks(task_period_ns));
if (err) {
printk("rt_task_set_periodic() failed: code %d\n", err);
rt_task_suspend(NULL);
}
for (count = 0;;) {
err = rt_task_wait_period(NULL);
if (err) {
if (err != -ETIMEDOUT) {
printk("rt_task_wait_period() failed: code %d\n", err);
rt_task_suspend(NULL);
}
continue;
}
rt_pipe_write(&pipe_desc, &count, sizeof(count), P_NORMAL);
if (rt_pipe_read(&pipe_desc, &c, sizeof(c), TM_INFINITE) == 1)
++count;
}
}
int demo_init(void)
{
int err;
err = rt_pipe_create(&pipe_desc, "data_pipe", P_MINOR_AUTO, 0);
if (err) {
printk("rt_pipe_create() failed: code %d\n", err);
goto fail;
}
err = rt_task_create(&task_desc,
"kernel_task",
TASK_STKSZ,
TASK_PRIO,
TASK_MODE);
if (err) {
printk("rt_task_create() failed: code %d\n", err);
goto fail;
}
err = rt_task_start(&task_desc, &demo_task, NULL);
if (err)
printk("rt_task_start() failed: code %d\n", err);
fail:
return err;
}
void demo_cleanup(void)
{
rt_task_delete(&task_desc);
rt_pipe_delete(&pipe_desc);
}
module_init(demo_init);
module_exit(demo_cleanup);
MODULE_LICENSE("GPL v2");
next prev parent reply other threads:[~2007-09-15 22:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1ce16a2c0709151255r52e63d66s7d626390c9d97f97@domain.hid>
[not found] ` <1189887314.25006.192.camel@domain.hid>
2007-09-15 21:01 ` [Xenomai-help] pipe example Bachman Kharazmi
2007-09-15 22:10 ` Philippe Gerum [this message]
2007-09-15 22:28 ` Bachman Kharazmi
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=1189894209.25006.193.camel@domain.hid \
--to=rpm@xenomai.org \
--cc=bahkha@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.