Implementing CAN bus intelligent node in μCOS-II on S3C44B0

Publisher:Enchanted2023Latest update time:2023-02-03 Source: elecfansKeywords:S3C44B0 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Today, as systems become more and more complex and their functions become more and more powerful, the use of real-time multi-tasking operating systems in the design of embedded systems has become the mainstream of embedded application design. μCOS-II is an open source embedded real-time operating system (Real Time Operating System, RTOS), which has been successfully ported to various CPUs. However, application software based on μCOS-II needs to be completed by itself after transplanting the operating system. Modular application design can make embedded design more convenient and product development faster. S3C44B0 is an ARM7 chip produced by Samsung. It has powerful performance and is widely used in general embedded design. CAN bus (Control Area Network) is a field bus that effectively supports distributed control and real-time control. Due to its high performance and high reliability, CAN bus is widely used in fields such as process industry, robotics and machinery industry. The paper transplants μCOS-II to S3C44B0, and designs and develops a CAN communication module based on μCOS-II. Compared with the traditional front-end and back-end systems, the CAN bus runs under μCOS-II, and the real-time performance is easier to ensure and more efficient. Easy to expand functions.


1 Introduction to S3C44BO

S3C44B0 is a 16/32-bit RISC processor designed by Samsung to provide a low-cost, high-performance solution for handheld devices. S3C44B0 provides a 2.5V ARM7TDMI core with a maximum clock frequency of 66MHz and a bus addressing space of 256M. It uses an interrupt vector table to reduce interrupt delays, provides 30 interrupt sources, supports C language programming and multi-tasking, and has rich on-chip resources: LCD controller, 2-channel UART, 2-channel DMA, external memory controller, 5-channel timer with PWM output, watchdog, RTC, 8-channel 10bit ADC, IIC interface, IIS interface, SIO, etc.


2 Introduction to SJA1000 and 82C250

SJA1000 is an independent CAN controller, which is a replacement product of PHILIPS company's PCA82C200 CAN controller. SJA1000 has two working modes: BasiCCAN and PeliCAN. The PeliCAN working mode supports the CAN2.0B protocol with many new features. SJA1000 supports both 11-bit and 29-bit identification codes, with a bit rate up to 1Mbits/s and a clock frequency up to 24MHz. It supports extended functions of PeliCAN mode, such as some error analysis functions, system diagnosis, system maintenance, and system optimization. wait.


82C250 is a CAN bus transceiver produced by PHILIPS. It provides differential sending and differential receiving functions for the bus. It also has a current limiting circuit to provide further protection for the bus.


3 μCOS-II transplantation on S3C44B0

μCOS-II (micro-controller OS II) is an open operating system kernel. It is a preemptive real-time multi-tasking operating system microkernel specially designed for microcontroller system and software development. μCOS-II is a real-time multi-tasking operating system with open source code, portable, solidifiable, tailorable, deprivable and deterministic. Most of its code is written in ANSI C language, and only less than 200 lines of code related to the processor are written in assembly language. Therefore, it has good portability and is relatively easy to be transplanted to CPUs of various systems. In this article, μCOS-II is transplanted to run on S3C44B0. The transplantation work mainly involves the modification of three files:

Relevant content of the modified header file OS_CPU.H, including: data type definitions, stack growth direction, some macro definitions related to interrupts, etc.


Write the task stack initialization function and system HOOK function in OS_CPU_C.C.

Write four assembly language functions in OS_CPU_A.ASM: OSSstartHighRdy(), OSCtxSw(), OSINTCtxSw() and OSTIckISR().

After completing the above work, μCOS-II can run on the S3C44B0 processor.


4 Software and hardware structure of CAN bus intelligent node

CAN bus is a type of field bus. It has a simple structure, flexible communication methods, non-destructive arbitration technology, and short frame format for communication, thus forming a low-cost, high-performance, and real-time communication system.


4.1 Hardware structure of CAN bus intelligent node

When using S3C44B0 and SJA1000 to implement CAN bus nodes, SJA1000 adopts the data transmission method of address data multiplexing, while S3C44B0 uses separate address bus and data bus. Therefore, it cannot be directly connected like the 51 series microcontroller and SJA-1000. Another solution must be found. Send the sent address and data from the data bus, and use the IO port and nGCSx, nOE, nWE and other signals to form the ALE signal and read, write, chip select signals and connect them to SJA1000, so that the connection between S3C44B0 and SJA1000 can be completed. , forming a CAN bus node on the hardware, and at the same time, in order to ensure that the signals do not interfere with each other, an optocoupler 6N137 is used for isolation. In addition, level conversion is required between the 3.3V signal of S3C44B0 and the 5V signal of SJA1000.

Implementing CAN bus intelligent node in μCOS-II on S3C44B0


4.2 Software structure of CAN bus intelligent node

