#include <sys/mman.h>
#include <stdio.h>
#include <string.h>
#include <native/task.h>
#include <native/queue.h>
#include <rtdk.h>
#define TASK_PRIO 99 /* Highest RT priority */
#define TASK_MODE 0 /* No flags */
#define TASK_STKSZ 0 /* Stack size (use default one) */
//RT_TASK eegsample, eegprocessor;
//RT_QUEUE queue;
struct parame {
int burstlength;
int p;
int c;
} ;
void eegprocessor_run (void *cookie)
{
ssize_t len;
void *msg;
int err,i,length;
RT_QUEUE q_desc;
/* Bind to a queue which has been created elsewhere, either in
kernel or user-space. The call will block us until such queue
is created with the expected name. The queue should have been
created with the Q_SHARED mode set, which is implicit when
creation takes place in user-space. */
err = rt_queue_bind(&q_desc,"Queue",TM_INFINITE);
if (err) {rt_printf("Consumer: Unable to bind to queue"); exit(-1); }
/* Collect each message sent to the queue by the queuer() routine,
until the queue is eventually removed from the system by a call
to rt_queue_delete(). */
length = parame.burstlength*1000/parame.c
while ((i=0; i<length; i++)
{
rt_printf("Consumer: received message len=%d bytes, ptr=%p, s=%s\n",
len,msg,(const char *)msg);
rt_queue_free(&q_desc,msg);
spin();
}
/* We need to unbind explicitly from the queue in order to
properly release the underlying memory mapping. Exiting the
process unbinds all mappings automatically. */
rt_queue_unbind(&q_desc);
if (len != -EIDRM) exit (-1);
/* We received some unexpected error notification. */
}
void spin()
{
int i;
for (i=1; i<10000000; i++)
{
int temp = 100;
temp=temp*1;
temp=temp/1;
}
}
void eegsample_run(void *cookie)
{
RT_QUEUE q_desc;
char *messages[];
int n, j,len;
void *msg;
int err;
err = rt_queue_bind(&q_desc,"Queue", TM_INFINITE);
if (err != 0)
{ rt_printf ("Producer: Unable to bind to queue%d\n",err); exit(-1); }
for (n=0; n<750; n++)
{
for (j=0; j<8; j++)
{
message[i] = get();
}
}
strcpy(msg,messages[n]);
rt_queue_send(&q_desc,msg,len,Q_NORMAL);
}
char get()
{
int randNum = 26 * (rand() / (RAND_MAX +1.0));
randNum = randNum + 97;
return (char)randNum;
}
P\partA.c
#include <sys/mman.h>
#include <stdio.h>
#include <string.h>
#include <native/task.h>
#include <native/queue.h>
#include <rtdk.h>
#define TASK_PRIO 99 /* Highest RT priority */
#define TASK_MODE 0 /* No flags */
#define TASK_STKSZ 0 /* Stack size (use default one) */
struct parame
{
int burstlength;
int p;
int c;
} ;
RT_TASK eegsample, eegprocessor;
RT_QUEUE queue;
void eegprocessor_run (void *cookie);
void eegsample_run(void *cookie);
int main (int argc, char *argv[])
{
int err, queuesize;
struct parame aparame;
aparame.burstlength = atoi(argv[argc-1]);
aparame.p = atoi(argv[argc-2]);
aparame.c = atoi(argv[argc-3]);
mlockall(MCL_CURRENT|MCL_FUTURE);
//rt_print_auto_init(1);
queuesize=(aparame.p-aparame.c)/aparame.burstlength;
err = rt_queue_create(&queue, "Queue",queuesize,10,Q_FIFO|Q_SHARED);
if (err != 0) { printf ("main():Unable to create queue %d\n",err); exit(-1);}
err = rt_task_create(&eegsample,"eegsample", TASK_STKSZ,TASK_PRIO,T_JOINABLE);
err = rt_task_create(&eegprocessor,"eegprocessor", TASK_STKSZ,TASK_PRIO,T_JOINABLE);
rt_task_start(&eegsample,&eegsample_run, &aparame);
rt_task_start(&eegprocessor,&eegprocessor_run, &aparame);
printf ("Joining\n");
rt_task_join(&eegsample);
// rt_task_join(&c_desc);
printf ("Deleting\n");
rt_task_delete(&eegsample);
rt_task_delete(&eegprocessor);
}
Makefile:
###### CONFIGURATION ######
### List of applications to be build
APPLICATIONS = partA
partA: partA.o Assign3.o
$(CC) -o partA $(LDFLAGS) partA.o Assign3.o
### Note: to override the search path for the xeno-config script, use "make XENO=..."
### List of modules to be build
MODULES =
### Note: to override the kernel source path, use "make KSRC=..."
###### USER SPACE BUILD (no change required normally) ######
ifeq ($(KERNELRELEASE),)
ifneq ($(APPLICATIONS),)
### Default Xenomai installation path
XENO ?= /usr/xenomai
XENOCONFIG=$(shell PATH=$(XENO):$(XENO)/bin:$(PATH) which xeno-config 2>/dev/null)
### Sanity check
ifeq ($(XENOCONFIG),)
all::
@echo ">>> Invoke make like this: \"make XENO=/path/to/xeno-config\" <<<"
@echo
endif
CC=$(shell $(XENOCONFIG) --cc)
CFLAGS=$(shell $(XENOCONFIG) --xeno-cflags) $(MY_CFLAGS)
LDFLAGS=$(shell $(XENOCONFIG) --xeno-ldflags) $(MY_LDFLAGS) -lnative
# This includes the library path of given Xenomai into the binary to make live
# easier for beginners if Xenomai's libs are not in any default search path.
LDFLAGS+=-Xlinker -rpath -Xlinker $(shell $(XENOCONFIG) --libdir)
all:: $(APPLICATIONS)
clean::
$(RM) $(APPLICATIONS) *.o
endif
endif
###### SPECIAL TARGET RULES ######
rtprint: rtprint.c
$(CC) $(CFLAGS) $? $(LDFLAGS) -lrtdk -o $@
###### KERNEL MODULE BUILD (no change required normally) ######
ifneq ($(MODULES),)
### Default to sources of currently running kernel
KSRC ?= /lib/modules/$(shell uname -r)/build
OBJS := ${patsubst %, %.o, $(MODULES)}
CLEANMOD := ${patsubst %, .%*, $(MODULES)}
PWD := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
### Kernel 2.6
ifeq ($(findstring 2.6,$(KSRC)),2.6)
obj-m := $(OBJS)
EXTRA_CFLAGS := -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/posix $(ADD_CFLAGS)
all::
$(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules
### Kernel 2.4
else
ARCH ?= $(shell uname -i)
INCLUDE := -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/compat -I$(KSRC)/include/xenomai/posix
CFLAGS += $(shell $(MAKE) -s -C $(KSRC) CC=$(CC) ARCH=$(ARCH) SUBDIRS=$(PWD) modules) $(INCLUDE)
all:: $(OBJS)
endif
## Target for capturing 2.4 module CFLAGS
modules:
@echo "$(CFLAGS)"
clean::
$(RM) $(CLEANMOD) *.o *.ko *.mod.c Module*.symvers
$(RM) -R .tmp*
endif
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment