* [Xenomai] xeno 3-rc7 : rtcanconfig fails to set baudrate @ 2015-08-18 16:26 Frederik Bayart 2015-08-18 17:25 ` Philippe Gerum 0 siblings, 1 reply; 4+ messages in thread From: Frederik Bayart @ 2015-08-18 16:26 UTC (permalink / raw) To: xenomai@xenomai.org I have build xeno-3.0.rc7 with kernel 3.18.12. I have a PEAK-PCIe CAN card in my system. Drivers are loaded and rtcan0 en rtcan1 are created in /proc/rtcan. However, I'm not able to set the baudrate when I'm execute 'rtcanconfig rtcan0 -v -b 1000000 start' By adding debug statements in rtcanconfig, I found that ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); fails, errno gives : SIOCSCANBAUDRATE(errno=19): No such device Below the output of rtcan0/info and xeno-config --info Any suggestions ? Frederik $cat ./rtcan0/info Device rtcan0 Controller SJA1000 Board PEAK-PCI Clock-Hz 8000000 Baudrate undefined Bit-time brp=0 prop_seg=0 phase_seg1=0 phase_seg2=0 sjw=0 sam=0 Ctrl-Mode State stopped TX-Counter 0 RX-Counter 0 Errors 0 Refcount 0 $ xeno-config --info Xenomai version: Xenomai/cobalt v3.0-rc7 -- Linux dev1 3.18.12-x86-64-xeno-3.0.rc7 #1 SMP PREEMPT Tue Aug 18 16:33:55 CEST 2015 x86_64 GNU/Linux Kernel parameters: BOOT_IMAGE=/vmlinuz-3.18.12-x86-64-xeno-3.0.rc7 root=UUID=20f2dd2f-f02f-4b82-8538-8fe52e55a8ff ro quiet I-pipe release #1 detected Cobalt core 3.0-rc7 detected Compiler: gcc version 4.9.2 (Debian 4.9.2-10) Build args: --prefix=/usr --includedir=/usr/include/xenomai --mandir=/usr/share/man --with-testdir=/usr/lib/xenomai/testsuite --with-core=cobalt --enable-smp --enable-pshared --enable-registry --build x86_64-linux-gnu build_alias=x86_64-linux-gnu ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai] xeno 3-rc7 : rtcanconfig fails to set baudrate 2015-08-18 16:26 [Xenomai] xeno 3-rc7 : rtcanconfig fails to set baudrate Frederik Bayart @ 2015-08-18 17:25 ` Philippe Gerum 2015-08-19 16:29 ` Frederik Bayart 0 siblings, 1 reply; 4+ messages in thread From: Philippe Gerum @ 2015-08-18 17:25 UTC (permalink / raw) To: Frederik Bayart, xenomai@xenomai.org On 08/18/2015 06:26 PM, Frederik Bayart wrote: > I have build xeno-3.0.rc7 with kernel 3.18.12. > I have a PEAK-PCIe CAN card in my system. > Drivers are loaded and rtcan0 en rtcan1 are created in /proc/rtcan. > > However, I'm not able to set the baudrate when I'm execute 'rtcanconfig rtcan0 -v -b 1000000 start' > > By adding debug statements in rtcanconfig, I found that ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); fails, > > errno gives : SIOCSCANBAUDRATE(errno=19): No such device > > Below the output of rtcan0/info and xeno-config --info > > Any suggestions ? This error is documented, I would check ->ifr_name in the request block: http://www.xenomai.org/documentation/xenomai-3/html/xeno3prm/group__rtdm__can.html#ga7c070037c218b40de849ebf4d299f977 -- Philippe. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai] xeno 3-rc7 : rtcanconfig fails to set baudrate 2015-08-18 17:25 ` Philippe Gerum @ 2015-08-19 16:29 ` Frederik Bayart 2015-08-19 16:38 ` Philippe Gerum 0 siblings, 1 reply; 4+ messages in thread From: Frederik Bayart @ 2015-08-19 16:29 UTC (permalink / raw) To: xenomai@xenomai.org >On Tuesday, 18 August 2015, 19:25, Philippe Gerum <rpm@xenomai.org> wrote: >> On 08/18/2015 06:26 PM, Frederik Bayart wrote: > >> I have build xeno-3.0.rc7 with kernel 3.18.12. >> I have a PEAK-PCIe CAN card in my system. >> Drivers are loaded and rtcan0 en rtcan1 are created in /proc/rtcan. >> >> However, I'm not able to set the baudrate when I'm execute 'rtcanconfig rtcan0 -v -b 1000000 start' >> By adding debug statements in rtcanconfig, I found that ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); fails, >> errno gives : SIOCSCANBAUDRATE(errno=19): No such device >> Below the output of rtcan0/info and xeno-config --info >> Any suggestions ? > >This error is documented, I would check ->ifr_name in the request block: > >http://www.xenomai.org/documentation/xenomai-3/html/xeno3prm/group__rtdm__can.html#ga7c070037c218b40de849ebf4d299f977 > >-- >Philippe. The problem was that the interface name was overwritten by the baudrate. The problem is caused by use of union { struct ifreq ifr; struct can_bittime bittime; can_baudrate_t baudrate; can_ctrlmode_t ctrlmode; can_mode_t mode; } u; I think the intention was to put struct ifreq.ifr_ifru in the union. But I think the union above doesn't work because struct ifreq has first member ifr_ifrn struct ifreq { #define IFHWADDRLEN 6 union { char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */ } ifr_ifrn; union { ...snip... } ifr_ifru; }; If I revert the union, the problem is solved. Diff below. Frederik --- rtcanconfig.c.old 2015-08-19 17:57:45.790326526 +0200 +++ rtcanconfig.c.new 2015-08-19 18:00:15.010330204 +0200 @@ -88,16 +88,10 @@ int new_ctrlmode = 0, set_ctrlmode = 0; int verbose = 0; int bittime_count = 0, bittime_data[6]; + struct ifreq ifr; can_baudrate_t *baudrate; can_ctrlmode_t *ctrlmode; can_mode_t *mode; - union { - struct ifreq ifr; - struct can_bittime bittime; - can_baudrate_t baudrate; - can_ctrlmode_t ctrlmode; - can_mode_t mode; - } u; struct can_bittime *bittime; int opt, ret; char* ptr; @@ -169,7 +163,7 @@ } strncpy(ifname, argv[optind], IFNAMSIZ); - strncpy(u.ifr.ifr_name, ifname, IFNAMSIZ); + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); if (optind == argc - 2) { /* Get mode setting */ new_mode = string_to_mode(argv[optind + 1]); @@ -187,7 +181,7 @@ return can_fd; } - ret = ioctl(can_fd, SIOCGIFINDEX, &u.ifr); + ret = ioctl(can_fd, SIOCGIFINDEX, &ifr); if (ret) { fprintf(stderr,"Can't get interface index for %s, code = %d\n", ifname, ret); return ret; @@ -197,16 +191,15 @@ if (new_baudrate != -1) { if (verbose) printf("baudrate: %d\n", new_baudrate); - baudrate = &u.baudrate; + baudrate = (can_baudrate_t *)&ifr.ifr_ifru; *baudrate = new_baudrate; - ret = ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); + ret = ioctl(can_fd, SIOCSCANBAUDRATE, &ifr); if (ret) { goto abort; } } - if (bittime_count) { - bittime = &u.bittime; + bittime = (struct can_bittime *)&ifr.ifr_ifru; if (bittime_count == 2) { bittime->type = CAN_BITTIME_BTR; bittime->btr.btr0 = bittime_data[0]; @@ -233,7 +226,7 @@ bittime->std.sam); } - ret = ioctl(can_fd, SIOCSCANCUSTOMBITTIME, &u.ifr); + ret = ioctl(can_fd, SIOCSCANCUSTOMBITTIME, &ifr); if (ret) { goto abort; } @@ -241,20 +234,20 @@ } if (set_ctrlmode != 0) { - ctrlmode = &u.ctrlmode; + ctrlmode = (can_ctrlmode_t *)&ifr.ifr_ifru; *ctrlmode = new_ctrlmode; if (verbose) printf("ctrlmode: %#x\n", new_ctrlmode); - ret = ioctl(can_fd, SIOCSCANCTRLMODE, &u.ifr); + ret = ioctl(can_fd, SIOCSCANCTRLMODE, &ifr); if (ret) { goto abort; } } if (new_mode != -1) { - mode = &u.mode; + mode = (can_mode_t *)&ifr.ifr_ifru; *mode = new_mode; - ret = ioctl(can_fd, SIOCSCANMODE, &u.ifr); + ret = ioctl(can_fd, SIOCSCANMODE, &ifr); if (ret) { goto abort; } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai] xeno 3-rc7 : rtcanconfig fails to set baudrate 2015-08-19 16:29 ` Frederik Bayart @ 2015-08-19 16:38 ` Philippe Gerum 0 siblings, 0 replies; 4+ messages in thread From: Philippe Gerum @ 2015-08-19 16:38 UTC (permalink / raw) To: Frederik Bayart, xenomai@xenomai.org On 08/19/2015 06:29 PM, Frederik Bayart wrote: >> On Tuesday, 18 August 2015, 19:25, Philippe Gerum <rpm@xenomai.org> wrote: >>> On 08/18/2015 06:26 PM, Frederik Bayart wrote: >> >>> I have build xeno-3.0.rc7 with kernel 3.18.12. >>> I have a PEAK-PCIe CAN card in my system. >>> Drivers are loaded and rtcan0 en rtcan1 are created in /proc/rtcan. >>> >>> However, I'm not able to set the baudrate when I'm execute 'rtcanconfig rtcan0 -v -b 1000000 start' >>> By adding debug statements in rtcanconfig, I found that ioctl(can_fd, SIOCSCANBAUDRATE, &u.ifr); fails, >>> errno gives : SIOCSCANBAUDRATE(errno=19): No such device >>> Below the output of rtcan0/info and xeno-config --info >>> Any suggestions ? >> >> This error is documented, I would check ->ifr_name in the request block: >> >> http://www.xenomai.org/documentation/xenomai-3/html/xeno3prm/group__rtdm__can.html#ga7c070037c218b40de849ebf4d299f977 >> >> -- >> Philippe. > > > The problem was that the interface name was overwritten by the baudrate. The problem is caused by use of > > union { > struct ifreq ifr; > struct can_bittime bittime; > can_baudrate_t baudrate; > can_ctrlmode_t ctrlmode; > can_mode_t mode; > } u; > > I think the intention was to put struct ifreq.ifr_ifru in the union. But I think the union above doesn't work because struct ifreq has first member ifr_ifrn I broke this code: commit 78e77431163e35a3dafb30c86cc71fa167c7faa2 Author: Philippe Gerum <rpm@xenomai.org> Date: Thu Dec 1 19:02:42 2011 +0100 utils/rtcanconfig: fix aliasing But we can't just revert it, the data aliasing is wrong. I'll have a look, thanks for the debug work. -- Philippe. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-08-19 16:38 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-08-18 16:26 [Xenomai] xeno 3-rc7 : rtcanconfig fails to set baudrate Frederik Bayart 2015-08-18 17:25 ` Philippe Gerum 2015-08-19 16:29 ` Frederik Bayart 2015-08-19 16:38 ` Philippe Gerum
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.