Message buffer area distribution method and device, storage medium and electronic equipment

By filtering and classifying long messages and allocating them to the appropriate buffers, the problem of frame loss in the CAN FD protocol is solved, improving the stability and efficiency of bus communication.

CN121037331APending Publication Date: 2025-11-28BEIJING JINGWEI HIRAIN TECH CO INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511340196.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-18
Publication Date
2025-11-28

AI Technical Summary

Technical Problem

The existing message buffer allocation method causes CAN FD protocol messages to be allocated to unreceiveable buffers, resulting in message frame loss and affecting the stability of bus communication.

Method used

By filtering out long messages whose data segment length exceeds a preset length threshold, and allocating them to the corresponding buffers where the data segment length exceeds the threshold, and by classifying and grouping long messages based on the message frame format, it is ensured that long messages are allocated to buffers that can be received normally.

Benefits of technology

This effectively avoids message frame loss, improves the stability of bus communication and message processing efficiency, and ensures the normal transmission of CAN FD protocol messages.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121037331A_ABST
    Figure CN121037331A_ABST
Patent Text Reader

Abstract

The invention provides a message buffer area distribution method and device, a storage medium and electronic equipment, and belongs to the technical field of buses, and the method comprises the steps: determining each sending message and each receiving message in a target channel; determining each first long message in the sending message, and determining each second long message in the receiving message; determining each first buffer area and each second buffer area in each hardware buffer area of the target channel; the data segment length of the first buffer area and the second buffer area is greater than a preset length threshold; distributing each first long message to each first buffer area based on the message frame format of each first long message; and distributing each second long message to each second buffer area based on the message frame format of each second long message. By applying the method provided by the invention, the long messages to be distributed can be screened out, and the long messages are distributed to the buffer areas of which the data segment lengths meet the requirements according to the message attributes, so that the message frame loss can be avoided, and the communication stability is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of bus, in particular to a message buffer allocation method and device, a storage medium and an electronic device. BACKGROUND

[0002] With the development of vehicle technology, the Controller Area Network (CAN) bus has gradually become one of the main communication methods between vehicle Electronic Control Units (ECU).

[0003] In the process of message transmission and reception based on the CAN bus, the corresponding hardware cache needs to be allocated for the transmitted and received messages. At present, the allocation of hardware cache resources for transmitted and received messages is usually based on the number of messages to allocate the transmitted and received messages to each message buffer.

[0004] With the change of data transmission demand, the CAN with Flexible Data-Rate (CANFD) protocol has gradually become one of the commonly used protocols in the vehicle CAN bus. The data segment length of the CAN FD protocol message may exceed the data segment length of some buffer. Based on the existing buffer allocation method, the bus message based on the CAN FD protocol may be allocated to the message buffer whose data segment length is lower than the actual data segment length of the message, resulting in that the message cannot be received, the message frame loss phenomenon occurs, and adverse effects on bus communication. SUMMARY

[0005] Therefore, the embodiments of the present application provide a message buffer allocation method to solve the problem that the existing message buffer allocation method may cause the CAN FD protocol message to be allocated to the message buffer that cannot receive the message, resulting in message frame loss and affecting normal communication of the bus.

[0006] The embodiments of the present application also provide a message buffer allocation device to ensure the implementation and application of the above method in practice.

[0007] To achieve the above object, the embodiments of the present application provide the following technical solutions:

[0008] A message buffer allocation method comprises the following steps:

[0009] When it is necessary to allocate a buffer for a message of a target channel, each transmitted message and each received message in the target channel is determined.

[0010] determining each first long packet in each of the sending packets and each second long packet in each of the receiving packets; the first long packet and the second long packet are respectively a packet whose data segment length is greater than a preset length threshold;

[0011] determining each first buffer and each second buffer in each hardware buffer corresponding to the target channel; the data segment length of the first buffer and the data segment length of the second buffer are respectively greater than the preset length threshold;

[0012] determining a packet frame format of each first long packet and a packet frame format of each second long packet;

[0013] allocating each first long packet to each first buffer based on the packet frame format of each first long packet;

[0014] allocating each second long packet to each second buffer based on the packet frame format of each second long packet.

[0015] The above method can further include:

[0016] counting the number of packets of each first long packet;

[0017] determining whether the number of packets meets a preset allocation condition;

[0018] if the number of packets meets the allocation condition, determining the number of buffers according to the number of packets;

[0019] determining each candidate buffer in each hardware buffer; the candidate buffer is a sending packet buffer whose data segment length is greater than the preset length threshold;

[0020] selecting each buffer matching the number of buffers from each candidate buffer, and taking the selected buffer as the first buffer.

[0021] The above method can further include:

[0022] if the number of packets does not meet the allocation condition, issuing an error message and stopping the buffer allocation process of each first long packet.

[0023] The above method can further include:

[0024] According to a message frame format of each of the first long messages, the first long messages are classified to obtain each first long message corresponding to each preset frame format;

[0025] A bit mask corresponding to each of the preset frame formats is determined.

[0026] For each of the preset frame formats, each first long message corresponding to the preset frame format is grouped based on a bit mask corresponding to the preset frame format, a message ID of each first long message corresponding to the preset frame format, and a preset dichotomy, to obtain each message group corresponding to the preset frame format, each of the message groups including at least one first long message; a total number of the message groups corresponding to all of the preset frame formats is equal to a total number of the first buffers.

[0027] A one-to-one correspondence between the message groups corresponding to all of the preset frame formats and the first buffers is determined.

[0028] For each of the first buffers, a first long message in the message group corresponding to the first buffer is assigned to the first buffer.

[0029] The method described above, optionally, further includes:

[0030] Each first short message is determined in each of the sending messages, and each second short message is determined in each of the receiving messages; the first short message and the second short message are respectively a message whose message data segment length is not greater than the preset length threshold.

[0031] Each third buffer and each fourth buffer are determined in each hardware buffer corresponding to the target channel; each of the first buffers, each of the second buffers, each of the third buffers, and each of the fourth buffers are mutually non-overlapping.

[0032] A message frame format of each of the first short messages and a message frame format of each of the second short messages are determined.

[0033] Each of the first short messages is assigned to each of the third buffers based on the message frame format of each of the first short messages.

[0034] Each of the second short messages is assigned to each of the fourth buffers based on the message frame format of each of the second short messages.

[0035] The method described above, optionally, further includes:

[0036] After the buffer allocation process of each channel message is completed, each of the channel messages is sorted in descending order of the length of the message data segment, wherein each of the channel messages comprises each of the first long messages, each of the second long messages, each of the first short messages, and each of the second short messages.