In BasicCAN mode, the RX and TX buffers are each 10 bytes long, with two ID bytes and up to 8 data bytes. Among them, ID byte 1 is 8 ID bits, ID byte 2 is 3 ID bits, 1 remote transmission request bit and 4 data length code bits. The 11-digit ID can create 2032 message types, which is sufficient for common application needs. The provisions of the ID bits can be defined according to actual needs.


When sending a message, call the CAN sending function U8 BCAN_DATA_WRITE(U8 *SendDataBuf), where *SendDataBuf points to the content to be sent. In this function, fill in the message content according to the format specified by the CAN receiving buffer, and then call the command function U8 BCAN_CMD_PRG (U8 cmd). The cmd parameter determines the command type. Select the send data command to send the message.


When receiving a message, call the CAN receiving function U8 BCAN_DATA_RECEIVE(U8 *RcvDataBuf), where *RcvDataBuf is the storage address of the message. In this function, the data in the receive buffer is read and stored in the specified location.


These two functions are just sending and receiving functions. Specific sending and receiving need to establish corresponding tasks or interrupts and call these two functions to complete. Among them, the sending adopts the active mode. When the sending task receives the instruction to start sending, it calls the CAN sending function to send the data. The receiving adopts the interrupt mode. The priority of the CAN interrupt is higher than the clock interrupt and other tasks.


The node communication flow chart is shown in Figure 2:


5 Design of CAN bus communication program module based on μCOS-II

The MCU program designed in the traditional front-end and back-end mode is an infinite loop. Calling the corresponding functions in the loop to complete the corresponding operations is its background behavior, and the interrupt service program handles    

Implementing CAN bus intelligent node in μCOS-II on S3C44B0

Handling asynchronous events is its foreground behavior. μCOS-II is a real-time multi-task operating system and a multi-task scheduling platform based on a preemptive kernel. As a module, the CAN bus program is embedded in μCOS-II. Compared with the front and backend mode, the running time of the CPU is allocated by μCOS-II to different task modules according to different priorities according to the scheduling algorithm. Each task program Accessing the CPU during its own running time makes it easier to ensure the real-time performance of the CAN bus. At the same time, each task is relatively independent and has little impact on each other. It also facilitates program debugging. More importantly, if you want to implement a more complex communication protocol There is no need to change the original program structure, just add the extension part of the program to expand the function.


In this article, the CAN bus uses an active mode to send data and an interrupt mode to receive data as mentioned above. The CAN interrupt priority is higher than the priority of other tasks. In this article, data sending establishes an independent task, which has its own stack space and can be suspended or deleted by other tasks and interrupt service subroutines. This task allocates 128 OS_STK stack spaces. OS_STK is defined as a word length in μCOS-II.


The system has established two tasks (excluding statistics and idle tasks): the starting task Main_Task and the sending task CANSENDDATA_Task, with priorities of 10 and 12 respectively. After the CAN controller is initialized and the OS is initialized, the starting task Main_Task is established, the OS starts running, enters the starting task Main_Task, the starting task starts the time beat, and creates the sending task, and then enters suspend. The sending task enters the running state. When the data is sent, the sending task is suspended.


After their respective delays are over, the two tasks enter the running state in order of priority. If both tasks are in the suspended state, the idle task of the system enters the running state. If a receiving interrupt occurs during this process, the interrupt service will suspend the running task and call the CAN data receiving function to complete the reception of the data. When the process is completed, the scene will be restored and high-priority tasks will continue. Figure 3 is the system structure block diagram of the CAN communication module running in μCOS-II:
 

Implementing CAN bus intelligent node in μCOS-II on S3C44B0

The CAN bus smart node designed in this article using the above ideas communicates normally with the ZLG USBCAN-1 CAN bus development equipment. From Figure 4, you can see that data reception and transmission are proceeding smoothly.       


Conclusion

Implementing CAN bus smart nodes in μCOS-II running on S3C44B0 can overcome the shortcomings of traditional front-end and back-end programming methods, and provide modular, portable, high-real-time, and easy-to-expand communication modules, which can greatly reduce product complexity. Development time.

[1] [2]
Keywords:S3C44B0 Reference address:Implementing CAN bus intelligent node in μCOS-II on S3C44B0

Previous article:USB-HOST driver design based on UClinux2.4.x+S3C4510B development platform
Next article:Design of microwave frequency automatic measurement system based on stepper motor control using S3C44B0 chip

Recommended ReadingLatest update time:2024-11-23 07:59

Using CAN-bus network to realize ADSL communication pole detection
The CAN-bus (Controller Area Network) bus is mainly used for data communication between the measurement and control center inside the car. It defines the data link layer and part of the physical layer of the OSI network model (see Figure 1). Figure 1: Relationship between fieldbus CAN-bus and OSI model
[Test Measurement]
Using CAN-bus network to realize ADSL communication pole detection
Latest Microcontroller Articles
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号