Multi-channel multi-priority hierarchical communication method and device based on MCU (Microprogrammed Control Unit)
By introducing a multi-channel and multi-priority hierarchical structure into the MCU's communication system, the problems of single hardware connection and data delay are solved, efficient data transmission and multi-channel support are achieved, and the real-time performance and communication speed of the system are improved.
Patent Information
- Application Number
- CN202510902468.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-01
- Publication Date
- 2025-09-23
AI Technical Summary
Existing MCU-based communication software only supports a single type of hardware connection and lacks data priority classification, making it difficult to send data with high real-time requirements in a timely manner. When system resources are tight, there will be large delays, making iteration and maintenance difficult and communication speeds slow.
It adopts a multi-channel and multi-priority layered communication method, which is divided into session layer, transport layer, data link layer, and driver layer. It sends and receives data through priority classification and event-driven methods, adds multi-channel support, and adds a large message cache at the session layer to improve system throughput.
It realizes timely priority transmission of data with high real-time requirements, reduces data delay on the link, improves the system's data throughput and communication speed, supports multiple hardware connection types, and facilitates development, debugging and maintenance.
Smart Images

Figure CN120692231A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to an MCU-based multi-channel, multi-priority layered communication method and device. Background Art
[0002] MCU (Microcontroller Unit) has been applied to various embedded devices. In automotive electronic systems (such as cockpit systems, Tbox, etc.), it is often used in conjunction with SOC due to its real-time performance.
[0003] , due to its real-time nature, it is often used in conjunction with SOC (System on Chip).
[0004] At present, the existing MCU-based communication software implementation provides SOC with various data collection (such as CAN, radar, etc.), power on and off, sleep and wake-up services to achieve stable, reliable and efficient communication between MCU and SOC.
[0005] However, existing MCU-based communication software implementations only support a single type of hardware connection, generally only one type of hardware connection. They lack priority classification for the data to be sent, making it difficult to send data with high real-time requirements in a timely manner when system resources are tight. They are also difficult to iterate and maintain in the face of increasingly complex applications and changing requirements. Furthermore, there is a relatively large delay between receiving a send command and actually sending the data to the hardware link, resulting in average real-time performance. Furthermore, the amount of data sent per unit time is small, resulting in slow communication speeds. Summary of the Invention
[0006] In view of this, the purpose of this application is to provide a multi-channel, multi-priority layered communication method and device based on an MCU. By implementing layered processing in design, it is divided into a session layer, a transport layer, a data link layer, and a driver layer, which is conducive to development, debugging, iteration, and maintenance. It also adds multi-channel support and can support multiple hardware connection types. It classifies the priority of the data to be sent, ensuring that data with high real-time requirements can be sent in a timely and preferential manner. Moreover, the sending and receiving of data is driven by events, and events are triggered continuously layer by layer, reducing the sending and receiving delay of data on the entire link and improving real-time performance. At the same time, adding a large message cache in the session layer improves the system's data throughput and communication speed.
[0007] In a first aspect, an embodiment of the present application provides an MCU-based multi-channel, multi-priority layered communication method, which is applied to an MCU-based multi-channel, multi-priority layered communication system; the multi-channel, multi-priority layered communication system includes a session layer, a transport layer, a data link layer, and a driver layer in the MCU that are bidirectionally connected in sequence, and the session layer and the transport layer, and the transport layer and the data link layer submit a sending request and return a result through a task specification; the method includes: When the session layer receives a message from the external application layer, it determines and adds the message to a message queue consistent with the priority of the message based on the priority of the message; wherein the session layer maintains multiple message queues, each message queue corresponding to a priority; the session layer allocates a first receive buffer and a first send buffer of a first size to each channel; each channel includes two task specifications; the parameters of each task specification include at least a channel number, a data type, a data address, a data length, and a processing result; In response to the first task specification being in a sending idle state, obtaining a corresponding target message from the message queue based on the priority of the message and the channel number of the channel to which the first task specification belongs, and submitting the target message to the transport layer through the first task specification to request sending of a message corresponding to the first task specification; In response to the transport layer receiving the first task specification, the transport layer obtains the target message based on the first task specification, and sends the target message to the data link layer via a second task specification to request sending the target message corresponding to the second task specification; wherein the transport layer allocates a second receive buffer and a second send buffer of a second size for each channel; In response to the data link layer receiving the second task description, the data link layer obtains the target message based on the second task description, calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing results to the transport layer after the sending is completed.
[0008] In a possible implementation, submitting the target message to the transport layer through the first task specification includes: Encoding the target message based on a preset encoding protocol, and filling the encoded target message into the first sending buffer; In response to the session layer completing processing of all target messages of the corresponding channel or the first sending buffer being filled, the first task description is filled in and submitted to the transport layer to request sending the message in the first sending buffer; wherein, the first task description includes the address of the first sending buffer.
[0009] In one possible implementation, the method further includes: determining whether the session layer has received a data reception processing request sent by the transport layer through a third task specification; If so, the transport layer decodes one or more target messages from the first receiving buffer according to the encoding protocol, and submits the target message to the application layer for processing, so that the application layer returns the result of processing the target message to the transport layer.
[0010] In a possible implementation, acquiring the target message based on the first task specification and sending the target message to the data link layer to request sending the target message includes: Upon receiving the sending request from the session layer through the first task specification, taking out the target message from a first sending buffer corresponding to the first task specification; Determining whether the target message can be sent in one go based on the sizes of the first sending buffer of the session layer and the second sending buffer of the transport layer, and returning a sending completion result to the session layer through the first task specification after the sending is completed; wherein the target message sent in one go corresponds to a single frame of data received by the transport layer, and the target message sent multiple times corresponds to multiple frames of data received by the transport layer; If so, encoding the target message retrieved from the first sending buffer into a second sending buffer of the transport layer based on the encoding protocol, filling in a corresponding second task specification and submitting it to the data link layer, so as to request the data link layer to send the target message in the second sending buffer in a single frame; wherein the second task specification includes the address of the second sending buffer; If not, the second task description is submitted to the data link layer multiple times to request the data link layer to send the target message in the second sending buffer in multiple frames.
[0011] In one possible implementation, the method further includes: In response to the transport layer receiving the receive data processing request sent by the data link layer through the fourth task description, the transport layer determines whether the data corresponding to the receive data processing request is multi-frame data; If so, packetizing the multiple frames of data according to the encoding protocol to obtain packetized data, submitting the packetized data to the session layer, and after the transport layer completes processing the multiple frames of data, the transport layer returns the received data processing result to the data link layer through the fourth task description, so that the data link layer can receive subsequent messages; If not, the single frame data is submitted to the session layer.
[0012] In a possible implementation, acquiring the target message based on the second task specification and calling an interface provided by the driver layer to send the target message to the external hardware layer includes: Packing the second sending buffer corresponding to the second task specification and adding a preset check code to write the second sending buffer; The interface provided by the driver layer is called to send the message in the second sending buffer to the external hardware layer.
[0013] In one possible implementation, the method further includes: The driver layer returns the sending result to the session layer; The driver layer returns the sending result to the session layer, including: The driver layer fills in the sending result in the fourth task specification and submits the fourth task specification to the transmission layer; The transport layer extracts the sending result from the fourth task specification and processes it, fills in the processed sending result in the first task specification, and submits the first task specification to the session layer; When the session layer receives the first task description, it retrieves the sending result from the first task description.
[0014] In a second aspect, an embodiment of the present application further provides an MCU-based multi-channel, multi-priority layered communication device, which is applied to an MCU-based multi-channel, multi-priority layered communication system, wherein the multi-channel, multi-priority layered communication system includes a session layer, a transport layer, a data link layer, and a driver layer connected in sequence bidirectionally under the MCU, and the session layer and the transport layer, and the transport layer and the data link layer submit a sending request and return a result through a task description; the device includes: A determination module is configured to, when the session layer receives a message from the external application layer, determine and, based on the priority of the message, add the message to a message queue consistent with the priority of the message; wherein the session layer maintains multiple message queues, each message queue corresponding to a priority; the session layer allocates a first receive buffer and a first send buffer of a first size to each channel; each channel includes two task specifications; parameters of each task specification include at least a channel number, a data type, a data address, a data length, and a processing result; a first sending module, configured to, in response to a first task specification being in a sending idle state, obtain a corresponding target message from the message queue based on a priority of the message and a channel number of a channel to which the first task specification belongs, and submit the target message to the transport layer through the first task specification to request sending of a message corresponding to the first task specification; a second sending module, configured to, in response to the transport layer receiving the first task specification, obtain the target message based on the first task specification, and send the target message to the data link layer via a second task specification to request the transmission of the target message corresponding to the second task specification; wherein the transport layer allocates a second receiving buffer and a second sending buffer of a second size for each channel; The third sending module is used to respond to the data link layer receiving the second task description, the data link layer obtains the target message based on the second task description, calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing results to the transport layer after the sending is completed.
[0015] In a possible implementation manner, the first sending module is specifically configured to: Encoding the target message based on a preset encoding protocol, and filling the encoded target message into the first sending buffer; In response to the session layer completing processing of all target messages of the corresponding channel or the first sending buffer being filled, the first task description is filled in and submitted to the transport layer to request sending the message in the first sending buffer; wherein, the first task description includes the address of the first sending buffer.
[0016] In a possible implementation, the device further includes: A first judgment module is used to judge whether the session layer has received the receive data processing request sent by the transport layer through the third task specification; The fourth sending module is used to: if so, the transport layer decodes a single or multiple target messages from the first receiving buffer according to the encoding protocol, and submits the target message to the application layer for processing, so that the application layer returns the result of processing the target message to the transport layer.
[0017] In a possible implementation manner, the second sending module is specifically configured to: Upon receiving the sending request from the session layer through the first task specification, taking out the target message from a first sending buffer corresponding to the first task specification; Determining whether the target message can be sent in one go based on the sizes of the first sending buffer of the session layer and the second sending buffer of the transport layer, and returning a sending completion result to the session layer through the first task specification after the sending is completed; wherein the target message sent in one go corresponds to a single frame of data received by the transport layer, and the target message sent multiple times corresponds to multiple frames of data received by the transport layer; If so, encoding the target message retrieved from the first sending buffer into a second sending buffer of the transport layer based on the encoding protocol, filling in a corresponding second task specification and submitting it to the data link layer, so as to request the data link layer to send the target message in the second sending buffer in a single frame; wherein the second task specification includes the address of the second sending buffer; If not, the second task description is submitted to the data link layer multiple times to request the data link layer to send the target message in the second sending buffer in multiple frames.
[0018] In a possible implementation, the device further includes: a second determining module, configured to, in response to the transport layer receiving a receive data processing request sent by the data link layer through the fourth task specification, determine by the transport layer whether the data corresponding to the receive data processing request is multi-frame data; a fifth sending module, configured to, if yes, packetize the multiple frames of data according to the encoding protocol to obtain packetized data, submit the packetized data to the session layer, and after the transport layer completes processing the multiple frames of data, return the received data processing result to the data link layer through the fourth task description, so that the data link layer can receive subsequent messages; The sixth sending module is configured to submit the single frame data to the session layer if no.
[0019] In a possible implementation manner, the third sending module is specifically configured to: Packing the second sending buffer corresponding to the second task specification and adding a preset check code to write the second sending buffer; The interface provided by the driver layer is called to send the message in the second sending buffer to the external hardware layer.
[0020] In a possible implementation, the device further includes: A return module, configured for the driver layer to return the sending result to the session layer; The return module is specifically used to: The driver layer fills in the sending result in the fourth task specification and submits the fourth task specification to the transmission layer; The transport layer extracts the sending result from the fourth task specification and processes it, fills in the processed sending result in the first task specification, and submits the first task specification to the session layer; When the session layer receives the first task description, it retrieves the sending result from the first task description.
[0021] An embodiment of the present application provides an MCU-based multi-channel, multi-priority layered communication method and device. When the session layer receives a message from an external application layer, it determines and adds the message to a message queue consistent with the priority of the message based on the priority of the message; in response to the first task specification being in an idle state for sending, the corresponding target message is obtained from the message queue based on the priority of the message and the channel number of the channel to which the first task specification belongs, and submits the target message to the transport layer through the first task specification to request sending the message corresponding to the first task specification; in response to the transport layer receiving the first task specification, the transport layer obtains the target message based on the first task specification, and sends the target message to the data link layer through the second task specification to request sending the target message corresponding to the second task specification; in response to the data link layer receiving the second task specification, the data link layer obtains the target message based on the second task specification, and calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing result to the transport layer after the sending is completed. This application utilizes a layered design consisting of a session layer, transport layer, data link layer, and driver layer, facilitating development, debugging, iteration, and maintenance. Multi-channel support is added to accommodate a variety of hardware connection types, and data transmission is prioritized to ensure timely delivery of data with high real-time requirements. Furthermore, events are used to drive data transmission and reception, with events triggered continuously layer by layer, reducing data transmission and reception delays across the entire link and improving real-time performance. Furthermore, a large message buffer is added to the session layer, increasing the system's data throughput and communication speed.
[0022] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0024] Figure 1 This is a flowchart of a multi-channel, multi-priority, hierarchical communication method based on an MCU according to an embodiment of the present application; Figure 2 It is a schematic diagram of the overall architecture of a multi-channel, multi-priority, hierarchical communication system; Figure 3 This is a schematic diagram of the sending process of a single frame of data; Figure 4 This is a schematic diagram of the receiving process of a single frame of data; Figure 5 This is a schematic diagram of the structure of a multi-channel, multi-priority, hierarchical communication device based on an MCU according to an embodiment of the present application; Figure 6 This is a schematic structural diagram of an electronic device provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of illustration and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowcharts can be implemented out of sequence, and steps without logical context can be reversed or implemented simultaneously. In addition, those skilled in the art, under the guidance of the contents of this application, can add one or more other operations to the flowchart, or remove one or more operations from the flowchart.
[0026] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present application.
[0027] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.
[0028] Considering that MCU has been applied to various embedded devices, and in automotive electronic systems (such as cockpit systems, Tbox, etc.), it is often used in conjunction with SOC due to its real-time nature.
[0029] At present, the existing MCU-based communication software implementation provides SOC with various data collection (such as CAN, radar, etc.), power on and off, sleep and wake-up services to achieve stable, reliable and efficient communication between MCU and SOC.
[0030] However, existing MCU-based communication software implementations only support a single type of hardware connection, generally only one type of hardware connection. They lack priority classification for the data to be sent, making it difficult to send data with high real-time requirements in a timely manner when system resources are tight. They are also difficult to iterate and maintain in the face of increasingly complex applications and changing requirements. Furthermore, there is a relatively large delay between receiving a send command and actually sending the data to the hardware link, resulting in average real-time performance. Furthermore, the amount of data sent per unit time is small, resulting in slow communication speeds.
[0031] To address this issue, the present application provides an MCU-based multi-channel, multi-priority layered communication method and device. This design utilizes a layered approach, divided into a session layer, a transport layer, a data link layer, and a driver layer, facilitating development, debugging, iteration, and maintenance. Multi-channel support is added, enabling support for a variety of hardware connection types. Data sent is prioritized, ensuring that data with high real-time requirements can be sent in a timely and prioritized manner. Furthermore, events are used to drive data transmission and reception, with events triggered continuously layer by layer, reducing data transmission and reception delays across the entire link and improving real-time performance. Furthermore, a large message cache is added to the session layer to increase the system's data throughput and communication speed.
[0032] Figure 1 This is a flowchart of a multi-channel, multi-priority, hierarchical communication method based on an MCU provided in an embodiment of the present application.
[0033] The multi-channel, multi-priority layered communication method based on MCU in the embodiment of the present application is applied to a multi-channel, multi-priority layered communication system based on MCU; the multi-channel, multi-priority layered communication system includes a session layer, a transport layer, a data link layer, and a driver layer in the MCU that are bidirectionally connected in sequence, and each layer only interacts with the adjacent layer. For example, Figure 2 The overall architecture diagram of the multi-channel multi-priority hierarchical communication system is shown in Figure 2. Figure 2 As shown, it includes session layer, transport layer, data link layer and driver layer.
[0034] like Figure 1 As shown, the multi-channel multi-priority hierarchical communication method based on MCU in the embodiment of the present application may specifically include: S101 . When the session layer receives a message from the external application layer, it determines and adds the message to a message queue consistent with the priority of the message based on the priority of the message.
[0035] S102. In response to the first task specification being in an idle state for sending, the corresponding target message is obtained from the message queue based on the priority of the message and the channel number of the channel to which the first task specification belongs, and the target message is submitted to the transport layer through the first task specification to request sending the message corresponding to the first task specification.
[0036] S103. In response to the transport layer receiving the first task specification, the transport layer obtains the target message based on the first task specification, and sends the target message to the data link layer through the second task specification to request sending the target message corresponding to the second task specification.
[0037] S104. In response to the data link layer receiving the second task description, the data link layer obtains the target message based on the second task description, calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing result to the transport layer after the sending is completed.
[0038] The aforementioned MCU-based multi-channel, multi-priority layered communication method utilizes a layered design, divided into the session layer, transport layer, data link layer, and driver layer. This facilitates development, debugging, iteration, and maintenance. It also supports multiple channels and various hardware connection types. It prioritizes transmitted data, ensuring that data with high real-time requirements is sent promptly and prioritized. Furthermore, data transmission and reception are driven by events, which are triggered continuously layer by layer, reducing data transmission and reception delays across the entire link and improving real-time performance. Furthermore, a large message buffer is added to the session layer, increasing the system's data throughput and communication speed.
[0039] The above exemplary steps of the embodiment of the present application are described below with reference to specific examples: S101 , when the session layer receives a message from the external application layer, it determines and adds the message to a message queue consistent with the priority of the message based on the priority of the message.
[0040] Specifically, such as Figure 2As shown in the figure, the session layer maintains multiple message queues (MsgQue), each message queue corresponds to a priority (for example, if the message priority is 1, it will be added to MsgQue1); the session layer allocates a first receive buffer (SRBufN) and a first send buffer (STBufN) of a first size to each channel, that is, the session layer allocates a receive buffer and a send buffer (SRBufN, STBufN, whose first size can be 4K bytes) to each channel.
[0041] It's important to note that each layer of the multi-channel, multi-priority, layered communication system interacts only with adjacent layers, and the interfaces are kept minimal to achieve high cohesion and low coupling. Furthermore, between the session layer and the transport layer, and between the transport layer and the data link layer, only task specifications are used to submit and return requests.
[0042] Each channel includes two job specifications (JobSpec), one for sending and one for receiving, specifically, for example, Figure 2 As shown, the task specifications from the session layer to the transport layer and then to the data link layer are the first task specification (STJobSpecN) and the second task specification (DTJobSpecN), and the task specifications from the data link layer to the transport layer and then to the session layer are the third task specification (SRJobSpecN) and the fourth task specification (DRJobSpecN). The first task specification corresponds to the third task specification, and the second task specification corresponds to the fourth task specification; the two task specifications STJobSpecN and DTJobSpecN are used to submit sending requests and return results, and the two task specifications SRJobSpecN and DRJobSpecN are used to receive data and return processing results.
[0043] The parameters of each task description include at least the channel number, data type, data address, data length and processing result, as follows: a. Channel number, also known as channel ID. Each channel has a channel ID.
[0044] b. Data type: There are only 4 types, namely sending and receiving, sending result feedback, and receiving processing result feedback.
[0045] c.Data address: The buffer address that needs to be sent or received.
[0046] d. Data length: the length of data to be sent or received.
[0047] e. Processing result: Send or receive the processing result, which is used to return the processing result to the service requester.
[0048] The first task specification (STJobSpecN) and the second task specification (DTJobSpecN) in each channel of the session layer are used to submit a sending request and return a result.
[0049] Here, in this application, when one layer initiates a data sending or receiving data processing request to another layer through JobSpec, the requested layer must process it as quickly as possible and return the result through JobSpec so that the requester can process subsequent requests and improve system efficiency.
[0050] In the embodiment of the present application, the session layer receives a message sending request from the application layer and adds the message to the message queue of the corresponding priority according to the priority of the message, that is, adds the Message to the corresponding MsgQue. Figure 2 .
[0051] Optionally, after the message is sent, the message is deleted from the corresponding message queue.
[0052] S102, in response to the first task specification being in an idle state for sending, obtain the corresponding target message from the message queue based on the priority of the message and the channel number of the channel to which the first task specification belongs, and submit the target message to the transport layer through the first task specification to request sending the message corresponding to the first task specification.
[0053] In the embodiment of the present application, when the first task specification STJobSpec1 is in the idle state, i.e., the unsent state (via STJobSpecN, i.e., idle state) or the session layer receives the result of the last send, the corresponding target message Message is obtained from the message queue MsgQue according to the priority and channel number of the message (if there is a message, the high-priority message is obtained first, and the state of the target message Message is marked as being sent), and the target message is submitted to the transport layer through the first task specification STJobSpec1 to request the sending of the message corresponding to the first task specification STJobSpec1. For example, Figure 2 .
[0054] Optionally, when the target message is submitted to the transport layer through the first task specification, the target message is encoded based on a preset encoding protocol, and the encoded target message is filled into the first sending buffer STBuf1; in response to the session layer completing processing of all target messages of the corresponding channel or the first sending buffer STBuf1 being filled, the first task specification STJobSpec1 is filled in and submitted to the transport layer to request the message in the first sending buffer STBuf1 to be sent. The first task specification STJobSpec1 includes the address of the first sending buffer STBufN, which is the above-mentioned data address.
[0055] Further, it is determined whether the session layer has received the receive data processing request sent by the transport layer through the third task specification SRJobSpec1; if so, the transport layer decodes a single or multiple target messages from the first receive buffer SRBuf1 according to the encoding protocol, and submits the target message to the application layer for processing, so that the application layer returns the result of processing the target message to the transport layer.
[0056] S103, in response to the transport layer receiving the first task specification, the transport layer obtains the target message based on the first task specification, and sends the target message to the data link layer through the second task specification to request the sending of the target message corresponding to the second task specification. In an embodiment of the present application, the transport layer allocates a second receive buffer (RxBufN) and a second send buffer (TxBufN) of a second size (for example, 512Bytes) to each channel. When the transport layer receives the first task specification STJobSpec1, the transport layer obtains the target message based on the first task specification STJobSpec1, and sends the target message to the data link layer through the second task specification DTJobSpec1 to request the sending of the target message corresponding to the second task specification DTJobSpec1. For example, Figure 2 shown.
[0057] In some embodiments, upon receiving a sending request from the session layer through the first task specification STJobSpec1, the target message is taken out from the first sending buffer STBuf1 corresponding to the first task specification STJobSpec1; based on the size of the first sending buffer STBuf1 of the session layer and the second sending buffer TxBuf1 of the transport layer, it is determined whether the target message can be sent in one go, and after the sending is completed, the sending completion result is returned to the session layer through the first task specification; if so, based on the encoding protocol, the target message taken out from the first sending buffer STBuf1 is encoded to the second sending buffer TxBuf1 of the transport layer, the corresponding second task specification DTJobSpec1 is filled in and submitted to the data link layer to request the data link layer to send the target message in the second sending buffer TxBuf1 in a single frame; if not, the second task specification DTJobSpec1 is submitted to the data link layer multiple times to request the data link layer to send the target message in the second sending buffer TxBufN in multiple frames.
[0058] Among them, the target message that is sent once corresponds to a single frame of data received by the transport layer, that is, it corresponds to the transport layer sending a single frame of data to the data link layer. The target message that needs to be sent multiple times corresponds to multiple frames of data received by the transport layer, that is, it corresponds to the transport layer sending multiple frames of data to the data link layer; the second task specification DTJobSpecN contains the address of the second sending buffer TxBuf1, that is, the data address.
[0059] Specifically, when the transport layer receives a send request from the session layer (through STJobSpecN), the transport layer will determine whether the data to be sent can be sent in one time or needs to be sent multiple times (this depends on the size of the session layer's STBufN and the transport layer's TxBufN). If it can be sent in one time, the data in STBufN will be packaged into TxBufN according to the protocol, and DTJobSpecN will be filled in and handed over to the data link layer, requesting the data in TxBufN to be sent. When the sending is completed (the data link layer returns the result through DTJobSpecN), the result of the sending completion can be returned to the session layer (through STJobSpecN). If it takes multiple times to complete the sending, it is necessary to submit a send request to the data link layer multiple times. When all the data is sent, the result of the sending completion is returned to the session layer.
[0060] To continue, the above can be sent in one time, which is called single-frame sending, and the data that needs to be sent multiple times is called multi-frame sending. Similarly, the transport layer will also receive single-frame and multi-frame data. If multi-frame data is received, the transport layer needs to package this data into a packet according to the protocol group into SRBufN and send it to the session layer through SRJobSpecN for processing.
[0061] Furthermore, in response to the transport layer receiving the receive data processing request sent by the data link layer through the fourth task specification DRJobSpecN, the transport layer determines whether the message data corresponding to the receive data processing request is multi-frame data; if so, the multi-frame data is packaged according to the encoding protocol to obtain packaged data, and the packaged data is submitted to the session layer. After the transport layer completes processing the multi-frame data, the transport layer returns the receive data processing result to the data link layer through the fourth task specification DRJobSpecN so that the data link layer can receive subsequent messages; if not, the single frame data is submitted to the session layer.
[0062] S104, in response to the data link layer receiving the second task specification DTJobSpecN, the data link layer obtains the target message based on the second task specification, and calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing result to the transport layer after the sending is completed.
[0063] In the embodiment of the present application, the hardware layer is below the driver layer. When the data link layer receives the second task specification DTJobSpec1, the data link layer obtains the target message based on the second task specification DTJobSpec1, and calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing result to the transport layer after the sending is completed. It should be noted that the driver layer mainly provides data sending and receiving services for each channel. For example, Figure 2 shown.
[0064] Optionally, when the target message is obtained based on the second task specification and the interface provided by the driver layer is called to send the target message to the external hardware layer, the second sending buffer TxBufN corresponding to the second task specification DTJobSpecN is packaged and a preset verification code is added to write into the second sending buffer TxBufN; the interface provided by the driver layer is called to send the message in the second sending buffer TxBufN to the external hardware layer.
[0065] Furthermore, the data link layer determines the data header identifier of the data received from the transport layer, and determines whether the transport layer successfully sent the data last time based on the data header identifier; if not, the transport layer resends the data to the data link layer.
[0066] It should be noted that the main function of the data link layer is to receive the sending request from the transport layer (through DTJobSpecN), then call the interface provided by the driver layer to send the data, and finally submit the processing results to the transport layer; receive data from the driver layer to RxBufN, and fill in DRJobSpecN to submit this data to the transport layer for processing; add a check code to the sent data and check the received data; determine whether the last data transmission was successful by receiving the data header identifier sent by the driver layer. If it fails, it can be resent again.
[0067] The embodiment of the present application provides an MCU-based multi-channel and multi-priority layered communication method. When the session layer receives a message from the external application layer, it determines and adds the message to a message queue consistent with the priority of the message based on the priority of the message; in response to the first task specification being in an idle state for sending, the corresponding target message is obtained from the message queue based on the priority of the message and the channel number of the channel to which the first task specification belongs, and the target message is submitted to the transport layer through the first task specification to request the sending of the message corresponding to the first task specification; in response to the transport layer receiving the first task specification, the transport layer obtains the target message based on the first task specification, and sends the target message to the data link layer through the second task specification to request the sending of the target message corresponding to the second task specification; in response to the data link layer receiving the second task specification, the data link layer obtains the target message based on the second task specification, and calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing result to the transport layer after the sending is completed. The MCU-based multi-channel, multi-priority layered communication method proposed in this application utilizes a layered design, divided into the session layer, transport layer, data link layer, and driver layer. This facilitates development, debugging, iteration, and maintenance. It also supports multiple channels and various hardware connection types. It prioritizes transmitted data, ensuring that data with high real-time requirements is promptly sent first. Furthermore, events drive the transmission and reception of data, with events triggered continuously layer by layer. This reduces data transmission and reception delays across the entire link and improves real-time performance. Furthermore, a large message buffer is added to the session layer, increasing the system's data throughput and communication speed.
[0068] Furthermore, the driver layer returns the sending result to the session layer.
[0069] In some embodiments, the driver layer fills in the sending result in the fourth task specification DRJobSpecN and submits the fourth task specification DRJobSpecN to the transport layer; the transport layer takes out the sending result from the fourth task specification DRJobSpecN and processes it, fills in the processed sending result in the first task specification STJobSpecN, and submits the first task specification STJobSpecN to the session layer; the session layer receives the first task specification STJobSpecN and takes out the sending result from the first task specification STJobSpecN.
[0070] Furthermore, the data link layer receives the data from the driver layer and packages it into the second receiving buffer RxBufN of the transport layer, and fills in the corresponding fourth task specification DRJobSpecN to submit the fourth task specification DRJobSpecN to the transport layer for processing.
[0071] In the data transmission, the above embodiments introduce the resources and functions mainly managed by each layer. For example, Figure 2 as shown, it shows the flow path of the Message data stream in the system. Next, mainly taking single-frame data as an example, the data transmission process is illustrated. Its general process is as Figure 3 shown; the processing of multiple frames only differs from that of single frames in the transport layer. Therefore, the processing process in the transport layer is as follows: Receive STJobSpec1; extract data from STBuf1, detect that multiple frames (N frames) need to be sent, and encode the data of the current frame (the frame sequence number is denoted as I, initially 0) according to the protocol into TxBuf1; fill in DTJobSpec1 (including the address of TxBuf1) and request transmission; when this frame is transmitted successfully (receive the transmission result DTJobSpec1 from the data link layer), detect whether the transmission of this multiple-frame is completed (whether N frames have been sent, which can be detected by the I sequence number). If the transmission is completed, submit the result (STJobSpec1) to the session layer; if not completed, then I++, and repeat the process of steps 2-4 until completion.
[0072] In the data reception, as Figure 2 shown, it shows the flow path of the received Message data stream in the system. Next, mainly taking single-frame data as an example, the data reception process is illustrated. Its general process is as Figure 4 shown; the processing of multiple frames only differs from that of single frames in the transport layer. Therefore, the processing process in the transport layer is as follows: Receive data DRJobSpec1 from the data link layer; analyze the received data and find that this reception is for multiple frames, with a total of N frames. Denote the current received frame sequence number as I (the initial value is 0); the current received frame is the I-th frame, fill the data of the I-th frame into SRBuf1 and I++; return the processing result (DRJobSpec1) to the data link layer; if this multiple-frame has been received completely (I >= N), then fill in SRJobSpec1 and submit the data in SRBuf1 to the session layer; if this multiple-frame has not been received completely (I < N), then wait for data reception and execute the process of steps 3-5.
[0073] Therefore, this application adds a message caching mechanism and a frame grouping and packetizing mechanism for the session layer message queue, improving the system data throughput and communication speed; events are triggered continuously layer by layer, with faster processing speed, reducing the transmission and reception delay of data on the entire link; data verification and retransmission are added to the data link layer, improving the system fault tolerance and anti-interference capabilities; support for multiple priority transmission queues ensures that data with high real-time requirements is sent first; support for multiple channels enables arbitrary configuration of the channels for sending and receiving; the hierarchical design is conducive to development, debugging, and maintenance.
[0074] It should be noted that the present application is a multi-channel multi-priority layered communication method based on MCU, that is, a multi-channel multi-priority layered communication method on MCU.
[0075] Figure 5 The multi-channel multi-priority layered communication device based on MCU provided in the embodiment of the present application is applied to the multi-channel multi-priority layered communication system based on MCU. The multi-channel multi-priority layered communication system includes a session layer, a transport layer, a data link layer, and a driver layer connected in sequence bidirectionally under the MCU. The session layer and the transport layer, and the transport layer and the data link layer submit sending requests and return results through task specifications. Figure 5 As shown, the MCU-based multi-channel multi-priority layered communication device 500 of the embodiment of the present application may specifically include: Determination module 501 is used to determine and add the message to a message queue consistent with the priority of the message based on the priority of the message when the session layer receives a message from the external application layer; wherein, the session layer maintains multiple message queues, each message queue corresponds to a priority; the session layer allocates a first receiving buffer and a first sending buffer of a first size to each channel; each channel includes two task specifications; the parameters of each task specification include at least the channel number, data type, data address, data length and processing result.
[0076] The first sending module 502 is used to obtain the corresponding target message from the message queue based on the priority of the message and the channel number of the channel to which the first task specification belongs in response to the first task specification being in the sending idle state, and submit the target message to the transport layer through the first task specification to request sending the message corresponding to the first task specification.
[0077] The second sending module 503 is used to respond to the transport layer receiving the first task specification, the transport layer obtaining the target message based on the first task specification, and sending the target message to the data link layer through the second task specification to request sending the target message corresponding to the second task specification; wherein, the transport layer allocates a second receiving buffer and a second sending buffer of a second size to each channel.
[0078] The third sending module 504 is used to respond to the data link layer receiving the second task description, the data link layer obtains the target message based on the second task description, calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing result to the transport layer after the sending is completed.
[0079] In a possible implementation, the first sending module is specifically configured to: Encoding the target message based on a preset encoding protocol, and filling the encoded target message into the first sending buffer; In response to the session layer completing processing of all target messages of the corresponding channel or the first sending buffer being filled, the first task description is filled in and submitted to the transport layer to request sending the message in the first sending buffer; wherein the first task description includes the address of the first sending buffer.
[0080] In a possible implementation, the device further includes: A first determination module is configured to determine whether the session layer has received a data reception processing request sent by the transport layer via a third task specification; The fourth sending module is used to: if so, the transport layer decodes a single or multiple target messages from the first receiving buffer according to the encoding protocol, and submits the target message to the application layer for processing, so that the application layer returns the result of processing the target message to the transport layer.
[0081] In a possible implementation manner, the second sending module is specifically configured to: Upon receiving a sending request from the session layer through the first task specification, taking out the target message from the first sending buffer corresponding to the first task specification; Determine whether the target message can be sent in one go based on the sizes of the first sending buffer of the session layer and the second sending buffer of the transport layer, and after the sending is completed, return the result of the sending completion to the session layer through the first task description; wherein, the target message sent in one go corresponds to a single frame of data received by the transport layer, and the target message sent multiple times corresponds to multiple frames of data received by the transport layer; If so, the target message retrieved from the first send buffer is encoded into the second send buffer of the transport layer based on the encoding protocol, and the corresponding second task specification is filled in and submitted to the data link layer to request the data link layer to send the target message in the second send buffer in a single frame; wherein the second task specification includes the address of the second send buffer (TxBufN); If not, the second task description is submitted to the data link layer multiple times to request the data link layer to send the target message in the second sending buffer in multiple frames.
[0082] In a possible implementation, the device further includes: A second judgment module is configured to, in response to the transport layer receiving the receive data processing request sent by the data link layer through the fourth task specification, determine whether the data corresponding to the receive data processing request is multi-frame data; a fifth sending module, configured to, if yes, package the multi-frame data according to the encoding protocol to obtain packaged data, submit the packaged data to the session layer, and after the transport layer completes processing of the multi-frame data, the transport layer returns the received data processing result to the data link layer through the fourth task specification DRJobSpecN, so that the data link layer can receive subsequent messages; The sixth sending module is configured to submit the single frame data to the session layer if no.
[0083] In a possible implementation manner, the third sending module is specifically configured to: Packing the second sending buffer corresponding to the second task specification and adding a preset check code to write into the second sending buffer; The interface provided by the driver layer is called to send the message in the second sending buffer to the external hardware layer.
[0084] In a possible implementation, the device further includes: The return module is used to drive the layer to return the sending result to the session layer; Returns the module, specifically used for: The driver layer fills in the sending result in the fourth task specification and submits the fourth task specification to the transport layer; The transport layer retrieves the sending result from the fourth task specification and processes it, fills in the processed sending result in the first task specification, and submits the first task specification to the session layer; When the session layer receives the first task description, it retrieves the sending result from the first task description.
[0085] The embodiment of the present application provides an MCU-based multi-channel, multi-priority layered communication device. When the session layer receives a message from the external application layer, it determines and adds the message to a message queue consistent with the priority of the message based on the priority of the message; in response to the first task specification being in an idle state for sending, the corresponding target message is obtained from the message queue based on the priority of the message and the channel number of the channel to which the first task specification belongs, and submits the target message to the transport layer through the first task specification to request the sending of the message corresponding to the first task specification; in response to the transport layer receiving the first task specification, the transport layer obtains the target message based on the first task specification, and sends the target message to the data link layer through the second task specification to request the sending of the target message corresponding to the second task specification; in response to the data link layer receiving the second task specification, the data link layer obtains the target message based on the second task specification, and calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing result to the transport layer after the sending is completed. The MCU-based multi-channel, multi-priority layered communication device of this application utilizes a layered design, divided into a session layer, a transport layer, a data link layer, and a driver layer. This facilitates development, debugging, iteration, and maintenance. It also supports multiple channels and various hardware connection types. It prioritizes transmitted data, ensuring that data with high real-time requirements is promptly sent first. Furthermore, events drive the transmission and reception of data, with events triggered continuously layer by layer, reducing data transmission and reception delays across the entire link and improving real-time performance. Furthermore, a large message buffer is added to the session layer, increasing the system's data throughput and communication speed.
[0086] like Figure 6 As shown, an electronic device 600 provided in an embodiment of the present application includes: a processor 601, a memory 602 and a bus, wherein the memory 602 stores machine-readable instructions executable by the processor 601. When the electronic device is running, the processor 601 communicates with the memory 602 through the bus, and the processor 601 executes the machine-readable instructions to perform the steps of the above-mentioned MCU-based multi-channel multi-priority layered communication method.
[0087] Specifically, the above-mentioned memory 602 and processor 601 can be general-purpose memories and processors, which are not specifically limited here. When the processor 601 runs the computer program stored in the memory 602, it can execute the above-mentioned MCU-based multi-channel multi-priority layered communication method.
[0088] Corresponding to the above-mentioned MCU-based multi-channel multi-priority layered communication method, an embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by the processor, the steps of the above-mentioned MCU-based multi-channel multi-priority layered communication method are executed.
[0089] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the method embodiment, and will not be repeated in this application. In the several embodiments provided in this application, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0090] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed across multiple network elements. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0091] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0092] If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of this application, or the portion that contributes to the prior art, or the portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the deployment method described in each embodiment of this application. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard drive, ROM, RAM, a magnetic disk, or an optical disk.
[0093] The above are only specific embodiments of the present application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A multi-channel, multi-priority layered communication method based on an MCU, applied to a multi-channel, multi-priority layered communication system based on an MCU; the multi-channel, multi-priority layered communication system comprises a session layer, a transport layer, a data link layer, and a driver layer in the MCU, which are bidirectionally connected in sequence, and the session layer and the transport layer, as well as the transport layer and the data link layer, submit a sending request and return a result through a task specification; characterized in that: The method comprises: When the session layer receives a message from the external application layer, it determines and adds the message to a message queue consistent with the priority of the message based on the priority of the message; wherein the session layer maintains multiple message queues, each message queue corresponding to a priority; the session layer allocates a first receive buffer and a first send buffer of a first size to each channel; each channel includes two task specifications; the parameters of each task specification include at least a channel number, a data type, a data address, a data length, and a processing result; In response to the first task specification being in a sending idle state, obtaining a corresponding target message from the message queue based on the priority of the message and the channel number of the channel to which the first task specification belongs, and submitting the target message to the transport layer through the first task specification to request sending of a message corresponding to the first task specification; In response to the transport layer receiving the first task specification, the transport layer obtains the target message based on the first task specification, and sends the target message to the data link layer via a second task specification to request sending the target message corresponding to the second task specification; wherein the transport layer allocates a second receive buffer and a second send buffer of a second size for each channel; In response to the data link layer receiving the second task description, the data link layer obtains the target message based on the second task description, calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing results to the transport layer after the sending is completed.
2. The method according to claim 1, characterized in that Submitting the target message to the transport layer through the first task specification includes: Encoding the target message based on a preset encoding protocol, and filling the encoded target message into the first sending buffer; In response to the session layer completing processing of all target messages of the corresponding channel or the first sending buffer being filled, the first task description is filled in and submitted to the transport layer to request sending the message in the first sending buffer; wherein, the first task description includes the address of the first sending buffer.
3. The method according to claim 2, characterized in that The method further comprises: determining whether the session layer has received a data reception processing request sent by the transport layer through a third task specification; If so, the transport layer decodes one or more target messages from the first receiving buffer according to the encoding protocol, and submits the target message to the application layer for processing, so that the application layer returns the result of processing the target message to the transport layer.
4. The method according to claim 3, characterized in that The acquiring the target message based on the first task specification and sending the target message to the data link layer to request sending the target message includes: Upon receiving the sending request from the session layer through the first task specification, taking out the target message from a first sending buffer corresponding to the first task specification; Determining whether the target message can be sent in one go based on the sizes of the first sending buffer of the session layer and the second sending buffer of the transport layer, and returning a sending completion result to the session layer through the first task specification after the sending is completed; wherein the target message sent in one go corresponds to a single frame of data received by the transport layer, and the target message sent multiple times corresponds to multiple frames of data received by the transport layer; If so, encoding the target message retrieved from the first sending buffer into a second sending buffer of the transport layer based on the encoding protocol, filling in a corresponding second task specification and submitting it to the data link layer, so as to request the data link layer to send the target message in the second sending buffer in a single frame; wherein the second task specification includes the address of the second sending buffer; If not, the second task description is submitted to the data link layer multiple times to request the data link layer to send the target message in the second sending buffer in multiple frames.
5. The method according to claim 4, characterized in that The method further comprises: In response to the transport layer receiving the receive data processing request sent by the data link layer through the fourth task description, the transport layer determines whether the data corresponding to the receive data processing request is multi-frame data; If so, packetizing the multiple frames of data according to the encoding protocol to obtain packetized data, submitting the packetized data to the session layer, and after the transport layer completes processing the multiple frames of data, the transport layer returns the received data processing result to the data link layer through the fourth task description, so that the data link layer can receive subsequent messages; If not, the single frame data is submitted to the session layer.
6. The method according to claim 5, characterized in that The acquiring the target message based on the second task specification and calling the interface provided by the driver layer to send the target message to the external hardware layer includes: Packing the second sending buffer corresponding to the second task specification and adding a preset check code to write the second sending buffer; The interface provided by the driver layer is called to send the message in the second sending buffer to the external hardware layer.
7. The method according to claim 6, characterized in that The method further comprises: The driver layer returns the sending result to the session layer; The driver layer returns the sending result to the session layer, including: The driver layer fills in the sending result in the fourth task specification and submits the fourth task specification to the transmission layer; The transport layer extracts the sending result from the fourth task specification and processes it, fills in the processed sending result in the first task specification, and submits the first task specification to the session layer; When the session layer receives the first task description, it retrieves the sending result from the first task description.
8. A multi-channel, multi-priority layered communication device based on an MCU, applied to a multi-channel, multi-priority layered communication system based on an MCU; The multi-channel, multi-priority layered communication system includes the session layer, transport layer, data link layer, and driver layer in the MCU, which are bidirectionally connected in sequence. The session layer and the transport layer, and the transport layer and the data link layer submit sending requests and return results through task specifications; it is characterized by: The device comprises: A determination module is configured to, when the session layer receives a message from the external application layer, determine and, based on the priority of the message, add the message to a message queue consistent with the priority of the message; wherein the session layer maintains multiple message queues, each message queue corresponding to a priority; the session layer allocates a first receive buffer and a first send buffer of a first size to each channel; each channel includes two task specifications; parameters of each task specification include at least a channel number, a data type, a data address, a data length, and a processing result; a first sending module, configured to, in response to a first task specification being in a sending idle state, obtain a corresponding target message from the message queue based on a priority of the message and a channel number of a channel to which the first task specification belongs, and submit the target message to the transport layer through the first task specification to request sending of a message corresponding to the first task specification; a second sending module, configured to, in response to the transport layer receiving the first task specification, obtain the target message based on the first task specification, and send the target message to the data link layer via a second task specification to request the transmission of the target message corresponding to the second task specification; wherein the transport layer allocates a second receiving buffer and a second sending buffer of a second size for each channel; The third sending module is used to respond to the data link layer receiving the second task description, the data link layer obtains the target message based on the second task description, calls the interface provided by the driver layer to send the target message to the external hardware layer, and submits the processing results to the transport layer after the sending is completed.
9. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the memory communicate via the bus. When the machine-readable instructions are executed by the processor, the steps of the MCU-based multi-channel, multi-priority hierarchical communication method as described in any one of claims 1 to 7 are performed.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, executes the steps of the MCU-based multi-channel multi-priority hierarchical communication method according to any one of claims 1 to 7.
