Scheduling method for improving CAN bus message receiving performance

By establishing a circular queue buffer and performing data filtering inside the MCU, the CAN bus message reception performance is improved, the problem of unstable data transmission under high load is solved, and efficient data storage and processing is achieved.

CN120785677APending Publication Date: 2025-10-14ZHEJIANG YANENG ENERGY TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511136235.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-14
Publication Date
2025-10-14

AI Technical Summary

Technical Problem

Under high load conditions, the data transmission success rate of the CAN bus decreases and the bit error rate increases. In particular, communication is affected in high-density data exchange scenarios, resulting in unstable communication between node modules.

Method used

A circular queue buffer is divided and established inside the MCU. The receive interrupt signal of the CAN controller triggers the MCU to read the CAN bus message data and perform data filtering. Only messages that meet the preset requirements are stored in the circular queue buffer, and the receive pointer is dynamically updated to achieve orderly storage and processing of messages.

Benefits of technology

It significantly improves the reception reliability, anti-interference capability and real-time performance of CAN bus messages under instantaneous high load and complex communication scenarios, ensuring that key data is not lost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120785677A_ABST
    Figure CN120785677A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of CAN communication, and discloses a scheduling method for improving CAN bus message receiving performance, which performs efficient cache management on received CAN messages by dividing and establishing a circular queue buffer area in an MCU (Microprogrammed Control Unit). Specifically, the CAN controller triggers receiving interruption after receiving a first frame of CAN bus message, the MCU responds immediately and obtains complete data of the message, then data filtering based on a preset rule is executed, and it is ensured that only the message meeting the condition is written into a circular queue. Through the dynamic update of the receiving pointer, the orderly storage of the message in the buffer area and the smoothness of the subsequent processing channel are realized, and the receiving reliability and the anti-interference capability of the message and the overall communication real-time performance of the system under the instantaneous high load and complex communication scene are obviously improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of CAN communication technology, and more specifically, to a scheduling method for improving the CAN bus message receiving performance. Background Art

[0002] With technological advancements, the CAN bus (Controller Area Network), a serial communication network for distributed real-time control, has gained widespread application and development in a variety of fields, including industrial automation, automotive electronics, and aerospace. The CAN bus transmits data via differential signals between two signal lines (CANH and CANL). All node submodules connected to the CAN bus are connected to these two communication lines and communicate using half-duplex mode. This design enables the CAN bus to operate stably in complex environments and exhibits excellent anti-interference performance.

[0003] However, in practical applications, the CAN bus faces multiple challenges. First, environmental factors such as differential-mode interference, common-mode interference, and communication distance can affect the normal operation of the CAN bus. Second, with technological advancements, the data load transmitted on the CAN bus is also increasing. Especially in some high-density data exchange applications, when a large number of messages suddenly appear on the bus, it may affect communication between node modules, reduce the success rate of data transmission, and increase the bit error rate. These challenges require the search for a more efficient scheduling method to improve the performance of CAN bus message reception and ensure the quality and stability of data transmission. Summary of the Invention

[0004] In order to solve the above technical problems, the present application is proposed. The embodiments of the present application propose a scheduling method for improving the CAN bus message reception performance, which aims to solve the problems of decreased data transmission success rate and increased bit error rate under high load conditions.

[0005] According to one aspect of the present application, a scheduling method for improving the CAN bus message reception performance is provided, including: dividing and establishing a circular queue buffer in the internal storage space of an MCU (microcontroller), wherein the circular queue buffer is used to temporarily store received CAN bus messages; after receiving a first frame of CAN bus message, the CAN controller triggers a receive interrupt signal; after responding to the receive interrupt signal, the MCU reads the complete message data of the first frame of CAN bus message from the CAN controller; the MCU performs data filtering on the complete message data of the first frame of CAN bus message to determine whether the first frame of CAN bus message meets preset requirements; in response to the first frame of CAN bus message meeting the preset requirements, the first frame of CAN bus message is stored in the circular queue buffer; after confirming that the first frame of CAN bus message is stored in the circular queue buffer, the receive pointer is updated, and the receive pointer points to the next idle slot of the circular queue buffer.

[0006] In a possible implementation, the complete message data of the first frame of the CAN bus message includes an identifier, a frame type, a frame format, a data length code, data content, a CRC check result, and an ACK status.

[0007] In one possible implementation, the MCU performs data filtering on the complete message data of the first frame CAN bus message to determine whether the first frame CAN bus message meets the preset requirements, including: extracting an identifier from the complete message data of the first frame CAN bus message; checking whether the identifier is in the interested ID list; in response to the identifier being in the interested ID list, confirming that the first frame CAN bus message meets the preset requirements; in response to the identifier not being in the interested ID list, confirming that the first frame CAN bus message does not meet the preset requirements.

