[prev in list] [next in list] [prev in thread] [next in thread] 

List:       uclinux-dev
Subject:    [uClinux-dev] patch for can4linux test program in
From:       "David Wu" <davidwu () arcturusnetworks ! com>
Date:       2008-09-30 17:42:05
Message-ID: op.uia14fdoqigx4y () cyprus ! local
[Download RAW message or body]

Hi Greg and all,

This patch applys to user/can4linux in uClinux-dist-200808008.

can_send.c
    -- added set_mask() to setup MASK for RX frame ID
    -- modified test3 to test more byte patterns and make sure each pattern  
is unique

receive.c
    -- added option to change baud rate
    -- added option to set mask
    -- option "t" for continuous test
       transmitter will send 6 group of data continuously
       receiver will check each 6 group of data with the first 6 group of  
data.
       receiver will exit on mismatch.

example:
run "receive -t -b 500" on receiver
and then run "can_send -m -b 500 -D can0 -t3 -s10" on trasmitter

-- 
David Wu
["user_can4linux.patch" (user_can4linux.patch)]

diff -urN user/can4linux/can_send.c user/can4linux/can_send.c
--- user/can4linux/can_send.c	2006-06-13 01:58:13.000000000 -0400
+++ user/can4linux/can_send.c	2008-09-30 13:15:22.000000000 -0400
@@ -62,7 +62,7 @@
 int baud		 = -1;		/* dont change baud rate */
 int priority		 = -1;		/* dont change priority rate */
 int canreset		 = FALSE;
-
+int mask                 = 0;
 /* functions */
 void clean_process(void);
 void test1(void);
@@ -122,6 +122,21 @@
     	);
 }
 
