Agl2017-Socketcan-Print.Pdf

Agl2017-Socketcan-Print.Pdf

The CAN Subsystem of the Linux Kernel A Linux CAN driver swiss army knife for automotive use-cases Presentation for Automotive Grade Linux F2F, 201 -0!-0!, "icroc#i$ %&ar'sru#e( SocketCAN – concepts usa!e Controller Area Network simpli#e$ for ner$s ) "edia access *y C+"A,C- ) +tructure of a CAN frame. + - 1 r 3 A 3 C#ecksum CAN-13 3LC 3A?A @ C @ @;F ; ? 3 e %1> 8it( F %11,2= 8it( - @ s %! 8it( %0-6 8yte( L & L % 8it( Ar*itration Contro' Data C#eck Acknowled4e ) +im$'i/ed. 0CAN 1dentifier2 03ata 'en4t#2 03ata 05562 ) Content addressin4 %*y CAN 1denti/er 7 CAN 8us( ) No "AC , Node addresses , A-P , -outin4 9 :ust $'ain ;+1 Layer 2 ) 1ncom$ati*'e <$4rade CAN F3 %1+; 116=6-1.201>(, ex$'ained 'ater Oliver Hartkopp SocketCAN – concepts usa!e Application areas for the Controller Area Network ) 1ndustria' contro' a$$'ications %e545 usin4 t#e CANo$en $rotoco'( ) Food $rocessin4 %e545 on /s# traw'ers( ) Ae#ic'es %Passen4er Cars, ?rucks, Fork 'ifters, etc5( ) -esearc# %e545 Nuc'ear $#ysics( ) +$acecrafts, "arina ) ;i' $'atforms ) Bind ener4y $'ants ) "easurement , +ensors ) +$ecia' @ffects Oliver Hartkopp SocketCAN – concepts usa!e %sa!e of the CAN bus in a vehicle ) +im$le CAN *roadcast messa4es ) Cyclic sent CAN messa4es %for failure detection( ) "u'tip'ex CAN messa4es %containin4 an index for diCerent data $ayload( ) ?rans$ort $rotocols %virtual $oint-to-$oint connection via CAN, e545 1+;-?P: 1+; 1> D>-2( Oliver Hartkopp @very CAN #ardware vendor se'ls #is own driver driver se'ls #is own vendor #ardware @very CAN #ardware #is CAN *und'ed to vendor #ardware CAN a different c#an4e ?#e to a$$lication%E( CAN of t#e ada$tation t#e ur4es Lock-1n Aendor FG SocketCAN – concepts usa!e concepts – SocketCAN ) ) CAN a$$'ication $rotoco's and inte''igent content content inte''igent and a$$'ication $rotoco's CAN inuserspace to*e im$'emented need filters ;n'y one a$$lication can use t#e CAN *us time at a one a$$licationCAN ;n'y canuse t#e mode' driver Linux nostandard CAN was ?#ere ) ) ) ;$eratin4 system CAN driver protoco' application CAN contro''er CAN The former concepts for CAN access CAN for concepts former The Oliver Hartkopp Oliver &)&O &, CAN L)' CAN application *iagnosis &)&O CAN T+ CAN CAN L)' CAN application *iagnosis SocketCAN – concepts usa!e concepts – SocketCAN &)&O T(C 'osch (CNet messa!e mana!ement A$$'ication context ;$eratin4 system &ormer automotive CAN transport protocol implementations transport protocol CAN automotive &ormer Oliver Hartkopp Oliver )$ea- $rotocols inside t#e $rotocols o$eratin4 system context system o$eratin4 1m$'ement CAN transport CAN 1m$'ement ?imeouts for CAN trans$ortt#e in $rotoco's CAN ?imeoutsfor mi''isecondsran4eof can rea'iHed *e are in systems o$eration $rotoco's ?rans$ort ?CP,1P( from known art t#e of %e45?CP +tate ) ) SocketCAN – concepts usa!e concepts – SocketCAN A$$'ication context ;$eratin4 system &, 'osch (CNet CAN T+ CAN )$ea: Meet timin! restictions in the operatin! system context timin! Meet restictions system operatin! in )$ea: the Oliver Hartkopp Oliver SocketCAN – concepts usa!e Concept i$ea from 2//0 %rs says- 1ou are $escribin! 'S* Sockets Oliver Hartkopp SocketCAN – concepts usa!e New protocol family for the Controller Area Net"ork (+&3CAN4 W W B @-"ai' CAN CAN app'ication application Linux +ocket LayerLinux +ocket Layer CAN $rotocol family PFI1N@? PF_CAN 3iCerent CAN *ased $rotoco's ?CP <3P 1C"P -AB 8C" 1+;?P ?P20 ?P16 "CNet K1=J= 1P CAN receive /'ters Packet ProcessingPacket Processing CAN network driver eth0 et#J Oliver Hartkopp SocketCAN – concepts usa!e Implications of usin! network sockets ) @sta*lished socket $ro4rammin4 interface to t#e o$eratin4 system ) Network driver model for networkin4 #ardware %e545 @t#ernet cards) ) Protoco's and routin4 inside t#e o$eratin4 system %e545 for ?CP/1P) ) -andom num*er of instances of network $rotocols ) @xistin4 infrastructure for exam$le for ) efficient messa4e Mueues ) t#e inte4ration of network #ardware drivers Oliver Hartkopp SocketCAN – concepts usa!e The socket pro!rammin! interface example: CAN-over5WLAN Bridge (..) /* some source code – don’t worry */ int can; /* socket handle */ int wlan; struct can_frame mymsg; /* data structure for CA frames */ can ! socket("#_CA $ %&C'_()*A+$ CA _*A,); /* CA *A, %ocket */ wlan ! socket("#_- ./$ %&C'_()*A+$ 0); /* 1("/-" %ocket */ (..) /* set addresses and CA filters */ 2ind(can$ (struct sockaddr *)3can_addr$ si4eof(can_addr)); connect(wlan$ (struct sockaddr *)3in_addr$ si4eof(in_addr)); while (5) 6 read(can$ 3mymsg$ si4eof(struct can_frame)); write(wlan$ 3mymsg$ si4eof(struct can_frame)); 7 Oliver Hartkopp A$$'ication context ;$eratin4 system &)&O &, CAN L)' CAN application *iagnosis SocketCAN – concepts usa!e concepts – SocketCAN &)&O CAN T+ CAN CAN L)' CAN application *iagnosis &)&O T(C 'osch (CNet messa!e mana!ement A$$'ication context ;$eratin4 system Technical improvement with SocketCAN improvement Technical Oliver Hartkopp Oliver ?ransparency and multi-user capabilities multi-user and ?ransparency data structures (eg. struct can_frame( struct (eg. structures data PF_CAN family $rotocol the in incorporated $rotocols (e.g. bitrates) devices network of CAN characteristics %Nraw'( transport without protocols access CAN messages CAN of Filtering Performance ) ) ) ) ) ) ) operating systems %'ike QNX, BSD Unix, Windows) QNX, BSD Unix, %'ike systems operating Generic interface de/nition for the use in other in use the for de/nition interface Generic Definition of CAN specific of Definition users CAN from requirements the -ealizing ) ) ) SocketCAN – concepts usa!e concepts – SocketCAN A$$'ication context ;$eratin4 system The stan$ar$ize$ CAN pro!rammin! interface pro!rammin! CAN The stan$ar$ize$ Oliver Hartkopp Oliver SocketCAN – concepts usa!e Highlights of the protocol family PF3CAN +tandard 8+3 network socket A$p1 A$p2 A$$J $ro4rammin4 interface Linux +ocket Layer -eceive filter lists #andled PFI1N@? PFICAN inside a software interru$t %Linux N@?I-P softirM( -AB 8C" 1+;?P CAN receive /'ters network device driver mode' Packet Processing Network transparency. 'ocal ec#o of sent CAN frames on can0 can3 vcan0 successful transmission Oliver Hartkopp SocketCAN – concepts usa!e 7irtual CAN net"ork $evice driver (vcan4 ) No need for rea' CAN #ardware %availa*le since Linux 25D52>( ) Local echo of sent CAN frames ‘loo$*ack deviceR ) vcan instances can *e created at run-time ) Exam$le. -e$'ay of ve#icle 'o4 files CAN application candump S33 can$'ayer vcan0 55 vcan3 can0 55 canJ vcan0 55 vcan3 Oliver Hartkopp SocketCAN – concepts usa!e How to create a virtual CAN network device ) Loadin4 t#e virtual CAN driver into t#e Linux kerne' sudo mod8ro2e 9can ) Create a virtual CAN interface sudo i8 link add ty8e 9can sudo i8 link add de9 helga ty8e 9can sudo i8 link set 9can0 u8 sudo i8 link set helga u8 Oliver Hartkopp SocketCAN – concepts usa!e CAN network layer protocols an$ CAN frame processin! App1 App2 A$$J cangw Linux +ocket Layer PF_N@?LIN& PFI1N@? PF_CAN CAN GB -AB 8C" 1+;?P CAN receiveCAN /'ters receive /'ters CAN Odisc Packet Processing can0 can3 vcan0 vcan9 Oliver Hartkopp LP-n4 Pen4uin Lo4o *y Arne Geor4 G'editsc# (CC 8T-+A J50) SocketCAN – concepts usa!e CAN38A, – Rea$in! an$ writin! of raw CAN frames A$$1 A$$2 Ap$J can4w ) +imilar to known $ro4rammin4 interfaces Linux Socket Layer PFIN@?L1N& PFI1N@? PFICAN A socket fee's like a $rivate CAN interface CAN GB ) -AB BC" 1+;?P ) $er-socket CAN identifier receive /ltersets CAN receive /'ters CAN Odisc Packet Processin4 ) Linux timestam$s in nano second resolution can0 canJ vcan0 vcan= ) @asy mi4ration of existin4 CAN software ) "ulti$le a$$lications can run inde$endent'y ) Network transparency t#rou4# local echo of sent frames ) Functions can *e s$lit into different $rocesses Oliver Hartkopp SocketCAN – concepts usa!e CAN38A, – Example CAN-over5,LAN Brid!e WLAN-PCCard WLAN-PCCard Bire'ess LAN <3P,1P CAN-PCCard CAN-PCCard CAN CAN Oliver Hartkopp SocketCAN – concepts usa!e CAN38A, – Example CAN-over5,LAN Brid!e (..) /* some source code – don’t worry */ int can; /* socket handle */ int wlan; struct can_frame mymsg; /* data structure for CA frames */ can ! socket("#_CA $ %&C'_()*A+$ CA _*A,); /* CA *A, %ocket */ wlan ! socket("#_- ./$ %&C'_()*A+$ 0); /* 1("/-" %ocket */ (..) /* set addresses and CA filters */ 2ind(can$ (struct sockaddr *)3can_addr$ si4eof(can_addr)); connect(wlan$ (struct sockaddr *)3in_addr$ si4eof(in_addr)); while (5) 6 read(can$ 3mymsg$ si4eof(struct can_frame)); write(wlan$ 3mymsg$ si4eof(struct can_frame)); 7 Oliver Hartkopp htt$s.,,github5com,'inux-can/can-tests SocketCAN – concepts usa!e CAN38A, socket options /* for socket o8tions affecting the socket (not the glo2al system) */ enum 6 CA _*A,_#-:/.* ! 5$ /* set 0 .. n can_filter(s) */ CA _*A,_.**_#-:/.*$ /* set filter for error frames */ CA _*A,_:&&";AC'$ /* local loo82ack (default<on) */ CA _*A,_*.C=_&, _+%)%$ /* recei9e my own msgs (default<off) */ CA _*A,_#(_#*A+.%$ /* allow CA #( frames (default<off) */ CA _*A,_>&- _#-:/.*%$ /* all filters must match to trigger */ 7; /** * A filter matches$ when * * ?recei9ed_can_id@ 3 mask !! can_id 3 mask */ struct can_filter 6 canid_t can_id; canid_t can_mask; 7; htt$s.,,www5kernel5or4,doc,3ocumentation/networking,can.txt Oliver Hartkopp !51.1.1 CAN /'ter usage optimisation SocketCAN – concepts usa!e CAN38A, relate$ can-utils ) candum8 9 display, /lter and lo4 CAN data to /les ) cansend 9 send a sin4le frame ) cangen 9 4enerate %random( CAN traLc ) can8layer 9 re$lay CAN 'o4/les ) can2usload 9 calculate and disp'ay t#e CAN *usload Oliver

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    63 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us