I have found that the get response function are implemented by the following code.If we can change it to real time. It should solve my problem!
//The name of this file is pcommx.c, and the following code is part of function I would use.
int pmac_get_response(int device, char *buf)
{
if(!ISDEVICEOPEN(device))
return -ENODEV;
pmac[device].ext.status = COMM_OK;
ioctl(pmac[device].node, IOCTL_MOTION_FLUSH_PORT);
ioctl(pmac[device].node, IOCTL_MOTION_FLUSH_MEM);
pmac_send_line(device, buf);
return pmac_get_line(device, buf);
}
int pmac_send_line(int device, char *buf)
{
int result;
if(!ISDEVICEOPEN(device))
return -ENODEV;
switch(pmac[device].ascii_mode){
case BUS:
result = pmac_bus_send_line(device, buf);
break;
case DPR:
result = pmac_dpr_send_line(device, buf);
break;
}
return result;
}
int pmac_bus_send_line(int device, char *buf)
{
if(!ISDEVICEOPEN(device))
return -ENODEV;
strncpy(pmac[device].ext.buffer, buf, 256);
ioctl(pmac[device].node, IOCTL_MOTION_WRITELN_PORT, &pmac[device].ext);
return 0;
}
It seems that the only function should change to real time is ioctl().
I have found a similiar problem and begining to solve it according to the mial list.
http://mail.rtai.org/pipermail/rtai/2009-June/021718.html
And I change my code as follows:
/*****************************Change from here*****************************/
//For real time.
#include
#define MY_LXRT_EXT // I just copy this from mail list,I do not know whether is correct!
#define RT_IOCTL 1
static inline int rt_ioctl(int dev,int req, void* ptr)
{
struct { long dev, long req, void *ptr ;} arg={dev,req,ptr};
return rtai_lxrt(MY_LXRT_EXT, SIZARG, RT_IOCTL, &arg).i[LOW];
}
/***************************The change end here***************************/
/****************************************For real time response**********************************************/
int rt_pmac_get_response(int device, char *buf)
{
if(!ISDEVICEOPEN(device))
return -ENODEV;
pmac[device].ext.status = COMM_OK;
rt_ioctl(pmac[device].node, IOCTL_MOTION_FLUSH_PORT);
rt_ioctl(pmac[device].node, IOCTL_MOTION_FLUSH_MEM);
rt_pmac_bus_send_line(device, buf);// For I use ISA bus of my device. The first time I did not chane this .
return pmac_get_line(device, buf);
}
/************************************************The End*****************************************************/
/****************************For real time***********************************/
int rt_pmac_bus_send_line(int device, char *buf)
{
if(!ISDEVICEOPEN(device))
return -ENODEV;
strncpy(pmac[device].ext.buffer, buf, 256);
rt_ioctl(pmac[device].node, IOCTL_MOTION_WRITELN_PORT, &pmac[device].ext);
return 0;
}
/****************************For real time***********************************/
The makefile is:
# The headers are taken from the kernel
INCLUDEDIR = /usr/src/linux-headers-2.6.32-122-rtai/include/
LIBDIR= /usr/lib
libpcommx.so.1.0.0: pcommx.o
gcc -g -shared -Wl,-soname,libpcommx.so.1 -o libpcommx.so.1.0.0 pcommx.o -lc
pcommx.o: pcommx.c pcommx.h
gcc -g -fPIC -c -I $(INCLUDEDIR) pcommx.c
all: libpcommx.so.1.0.0
#test: Test.c
#gcc -g Test.c -o test -L. -lpcommx -I$(INCLUDEDIR)
install:
install -c pcommx.h $(INCLUDEDIR)/linux
install -c libpcommx.so.1.0.0 $(LIBDIR)
ln -s $(LIBDIR)/libpcommx.so.1.0.0 $(LIBDIR)/libpcommx.so.1
ln -s $(LIBDIR)/libpcommx.so.1 $(LIBDIR)/libpcommx.so
clean:
rm -f *.o *.so* $(LIBDIR)/libpcommx.*
rm -f $(INCLUDEDIR)/linux/pcommx.h
The readme is
lib #contain library for pmac
LIBRARY INSTALLATION:
1 In lib/Makefile
Change $(INCLUDEDIR) to target machine include dir
2 Run make in lib directory as
make
make install
I remember that the first time I successfully finished these steps, but when I turn to the project file , it shows undefined reference to 'rt_pmac_get_response'. The first time I did not change the pmac_send_line(device, buf) to rt type. So I changed it, then I started the step again. Unfortun ately, it shows the following errors:
root@sjtu-desktop:/home/sjtu/pmac_driver-installed/lib_mod_new# make
make: Warning: File `pcommx.c' has modification time 2.6e+02 s in the future
gcc -g -fPIC -c -I /usr/src/linux-headers-2.6.32-122-rtai/include/ pcommx.c
pcommx.c:14:23: error: rtai_lxrt.h: No such file or directory
pcommx.c: In function ‘rt_ioctl’:
pcommx.c:20: error: expected identifier or ‘(’ before ‘long’
pcommx.c:20: warning: no semicolon at end of struct or union
pcommx.c:20: warning: excess elements in struct initializer
pcommx.c:20: warning: (near initialization for ‘arg’)
pcommx.c:20: warning: excess elements in struct initializer
pcommx.c:20: warning: (near initialization for ‘arg’)
pcommx.c:21: error: expected expression before ‘,’ token
pcommx.c:21: error: ‘SIZARG’ undeclared (first use in this function)
pcommx.c:21: error: (Each undeclared identifier is reported only once
pcommx.c:21: error: for each function it appears in.)
pcommx.c:21: error: ‘LOW’ undeclared (first use in this function)
pcommx.c: In function ‘rt_pmac_get_response’:
pcommx.c:302: error: too few arguments to function ‘rt_ioctl’
pcommx.c:303: error: too few arguments to function ‘rt_ioctl’
make: *** [pcommx.o] Error 1
root@sjtu-
What should I do now?
Any advice are appreciated!
Thanks!