[0037] Based on the arrangement order of each of the channel messages, a message list corresponding to each of the channel messages is generated.

[0038] The method described above, optionally, further comprises:

[0039] determining the cache location corresponding to each of the channel messages;

[0040] Based on the message list and the cache location corresponding to each of the channel messages, a mapping table corresponding to each of the channel messages is generated, wherein the mapping table is used to record the mapping relationship between the message ID of each of the channel messages and the hardware cache location.

[0041] An apparatus for allocating a message buffer, comprising:

[0042] a first determining unit configured to determine each of the sending messages and each of the receiving messages in a target channel when message buffer allocation for the target channel is required;

[0043] a second determining unit configured to determine each of the first long messages in each of the sending messages and each of the second long messages in each of the receiving messages, wherein the first long message and the second long message are respectively a message with a message data segment length greater than a preset length threshold;

[0044] a third determining unit configured to determine each of the first buffer and each of the second buffer in each of the hardware buffers corresponding to the target channel, wherein the data segment length of the first buffer and the data segment length of the second buffer are respectively greater than the preset length threshold;

[0045] a fourth determining unit configured to determine the message frame format of each of the first long messages and the message frame format of each of the second long messages;

[0046] a first allocating unit configured to allocate each of the first long messages to each of the first buffer based on the message frame format of each of the first long messages;

[0047] a second allocating unit configured to allocate each of the second long messages to each of the second buffer based on the message frame format of each of the second long messages.

[0048] A storage medium includes stored instructions, wherein the instructions, when executed, control a device in which the storage medium resides to perform the method for allocating a message buffer zone as described above.

[0049] An electronic device includes a memory, and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform the method for allocating a message buffer zone as described above.

[0050] The method for allocating a message buffer zone provided by the embodiment of the present application comprises: when it is necessary to allocate a message buffer zone to a target channel, determining each sending message and each receiving message in the target channel; determining each first long message in each sending message and each second long message in each receiving message; the first long message and the second long message are respectively a message whose data segment length is greater than a preset length threshold; determining each first buffer zone and each second buffer zone in each hardware buffer zone corresponding to the target channel; the data segment length of the first buffer zone and the data segment length of the second buffer zone are respectively greater than the preset length threshold; determining the message frame format of each first long message and the message frame format of each second long message; allocating each first long message to each first buffer zone based on the message frame format of each first long message; and allocating each second long message to each second buffer zone based on the message frame format of each second long message. When the message buffer zone is allocated to the message in each channel by using the method provided by the embodiment of the present application, the long message whose data segment length is greater than a certain length can be screened out, and the long message is allocated to the message buffer zone whose data segment length also exceeds the corresponding length, so that the long message is allocated to the message buffer zone capable of normally receiving the message, which is beneficial to guarantee the normal transmission of the bus message based on the CAN FD protocol, avoid the message frame loss phenomenon, and improve the stability of the bus communication. In addition, in the buffer zone allocation process, the buffer zone can be allocated to each type of message based on the message transmission direction (sending or receiving), the message data segment length (whether greater than the threshold), and the message frame format, so that the messages allocated to the same buffer zone have the same attribute, which is beneficial to improve the message processing efficiency. BRIEF DESCRIPTION OF DRAWINGS

[0051] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor based on the provided drawings.

[0052] Figure 1 The method flowchart of the method for allocating a message buffer zone provided by the embodiment of the present application;

[0053] Figure 2 A schematic diagram of a message processing process of each channel of a CAN bus provided by an embodiment of the present application is shown in FIG. 1.

[0054] Figure 3 A schematic diagram of a message buffer allocation process provided by an embodiment of the present application is shown in FIG. 2.

[0055] Figure 4 A structural schematic diagram of a message buffer allocation device provided by an embodiment of the present application is shown in FIG. 3.

[0056] Figure 5 A structural schematic diagram of an electronic device provided by an embodiment of the present application is shown in FIG. 4. DETAILED DESCRIPTION

[0057] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.

[0058] In the present application, the term “comprising” or “including” or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such a process, method, article or device. Without more limitations, the element defined by the phrase “including a…” does not exclude the presence of another identical element in the process, method, article or device including the element.

[0059] The embodiments of the present application provide a message buffer allocation method, which can be applied to a vehicle CAN bus system, and the execution subject of the method can be a controller of a vehicle bus node. A flowchart of the method is shown in FIG. 1, which includes the following steps. Figure 1

[0060] S101: When message buffer allocation for a target channel is needed, determine each sending message and each receiving message in the target channel.

[0061] ​In the method provided by the embodiment of the application, the controller can cyclically traverse each CAN channel, and distribute the messages of each CAN channel to the corresponding message buffer. When the controller accesses the current channel, the current channel can be taken as a target channel, and the message buffer distribution is performed on the messages in the target channel. The controller can traverse all the messages in the target channel, classify all the messages according to the transmission direction of the messages, and divide the messages into sending messages or receiving messages. The sending messages refer to the messages to be sent by the current node, and the receiving messages refer to the messages received by the current node. Thus, each sending message and each receiving message in the target channel are obtained.

[0062] In S102, each first long message is determined in each sending message, and each second long message is determined in each receiving message. The first long message and the second long message are respectively a message whose data segment length is greater than a preset length threshold.

[0063] In the method provided by the embodiment of the application, according to the data segment length (Data Length Code, DLC) of the message, each sending message and each receiving message are classified, and the message whose data segment length is greater than a preset length threshold is screened out. Specifically, the preset length threshold can be set according to actual needs, and is used to divide long messages and short messages. For example, the limit length (8 bytes) of the traditional CAN message is taken as the preset length threshold, the message whose data segment length is greater than 8 bytes is called a long message, and the message whose data segment length is not greater than 8 bytes is called a short message. The data segment length of each sending message is compared with the preset length threshold, and the sending message whose data segment length is greater than the preset length threshold is taken as a first long message. The data segment length of each receiving message is compared with the preset length threshold, and the receiving message whose data segment length is greater than the preset length threshold is taken as a second long message.

[0064] It should be noted that in the actual communication process, there can be no long message in the current target channel, that is, the message whose data segment length is greater than the preset length threshold. At this time, the message buffer distribution is not involved, and other ways can be used to perform the message buffer distribution. Or only one type of message has a long message in the sending message or the receiving message, and only the processing of the long message of this type is involved in the long message buffer distribution.

[0065] In S103, each first buffer and each second buffer are determined in each hardware buffer corresponding to the target channel. The data segment length of the first buffer and the data segment length of the second buffer are respectively greater than the preset length threshold.

[0066] In the method provided by the embodiment of the application, each hardware buffer area allocated to the target channel, that is, the buffer area used to store the message in the target channel, exists in the hardware cache. The controller can calculate the number of buffer areas required to be allocated to the first long message according to the message quantity of each first long message, and then select the required buffer areas from each hardware buffer area based on the number of buffer areas and the attribute of each hardware buffer area, and take the selected buffer areas as the first buffer areas. Similarly, the number of buffer areas required to be allocated to the second long message can be calculated according to the message quantity of each second long message, and then the required buffer areas are selected from each hardware buffer area based on the number of buffer areas and the attribute of each hardware buffer area, and the selected buffer areas are taken as the second buffer areas. The data segment length of the first buffer area and the data segment length of the second buffer area are both greater than the preset length threshold, that is, the first buffer area and the second buffer area can both store the message whose message data segment length is greater than the preset length threshold.

[0067] S104: determine the message frame format of each first long message and the message frame format of each second long message.

[0068] In the method provided by the embodiment of the application, the message frame format of each first long message can be obtained from the message attribute of each first long message, and the message frame format of each second long message can be obtained from the message attribute of each second long message. The message frame format of the first long message / second long message refers to the frame format of the message, that is, the frame format based on the communication protocol, for example, the message frame format can be a standard frame format, an extended frame format or a CAN FD frame format.

[0069] S105: allocate each first long message to each first buffer area based on the message frame format of each first long message.

[0070] In the method provided by the embodiment of the application, each first long message can be allocated to each first buffer area based on the message frame format of each first long message. Specifically, each first long message can be classified based on the message frame format of each first long message, and first long messages of different formats are allocated to different buffer areas.

[0071] S106: allocate each second long message to each second buffer area based on the message frame format of each second long message.

[0072] In the method provided by the embodiment of the application, each second long message can be allocated to each second buffer area based on the message frame format of each second long message. Specifically, each second long message can be classified based on the message frame format of each second long message, and second long messages of different formats are allocated to different buffer areas.

[0073] Based on the method provided by the embodiment of the application, when it is necessary to allocate a buffer to a message of a target channel, each sending message and each receiving message in the target channel are determined; each first long message is determined in each sending message, and each second long message is determined in each receiving message; the first long message and the second long message are respectively a message whose data segment length is greater than a preset length threshold; each first buffer and each second buffer are determined in each hardware buffer corresponding to the target channel; the data segment length of the first buffer and the data segment length of the second buffer are respectively greater than the preset length threshold; the message frame format of each first long message and the message frame format of each second long message are determined; each first long message is allocated to each first buffer based on the message frame format of each first long message; and each second long message is allocated to each second buffer based on the message frame format of each second long message. When the message in each channel is allocated to the buffer, the long message whose data segment length is greater than a certain length can be screened out, and the long message is allocated to the message buffer whose data segment length also exceeds the corresponding length, so that the long message is allocated to the message buffer capable of normally receiving the message, which is beneficial to guarantee the normal transmission of the bus message based on the CAN FD protocol, avoid the message frame loss phenomenon, and improve the stability of the bus communication. In addition, in the buffer allocation process, the buffer allocation can be performed on various messages based on the message transmission direction (sending or receiving), the message data segment length (whether greater than the threshold), and the message frame format, so that the messages allocated to the same buffer have the same attribute, which is beneficial to improve the message processing efficiency.

[0074] In the method shown in the figure, the process of determining each first buffer in each hardware buffer corresponding to the target channel in step S103 includes: Figure 1 In the method shown in the figure, the process of determining each first buffer in each hardware buffer corresponding to the target channel in step S103 includes:

[0075] The number of messages of each first long message is counted.

[0076] In the method provided by the embodiment of the application, the number of messages of each first long message can be counted to obtain the number of messages of each first long message.

[0077] It is judged whether the number of messages meets a preset allocation condition.

[0078] In the method provided by the embodiment of the application, the constraint condition, i.e., the allocation condition, when the long message buffer is allocated can be set according to the actual demand in advance, for example, the number of long messages allocated to the buffer needs to be limited, the number of messages threshold can be set, and the number of messages not exceeding the number of messages threshold is taken as the allocation condition. Specifically, the number of messages threshold can be set based on the number of buffers for storing the corresponding type of long message in the hardware cache.

[0079] In the method provided by the embodiment of the present application, the controller can determine whether the current message quantity meets the preset allocation condition based on the content defined in the allocation condition. For example, if the allocation condition is that the message quantity does not exceed the message quantity threshold, then the current message quantity is compared with the preset message quantity threshold. If the current message quantity exceeds the preset message quantity threshold, it is considered that the current message quantity does not meet the allocation condition. If the current message quantity does not exceed the preset message quantity threshold, it is considered that the current message quantity meets the allocation condition.

[0080] If the message quantity meets the allocation condition, the number of buffer zones is determined according to the message quantity.

[0081] In the method provided by the embodiment of the present application, if the current message quantity meets the allocation condition, the number of buffer zones required is determined based on the message quantity. For example, if each buffer zone is allocated with at most one long message during each allocation, then the message quantity can be used as the number of buffer zones.

[0082] In each of the hardware buffer zones, each candidate buffer zone is determined. The candidate buffer zone is a sending message buffer zone with a data segment length greater than the preset length threshold.

[0083] In the method provided by the embodiment of the present application, each hardware buffer zone is divided into a sending message buffer zone and a receiving message buffer zone, and each sending message buffer zone and each receiving message buffer zone respectively contains a short message buffer zone and a long message buffer zone. The short message buffer zone is a buffer zone for storing a short message, and the long message buffer zone is a buffer zone for storing a long message. It can be understood that the data segment length of the long message buffer zone needs to be greater than the preset length threshold. The first long message is a sending message and needs to be allocated to the sending message buffer zone. Each sending message buffer zone can be first screened out in each hardware buffer zone, and then the long message buffer zone is screened out according to the buffer zone attribute of each sending message buffer zone. The screened buffer zone is used as the candidate buffer zone, that is, the sending message buffer zone with a data segment length greater than the preset length threshold.

[0084] In each of the candidate buffer zones, each buffer zone matched with the number of buffer zones is selected, and the selected buffer zone is used as the first buffer zone.

[0085] In the method provided by the embodiment of the present application, a corresponding number of buffer zones can be screened out in each candidate buffer zone according to the current required number of buffer zones, and the selected buffer zone is used as the first buffer zone.

[0086] It should be noted that the way of determining each second buffer zone mentioned in step S103 is the same as the way of determining each first buffer zone, and reference can be made to the description in the above embodiment, which will not be repeated here.

[0087] The method provided in the embodiment of the present application further comprises the following steps:

[0088] If the number of the messages does not meet the allocation condition, an error message is sent, and the buffer allocation process for each first long message is stopped.

[0089] In the method provided in the embodiment of the present application, if the number of the current messages does not meet the allocation condition, the controller can report an error, send an error message, for example, remind the user to reduce the number of long messages, and stop the buffer allocation process for each first long message.

[0090] Based on the method provided in the embodiment of the present application, the limitation condition for long message buffer allocation can be set in advance according to actual needs, and in the buffer allocation process, the error condition can be identified in real time and an error can be reported, which is beneficial to meet the allocation requirements in different hardware scenarios.

[0091] In the method shown in the above embodiment, the process of allocating each first long message to each first buffer based on the message frame format of each first long message in step S105 comprises the following steps: Figure 1

[0092] According to the message frame format of each first long message, the first long messages are classified, and each first long message corresponding to each preset frame format is obtained.

[0093] In the method provided in the embodiment of the present application, each first long message is classified based on the message frame format, and the first long messages with the same message frame format are classified into the same type of message, so that each first long message corresponding to each frame format is obtained. The preset frame format is an object set according to the actual frame format category, for example, the standard frame format and the extended frame format are involved in the bus system, and the preset frame format is configured as the standard frame format and the extended frame format. When classifying each first long message, the messages with the standard frame format are classified into one category, and the messages in this category are taken as each first long message corresponding to the standard frame format. The messages with the extended frame format are classified into one category, and the messages in this category are taken as each first long message corresponding to the extended frame format.

[0094] The bit mask corresponding to each preset frame format is determined.

[0095] ​In the method provided by the embodiment of the present application, a bit mask can be set in advance for each type of preset frame format, and used for bit-by-bit operation on the message ID, so as to realize message screening. The bit mask can be set according to the message ID length of the message of the corresponding frame format, for example, if the frame format is a standard frame format, the corresponding bit mask can be set as 0x400, and if the frame format is an extended frame format, the corresponding bit mask can be set as 0x10000000. In the message distribution process, the controller can obtain the bit mask corresponding to each preset frame format from the preconfigured information.

[0096] For each of the preset frame formats, each first long message corresponding to the preset frame format is grouped based on the bit mask corresponding to the preset frame format, the message ID of each first long message corresponding to the preset frame format, and a preset binary method, to obtain each message group corresponding to the preset frame format, and each of the message groups includes at least one first long message; and the total number of the message groups corresponding to all the preset frame formats is equal to the total number of the buffer areas of each first buffer area.

[0097] In the method provided by the embodiment of the present application, for each first long message corresponding to each preset frame format, the bit mask corresponding to the preset frame format is used to perform bit-by-bit operation on the message ID of each first long message, and each first long message is sequentially grouped according to the binary method based on the operation result of each bit, messages with the same operation result are grouped in the same group, and finally a plurality of message groups with the same number of groups as the total number of the buffer areas of the first buffer area are obtained, and these message groups are used as each message group corresponding to the preset frame format. Specifically, the bit mask is operated with the message ID of each first long message respectively to identify whether the first bit of each message ID is 1 or 0, messages with the first bit of the message ID being 1 are grouped into one group, and messages with the first bit of the message ID being 0 are grouped into one group, then the bit mask is right-shifted by one bit, and the adjusted bit mask is operated with each message ID respectively to identify whether the second bit of each message ID is 1 or 0, and further in each current group, messages with the second bit of the message ID being 1 are grouped into one group, and messages with the second bit of the message ID being 0 are grouped into one group, that is, four groups are obtained at this time, one group is for messages with the first bit and the second bit of the message ID both being 0, one group is for messages with the first bit of the message ID being 0 and the second bit being 1, one group is for messages with the first bit of the message ID being 1 and the second bit being 0, and one group is for messages with the first bit and the second bit of the message ID both being 1. Similarly, the current bit mask can be further right-shifted by one bit, and the operation of the bit mask with each message ID is continued, and based on the operation result, each current group is further divided into two groups, which is the binary method. In the grouping process, the number of groups to be grouped is determined according to the total number of the message groups corresponding to all the preset frame formats being equal to the number of the buffer areas of the first buffer area.

[0098] determining a one-to-one correspondence between all the preset frame format corresponding message packets and each first buffer;

[0099] In the method provided by the embodiment of the application, a one-to-one correspondence between all the message packets and each first buffer can be established based on a pre-set allocation manner, that is, one message packet corresponds to one first buffer, and one first buffer also corresponds to only one message packet. For example, each first buffer corresponding to a message packet can be allocated randomly.

[0100] For each first buffer, a first long message in the message packet corresponding to the first buffer is allocated to the first buffer.

[0101] In the method provided by the embodiment of the application, the first long message in each message packet is allocated to the first buffer corresponding to the message packet. A corresponding mask can be set based on the message ID in each message packet, and the mask is used to filter the message entering the buffer.

[0102] It should be noted that in the embodiment of the application, the manner of allocating each second long message to each second buffer in step S106 is the same as the manner of allocating each first long message to each first buffer in step S105, and the foregoing description in the embodiment can be referred to, and thus will not be described herein.

[0103] Based on the method provided by the embodiment of the application, the message packets of different frame formats can be allocated to different buffers, and further allocation is performed through the message ID when grouping, the mask corresponding to each message packet is generated to filter the message entering the buffer, and the message processing efficiency is improved.

[0104] On the basis of the method shown in Figure 1 The method provided by the embodiment of the application further comprises the following steps:

[0105] In each of the sending messages, a first short message is determined, and in each of the receiving messages, a second short message is determined; the first short message and the second short message are respectively a message whose message data segment length is not greater than the preset length threshold value;

[0106] In the method provided by the embodiment of the present application, when each sending packet and each receiving packet are classified according to the data segment length of the packet, the packets whose data segment length does not exceed the preset length threshold can be screened out, and these packets are short packets. Specifically, the data segment length of each sending packet can be compared with the preset length threshold, and the sending packet whose data segment length does not exceed the preset length threshold is taken as a first short packet. Similarly, the data segment length of each receiving packet can be compared with the preset length threshold, and the receiving packet whose data segment length does not exceed the preset length threshold is taken as a second short packet.

[0107] It should be noted that in the actual processing process, one classification of each sending packet and each receiving packet is performed by using the preset length threshold, and each first long packet, second long packet, first short packet and second short packet can be obtained at the same time. On the other hand, it should be noted that in the actual communication process, there can be no short packet in the current target channel, and in this case, the buffer allocation of the short packet is not involved. Or only one type of packet in the sending packet or receiving packet has a short packet, and in the buffer allocation of the short packet, only the processing of this type of short packet is involved.

[0108] In each hardware buffer corresponding to the target channel, each third buffer and each fourth buffer are determined; each first buffer, each second buffer, each third buffer and each fourth buffer are mutually exclusive;

[0109] In the method provided by the embodiment of the present application, the controller can calculate the number of buffers to be allocated to the first short packet according to the number of first short packets, and then select a corresponding number of sending packet buffers as third buffers in each hardware buffer corresponding to the target channel. Similarly, the number of buffers to be allocated to the second short packet can be calculated according to the number of second short packets, and then a corresponding number of receiving packet buffers are selected as fourth buffers in each hardware buffer corresponding to the target channel. Specifically, in the embodiment of the present application, each receiving packet buffer and each sending packet buffer include long packet buffers and short packet buffers, a corresponding number of short packet buffers in each receiving packet buffer can be selected as third buffers, and a corresponding number of short packet buffers in each sending packet buffer can be selected as fourth buffers. It can be understood that the first buffer is a long packet buffer in each sending packet buffer, the second buffer is a long packet buffer in each receiving packet buffer, the third buffer is a short packet buffer in each sending packet buffer, and the fourth buffer is a short packet buffer in each receiving packet buffer, so each first buffer, second buffer, third buffer and fourth buffer are mutually exclusive.

[0110] determining the message frame format of each of the first short messages and the message frame format of each of the second short messages;

[0111] In the method provided by the embodiment of the present application, the message frame format of each of the first short messages can be obtained from the message attribute of each of the first short messages, and the message frame format of each of the second short messages can be obtained from the message attribute of each of the second short messages.

[0112] allocating each of the first short messages to each of the third buffer areas based on the message frame format of each of the first short messages;

[0113] In the method provided by the embodiment of the present application, each of the first short messages can be allocated to each of the third buffer areas based on the message frame format of each of the first short messages. Specifically, each of the first short messages can be classified according to the message frame format of each of the first short messages to obtain each of the first short messages corresponding to each preset frame format. For each preset frame format, each of the first short messages corresponding to the preset frame format can be grouped based on the bit mask corresponding to the preset frame format, the message ID of each of the first short messages corresponding to the preset frame format, and the preset dichotomy to obtain each short message group corresponding to the preset frame format. Each short message group includes at least one short message, the total number of the short message groups corresponding to all preset frame formats is equal to the total number of the third buffer areas, and a one-to-one correspondence between all the short message groups and the third buffer areas is determined. Then, the first short message in each short message group is allocated to the third buffer area corresponding to the short message group.

[0114] allocating each of the second short messages to each of the fourth buffer areas based on the message frame format of each of the second short messages.

[0115] In the method provided by the embodiment of the present application, each of the second short messages can be allocated to each of the fourth buffer areas based on the message frame format of each of the second short messages. Specifically, each of the second short messages can be classified according to the message frame format of each of the second short messages to obtain each of the second short messages corresponding to each preset frame format. Then, each of the second short messages can be grouped based on the bit mask corresponding to each preset frame format, and a one-to-one correspondence between the final short message group and the fourth buffer area is determined to realize message allocation. The specific processing manner is the same as that of allocating each of the first short messages to each of the third buffer areas, and the description of the previous step can be referred to, which is not repeated here.

[0116] Based on the method provided in the embodiment of the present application, each message can be grouped based on the transmission direction (sending or receiving) of the message, the message length (such as long message or short message) of the message, and the data frame format (such as standard frame or extended frame) of the message, messages with the same attribute are grouped into a group, and the messages in the uniform group are distributed to a uniform buffer, which is beneficial to improve the message processing efficiency. Secondly, in the message distribution process, the message ID can be grouped by using the dichotomy, so that the message ID in the same group has a certain similarity, which is beneficial to filter the messages distributed to the same buffer, and is beneficial to improve the message processing efficiency.

[0117] Based on the method provided in the above embodiment, the method provided in the embodiment of the present application further comprises:

[0118] After completing the buffer distribution process of each channel message, the channel messages are sorted in the order of the message data segment length from large to small; each channel message comprises each first long message, each second long message, each first short message, and each second short message.

[0119] In the method provided in the embodiment of the present application, each first long message, each second long message, each first short message, and each second short message are collectively referred to as a channel message. After each channel message is distributed to a corresponding buffer, the channel messages can be sorted in the order of the message data segment length from large to small, that is, the channel message with a longer message data segment length is arranged in the front of the list.

[0120] Based on the arrangement order of each channel message, a message list corresponding to each channel message is generated.

[0121] In the method provided in the embodiment of the present application, each channel message is stored in a list form according to the arrangement order of each channel message, that is, each channel message is stored in a corresponding list, and the channel messages in the list are arranged in the order of the message data segment length from large to small. The message list in which each channel message is stored is used as the message list corresponding to the target channel.

[0122] Based on the method provided in the above embodiment, the method provided in the embodiment of the present application further comprises:

[0123] The cache location corresponding to each channel message is determined.

[0124] In the method provided in the embodiment of the present application, the cache location of each channel message in the hardware cache is determined according to the buffer to which each channel message is distributed. Specifically, the correspondence between the channel message and the cache location can be represented by the message ID and the buffer identifier.

[0125] generate a mapping table corresponding to each of the channel packets based on the packet list and the cache location corresponding to each of the channel packets; the mapping table is used to record the mapping relationship between the packet ID of each of the channel packets and the hardware cache location.

[0126] In the method provided by the embodiment of the application, the mapping table of the packet ID to the hardware cache location of each channel packet is generated according to the order of the channel packets in the packet list, that is, the mapping table records the hardware cache location corresponding to each channel packet (indicated by the packet ID) according to the order of each channel packet in the packet list.

[0127] Based on the method provided by the embodiment of the application, after the buffer allocation of the packet is completed, each channel packet can be stored in the corresponding list, and the corresponding mapping table is generated. In the process of processing the packet, the packet ID can be mapped to the specific location of the packet in the hardware cache through the mapping table, which is beneficial to improving the packet processing efficiency.

