Added RT-Linux version of sendburst and readburst utilities.
authorppisa <ppisa>
Sun, 4 Jan 2004 15:53:14 +0000 (15:53 +0000)
committerppisa <ppisa>
Sun, 4 Jan 2004 15:53:14 +0000 (15:53 +0000)
It worked on the first try with previously committed LinCAN RTL changes :-).
Corrected one forgotten line in ioctl_rtl.c => filters work from RT-linux
same way as from Linux user-space applications.

lincan/src/Makefile.omk
lincan/src/ioctl_rtl.c
lincan/src/main.c
lincan/utils/Makefile.omk
lincan/utils/readburst_rtl.c [new file with mode: 0644]
lincan/utils/sendburst_rtl.c [new file with mode: 0644]

index 37efcca..674077c 100644 (file)
@@ -1,6 +1,6 @@
 rtlinux_INCLUDES = -I $(srcdir)/../include -DCAN_WITH_RTL
 kernel_INCLUDES = -I $(srcdir)/../include
-kernel_INCLUDES += -DCAN_DEBUG
+#kernel_INCLUDES += -DCAN_DEBUG
 kernel_INCLUDES += -DWITH_DEVFS_FS
 
 kernel_MODULES = lincan
index 449b345..6c116a3 100644 (file)
@@ -76,8 +76,7 @@ int can_ioctl_rtl_posix(struct rtl_file *fptr, unsigned int cmd, unsigned long a
                }
                
                case CANQUE_FILTER: {
-                       struct canfilt_t canfilt;
-                       copy_from_user(&canfilt, (void*)arg, sizeof(struct canfilt_t));
+                       struct canfilt_t canfilt=*(struct canfilt_t *)arg;
                        if(canuser->rx_edge0){
                                canque_set_filt(canuser->rx_edge0, canfilt.id, canfilt.mask, canfilt.flags);
                        }
index 38a0ec0..b57c79c 100644 (file)
@@ -102,6 +102,9 @@ MODULE_LICENSE("GPL");
 #ifdef MODULE_DESCRIPTION
 MODULE_DESCRIPTION("Universal Linux CAN-bus device driver");
 #endif
+#ifdef MODULE_AUTHOR
+MODULE_AUTHOR("Pavel Pisa <pisa@cmp.felk.cvut.cz>, Arnaud Westenberg");
+#endif
 
 /* Global structures, used to describe the installed hardware. */
 struct canhardware_t canhardware;
index 6c1b093..cdfaf52 100644 (file)
@@ -8,5 +8,10 @@ rxtx_SOURCES = rxtx.c
 send_SOURCES = send.c
 can_proxy_SOURCES = can-proxy.c
 
+# RT-Linux version of build
 
+rtlinux_MODULES = sendburst_rtl readburst_rtl
 
+sendburst_rtl_SOURCES = sendburst_rtl.c
+
+readburst_rtl_SOURCES = readburst_rtl.c
diff --git a/lincan/utils/readburst_rtl.c b/lincan/utils/readburst_rtl.c
new file mode 100644 (file)
index 0000000..9f03cbf
--- /dev/null
@@ -0,0 +1,157 @@
+#include <rtl.h>
+#include <time.h>
+#include <signal.h>
+#include <pthread.h>
+#include <posix/unistd.h>
+
+#define printf rtl_printf
+
+#include "../include/can.h"
+
+int fd;
+
+struct canfilt_t canfilt = {
+       .flags = 0,
+       .queid = 0,
+       .cob = 0,
+       .id = 0,
+       .mask = 0
+};
+
+int canfilt_fl;
+
+int canfilt_mask, canfilt_id, canfilt_flags;
+
+
+int can_wait_sec = 5;
+
+char *can_dev_name = "/dev/can0";
+
+#define PRT_PREFIX_SIZE 40
+char prt_prefix[PRT_PREFIX_SIZE];
+
+char *prt_prefix_in = "CAN %s : ";
+
+MODULE_PARM_DESC(can_dev_name,"name of CAN device [/dev/can0]");
+MODULE_PARM(can_dev_name,"1s");
+MODULE_PARM_DESC(canfilt_mask,"CAN filter mask");
+MODULE_PARM(canfilt_mask,"1i");
+MODULE_PARM_DESC(canfilt_id,"CAN filter message ID");
+MODULE_PARM(canfilt_id,"1i");
+MODULE_PARM_DESC(canfilt_flags,"CAN filter flags");
+MODULE_PARM(canfilt_flags,"1i");
+MODULE_PARM_DESC(can_wait_sec,"number of seconds to wait between messages");
+MODULE_PARM(can_wait_sec,"1i");
+MODULE_PARM_DESC(prt_prefix_in,"string prefix for output");
+MODULE_PARM(prt_prefix_in,"1i");
+
+MODULE_SUPPORTED_DEVICE("sendburst_rtl");
+MODULE_AUTHOR("Pavel Pisa <pisa@cmp.felk.cvut.cz>");
+MODULE_DESCRIPTION("readburst_rtl: receiver of CAN messages for RT-Linux interface to LinCAN driver");
+MODULE_LICENSE("GPL");
+
+void readburst_cleanup(void *arg)
+{
+       printf("%scleanup handler called\n", prt_prefix);
+       close((int)arg);
+}
+
+#if 0
+int can_fd_wait(int fd, int wait_sec)
+{
+       int ret;
+       struct timeval timeout;
+       fd_set set;
+
+       FD_ZERO (&set);
+       FD_SET (fd, &set);
+       timeout.tv_sec = wait_sec;
+       timeout.tv_usec = 0;
+       while ((ret=select(FD_SETSIZE,&set, NULL, NULL,&timeout))==-1
+          &&errno==-EINTR);
+       return ret;
+}
+#endif
+
+int readburst_main(void *arg)
+{
+       int n,ret;
+       unsigned long i=0;
+       struct canmsg_t readmsg={0,0,5,0,0,{0,}};
+
+       if(canfilt_mask || canfilt_id || canfilt_flags){
+               canfilt_fl=1;
+               canfilt.mask=canfilt_mask;
+               canfilt.id=canfilt_id;
+               canfilt.flags=canfilt_flags;
+       }
+
+       if ((fd=open(can_dev_name, O_RDWR)) < 0) {
+               printf("Error opening %s\n", can_dev_name);
+               return -1;      
+       }
+        pthread_cleanup_push(readburst_cleanup,(void*)fd);
+
+       snprintf(prt_prefix, PRT_PREFIX_SIZE, prt_prefix_in, can_dev_name);
+       
+       if (canfilt_fl) {
+               ret = ioctl(fd, CANQUE_FILTER, &canfilt);
+               if(ret<0) {
+                       printf("%serror in call ioctl FILTER_QUE",prt_prefix);
+               }
+       }
+
+       
+       while (1) {
+               readmsg.flags=0;
+               readmsg.cob=0;
+               readmsg.timestamp=0;
+           #if 0
+               ret=can_fd_wait(fd, can_wait_sec);
+               printf("%scan_fd_wait returned %d\n", prt_prefix, ret);
+           #endif
+               ret=read(fd,&readmsg,sizeof(struct canmsg_t));
+               if(ret <0) {
+                       printf("%sError reading message\n", prt_prefix);
+               }
+               else if(ret == 0) {
+                       printf("%sNo message arrived\n", prt_prefix);
+               } else {
+                       printf("%sRx msg #%lu: id=%lX dlc=%u flg=0x%02x",
+                               prt_prefix,i,readmsg.id,readmsg.length,readmsg.flags);
+                       for(n=0 ; n<readmsg.length ; n++)
+                               printf(" %.2X",(unsigned char)readmsg.data[n]);
+                       printf("\n");
+                       i++;
+               }
+       }
+       /* close(fd); is called by cleanup handler*/
+        pthread_cleanup_pop(1);
+       return 0;
+}
+
+/*===========================================================*/
+
+
+void * t1_routine(void *arg)
+{
+  readburst_main(NULL);
+
+  while (1) {
+    pthread_wait_np ();
+
+  }
+  return 0;
+}
+
+pthread_t t1;
+
+int init_module(void) {
+       
+        return pthread_create (&t1, NULL, t1_routine, 0);
+
+}
+
+void cleanup_module(void) {
+        pthread_delete_np (t1);
+}
diff --git a/lincan/utils/sendburst_rtl.c b/lincan/utils/sendburst_rtl.c
new file mode 100644 (file)
index 0000000..45a69fd
--- /dev/null
@@ -0,0 +1,119 @@
+#include <rtl.h>
+#include <time.h>
+#include <signal.h>
+#include <pthread.h>
+#include <posix/unistd.h>
+
+#define printf rtl_printf
+
+#include "../include/can.h"
+
+int canmsg_flags = 0;
+unsigned long canmsg_id = 5;
+int block = 10;
+int count = 0;
+
+int can_wait_sec = 1;
+int o_sync_fl = 0;
+
+char *can_dev_name = "/dev/can0";
+
+#define PRT_PREFIX_SIZE 40
+char prt_prefix[PRT_PREFIX_SIZE];
+
+char *prt_prefix_in = "CAN %s : ";
+
+MODULE_PARM_DESC(can_dev_name,"name of CAN device [/dev/can0]");
+MODULE_PARM(can_dev_name,"1s");
+MODULE_PARM_DESC(canmsg_id,"ID of generated messages");
+MODULE_PARM(canmsg_id,"1i");
+MODULE_PARM_DESC(canmsg_flags,"CAN filter flags");
+MODULE_PARM(canmsg_flags,"1i");
+MODULE_PARM_DESC(o_sync_fl,"open in synchronous mode");
+MODULE_PARM(o_sync_fl,"1i");
+MODULE_PARM_DESC(can_wait_sec,"number of seconds to wait between messages");
+MODULE_PARM(can_wait_sec,"1i");
+MODULE_PARM_DESC(block,"number of messages in  block");
+MODULE_PARM(block,"1i");
+MODULE_PARM_DESC(count,"number of sent blocks of messages");
+MODULE_PARM(count,"1i");
+MODULE_PARM_DESC(prt_prefix_in,"string prefix for output");
+MODULE_PARM(prt_prefix_in,"1i");
+
+
+MODULE_SUPPORTED_DEVICE("sendburst_rtl");
+MODULE_AUTHOR("Pavel Pisa <pisa@cmp.felk.cvut.cz>");
+MODULE_DESCRIPTION("sendburst_rtl: generatot of CAN messages for RT-Linux interface to LinCAN driver");
+MODULE_LICENSE("GPL");
+
+void sendburst_cleanup(void *arg)
+{
+       printf("%scleanup handler called\n", prt_prefix);
+       close((int)arg);
+}
+
+int sendburst_main(void *arg)
+{
+       struct canmsg_t sendmsg={0,0,5,0,8,{1,2,3,4,5,6,7,8}};
+       int fd, ret,i,j;
+
+
+       if ((fd=open(can_dev_name, O_RDWR | (o_sync_fl? O_SYNC:0))) < 0) {
+               printf("Error opening %s\n", can_dev_name);
+               return -1;
+       }
+        pthread_cleanup_push(sendburst_cleanup,(void*)fd);
+
+       snprintf(prt_prefix, PRT_PREFIX_SIZE, prt_prefix_in, can_dev_name);
+
+       j=0;
+       while (1) {
+               for(i=0;i<block;i++) {
+                       sendmsg.flags=canmsg_flags;
+                       sendmsg.id=canmsg_id;
+                       sendmsg.data[0]=i;
+                       sendmsg.data[1]=j;
+                       if ((ret=write(fd,&sendmsg,sizeof(struct canmsg_t))) < 0) {
+                               printf("%sError sending message\n", prt_prefix);
+                               break;
+                       }
+               }
+               printf("%sSent block of %d messages #: %u\n", prt_prefix, block, j);
+               j++;
+               pthread_testcancel();
+               usleep(1000000*can_wait_sec);
+               if(count)
+                       if(!--count) break;
+               pthread_testcancel();
+       }
+       /* close(fd); is called by cleanup handler*/
+        pthread_cleanup_pop(1);
+       return 0;
+}
+
+       
+/*===========================================================*/
+
+
+void * t1_routine(void *arg)
+{
+  sendburst_main(NULL);
+
+  while (1) {
+    pthread_wait_np ();
+
+  }
+  return 0;
+}
+
+pthread_t t1;
+
+int init_module(void) {
+       
+        return pthread_create (&t1, NULL, t1_routine, 0);
+
+}
+
+void cleanup_module(void) {
+        pthread_delete_np (t1);
+}