A multi-frame communication method and system for reducing software load rate

CN116389386BActive Publication Date: 2026-10-20WENZHOU CHANGJIANG AUTOMOBILE ELECTRONICS SYST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310356612.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-31
Publication Date
2026-10-20
Estimated Expiration
2043-03-31

AI Technical Summary

Technical Problem

[0005]为了改善单位时间内主机与从机之间的请求、响应过多导致系统稳定性下降的问题,本申请提供一种降低软件负载率的多帧通信方法及其系统

Benefits of technology

1.使得发送状态机持续保持在最佳工作状态下发送数据,防止了同时接收到多个请求时发送状态机持续保持最高功率工作,导致芯片负载率过高,出现温度上升等因素,影响系统稳定性,从而影响后续工作效率,提高了系统稳定性,还保证了工作效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116389386B_ABST
    Figure CN116389386B_ABST
Patent Text Reader

Abstract

The application relates to the field of automobile electronic communication, in particular to a multi-frame communication method and system for reducing software load rate, which comprises setting a request cycle time and a sending-receiving cycle time; a communication main task is periodically triggered to obtain a request under a current priority, and corresponding protocol frame data of the request is copied to a data sending buffer for sending; the request cycle time is obtained, and a request under a next priority is obtained according to time data in the request cycle time to perform a cycle of the communication main task; a sending-receiving task is periodically triggered, a sending state machine obtains the sending-receiving cycle time, and protocol frame data in the data sending buffer is sent in sequence according to bit numbers; interval time of data sending of adjacent bit numbers is determined according to time data in the sending-receiving cycle time; after receiving the protocol frame data, a receiving state machine stores the protocol frame data in a receiving buffer in a receiving sequence for calling by an upper layer. The application has the effect of improving system stability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automotive electronic communication, and in particular to a multi-frame communication method and system for reducing software load. Background Technology

[0002] With the development of new energy in my country, the use of new energy vehicles is becoming more and more widespread. Since new energy vehicles use new energy as their energy source, it is inevitable that a system is needed to coordinate and control the entire vehicle. MCU is often used for system communication.

[0003] Most existing communication mechanisms between MCUs rely on application requests, such as local button and knob status requests, or network requests (including requests from other network nodes and diagnostic requests from the host computer), to be converted into the required data frames for communication. For example, the host might request the slave to send its local button status, the host might send its indicator light status, and the host might need to read the slave's diagnostic status.

[0004] A master controller typically corresponds to multiple slave controllers. In a car, a master control chip often corresponds to multiple slave chips. These slave chips include components for the central control screen, lighting controls, accelerator pedals, and detection devices such as distance sensors. Because these slave chips are constantly working, they continuously communicate with the master controller. If the number and frequency of requests between the master and slave controllers are high within a given timeframe, the responses will also be numerous and concentrated. This will cause the MCU to spend most of its time, or at certain points in time, processing sending and receiving tasks. This leads to excessively high MCU load, especially a high instantaneous load, meaning an excessively high peak task load. Excessive MCU load can result in decreased system stability and failure to meet the requirements of OEM customers. Summary of the Invention

[0005] To address the issue of decreased system stability caused by excessive requests and responses between the host and slave devices within a given time period, this application provides a multi-frame communication method and system for reducing software load.

[0006] This application provides a multi-frame communication method and system for reducing software load, which adopts the following technical solution: A multi-frame communication method for reducing software load includes: Set the request loop time and send / receive loop time; The main communication task is triggered periodically to obtain requests under the current priority, copy the corresponding protocol frame data to the data sending buffer to be sent, obtain the request loop time, and obtain the next priority request based on the time data in the request loop time to perform the loop of the main communication task. The transmitting state machine obtains the transmit / receive cycle time. The transmitting state machine transmits the protocol frame data in the data transmission buffer in order of bit length. The interval between the transmission of adjacent bit lengths is determined by the time data in the transmit / receive cycle time. After receiving protocol frame data, the receiving state machine will store the protocol frame data in the receiving buffer according to the receiving order for use by the upper layer.

[0007] By adopting the above technical solution, when the main communication task receives multiple requests simultaneously, the requests are first classified according to priority, then the requests of the same priority are sorted, and then a frame of data in the sending buffer is determined at each request loop time. The sending state machine sends one byte of data to the sending buffer at a time, and then sends the next byte of data after the send-receive loop time. This ensures that the sending state machine is always in the optimal working state to send data, preventing the sending state machine from continuously operating at the highest power when multiple requests are received simultaneously, which would lead to excessive chip load, failure of other system tasks to execute normally, and impact on system stability and subsequent work efficiency. This improves system stability and ensures work efficiency.

[0008] Optionally, after setting the request loop time and the send / receive loop time, the method further includes: Set the frame start data, frame ID data, frame length data, and frame check data; After receiving the protocol frame data, the receiving state machine also includes: After receiving protocol frame data, it is determined whether the protocol frame data has an escape flag. If it is, the escape flag is removed and it is determined whether it is a frame start escape. If the frame start escape determination is true, the received protocol frame data is subjected to frame start determination A. Frame start determination A is to determine whether the protocol frame data matches the set frame start data. If the frame start escape determination is true, the escape data other than the frame start data is escaped.

[0009] By adopting the above technical solution, several sets of frame start data, frame ID data, frame length data, and frame check data are first stored in the processor's database. The presence or absence of an escape flag determines whether the received data should be escaped. This enables automatic classification of escaped and non-escapable data, automatic escaping of data that needs to be escaped, and filtering out data that does not need to be escaped, thus reducing some steps. Then, by comparison and matching, it is determined whether the received data is the set frame start, and whether the data is allowed to be received. Only after the frame start data is confirmed to be received will subsequent data be received. Otherwise, the received data is continuously compared with the frame start data, and the frame start is used to determine whether to start receiving data.

[0010] Optionally, after determining that the frame start data is yes, the method further includes: The receiving state machine performs a detection and judgment B on the received protocol frame data of subsequent bits. The detection and judgment B includes checking whether the received protocol frame data is frame ID data. If it is, it compares whether the frame ID data matches the set frame ID data. If it is, it stores the received frame ID data into a temporary buffer according to the corresponding number of bits. The receiving state machine then receives the next bit of protocol frame data. If it does not match the set frame ID data, it sets an error code to indicate a frame ID error, ends the reception of the current bit of protocol frame data, and performs a frame start judgment A on the next bit of protocol frame data.

[0011] By adopting the above technical solution, the received frame ID data is compared and matched with the set frame ID data to determine whether the data is allowed to be received. If they match, the received data is stored in a temporary buffer, which reduces the probability of receiving erroneous data.

[0012] Optionally, after determining that the frame start data is yes, the method further includes: The receiving state machine performs a detection and judgment B on the received protocol frame data of subsequent bits. Detection and judgment B also includes checking whether the received protocol frame data is of the correct length. If it is, it compares the received frame length data with the set frame length data. If it is, it stores the received frame length data into a temporary buffer according to the corresponding number of bits. The receiving state machine then receives the next bit of protocol frame data. If the frame length data does not match the set frame length data, an error code is set to indicate a frame length error, the reception of the current bit of protocol frame data ends, and a frame start judgment A is performed on the next bit of protocol frame data.

[0013] By adopting the above technical solution, the frame length of the data is compared and matched with the set frame length data to determine whether the frame length of the data is correct. This reduces the probability that the frame ID is correct but the number of bits of the protocol frame data is lost during transmission, confirms that the frame length data of the protocol frame data in the data transmission buffer matches, and further reduces the probability of receiving erroneous data.

[0014] Optionally, after determining that the frame start data is yes, the method further includes: The receiving state machine performs a detection and judgment B on the subsequent bits of protocol frame data received. Detection and judgment B also includes checking whether the received protocol frame data is frame check data based on the number of bits. If it is, the frame check data is calculated using the transmitted normal data, and the calculated frame check data is compared with the received frame check data. If they match, the protocol frame data in the temporary buffer is copied to the receiving buffer for use by the upper layer, and the current receiving task is terminated. If the comparison between the calculated frame check data and the received frame check data does not match, an error code frame check error is set, the reception of the current bit of protocol frame data is terminated, and a frame start judgment A is performed on the next bit of protocol frame data received. If the frame ID, frame length, and frame checksum are all negative, then the protocol frame data is normal and will be stored in a temporary buffer.

[0015] By adopting the above technical solution, after receiving normal data, the receiving state machine calculates the frame check data of the received protocol frame data by combining the received normal data with the frame ID data. At the same time, the transmitting state machine calculates the frame check data of the normal data of the protocol frame data in the data transmission buffer and outputs it. After receiving the frame check data, the receiving state machine compares and matches it with the frame check data it has calculated to make a judgment on the frame check data. This realizes the judgment of normal data, reduces the probability of errors in the transmission and reception process due to frame ID data matching but normal data errors, such as data loss or process judgment errors, and further improves the stability of the system and further reduces the probability of receiving erroneous data.

[0016] Optionally, after receiving the protocol frame data, the step of determining whether the protocol frame data has an escape flag further includes: If the condition is met, check if the received protocol frame data is an escape character. If the condition is met, set the escape flag. If the condition is not met, check if the frame start data has passed the check. If the frame start data has not passed the check, perform frame start check A on the protocol frame data.

[0017] By adopting the above technical solution, when the escaping is judged by the escape flag and the escape character, if there is no escape flag but it is an escape character, it means that the next data needs to be escaped, so the escape flag is set. If both the escape flag and the escape character are judged as no, it means that it is normal data that does not need to be escaped, and the data is judged and classified.

[0018] Optionally, after removing the escape flag, the method further includes: Determine whether the received protocol frame data is an escape character. If it is, set the protocol frame data as an escape character. After escaping the protocol frame data, the receiving state machine will check and judge the protocol frame data (B). Determine whether the received protocol frame data is empty data escaped. If so, perform a frame start determination A on the protocol frame data. If the protocol frame data is found to be no when checking the start of the frame escape, the escape character escape, or the empty data escape, then an error code is set to indicate a frame format error, and the protocol frame data is checked for the start of the frame (A).

[0019] By adopting the above technical solution, the specific escape type of the data that needs to be escaped is determined, and the specific classification and judgment of the data are realized. The automatic processing of different data escaping situations is realized, which is more refined. Furthermore, various cases of erroneous data are identified and prompted, so that staff can make targeted adjustments to the data and reduce the need for staff to search for the source of the error without any clue.

[0020] Optionally, the main communication task acquiring requests under the current priority includes: The priority includes several sub-priority counters. The main communication task iterates through all the sub-priority counters under the current priority to see if there is a corresponding request. If yes, the corresponding protocol frame data under the corresponding sub-priority counter is copied to the data sending buffer to be sent, the current main communication task ends, and after delaying the time data corresponding to the time data in the request loop time, the main communication task is triggered again to iterate through and check if there is a corresponding request in the subsequent sub-priority counters under the current priority. If the current priority's sub-priority counters are all negative (meaning there are no sub-priority requests for the current priority), then read and iterate through all sub-priorities under the next priority, and check if there are corresponding requests for each sub-priority. If yes, copy the corresponding protocol frame data under the corresponding sub-priority counter to the data sending buffer to be sent, end the current main communication task, and after delaying the time data corresponding to the request loop time, the main communication task is triggered again, iterating through and checking if there are corresponding requests for subsequent sub-priority counters under this priority.

[0021] By adopting the above technical solution, the current cycle task will not end when there is no corresponding request under the sub-priority counter. Instead, it will directly traverse and return to determine whether there is a corresponding request under the subsequent sub-priority counters of the current priority. If there is no corresponding request under all sub-priorities of the current priority, the current cycle task will not end. Instead, it will traverse and determine whether there is a corresponding request under all sub-priority counters of the next priority. The traversal of the priority and sub-priority counters greatly shortens the process cycle. Since the data transmission buffer is not stored because the traversal has not ended, the sending state machine does not actually process the protocol frame data during this process, making the sending state machine idle. Therefore, it immediately returns to the process to immediately determine the corresponding request of the next sub-priority counter, shortening the idle time of the sending state machine and keeping it in the best working state for a long time.

[0022] Optionally, before the main communication task obtains the request with the current priority, it further includes: Reset the current priority counter, and then set the current priority and its sub-priority counters as the starting point for traversal.

[0023] By adopting the above technical solution, when a higher priority request is received, after processing the current request, the reading of the request corresponding to the next sub-priority counter will be paused first, and the higher priority request will be processed first, which facilitates the handling of urgent requests.

[0024] A system includes a memory and a processor, wherein the memory stores a computer program for a multi-frame communication method that can be loaded and executed by the processor to reduce software load.

[0025] By adopting the above technical solution, the program is run by the processor and stored by the memory.

[0026] In summary, this application includes at least one of the following beneficial technical effects: 1. This ensures that the transmitting state machine continuously maintains its optimal operating state when transmitting data, preventing the transmitting state machine from continuously operating at maximum power when multiple requests are received simultaneously. This avoids factors such as excessive chip load and temperature rise, which would affect system stability and subsequent work efficiency. This improves system stability while also ensuring work efficiency.

[0027] 2. It reduces the probability of receiving erroneous data. Attached Figure Description

[0028] Figure 1 This is a flowchart of a multi-frame communication method for reducing software load rate in Embodiment 1 of this application.

[0029] Figure 2This is a flowchart of a periodic task with priority determination.

[0030] Figure 3 This is a flowchart of the state machine's workflow.

[0031] Figure 4 This is a flowchart for escape judgment.

[0032] Figure 5 This is a flowchart of receiving state machine storage protocol frame data. Detailed Implementation

[0033] The following is in conjunction with the appendix Figure 1-5 This application will be described in further detail.

[0034] This application discloses a multi-frame communication method and system for reducing software load. (Refer to...) Figure 1 The multi-frame communication method for reducing software load includes steps S1 to S43. Both the master and slave devices include a transmitting state machine and a receiving state machine.

[0035] Reference Figure 1 Step S1: Set the request loop time, send / receive loop time, frame start data, frame ID data, and frame length data.

[0036] Reference Figure 1 The staff sets the request loop time, transmit and receive loop time, frame start data, frame ID data, and frame length data in advance. In the subsequent process, the sending state machine and the receiving state machine obtain the set data as needed.

[0037] The protocol frame data includes frame start data, frame ID data, frame length data, and frame normal data. The normal data is the data to be transmitted. The frame check data can be calculated from the normal data. The frame check data, frame start data, frame ID data, and frame length data are all used to determine whether the protocol frame data is correct.

[0038] Reference Figure 1 Step S11: Reset the current priority counter and set the current sub-priority counter as the starting point for traversing the sub-priority counters under the corresponding priority.

[0039] Reference Figure 1The priority traversal order is from high priority to low priority, and the sub-priority traversal order is also from high priority to low priority. The current priority counter is reset in each cycle to facilitate the access of higher priority requests. However, the sub-priority counter is not reset. This is convenient when there are no higher priority requests to access. When the priority traversal reaches the corresponding request with a sub-priority counter, the sub-priority counter traversal can directly start from the next sub-priority counter read in the previous cycle, reducing the number of sub-priority counter traversals.

[0040] For example: Given current priorities A and B, with sub-priority counters A1, A2, and A3 under priority A, and B1, B2, and B3 under priority B, when the process reaches B1 and sends the corresponding request, ending the current cycle task and restarting the main communication task, the process resets and restarts from the A priority counter. If a new A priority counter request is inserted, the request corresponding to the A priority counter will be processed first, and then the process will restart. If no higher priority counter request is received, the current priority counter is reset and the process restarts from priority A. If no request exists in the sub-priority counters of priority A, the process moves to the B priority counter, checks for a request, and then begins traversing the sub-priority counters, starting directly from B2.

[0041] Reference Figure 1 Step S12: Send the state machine to determine whether there is a corresponding request under the current priority sub-priority counter and obtain the request loop time.

[0042] Reference Figure 1 and Figure 2 For example, the sending state machine first determines whether a corresponding request exists in A1 and obtains the request loop time data set by the staff.

[0043] Reference Figure 1 Step S13: Check if there is a corresponding request in the sub-priority counters under the current priority. If all are negative, then proceed to the next priority and return to step S12. In this embodiment, the main communication task involves two traversals: traversing the priority and traversing the sub-priority counters. The priority of traversing the sub-priority counters is higher than the priority of traversing the priority. That is, if there are untraversed sub-priority counters under the priority, then the traversal of the sub-priority counters is executed first. After the sub-priority counters are traversed, the priority is traversed again. After traversing to a new priority, if there are sub-priority counters under the priority, then the traversal of the sub-priority counters is executed again with priority.

[0044] Reference Figure 1 and Figure 2 For example: After all requests corresponding to A1, A2, and A3 have been processed, there will be no requests corresponding to the sub-priority counters under priority A. At this time, the counter of the current priority A will be incremented by 1, and priority B will be read. It will be determined whether priority B exists. If priority B exists, it is determined that the priority traversal has not ended. At this time, the sub-priority counters B1, B2, and B3 under priority B will be read. The process will return to determining whether the current sub-priority counter B1 under the current priority B has a corresponding request. If priority B does not exist, it is determined that the priority traversal has ended, and the cycle task ends. If the staff sets the request loop time to 10ms, the loop will start again 10ms after the current cycle task ends.

[0045] Reference Figure 1 Step S2: If the condition is met, copy the corresponding protocol frame data under the corresponding sub-priority counter to the data sending buffer to be sent. Then, after delaying the time data in the request loop time, continue to traverse and judge the requests corresponding to the subsequent sub-priority counters under the current priority (i.e., return to step S11).

[0046] Reference Figure 1 and Figure 2 For example: after determining that there is a corresponding request under sub-priority counter B1, the sending state machine copies the corresponding protocol frame data to the data sending buffer to be sent. Then, the sub-priority counter under the current priority B is incremented by 1 to facilitate the next reading of sub-priority counter B2, the current cycle task ends, and the cycle task starts again after 10ms.

[0047] Reference Figure 2Within a cycle of a communication main task's cyclical call, the current priority counter is first reset, and the current priority is set as the starting point for traversal. The current sub-priority counter is also set as the starting point for traversing the sub-priority counters under the corresponding priority. Then, it checks if a corresponding request exists for the current sub-priority under the current priority. If yes, the corresponding protocol frame data is copied to the data sending buffer for transmission, and the current cycle task ends, waiting for the next cycle task to begin. If a corresponding request exists for the current sub-priority under the current priority, the sub-priority counter is incremented by 1, preparing to check for requests from the next sub-priority counter. Then, it checks if the current priority traversal has ended. If no, it returns to the step of checking if a corresponding request exists for the current sub-priority under the current priority. If the current priority traversal has ended, the current priority counter is incremented by 1, preparing to check the next priority counter. If the current priority traversal has ended, it returns to the step of setting the current sub-priority counter as the starting point for traversing the sub-priority counters under the corresponding priority. Finally, if the current priority traversal has ended, the current cycle task ends, waiting for the next cycle task to begin.

[0048] Reference Figure 1 S21. The send / receive task obtains the send / receive cycle time. The send state machine sends the protocol frame data in the data send buffer in sequence according to the number of bits. The interval between sending adjacent bits of data is determined by the time data in the send / receive cycle time.

[0049] Reference Figure 1 and Figure 3 After the periodic task begins, it checks if the current sending state machine is in the Tx_Idle (idle state). If so, it sends idle data to the receiving state machine. It then checks if there is ready-made protocol frame data in the data sending buffer. If so, it sets the sending state machine to Tx_data and sets the data index to 0. Next, it calls the communication driver interface to send the idle data to the other network node, i.e., the receiving state machine. After the receiving state machine finishes receiving the data, the current periodic task ends. If the operator has pre-set the transmit / receive loop time to 2ms, the next periodic task begins after 2ms. Operators can adjust the transmit / receive loop time according to the software load. If the load is low, the transmit / receive loop time can be increased to improve data processing speed; if the load is high, the transmit / receive loop time can be decreased to reduce the load.

[0050] Reference Figure 1 and Figure 3If the current sending state machine is not Tx_Idle, then the sending data is set to the protocol frame data corresponding to the current sending data index and the sending data index is incremented by 1. The sending data index is compared with the protocol frame length data to determine whether the protocol frame data has been sent. If the sending is completed, the sending state machine is set to Tx_Idle. If the sending is not completed, the data continues to be sent, and then the communication driver interface is called to send out the protocol frame data.

