All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] inscrutable pipes
@ 2006-09-14 16:06 ckreider
  2006-09-14 16:17 ` Gilles Chanteperdrix
  2006-09-14 16:17 ` Philippe Gerum
  0 siblings, 2 replies; 7+ messages in thread
From: ckreider @ 2006-09-14 16:06 UTC (permalink / raw)
  To: xenomai

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

Proud though I am, it is time to ask for help.  I have used pipes  
with RTLinux but want to use Xenomai this time.  I can't get pipes  
working.

(as an aside, I saw on here where if you do make install, it will  
create the necessary /dev/rtp* entries.  I work on a development host  
and do not compile on the target, so I do not run make install.  I  
finally found the mknod magic in a message on this list)

I am using Xenomai 2.2.1 with a 2.6.17.8 kernel.

I finally took Captain's example and added the missing function  
parameters, but it did not work.  Then I tried an example from a  
message here, which appears to be derived from Captain's example.   
Again, I had to add missing function parameters, and again it did not  
work.  I compared the examples to  ksrc/skins/native/snippets/pipe.c,  
and they look correct, except that the snippet is missing some  
function parameters also.

First the results:

try1:
insmod pipe.ko, ./user

kernel: rt_pipe_alloc starting
kernel: rt_pipe_alloc done - no errors
kernel: rt_pipe_send starting
kernel: rt_pipe_send done - no errors
kernel: rt_pipe_receive starting
kernel: INIT DONE - no errors

"user" is sleeping in read

try2:
insmod pipe.ko, cat /dev/rtp0

kernel: rt_pipe_alloc starting
kernel: rt_pipe_alloc done - no errors
kernel: rt_pipe_send starting
kernel: rt_pipe_send done - no errors
kernel: rt_pipe_receive starting
kernel: INIT DONE - no errors

cat hangs waiting for input

try3:
insmod pipe.ko, echo "World" >/dev/rtp0

kernel: rt_pipe_alloc starting
kernel: rt_pipe_alloc done - no errors
kernel: rt_pipe_send starting
kernel: rt_pipe_send done - no errors
kernel: rt_pipe_receive starting
kernel: INIT DONE - no errors
kernel: received msg> World
kernel: , size=6
kernel: rt_pipe_receive done

Obviously I got the right major/minor for /dev/rtp* as the rt task  
reads my echo.  Neither "user" or "cat" read anything from the rt task.

The code:

==== user.c ====
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <native/pipe.h>

#define PIPE_MINOR 0

int pipe_fd;

int main (int argc, char *argv[])
         {
         char devname[32], buf[32];
         sprintf(devname, "/dev/rtp%d", PIPE_MINOR);
         pipe_fd = open(devname, O_RDWR);

         if (pipe_fd < 0)
                 {
                 printf("cannot open pipe %s\n", devname);
                 exit(1);
                 }

         read(pipe_fd, buf, sizeof(buf));
         printf("read from pipe: %s\n", buf);
         read(pipe_fd, buf, sizeof(buf));
         printf("read from pipe: %s\n", buf);

         write(pipe_fd, "World", sizeof("World"));
         printf("written string 'World' - see kernel log\n");

         close(pipe_fd);
         }


==== pipe.c ====
#include <linux/module.h>
#include <native/task.h>
#include <native/pipe.h>

#define PIPE_MINOR 0

#define TASK_PRIO  2               /* Highest RT priority */
#define TASK_MODE  T_FPU|T_CPU(0)  /* Uses FPU, bound to CPU #0 */
#define TASK_STKSZ 4096            /* Stack size (in bytes) */

RT_TASK task_desc;
RT_PIPE pipe_desc;

void task_body (void *cookie)
         {
         RT_PIPE_MSG * msgout, *msgin;
         int len = sizeof("HELLO");
         printk("rt_pipe_alloc starting\n");
         msgout = rt_pipe_alloc(&pipe_desc, len);
         if (msgout)
                 {
                 printk("rt_pipe_alloc done - no errors\n");
                 strcpy(P_MSGPTR(msgout), "HELLO");
                 printk("rt_pipe_send starting\n");
                 if (rt_pipe_send(&pipe_desc, msgout, len, 0) != len)
                         {
                         rt_pipe_free(&pipe_desc, msgout);
                         }
                 printk("rt_pipe_send done - no errors\n");
                 printk("rt_pipe_receive starting\n");
                 rt_pipe_receive(&pipe_desc, &msgin, TM_INFINITE);
                 printk("received msg> %s, size=%d\n", P_MSGPTR 
(msgin), P_MSGSIZE
                         (msgin));
                 printk("rt_pipe_receive done\n");
                 rt_pipe_free(&pipe_desc, msgin);
                 }
         else
                 {
                 printk("ERROR: rt_pipe_alloc\n");
                 }
         }

int __init init_module (void)
         {
         int err;
         err = rt_pipe_create(&pipe_desc, "pipetest", PIPE_MINOR, 0);
         if (!err)
                 {
                 err = rt_task_create(&task_desc, "MyTaskName",  
TASK_STKSZ,
                         TASK_PRIO, TASK_MODE);
                 if (!err)
                         {
                         rt_task_start(&task_desc, &task_body, NULL);
                         }
                 else
                         {
                         printk("ERROR: cannot create task\n");
                         return 0;
                         }
                 }
         else
                 {
                 printk("ERROR: cannot create pipe\n");
                 return 0;
                 }
         printk("INIT DONE - no errors\n");
         return 0;
         }

void __exit cleanup_module (void) {
     rt_pipe_delete(&pipe_desc);
     rt_task_delete(&task_desc);
     printk("CLEANUP DONE\n");
}

MODULE_LICENSE("GPL");



---
Carl Kreider
ckreider@domain.hid




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

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

end of thread, other threads:[~2006-09-23 17:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-14 16:06 [Xenomai-help] inscrutable pipes ckreider
2006-09-14 16:17 ` Gilles Chanteperdrix
     [not found]   ` <1BECC866-4567-477D-9A18-144496828EB7@domain.hid>
2006-09-14 21:22     ` Gilles Chanteperdrix
2006-09-23 17:59       ` Gilles Chanteperdrix
2006-09-14 16:17 ` Philippe Gerum
     [not found]   ` <38A01364-EC56-46D9-9768-A14979EA98E5@domain.hid>
     [not found]     ` <1158326750.5072.2.camel@domain.hid>
2006-09-16 11:32       ` ckreider
2006-09-17 12:05         ` Jan Kiszka

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.