[0008] In one possible implementation, in response to the identifier not being in the interested ID list, confirming that the first frame CAN bus message does not meet preset requirements includes: in response to the identifier not being in the interested ID list, immediately discarding the first frame CAN bus message.

[0009] In one possible implementation, in response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer, including: checking whether the circular queue buffer is full; if the circular queue buffer is not full, the first frame CAN bus message is stored in the circular queue buffer.

[0010] In a possible implementation, in response to the first frame CAN bus message meeting preset requirements, the first frame CAN bus message is stored in the circular queue buffer, and further includes: in response to the circular queue buffer being full, triggering an overflow alarm prompt.

[0011] In one possible implementation, in response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer, and it also includes: in response to the circular queue buffer being full, the first frame CAN bus message overwrites the earliest unprocessed message in the circular queue buffer.

[0012] In one possible implementation, in response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer, and it also includes: in response to the circular queue buffer being full, based on the comparison between the overwrite probability and the preset threshold, determining whether to overwrite the earliest unprocessed message in the circular queue buffer with the first frame CAN bus message.

[0013] In one possible implementation, determining the rewrite probability includes: determining the ratio between the data content in the message data of the first frame CAN bus message and the total message data of the first frame CAN bus message to obtain a first ratio; determining the ratio between the total message data of the first frame CAN bus message and the capacity of the slots in the circular queue buffer to obtain a first capacity ratio; determining the capacity ratio of each slot in the current circular queue buffer as a capacity topology probability distribution representation within the capacity feature distribution space; calculating a joint probability determination coefficient based on the first ratio, the first capacity ratio and the mean of the capacity topology probability distribution; performing a logarithmic transformation on the first ratio and the first capacity ratio to determine a logarithmically corrected comprehensive probability; and determining the rewrite probability by reconstructing the distribution solution space based on the capacity topology probability distribution, the joint probability determination coefficient and the logarithmically corrected comprehensive probability.

[0014] Compared with the prior art, the scheduling method provided by this application for improving the CAN bus message reception performance is to divide and establish a circular queue buffer within the MCU to efficiently cache the received CAN messages. Specifically, after the CAN controller receives the first frame of the CAN bus message, it triggers a receive interrupt. The MCU responds immediately and obtains the complete message data. It then performs data filtering based on preset rules to ensure that only messages that meet the conditions are written to the circular queue. By dynamically updating the receiving pointer, the orderly storage of messages in the buffer and the smooth flow of subsequent processing channels are achieved, significantly improving the message reception reliability, anti-interference ability and real-time communication performance of the system as a whole under instantaneous high load and complex communication scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The above and other purposes, features, and advantages of the present application will become more apparent through a more detailed description of the embodiments of the present application in conjunction with the accompanying drawings. The accompanying drawings are intended to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. In the drawings, the same reference numerals generally represent the same components or steps.

[0016] Figure 1 The figure shows a schematic diagram of a CAN bus network according to an embodiment of the present application.

[0017] Figure 2 The figure shows a schematic diagram of a CAN hardware driver circuit according to an embodiment of the present application.

[0018] Figure 3 The figure shows a schematic diagram of a CAN message frame according to an embodiment of the present application.

[0019] Figure 4 The figure shows a schematic diagram of message flow under high load conditions of the CAN bus according to an embodiment of the present application.

[0020] Figure 5 The figure shows a schematic diagram of the CAN message processing mechanism according to an embodiment of the present application.

[0021] Figure 6 The figure shows a schematic diagram of a CAN message queue receiving buffer according to an embodiment of the present application.

[0022] Figure 7 The figure illustrates a schematic flow chart of a scheduling method for improving CAN bus message reception performance according to an embodiment of the present application.

[0023] Figure 8 The figure illustrates a schematic flowchart of step S4 in the scheduling method for improving the CAN bus message reception performance according to an embodiment of the present application. DETAILED DESCRIPTION

[0024] Below, the exemplary embodiments according to the present application will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application, and it should be understood that the present application is not limited to the exemplary embodiments described herein.

[0025] Figure 1 The diagram shows a schematic diagram of a CAN bus network according to an embodiment of the present application. Figure 1As shown, the CAN bus can have multiple CAN nodes connected to the CAN bus. At least one of the CAN nodes includes the receiver and controller functions of any of the CAN communications described. The topology of the CAN bus should be a linear structure or a star structure, and a ring structure should not be used. The bus length should not exceed 40 meters, otherwise the bus signal will attenuate, affecting data transmission. Generally speaking, the number of bus nodes should not exceed 100, otherwise it will affect the communication speed and reliability of the bus. When using the CAN bus, bus errors need to be processed, including the processing of error frames, the processing of bus disconnections, the processing of bus conflicts, etc. This is generally designed in the corresponding CAN peripheral configuration to ensure the stability and reliability of the bus.

[0026] After the bus physical network architecture is clear, Figure 2 FIG. 1 shows a schematic diagram of a CAN hardware driver circuit according to an embodiment of the present application. Figure 2 As shown, the CAN hardware driver circuit comprises an MCU (microcontroller), a CAN controller, a CAN transceiver, CANH (high voltage line), and CANL (low voltage line). The CAN transceivers of all CAN nodes are connected to the same bus using the CANH and CANL lines. Furthermore, this application provides two solutions for building the CAN hardware driver circuit. The first technical solution utilizes a standard microcontroller, an independent CAN controller, and a CAN transceiver; the second technical solution utilizes a microcontroller with an integrated CAN controller and a CAN transceiver. The first solution offers a flexible architecture, adaptable to a variety of standard buses, and is relatively cost-effective, but with a more complex circuit. The second solution offers a high degree of integration and a simple circuit design, making it suitable for high-density deployments, but at a relatively higher cost. Current mainstream microcontrollers, such as MCUs with CAN functionality, only require a CAN transceiver to perform voltage level conversion and bus communication. Regardless of the node architecture used to join the network, they can be connected via a bus or star topology, ensuring compatibility and matching of hardware resources with the physical topology.

[0027] Figure 3 The figure shows a schematic diagram of a CAN message frame according to an embodiment of the present application. Figure 3As shown in the figure, each CAN message frame consists of an identifier, frame type, frame format, data length code, data content, CRC check result, and ACK status. The identifier (ID) determines the message priority and, based on its length, categorizes messages into standard frames (11-bit identifier, CAN2.0A) and extended frames (29-bit identifier, CAN2.0B). The frame type and format further indicate the message type and structure. The data length code specifies the number of bytes in the data content area, providing the basis for the effective carrying of data content. The data content area is the primary payload of each message and can be up to 8 bytes. Furthermore, the CRC check result ensures data integrity during message transmission, and the ACK status provides confirmation of message reception. Data interoperability and protocol compatibility between nodes require compliance with the above message frame format and its various field design and functional specifications. Only in this way can subsequent processing steps, such as message filtering, identification, buffering, and retransmission, be performed efficiently and accurately, ensuring stable and reliable system operation.

[0028] Node configuration and data synchronization also require setting appropriate timing parameters for each CAN controller. During the initial configuration phase, nodes must specify the transmitting end's bit timing information, including the length of the time quantum, the allocation of various timing segments, and the jump width for resynchronization. The CAN protocol decomposes each bit into a synchronization segment, a propagation segment, and the first / second phase buffer segments. Each segment is precisely defined, with the minimum time unit being the time quantum (Tq). The entire bit period can consist of 8 to 25 Tqs. This configuration ensures signal sampling and synchronization among all nodes on the bus network, preventing data distortion and ensuring continuous and stable communication between nodes and their peers.

[0029] After the node is configured with the above timing parameters, combined with the message format and hardware architecture, Figure 4 The diagram shows a schematic diagram of message flow under high load conditions on the CAN bus according to an embodiment of the present application. In actual operation, the bus only allows single-frame messages to be transmitted at the same time. When multiple nodes (such as node 1, node 2, and node 3) try to send messages at the same time, an arbitration mechanism is used to determine who will occupy the bus first, and the remaining nodes queue up in turn. This figure simulates a high-load instantaneous multi-message impact scenario, directly revealing the necessity of bus congestion, message orderliness, and non-frame loss transmission. In this case, if the node end does not have an efficient burst buffer and flow control mechanism, the messages that are of real concern and high priority are at risk of being lost.

[0030] In response to the data management pressure on the node end, this application proposes a scheduling method to improve the CAN bus message receiving performance. Its processing mechanism is as follows: Figure 5 As shown. It divides a storage space inside the MCU as a circular buffer queue at the software level. The CAN message queue receiving buffer is as follows Figure 6 As shown. When a message arrives, it is temporarily stored in the buffer queue without waiting for application processing, ensuring that message reception and buffering are carried out asynchronously on both channels. If the application is still processing the previous frame of data, the new message is automatically transferred to the next free slot. By setting the lock flag, problems such as concurrent write and read conflicts can be properly resolved to prevent data overwriting and omission. This mechanism essentially converts the hardware signal flow into a controllable data stream managed by software without loss, greatly enhancing the node's stress resistance and emergency response capabilities in high-concurrency scenarios. In this way, the actual challenge of massive message bursts arriving at the node end can be addressed, ensuring the overall reliable operation of the network.

[0031] More specifically, Figure 7 FIG2 is a schematic flow chart of a scheduling method for improving the CAN bus message receiving performance according to an embodiment of the present application. Figure 1 As shown, the scheduling method for improving the CAN bus message receiving performance includes: S1, dividing and establishing a circular queue buffer in the internal storage space of the MCU, and the circular queue buffer is used to temporarily store the received CAN bus messages; S2, the CAN controller triggers a receive interrupt signal after receiving the first frame of the CAN bus message; S3, the MCU reads the complete message data of the first frame of the CAN bus message from the CAN controller after responding to the receive interrupt signal; S4, the MCU performs data filtering on the complete message data of the first frame of the CAN bus message to determine whether the first frame of the CAN bus message meets the preset requirements; S5, in response to the first frame of the CAN bus message meeting the preset requirements, the first frame of the CAN bus message is stored in the circular queue buffer; S6, after confirming that the first frame of the CAN bus message is stored in the circular queue buffer, the receive pointer is updated, and the receive pointer points to the next idle slot of the circular queue buffer.

[0032] For example, in step S1, a circular queue buffer is established within the MCU's internal memory space to temporarily store received CAN bus messages. This should be understood. A dedicated area within the MCU's internal memory space is allocated to create a circular queue buffer for temporarily storing each message received via the CAN bus. This creates a large-capacity temporary data buffer pool that is reusable and adaptable to sudden timing fluctuations. A circular queue divides a designated RAM space into several consecutive buffer slots, connecting them end-to-end using the logical structure of a ring queue. This allows for dynamic and efficient management of message reception and output within limited physical memory capacity, significantly improving cache utilization and the immediacy of data processing. A circular queue differs from a traditional FIFO queue in that the queue does not stop when the tail pointer reaches the bottom of the queue, but instead wraps back to the starting point to continue writing in a circular loop, achieving slot recycling. As long as the queue is not overloaded and new messages do not overwrite unprocessed data, the entire queue can continuously and efficiently provide reliable cache support for the MCU's message reading and processing. In a specific embodiment, 10 buffer zones are set to be circulated. Of course, this is only an example, and the specific buffer zone can be adjusted according to actual conditions.

[0033] For example, in step S2, the CAN controller triggers a receive interrupt signal after receiving the first frame of the CAN bus message. It should be understood that in the communication environment of the CAN bus, the arrival of external messages is obviously asynchronous and sudden. The traditional polling mechanism is not only inefficient, but also easily causes the node to lose messages under high load or burst traffic conditions. When the interrupt trigger method is adopted, the MCU can receive an immediate response signal when the message actually arrives, without wasting processing resources waiting for data, greatly improving the real-time response of the system and ensuring that data can be captured in the first time. This is especially important for industrial control, automotive electronics and other occasions that require extremely high communication reliability and low latency.

[0034] In one specific embodiment, the CAN controller has a built-in transmit and receive buffer, or message mailbox. Whenever a new message arrives on the bus and successfully passes arbitration and verification, the CAN controller stores all data fields of the message in an internal register. Once this storage process is complete, the CAN controller automatically sets the corresponding receive interrupt flag based on the hardware configuration and quickly reports this event to the MCU via an interrupt line. This process is accomplished quickly through a direct hardware connection, with the interrupt signal connected to the MCU's external interrupt pin or a dedicated serial peripheral interrupt set, ensuring that the MCU can be immediately awakened at any time and clearly informed of the arrival of a new message.

[0035] The use of this interrupt-driven mechanism not only significantly reduces the latency from when a message arrives at the CAN interface until the MCU is given the opportunity to process it, but also ensures that the MCU is not overloaded when processing batches of high-frequency messages, because message processing only begins when a new message actually arrives. This event-driven design provides a solid foundation for efficient information flow and compact management, and fully leverages the synergy between hardware and MCUs. Regardless of sudden changes in communication traffic or peak values, it can effectively buffer and process critical data, preventing the loss of critical data.

