0 Introduction
CAN bus is a bus-type control network for interconnecting devices. Compared with other field buses, the data communication of CAN bus has outstanding reliability, real-time and flexibility. These characteristics enable it to meet the needs of process control and manufacturing automation at the same time, so it is considered to be one of the most promising field buses. However, due to the limitation of its transceiver driving capability, the maximum direct transmission distance of CAN bus and the maximum number of nodes that can be connected to the bus are restricted, which brings certain difficulties to the system networking. On the other hand, due to the low cost, openness, application software and hardware support and powerful networking capabilities of Ethernet, it is currently the most widely used local area network technology, and more and more engineers are beginning to adopt the technology of combining CAN bus and Ethernet. In view of such a situation, this paper proposes a design scheme for the interconnection system of CAN bus and Ethernet to realize the data interconnection between CAN bus network and Ethernet.
1 System Structure
The network architecture diagram of connecting CAN fieldbus and Ethernet with a gateway is shown in Figure 1.
Figure 1 System network structure diagram
The embedding of the gateway not only enables management to go deep into the control site, but also brings great convenience to the system networking.
1.1 Benefits of Gateway Embedding
① Increased the maximum number of CAN nodes in the system
Without a repeater, a CAN subnet can connect up to 110 nodes, and each gateway can be connected to a subnet. Multiple subnets can be connected together through multiple gateways, thereby increasing the number of nodes in the system.
② Expanded the networking scope of the system
The direct communication distance of CAN is only about 10km. The system builds subnets according to the site area and number of nodes. The subnets are connected through Ethernet, thus breaking through the limitations of area and distance.
③ The mutual communication of fieldbus subnets with different transmission speeds is realized. The gateway provides a friendly human-machine interface, and users can set the IP address and baud rate of the CAN controller as needed.
1.2 Gateway Embedding Issues
While the application of gateways brings convenience to the system, it also comes at a certain cost. These issues must be considered in the design to improve the overall efficiency of the system. These issues are manifested in:
① Real-time
Due to the use of gateways, data processing must go through the process of first storing, then converting, and finally sending, which increases some storage and forwarding delays. Therefore, the real-time performance of the system must be considered in the design, requiring the system to start protocol conversion and data forwarding tasks immediately after storing the newly received data, so as to minimize system delays.
② Security
If the gateway fails, it will affect the communication between the CAN subnet and Ethernet, and even paralyze the communication between this subnet and the entire system. Therefore, in hardware design, we should try to avoid interference and other problems; software design must be able to respond to some correctable errors in a timely manner and return error information to the user.
2 Gateway Hardware Design
The gateway hardware design is divided into three parts: CAN interface, Ethernet network interface and human-machine interface.
2.1 Selection of main controller
The main controller uses Philips' ARM controller LPC2292. LPC2292 is based on a 16/32-bit ARM7TDMI-SCPU that supports real-time simulation and trackingTM. The CPU core operating voltage is 1.8V and the pin operating voltage is 3.3V.
LPC2292 has 256 kbytes (kB) of embedded high-speed Flash memory, which can fully meet the capacity requirements of system code without external memory expansion; the unique acceleration structure enables 32-bit code to run at the maximum clock rate, and can implement network protocols such as ARP, TCP, UDP, ICMP in the TCP/IP protocol stack.
LPC2292 integrates two CAN controllers to facilitate the system to adopt redundant design. The main features of the CAN controller are: data transmission rate on a single bus up to 1Mb/s; 32-bit register and RAM access; compatible with CAN2.0B, ISO11898-1 specifications; global acceptance filter can recognize all 11-bit and 29-bit Rx identifiers; acceptance filter provides FullCAN-style automatic reception for selected standard identifiers.
The CPU external static memory controller provides an interface between the CPU internal system bus and external memory or external I/O devices. This external bus can be used to easily connect to the Ethernet network card controller.
2.2 CAN interface
Considering the safety of the system, the CAN interface adopts a redundant design. When the normal channel fails, the redundant channel is automatically called for transmission; if the redundant channel also fails, the fault processing is started. The hardware interface diagram is shown in Figure 2. The two channels of LPC2292 are connected to the bus through the high-speed bus driver TJA1050. The bus driver is powered by an isolated DC/DC, which not only realizes the electrical isolation between the two channels, but also realizes the electrical isolation between the gateway and the bus.
2.3 Network Interface
The network card controller uses the 10M Ethernet control chip RTL8019 from Taiwan RETACK Company, which supports full-duplex working mode and is software compatible with 8-bit or 16-bit NE2000 mode; it integrates DMA controller, ISA bus controller, 16kRAM, network PHY transceiver, etc. RTL8019 uses the BANK3 part of the LPC2292 external storage control, and its data address range is 0x83400000~0x8340001F. The operating voltage of RTL8019 is +5V, while the pin operating voltage of LPC2292 is 3.3V, so a 470Ω protection resistor should also be connected in series on the connection line. The network uses twisted pair transmission.
Figure 2 Schematic diagram of network hardware structure
2.4 Human-machine interface
In addition to the above main parts, there are also LED digital tube display and keyboard parts. The LED is used to display the working status, and the keyboard corrects the bus baud rate and the IP address of the gateway according to the actual situation.
3 Software Design
3.1 Introducing RTOS
Gateway design has high requirements for the real-time performance of the system, while the traditional front-end and back-end design methods are too complicated and the real-time performance cannot be guaranteed. The best way to solve this problem is to use a real-time operating system RTOS. At present, there are a large number of mature embedded operating systems in the world, among which the μC/OS-II operating system is an embedded operating system with open source code. It has the characteristics of short and powerful code and is easy to learn. It is an ideal choice for gateway design.
μC/OS-II is a completely preemptive real-time kernel, which is based on priority, that is, the highest priority task in the ready state is always run first, so the real-time performance is better than that of non-preemptive kernels. Most of its code is written in C language, which is highly portable.
Figure 3 Embedded computer system [page]
3.2 System composition
The function of the embedded gateway is mainly to convert the protocol between Ethernet data messages and CAN data frames to realize the interconnection between Ethernet and CAN bus; secondly, according to the application environment, the IP address of the gateway and the baud rate of the CAN bus are changed through the human-computer interaction interface. The composition of the entire embedded system is shown in Figure 3. The preliminary work before the task design is as follows:
① Porting of real-time operating system. μC/OS-II can run on most 8-bit, 16-bit, 32-bit, and even 64-bit microprocessors, microcontrollers, and digital signal processors (DSPs). For the porting of μC/OS-II on LPC2292, please refer to reference [1].
② Embedding of TCP/IP protocol and CAN protocol. Since the μC/OS-II operating system only includes real-time kernel, task management, time management, communication synchronization between tasks (semaphore, mailbox, message queue) and memory management functions, users must add some functional modules according to their needs. The design of the gateway embeds TCP/IP and CAN protocols into the operating system and provides some API interface functions for users to call.
3.3 System Implementation
The use of RTOS makes the entire design simple and easy to debug. Each task is independent of each other, and each task has a different priority to ensure timely response to emergency tasks, so that tasks can be effectively scheduled. The system software design consists of an operating system and a series of user applications. The main function is the first function executed by the program. This function never returns. It mainly implements the initialization of the system's hardware (including interrupts, keyboards, displays, etc.) and the operating system (including task control blocks and event control blocks). Before starting multi-task scheduling, at least one task must be created. In this system, a startup task is created, which is mainly responsible for the initialization and startup of the clock, the startup of interrupts, the initialization and startup of the CAN controller, the initialization of ports and IP addresses, and the initialization and startup of RTL8019, and the various application tasks are divided. After handing over the right to use the CPU, it does some idle processing.
3.3.1 Division of tasks
To complete the various functions of the multi-task system, tasks must be divided. This program divides the entire module into 7 application tasks with different priorities according to the importance and real-time nature of each task: system monitoring, CAN data transmission, keyboard scanning, Ethernet data transmission, protocol conversion, LED display, system configuration, etc. Table 1 shows the task division table.
Table 1 Classification of items
In addition to the 7 main application tasks, there are two interrupt service routines: a clock beat interrupt to provide a periodic signal source; and a receive interrupt to write the received data into the buffer.
3.1.2 Specific Implementation of Tasks After the tasks are divided, each task has its own stack space and competes with each other for the right to use the CPU. Once it obtains the right to use the CPU, it will run independently to complete specific functions.
The CAN bus communication module includes two parts: data transmission and bus management. The functions implemented by data transmission include CAN initialization, CAN message sending and CAN message receiving. CAN initialization and message receiving are implemented in the startup task and interrupt service program. CAN message sending and bus management run independently as a separate task. The bus management function block mainly implements bus detection to determine whether one bus is good. If not, enter another bus detection; if the redundant bus is good, use the redundant bus communication. The CAN data sending task requires the system scheduler to notify whether there is data to be sent to enter the sending queue. The implementation of the task is shown in Figure 4.
Figure 4 Data sending task implementation diagram
The Ethernet communication module consists of an Ethernet data transceiver function block and a data protocol management function block. The data transceiver function block mainly implements the initialization of RTL8019 and the sending and receiving of data packets. Similarly, the initialization of RTL8019 is implemented in the system startup task. The reception of data is implemented in the interrupt service program of RTL8019. The data protocol management mainly implements the parsing of the received data packet and the addition of the protocol header to the data to be sent. Ethernet data transmission and protocol management run as independent tasks.
The Ethernet data transmission task also requires the system scheduler to notify whether there is data to be sent in the transmission queue. If there is no data to be sent, the task will be suspended and the system will run other tasks. The Ethernet data transmission task is completed by operating RTL8019. According to the status of RTL8019, the data in the transmission queue is transferred to the transmission buffer of 8019 through DMA to start transmission, and the transmission queue pointer is adjusted according to the transmission result.
Ethernet protocol management, i.e., protocol conversion tasks, performs protocol conversion between user data and data packets required by the 8019 driver. The TCP/IP protocol is a 4-layer model consisting of the application layer, transport layer, network layer, and data link layer. Each layer has different functions and corresponds to corresponding sub-protocols, and the layers are logically independent of each other. When programming, you can directly call the embedded TCP/IP protocol API function to layer the data packets. The task's schematic diagram for processing data transmitted from 8019 is shown in Figure 5. Different sub-protocols have different function numbers, and the task distinguishes the protocols based on the function numbers. The schematic diagram for passing user data to the 8019 driver is the reverse representation of Figure 5.
Figure 5 Schematic diagram of data processing of protocol conversion task
3.3.3 Synchronization and Scheduling between Tasks
Usually, the task of a multitasking operating system is different from a general function. It is an infinite loop and has no return value. If no higher priority task enters the ready state, the current task will not give up the right to use the CPU. In order to achieve the normal operation of the operating system and the synchronization of related events, the communication between tasks and the setting of event flags must be handled correctly. The functional structure of the entire system is shown in Figure 6.
Figure 6 System operation diagram
Each task has a different priority. By calling the system suspend function or delay function, a task with a higher priority that enters the ready state can be started. High-priority tasks, such as tasks 1, 2, 3, and 4, are often blocked due to applying for a certain resource and enter the suspended state. The system scheduler starts low-priority tasks and starts keyboard scanning or LED display tasks at regular clock beats by setting delay parameters. If any of the events occurs, the related tasks are started. This process is implemented through the semaphore communication mechanism. A semaphore is assigned to each event. Once an event occurs, the task in the waiting task list of the semaphore that enters the ready state is started, thereby ensuring the synchronization of tasks and events.
4 Conclusion
Based on the embedded hardware platform, the μC/OS-II real-time operating system is unique in developing applications. Users can directly use the system's interface functions to write their own applications without the need for separate development, which greatly facilitates user programming, shortens the software development cycle, and improves development efficiency. The gateway between the CAN bus and Ethernet based on ARM LPC2292 runs well and stably during the experimental debugging process.
Previous article:Research on transplantation and optimization of Gameboy emulator based on ARM Linux
Next article:Design and implementation of solar power generation control system based on ARM
Recommended ReadingLatest update time:2024-11-16 17:40
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- A huge reward! Looking for someone who can crack the RSA2048 and factory protocol in the ECU!
- Family Pet Health Maintenance System
- A thorough understanding of the filter circuit in the power supply
- AD9361 output waveform amplitude is different
- Arteli - RT Thread - Portable Heart Rate Monitor Sharing
- HF Antenna Analyzer(3MHz to 30MHz)
- 1. Previous Power Supply Competition Topics
- Variable value problem in makefile
- The "Soul" of the Microcontroller - The Use of Data Memory
- Detailed Explanation of I2C Bus Protocol