“CAN overview”的版本间的差异

来自百问网嵌入式Linux wiki
 
(未显示同一用户的1个中间版本)
第1行: 第1行:
This article gives information about the Linux<sup>&reg;</sup> Controller Area Network (CAN) framework.
+
本文提供有关 Linux<sup>&reg;</sup> 控制器局域网(CAN)框架的信息。
It explains how to activate the CAN interface and, based on examples, how to use it.
+
它说明了如何激活CAN接口以及基于示例的使用方法。
  
 
== Framework purpose ==
 
== Framework purpose ==
The '''Controller Area Network''' (CAN) is a multi-master serial bus standard connecting at least two nodes. It is a message-based protocol originally designed for in-vehicle communication and which main benefits are a significant reduction of wiring and the prevention of message collision.
+
'''Controller Area Network'''(CAN)是一种多主机串行总线标准,它连接至少两个节点。 它是一种基于消息的协议,最初是为车载通信而设计的,其主要优点是显着减少了接线并防止了消息冲突。
  
For better real-time performance, CAN with Flexible Data-Rate (CAN FD)<ref>[https://www.can-cia.org/can-knowledge/can/can-fd/ CAN FD - The basic idea], from the CAN in Automation group (CiA)</ref> is used as an extension to the classic CAN protocol<ref>[https://www.can-cia.org/can-knowledge/can/can-implementations/ CAN protocol implementations], from the CAN in Automation group (CiA)</ref>. It allows data rates higher than 1 MBit/s and payloads longer than 8 bytes per frame (up to 64 data bytes).
+
为了获得更好的实时性能,具有灵活数据速率(CAN FD)的CAN<ref>[https://www.can-cia.org/can-knowledge/can/can-fd/ CAN FD - The basic idea], from the CAN in Automation group (CiA)</ref> 用作经典CAN协议的扩展<ref>[https://www.can-cia.org/can-knowledge/can/can-implementations/ CAN protocol implementations], from the CAN in Automation group (CiA)</ref>. 它允许的数据速率高于1 MBit/s有效载荷则超过每帧8个字节(最多64个数据字节)。
  
'''SocketCAN''' <ref name=SocketCAN>{{CodeSource | Linux kernel | Documentation/networking/can.rst | Kernel SocketCAN documentation}}, Linux Foundation</ref> is a uniform CAN Framework for the Linux kernel. It implements a new protocol family called '''PF_CAN'''<ref name=PF_CAN>{{CodeSource | Linux kernel | net/can/af_can.c | net/can/af_can.c}}, Protocol family CAN core module</ref> and allows applications to receive and transmit CAN messages via Socket APIs with CAN specific socket options.
+
'''SocketCAN''' <ref name=SocketCAN>{{CodeSource | Linux kernel | Documentation/networking/can.rst | Kernel SocketCAN documentation}}, Linux Foundation</ref> 是用于Linux内核的统一CAN框架。 它实现了一个名为'''PF_CAN'''<ref name=PF_CAN>{{CodeSource | Linux kernel | net/can/af_can.c | net/can/af_can.c}}, Protocol family CAN core module</ref> 并允许应用程序通过具有CAN特定套接字选项的套接字API接收和传输CAN消息。
 +
您可以在汽车行业找到CAN的许多应用。在车辆中,它允许电子控制单元和设备在没有主机的情况下在应用程序中相互通信。例如,高速CAN总线专用于安全设备,例如紧急制动系统或安全气囊。另一种低速CAN总线专用于舒适设备,例如室内照明或座椅控制。
  
You can find many applications of CAN in the automotive industry. In vehicles, it allows electronic control units and devices to communicate with each other in applications without a host computer. For example, a high speed CAN bus is dedicated to security devices such as emergency brake system or airbags. Another low speed CAN bus is dedicated to comfort devices such as interiror lighting or seat control.
+
本文介绍了CAN框架的主要组件和API,并提供了CAN使用示例。
 
 
This article describes the main components and APIs of the CAN Framework and gives examples of CAN usage.
 
  
 
==System overview==
 
==System overview==
第17行: 第16行:
  
 
===Component description===
 
===Component description===
''From user space to hardware''
+
''从用户空间到硬件''
*'''Application''' (User space)
+
*'''应用''' (用户空间)
Application to read/write data on the [[CAN overview#API description | SocketCAN interface]] for communication with external devices connected on the CAN network (such as can-utils).
+
读取/写入[[CAN overview#API description | SocketCAN interface]],用于与CAN网络上连接的外部设备(例如can-utils)进行通信。
 +
 
 +
*'''CAN 工具''' (用户空间)
 +
一组实用程序,用于配置和启用SocketCAN接口(例如iproute2)。
  
*'''CAN tools''' (User space)
+
*'''SocketCAN''' (内核空间)
Set of utilities for configuring and enabling SocketCAN interface (such as iproute2).
+
具有特定CAN选项的套接字接口,该选项建立在Linux网络层上。
  
*'''SocketCAN''' (Kernel space)
+
*'''Linux套接字层和CAN协议(PF_CAN)''' (内核空间)
Socket interface with specific CAN options which builds upon the Linux network layer.
+
协议系列PF_CAN<ref name=PF_CAN/>,为传输协议模块的注册提供了API,并提供了在总线上启用不同CAN协议的结构。
  
*'''Linux Socket Layer and CAN Protocols (PF_CAN)''' (Kernel space)
 
The protocol family, PF_CAN<ref name=PF_CAN/>, provides an API for transport protocol modules to register and the structures to enable different CAN protocols on the bus.
 
  
*'''Linux Networking Core''' (Kernel space)
+
*'''Linux网络核心''' (内核空间)
Kernel network layer that adapts the message to the transport protocol in use. The network subsystem of the Linux kernel is designed to be completely protocol-independent.
+
内核网络层,使消息适应所使用的传输协议。 Linux内核的网络子系统设计为完全独立于协议。
  
*'''M_CAN Driver''' (Kernel space)
+
*'''M_CAN Driver''' (内核空间)
Driver implemented as a network interface for Bosch M_CAN controller<ref name=M_CAN>{{CodeSource | Linux kernel | drivers/net/can/m_can}}, Driver for Bosch M_CAN controller</ref>.
+
驱动程序已实现为Bosch M_CAN控制器的网络接口<ref name=M_CAN>{{CodeSource | Linux kernel | drivers/net/can/m_can}}, Driver for Bosch M_CAN controller</ref>.
  
*'''CAN''' (Hardware)
+
*'''CAN''' (硬件)
This is the CAN Core IP.
+
这是CAN Core IP。
  
*'''CAN Transceiver''' (Hardware)
+
*'''CAN Transceiver''' (硬件)
Interface between the CAN protocol controller and the physical wires of the CAN bus lines.
+
CAN协议控制器和CAN总线的物理线路之间的接口。
  
 
===API description===
 
===API description===
The SocketCAN interface API description can be found in kernel documentation <ref name=SocketCAN/>.
+
SocketCAN接口API描述可以在内核文档中找到 <ref name=SocketCAN/>.
  
 
==Configuration ==
 
==Configuration ==
 
===Kernel configuration===
 
===Kernel configuration===
Activate the CAN driver in kernel configuration with Linux [[Menuconfig or how to configure kernel | Menuconfig ]] tool.
+
使用Linux [[Menuconfig or how to configure kernel | Menuconfig ]]工具在内核配置中激活CAN驱动程序。
  
For compiling M_CAN driver, select "Bosch M_CAN devices":
+
要编译M_CAN驱动程序,请选择 "Bosch M_CAN 设备":
 
<pre>
 
<pre>
 
  [*] Networking support  --->                                                                                   
 
  [*] Networking support  --->                                                                                   
第56行: 第56行:
 
                         <*>  Bosch M_CAN devices                 
 
                         <*>  Bosch M_CAN devices                 
 
</pre>
 
</pre>
M_CAN driver is activated by default in ST deliveries.
+
默认情况下,ST交付中已激活M_CAN驱动程序。
  
 
===Device tree configuration===
 
===Device tree configuration===
CAN generic DT bindings:
+
CAN通用DT绑定:
* The M_CAN device tree bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/can/m_can.txt | Documentation/devicetree/bindings/net/can/m_can.txt}} M_CAN device tree bindings</ref> describe all the required and optional properties.
+
* M_CAN设备树绑定<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/can/m_can.txt | Documentation/devicetree/bindings/net/can/m_can.txt}} M_CAN device tree bindings</ref> 描述所有必需和可选的属性。
Detailed DT configuration for STM32 internal peripherals:
+
STM32内部外设的详细DT配置:
 
* [[FDCAN device tree configuration]]
 
* [[FDCAN device tree configuration]]
  
 
== How to use the framework==
 
== How to use the framework==
The CAN device must be configured via netlink interface. The following articles give user space examples of how to set up a SockeCAN interface (and configure settings like bit-timing parameters) and how to send/receive data on the CAN bus.
+
必须通过netlink接口配置CAN设备。以下文章为用户空间示例提供了有关如何设置SockeCAN接口(以及配置位定时参数等设置)以及如何在CAN总线上发送/接收数据的示例。
  
 
=== How to set up a SocketCAN interface ===
 
=== How to set up a SocketCAN interface ===
第75行: 第75行:
 
==How to trace and debug the framework==
 
==How to trace and debug the framework==
 
=== How to trace ===
 
=== How to trace ===
CAN Framework, specifically M_CAN driver, print out info and error messages. You can display them with dmesg command:
+
CAN框架,特别是M_CAN驱动程序,可以打印出信息和错误消息。您可以使用dmesg命令显示它们:
 
  {{Board$}} '''dmesg | grep m_can'''
 
  {{Board$}} '''dmesg | grep m_can'''
 
  [    1.327824] m_can 4400e000.can: m_can device registered (irq=30, version=32)
 
  [    1.327824] m_can 4400e000.can: m_can device registered (irq=30, version=32)
第82行: 第82行:
  
 
=== How to monitor CAN bus ===
 
=== How to monitor CAN bus ===
You can use the CAN FD adapter '''PCAN-USB Pro FD'''<ref>[http://www.peak-system.com/PCAN-USB-Pro-FD.366.0.html?&L=1 PCAN-USB Pro FD description], by PEAK System</ref> to connect a computer to the CAN network via USB. The PCAN-View software provided with the tool is a monitoring program that allows to supervise the data flow on the CAN network and to detect frame errors.
+
您可以使用CAN FD适配器 '''PCAN-USB Pro FD'''<ref>[http://www.peak-system.com/PCAN-USB-Pro-FD.366.0.html?&L=1 PCAN-USB Pro FD description], by PEAK System</ref>通过USB将计算机连接到CAN网络。该工具随附的PCAN-View软件是一个监视程序,可以监视CAN网络上的数据流并检测帧错误。
 
 
 
==Source code location==
 
==Source code location==
The source files are located inside the Linux kernel.
+
源文件位于Linux内核中。
  
 
*'''PF_CAN''': af_can.c<ref name=PF_CAN/>
 
*'''PF_CAN''': af_can.c<ref name=PF_CAN/>
第92行: 第91行:
  
 
==To go further==
 
==To go further==
CAN bit timing calculation plays an important role in ensuring performance of CAN network. To avoid transmission errors, the bit timing must be configured properly.
+
CAN位时序计算在确保CAN网络性能方面起着重要作用。为避免传输错误,必须正确配置位时序。
  
For more information about CAN bit timing:
+
有关CAN位时序的更多信息
* ''Computation of CAN Bit Timing Parameters Simplified''<ref>[https://www.can-cia.org/fileadmin/resources/documents/proceedings/2012_taralkar.pdf Computation of CAN Bit Timing Parameters Simplified], from the CAN in Automation group (CiA)</ref>, from the CAN in Automation group (CiA)
+
* ''简化了CAN位时序参数的计算''<ref>[https://www.can-cia.org/fileadmin/resources/documents/proceedings/2012_taralkar.pdf Computation of CAN Bit Timing Parameters Simplified], from the CAN in Automation group (CiA)</ref>, 来自Automation group的CNA (CiA)
* ''The Configuration of the CAN Bit Timing''<ref>[https://www.mikrocontroller.net/attachment/114193/BOSCH_The_config_of_CAN_Bit_Timing_L-1.pdf The Configuration of the CAN Bit Timing], from Bosch documentation</ref>, from Bosch documentation
+
* ''CAN位时序的配置''<ref>[https://www.mikrocontroller.net/attachment/114193/BOSCH_The_config_of_CAN_Bit_Timing_L-1.pdf The Configuration of the CAN Bit Timing], from Bosch documentation</ref>, 来自 Bosch 文档。
  
 
==References==
 
==References==
 
<references />
 
<references />
 
<noinclude>
 
[[Category:CAN|1]]
 
{{ArticleBasedOnModel | Framework overview article model}}
 
{{PublicationRequestId | 9718 | 2018-11-20 | BrunoB}}
 
</noinclude>
 

2020年11月6日 (五) 15:28的最新版本

本文提供有关 Linux® 控制器局域网(CAN)框架的信息。 它说明了如何激活CAN接口以及基于示例的使用方法。

Framework purpose

Controller Area Network(CAN)是一种多主机串行总线标准,它连接至少两个节点。 它是一种基于消息的协议,最初是为车载通信而设计的,其主要优点是显着减少了接线并防止了消息冲突。

为了获得更好的实时性能,具有灵活数据速率(CAN FD)的CAN[1] 用作经典CAN协议的扩展[2]. 它允许的数据速率高于1 MBit/s有效载荷则超过每帧8个字节(最多64个数据字节)。

SocketCAN [3] 是用于Linux内核的统一CAN框架。 它实现了一个名为PF_CAN[4] 并允许应用程序通过具有CAN特定套接字选项的套接字API接收和传输CAN消息。 您可以在汽车行业找到CAN的许多应用。在车辆中,它允许电子控制单元和设备在没有主机的情况下在应用程序中相互通信。例如,高速CAN总线专用于安全设备,例如紧急制动系统或安全气囊。另一种低速CAN总线专用于舒适设备,例如室内照明或座椅控制。

本文介绍了CAN框架的主要组件和API,并提供了CAN使用示例。

System overview

Alternate text
CAN Overview

Component description

从用户空间到硬件

  • 应用 (用户空间)

读取/写入 SocketCAN interface,用于与CAN网络上连接的外部设备(例如can-utils)进行通信。

  • CAN 工具 (用户空间)

一组实用程序,用于配置和启用SocketCAN接口(例如iproute2)。

  • SocketCAN (内核空间)

具有特定CAN选项的套接字接口,该选项建立在Linux网络层上。

  • Linux套接字层和CAN协议(PF_CAN) (内核空间)

协议系列PF_CAN[4],为传输协议模块的注册提供了API,并提供了在总线上启用不同CAN协议的结构。


  • Linux网络核心 (内核空间)

内核网络层,使消息适应所使用的传输协议。 Linux内核的网络子系统设计为完全独立于协议。

  • M_CAN Driver (内核空间)

驱动程序已实现为Bosch M_CAN控制器的网络接口[5].

  • CAN (硬件)

这是CAN Core IP。

  • CAN Transceiver (硬件)

CAN协议控制器和CAN总线的物理线路之间的接口。

API description

SocketCAN接口API描述可以在内核文档中找到 [3].

Configuration

Kernel configuration

使用Linux Menuconfig 工具在内核配置中激活CAN驱动程序。

要编译M_CAN驱动程序,请选择 "Bosch M_CAN 设备":

 [*] Networking support  --->                                                                                   
        <*>   CAN bus subsystem support  --->
                CAN Device Drivers  --->
                        <*>   Bosch M_CAN devices                 

默认情况下,ST交付中已激活M_CAN驱动程序。

Device tree configuration

CAN通用DT绑定:

  • M_CAN设备树绑定[6] 描述所有必需和可选的属性。

STM32内部外设的详细DT配置:

How to use the framework

必须通过netlink接口配置CAN设备。以下文章为用户空间示例提供了有关如何设置SockeCAN接口(以及配置位定时参数等设置)以及如何在CAN总线上发送/接收数据的示例。

How to set up a SocketCAN interface

如何设置SocketCAN接口

How to send/receive CAN data

如何发送或接收CAN数据

How to trace and debug the framework

How to trace

CAN框架,特别是M_CAN驱动程序,可以打印出信息和错误消息。您可以使用dmesg命令显示它们:

Board $> dmesg | grep m_can
[    1.327824] m_can 4400e000.can: m_can device registered (irq=30, version=32)
[   25.560759] m_can 4400e000.can can0: bitrate error 0.3%
[   25.564630] m_can 4400e000.can can0: bitrate error 1.6%

How to monitor CAN bus

您可以使用CAN FD适配器 PCAN-USB Pro FD[7]通过USB将计算机连接到CAN网络。该工具随附的PCAN-View软件是一个监视程序,可以监视CAN网络上的数据流并检测帧错误。

Source code location

源文件位于Linux内核中。

  • PF_CAN: af_can.c[4]
  • M_CAN driver: m_can.c[5]

To go further

CAN位时序计算在确保CAN网络性能方面起着重要作用。为避免传输错误,必须正确配置位时序。

有关CAN位时序的更多信息

  • 简化了CAN位时序参数的计算[8], 来自Automation group的CNA (CiA)
  • CAN位时序的配置[9], 来自 Bosch 文档。