[0128] In order to better illustrate the method provided by the embodiment of the application, on the basis of the method provided in each of the foregoing embodiments, in combination with the actual application scenario, the embodiment of the application provides another method for allocating a packet buffer area. The method provided by the embodiment of the application is applied to an S32K3XX series microcontroller. The controller has six CAN channels, each of which corresponds to 96, 64, 64, 32, 32, and 32 buffer areas, respectively. The buffer areas of each channel are divided into BLOCK data blocks. The channel with 96 buffer areas has three BLOCK data blocks, each of which has 32 buffer areas. The channel with 64 buffer areas has two BLOCK data blocks, and the channel with 32 buffer areas has one BLOCK data block. Part of the buffer areas in each buffer area are configured as long-packet buffer areas. For example, the first block of the channel with 96 buffer areas contains seven long-packet buffer areas, six of which are used to store received packets. In the embodiment of the application, a packet with a data segment length DLC less than 8 bytes is referred to as a short packet, and a packet with a data segment length DLC greater than 8 bytes is referred to as a long packet. The data segment length DLC of the long packet is limited to 64 bytes.

[0129] Overall, the method provided by the embodiment of the application allocates each packet to the CAN hardware cache according to different attributes (packet frame format, packet data segment length, and packet transmission direction) of the CAN packet, and generates a mapping table of the packet ID to the hardware cache location for each channel. As shown in FIG. 6, the packet buffer area allocation process provided by the embodiment of the application mainly includes the following steps. Figure 2

[0130] S201: initialization and variable definition;

[0131] ​The method provided by the embodiment of the application can initialize various parameters and define various variables.

[0132] S202: traversing messages in each CAN channel;

[0133] In the method provided by the embodiment of the application, messages in all channels are traversed in a loop, and in each loop cycle, various containers and flags can be emptied and reset for each channel to ensure that message processing of each channel is independent. When traversing the messages in the channel, the format and type of each message are checked, and if a CAN FD format message exists in the message of the current channel, the channel can be marked as a CAN FD mode to ensure that the message format of each channel is consistent in subsequent processing.

[0134] S203: message classification;

[0135] In the method provided by the embodiment of the application, when processing the messages in each channel, the messages are classified according to different attributes (transmission or reception of messages, standard frame or extended frame, long message or short message) of the messages, each type of message is stored in a corresponding container, and the messages are classified and stored in different containers (Vectors). The type of the container can be divided into received standard frame short message, received extended frame short message, received standard frame long message, received extended frame long message, transmitted standard frame short message, transmitted extended frame short message, transmitted standard frame long message and transmitted extended frame long message, and each container is used to store messages of a corresponding type, for example, a container of the received standard frame short message type is used to store short messages of the standard frame format in the received message, and the messages stored in the container are the same. When processing the messages of the current channel, the messages are classified and stored in the container corresponding to the current channel.

[0136] S204: buffer allocation;

[0137] In the method provided by the embodiment of the application, each message can be allocated to the buffer area corresponding to the channel based on the data segment length of the message in each channel, the transmission direction (transmission or reception) of the message and the frame format of the message. When allocating a buffer area to the message in a certain channel, the received message and the transmitted message can be sorted in ascending order, and the sorting basis is the ID of the message, so as to facilitate subsequent allocation of the message and ensure the order of the message ID in the buffer area. According to the number of received messages and the number of transmitted messages, the number of buffer areas allocated to the received messages and the number of buffer areas allocated to the transmitted messages are calculated, and then each transmitted message and each received message is allocated to a corresponding buffer area. The process of allocating a buffer area to the transmitted message or the received message can be as shown in Figure 3 , and specifically includes:

[0138] S301: setting a mask according to a frame format;

[0139] In the method provided by the embodiment of the present application, different bit mask initial values are set for different message frame formats. For example, the bit mask corresponding to the standard frame format is set as 0x400, and the bit mask corresponding to the extended frame format is set as 0x10000000. For each message to be allocated, the messages are classified according to the frame format of the messages. The messages with the standard frame format are taken as a group of messages, and the bit mask corresponding to the standard frame format is taken as the bit mask corresponding to the group of messages. The messages with the extended frame format are taken as a group of messages, and the bit mask corresponding to the extended frame format is taken as the bit mask corresponding to the group of messages.

[0140] S302: judging whether there is a long message;

[0141] In the method provided by the embodiment of the present application, for each group of messages with the same frame format, it is judged whether there is a long message in the messages. If there is a long message, step S303 is entered to allocate a buffer for all the long messages in the group of messages. If there is no long message, it is indicated that all the messages in the group of messages are short messages, and step S307 is entered to allocate a buffer for all the short messages.

[0142] S303: long message processing;

[0143] In the method provided by the embodiment of the present application, if there is a long message, all the messages are traversed to screen out the long messages for processing.

[0144] S304: long message buffer allocation;

[0145] In the method provided by the embodiment of the present application, the number of allocated long messages does not exceed the number of reserved long message buffers, that is, at most one long message is allocated in each long message buffer, so the long message and the required long message buffer are one-to-one corresponding. In the embodiment of the present application, the long messages can be traversed, the message ID is operated bit by bit according to the bit mask corresponding to the message, and each long message is grouped according to the operation result of each bit, until the number of groups is equal to the number of long message buffers to be allocated. For example, there are 6 long messages, and the corresponding long message buffers are 6, assuming that these long messages are all standard frames, and the message IDs are 0x400 (binary: 10000000000), 0x450, 0x500, 0x550, 0x600 and 0x650. In order to express simply, the message ID is expressed in hexadecimal number here, and in actual processing, the message ID is a binary number, that is, each bit of the message ID is 0 or 1. Through the operation of the bit mask, it can be judged whether the first bit of the message ID is 0 or 1, and accordingly the messages are divided into two parts, that is, one part is the message whose first bit of the message ID is 0, and the other part is the message whose first bit of the message ID is 2. Then the messages in each part are further grouped, and specifically, the bit mask is right shifted by one bit, and the adjusted bit mask is operated with each message ID to judge whether the second bit of the message ID is 0 or 1, and accordingly each part of the message is divided into two parts, until the last bit of the message ID is judged, and this method is called binary method. Finally, the 6 ID messages are divided into 6 parts, a mask is generated based on the ID of each part of the message, which is used to filter the message, and when each long message buffer is configured to allocate only one message, the generated mask for filtering the message is all 1, so as to select a specified message into the corresponding long message buffer.

[0146] S305: updating long message buffer information;

[0147] In the method provided by the embodiment of the present application, when all long message buffers are allocated and each long message buffer is allocated only one long message, the long message traversal is exited. Finally, the long message buffer information is updated.

[0148] S306: judging whether there is a short message;

[0149] In the method provided by the embodiment of the present application, for each group of messages with the same frame format, it can be judged whether there is a short message in each message, if there is a short message, the step S307 is entered to perform buffer allocation processing on the short message, and if there is no short message, the buffer allocation process of the frame format message is ended after the long message buffer processing is completed.

[0150] S307: short message processing;

[0151] If the short message exists in the group of messages, the short message is filtered out and enters step S308 to perform buffer allocation for the short message.

[0152] S308: Short message buffer allocation;

[0153] In the method provided by the embodiment of the application, the short messages are classified by using dichotomy through step-by-step adjustment of the bit mask. First, each short message is traversed, and the ID of the message is operated by using the bit mask corresponding to the message, and the message is grouped according to the operation result. The grouping principle is the same as that of the long message grouping, which will not be repeated here. Overall, all the short messages are circularly traversed, and through the mask operation, it is judged whether the first bit of the message ID is 1 or 0, and the messages with the same bit value are grouped. If the actual grouping number reaches the expected grouping number (i.e. the number of short message buffers to be allocated) after the current traversal process is completed, the circular traversal is exited. If the expected grouping number is not reached, the bit mask is right shifted by one bit, and the next round of circular traversal is continued, and the messages in the current group are continuously grouped. When the circular traversal is completed, the short messages have been grouped into multiple groups based on the high bit part of the ID. The high bit part of the ID of each group of messages is the same, the ID range of each group of messages is non-overlapping, and the ID range of the long message and the short message is also non-overlapping. These groups will be allocated to different hardware buffers, which is beneficial to improve the processing efficiency of the CAN bus message bit mask.

[0154] S309: Update short message buffer information;

[0155] In the method provided by the embodiment of the application, after the buffer allocation of the short message is completed, the short message buffer information can be updated.

[0156] S205: Error processing logic;

[0157] In the method provided by the embodiment of the application, some error logic processing is also contained in the buffer allocation process, for example, the number of allocated long messages is limited. When the number of long messages to be allocated exceeds the pre-set number threshold, error information can be immediately output and the allocation process is exited.

[0158] S206: Sorting and storage;

[0159] In the method provided by the embodiment of the application, after the messages of the current channel are allocated to the corresponding hardware cache, the messages can be sorted in descending order of the message data segment length, and the messages are stored in the message list corresponding to the current channel according to the arrangement order. After the messages of all channels are processed, the message list corresponding to each channel is obtained, and the message list stores the received messages and the sent messages of each channel.

[0160] S207: generate a mapping table of message ID to hardware cache location;

[0161] In the method provided by the embodiment of the application, by traversing the message list of each channel, a mapping table of message ID to hardware cache location can be generated. The mapping table can quickly map the message ID to the specific location of the message ID in the hardware cache during actual operation, which is beneficial to improving the processing efficiency of the system.

[0162] Based on the method provided by the embodiment of the application, by intelligently allocating cache resources based on the frame format and data segment length of the message, it can be ensured that each cache unit is reasonably utilized, effectively avoiding waste of cache resources and improving cache resource utilization. By preferentially allocating cache resources for long data frames (long messages) and preferentially sorting them in the cache group, large data volume messages can be transmitted faster and more stably, avoiding message delay or loss due to insufficient cache, improving the transmission efficiency of long data frames, and can be effectively applied to CAN FD format message processing. By grouping and sorting the messages and arranging the priority according to the message ID and DLC length, it can be ensured that high-priority messages are processed in time, thereby improving the real-time performance and response speed of the system. Through reasonable cache allocation and efficient message sorting, the problems of message loss and transmission delay caused by insufficient cache resources or improper sorting are effectively reduced, which is beneficial to improving the reliability of the communication system and ensuring accurate transmission of important data. The method provided by the embodiment of the application allows real-time adjustment of the mapping of message ID and cache location in actual use, further optimizes the cache usage efficiency, and enables the system to dynamically cope with cache requirements under different communication loads, improving the adaptability of the system. Based on the method provided by the embodiment of the application, an efficient and reliable CAN message buffer allocation scheme can be provided in a vehicle CAN communication system to improve the CAN message transmission performance in a complex communication environment.

[0163] With Figure 1 Corresponding to the message buffer allocation method shown in Figure 1 The structure diagram is shown in Figure 4 It includes:

[0164] The first determination unit 401 is configured to determine each sending message and each receiving message in the target channel when it is necessary to allocate a buffer to the messages of the target channel.

[0165] The second determining unit 402 is used to determine each first long message in each of the sent messages and to determine each second long message in each of the received messages; the first long message and the second long message are respectively messages whose message data segment length is greater than a preset length threshold.

[0166] The third determining unit 403 is used to determine each first buffer and each second buffer in each hardware buffer corresponding to the target channel; the data segment length of the first buffer and the data segment length of the second buffer are respectively greater than the preset length threshold.

[0167] The fourth determining unit 404 is used to determine the message frame format of each of the first long messages and the message frame format of each of the second long messages;

[0168] The first allocation unit 405 is used to allocate each of the first long messages to each of the first buffers based on the message frame format of each of the first long messages.

[0169] The second allocation unit 406 is used to allocate each of the second long messages to each of the second buffers based on the message frame format of each of the second long messages.

[0170] By applying the apparatus provided in this embodiment of the invention, when allocating buffers for messages in each channel, long messages with data segment lengths exceeding a certain length can be filtered out and allocated to message buffers whose data segment lengths also exceed the corresponding length. This ensures that long messages are allocated to message buffers capable of receiving them normally, which helps guarantee the normal transmission of bus messages based on the CAN FD protocol, avoids message frame loss, and improves the stability of bus communication. Furthermore, during buffer allocation, buffer allocation can be performed on various types of messages based on the message transmission direction (send or receive), message data segment length (whether it exceeds a threshold), and message frame format. This allows messages allocated to the same buffer to have the same attributes, which helps improve message processing efficiency.

[0171] exist Figure 4 Based on the device shown, the device provided in this embodiment of the invention can be further extended to include multiple units. The functions of each unit can be found in the descriptions of the various embodiments of the message buffer allocation method provided above, and will not be further illustrated here.

[0172] This invention also provides a storage medium, which includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to perform the message buffer allocation method described above.

[0173] This invention also provides an electronic device, the structural schematic of which is shown below. Figure 5As shown, specifically includes a memory 501, and one or more instructions 502, wherein one or more instructions 502 stored in the memory 501, and configured to be executed by one or more processors 503 said one or more instructions 502 to perform the following operations:

[0174] When the target channel packet needs to be buffered, determine the target channel of each sending packet and each receiving packet;

[0175] In each of the sending packet to determine each first long packet, and in each of the receiving packet to determine each second long packet; the first long packet and the second long packet are respectively the packet data segment length greater than the preset length threshold value of the packet;

[0176] In the target channel corresponding to each hardware buffer, determine each first buffer and each second buffer; the data segment length of the first buffer and the data segment length of the second buffer are respectively greater than the preset length threshold value;

[0177] Determine the packet frame format of each first long packet and the packet frame format of each second long packet;

[0178] Based on the packet frame format of each first long packet, each first long packet is allocated to each first buffer;

[0179] Based on the packet frame format of each second long packet, each second long packet is allocated to each second buffer.

[0180] Each embodiment in the specification is described in a progressive manner, and the same and similar parts between each embodiment can be referred to each other, and each embodiment focuses on the difference from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, it is described more simply, and the related parts can be referred to the part of the method embodiment. The above described system and system embodiment is only illustrative, wherein the unit described as a separate component can be or can not be physically separated, and the component displayed as a unit can be or can not be a physical unit, that is, it can be located in one place, or it can be distributed to multiple network units. According to the actual needs, part or all of the modules can be selected to achieve the purpose of the embodiment scheme. Those skilled in the art can understand and implement without creative labor.

[0181] Those skilled in the art will further realize that the mechanisms of the various examples described herein are capable of being implemented using any number of combinations of the described features. Accordingly, these examples are not limited to the mechanisms described herein, but rather, the intent is to cover all modifications and alternatives equivalent thereto. The preceding description of the examples is illustrative, and not restrictive. Many other examples will be apparent to those of skill in the art upon reviewing the above description. The scope of the examples should, therefore, be determined not with reference to the above description, but instead should be given to the appended claims, along with their full scope of equivalents.

[0182] The above description of disclosed examples allows one of ordinary skill in the art to make and use the application. Modifications of those examples will be obvious to those of ordinary skill in the art, and the generic principles defined herein can be applied to other examples without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the examples shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for allocating a message buffer, characterized in that, include: When it is necessary to allocate buffers for messages in the target channel, determine each sent message and each received message in the target channel; Each first long message is determined in each of the sent messages, and each second long message is determined in each of the received messages; The first long message and the second long message are respectively messages whose data segment length is greater than a preset length threshold; In each hardware buffer corresponding to the target channel, each first buffer and each second buffer are determined; the data segment length of the first buffer and the data segment length of the second buffer are respectively greater than the preset length threshold. Determine the message frame format of each first long message and the message frame format of each second long message; Based on the message frame format of each first long message, each first long message is allocated to each first buffer. Based on the message frame format of each second long message, each second long message is allocated to each second buffer.

2. The message buffer allocation method according to claim 1, characterized in that, The step of determining each first buffer in each hardware buffer corresponding to the target channel includes: Count the number of messages in each of the first longest messages; Determine whether the number of messages meets the preset allocation conditions; If the number of messages meets the allocation conditions, then the number of buffers is determined based on the number of messages. In each of the aforementioned hardware buffers, a candidate buffer is determined; the candidate buffer is a message buffer whose data segment length is greater than the preset length threshold. Among the candidate buffers, select each buffer that matches the number of buffers, and use the selected buffer as the first buffer.

3. The message buffer allocation method according to claim 2, characterized in that, Also includes: If the number of messages does not meet the allocation conditions, an error message is issued, and the buffer allocation process for each of the first long messages is stopped.

4. The message buffer allocation method according to claim 1, characterized in that, The allocation of each first long message to each first buffer based on the message frame format of each first long message includes: According to the message frame format of each first long message, each first long message is classified to obtain each first long message corresponding to each preset frame format; Determine the bitmask corresponding to each of the preset frame formats; For each preset frame format, based on the bitmask corresponding to the preset frame format, the message ID of each first long message corresponding to the preset frame format, and the preset binary search method, each first long message corresponding to the preset frame format is grouped to obtain each message group corresponding to the preset frame format. Each message group includes at least one first long message. The total number of message groups corresponding to all preset frame formats is equal to the total number of buffers in each first buffer. Determine the one-to-one correspondence between all the message packets corresponding to the preset frame formats and each of the first buffers; For each of the first buffers, the first long message in the message group corresponding to the first buffer is allocated to the first buffer.

5. The message buffer allocation method according to claim 1, characterized in that, Also includes: Each first short message is determined in each of the sent messages, and each second short message is determined in each of the received messages; The first short message and the second short message are respectively messages whose data segment length is not greater than the preset length threshold; In each hardware buffer corresponding to the target channel, each third buffer and each fourth buffer are determined; each first buffer, each second buffer, each third buffer and each fourth buffer do not overlap with each other; Determine the message frame format of each first short message and the message frame format of each second short message; Based on the message frame format of each of the first short messages, each of the first short messages is allocated to each of the third buffers; Based on the message frame format of each of the second short messages, each of the second short messages is allocated to each of the fourth buffers.

6. The message buffer allocation method according to claim 5, characterized in that, Also includes: After completing the buffer allocation process for each channel message, the channel messages are sorted in descending order of message data segment length; Each of the aforementioned channel messages includes each of the first long messages, each of the second long messages, each of the first short messages, and each of the second short messages; Based on the order of the messages in each channel, a message list corresponding to each message in the channel is generated.

7. The message buffer allocation method according to claim 6, characterized in that, Also includes: Determine the cache location corresponding to each of the aforementioned channel messages; Based on the message list and the cache location corresponding to each channel message, a mapping table is generated for each channel message; the mapping table is used to record the mapping relationship between the message ID of each channel message and the hardware cache location.

8. A message buffer allocation device, characterized in that, include: The first determining unit is used to determine each transmitted message and each received message in the target channel when it is necessary to allocate a buffer for the messages in the target channel. The second determining unit is used to determine each first long message in each of the sent messages and to determine each second long message in each of the received messages. The first long message and the second long message are respectively messages whose data segment length is greater than a preset length threshold; The third determining unit is used to determine each first buffer and each second buffer in each hardware buffer corresponding to the target channel; the data segment length of the first buffer and the data segment length of the second buffer are respectively greater than the preset length threshold; The fourth determining unit is used to determine the message frame format of each of the first long messages and the message frame format of each of the second long messages; The first allocation unit is configured to allocate each of the first long messages to each of the first buffers based on the message frame format of each of the first long messages. The second allocation unit is used to allocate each of the second long messages to each of the second buffers based on the message frame format of each of the second long messages.

9. A storage medium, characterized in that, The storage medium includes stored instructions, wherein when the instructions are executed, the device in which the storage medium is located executes the message buffer allocation method as described in any one of claims 1 to 7.

10. An electronic device, characterized in that, It includes memory, and one or more instructions, wherein one or more instructions are stored in memory and configured to be executed by one or more processors using the message buffer allocation method as described in any one of claims 1 to 7.