[0051] Reference Figure 1 and Figure 3 For example: If it is the first cycle of the periodic task corresponding to sub-priority counter B1, and the number of bits of the protocol frame data corresponding to sub-priority counter B1 is greater than 6 bits, the sending state machine is Tx_Idle, the sending data is set to idle data, the protocol frame data in the data sending buffer is ready, the sending state machine is set to Tx_data, and the sending data index is set to 0, and the communication driver interface is called to send the idle data.

[0052] Reference Figure 1 and Figure 3 If it is the second cycle of the periodic task corresponding to sub-priority B1, the state machine is Tx_data. At this time, the data transmission index is 0. Then, the protocol frame data of the 0th bit is set as the data to be transmitted, and the data transmission index is increased by 1 to become 1. At this time, the data transmission index is less than the protocol frame length, so the communication driver interface is directly called to transmit the data.

[0053] Reference Figure 1 Step S3: After receiving the protocol frame data, the receiving state machine determines whether the protocol frame data has an escape flag.

[0054] Reference Figure 1 and Figure 4 The receiver state machine determines whether the escape flag is TRUE after receiving the protocol frame data (escaping special data).

[0055] Reference Figure 1 Step S31: If the condition is true, remove the escape flag.

[0056] Reference Figure 1 and Figure 4 If the protocol frame data received by the receiving state machine needs to be escaped, the escape flag is removed first, and the transfer flag is set to FALSE.

[0057] Reference Figure 1 Step S311: Determine whether it is a frame start escape. If so, compare the received protocol frame data to perform frame start determination A. In this embodiment, frame start determination A is to determine whether the protocol frame data matches the set frame start data.

[0058] Reference Figure 4 and Figure 5 The process involves checking whether a frame start escape sequence (e.g., 7Fh) has been received. If so, the frame start flag is set, and the receiver state is set to Rx_Idle. Then, the receiver state machine is checked to see if it is Rx_Idle. If so, the received data is checked to see if it is frame start data. If so, the frame start flag is cleared, the received data index is set to 0, the receiver state machine is set to Rx_Data, and the protocol frame data in the temporary buffer is cleared. The current cycle task ends, and the cycle task restarts after 2ms. If not, the current cycle task ends, and the cycle task restarts after 2ms.

[0059] Reference Figure 4 and Figure 5 For example: if the sent data is the start of a frame, the start of frame escape is determined to be yes. After setting the start of frame flag, the receive state machine is set to Rx_Idle. After determining whether the receive state machine is Rx_Idle, and whether the received data is the start of a frame, the set start of frame flag is cleared, the received data index is set to 0, and the receive state machine is set to Rx_Data. The main purpose of this step is to change the receive state machine from Rx_Idle to Rx_Data, that is, to start receiving subsequent data after receiving the start of a frame.

[0060] Reference Figure 1 Step S312: Determine whether the received protocol frame data is escaped. If so, set the protocol frame data as an escape character. After escaping the protocol frame data, the receiving state machine performs detection and judgment B on the protocol frame data. In this embodiment, detection and judgment B involves determining the position of the received protocol frame data based on the data index, and then matching this position of the protocol frame data with the corresponding set frame ID data, frame length data, or frame check data.

[0061] Reference Figure 4 If the frame start escape is not received, check if an escape character is received. If yes, set the data to the escape character (e.g., 7Dh).

[0062] Reference Figure 4 and Figure 5For example: Data that needs to be escaped with an escape character is special data, usually normal data. If the data being sent is normal data that needs to be escaped, the escape character will be received first. If it is true, the data will be set as the escape character and escaped. If the receiving state machine is Rx_Idle, it will be determined that it is not (the receiving state machine has been changed to Rx_Data in the frame start step). If the receiving state machine is Rx_Data, it will be determined that it is true. The normal received data will be stored in the temporary buffer, the received data index will be incremented by 1, the current cycle task will end, and the cycle task will start again after 2ms.

[0063] Reference Figure 1 S313. Determine whether the received protocol frame data is empty data escaped. If so, perform frame start judgment A on the protocol frame data and wait to match the frame start of the next frame.

[0064] Reference Figure 4 If the frame start escape is not received and the escape character is not received, then check if empty data escape (such as DFh) is received. If yes, set the receiver state machine to Rx_Idle.

[0065] Reference Figure 4 and Figure 5 For example, if an empty data escape is received, it means that the sending state machine is in an idle state or has mistakenly sent idle data. The receiving state machine is changed from Rx_Data to Rx_Idle, so that when the receiving state machine is Rx_Idle in the subsequent judgment, it will be Rx_Idle. Then the frame start judgment step is entered until the frame start data of the next protocol frame is received and normal data reception begins.

[0066] Reference Figure 1 In step S314, if the protocol frame data is determined to be no frame start escaping, no escape character escaping, and no empty data escaping, then an error code is set to indicate a frame format error, and the protocol frame data is judged to be no frame start A, and the frame start of the next frame is waited to be matched.

[0067] Reference Figure 4 and Figure 5 If the frame start escape is not received, the escape character escape is not received, and the empty data escape is not received, it usually means that erroneous data has occurred. In this case, the error code "Frame format error" is set, and the receiver state is set to Rx_Idle. This will ensure that subsequent checks on whether the receiver state machine is Rx_Idle will be performed as "yes". Then, the frame start judgment step will continue until the frame start data of the next protocol frame is received, and normal data reception will begin.

[0068] Reference Figure 1Step S32: If the escape flag is not checked, then check whether the received protocol frame data is an escape character. If it is checked, it means that the data needs to be escaped, so the escape flag is set. If it is checked, then check whether the frame start data has been checked. If the frame start data has not been checked, then perform frame start check A on the protocol frame data.

[0069] Reference Figure 4 and Figure 5 If the escape flag is TRUE, then check if it is an escape character (e.g., 7Dh). If it is, set the escape flag to TRUE. Otherwise, check if the receiving state machine is Rx_Idle.

[0070] Reference Figure 4 and Figure 5 For example: if the normal data in the previous protocol frame is unescaped data, and the normal data in the next frame is data that needs to be escaped, then the preceding normal data that needs to be escaped is usually an escape character. In this case, during the escape character loop, the system first checks if the escape flag is TRUE. If it is TRUE, it checks if the escape character is TRUE. If it is TRUE, then the escape character flag is TRUE. Then the next normal data is sent, and the system checks if the escape flag is TRUE. If it is TRUE, then the system enters the escaping step.

[0071] Reference Figure 4 and Figure 5 If the transmitted data is normal data that does not require escaping, then the system checks whether the escape flag is TRUE or not, and whether it is an escape character. This leads to the determination of whether the receiver state machine is Rx_Idle.

[0072] Reference Figure 1 Step S321: If the condition is not met, continue to perform frame start judgment A after the receiving state machine receives the next bit of protocol frame data.

[0073] Reference Figure 5 The system determines whether the received data is the start of a frame. If it is not, the state of the receiving state machine is not changed, and the receiving state machine remains in Rx_Idle (idle state). The next protocol frame data sent will still be checked for the start of a frame until the start of a frame is received, and then the data will be received and subsequent checks will be performed.

[0074] Reference Figure 1In step S4, if the judgment is yes, the receiving state machine will detect and judge the subsequent bits of protocol frame data received by B. It will detect the number of bits of the received protocol frame data to determine whether it is frame ID data. If it is yes, it will compare and judge whether the frame ID data matches the set frame ID data. If it is yes, it will store the received frame ID data into the temporary buffer according to the corresponding number of bits. The receiving state machine will receive the next bit of protocol frame data and judge whether the frame ID data matches the set frame ID data. If it is no, it will set an error code to indicate that the frame ID is wrong, end the reception of the current bit of protocol frame data, and perform frame start judgment A on the next bit of protocol frame data received.

[0075] Reference Figure 5 After the frame start check passes, the receiver state machine is set to Rx_Data, and the received data index is set to 0. When the next protocol frame data arrives, the receiver state machine checks if it is Rx_Data. If so, it checks if the received data index corresponds to the frame ID data. Typically, a received data index of 0 corresponds to the frame ID data. If so, it checks if the received frame ID data matches the frame ID data set by the operator beforehand. If it does, the received frame ID data is stored in a temporary buffer, and the received data index is incremented by 1, making it 1, thus ending the current cycle task. If the frame ID matching check fails, an error code "Frame ID Error" is set to notify the operator, the receiver state machine is set to Rx_Idle, the current cycle task ends, and subsequent frame protocol data undergoes a new frame start check. After the current cycle task ends, the cycle task restarts after 2ms.

[0076] Reference Figure 1 Step S41: Detect the number of bits in the received protocol frame data to determine if it is frame length data. If it is, compare the frame length data to see if it matches the set frame length data. If it is, store the received frame length data into a temporary buffer according to the corresponding number of bits. The receiving state machine receives the next bit of protocol frame data. If the frame length data does not match the set frame length data, set an error code to indicate a frame length error, end the reception of the current bit of protocol frame data, and perform frame start judgment A on the next bit of protocol frame data.

[0077] Reference Figure 5After the frame ID check passes, the next bit of protocol frame data is received. Since the received data index changes from 0 to 1 during frame ID check, the system checks whether the received data index matches the frame ID (if yes), and whether it matches the frame length (if yes). Then, it checks if the frame length matches the pre-set frame length. If yes, the received frame length is stored in a temporary buffer, and the received data index is incremented by 1 to 2. The frame length in the temporary buffer is then placed after the frame ID, ending the current task cycle. If the frame length does not match, an error code "frame length error" is set to notify the operator, and the receive state machine is set to Rx_Idle, causing subsequent frame protocol data to undergo frame start checks again, ending the current task cycle. The current task cycle restarts after 2ms after the current cycle ends.

[0078] Reference Figure 1 Step S42: Detect the number of bits in the received protocol frame data to determine if it is frame check data. If it is, calculate the frame check data using the sent normal data and compare the calculated frame check data with the set frame check data. If they match, copy the protocol frame data in the temporary buffer to the receive buffer for the upper layer to call, and end the current receiving task. If the calculated frame check data does not match the set C frame check data, set the error code frame check error, end the reception of the current number of bits of protocol frame data, and perform frame start judgment A for the next bit of protocol frame data.

[0079] Reference Figure 1 In step S43, if the frame ID data, frame length data, and frame check data are all negative, it indicates that the frame data is normal, and the protocol frame data is stored in a temporary buffer.

[0080] Reference Figure 5 When receiving protocol frame data following the frame length data, first determine whether it is frame verification based on the received data index. If the determination is no, it means that it is normal frame data. Store the normal received data in a temporary buffer, increment the received data index by 1, end the current cycle task, and start the cycle task again after 2ms.

[0081] Reference Figure 5If the received protocol frame data is the last bit, the system checks if it's a frame checksum based on the received data index. If so, it calculates the frame checksum data using the previously received frame ID data and normal data. It then checks if the calculated frame checksum data matches the received frame checksum. If it matches, all protocol frame data in the temporary buffer is copied to the receive buffer for upper-layer use, and the receive state machine is set to Rx_Idle, ending the current cycle task. If the frame checksum doesn't match, an error code "Frame Checksum Error" is set to notify the operator, the receive state machine is set to Rx_Idle, and the current cycle task ends. The cycle task restarts 2ms after its end.

[0082] Reference Figure 5 For example, when a normal data bit following the frame length data is received, since the received data index changed from 1 to 2 during the frame length determination and has not yet been added to the last bit, the received data index is less than the received data index corresponding to the last bit of data. Therefore, the frame check determination is negative. This normal data is stored in a temporary buffer, and the received data index is incremented by 1 to become 3. This process is repeated until the received data index is added to the received data index corresponding to the last bit of data. The last bit of data sent by the sending state machine is the frame check data calculated by the sending state machine based on the previously sent normal data. At this time, the received data index is equal to the received data index corresponding to the last bit of data, so the frame check determination is positive. Then, the received normal data is calculated to obtain the frame check data, and the calculated frame check data is compared and matched with the received frame check data. If the match is found, it means that the protocol frame data reception is complete. The receiving state machine is then set to Rx_Idle and the current cycle task ends.

[0083] All error codes (including frame ID errors, frame length errors, frame check errors, and frame format errors) can be reported to staff.

[0084] The implementation principle of a multi-frame communication method for reducing software load rate according to an embodiment of this application is as follows: When there are multiple requests, the main communication task classifies the requests according to their priority, forming a priority and a sub-priority. The main communication task performs periodic detection on the requests under the priority according to the request cycle time, and then copies the request data to the sending buffer according to the priority for the sending state machine to send. The sending state machine sends the protocol frame data according to the sending and receiving cycle time.

[0085] A system includes a memory and a processor, wherein the memory stores a computer program for a multi-frame communication method that reduces software load and can be loaded and executed by the processor.

[0086] Processors can include CPUs or MPUs, or master / slave systems built around CPUs or MPUs, encompassing both hardware and software. Once master and slave devices have processors, users can program them to operate according to their desired behavior. Processors can control local data transfer / traceability components, remote data transfer / traceability components, and remote communication components through internal protocols. Internal protocols broadly refer to all protocols that enable communication or linking within the same master or slave device or the same system, including: human-machine interface protocols, software / hardware (interface) protocols, chip bus (C-Bus) protocols, internal bus (I-Bus) protocols, etc. With the development of integrated circuit technology, some protocols that belong to external bus (E-Bus) have also been integrated into the chip and are now considered internal protocols.

[0087] It also includes a database for storing data, which is stored in the memory. The database contains frame start data, frame ID data, frame length data, frame checksum data, frame normal data, etc. In this embodiment, the frame checksum data includes checksum, CRC, etc.

[0088] Storage devices include various media that can store program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0089] The memory can store parameters and algorithms that need to be modified or corrected after the host and slave have gone through processes such as verification, self-calibration, self-test, verification, and calibration, so that subsequent programs can call them at any time. It can also store data generated by the local measurement / traceability component when it is working normally, as well as data on the local measurement / traceability component's measurement / traceability of external devices.

[0090] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application.

Claims

1. A multi-frame communication method for reducing software load, characterized in that, include: Set the request loop time and send / receive loop time; The main communication task is triggered periodically to obtain requests under the current priority, copy the corresponding protocol frame data to the data sending buffer to be sent, obtain the request loop time, and obtain the next priority request based on the time data in the request loop time to perform the loop of the main communication task. The send and receive task is triggered periodically. The send state machine obtains the send and receive cycle time. The send state machine sends the protocol frame data in the data send buffer in order of bit length. The interval between sending adjacent bits of data is determined by the time data in the send and receive cycle time. After receiving protocol frame data, the receiving state machine will store the protocol frame data in the receiving buffer according to the receiving order for use by the upper layer. The main communication task obtains requests under the current priority, including: The priority includes several sub-priority counters. The main communication task iterates through all the sub-priority counters under the current priority to see if there is a corresponding request. If yes, the corresponding protocol frame data under the corresponding sub-priority counter is copied to the data sending buffer to be sent, the current main communication task ends, and after delaying the time data corresponding to the time data in the request loop time, the main communication task is triggered again to iterate through and check if there is a corresponding request in the subsequent sub-priority counters under the current priority. If the corresponding request exists in the sub-priority counters under the current priority, check if the priority traversal is complete. If not, check if the priority traversal is complete. If not, traverse all sub-priorities under the next priority and check if the corresponding request exists in the sub-priority. If yes, copy the corresponding protocol frame data under the corresponding sub-priority counter to the data sending buffer to be sent, end the current main communication task, and then delay the time corresponding to the time data in the request loop time. The main communication task is triggered again, and the traversal is checked to see if the corresponding request exists in the subsequent sub-priority counters under this priority. After the periodic task starts, it checks whether the current sending state machine is Tx_Idle. If so, it sends idle data to the receiving state machine. It checks whether there is prepared protocol frame data in the data sending buffer. If so, it sets the sending state machine to Tx_data and sets the data index to 0. Then, it calls the communication driver interface to send idle data to the other network node, i.e. the receiving state machine. After the receiving state machine finishes receiving, the current periodic task ends.

2. The multi-frame communication method for reducing software load rate according to claim 1, characterized in that, After setting the request loop time and the send / receive loop time, it also includes: Set the frame start data, frame ID data, and frame length data; After receiving the protocol frame data, the receiving state machine also includes: After receiving protocol frame data, it is determined whether the protocol frame data has an escape flag. If it is, the escape flag is removed and it is determined whether it is a frame start escape. If the frame start escape is determined, the received protocol frame data is subjected to frame start judgment A. Frame start judgment A is to determine whether the protocol frame data matches the set frame start data. If the frame start escape is determined, the escape data other than the frame start data is escaped.

3. The multi-frame communication method for reducing software load rate according to claim 2, characterized in that, After determining that the frame start data is yes, the following is also included: The receiving state machine performs a detection and judgment B on the received protocol frame data of subsequent bits. The detection and judgment B includes checking whether the received protocol frame data is frame ID data. If it is, it compares whether the frame ID data matches the set frame ID data. If it is, it stores the received frame ID data into a temporary buffer according to the corresponding number of bits. The receiving state machine then receives the next bit of protocol frame data. If it does not match the set frame ID data, it sets an error code to indicate a frame ID error, ends the reception of the current bit of protocol frame data, and performs a frame start judgment A on the next bit of protocol frame data.

4. The multi-frame communication method for reducing software load rate according to claim 3, characterized in that, After determining that the frame start data is yes, the following is also included: The receiving state machine performs a detection and judgment B on the received protocol frame data of subsequent bits. Detection and judgment B also includes checking whether the received protocol frame data is of the correct length. If it is, it compares the received frame length data with the set frame length data. If it is, it stores the received frame length data into a temporary buffer according to the corresponding number of bits. The receiving state machine then receives the next bit of protocol frame data. If the frame length data does not match the set frame length data, an error code is set to indicate a frame length error, the reception of the current bit of protocol frame data ends, and a frame start judgment A is performed on the next bit of protocol frame data.

5. The multi-frame communication method for reducing software load rate according to claim 4, characterized in that, After determining that the frame start data is yes, the following is also included: The receiving state machine performs a detection and judgment B on the subsequent bits of protocol frame data received. Detection and judgment B also includes checking whether the received protocol frame data is frame check data based on the number of bits. If it is, the frame check data is calculated using the transmitted normal data, and the calculated frame check data is compared with the received frame check data. If they match, the protocol frame data in the temporary buffer is copied to the receiving buffer for use by the upper layer, and the current receiving task is terminated. If the comparison between the calculated frame check data and the received frame check data does not match, an error code frame check error is set, the reception of the current bit of protocol frame data is terminated, and a frame start judgment A is performed on the next bit of protocol frame data received. If the frame ID data, frame length data, and frame check data are all negative, then the protocol frame data is normal data and the protocol frame data is stored in a temporary buffer.

6. The multi-frame communication method for reducing software load rate according to claim 2, characterized in that: After receiving protocol frame data, determining whether the protocol frame data has an escape flag also includes: If the condition is met, check if the received protocol frame data is an escape character. If the condition is met, set the escape flag. If the condition is not met, check if the frame start data has passed the check. If the frame start data has not passed the check, perform frame start check A on the protocol frame data.

7. The multi-frame communication method for reducing software load rate according to claim 2, characterized in that: The process of removing escape symbols also includes: Determine whether the received protocol frame data is an escape character. If it is, set the protocol frame data as an escape character. After escaping the protocol frame data, the receiving state machine will check and judge the protocol frame data. Determine whether the received protocol frame data is empty data escaped. If so, perform frame start determination A on the protocol frame data. If the protocol frame data is found to be no when checking the start of the frame escape, the escape character escape, or the empty data escape, then an error code is set to indicate a frame format error, and the protocol frame data is checked for the start of the frame (A).

8. The multi-frame communication method for reducing software load rate according to claim 1, characterized in that: Before the main communication task obtains the request with the current priority, it also includes: Reset the current priority counter, and then set the current priority and its sub-priority counters as the starting point for traversal.

9. A system, characterized in that: It includes a memory and a processor, wherein the memory stores a computer program for a multi-frame communication method for reducing software load as described in any one of claims 1 to 8, which can be loaded and executed by the processor.

Citation Information

Patent Citations

  • Identifier distribution method of sensor network CAN bus frame format

    CN105119793A

  • Reliable polling communication method of power line carrier

    CN108667486A