Serial port data analysis method and system

CN116185927BActive Publication Date: 2026-09-22HUNAN ECONOVEL TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211581632.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-09
Publication Date
2026-09-22
Estimated Expiration
2042-12-09

AI Technical Summary

Technical Problem

然而不同的串口通讯协议导致串口数据的解析方式存在较大差异,导致串口缓存的设计相对困难,缓存设计差异性很大,没有形成一种较为通用的数据解析框架

Benefits of technology

[0036]本发明设计了串口数据接收步骤,串口数据查找步骤,串口数据帧识别步骤共三个部分,其中串口数据接收步骤将串口接收的字节数据存入循环队列,串口数据查找步骤从二级缓存中查找新增串口数据,并通过串口数据帧识别步骤进行新增串口数据的解析,从而将串口接收和串口解析的过程进行分隔,增加了串口解析的适用性,在单核多串口、多核多串口等实时性高的情况下都能适用。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116185927B_ABST
    Figure CN116185927B_ABST
Patent Text Reader

Abstract

The application discloses a serial port data analysis method and system, and the method comprises the following steps: a serial port data receiving step: obtaining serial port data from a serial port, and storing the serial port data into a first cyclic queue corresponding to the serial port according to a serial port ID; a serial port data searching step: calculating newly added serial port data in the first cyclic queue, storing the newly added serial port data into a second cache, and searching serial port data stored in the second cache; and a serial port data frame identification step: identifying a frame header and a frame tail of serial port data in the second cache, and analyzing data between the frame header and the frame tail according to a preset serial port protocol. The application improves the real-time performance and correctness of serial port analysis and expands the application range of serial port analysis under the condition of ensuring the generality of the serial port analysis method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to serial communication technology, and more particularly to a serial data parsing method and system. Background Technology

[0002] Currently, when defining serial port protocol messages, a data frame header is typically added before the valid serial port data content, and a data frame trailer or data checksum is added after the valid serial port data content. This requires the receiving end of the serial port data to parse the received serial port data, that is, to find the data frame header and data frame trailer from the received serial port data, then buffer the data segment from the data frame header to the data frame trailer, and finally parse each frame of valid serial port data in the data segment according to the communication protocol. However, different serial port communication protocols lead to significant differences in the way serial port data is parsed, making the design of serial port buffers relatively difficult, resulting in large differences in buffer design and the lack of a universal data parsing framework.

[0003] For single-core multi-serial-port devices, parsing multiple serial ports is relatively complex and has high real-time requirements, requiring timely CPU response. For multi-core multi-serial-port devices, there are situations where other interfaces are used to simulate serial port functions. Especially when simulating multiple serial ports, if only one interface is used to receive data from multiple serial ports, the serial port speed will increase exponentially. In this case, serial port reception and serial port parsing are usually processed on different cores to distribute the system load. Summary of the Invention

[0004] The technical problem to be solved by this invention is: in view of the technical problems existing in the prior art, this invention provides a serial port data parsing system and parsing method, which improves the real-time performance and accuracy of serial port parsing and expands the scope of application of serial port parsing while ensuring universality.

[0005] To solve the above-mentioned technical problems, the technical solution proposed by this invention is as follows:

[0006] A serial port data parsing method includes the following steps:

[0007] Serial port data receiving steps: Obtain serial port data from the serial port and store the serial port data into the first-level circular queue corresponding to the serial port according to the serial port ID;

[0008] Serial port data lookup steps: Calculate the newly added serial port data in the first-level circular queue, store the newly added serial port data in the second-level cache, and then search for the serial port data stored in the second-level cache.

[0009] Serial port data frame identification steps: Identify the frame header and frame tail of the serial port data in the secondary buffer, and parse the data between the frame header and frame tail according to the preset serial port protocol.

[0010] Furthermore, the following steps are included before acquiring serial port data:

[0011] Define a corresponding data receive buffer and a buffer count variable buffCnt for each serial port. The buffer count variable buffCnt shall not exceed the length of the corresponding data receive buffer.