[0036] Exemplarily, in step S3, after responding to the receive interrupt signal, the MCU reads the complete message data of the first CAN bus message frame from the CAN controller. It should be understood that after the CAN controller generates a receive interrupt, the MCU must immediately respond and proactively read all the component fields of the frame message from the corresponding message buffer of the CAN controller. The importance of this design is primarily reflected in the strict guarantee of data real-time and integrity. In one embodiment, the complete message data of the first CAN bus message frame includes an identifier, frame type, frame format, data length code, data content, CRC check result, and ACK status. The identifier determines the message's ownership and priority, serving as an important basis for subsequent filtering and reception. The frame type and format distinguish the message's physical form and protocol version (e.g., standard or extended), facilitating protocol compatibility in subsequent industrial applications. The data length code (DLC) indicates the length of the subsequent data area, ensuring consistent data parsing and access, and preventing data misreading due to missing fields. The data content area carries valid business data and is fundamental to the actual control and monitoring of each CAN bus node. The CRC checksum ensures the integrity and correctness of data transmission, and the ACK status reflects the reception feedback of the frame message on the bus, providing a valuable reference for identifying communication anomalies. Only when the MCU actively, completely, and simultaneously reads all of this data after a receive interrupt occurs can the entire data reception process be guaranteed to be free of loss, interruption, and ambiguity.

[0037] In one embodiment, a special interrupt service function is designed inside the MCU for the CAN controller message reading process. When the CAN controller detects that the data information has reached the designated mailbox or receiving buffer, it will lead the receiving interrupt signal to an external interrupt input pin of the MCU, or as a high-priority interrupt source of the internal system bus. After the interrupt is triggered, the MCU immediately suspends the current normal task flow execution and switches to the corresponding interrupt handling routine. At this time, the interrupt service function first finds out which CAN channel and which buffer mailbox generated the interrupt, and then accesses the register or memory mapping space of the CAN controller according to the protocol, and reads all the fields of the corresponding frame through SPI, I2C, parallel bus, etc. In a specific embodiment, a Cortex-M series chip or a higher-performance MCU will be used, and its hardware driver library provides standard API functions or register access strategies, which can pull all data frames except error frames into internal RAM or a custom cache structure with one instruction.

[0038] For example, in step S4, the MCU performs data filtering on the complete message data of the first CAN bus message frame to determine whether the first CAN bus message frame meets preset requirements. It should be understood that the CAN bus is a multi-main linear structure, with a large number of different types of nodes connected to a single communication line. All nodes can receive all messages published on the bus, and the messages are physically transmitted in broadcast mode. Essentially, messages on the bus do not directly distinguish "destination addresses" but instead rely on IDs to classify message attributes and content types. As a result, only a portion of the messages received by each node are truly relevant to its own business logic, while the majority are irrelevant messages. If every node in all environments indiscriminately processes and caches all messages, it will not only significantly increase the processing burden, memory pressure, and power consumption of the node MCU, but will also easily cause the cache queue resources to be occupied by invalid messages, resulting in frame loss, delays, or even anomalies in critical communication information.

[0039] In one embodiment, Figure 8 FIG is a schematic flow chart of step S4 in the scheduling method for improving the CAN bus message receiving performance according to an embodiment of the present application. Figure 8 As shown, the MCU performs data filtering on the complete message data of the first frame CAN bus message to determine whether the first frame CAN bus message meets the preset requirements, including: S41, extracting an identifier from the complete message data of the first frame CAN bus message; S42, checking whether the identifier is in the interested ID list; S43, in response to the identifier being in the interested ID list, confirming that the first frame CAN bus message meets the preset requirements; S44, in response to the identifier not being in the interested ID list, confirming that the first frame CAN bus message does not meet the preset requirements.

[0040] Specifically, the MCU first filters the complete message data of the first CAN bus message frame based primarily on the message identifier. Since each message identifier in the CAN protocol maps to a specific signal, command, or service scenario, a node can pre-compile a list of IDs of interest based on its service requirements. The MCU extracts the identifier field of each received complete message and matches it against a locally preloaded list of IDs. In one specific embodiment, the MCU can use a table lookup, hashing, or efficient logical comparison to compare each identifier against the local table of IDs of interest. If the identifier is in the list of IDs of interest, it indicates that the content of the message is relevant to the node, such as requiring the node to parse its data field, trigger certain services, provide status feedback, or perform fault handling. In this case, the MCU confirms that the first CAN bus message frame meets the preset requirements and subsequently caches it in a circular queue for further processing. Conversely, if the message identifier is not in the list of IDs of interest, it indicates that the first CAN bus message frame does not meet the preset requirements, and the MCU can simply ignore the data, saving valuable subsequent storage and processing resources.

[0041] In one embodiment, in response to the identifier not being in the list of interested IDs, determining that the first CAN bus message frame does not meet preset requirements includes: immediately discarding the first CAN bus message frame in response to the identifier not being in the list of interested IDs. It should be understood that this receive-and-discard mechanism can achieve high real-time performance, reduce system load, and optimize resource allocation.

[0042] Exemplarily, in step S5, in response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer. It should be understood that the CAN bus is a typical multi-node communication structure, which physically adopts a broadcast mechanism, and all nodes can theoretically see all messages. After the node MCU receives the message and filters the data, only when this first frame CAN bus message meets the preset requirements, it truly represents that it has practical significance for this node or its upper business. Caching these valid messages that meet the specified business logic or associated system can not only ensure that the information of interest to the system is recorded reliably, completely and sequentially, but also ensure that the buffer is not lost under short-term data peaks, the memory is not overloaded, and subsequent business can be processed sustainably and efficiently.

[0043] In one embodiment, in response to the first CAN bus message frame meeting preset requirements, storing the first CAN bus message frame in the circular queue buffer includes: checking whether the circular queue buffer is full; and if the circular queue buffer is not full, storing the first CAN bus message frame in the circular queue buffer. It should be understood that under high load conditions, a large number of messages received in real time may quickly fill the buffer, so effective buffer space management is crucial to ensuring system stability and reliability. By promptly checking the buffer status and storing new messages only when there is sufficient space, data loss or system crashes caused by buffer overflow can be avoided. In a specific embodiment, the presence of an available slot is determined by comparing the states of the receive pointer and the transmit pointer after movement, combined with a logical condition for distinguishing an empty queue state (e.g., the head of the queue is equal to the tail of the queue and the empty slot flag is true). If the queue is not full, the MCU writes the target message completely to the slot indicated by the receive pointer in accordance with the protocol sequence.

[0044] In one embodiment, in response to the first CAN bus message frame meeting preset requirements, the first CAN bus message frame is stored in the circular queue buffer, and the method further includes: in response to the circular queue buffer being full, triggering an overflow alarm prompt. It should be understood that in special scenarios where the buffer is full, to prevent the inability to store new data due to the continuous arrival of a large number of valid messages, the present application further proposes an overflow alarm mechanism. When the MCU determines that the queue is full, it can actively trigger a system warning, and the system task coordination, business monitoring layer, or operator can intervene in a timely manner.

[0045] In another embodiment, in response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer, and further includes: in response to the circular queue buffer being full, the first frame CAN bus message is used to overwrite the earliest unprocessed message in the circular queue buffer. Specifically, when the buffer is full but new valid messages need to be forcibly stored, the MCU is allowed to directly overwrite the earliest queued data that has not been processed by the application in the order of the queue. The core purpose of doing this is to prevent the complete loss of critical messages under extreme conditions of continuous high load. This rolling window mechanism can ensure that the system always saves the latest N business-critical messages, taking into account both data real-time and buffer robustness.

[0046] When the circular queue buffer is full, one way to determine whether to overwrite the earliest unprocessed message in the circular queue buffer with the first frame CAN bus message can be to make a determination based on the probabilistic generalization of the capacity topology of each slot, thereby adapting to the complex data capacity distribution change scenario between frames of CAN bus messages, so as to achieve the optimization of the rewrite strategy for covering the earliest unprocessed message.

[0047] Based on this, in yet another embodiment, in response to the first frame CAN bus message meeting the preset requirement, storing the first frame CAN bus message into the circular queue buffer further includes: in response to the circular queue buffer being full, determining whether to overwrite the earliest unprocessed message in the circular queue buffer based on a comparison between the overwrite probability and a preset threshold.

[0048] Specifically, determining the overwrite probability includes: determining a ratio between data content in message data of the first frame CAN bus message and total message data of the first frame CAN bus message to obtain a first ratio That is, expressing the effectiveness of the first frame CAN bus message as data in the capacity feature distribution space, and further determining a capacity ratio between the total message data of the first frame CAN bus message and a slot capacity in the circular queue buffer to obtain a first capacity ratio That is, the compatibility representation under the capacity feature distribution space, and determining a capacity ratio of each slot in the circular queue buffer at present as a capacity topological probability distribution in the capacity feature distribution space .

[0049] Then, based on the first ratio, the first capacity ratio, and a mean value of the capacity topological probability distribution , a joint probability decision coefficient is calculated to balance the effectiveness and compatibility in the capacity feature distribution space, that is: ; wherein, represents the joint probability decision coefficient.

[0050] Thus, the topological probability distribution is used to replace the compensation of the capacity ratio probability distribution in the fixed dimension, thereby realizing the dynamic probability distribution strategy.

[0051] Next, logarithmic transformation is performed on the first ratio and the first capacity ratio to determine a logarithmic modified comprehensive probability, that is, the logarithmic transformation is used to reduce the priority of low effectiveness and low compatibility data, that is: ; wherein, represents the logarithmic modified comprehensive probability.

[0052] In order to avoid the influence of the small probability sample significantly deviating from the center of the probability distribution on the decision probability.

[0053] Finally, based on the capacity topological probability distribution, the joint probability decision coefficient, and the logarithmic modified comprehensive probability, the overwrite probability is determined through distribution solution space reconstruction, that is: ; wherein, is an amplitude modulation coefficient, which can be set according to experience, for example , of course, the above is only an example, the present example is not specifically limited, represents the rewriting probability.

[0054] That is, by representing the effectiveness probability in the capacity feature distribution space and the compatibility probability is substituted into the capacity topological probability distribution represented by the capacity feature probability topological distribution space, the rewriting strategy optimization based on the capacity distribution can be converted into distribution reconstruction in the probability topological distribution space, thereby avoiding direct dependence on local capacity information and improving the rewriting judgment accuracy in the complex data capacity distribution change scenario of the circular queue.

[0055] More specifically, in this embodiment, the preset threshold reflects the dynamic balance between the tolerance of data loss risk and the demand for data timeliness, which can be set according to experience. For example, in some extremely real-time occasions, such as safety control or motion control fields, it is more inclined to preferentially guarantee the reception of the latest message, even if part of the historical data is discarded. In this case, the threshold is often set lower. For example, when the rewriting probability reaches a relatively low level of 0.4, 0.5, it is allowed to be overwritten to ensure the real-time of the data. In the industrial acquisition or fault tracing scene that needs full data tracing or complete historical monitoring, the complete storage and continuity of each frame of data are pursued, and the latest message is discarded, and the earliest unprocessed message is not allowed to be overwritten, and the threshold is set relatively high, such as 0.8 or even higher, of course, the above is only an example, the present example is not specifically limited.

[0056] Illustratively, in step S6, after confirming that the first frame of CAN bus message is stored in the circular queue buffer, the receiving pointer is updated, and the receiving pointer points to the next free slot of the circular queue buffer. It should be understood that the circular queue actually divides a continuous or logically annular storage space into multiple equal-length slots, and each slot can accommodate all component fields of a complete CAN message according to the protocol. The entire queue is maintained by the head pointer (receiving pointer, write pointer), tail pointer (processing pointer, read pointer) and ring capacity state variable. Whenever a successful write is made, only when all fields of the message (such as identifier, frame type, data, check, ACK, etc.) are correctly written into the target slot, the receiving pointer is incremented (i.e., pointing to the next free slot) or rolled back (i.e., when the pointer grows to the end of the queue, it automatically returns to the beginning of the queue). This mechanism ensures that the available space of the buffer and the state of the data to be processed are completely controllable at any time, and the first-in first-out model and resource reusability are fully realized.

[0057] In a specific embodiment, the circular queue is implemented as a structure array and equipped with an integer variable as a receiving pointer. This pointer initially points to the first slot of the array. Each time a valid message is written, the content is first copied or written into the target data block according to the protocol format, and then the pointer is incremented to determine whether the upper limit has been reached. If it has been reached, the pointer is reset to 0 or 1 to achieve wraparound. Any enqueue operation must update the pointer after the write integrity check is passed to prevent data inconsistency or incomplete assignment. This post-write pointer update method is the only correct way to ensure data block consistency, thread safety, and efficient use of queue capacity.

[0058] In summary, the scheduling method for improving the CAN bus message reception performance provided by this application performs efficient cache management of received CAN messages by dividing and establishing a circular queue buffer within the MCU. Specifically, the CAN controller triggers a receive interrupt after receiving the first frame of the CAN bus message. The MCU responds immediately and obtains the complete message data, and then performs data filtering based on preset rules to ensure that only messages that meet the conditions are written to the circular queue. By dynamically updating the receiving pointer, the orderly storage of messages in the buffer and the smooth flow of subsequent processing channels are achieved, significantly improving the message reception reliability, anti-interference ability and overall communication real-time performance of the system under instantaneous high load and complex communication scenarios.

[0059] The basic principles of the present application have been described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, and effects mentioned in this application are merely illustrative and not restrictive, and it should not be assumed that these advantages, strengths, and effects are required of each embodiment of this application. In addition, the specific details disclosed above are merely illustrative and facilitating understanding, and are not restrictive. The above details do not limit this application to necessarily being implemented using the above specific details.

[0060] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present application. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present application. Therefore, the present application is not intended to be limited to the aspects shown herein, but rather to be accorded the widest scope consistent with the principles and novel features disclosed herein.

[0061] The above description has been provided for the purpose of illustration and description. Furthermore, this description is not intended to limit the embodiments of the present application to the forms disclosed herein. Although a number of example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations thereof.

Claims

1. A scheduling method for improving CAN bus message reception performance, characterized in that: include: Divide and establish a circular queue buffer in the internal storage space of the MCU, wherein the circular queue buffer is used to temporarily store received CAN bus messages; After receiving a first frame of a CAN bus message, the CAN controller triggers a receive interrupt signal; after responding to the receive interrupt signal, the MCU reads complete message data of the first frame of the CAN bus message from the CAN controller; the MCU performs data filtering on the complete message data of the first frame of the CAN bus message to determine whether the first frame of the CAN bus message meets preset requirements; In response to the first frame of CAN bus message meeting a preset requirement, storing the first frame of CAN bus message in the circular queue buffer; After confirming that the first frame of CAN bus message is stored in the circular queue buffer, the receiving pointer is updated to point to the next idle slot in the circular queue buffer.

2. The scheduling method for improving CAN bus message receiving performance according to claim 1, characterized in that: The complete message data of the first frame of CAN bus message includes an identifier, a frame type, a frame format, a data length code, data content, a CRC check result and an ACK status.

3. The scheduling method for improving CAN bus message receiving performance according to claim 2 is characterized in that: The MCU performs data filtering on the complete message data of the first frame CAN bus message to determine whether the first frame CAN bus message meets the preset requirements, including: extracting an identifier from the complete message data of the first frame CAN bus message; checking whether the identifier is in the interested ID list; in response to the identifier being in the interested ID list, confirming that the first frame CAN bus message meets the preset requirements; in response to the identifier not being in the interested ID list, confirming that the first frame CAN bus message does not meet the preset requirements.

4. The scheduling method for improving CAN bus message receiving performance according to claim 3 is characterized in that: In response to the identifier not being in the interested ID list, confirming that the first frame of the CAN bus message does not meet the preset requirements includes: in response to the identifier not being in the interested ID list, immediately discarding the first frame of the CAN bus message.

5. The scheduling method for improving CAN bus message receiving performance according to claim 1, characterized in that: In response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer, including: checking whether the circular queue buffer is full; if the circular queue buffer is not full, the first frame CAN bus message is stored in the circular queue buffer.

6. The scheduling method for improving CAN bus message receiving performance according to claim 5, characterized in that: In response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer, and also includes: in response to the circular queue buffer queue being full, triggering an overflow alarm prompt.

7. The scheduling method for improving CAN bus message receiving performance according to claim 5, characterized in that: In response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer, and also includes: in response to the circular queue buffer being full, the first frame CAN bus message overwrites the earliest unprocessed message in the circular queue buffer.

8. The scheduling method for improving CAN bus message receiving performance according to claim 5, characterized in that: In response to the first frame CAN bus message meeting the preset requirements, the first frame CAN bus message is stored in the circular queue buffer, and also includes: in response to the circular queue buffer being full, based on the comparison between the overwrite probability and the preset threshold, determining whether to overwrite the earliest unprocessed message in the circular queue buffer with the first frame CAN bus message.

9. The scheduling method for improving CAN bus message receiving performance according to claim 8, characterized in that: Determining the rewrite probability includes: determining the ratio between the data content in the message data of the first frame CAN bus message and the total message data of the first frame CAN bus message to obtain a first ratio; determining the ratio between the total message data of the first frame CAN bus message and the capacity of the slots in the circular queue buffer to obtain a first capacity ratio; determining the capacity ratio of each slot in the current circular queue buffer as a capacity topology probability distribution representation within the capacity feature distribution space; calculating a joint probability determination coefficient based on the first ratio, the first capacity ratio and the mean of the capacity topology probability distribution; performing a logarithmic transformation on the first ratio and the first capacity ratio to determine a logarithmically corrected comprehensive probability; and determining the rewrite probability by reconstructing the distribution solution space based on the capacity topology probability distribution, the joint probability determination coefficient and the logarithmically corrected comprehensive probability.

Citation Information

Cited By

  • Electric energy meter, charging pile and metering box monitoring method thereof and readable storage medium

    CN121940242A