Eth Driver of Automotive Ethernet Basics

Ethernet Driver for Automotive Ethernet Basics

foreword

First of all, I would like to ask you a few questions, you know:

  • Do you know what the main function of the Eth Driver module is?
  • What is the relationship between EthDriver and Ethernet controllers and Ethernet transceivers?
  • What are the common function interfaces of Eth Driver?
  • Does the Eth Driver generally have features that distinguish it from other drivers?

Today, we will explore and answer these questions together. To make it easier for everyone to understand, the following is an outline of the topics of this article:

insert image description here


text

As mentioned in the previous article "EthIf of Automotive Ethernet Basics", the Eth Driver will be used as the underlying driver for configuring Ethernet. It can not only be called by EthIf, but also meet the calling requirements of the Eth transceiver driver, because it is necessary to understand the following The car Ethernet driver (Eth Driver) plays an important role in the entire AUTOSAR layer.

As shown in Figure 1 below, the Ethernet If module not only directly controls the Ethernet Driver, but also indirectly controls the Ethernet Driver module if there is an Ethernet Switch driver or Ethernet Transiver driver. In a word, the Ethernet driver can not only complete the normal sending and receiving of Ethernet data , and also enables direct configuration for Ethernet gateways or Ethernet transceivers.

insert image description here

Figure 1 Relationship between Ethernet Driver and other Ethernet drivers

AUTOSAR hierarchical relationship

According to the AUTOSAR standard document specification, the specific location description of the Eth Driver module in the entire AUTOSAR software architecture is shown in Figure 2 below:
insert image description here

Figure 2 Relationship between Eth Driver and Ethernet protocol stack

As shown in the figure above, the following basic conclusions can be drawn:

  • There can be Ethernet controllers from multiple suppliers in one Ethernet protocol stack, and each supplier's controller can be controlled separately without affecting each other;
  • Multiple Ethernet controllers from the same supplier can exist, but only the same set of Ethernet controller drivers can be used;
  • As a part of the standard AUTOSAR MCAL, the Ethernet drivers of the above three different suppliers can be completely decoupled from the underlying hardware;

Module main function

As the most important underlying component of the vehicle Ethernet protocol stack, Eth Driver will lead you to get a preliminary understanding of the Ethernet driver from the following levels:

  • How to set the index relationship inside different drivers of Ethernet?
  • How the Ethernet driver sends data;
  • How the Ethernet driver performs data reception;
  • What functions do Ethernet driver features such as QoS, hardware timestamp, and Offloading have?
  • Common communication protocols in Ethernet drivers such as MDIO, how does DMA play a role in the driver?

Drive Index Rules

As shown in Figure 3 below, each Ethernet driver is independent of each other, and its index number starts from 0, but the bufidx inside each driver can start from 0 without interfering with each other.
insert image description here

Figure 3 Eth Driver index relationship

data sending process

If the upper-layer application needs to send data through the Eth Driver, it needs to indirectly call the sending function Eth_Transmit of the Eth Driver through the EthIf module to complete the data sending.

Among them, the data transmission function of the EthIf module is divided into two modes, one is Polling mode, and the other is Interrupt mode . Generally speaking, the interrupt mode is preferred to meet the real-time requirements of the system.

Figure 4 below shows the Polling mode. In the Polling mode, you can see that the EthIf_MainfunctionTx function will poll whether the transmission is successful. This is also a typical feature of the Polling mode.

Polling mode
insert image description here

Figure 4 Data sending Polling mode

Interrupt mode

Figure 5 below shows the interrupt mode of Ethernet data transmission. Compared with the Polling mode, it can be seen that the interrupt mode does not use the EthIf_MainfunctionTx function, but uses the interrupt function of the Eth module to confirm whether the transmission is successful.

insert image description here

Figure 5 Data transmission interrupt mode

Data receiving function

Similarly, compared with the data sending function, the data receiving function of the EthIf module can also be divided into two types: Polling mode and interrupt mode. Figure 9 below shows the data receiving Polling mode of the EthIf module.

As shown in Figure 6 below, if the EthIf module data reception adopts the Polling mode, then the EthIf_MainfunctionRx function needs to be used, and the EthIf_RxIndication is called in this function to inform the upper layer that the data has been successfully received. Using this mode will greatly reduce the data receiving efficiency . Reception takes priority in interrupt mode .

Polling mode

insert image description here

Figure 6 Data receiving Polling mode

Interrupt mode

Figure 7 below shows the data receiving interrupt function of the EthIf module. In this mode, it can be seen that the Eth module informs the upper layer that the data has been received through the interrupt function.

insert image description here

Figure 7 Data reception interrupt mode

Introduction to drive characteristics

Compared with other drivers, the Ethernet driver has many unique features. Little T will lead everyone to understand these features, and strive to have a basic understanding of these features so that we can have a more comprehensive understanding of the Ethernet driver. Knowing it will make you more comfortable applying it.

The following lists three common features of Ethernet drivers (network cards): Offloading features, hardware TimeStamp features, and QoS features .

Offloading characteristics

"Offload", as the name suggests, means to uninstall, so who to uninstall and what to uninstall? In fact, the purpose of this feature is to offload the CPU. The way of offloading is to hand over the CRC calculation to the hardware, or the action of sub-packetization is also handled by the hardware, so as to reduce this part in the Ethernet protocol stack. Occupying time in the software, reducing performance problems caused by software running delays and high CPU loading.

In the AUTOSAR specification, the special description of Offloading for the CRC of the Ethernet driver (Eth Driver) sending or receiving messages is as follows:

  • For IPV4 frames, if EthCtrlEnableOffloadChecksumIPv4 is set to TRUE, Offloading CRC is possible;
  • For ICMP frames, if EthCtrlEnableOffloadChecksumICMP is set to TRUE, Offloading CRC is possible;
  • For TCP frames, if EthCtrlEnableOffloadChecksumTCP is set to TRUE, Offloading CRC is possible;
  • For UDP frames, if EthCtrlEnableOffloadChecksumUDP is set to TRUE, Offloading CRC is possible;

It is worth noting that these CRC calculations will only be done in hardware. For the receiver, the CRC check detection will be done through hardware. If the CRC check fails, the received frame will be discarded.

Hardware TimeStamp Features

As mentioned in the previous articles " cantsyncc" and "StbM ", everyone has a basic understanding and understanding of CAN time synchronization. Compared with CAN time synchronization, the Ethernet time synchronization protocol uses IEEE1588 or IEEE802.1AS PTP (Precise Time Protocol) protocol , which needs to confirm whether the network card (MAC) used supports itself.

This protocol uses the underlying hardware MAC to stamp the corresponding Ethernet message sending and receiving time stamps, which can minimize the uncertainty brought by software time stamps, and achieve time synchronization accuracy of microseconds or even nanoseconds second level.

The EthTsync module defined in the AUTOSAR specification uses the two-step end-delay PTP time synchronization protocol . The following is the interactive relationship between the Time Master and Time Slave based on this protocol. A single explanation will be given for the EthTsync module later. Dear Please pay attention.

insert image description here

Figure 8 PTP time synchronization protocol of two-step Ethernet side delay mechanism

As shown in Figure 8 above, if it is based on the PTP time synchronization of the Ethernet side delay mechanism in single-step mode , then the part marked with a dotted line will not exist. If it is based on the Ethernet side delay mechanism in double-step mode PTP time synchronization, then the part marked with dotted lines must be present.

It is worth noting that there is a GrandMaster concept in IEEE802.1AS, which needs to be realized through BMCA (Best Master Clock Algorithm). However, because the car is a static network, there will only be a unique GrandMaster, and there is no need to use the BMCA dynamic allocation confirmation algorithm.

Ethernet hardware implements PTP protocol in the following two ways:

  • Ethernet MAC controller supports PTP protocol, common dual-step mode;
  • Some TI PHY layers can also support PTP, but generally it is a single-step mode. If you use the AUTOSAR standard EthTsync module, you must confirm in advance whether it supports the two-step mode;

QoS features

Qos is an IEEE 802.1P protocol, which runs on the second layer of Ethernet, and is used to ensure that important data packets can be sent out in time by priority when Ethernet data forwarding is congested.

Ordinary Ethernet Layer 2 packets do not contain a priority field. IEEE802.1P is an extension technology of the IEEE802.1Q (VLAN tag technology) standard, and they work together . Although 802.1Q defines the tag field, it does not Define and use the priority, and the priority can be used normally after supplementing with the 802.1P protocol, just as the label field defined by IEEE 802.1P and IEEE802.1Q is shown in Figure 9 below:

insert image description here

Figure 9 IEEE802.1Q tag header information

The Ethernet frame is marked by the 802.1P user priority (COS) in the 802.1Q label through the QoS feature, and its priority has 8 levels, from priority 0 to priority 7, as shown in Figure 10 below:

insert image description here

Figure 10 COS Priority Description

Communication protocol introduction

In the process of using the vehicle Ethernet driver, we often encounter the following three common communication protocols, which are very important for the normal operation of the vehicle Ethernet:

  • The MII interface communication protocol is used for the data transmission protocol between the Ethernet MAC layer and the physical layer transceiver PHY;
  • MDIO communication protocol, used for Ethernet MAC layer control PHY state setting and acquisition protocol;
  • DMA communication protocol, used for data transfer communication protocol between Ethernet MAC layer and CPU, improves data transfer efficiency and reduces CPU load;

