All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] pipe.c
@ 2008-07-02 19:09 Breno Carneiro Pinheiro
  2008-07-06 14:13 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 2+ messages in thread
From: Breno Carneiro Pinheiro @ 2008-07-02 19:09 UTC (permalink / raw)
  To: xenomai


[-- Attachment #1.1: Type: text/plain, Size: 379 bytes --]

Hi all, I'm trying to compile and then run the pipe.c example on my MPC5200
board but I got so many errors on cross-compiling process.  The code has two
parts (user and kernel space). Firstly I separated the kernel space to get
the kernel module .
The Makefile and code used are attached. If anyone have already tried, let
me know. I'm  missing something likely.

Thanks,

Breno

[-- Attachment #1.2: Type: text/html, Size: 417 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pipe.c --]
[-- Type: text/x-csrc; name=pipe.c, Size: 2157 bytes --]

#include <sys/types.h>
#include "fcntl.h"
#include "string.h"
#include "stdio.h"
#include <native/pipe.h>
#include <linux/module.h>
#include <native/task.h>

/* Kernel-side */
#define PIPE_MINOR 0
#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");
    /* Get a message block of the right size in order to initiate the
       message-oriented dialog with the user-space process. Sending a
       continuous stream of bytes is also possible using
       rt_pipe_stream(), in which case no message buffer needs to be
       preallocated. */
    msgout = rt_pipe_alloc(len);

    if (msgout) {

		// Send prompt message "Hello"
		strcpy( P_MSGPTR(msgout), "Hello");
		//rt_pipe_send(&pipe_desc, msgout, len, P_NORMAL);
		if (rt_pipe_send(&pipe_desc, msgout, len, 0) != len) {
			rt_pipe_free(msgout);
		}

		// Then wait for the reply string "World":
		rt_pipe_receive(&pipe_desc, &msgin, TM_INFINITE);
		printk("received msg> %s, size=%d\n",P_MSGPTR(msgin),P_MSGSIZE(msgin));
		// Free the received message buffer.
		rt_pipe_free(msgin);

	} else {
		printk("ERROR: rt_pipe_alloc\n");
	}
}

int __init init_module (void) {
	int err;
	err = rt_pipe_create(&pipe_desc, "pipetest", PIPE_MINOR);
	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;
		}
/*		// since fusion 0.7.3 you can also use rt_task_spawn
		err = rt_task_spawn(&task_desc, "MYTask", TASK_STKSZ, TASK_PRIO, 0, &task_body, NULL);
		if (err) {
			printk("error rt_task_spawn\n");
			return 0;
		}	
*/
	} else {
		printk("ERROR: cannot create pipe\n");
	}
	printk("INIT DONE\n");
	return 0;
}

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



[-- Attachment #3: Makefile --]
[-- Type: application/octet-stream, Size: 1256 bytes --]

###### CONFIGURATION ######

### List of applications to be build
#APPLICATIONS = trivial-periodic sigxcpu rtprint
APPLICATIONS =
### Note: to override the search path for the xeno-config script, use "make XENO=..."


### List of modules to be build
MODULES = pipe

### Note: to override the kernel source path, use "make KSRC=..."

###### SPECIAL TARGET RULES ######
#task_test_native: task_test_native.c
#	$(CC) $(CFLAGS) $? $(LDFLAGS) -lrtdk -o $@
#	$(CC) $(CFLAGS) $? $(LDFLAGS) -lpsos -o $@

###### KERNEL MODULE BUILD (no change required normally) ######
ifneq ($(MODULES),)

### Default to sources of currently running kernel
#KSRC ?= /lib/modules/$(shell uname -r)/build
KSRC ?= /home/breno/ELDK/ppc_6xx/usr/src/Denx-kernel-tree-3

OBJS     := ${patsubst %, %.o, $(MODULES)}
CLEANMOD := ${patsubst %, .%*, $(MODULES)}
PWD      := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)

obj-m        := $(OBJS)
EXTRA_CFLAGS := -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/posix -I/home/breno/ELDK/ppc_6xx/usr/include $(ADD_CFLAGS)

all::
	$(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules

## Target for capturing 2.4 module CFLAGS
modules:
	@echo "$(CFLAGS)"

clean::
	$(RM) $(CLEANMOD) *.o *.ko *.mod.c Module*.symvers
	$(RM) -R .tmp*

endif

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

end of thread, other threads:[~2008-07-06 14:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-02 19:09 [Xenomai-help] pipe.c Breno Carneiro Pinheiro
2008-07-06 14:13 ` Gilles Chanteperdrix

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.