[0012] Furthermore, the serial port data lookup process specifically includes the following steps:

[0013] Get the buffer count variable buffCnt and the first-level buffer count variable lastBuffCnt corresponding to the current first-level circular queue, and subtract the two to get the number of newly added serial port data curCnt. If the number of newly added serial port data curCnt is equal to zero, wait for a preset time, and then get the buffer count variable buffCnt and the first-level buffer count variable lastBuffCnt corresponding to the current first-level circular queue again, and subtract the two to get the number of newly added serial port data curCnt, until the number of newly added serial port data curCnt is greater than zero.

[0014] Starting from the beginning address pStartAddr of the data receive buffer corresponding to the current first-level circular queue, copy the serial port data of number curCnt to the second-level buffer frameBuff.

[0015] Furthermore, the serial port data frame identification process specifically includes the following steps:

[0016] Start searching for newly added serial port data from the starting address of the second-level cache frameBuff;

[0017] If the current byte is the frame header and the byte preceding the frame length byte after the current byte is the frame tail, then the data of a frame starting from the current byte is parsed according to the serial port protocol.

[0018] Select the next few bytes after the current byte as the new current byte, and continue to determine whether the current byte is the frame header and whether the byte before the next few bytes after the current byte is the frame tail, until all newly added serial port data has been found, and obtain the number of successfully parsed serial port data anaNum.

[0019] Furthermore, after sequentially searching for newly added serial port data starting from the starting address of the second-level cache frameBuff, the process also includes: if the current byte is not the frame header or the byte before the frame length bytes after the current byte is not the frame tail, the serial port parsing failure count value errCnt is incremented.

[0020] If the serial port parsing failure count value errCnt has not reached the set value, select the byte after the current byte as the new current byte, and continue to determine whether the current byte is the frame header and the byte before the frame length bytes after the current byte is the frame tail, until the new serial port data search is completed or the serial port parsing failure count value errCnt reaches the set value.

[0021] If the serial port parsing failure count value errCnt reaches the set value, the newly added serial port data is invalid data, and the secondary buffer is cleared.

[0022] Furthermore, the serial port data lookup step also includes: after the serial port data frame identification step is completed, if the number of successfully parsed serial port data anaNum is not 0, the first-level buffer count variable lastBuffCnt is added to the number of successfully parsed serial port data anaNum to obtain the updated first-level buffer count variable; the starting address pStartAddr of the data receiving buffer corresponding to the current first-level circular queue is added to the number of successfully parsed serial port data anaNum to obtain the updated starting address of the data receiving buffer corresponding to the current first-level circular queue; at the same time, the serial port parsing failure count value errCnt is cleared to zero, and the second-level buffer is cleared.

[0023] Furthermore, the serial port data lookup step also includes: after the serial port data frame identification step is completed, if the number of successfully parsed serial port data anaNum is 0, add the number of newly added serial port data curCnt to the first-level buffer count variable lastBuffCnt to obtain the updated first-level buffer count variable, and add the number of newly added serial port data curCnt to the starting address pStartAddr of the data receiving buffer corresponding to the current first-level circular queue to obtain the updated starting address of the data receiving buffer corresponding to the current first-level circular queue.

[0024] Furthermore, the steps for receiving serial data in a single-core, multi-serial-port device specifically include:

[0025] After receiving a serial port interrupt, the serial port data receiving steps are executed. The data received by each serial port is stored in the data receiving buffer corresponding to the first-level circular queue of each serial port according to the serial port ID, and the buffer count variable buffCnt corresponding to these data receiving buffers is incremented.

[0026] The serial port data search and serial port data frame identification steps are executed periodically to obtain the parsing results of the data received from each serial port.

[0027] Furthermore, the method includes a step of receiving serial data using a multi-core, multi-serial-port device, wherein the multi-core, multi-serial-port device includes an FPGA and a DSP, and the steps specifically include:

[0028] After the FPGA obtains data from multiple serial ports, it saves the corresponding serial port ID and data into memory and sends a serial port interrupt to the DSP through the SRIO interface.

[0029] After the DSP receives a serial port interrupt, the second core of the DSP executes the serial port data receiving steps. According to the serial port ID, it stores the serial port data into the data receiving buffer corresponding to the first-level circular queue of each serial port, and increments the buffer count variable buffCnt corresponding to these data receiving buffers.

[0030] The first core of the DSP executes the serial port data search step and the serial port data frame recognition step in a timer to obtain the parsing results of each serial port data.

[0031] This invention also proposes a serial port data parsing system, comprising:

[0032] The serial port data receiving module is used to acquire serial port data from the serial port and store the serial port data into the first-level circular queue corresponding to the serial port according to the serial port ID.

[0033] The serial port data lookup module is used to calculate the newly added serial port data in the first-level circular queue, store the newly added serial port data in the second-level cache, and then search for the serial port data stored in the second-level cache.

[0034] The serial port data frame identification module is used to identify the frame header and frame tail of the serial port data in the secondary buffer, and to parse the data between the frame header and frame tail according to the preset serial port protocol.

[0035] Compared with the prior art, the advantages of the present invention are as follows:

[0036] This invention designs three parts: a serial port data receiving step, a serial port data searching step, and a serial port data frame identification step. The serial port data receiving step stores the received byte data into a circular queue. The serial port data searching step searches for newly added serial port data from the secondary cache and parses the newly added serial port data through the serial port data frame identification step. This separates the serial port receiving and serial port parsing processes, increasing the applicability of serial port parsing. It can be applied to high real-time scenarios such as single-core multi-serial port and multi-core multi-serial port.

[0037] The serial port data frame identification step of the present invention only requires the frame header, frame tail and frame length to identify the serial port buffer data, without the need to modify the serial port search and identification code, thus improving the universality of serial port parsing. Attached Figure Description

[0038] Figure 1 This is a flowchart of an embodiment of the present invention.

[0039] Figure 2This is a flowchart of the serial port data search step and the serial port data frame identification step in an embodiment of the present invention.

[0040] Figure 3 This is a flowchart of serial port data reception according to Embodiment 1 of the present invention.

[0041] Figure 4 This is a flowchart of serial port data reception according to Embodiment 2 of the present invention. Detailed Implementation

[0042] The present invention will be further described below with reference to the accompanying drawings and specific preferred embodiments, but this does not limit the scope of protection of the present invention.

[0043] To improve the reliability and real-time performance of serial port parsing in complex scenarios such as multiple serial ports and multiple cores, and to ensure the versatility of serial port parsing in different scenarios. For example... Figure 1 As shown, we design a serial port data parsing method, which includes the following steps:

[0044] Serial port data receiving steps: Obtain serial port data from the serial port and store the serial port data into the first-level circular queue corresponding to the serial port according to the serial port ID;

[0045] Serial port data lookup steps: Calculate the newly added serial port data in the first-level circular queue, store the newly added serial port data in the second-level cache, and then search for the serial port data stored in the second-level cache.

[0046] Serial port data frame identification steps: Identify the frame header and frame tail of the serial port data in the secondary buffer, and parse the data between the frame header and frame tail according to the preset serial port protocol.

[0047] Through the above steps, this solution uses a two-level serial port buffer. The first-level buffer is used as a circular queue to store the byte data received from the serial port. The second-level buffer only takes newly added serial port data from the first-level buffer's circular queue and places it at the starting address of the second-level buffer. The purpose is to convert the circular queue into a regular queue, which facilitates frame breaking and frame identification in sequence according to the communication protocol. This essentially completely separates serial port reception and serial port parsing, increasing the applicability of serial port parsing. It can be applied in high-real-time situations such as multi-serial-port and multi-core environments.

[0048] Corresponding to the method, we also designed a serial port data parsing system, which includes the following modules:

[0049] 1. Serial port data receiving module

[0050] The serial port data receiving module is used to perform the serial port data receiving steps, storing the received byte data into a first-level circular queue. It is configured to perform the following steps:

[0051] A1. Define a different data receive buffer for each serial port;

[0052] B1. Define a buffer count variable `buffCnt` for each serial port to count the number of serial bytes currently received in the receive buffer. Since a circular queue is used, the buffer count variable `buffCnt` continuously increments, never exceeding the length of the receive buffer. The defined serial port data structure is shown below:

[0053] struct com_rx_buff_man

[0054] {

[0055] unsigned int buffCnt[COMM_NUM]; / * Serial port data receive buffer count * /

[0056] unsigned int lastBuffCnt[COMM_NUM]; / * Level 1 cache count * /

[0057] unsigned int errCnt[COMM_NUM]; / * Serial port parsing error count * /

[0058] unsigned char buff[COMM_NUM][BUFF_LEN]; / * Serial port primary circular queue buffer * /

[0059] unsigned char frameBuff[COMM_NUM][BUFF_LEN]; / * Serial port secondary buffer * /

[0060] };

[0061] Where COMM_NUM is the number of serial ports and BUFF_LEN is the number of bytes in the buffer;

[0062] C1. Receive serial port data. Through the serial port receive function, each received serial port byte data is stored in the corresponding data receive buffer according to the serial port ID. At the same time, the corresponding buffer count variable buffCnt is continuously incremented according to the number of received serial port bytes.

[0063] As can be seen from the above steps, the serial port data receiving module only performs the function of adding serial port data to the circular queue, occupying only a few CPU clock cycles, consuming very little time and resources, and improving the ability to process multiple serial ports in real time. At the same time, the serial port data buffering is independent of the communication protocol, improving the versatility of serial port parsing.

[0064] 2. Serial port data lookup module

[0065] The serial port data lookup module is used to perform the serial port data lookup step, which involves searching for the serial port data stored in the buffer. Together with the serial port frame recognition module (described later), the serial port data lookup module performs serial port data parsing through timed calls. Figure 2 As shown outside the dashed box, the serial port data lookup module is configured to perform the following steps:

[0066] A2. Obtain the buffer count variable buffCnt and the first-level buffer count variable lastBuffCnt corresponding to the current first-level circular queue, subtract the two to obtain the number of newly added serial port data curCnt. If the number of newly added serial port data curCnt is equal to zero, wait for a preset time (i.e., the interval set by the timed call) and then obtain the buffer count variable buffCnt and the first-level buffer count variable lastBuffCnt corresponding to the current first-level circular queue again, subtract the two to obtain the number of newly added serial port data curCnt, until the number of newly added serial port data curCnt is greater than zero;

[0067] B2. Starting from the beginning address pStartAddr of the data receive buffer corresponding to the current first-level circular queue, copy the serial port data of number curCnt to the second-level buffer frameBuff.

[0068] C2. Call the serial port data frame recognition module to obtain the number of frames parsed in the newly added serial port data, anaNum;

[0069] After obtaining the number of parsed frames, anaNum, the relevant addresses and variables can be updated to prepare for the next lookup of newly added serial port data.

[0070] D. If the number of parsed frames is not 0, that is, the number of successfully parsed serial port data is anaNum, add the number of successfully parsed serial port data anaNum to the first-level buffer count variable lastBuffCnt to obtain the updated first-level buffer count variable. Add the number of successfully parsed serial port data anaNum to the starting address pStartAddr of the data receiving buffer corresponding to the current first-level circular queue to obtain the updated starting address of the data receiving buffer corresponding to the current first-level circular queue.

[0071] E. If the number of parsed frames is 0, it means that the parsing of the new serial port data failed. The serial port parsing failure count value errCnt is incremented. If the serial port parsing failure count value is greater than the set number of times, the current total number of serial ports in curCnt is considered invalid. The first-level buffer count variable lastBuffCnt is added to the number of new serial port data curCnt to obtain the updated first-level buffer count variable. The starting address pStartAddr of the data receive buffer corresponding to the current first-level circular queue is added to the number of new serial port data curCnt to obtain the updated starting address of the data receive buffer corresponding to the current first-level circular queue, thus completing the discarding of invalid data.

[0072] 3. Serial port data frame recognition module

[0073] The serial port data frame recognition module is used to perform the serial port data frame recognition step. Based on the frame header and frame trailer, it determines whether the frame data in the secondary serial port buffer can be parsed. Figure 2 As shown within the dashed box, the serial port data frame recognition module is configured to perform the following steps:

[0074] A3. Starting from the starting address of the second-level cache frameBuff, the search is called repeatedly to find newly added serial port data in turn. The number of times the search is performed is the number of newly added serial port data, curCnt.

[0075] B3. If the current byte is the frame header and the byte preceding the frame length bytes after the current byte is the frame tail, then it is determined that the second-level buffer frameBuff has stored a complete frame of data, and the frame of data starting from the current byte can be parsed according to the serial port protocol; if the above two conditions are not met, that is, the current byte is not the frame header or the byte preceding the frame length bytes after the current byte is not the frame tail, then the serial port parsing failure count value errCnt is incremented. If the serial port parsing failure count value errCnt is greater than the set value, it is considered that curCnt serial port data are all invalid data, the second-level buffer is cleared, so the number of parsed frames is 0, the serial port data frame identification step ends, and the corresponding step C2 in the serial port data search step is returned;

[0076] C3. For the current byte that satisfies the above two conditions, after parsing, select the frame length bytes after the current byte as the new current byte, and continue to determine whether the current byte is the frame header and the byte before the frame length bytes after the current byte is the frame tail starting from the beginning of the next frame;

[0077] For a current byte that does not meet the above two conditions, after parsing fails, the byte after the current byte is selected as the new current byte, so that the judgment is continued from the next byte to determine whether the current byte is the frame header and the byte before the frame length after the current byte is the frame tail.

[0078] Return to step B3 for judgment and parsing until the newly added serial port data has been found. That is, for the current byte that meets the above two conditions, the next byte of the frame length does not exist, or for the current byte that does not meet the above two conditions, the next byte does not exist. At this point, the number of successfully parsed serial port data anaNum can be obtained, the serial port data frame identification step ends, and the corresponding step C2 in the serial port data search step is returned.

[0079] In the serial port data lookup step, in order to prepare for the parsing of the next batch of newly added serial port data, step D, while obtaining the updated first-level buffer count variable and the starting address of the data receiving buffer corresponding to the updated current first-level circular queue, also clears the serial port parsing failure count value errCnt and clears the second-level buffer.

[0080] Example 1

[0081] This embodiment aims to apply the serial port data parsing method of the present invention to single-core multi-serial-port devices, such as... Figure 3 As shown, a single-core multi-serial-port device receives serial data primarily by storing the serial data into different data receive buffers (buff) within different serial port interrupt functions, and continuously incrementing the serial port buffer counter variable buffCnt. Specifically, this includes the following steps:

[0082] After receiving a serial port interrupt, the device CPU executes the serial port data receiving steps. Based on the serial port ID that sent the serial port interrupt, it stores the data received by each serial port into the data receiving buffer corresponding to the first-level circular queue of each serial port, and increments the buffer count variable buffCnt corresponding to these data receiving buffers.

[0083] In the main function, the serial port data search module and the serial port data frame recognition module are called periodically to execute the serial port data search steps and the serial port data frame recognition steps, and obtain the parsing results of the data received by each serial port.

[0084] Example 2

[0085] This embodiment aims to apply the serial port data parsing method of the present invention to multi-core, multi-serial-port devices, such as... Figure 4 As shown, taking the TMS320C6678 (C6678) as an example, this multi-core, multi-serial-port device uses a single SRIO interface to receive multiple external serial port data sent from the FPGA. The serial communication protocol with the FPGA stipulates that after storing the serial port ID and serial port byte data in a fixed memory address on the C6678's receiving end, an interrupt is sent to notify the C6678 to retrieve the serial port ID and serial port data from the fixed memory address. During serial port data reception, the FPGA simulates serial port transmission and interrupts, implementing the function of multiple serial port reception and transmission. Specifically, the following steps are included:

[0086] After the FPGA obtains data from multiple serial ports, it saves the corresponding serial port ID and data into memory and sends a serial port interrupt to the DSP through the SRIO interface.

[0087] After the DSP receives a serial port interrupt, since it only has one receiving port, when multiple serial ports need to be received and parsed, its parsing interrupt function is the same as that of the interface port, with only one function. In order to reduce the system operating pressure, the DSP calls the serial port receiving module in the interrupt function of the first core (such as core 1) to execute the serial port data receiving steps. According to the serial port ID, the serial port data is stored in the data receiving buffer corresponding to the first-level circular queue of each serial port, and the buffer count variable buffCnt corresponding to these data receiving buffers is incremented.

[0088] Correspondingly, the second core of the DSP (such as core 0) timed serial port data lookup module and serial port data frame recognition module execute the serial port data lookup step and the serial port data frame recognition step to obtain the parsing results of each serial port data.

[0089] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the invention. Therefore, any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention should fall within the protection scope of the present invention.

Claims

1. A serial port data parsing method, characterized in that, Includes the following steps: Serial port data receiving steps: Obtain serial port data from the serial port and store the serial port data into the first-level circular queue corresponding to the serial port according to the serial port ID; Serial port data lookup steps: Calculate the newly added serial port data in the first-level circular queue, and store the newly added serial port data in the second-level buffer. Then, search for the serial port data stored in the second-level buffer. Specifically, when calculating the newly added serial port data in the first-level circular queue and storing the newly added serial port data in the second-level buffer, obtain the buffer count variable buffCnt and the first-level buffer count variable lastBuffCnt corresponding to the current first-level circular queue, subtract the two to obtain the number of newly added serial port data curCnt, and copy the serial port data of the number curCnt to the second-level buffer frameBuff starting from the starting address pStartAddr of the data receiving buffer corresponding to the current first-level circular queue. Serial port data frame identification steps: Identify the frame header and frame tail of the serial port data in the secondary buffer, and parse the data between the frame header and frame tail according to the preset serial port protocol. If the number of successfully parsed serial port data anaNum is not 0, add the number of successfully parsed serial port data anaNum to the first-level buffer count variable lastBuffCnt, and add the number of successfully parsed serial port data anaNum to the starting address pStartAddr of the data receiving buffer corresponding to the current first-level circular queue. If the number of successfully parsed serial port data anaNum is 0, add the number of newly added serial port data curCnt to the first-level buffer count variable lastBuffCnt, and add the number of newly added serial port data curCnt to the starting address pStartAddr of the data receive buffer corresponding to the current first-level circular queue.

2. The serial port data parsing method according to claim 1, characterized in that, Before acquiring serial port data, the following steps are required: Define a corresponding data receive buffer and a buffer count variable buffCnt for each serial port. The buffer count variable buffCnt shall not exceed the length of the corresponding data receive buffer.

3. The serial port data parsing method according to claim 1, characterized in that, The serial port data lookup process also includes the following steps: If the number of newly added serial port data, curCnt, is zero, wait for a preset time, then retrieve the buffer count variable buffCnt and the first-level buffer count variable lastBuffCnt corresponding to the current first-level circular queue, subtract the two to get the number of newly added serial port data, curCnt, until the number of newly added serial port data, curCnt, is greater than zero.

4. The serial port data parsing method according to claim 1, characterized in that, The serial port data frame identification process specifically includes the following steps: Start searching for newly added serial port data from the starting address of the second-level cache frameBuff; If the current byte is the frame header and the byte preceding the frame length byte after the current byte is the frame tail, then the data of a frame starting from the current byte is parsed according to the serial port protocol. Select the next few bytes after the current byte as the new current byte, and continue to determine whether the current byte is the frame header and whether the byte before the next few bytes after the current byte is the frame tail, until all newly added serial port data has been found, and obtain the number of successfully parsed serial port data anaNum.