+int set_mask( int fd )
+{
+
+int ret;
+Config_par_t  cfg;
+
+    cfg.target = CONF_ACCM; 
+    cfg.val1   = 0xffffffff; /* mask */
+    cfg.val2   = 0xffffffff; /* mask */
+
+    ret = ioctl(fd, CONFIG, &cfg);
+
+    return ret;
+}
+
 int can_reset( void ) {
 
 int ret;
@@ -173,7 +188,7 @@
     message.data[6] = 7;
     message.data[7] = 0xaa;
 
-    while ((c = getopt(argc, argv, "b:dehl:rp:s:n:D:t:T:VR")) != EOF) {
+    while ((c = getopt(argc, argv, "b:dehl:rp:s:mn:D:t:T:VR")) != EOF) {
 	switch (c) {
 	    case 'r':
 		rtr = TRUE;
@@ -218,6 +233,9 @@
 	    case 's':
 		sleeptime = atoi(optarg);
 		break;
+	    case 'm':
+		mask = 1;
+		break;
 	    case 'n':
 		node = atoi(optarg);
 		sprintf(device, "/dev/canp%d", node);
@@ -261,7 +279,7 @@
     if ( argc - optind > 0 ) {
     	/* also data bytes areg given with the command */
 	cnt = 0;
-	while(optind != argc) {
+	while(optind != argc && cnt < 8) {
 	    message.data[cnt++] = strtol(argv[optind++], NULL, 0);
 	}
 	message.length = cnt;
@@ -299,7 +317,10 @@
 	if ( debug == TRUE ) {
 	    printf("Open device %s\n", device);
 	}
-	can_fd = open(device, O_RDWR);
+        if(!mask) 
+	    can_fd = open(device, O_WRONLY);
+	else
+            can_fd = open(device, O_RDWR);
 	if (can_fd == -1) {
 	    fprintf(stderr, "open error %d;", errno);
 	    perror(device);
@@ -421,7 +442,7 @@
  eingabe dezimal 100 or hex 0x64\n\
 -r send message as rtr message.\n\
 -e send message in extended message format.\n\
--l load try to reach this bus load, given in %\n\
+-l load try to reach this bus load, given in %%\n\
 -s n - sleeptime between messages in ms, if not specified send single message\n\
 -d   - debug On\n\
        schaltet zusaetzlich Debugging im Treiber an/aus\n\
@@ -648,9 +669,10 @@
 void test3(void)
 {
 long int test_count = 0;
-canmsg_t tm[5];
+canmsg_t tm[6];
 int ret;
 unsigned int cnt = 0;
+int i;
 
 struct timespec req;
 /* struct timespec rem; */
@@ -664,14 +686,14 @@
     if (extd) {
 	tm[0].flags |= MSG_EXT;
     }
-    tm[0].data[0] = 0x55;
+    tm[0].data[0] = 0x11;
     tm[0].data[1] = 2;
     tm[0].data[2] = 3;
     tm[0].data[3] = 4;
     tm[0].data[4] = 5;
     tm[0].data[5] = 6;
     tm[0].data[6] = 7;
-    tm[0].data[7] = 0xaa;
+    tm[0].data[7] = 0x11;
 
     tm[1].id = tm[0].id + ID_OFFSET;
     tm[1].cob = 0;
@@ -680,22 +702,26 @@
     if (extd) {
 	tm[1].flags |= MSG_EXT;
     }
-    tm[1].data[0] = 0xaa;
+    tm[1].data[0] = 0x22;
     tm[1].data[1] = 7;
     tm[1].data[2] = 6;
     tm[1].data[3] = 5;
     tm[1].data[4] = 4;
     tm[1].data[5] = 3;
     tm[1].data[6] = 2;
-    tm[1].data[7] = 0x55;
+    tm[1].data[7] = 0x22;
 
     tm[2].id = tm[1].id + ID_OFFSET;
     tm[2].cob = 0;
-    tm[2].length = 0;
+    tm[2].length = 8;
     tm[2].flags = 0;
     if (extd) {
 	tm[2].flags |= MSG_EXT;
     }
+    tm[2].data[0] = 0x33;
+    for(i=1; i< 7; i++)
+        tm[2].data[i] = 0x00;
+    tm[2].data[7] = 0x33;
 
     tm[3].id = tm[2].id + ID_OFFSET;
     tm[3].cob = 0;
@@ -704,24 +730,40 @@
     if (extd) {
 	tm[3].flags |= MSG_EXT;
     }
-    tm[3].data[0] = 0x55;
-    tm[3].data[1] = 2;
-    tm[3].data[2] = 3;
-    tm[3].data[3] = 4;
-    tm[3].data[4] = 5;
-    tm[3].data[5] = 6;
-    tm[3].data[6] = 7;
-    tm[3].data[7] = 0xaa;
+    for(i=0; i< 8; i++)
+        tm[3].data[i] = 0x44;
 
     tm[4].id = tm[3].id + ID_OFFSET;
     tm[4].cob = 0;
-    tm[4].length = 4;
+    tm[4].length = 8;
     tm[4].flags = 0;
-    *(unsigned int *)&tm[4].data[0] = cnt++;
-
     if (extd) {
 	tm[4].flags |= MSG_EXT;
     }
+    tm[4].data[0] = 0x55;
+    tm[4].data[1] = 2;
+    tm[4].data[2] = 3;
+    tm[4].data[3] = 4;
+    tm[4].data[4] = 4;
+    tm[4].data[5] = 3;
+    tm[4].data[6] = 2;
+    tm[4].data[7] = 0x55;
+
+    tm[5].id = tm[4].id + ID_OFFSET;
+    tm[5].cob = 0;
+    tm[5].length = 8;
+    tm[5].flags = 0;
+    if (extd) {
+	tm[5].flags |= MSG_EXT;
+    }
+    tm[5].data[0] = 0x66;
+    tm[5].data[1] = 0x26;
+    tm[5].data[2] = 0x35;
+    tm[5].data[3] = 0x44;
+    tm[5].data[4] = 0x53;
+    tm[5].data[5] = 0x62;
+    tm[5].data[6] = 0x71;
+    tm[5].data[7] = 0x66;
 
 #if 1
 	/*
@@ -735,10 +777,10 @@
 	    printf("Sleep %ld.%09ld\n", req.tv_sec, req.tv_nsec);
 	}
 #endif
-
+    if(mask) set_mask(can_fd);
 
     do {
-	ret = write(can_fd, &tm[0], 5);
+	ret = write(can_fd, &tm[0], 6);
 	if (ret == -1) {
 	    perror("write error");
 	    usleep(sleeptime); 
@@ -753,7 +795,7 @@
 	    }
 	}
 
-	*(unsigned int *)&tm[4].data[0] = cnt++;
+	/* *(unsigned int *)&tm[4].data[0] = cnt++; Don't change the data */
 	if (++test_count == test_count_soll) {
 	    break;
 	}
diff -urN user/can4linux/Makefile user/can4linux/Makefile
--- user/can4linux/Makefile	2006-06-13 01:58:13.000000000 -0400
+++ user/can4linux/Makefile	2008-09-12 15:59:02.000000000 -0400
@@ -26,7 +26,7 @@
 clean:
 	rm -f $(EXEC) *.elf *.gdb *.o
 
-romfs:
-	$(ROMFSINST) /bin/can_send
-	$(ROMFSINST) /bin/ctest
-	$(ROMFSINST) /bin/receive
+install romfs:
+	$(ROMFSINST) $(TUSRBINDIR)/bin/can_send
+	$(ROMFSINST) $(TUSRBINDIR)/bin/ctest
+	$(ROMFSINST) $(TUSRBINDIR)/bin/receive
diff -urN user/can4linux/receive.c user/can4linux/receive.c
--- user/can4linux/receive.c	2003-07-17 20:11:46.000000000 -0400
+++ user/can4linux/receive.c	2008-09-12 15:59:52.000000000 -0400
@@ -9,45 +9,127 @@
 
 #define STDDEV "can0"
 
-int main(int argc,char **argv)
+#define TotalMessages 6
+
+int     set_bitrate(
+        int fd,                 /* device descriptor */
+        int baud                /* bit rate */
+        )
 {
-int fd;
-int got;
-canmsg_t rx;
-char device[40];
+Config_par_t  cfg;
+volatile Command_par_t cmd;
 
-    if(argc == 2) {
-	sprintf(device, "/dev/%s", argv[1]);
-    }
-    else {
-	sprintf(device, "/dev/%s", STDDEV);
+
+    cmd.cmd = CMD_STOP;
+    ioctl(fd, COMMAND, &cmd);
+
+    cfg.target = CONF_TIMING;
+    cfg.val1   = baud;
+    ioctl(fd, CONFIG, &cfg);
+
+    cmd.cmd = CMD_START;
+    ioctl(fd, COMMAND, &cmd);
+    return 0;
+}
+
+int set_mask( int fd, int mask )
+{
+
+int ret;
+Config_par_t  cfg;
+
+    cfg.target = CONF_ACCM;
+    cfg.val1   = mask; /* mask */
+    cfg.val2   = mask; /* mask */
+
+    ret = ioctl(fd, CONFIG, &cfg);
+
+    return ret;
+}
+
+
+
+int main(int argc,char **argv)
+{
+    int fd;
+    int got;
+    int i;
+    int test=0;
+    canmsg_t rx;
+    char device[40];
+    int baud = 125; /* default 125kbp*/
+    int c;
+    int M[TotalMessages];
+    int counter = 0;
+
+    sprintf(device, "/dev/%s", STDDEV);
+
+    while ((c = getopt(argc, argv, "b:D:t")) != EOF) {
+       switch (c) {
+            case 'b': baud = atoi(optarg); 
+            break;
+	    case 'D': sprintf(device, "/dev/%s", optarg);
+            break;
+            case 't': test=1; 
+            break;
+            default: break;
+       }
     }
-    printf("using CAN device %s\n", device);
+    printf("using CAN device %s with bit rate %d k\n", device, baud);
     
     if(( fd = open(device, O_RDWR )) < 0 ) {
 	fprintf(stderr,"Error opening CAN device %s\n", device);
         exit(1);
     }
+    set_bitrate(fd, baud);
 
     printf("waiting for msg at 0x%p:\n", &rx);
 
+    set_mask(fd, 0x0);
+
+    for(i = 0; i < TotalMessages; i++)
+        M[i] = 0;
+    i = 0;
     while(1) {
       got=read(fd, &rx, 1);
       if( got > 0) {
-	printf("Received with ret=%d: %12lu.%06lu id=%ld len=%d msg='%s' flags=0x%x \n",
+        if(test){
+              i %= TotalMessages;
+              if(M[i]){
+                  if(M[i] != rx.data[0]) {
+                      printf("missed 0x%02X\n", M[i]);
+          	      printf("loops:%d\n", counter);
+                      exit(-1);
+                  }
+              } else {
+                 M[i] = rx.data[0];
+              } 
+              i++;
+
+        } else {
+           printf("Received with ret=%d: %12lu.%06lu id=%ld len=%d flags=0x%x msg=[0x",
 		    got, 
 		    rx.timestamp.tv_sec,
 		    rx.timestamp.tv_usec,
-		    rx.id, rx.length, rx.data ,rx.flags );
-	fflush(stdout);
-      } else {
+		    rx.id, rx.length, rx.flags );
+	    for(i=0; i < rx.length; i++)
+               printf("%02X", rx.data[i]);
+	    printf("]\n");
+	    fflush(stdout);
+          }
+      counter++;
+      if((counter % 1000) == 0)
+          printf("loops:%d\n", counter);
+      }
+#if 0
+       else {
 	printf("Received with ret=%d\n", got);
 	fflush(stdout);
       }
-      sleep(1);
+	sleep(1);
+#endif
     }
 
-
     close(fd);
     return 0;
 }


_______________________________________________
uClinux-dev mailing list
uClinux-dev@uclinux.org
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by uclinux-dev@uclinux.org
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic