00001 #include <sys/types.h>
00002 #include <fcntl.h>
00003 #include <string.h>
00004 #include <stdio.h>
00005 #include <native/pipe.h>
00006
00007 #define PIPE_MINOR 0
00008
00009
00010
00011 int pipe_fd;
00012
00013 int main(int argc, char *argv[])
00014 {
00015 char devname[32], buf[16];
00016
00017
00018
00019 sprintf(devname, "/dev/rtp%d", PIPE_MINOR);
00020 pipe_fd = open(devname, O_RDWR);
00021
00022 if (pipe_fd < 0)
00023 fail();
00024
00025
00026 read(pipe_fd, buf, sizeof(buf));
00027
00028
00029 write(pipe_fd, "World", sizeof("World"));
00030
00031
00032 }
00033
00034 void cleanup(void)
00035 {
00036 close(pipe_fd);
00037 }
00038
00039
00040
00041 #define TASK_PRIO 0
00042 #define TASK_MODE T_FPU|T_CPU(0)
00043 #define TASK_STKSZ 4096
00044
00045 RT_TASK task_desc;
00046
00047 RT_PIPE pipe_desc;
00048
00049 void task_body(void)
00050 {
00051 RT_PIPE_MSG *msgout, *msgin;
00052 int err, len, n;
00053
00054 for (;;) {
00055
00056
00057 len = sizeof("Hello");
00058
00059
00060
00061
00062
00063
00064 msgout = rt_pipe_alloc(len);
00065
00066 if (!msgout)
00067 fail();
00068
00069
00070
00071 strcpy(RT_PIPE_MSGPTR(msgout), "Hello");
00072 rt_pipe_send(&pipe_desc, msgout, len, P_NORMAL);
00073
00074
00075 n = rt_pipe_receive(&pipe_desc, &msgin, TM_INFINITE);
00076
00077 if (n < 0) {
00078 printf("receive error> errno=%d\n", n);
00079 continue;
00080 }
00081
00082 if (n == 0) {
00083 if (msg == NULL) {
00084 printf("pipe closed by peer while reading\n");
00085 continue;
00086 }
00087
00088 printf("empty message received\n");
00089 } else
00090 printf("received msg> %s, size=%d\n", P_MSGPTR(msg),
00091 P_MSGSIZE(msg));
00092
00093
00094 rt_pipe_free(&pipe_desc, msgin);
00095
00096
00097 }
00098 }
00099
00100 init init_module(void)
00101 {
00102 int err;
00103
00104 err = rt_pipe_create(&pipe_desc, NULL, PIPE_MINOR);
00105
00106 if (err)
00107 fail();
00108
00109
00110
00111 err = rt_task_create(&task_desc,
00112 "MyTaskName", TASK_STKSZ, TASK_PRIO, TASK_MODE);
00113 if (!err)
00114 rt_task_start(&task_desc, &task_body, NULL);
00115
00116
00117 }
00118
00119 void cleanup_module(void)
00120 {
00121 rt_pipe_delete(&pipe_desc);
00122 rt_task_delete(&task_desc);
00123 }