Hello, friends of Comedi and RTL,
Please excuse me for my posting again on a simple problem,  on which I've spent three days and still no result yet.

My RT-routine purpose is very simple:  analog input/output(one channel respectively) every 500ms from/to NI PCI6035E DAQ card. Attached please find my codes "myrt_process.c" and the correspnding "Makefile". Also, please see the modules inserted shown in  "lsmod".

Now, I encounter a problem which annoyed me much:

1) When "comedi.h" and "comedilib.h" are both included in the program, the error information after "make" is shown in the attached file "error_with_comedilib".

2) When only "comedi.h" is included in the program, it seems that the compiler doesn't know the structure of "comedi_t", please see the attached error information of "error_without_comedilib".

On the other hand, I have also tested the demos of comedilib-0.7.9, they all are ok, and could read and write data to/from my PCI6035E card. However, if I modify them into the rt-routine like my "myrt_process.c", the problems mentioned above come out.  I was suggested by Mr. Markus Kempf that the problems may be due to that they are running in kernel-space,  but I am not clear about the difference of programs running in kernel-space and user-space, and wish to be informed how I could run the Comedi program in RT-rountine?? I even doublt if there is error in my "Makefile".

Could you please point out where I was wrong? and any kind hints will be much appreciated!!

Warm regards,

Yuhong
 
 
 


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>

#include <rtl.h>
#include <rtl_fifo.h>
#include <rtl_sched.h>
#include <rtl_sync.h>
#include <rtl_debug.h>

#include <comedi.h>           //main comedi header file
//#include <comedilib.h>



// Using NI PCI6035E, which has been setup well at /dev/comedi0
int AI_device = 0; //AI subdevice
int AO_device =1 ; //AO subdevice
int AI_chan = 0;  //AI channel
int AO_chan = 0;  //AO channel
int range = 0;
int aref = 0;

comedi_t *cf;

pthread_t thread;


void *start_routine(void *arg)
{
        int data,ret;

        struct sched_param p;
        p.sched_priority = 1;
        pthread_setschedparam(pthread_self(), SCHED_FIFO, &p);
        pthread_make_periodic_np(pthread_self(), gethrtime(), 50000000);

        cf=comedi_open("/dev/comedi0");

        while (1) {
                 comedi_data_read(cf,AI_device,AI_chan,range,aref,&data);
                 rtl_printf("AI data = %d \n", data);
                 ret=comedi_data_write(cf,AO_device,AO_chan,range,aref,100.0);
                 rtl_printf("Write data 100.0 into AO \n");

                 pthread_wait_np();                                                    
                 
        }
        return 0;
}

int init_module(void) {
        
        pthread_create(&thread, NULL, start_routine, 0);
        return 0;
}

void cleanup_module(void) {
        pthread_delete_np(thread);
}


include /usr/src/linux/.config

##### Compiler, Flags, Paths, etc. #####

RTL_CFLAGS  = -Wall -Wstrict-prototypes -O2 \
        -fomit-frame-pointer -fno-strength-reduce
RTL_DEFS    = -D__RTL__ -D__KERNEL__ \
        -DMODULE -c

ifeq ($(CONFIG_MODVERSIONS),y)
RTL_DEFS += -DMODVERSIONS -include \
        /usr/src/rtlinux-2.3/linux/include/linux/modversions.h
endif

RTL_INCLUDE = -I . -I /usr/include/rtlinux \
         -I /usr/src/rtlinux-2.3/linux/include/asm-i386

LFLAGS = -L/usr/lib

GCC = gcc

##### File Names #####

#RTL_HEADER     =       myrt_process.h

RTL_SOURCE      =       myrt_process.c

RTL_TARGET      =       myrt_process.o

##### Build Rules #####

all: $(RTL_TARGET)