5. The serial port data parsing method according to claim 4, characterized in that, Starting from the beginning address of the second-level cache frameBuff, the search for newly added serial port data includes: if the current byte is not the frame header or the byte before the frame length after the current byte is not the frame tail, the serial port parsing failure count value errCnt is incremented. If the serial port parsing failure count value errCnt has not reached the set value, select the byte after the current byte as the new current byte, and continue to determine whether the current byte is the frame header and the byte before the frame length bytes after the current byte is the frame tail, until the new serial port data search is completed or the serial port parsing failure count value errCnt reaches the set value. If the serial port parsing failure count value errCnt reaches the set value, the newly added serial port data is invalid data, and the secondary cache is cleared.

6. The serial port data parsing method according to claim 4, characterized in that, The serial port data search step further includes: after the serial port data frame identification step is completed, if the number of successfully parsed serial port data anaNum is not 0, the serial port parsing failure count value errCnt is cleared to zero, and the secondary buffer is cleared.

7. The serial port data parsing method according to claim 1, characterized in that, This includes the steps for a single-core, multi-serial-port device to receive serial data, specifically: After receiving a serial port interrupt, the serial port data receiving steps are executed. The data received by each serial port is stored in the data receiving buffer corresponding to the first-level circular queue of each serial port according to the serial port ID, and the buffer count variable buffCnt corresponding to these data receiving buffers is incremented. The serial port data search and serial port data frame identification steps are executed periodically to obtain the parsing results of the data received from each serial port.

8. The serial port data parsing method according to claim 1, characterized in that, The steps include receiving serial data using a multi-core, multi-serial-port device, which includes an FPGA and a DSP. The specific steps include: After the FPGA obtains data from multiple serial ports, it saves the corresponding serial port ID and data into memory and sends a serial port interrupt to the DSP through the SRIO interface. After the DSP receives a serial port interrupt, the second core of the DSP executes the serial port data receiving steps. According to the serial port ID, it stores the serial port data into the data receiving buffer corresponding to the first-level circular queue of each serial port, and increments the buffer count variable buffCnt corresponding to these data receiving buffers. The first core of the DSP executes the serial port data search step and the serial port data frame recognition step in a timer to obtain the parsing results of each serial port data.

9. A serial port data parsing system, characterized in that, include: The serial port data receiving module is used to acquire serial port data from the serial port and store the serial port data into the first-level circular queue corresponding to the serial port according to the serial port ID. The serial port data lookup module is used to calculate the newly added serial port data in the first-level circular queue, and after storing the newly added serial port data in the second-level buffer, it searches for the serial port data stored in the second-level buffer. Specifically, when calculating the newly added serial port data in the first-level circular queue and storing the newly added serial port data in the second-level buffer, it obtains the buffer count variable buffCnt and the first-level buffer count variable lastBuffCnt corresponding to the current first-level circular queue, subtracts the two to obtain the number of newly added serial port data curCnt, and copies the serial port data of the number curCnt to the second-level buffer frameBuff starting from the starting address pStartAddr of the data receiving buffer corresponding to the current first-level circular queue. The serial port data frame identification module is used to identify the frame header and frame tail of the serial port data in the secondary buffer, and parse the data between the frame header and frame tail according to the preset serial port protocol. If the number of successfully parsed serial port data anaNum is not 0, the first-level buffer count variable lastBuffCnt is added to the number of successfully parsed serial port data anaNum, and the starting address pStartAddr of the data receiving buffer corresponding to the current first-level circular queue is added to the number of successfully parsed serial port data anaNum. If the number of successfully parsed serial port data anaNum is 0, add the number of newly added serial port data curCnt to the first-level buffer count variable lastBuffCnt, and add the number of newly added serial port data curCnt to the starting address pStartAddr of the data receive buffer corresponding to the current first-level circular queue.

Citation Information

Patent Citations

  • Frame identifying method for serial data

    CN102510323A

  • FPGA-based (Field Programmable Gate Array) extended multi-serial port device and data receiving-transmitting method thereof

    CN102760111A

  • Circular queue cache-based intelligent iron shoe data transmission and processing method as well as communication data terminal

    CN108198394A