Instrument CAN message processing method and device, computer readable storage medium and electronic equipment
By using an interrupt program to transfer messages from the cache area to RAM in CAN message processing and processing by the main processor, the problem of message processing occupies the main processor resources in the traditional method is solved, and more efficient and real-time message processing is achieved.
Patent Information
- Application Number
- CN202411839645.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-05-02
AI Technical Summary
When traditional CAN message processing methods face frequent sending and receiving messages, they occupy the main processor resources, which can easily lead to data loss or delay, affecting the stability and response speed of the system.
By triggering the interrupt program after receiving the CAN message in the CAN message cache area, the interrupt program transfers the message from the cache area to RAM, and releases the cache area and interrupt program in time. The main processor processes the messages in the RAM and sends them to the SOC.
This method effectively reduces the working pressure of the main processor, improves the real-time and accuracy of message processing, and improves the performance of the entire system.
Smart Images

Figure CN119922034A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a method and device for processing instrument CAN messages, a computer-readable storage medium and an electronic device. Background Art
[0002] With the rapid development of automotive electronic technology, vehicle network communication technology has also made significant progress. In modern automobiles, the Controller Area Network (CAN) is an efficient and reliable serial communication protocol that is widely used in data exchange between various vehicle control systems. The CAN protocol supports a multi-master structure and has a priority arbitration mechanism, which can ensure the real-time transmission of key data, so it occupies an important position in the automotive instrument system.
[0003] However, in actual applications, due to the frequent sending and receiving of CAN messages, how to efficiently process these messages has become a technical problem. The traditional CAN message processing method usually reads and parses the message by the interrupt program after receiving the message. This method not only occupies the resources of the main processor, but also easily causes data loss or delay when the message flow is large, affecting the stability and response speed of the system. Summary of the invention
[0004] In view of the above problems, the purpose of the present invention is to provide a method for processing instrument CAN messages which not only improves the real-time and accuracy of message processing, but also effectively reduces the working pressure of the system main processor and improves the performance of the entire system.
[0005] In a first aspect, a method for processing an instrument CAN message is provided, comprising:
[0006] After the CAN message buffer receives the CAN message, the interrupt program is triggered;
[0007] The interrupt program reads the CAN message in the CAN message buffer area and stores it in RAM;
[0008] Release the CAN message buffer area and the interrupt program;
[0009] The main processor processes the CAN message stored in the RAM and sends it to the SOC.
[0010] Furthermore, the processing time of the interrupt program is less than the interval time between the arrival of two adjacent frames of the CAN message.
[0011] Furthermore, the processing time of the interrupt program includes the sum of the longest interrupt processing time in the interrupt list, the interrupt processing time with a higher priority than the CAN message reception interrupt, and the CAN message reception interrupt processing time.
[0012] Furthermore, a storage area is divided in the RAM for storing the CAN messages; the capacity of the storage area is greater than twice the total storage capacity of all messages.
[0013] Further, the main processor processes the CAN message stored in the RAM and sends it to the SOC, including:
[0014] Read the CAN message;
[0015] Perform CRC, format and ACK detection checks on the CAN message;
[0016] The CAN message that has passed the detection and verification is parsed and sent to the SOC for display operation.
[0017] Furthermore, the CAN messages that fail the detection and verification are discarded.
[0018] Furthermore, the detection check includes at least one of the following: CRC detection check, format detection check and ACK detection check.
[0019] In a second aspect, a device for processing instrument CAN messages is provided, comprising:
[0020] The receiving module is used to trigger the interrupt program after the CAN message buffer area receives the CAN message;
[0021] A saving module, used for the interrupt program to read the CAN message in the CAN message buffer area and save it in RAM;
[0022] A release module, used for releasing the CAN message buffer area and the interrupt program;
[0023] Processing module: used for the main processor to process the CAN message stored in the RAM and send it to the SOC.
[0024] In a third aspect, a computer-readable storage medium is provided, which stores a program or instruction. When the program or instruction is executed on a computer, the computer executes the method for processing the instrument CAN message as described in the above technical solution.
[0025] In a fourth aspect, an electronic device is provided, comprising: a processor, the processor being coupled to a memory,
[0026] The processor is used to read and execute the computer program stored in the memory to implement the instrument CAN message processing method as described in the above technical solution.
[0027] The embodiments of the present invention have the following advantages or beneficial effects:
[0028] 1. By triggering the interrupt program immediately after receiving the CAN message in the CAN message buffer, the interrupt program is responsible for transferring the message from the buffer to the RAM and releasing the buffer and the interrupt program in time, thereby reducing the burden on the main processor and improving the speed and efficiency of message processing.
[0029] 2. In order to ensure the real-time processing of messages, this paper also considers that the processing time of the interrupt program should be less than the time interval between the arrival of two adjacent CAN message frames, and at the same time ensures that the processing time of the interrupt program includes all factors that may affect the message processing speed, such as the longest interrupt processing time, high-priority interrupt processing time, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The above and other features and advantages of the present invention will become more apparent by describing in detail exemplary embodiments thereof with reference to the attached drawings.
[0031] Figure 1 is a flow chart of a method for processing an instrument CAN message according to an exemplary embodiment;
[0032] Figure 2 is a structural schematic diagram of a system for processing instrument CAN messages according to an exemplary embodiment;
[0033] Figure 3 is a schematic structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0034] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that the present invention will be comprehensive and complete and fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar structures, and thus their detailed description will be omitted.
[0035] The terms "a", "an", "the", and "said" are used to indicate the presence of one or more elements / components / etc.; the terms "comprising" and "having" are used to express an open-ended inclusive meaning and mean that additional elements / components / etc. may be present in addition to the listed elements / components / etc.
[0036] The English abbreviations and definitions in this article are explained as follows:
[0037] CAN (Controller Area Network) is the full Chinese name: Controller Area Network.
[0038] Definition: CAN is a serial communication protocol mainly used for real-time data transmission in automobiles and other industrial equipment. It supports multi-master structure and has a priority arbitration mechanism to ensure real-time transmission of critical data.
[0039] The Chinese full name of RAM (Random Access Memory): Random Access Memory.
[0040] Definition: RAM is a volatile memory that can be accessed randomly anywhere in it. Data can be read and written quickly, but data will be lost after power failure. It is widely used in computers and embedded systems for temporary storage of data and program code.
[0041] The full Chinese name of FIFO (First In First Out): First In First Out.
[0042] Definition: FIFO is a data structure that follows the first-in-first-out principle, that is, the earliest data item to enter the queue is removed first. This structure is often used in caches and message queues to ensure that data is processed in order.
[0043] The Chinese full name of CRC (Cyclic Redundancy Check): Cyclic Redundancy Check.
[0044] Definition: CRC is a data verification algorithm used to detect errors in data transmission. By calculating the redundant code of the data and comparing it with the calculation result of the receiving end, it can be detected whether the data has errors during transmission.
[0045] ACK (Acknowledgment) stands for "Response".
[0046] Definition: ACK is a confirmation mechanism used to confirm that a data packet or message has been correctly received. After sending data, the sender will wait for the receiver's ACK signal. If ACK is received, it means that the data has been successfully transmitted; if it is not received or a NACK (negative acknowledgment) is received, the data needs to be resent.
[0047] The full Chinese name of SOC (System on Chip): system on chip.
[0048] Definition: SOC is an integrated circuit that integrates the key components of the system (such as processor, memory, input and output interface, etc.) on a single chip. SOC is designed to improve the performance and integration of the system, reduce the size and power consumption, and is widely used in embedded systems and mobile devices.
[0049] like Figure 1 As shown, a method for processing an instrument CAN message includes:
[0050] Step S101: After the CAN message buffer receives the CAN message, an interrupt program is triggered.
[0051] When the CAN transceiver receives a message, the message will be temporarily stored in the CAN message buffer. At this time, the hardware will automatically trigger an interrupt request to notify the CPU that a new message has arrived.
[0052] The CPU responds to the interrupt request and executes the CAN message reception interrupt program. According to the interrupt priority design, the priority of the CAN message reception interrupt is only lower than the power-on interrupt, which means that in most cases, this interrupt program will be processed before other interrupts.
[0053] Assume that in an automobile instrument system, the CAN transceiver of the instrument cluster receives a CAN message from the engine control unit (ECU). The CAN message contains important information such as engine speed and throttle opening. When this CAN message is successfully received and stored in the CAN message buffer, a CAN message reception interrupt program is immediately triggered. The priority of this interrupt program is set to be second only to the power-on interrupt, ensuring that in most cases, it can be processed before other types of interrupts, thereby ensuring timely processing of CAN messages and preventing messages from being overwritten by subsequent messages.
[0054] Among them, interrupt priority design: Since the interrupt program includes power-on interrupt, CAN message reception interrupt, UART interrupt, IIC interrupt and other calculation interrupts, each interrupt program has a priority level. The design priority of CAN message reception interrupt is second only to the power-on interrupt. Since the power-on interrupt is not triggered frequently when the instrument is working normally, the CAN message reception interrupt is almost the highest priority when the instrument is working normally, that is, the CAN message reception interrupt is processed first. The design of this priority level ensures that the CAN message reception interrupt does not need to wait for other interrupts to be executed, and can give priority to the reading operation of CAN messages.
[0055] Step S102: the interrupt program reads the CAN message in the CAN message buffer area and stores it in RAM.
[0056] The interrupt program starts to execute, first reading the message data from the CAN message buffer. Then, the data is copied to the pre-allocated storage area in RAM. The storage area in RAM is designed as a queue to ensure that the messages are processed according to the first-in-first-out principle. Each message can be stored in RAM in sequence to ensure that there will be no conflict with other messages.
[0057] Once the interrupt program is triggered, it will perform a series of operations to process the CAN message. First, the interrupt program will read the message data in the CAN message buffer and copy it to the storage area pre-allocated in the RAM. This RAM area is designed in the form of a queue to manage messages according to the first-in-first-out principle. Each message occupies a certain amount of storage space to ensure that even under high load conditions, message overwriting will not occur. The storage capacity of RAM is at least twice the sum of all possible received messages, which can fully guarantee the integrity of the message.
[0058] The processing time of the interrupt program is less than the interval between the arrival of two adjacent frames of the CAN messages.
[0059] In addition, the processing time of the interrupt program includes the sum of the longest interrupt processing time in the interrupt list, the interrupt processing time with a higher priority than the CAN message reception interrupt, and the CAN message reception interrupt processing time.
[0060] In order to ensure timely processing of CAN messages and avoid overwriting of messages, the processing time of the interrupt program must be less than the interval between the arrival of two adjacent CAN messages. Specifically, the interval between CAN messages on the bus is about 250 microseconds (μs). Therefore, the processing time of the interrupt program must meet the following conditions: The processing time of the interrupt program is less than 250μs.
[0061] The processing time of the interrupt program includes the following parts:
[0062] The longest interrupt processing time in the interrupt list: This refers to the interrupt with the longest processing time among all interrupts. Assume that this time is T max .
[0063] Interrupt processing time with higher priority than CAN message reception interrupt: This refers to the sum of the processing time of all interrupts with higher priority than CAN message reception interrupt. Assume this time is T higher .
[0064] CAN message receiving interrupt processing time: This refers to the processing time of the CAN message receiving interrupt itself. Assume that this time is T CAN .
[0065] Therefore, the total interrupt program processing time T totalIt can be expressed as:
[0066] T total =T max +T higher +T CAN
[0067] To ensure that all interrupts are processed within 250 microseconds, the following conditions must be met:
[0068] T max +T higher +T CAN Less than 250μs
[0069] Step S103: Release the CAN message buffer and interrupt program. After completing the copying of the message data, the interrupt program will release the CAN message buffer and interrupt program. This step ensures that the buffer can be immediately ready to receive new messages, avoiding the problem of message loss caused by a full buffer.
[0070] After the CAN message data is successfully copied to RAM, the interrupt program will release the CAN message buffer. This step is very important because only when the buffer is released can new messages continue to be received. In this way, it can ensure that the CAN message buffer is always available, avoiding the problem of new messages not being received due to the buffer being full.
[0071] After releasing the buffer, the interrupt program needs to complete the final cleanup work, such as clearing the interrupt request flag, resetting the interrupt counter, etc., and then exit the interrupt handler. This step ensures that the system can respond normally to subsequent interrupt requests. Finally, the interrupt program will resume the normal processing flow of the CPU, allowing other tasks to continue to execute. This step is usually achieved by returning to the state before the interrupt or executing a specific recovery instruction.
[0072] Step S104: the main processor processes the CAN message stored in the RAM and sends it to the SOC.
[0073] The main processor will process the message data in the RAM through a series of processes, including CRC check, format check and ACK confirmation. If the message passes all checks, it will be parsed and sent to the SOC (System on Chip), and finally displayed on the instrument cluster. If the message fails to pass the check, it will be discarded to avoid the spread of erroneous information. Specifically:
[0074] S1041: Read the CAN message. The message processing module in the RAM will read the CAN messages stored in the queue in order. Since the queue adopts the first-in-first-out (FIFO) principle, the earliest stored message will be read first.
[0075] S1042: Perform CRC, format and ACK detection checks on the CAN message.
[0076] Perform a cyclic redundancy check (CRC) on the read CAN message to ensure that no error occurs during the message transmission process.
[0077] Check whether the format of the message meets the expected standards, such as message length, identifier, etc.
[0078] Check whether the message has received the correct ACK to ensure that the message is received correctly during the transmission process.
[0079] S1043: Parse the CAN message that has passed the detection and verification and send it to the SOC for display operation.
[0080] If the message passes all checks, it is parsed into readable signal data and sent to the SOC for display.
[0081] S1044: The CAN message that fails the detection check is discarded. If the message fails any check, it is discarded to avoid the spread of erroneous information.
[0082] Through the above steps, the CAN message is processed in detail, including reading, checking, parsing and sending. Only messages that pass all checks will be parsed and sent to the SOC for display, and messages that fail the check will be discarded, ensuring the reliability of the system and the accuracy of the data. This step ensures that the instrument cluster can display accurate information, improving the user's driving safety and experience.
[0083] The present invention provides an efficient and reliable instrument CAN message processing method, which ensures timely processing and correct display of messages and improves the performance and stability of the automobile instrument system. In particular, by strictly controlling the interrupt program processing time, the problem of message coverage is effectively avoided, ensuring the real-time performance and reliability of the system.
[0084] like Figure 2 As shown, a device for processing instrument CAN messages according to an embodiment of the present invention includes:
[0085] The receiving module 201 is used to trigger the interrupt program after the CAN message buffer area receives the CAN message;
[0086] A saving module 202 is used for the interrupt program to save the CAN message in the CAN message buffer area in the RAM;
[0087] A release module 203, used for releasing the CAN message buffer area and the interrupt program;
[0088] Processing module 204: used for the main processor to process the CAN message stored in the RAM and send it to the SOC.
[0089] It should be noted here that the above-mentioned receiving module 201, saving module 202, releasing module 203 and processing module 204 correspond to steps S101 to S104 in the embodiment of the method for processing instrument CAN messages, and the examples and application scenarios implemented by the above-mentioned modules and corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned embodiments.
[0090] The technical solutions in the above embodiments of the present application have at least the following technical effects or advantages:
[0091] 1. By triggering the interrupt program immediately after receiving the CAN message in the CAN message buffer, the interrupt program is responsible for transferring the message from the buffer to the RAM and releasing the buffer and the interrupt program in time, thereby reducing the burden on the main processor and improving the speed and efficiency of message processing.
[0092] 2. In order to ensure the real-time nature of message processing, the present invention also considers that the processing time of the interrupt program should be less than the time interval between the arrival of two adjacent CAN message frames, and ensures that the processing time of the interrupt program includes all factors that may affect the message processing speed, such as the longest interrupt processing time, high priority interrupt processing time, etc. An embodiment of the present invention also provides a computer-readable storage medium storing a program or instruction, which, when executed on a computer, enables the computer to execute the CAN message processing method described in the above embodiment.
[0093] like Figure 3 As shown, an embodiment of the present invention further provides an electronic device 300, including: a processor 301, the processor 301 is coupled to a memory 302,
[0094] The processor 301 is used to read and execute the computer program stored in the memory to implement the method for processing the instrument CAN message as described in the above method embodiment.
[0095] In the embodiments of the present invention, the term "plurality" refers to two or more than two, unless otherwise clearly defined. The terms "installation", "connection", "fixation" and the like should be understood in a broad sense. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection. For those of ordinary skill in the art, the specific meanings of the above terms in the embodiments of the present invention can be understood according to specific circumstances.
[0096] In the description of the embodiments of the present invention, it needs to be understood that the directions or positional relationships indicated by the terms "upper" and "lower" are based on the directions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the embodiments of the present invention and simplifying the description, rather than indicating or implying that the device or unit referred to must have a specific direction, be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation on the embodiments of the present invention.
[0097] In the description of this specification, the description of the terms "one embodiment", "a preferred embodiment", etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiment of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0098] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for processing instrument CAN messages, characterized in that: include: After the CAN message buffer receives the CAN message, the interrupt program is triggered; The interrupt program reads the CAN message in the CAN message buffer area and stores it in RAM; Release the CAN message buffer area and the interrupt program; The main processor processes the CAN message stored in the RAM and sends it to the SOC.
2. The method for processing instrument CAN messages according to claim 1, characterized in that: The processing time of the interrupt program is less than the interval time between the arrival of two adjacent frames of the CAN message.
3. A method for processing instrument CAN messages according to any one of claims 1 or 2, characterized in that: The processing time of the interrupt program includes the sum of the longest interrupt processing time in the interrupt list, the interrupt processing time with a higher priority than the CAN message reception interrupt, and the CAN message reception interrupt processing time.
4. The method for processing instrument CAN messages according to claim 1, characterized in that: A storage area is divided in the RAM for storing the CAN message; the capacity of the storage area is greater than twice the total storage capacity of all messages.
5. The method for processing instrument CAN messages according to claim 1, characterized in that: The main processor processes the CAN message stored in the RAM and sends it to the SOC, including: Read the CAN message; Perform CRC, format and ACK detection checks on the CAN message; The CAN message that has passed the detection and verification is parsed and sent to the SOC for display operation.
6. The method for processing instrument CAN messages according to claim 5, characterized in that: The CAN messages that fail the detection verification are discarded.
7. The method for processing instrument CAN messages according to claim 6, characterized in that: The detection check includes at least one of the following: CRC detection check, format detection check and ACK detection check.
8. A device for processing instrument CAN messages, characterized in that: include: The receiving module is used to trigger the interrupt program after the CAN message buffer area receives the CAN message; A storage module, used for the interrupt program to read the CAN message in the CAN message buffer area and store it in RAM; A release module, used for releasing the CAN message buffer area and the interrupt program; Processing module: used for the main processor to process the CAN message stored in the RAM and send it to the SOC.
9. A computer-readable storage medium, characterized in that: A program or instruction is stored, and when the program or instruction is run on a computer, the computer is caused to execute the instrument CAN message processing method according to any one of claims 1 to 7.
10. An electronic device, characterized in that: include: a processor coupled to the memory, The processor is used to read and execute the computer program stored in the memory to implement the instrument CAN message processing method according to any one of claims 1 to 7.