Design of a gateway between CAN bus and Ethernet based on ARM LPC2292

Publisher:WeaselLatest update time:2011-06-30 Keywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:ARM Reference address:Design of a gateway between CAN bus and Ethernet based on ARM LPC2292

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

Transplantation of μC/OS-Ⅱ on ARM Series MCU S3C44B0x
Introduction At present, embedded systems have been more and more widely used in various fields such as industrial control, household appliances, mobile communications, PDAs, etc. As users have higher and higher requirements for the performance of embedded products, program design has become more and more compli
[Microcontroller]
Transplantation of μC/OS-Ⅱ on ARM Series MCU S3C44B0x
Fingerprint recognition access control system based on ARM9
Fingerprint access control system is a high-tech security facility based on biometric recognition technology. In recent years, it has been widely used at home and abroad and has become one of the symbols of modern building intelligence. For some core confidential departments, such as important agencies, scientific res
[Microcontroller]
Fingerprint recognition access control system based on ARM9
Solution of ECG Defibrillation Simulation Generation System Based on ARM9 Embedded Development Platform
    With the development of society, people's awareness of medical care is getting stronger and stronger, so the training of doctors has become a very important link. As a major aspect of doctor training, ECG defibrillation technology can often save people from danger in an emergency if the operation is standardized a
[Microcontroller]
Solution of ECG Defibrillation Simulation Generation System Based on ARM9 Embedded Development Platform
ARM interrupt generation to processing process
ARM interrupt generation to processing process (bottom-level stuff) There are two types of interrupts in ARM: IRQ & FIQ. The on-chip peripherals are usually defined as IRQs, which are controlled in the VIC module, i.e. the interrupt vector control module. The control register is VICintselect, which has 32 bits in tota
[Microcontroller]
British chip giant ARM sets price, Masayoshi Son wins biggest listing deal of the year
On September 14, Beijing time, ARM, a British chip design company under SoftBank Group, has set the issue price of its initial public offering (IPO) at the upper limit of the issue price range, raising US$4.87 billion (approximately 35.4 billion yuan), becoming the largest company so far this year. It is the largest l
[Semiconductor design/manufacturing]
ARM assembly learning (Part 3)
1. NDK compiles C programs running on Android Create a new hello directory, under which there should be a jni directory, and below that is the Android.mk file 1.The contents of the Android.mk file are as follows: LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= hello.c LOCAL_MODULE:= hello L
[Microcontroller]
ARM Learning Notes 9——Pseudo-instructions in ARM assembly language
  The ARN assembler supports ARM pseudo-instructions, which are translated into ARM or Thumb instructions during the assembly phase. ARM pseudo-instructions include ADR, ADRL, MOV32, and LDR. 1. ADR pseudo-instruction   1. Function     ADR is a pseudo-instruction for reading addresses in a small range. It reads addre
[Microcontroller]
Get ready for the IPO! Arm board brings in former Qualcomm and Intel executives
Arm, a chip design company owned by SoftBank Group, has added former Qualcomm CEO Paul Jacobs and former Intel executive Rose Schooler to its board of directors to prepare for its upcoming initial public offering. IPO) preparation. The two executives will help Arm prepare for the IPO by providing experience in develo
[Semiconductor design/manufacturing]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号