{"id":1415,"date":"2016-01-09T14:38:10","date_gmt":"2016-01-09T06:38:10","guid":{"rendered":"http:\/\/kaoru.tech\/?p=1415"},"modified":"2016-09-26T21:30:59","modified_gmt":"2016-09-26T13:30:59","slug":"1415","status":"publish","type":"post","link":"http:\/\/kaoru.tech:7000\/wordpress\/?p=1415","title":{"rendered":"CAN review"},"content":{"rendered":"<p>\u672c\u4eba\u6700\u65e9\u572806\u300107\u5e74\u5f00\u59cb\u641eCAN\u603b\u7ebf\uff0c\u91c7\u7528\u7684\u662fRM9200+SJA1000\u548cLPC2100\u901a\u4fe1\u3002<\/p>\n<p>\u5f53\u65f6CAN\u6709CANOpen\u548cDeviceNet 2\u79cd\u67b6\u6784\u4e4b\u5206\u3002\u6211\u4eec\u91c7\u7528\u4e86\u5f00\u6e90\u7684lincan-0.3.2\uff0c\u628aCAN\u6ce8\u518c\u4e3a\u4e00\u4e2achar\u8bbe\u5907\uff0c\u7136\u540e\u901a\u8fc7read\/write\u51fd\u6570\u8fdb\u884cCAN\u62a5\u6587\u7684\u63a5\u6536\u548c\u53d1\u9001\u3002<\/p>\n<p>\u6700\u8fd1\u73a9\u4e86freescale\u7684i.MX6UL\uff0c\u8fd9\u9897CPU\u672c\u8eab\u5177\u59072\u8defCAN\u603b\u7ebf\u3002<\/p>\n<p>\u67e5\u4e86\u4e0b\u5f53\u524dCAN\u7684\u652f\u6301\uff0c\u53d1\u73b0\u4ece2.6.25\u5f00\u59cb\uff0cCAN\u5df2\u7ecf\u88ab\u5f15\u5165\u5230linux\u5185\u6838\u4e2d\uff0c\u5e76\u88ab\u4f5c\u4e3a\u4e00\u4e2asocket\u8bbe\u5907\u8fdb\u884c\u7ba1\u7406\u3002<\/p>\n<h2>\u5de5\u5177<\/h2>\n<p>\u7531\u4e8eCAN\u88ab\u6574\u5408\u8fdbnetwork\uff0c\u6240\u4ee5\u9700\u8981\u65b0\u7684ip\u624d\u80fd\u652f\u6301\uff0c<a href=\"http:\/\/www.linuxfoundation.org\/collaborate\/workgroups\/networking\/iproute2\/\">\u70b9\u51fb\u8fdb\u5b98\u7f51<\/a>\u3002\u6216\u8005\u53ef\u4ee5\u4f7f\u7528GIT\u540c\u6b65\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">$ git clone git:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/shemminger\/iproute2.git<\/pre>\n<h2>\u5e38\u7528\u7684CAN\u547d\u4ee4<\/h2>\n<p>\u67e5\u770b\u53ef\u8bbe\u7f6e\u7684\u914d\u7f6e\u53c2\u6570\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">    $ ip link set can0 type can help\r\n    Usage: ip link set DEVICE type can\r\n        [ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |\r\n        [ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\r\n          phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\r\n\r\n        [ loopback { on | off } ]\r\n        [ listen-only { on | off } ]\r\n        [ triple-sampling { on | off } ]\r\n\r\n        [ restart-ms TIME-MS ]\r\n        [ restart ]\r\n\r\n        Where: BITRATE       := { 1..1000000 }\r\n               SAMPLE-POINT  := { 0.000..0.999 }\r\n               TQ            := { NUMBER }\r\n               PROP-SEG      := { 1..8 }\r\n               PHASE-SEG1    := { 1..8 }\r\n               PHASE-SEG2    := { 1..8 }\r\n               SJW           := { 1..4 }\r\n               RESTART-MS    := { 0 | NUMBER }\r\n<\/pre>\n<p>\u8bbe\u7f6eCAN\u6ce2\u7279\u7387\u4e3a1Mbps\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">$ ip link set can0 up type can bitrate 1000000<\/pre>\n<p>\u67e5\u770bCAN\u7684\u914d\u7f6e\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">$ ip -s -d link show can0         \r\n2: can0: &lt;NOARP,UP,LOWER_UP,ECHO&gt; mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10\r\n    link\/can  promiscuity 0 \r\n    can  state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 \r\n          bitrate 1000000 sample-point 0.733 \r\n          tq 66 prop-seg 5 phase-seg1 5 phase-seg2 4 sjw 1\r\n          flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1\r\n          clock 30000000\r\n          re-started bus-errors arbit-lost error-warn error-pass bus-off\r\n          0          0          0          1          0          0         \r\n    RX: bytes  packets  errors  dropped overrun mcast   \r\n    44427      7830     0       0       0       0      \r\n    TX: bytes  packets  errors  dropped carrier collsns \r\n    29         29       0       0       0       0<\/pre>\n<p>\u542f\u52a8\/\u505c\u6b62CAN\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">$ ip link set can0 up\/down<\/pre>\n<p>\u6216\u8005<\/p>\n<pre class=\"lang:sh decode:true\">$ ifconfig can0 up\/down<\/pre>\n<p>\u63a5\u6536CAN\u62a5\u6587\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">$ candump can0<\/pre>\n<p>\u53d1\u9001CAN\u62a5\u6587<\/p>\n<pre class=\"lang:sh decode:true\">$ cansend &lt;device&gt; &lt;can_frame&gt;<\/pre>\n<p>\u4f8b\u5982\u4f7f\u7528\u901a\u9053CAN1\u53d1\u9001CAN ID\u4e3a1\uff0c\u5e26\u67095\u4e2a\u6570\u636e\uff080x01 0x23 0x45 0x67 0x89\uff09\u7684\u62a5\u6587\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">$ cansend can1 001#0123456789<\/pre>\n<p>\u53d1\u9001\u8fdc\u7a0b\u8bf7\u6c42\u5e27\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">$ cansend can1 500#R<\/pre>\n<p>\u5982\u679c\u5bf9\u65b9\u4f7f\u7528candump\u63a5\u6536\uff0c\u5219\u4f1a\u663e\u793a\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">$ candump can0\r\n  can0  001   [5]  01 23 45 67 89\r\n  can0  500   [0]  remote request<\/pre>\n<p>\u53d1\u9001<\/p>\n<h2>\u53c2\u8003<\/h2>\n<ul>\n<li>https:\/\/en.wikipedia.org\/wiki\/SocketCAN<\/li>\n<li>Linux\/Documentation\/networking\/can.txt<\/li>\n<li>https:\/\/github.com\/linux-can\/can-utils\/<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u4eba\u6700\u65e9\u572806\u300107\u5e74\u5f00\u59cb\u641eCAN\u603b\u7ebf\uff0c\u91c7\u7528\u7684\u662fRM9200+SJA1000\u548cLPC2100\u901a\u4fe1\u3002 \u5f53\u65f6CAN\u6709CANOpen\u548cDeviceNet 2\u79cd\u67b6\u6784\u4e4b\u5206\u3002\u6211\u4eec\u91c7\u7528\u4e86\u5f00\u6e90\u7684lincan-0.3.2\uff0c\u628aCAN\u6ce8\u518c\u4e3a\u4e00\u4e2achar\u8bbe\u5907\uff0c\u7136\u540e\u901a\u8fc7read\/write\u51fd\u6570\u8fdb\u884cCAN\u62a5\u6587\u7684\u63a5\u6536\u548c\u53d1\u9001\u3002 \u6700\u8fd1\u73a9\u4e86freescale\u7684i.MX6UL\uff0c\u8fd9\u9897CPU\u672c\u8eab\u5177\u59072\u8defCAN\u603b\u7ebf\u3002 \u67e5\u4e86\u4e0b\u5f53\u524dCAN\u7684\u652f\u6301\uff0c\u53d1\u73b0\u4ece2.6.25\u5f00\u59cb\uff0cCAN\u5df2\u7ecf\u88ab\u5f15\u5165\u5230linux\u5185\u6838\u4e2d\uff0c\u5e76\u88ab\u4f5c\u4e3a\u4e00\u4e2asocket\u8bbe\u5907\u8fdb\u884c\u7ba1\u7406\u3002 \u5de5\u5177 \u7531\u4e8eCAN\u88ab\u6574\u5408\u8fdbnetwork\uff0c\u6240\u4ee5\u9700\u8981\u65b0\u7684ip\u624d\u80fd\u652f\u6301\uff0c\u70b9\u51fb\u8fdb\u5b98\u7f51\u3002\u6216\u8005\u53ef\u4ee5\u4f7f\u7528GIT\u540c\u6b65\u4ee3\u7801\uff1a $ git clone git:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/shemminger\/iproute2.git \u5e38\u7528\u7684CAN\u547d\u4ee4 \u67e5\u770b\u53ef\u8bbe\u7f6e\u7684\u914d\u7f6e\u53c2\u6570\uff1a $ ip link set can0 type can help Usage: ip link set DEVICE type can [ bitrate&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[35],"tags":[216],"class_list":["post-1415","post","type-post","status-publish","format-standard","hentry","category-can","tag-can"],"_links":{"self":[{"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1415"}],"version-history":[{"count":8,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1415\/revisions"}],"predecessor-version":[{"id":1650,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1415\/revisions\/1650"}],"wp:attachment":[{"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1415"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}