$(RTL_TARGET): $(RTL_SOURCE) #$(RTL_HEADER)
        $(GCC) $(RTL_INCLUDE) $(RTL_CFLAGS) $(RTL_DEFS) \
        -c $(RTL_SOURCE) -o $(RTL_TARGET)

clean:
        -rm -f *.o 
Module                  Size  Used by
kcomedilib              4804   0 
ni_pcimio              18436   0 
8255                    1720   0  [ni_pcimio]
mite                    1584   0  [ni_pcimio]
comedi                 16404   0  [kcomedilib ni_pcimio 8255]
rtl_fifo                8700   0 
rtl_posixio             6916   0  [rtl_fifo]
rtl_sched              37932   0 
rtl_time               16360   0  [kcomedilib ni_pcimio comedi rtl_posixio rtl_sched]
opl3                   11400   0 
sb                     34132   0 
uart401                 6224   0  [sb]
sound                  57612   0  [opl3 sb uart401]
soundcore               2532   6  [sb sound]
In file included from /usr/include/stdio.h:40,
                 from /usr/include/comedilib.h:31,
                 from myrt_process.c:14:
/usr/include/bits/types.h:95: warning: `__NFDBITS' redefined
/usr/include/linux/posix_types.h:22: warning: this is the location of the previous 
definition
/usr/include/bits/types.h:97: warning: `__FDMASK' redefined
/usr/include/linux/posix_types.h:34: warning: this is the location of the previous 
definition
In file included from /usr/include/sys/ioctl.h:30,
                 from /usr/include/comedilib.h:29,
                 from myrt_process.c:14:
/usr/include/bits/ioctl-types.h:29: redefinition of `struct winsize'
/usr/include/bits/ioctl-types.h:38: redefinition of `struct termio'
In file included from /usr/include/comedilib.h:31,
                 from myrt_process.c:14:
/usr/include/stdio.h:477: warning: redefinition of `off_t'
/usr/include/linux/types.h:14: warning: `off_t' previously declared here
In file included from myrt_process.c:14:
/usr/include/comedilib.h:63: conflicting types for `comedi_open'
/usr/include/comedi.h:322: previous declaration of `comedi_open'
/usr/include/comedilib.h:64: conflicting types for `comedi_close'
/usr/include/comedi.h:323: previous declaration of `comedi_close'
/usr/include/comedilib.h:102: conflicting types for `comedi_data_read'
/usr/include/comedi.h:343: previous declaration of `comedi_data_read'
/usr/include/comedilib.h:104: conflicting types for `comedi_data_write'
/usr/include/comedi.h:341: previous declaration of `comedi_data_write'
/usr/include/comedilib.h:114: conflicting types for `comedi_dio_config'
/usr/include/comedi.h:345: previous declaration of `comedi_dio_config'
/usr/include/comedilib.h:115: conflicting types for `comedi_dio_read'
/usr/include/comedi.h:347: previous declaration of `comedi_dio_read'
/usr/include/comedilib.h:116: conflicting types for `comedi_dio_write'
/usr/include/comedi.h:349: previous declaration of `comedi_dio_write'
/usr/include/comedilib.h:118: conflicting types for `comedi_dio_bitfield'
/usr/include/comedi.h:351: previous declaration of `comedi_dio_bitfield'
make: *** [myrt_process.o] Error 1
myrt_process.c:26: parse error before `*'
myrt_process.c:26: warning: type defaults to `int' in declaration of `cf'
myrt_process.c:26: warning: data definition has no type or storage class
myrt_process.c: In function `start_routine':
myrt_process.c:40: warning: passing arg 1 of `comedi_open' makes integer from pointer 
without a cast
myrt_process.c:40: warning: assignment makes pointer from integer without a cast
myrt_process.c:43: warning: passing arg 1 of `comedi_data_read' makes integer from 
pointer without a cast
myrt_process.c:45: warning: passing arg 1 of `comedi_data_write' makes integer from 
pointer without a cast
make: *** [myrt_process.o] Error 1

Reply via email to