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.
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
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:
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.
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
- Popular Resources
- Popular amplifiers
- Principle and maintenance of automobile on-board network system (CAN-BUS)
- Application of CAN bus in communication between electric vehicle BMS system and charging pile
- Learn to repair variable frequency air conditioner easily with zero basic knowledge (Zhang Yunkun and Zhang Xinde)
- Debugging and application of Mitsubishi CNC system
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- CAN communication
- Standard IC Operational Amplifier Databook (Chinese)
- Can the required driving current or driving power be calculated based on the Ciss, Qg and driving frequency of the MOS tube?
- "Constant power" power control strategy for hard-start loads (such as high-power permanent magnet brushed motors and solenoid valves)
- EEWORLD University Hall--Matlab Neural Network Principles and Examples
- Please help me explain the principle of this filter circuit and the calculation of inductance and capacitance parameters.
- CAN standard features of power system and emission diagnosis in China VI OBD online monitoring
- Happy New Year to everyone! I wish you all a happy new year!
- Help, why can't this negative voltage output circuit work?
- HSPICE Tutorial