Basic introduction of MII interface communication protocol

The MII interface is an Ethernet industry standard defined by IEEE802.3. This standard is to solve the compatibility between the Ethernet MAC layer and the PHY, and to ensure that the PHY can always work normally even if a different type of MAC is replaced.

MII interface With the development and progress of technology, a variety of enhanced MII interfaces have been derived. The commonly used ones are MII, RMII, SMII, SSMII, SSSMII, GMII, RGMII, and SGMII, among which the most commonly used for automotive Ethernet Or RGMII interface .

The specific communication protocol introduction will not be expanded in this article. The selection of this interface only needs to configure MCAL on the software to use the corresponding MII interface type. The relationship of the MII interface on the Ethernet hardware connection:

insert image description here

Figure 11 Schematic diagram of the MII physical connection between the Ethernet MAC and the PHY

Introduction to MDIO Protocol Basics

First of all, MDIO is the abbreviation of Management Data Input/Output, and this interface protocol is also reflected in IEEE802.3. It is a serial data interface specially used to manage the MAC and PHY. The basic functions are as follows:

  • Read the value of PHY-related registers;
  • Obtain the Link and other working status of the PHY;
  • Set the working mode of the corresponding PHY, etc.;

In addition, the MDIO protocol interface is a real-time, half-duplex, serial data interface, which consists of two lines, one is called MDIO line, and the other is MDC line.

The MDIO line is responsible for the transmission of data. Two-way transmission is possible between the MAC and the PHY. When writing the register, it is driven by the MAC, and when reading the register, it is driven by the PHY. The high bit (MSB) is transmitted first, and then the low bit (LSB). Resistors in the range of 1.5kΩ-10kΩ .

The MDC line is responsible for transmitting the clock synchronization signal. It can only be driven by the MAC in one direction, and the data on the MDIO line can only be sampled on the rising edge of the MDC. The maximum time frequency allowed by the MDC is generally determined by the PHY .

An MDIO interface can support 32 PHY addresses, and the interface has 32 register addresses, of which the first 16 registers have been defined in the standard, and the remaining 16 are defined by each device manufacturer.

According to the IEEE802.3 protocol, the MDIO protocol is divided into two frame formats, Clause 22 and Clause 45, among which Clause 22 is mainly used for Ethernet PHY below Gigabit, and Clause 45 is used for Ethernet above Gigabit PHY.

Next, I will briefly explain the basic usage and differences between Clause 22 and Clause 45:

The format of the Clause 22 read data frame is as follows:
insert image description here

Figure 12 Clause 22 read data frame format

The format of Clause 22 write data frame is as follows:

insert image description here

Figure 13 Clause 22 write data frame format

The format of the Clause 45 address frame is as follows:

insert image description here

Figure 14 Clause 45 address frame format

The format of the Clause 45 read data frame is as follows:

insert image description here

Figure 15 Clause 45 read data frame format

The format of Clause 45 write data frame is as follows:

insert image description here

Figure 16 Clause 45 write data frame format

As shown in Figure 17 below, according to the frame format definition of Clause 22 and Clause 45 above, Little T lists the definition of the frame format and the difference between the two, so that everyone can have a basic understanding of the use of the two formats.

insert image description here

Figure 17 Differences and connections between Clause 22 and Clause 45 frame formats

Introduction to DMA Protocol Basics

The DMA protocol should be familiar to friends who have used it, especially those who are doing low-level driver development. DMA is to realize the transfer between peripherals and memory or between memory and memory without CPU intervention. The same is true for Ethernet DMA, which is to realize data exchange between Ethernet peripherals and memory.

This article will not explain too much about the DMA protocol itself. It aims to explain how DMA works in the process of sending and receiving Ethernet data. Use the following two pictures to understand the use of DMA in the process of sending and receiving Ethernet data.

Ethernet DMA send

As shown in Figure 18 below, Tx ringbuffer is used as a DMA descriptor, and the role of DMA in the Ethernet transmission process is as follows:

insert image description here

Figure 18 Ethernet DMA sending process

Ethernet DMA receive

As shown in Figure 19 below, Tx Ringbuffer is used as a DMA descriptor, and the role of DMA in the Ethernet receiving process is as follows:

insert image description here

Figure 18 Ethernet DMA receiving process

Summary of common functions

In order to make it easier for everyone to use the Eth Driver module better, Xiao T sorted out the commonly used function interfaces and function descriptions of the vehicle Ethernet driver, as shown in Figure 19 below:

insert image description here

Figure 19 Ethernet driver common function interface

For more exciting content, please pay attention to the official account "My View on ADAS and ECU"! ! !

Guess you like

Origin blog.csdn.net/wto9109/article/details/130071521