Multi-machine communication data processing method based on serial port and multi-machine communication system
The multi-machine communication method using DMA channels and circular queues addresses real-time data processing challenges in serial port communication, enhancing efficiency and error detection in aerospace applications.
Patent Information
- Application Number
- CN202411689494.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2044-11-25
AI Technical Summary
Existing multi-machine communication systems using serial ports face challenges in ensuring real-time data processing, avoiding packet sticking, and quickly identifying transmission errors, particularly in aerospace applications where weight and wiring complexity are critical.
A multi-machine communication method using hardware and software flow control mechanisms, DMA channels, and error detection/correction to manage serial port transmission streams, ensuring efficient data reception and processing through periodic pulses and circular queues.
Improves data reception and processing efficiency, reduces CPU intervention, ensures real-time data acquisition, and quickly identifies transmission errors, maintaining data integrity and continuity.
Smart Images

Figure CN119201805A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a multi-machine communication data processing method based on a serial port, a multi-machine communication system, a server device and a storage medium. Background Art
[0002] Multi-machine communication is the process of data exchange and communication between multiple devices. This communication can occur between different types of devices, such as computers, embedded systems, sensors, etc., with the purpose of achieving data sharing, collaborative work or information transmission. Although with the rapid development of communication technology today, multi-machine communication is no longer limited to the use of serial ports, but is achieved using higher-speed physical buses such as SPI, IIC, network cables, and optical fibers, but due to cost and wiring difficulty considerations, using multiple serial ports, that is, UART for multi-machine communication is still a common method in the embedded and communication fields. Especially for the aerospace field, the design of aircraft volume is bound to be based on wiring difficulty considerations, and the volume directly affects the weight of the aircraft. Therefore, for short-distance multi-machine communication, using UART with only three wires (Tx, Rx, GND) is one of the best choices.
[0003] However, how to use only the serial port as a communication interface to asynchronously receive and summarize multi-machine communication data and perform calculations and processing, how to ensure the real-time and accuracy of periodic multi-machine data communication, how to ensure that the serial communication receiver can avoid or solve the packet sticking problem of the received cached data stream when receiving and parsing the data stream to improve the unpacking efficiency, and how to quickly distinguish between transmission errors and packet sticking and broken packets in the case of serial communication transmission errors or packet loss are still important technical requirements and performance issues in the field of communication technology. Summary of the invention
[0004] In view of the above problems, this scheme proposes a multi-machine communication data processing method and a multi-machine communication system based on serial port implementation, uses hardware and software flow control mechanisms to manage serial port transmission streams and avoid conflicts, and introduces error detection and correction mechanisms to improve the reliability of communication.
[0005] According to a first aspect of the present invention, a multi-machine communication data processing method based on a serial port is provided, which is implemented based on a server device, and the server device communicates with a client host computer and one or more controlled devices through a serial port respectively. The server device is used to periodically send pulses to trigger one or more controlled devices to send collected data, and summarize and calculate the data received from the controlled devices in each cycle and then send them to the client host computer. The method includes: The server device and each controlled device perform power-on initialization and handshake synchronization, wherein the power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, so that the sending channel and the receiving channel of each serial port are respectively bound to a transmission stream of a unique DMA channel, registering a receiving idle interrupt for each serial port, and creating a circular queue for storing the calculation results of the collected data of the controlled devices received after the summary processing in each cycle, and the queue elements of the circular queue at least include the packet ID, the packet grouping timestamp, the calculation results and the valid flag of the collected data of each controlled device; Start the system tick clock for periodic timing, and send a pulse or trigger an interrupt at the beginning of each timing cycle to notify each controlled device to start sending data; After receiving the data sent by the controlled device from the transmission stream of the DMA channel corresponding to each serial port, the corresponding receiving idle interrupt processing function is entered, the received data is parsed in the interrupt processing function, and the parsed data is saved in the ring queue; After waiting for a specified time in each timing cycle, the data collected by each controlled device is summarized and processed, and the calculation results are sent to the client host computer through the serial port in DMA mode.
[0006] Through the above technical solution, the use of DMA and serial port idle interrupts improves the efficiency of data reception and processing, reduces CPU intervention and processing delays, and triggers the controlled device to send data through periodic pulses to ensure the regularity and synchronization of data acquisition.
[0007] Optionally, in the multi-machine communication data processing method based on serial port provided by the present invention, the controlled device writes an agreed value to the specified register after power-on initialization is completed; the server device cyclically reads the specified register after power-on initialization is completed until the agreed value is read out, and the server device shakes hands with the controlled device successfully. When the server device shakes hands with all controlled devices successfully, the handshake synchronization is completed.
[0008] Through the above technical solution, handshake is performed through registers after power-on initialization, which simplifies the complexity of communication initialization and avoids additional handshake protocols.
[0009] Optionally, in the multi-machine communication data processing method based on serial port implementation provided by the present invention, the reload value of the system tick clock is set according to the system tick clock frequency, so that each reload cycle time of the system tick clock is equal to the periodic notification time required by the server; the counter value of the system tick clock is cleared and the system tick clock timer is started, and the status register of the system tick clock is repeatedly read until the value of the reload flag COUNTFLAG in the read status register of the system tick clock is 1, the count value of the system tick clock counter is cleared and a pulse is sent to each controlled device to trigger a GPIO interrupt to notify each controlled device to send data, and the COUNTFLAG flag is automatically set to 1 by hardware when the count value decreases to 0, and the COUNTFLAG flag is automatically cleared by hardware when it is read.
[0010] According to the above technical solution, by setting the reload value of the system tick clock so that its period is equal to the notification period time required by the server, accurate periodic triggering is ensured and time deviation is reduced. The automatic clearing of the system tick clock counter and the automatic management of the COUNTFLAG flag simplify the use of the timer, reduce software intervention, and reduce the possibility of errors.
[0011] Optionally, in the multi-machine communication data processing method based on the serial port provided by the present invention, the packet assembly timestamp of the queue element is calculated by the system tick clock count value and the number of reloads read during packet assembly, and the calculation method of the packet assembly timestamp is: time_us = [loadCnt+(load+1-val) / (load+1)] * TRIG_PERIOD, where time_us is the packet assembly timestamp, TRIG_PERIOD is the notification period of the server, loadCnt is the number of reloads during packet assembly, and load is the reload count value of the system tick clock.
[0012] Optionally, in the multi-machine communication data processing method based on the serial port provided by the present invention, after the server device completes handshake synchronization with each controlled device, a DMA receive buffer is set for each serial port, DMA reception is turned on and the receive first address is specified as the DMA receive buffer first address, and the receive length is specified as the buffer length; when the serial port receives an idle interrupt, the reception of the transmission stream of the serial port DMA channel is stopped, and the actual receive data length rxLen of the serial port is calculated according to the specified receive length size and the number of data units HAL_DMA_GET_COUNTER remaining for this DMA stream transmission, wherein rxLen=size-HAL_DMA_GET_COUNTER; the data stream with the length rxLen starting from the first address of the DMA receive buffer is parsed according to the protocol format predetermined with the sender, and the parsing result is saved in a global variable; DMA reception is turned on again, and the first address and the specified receive length of the DMA receive buffer are reconfigured to continue to receive subsequent data, and the specified receive length is greater than the estimated maximum length of a single packet received from the serial port.
[0013] Optionally, in the multi-machine communication data processing method based on serial port implementation provided by the present invention, when the serial port receives an idle interrupt to receive and parse the transmission stream received in this DMA receive buffer whose length is the actual receive data length, if errors such as missing cache packet format and missing packet length are detected, the data whose parsing failed is abandoned and the next DMA reception is directly started.
[0014] Optionally, in the multi-machine communication data processing method based on the serial port provided by the present invention, a specified time is waited in the current timing cycle. If the data sent by all controlled devices are successfully received and parsed within the specified time, the data collected by each controlled device is summarized and calculated and processed to generate a new queue element to be inserted into the ring queue. The head element of the ring queue is sent to the client host computer in a DMA manner through the serial port. The queue element contains the packet ID, the packet group timestamp, the data calculation result and the valid flag bit of the data collected by the controlled device; If the data collected by all controlled devices is not received within the specified time, a new queue element is generated and inserted at the end of the circular queue. The member values of the new queue element are the same as those of the previous queue element. The valid flag of the collected data of the controlled device that has not received the data is cleared and the package ID is updated. The head element of the circular queue is sent to the client host computer through the serial port in DMA mode; wait for the timing cycle to end and continue to receive and process data in the next round of timing cycle.
[0015] Optionally, in the multi-machine communication data processing method based on the serial port provided by the present invention, the server triggers a GPIO interrupt, notifies the controlled device, and immediately reads the system tick clock and creates a local variable to save the initial count value of the system tick clock and the initial reload number; Repeatedly read the current count value of the system tick clock and the current reload count until the calculated time interval between the current moment and the notification moment is greater than or equal to the waiting specified time, where the waiting specified time is the periodic notification time minus the maximum estimated time required to receive, summarize and calculate the data collected by each serial port. The time interval between the current moment and the notification moment is: dTime=[(val1-val2) / (load+1)+loadCnt2-loadCnt1]*TRIG_PERIOD, where load is the reload count value, TRIG_PERIOD is the notification period of the server, val1 is the initial count value of the system tick clock, val2 is the current count value of the system tick clock, loadCnt1 is the initial reload count, and loadCnt2 is the current reload count.
[0016] Optionally, in the multi-machine communication data processing method based on serial port implementation provided by the present invention, the circular queue is a first-in-first-out data structure. When writing to the queue, the queue element is inserted into the queue space indicated by the tail position number and the tail position number is updated to WrId = (WrId +1) % MAX. When reading the queue, the queue element indicated by the head position number is read and the head position number is updated to RdId = (RdId +1) % MAX, where MAX is the maximum number of queue elements that the circular queue can accommodate; When the main thread has not received the data collected by all controlled devices after waiting for the specified time in this round of timing cycle, the queue element saved by the summary calculation of the previous round of timing cycle is found through the queue tail position sequence number. The packet ID of the queue element sent to the client host computer through the serial port in each timing cycle is always equal to the queue head position sequence number to ensure that the client host computer can check whether there is any packet loss during the transmission process by checking whether the received packet IDs are continuous.
[0017] According to the above technical solution, the read and write operations of the circular queue only involve the update of the position number, without complex operations, ensuring the efficiency of data processing. Through the continuity check of the packet ID, even if the data is not fully received, it can be restored through the saved historical data, ensuring the integrity of data transmission and being able to detect and handle packet loss in a timely manner.
[0018] According to a second aspect of the present invention, there is provided a multi-machine communication system based on a serial port, comprising: a client host computer, a server device, a plurality of controlled devices and a UART interface for multi-machine communication; the client host computer runs a user interaction interface program for graphically displaying the data or signals after the summary calculation and processing; the controlled device is an embedded computer or other device for collecting data or signals, and the controlled device has a serial port for collecting data in real time and sending the data to the server device through the serial port after receiving a notification from the server device; the server device is provided with a plurality of serial ports, each serial port being used for communicating with the client host computer or a single controlled device.
[0019] The server device runs server software, which is used to periodically send pulses to trigger one or more controlled devices to send real-time collected data, and summarize and calculate the data received from the controlled devices in each cycle and send it to the client host computer, including: The server device and each controlled device perform power-on initialization and handshake synchronization, wherein the power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, so that the sending channel and the receiving channel of each serial port are respectively bound to a unique DMA channel, registering the receiving idle interrupt for each serial port, and creating a circular queue for storing the calculation results of the collected data of the controlled devices received after the summary processing in each cycle, and the queue elements of the circular queue at least include the packet ID, the packet grouping timestamp, the calculation results and the valid flag of the collected data of each controlled device; waiting for all controlled devices to be successfully powered on and initialized before the handshake is completed; Start the system tick clock for periodic timing, and send a pulse or trigger an interrupt at the beginning of each timing cycle to notify each controlled device to start sending data; After receiving the data sent by the controlled device from the DMA channel corresponding to each serial port, the corresponding receiving idle interrupt processing function is entered, the received data is parsed in the interrupt processing function, and the parsed data is saved in the ring queue; After waiting for a specified time in each timing cycle, the data collected by each controlled device is summarized and processed, and the calculation results are sent to the client host computer through the serial port in DMA mode.
[0020] According to a third aspect of the present invention, there is provided a server-side device, comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be suitable for execution by at least one processor, and the program instructions include instructions for executing the multi-machine communication data processing method based on serial port implementation of the first aspect of the present invention.
[0021] According to a fourth aspect of the present invention, a readable storage medium storing program instructions is provided. When the program instructions are read and executed by a server device, the server device executes the multi-machine communication data processing method based on a serial port according to the first aspect of the present invention.
[0022] The multi-machine communication data processing method and multi-machine communication system based on serial port implementation according to the present invention can at least achieve the following beneficial effects: (1) Each serial port's Tx and Rx channels are bound to a transmission stream of a unique DMA channel, ensuring that each serial port data channel is independent and improving serial port data transmission efficiency; (2) Register the receive idle interrupt for each serial port respectively. In the receive idle interrupt processing function, the length of a single packet in the DMA buffer is calculated by the remaining length of the DMA channel transmission stream, and the DMA reception is enabled again after the unpacking is completed. This avoids the problem of receiving sticky packets, improves the unpacking efficiency, and reduces the CPU occupancy time during the data transmission process. (3) Under the premise of using only the non-interrupt timing method of the same system tick clock SysTick, it also provides a method for generating an accurate timing cycle for triggering an interrupt to notify the controlled device, a method for generating a fixed timeout specified time for waiting for packet reception within the timing cycle, and a method for generating an accurate timestamp when sending the packet, thereby ensuring the real-time and periodicity of the collected data received in aggregate; (4) The head position ID of the circular queue is used as the packet ID. When all collected data are not received within a timeout period, the most recently sent packet can be quickly found from the circular queue and the data valid flag can be cleared to zero before being sent to the client host computer. This ensures the continuity of the graphical display of the client host computer and facilitates the client to quickly identify errors such as packet loss and failure to receive collected data.
[0023] Therefore, this solution can periodically notify the controlled devices to collect data or signals, receive data sent by multiple controlled devices through the serial port in real time, and quickly and accurately summarize and calculate the data before sending it to the client host computer, solving the performance problem of using serial ports for multi-machine communication.
[0024] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings: Figure 1 It shows a schematic structural diagram of a multi-machine communication system based on a serial port according to an embodiment of the present invention; Figure 2 A schematic diagram of the software architecture of a server device according to an embodiment of the present invention is shown; Figure 3 An example of code implementation of the main thread of a server device according to an embodiment of the present invention is shown; Figure 4 A schematic diagram of the structure of a server device 100 according to an embodiment of the present invention is shown; Figure 5 A schematic flow chart of a multi-machine communication data processing method 500 based on a serial port according to an embodiment of the present invention is shown; Figure 6 An example of code implementation of non-interrupt timing and generation of timestamps by a system tick clock according to an embodiment of the present invention is shown; Figure 7 An example of a serial port receiving idle interrupt processing function code according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0026] Multi-machine communication is a common requirement in various fields such as communication networks, aerospace, measurement and control, and industrial automation. Among them, the client / server architecture is one of the most common multi-machine communication architectures. For example, in the measurement and control field, an embedded lower computer is used as a communication server, and other embedded devices used to collect bus data in real time are used as controlled devices. When the controlled device receives the notification signal from the server device, it transmits the real-time collected data to the communication server through the serial port. After the communication server summarizes and calculates the data collected by each controlled device, it sends it to the client host computer through the serial port to display it to the user on the interface; for the industrial automation and aerospace fields, the server periodically receives and summarizes the temperature, humidity, directional acceleration and other information sent by each embedded device or sensor through the serial port, and calculates and processes it into average temperature, average humidity, synthetic acceleration and other information, and then sends it to the client host computer through the serial port. Due to the advantages of low cost, low wiring difficulty, and short-distance transmission delay of the serial interface, using multiple serial ports, namely UART, for multi-machine communication is still a better choice in the embedded and communication fields.
[0027] However, how to use the serial port to more quickly receive, summarize and calculate the communication data of multiple machines, improve the real-time and periodicity of notifying each controlled device to send collected data or signals, ensure that the serial communication receiver can solve the packet sticking problem of the transmission stream when parsing the transmission stream to improve the unpacking efficiency, and quickly identify transmission errors in the case of serial communication transmission errors or packet loss, are still communication performance issues that need to be solved in the embedded and communication fields.
[0028] In order to improve the performance of multi-machine communication using serial ports, this scheme proposes a multi-machine communication data processing method based on serial ports, which can periodically and accurately notify the controlled devices to collect data, receive data sent by multiple controlled devices through serial ports in real time, and quickly summarize and calculate the data before sending it to the client host computer.
[0029] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0030] Figure 1 FIG. 1 shows a schematic diagram of a multi-machine communication system based on a serial port according to an embodiment of the present invention. Figure 1 As shown, the system includes a client host computer, a server device, multiple controlled devices (controlled device 1, controlled device 2...controlled device n) and UART interfaces (UART0, UART1, UART2...UARTn) for multi-machine communication. Among them, the client host computer runs a user interaction interface program for graphically displaying the data or signals after the summary calculation and processing. The server device is provided with multiple serial ports, each of which is used to communicate with the client host computer or a single controlled device. The controlled device is an embedded computer or other device for collecting data or signals. Figure 1 As shown, the server device is connected to the client host computer through the serial port UART0, and is connected to the controlled device 1, the controlled device 2...the controlled device n through the serial ports UART1, UART2...UARTn respectively.
[0031] The server device runs server software, which is used to periodically send pulses to trigger one or more controlled devices to send real-time collected data, and summarize and calculate the data received from the controlled devices in each cycle and send it to the client host computer. After receiving the notification from the server device, the controlled device collects data or signals in real time and sends them to the server device through the corresponding serial port.
[0032] Figure 2 FIG. 2 shows a schematic diagram of the software architecture of a server device according to an embodiment of the present invention. Figure 2 As shown, in the main thread, 1) the server device and each controlled device perform power-on initialization and handshake synchronization, where the power-on initialization includes: configuring the period of the system tick clock and a transmission stream of the DMA channel corresponding to each serial port, so that the sending channel and receiving channel of each serial port are respectively bound to a unique DMA channel transmission stream, registering the receiving idle interrupt for each serial port, and creating a circular queue to save the calculation results of the collected data of the controlled devices received in each cycle after the summary processing, and waiting for all controlled devices to be successfully powered on and initialized before the handshake is completed. Among them, the queue elements of the circular queue include at least the packet ID, the packet group timestamp, the calculation result, and the valid flag of the collected data of each controlled device; 2) Start the system tick clock for periodic timing, and send pulse 1 and pulse 2 at the beginning of each timing cycle to notify the controlled device A and the controlled device B to start sending the real-time collected data; 3) The main thread waits for a specified time in each timing cycle. During this period, it automatically receives data sent by the controlled device from the DMA channel corresponding to each serial port, and then enters the corresponding receive idle interrupt processing function. In the receive idle interrupt processing function, DMA reception is temporarily turned off, and then the data in the DMA receive buffer is parsed and saved. Then, DMA reception is reopened and the receive length is specified as the buffer length. To ensure that a whole packet of data is cached each time an idle interrupt is entered, the specified receive length should be much larger than the maximum length of a single packet expected to be received; 4) After waiting for the specified time in each timing cycle, check whether the collected data of each controlled device has been received: if the collected data of all controlled devices have been received, the collected data are summarized and processed, and a new queue element is generated and inserted into the ring queue, and then the queue element is sent to the client host computer through the serial port in DMA mode; on the contrary, if the collected data of all controlled devices is not received within the time limit, the previous packet of queue elements in the ring queue is sent to the client host computer through the serial port in DMA mode; 5) Return to step 3) and start the next timing cycle to notify the controlled device to send the collected data and receive the summary processing process.
[0033] Figure 3 FIG. 1 shows an example of a code implementation of the main thread of a server device according to an embodiment of the present invention. Figure 3 As shown, Acc1A, Acc1B, and Acc1C are three different controlled devices, which communicate with the server device through serial ports Uart5, Uart3, and Uart2 respectively.
[0034] When the main thread is powered on, it first initializes the serial port, DMA, system tick clock SysTick and other hardware. When initializing each serial port, it will register a serial port receive idle interrupt (IDEL interrupt) for each serial port, and bind the Tx and Rx of each serial port to the only DMA transmission stream.
[0035] After the initialization is completed, the power-on handshake synchronization is performed with Acc1A, Acc1B, and Acc1C respectively, and the handshake is completed when the controlled devices are all powered on and initialized. After the handshake is completed, the receive idle interrupt of each serial port is enabled, and the function is called to specify the DMA receive buffer of each serial port to start the first DMA reception. At this time, the specified DMA receive length is the buffer length, which should be much larger than the maximum length of a single packet that may be received to ensure that there is no cache break in the receive buffer.
[0036] Then start the system tick timer. In the example, set the reload value of the system tick timer according to the 1us trigger notification timing period and the system tick clock frequency. Figure 4 TRIGPERIOD_ACC1_US in the code is the macro value representing the trigger period. After the tick timer is turned on, it will count down. When the count value decreases to 0, it will automatically reload the set reload value and the hardware will automatically set the COUNTFLAG flag position of the SysTick status register to 1.
[0037] Figure 3 The WaitSysTimerEnd() function in the code essentially waits in a loop until the COUNTFLGA flag read from the SysTick status register changes from 0 to 1, which means the current timing cycle ends and the next timing cycle begins. Since COUNTFLGA is automatically cleared by hardware when it is read, as long as the flag is 1, it means the tick timer has been reloaded and a timing cycle (1us) has ended.
[0038] At the beginning of each timing cycle, the main thread sends pulses to the controlled devices Acc1A, Acc1B, and Acc1C, notifying each controlled device to collect and send data in real time. At this time, when receiving the collected data sent by any controlled device, the CPU will enter the corresponding serial port's receive idle interrupt to receive and parse the packet. After sending the pulse notification, the main thread will wait for the specified time. When the specified time is exceeded, the function MakeGuiPkt() is called to summarize and calculate the data collected by each controlled device to generate a new circular queue element, and in this function, the queue element is sent to the client host computer through the serial port in DMA mode.
[0039] It is worth noting that if the data sent by all controlled devices is not received within the specified time, the last queue element cached in the circular queue will be directly copied and inserted into the end of the queue and sent to the host computer. Its timestamp and packet ID will be modified before sending. The timestamp is also obtained in the MakeGuiPkt function, and the packet ID is equal to the head position ID of the circular queue where the queue element sent is located. Then the main thread returns to the WaitSysTimerEnd() function to wait for the next round of timing cycle to start.
[0040] Figure 4 FIG. 1 shows a schematic diagram of the structure of a server device 100 according to an embodiment of the present invention. Figure 4 As shown, in a basic configuration 102 , the server device 100 typically includes a memory 106 and one or more processors 104 . A memory bus 108 may be used for communication between the processor 104 and the memory 106 .
[0041] Depending on the desired configuration, the processor 104 can be any type of processor, including but not limited to: a microprocessor (µP), a microcontroller (µC), a digital signal processor (DSP), or any combination thereof. The processor 104 can include one or more levels of cache, such as a primary cache 110 and a secondary cache 112, a processor core 114, and registers 116. An example processor core 114 can include an arithmetic logic unit (ALU), a floating point unit (FPU), a digital signal processing core (DSP core), or any combination thereof. An example memory controller 118 can be used with the processor 104, or in some implementations, the memory controller 118 can be an internal part of the processor 104.
[0042] Depending on the desired configuration, the memory 106 can be any type of memory, including but not limited to: volatile memory (such as RAM), non-volatile memory (such as ROM, flash memory, etc.) or any combination thereof. The physical memory in the server device generally refers to the volatile memory RAM, and the data in the disk needs to be loaded into the physical memory before it can be read by the processor 104. The memory 106 may include an operating system 120, one or more programs 122, and program data 124. In some embodiments, the program 122 may be arranged to execute instructions on the operating system by one or more processors 104 using program data 124. The operating system 120 may be, for example, Linux, Windows, etc., which includes program instructions for processing basic system services and performing hardware-dependent tasks. The program 122 includes program instructions for implementing various user-desired functions, and the program 122 may be, for example, a browser, instant messaging software, a software development tool (such as an integrated development environment IDE, a compiler, etc.), etc., but is not limited thereto. When the program 122 is installed in the server device 100, a driver module may be added to the operating system 120.
[0043] When the server device 100 starts running, the processor 104 reads and executes the program instructions of the operating system 120 from the memory 106. The program 122 runs on the operating system 120, and uses the interfaces provided by the operating system 120 and the underlying hardware to implement various functions expected by the user. When the user starts the program 122, the program 122 is loaded into the memory 106, and the processor 104 reads and executes the program instructions of the program 122 from the memory 106.
[0044] The server device 100 further includes a storage device 132 . The storage device 132 includes a removable storage 136 and a non-removable storage 138 . Both the removable storage 136 and the non-removable storage 138 are connected to the storage interface bus 134 .
[0045] The server device 100 may also include an interface bus 140 that facilitates communication from various interface devices (e.g., output devices 142, peripheral interfaces 144, and communication devices 146) to the basic configuration 102 via the bus / interface controller 130. The output device 142 of the example includes a graphics processing unit 148 and an audio processing unit 150. They can be configured to facilitate communication with various external devices such as a display or a speaker via one or more A / V ports 152. The example peripheral interface 144 may include a serial interface controller 154 and a parallel interface controller 156, which may be configured to facilitate communication with external devices such as input devices (e.g., keyboards, mice, pens, voice input devices, touch input devices) or other peripherals (e.g., printers, scanners, etc.) via one or more I / O ports 158. The example communication device 146 may include a network controller 160, which may be arranged to facilitate communication with one or more other computing devices 162 via a network communication link via one or more communication ports 164.
[0046] A network communication link may be an example of a communication medium. Communication media may generally be embodied as computer-readable instructions, data structures, program modules in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium. A "modulated data signal" may be a signal in which one or more of its data sets or changes thereto may be carried out in a manner that encodes information in the signal. As non-limiting examples, communication media may include wired media such as a wired network or a dedicated line network, and various wireless media such as sound, radio frequency (RF), microwave, infrared (IR) or other wireless media. The term computer-readable media used herein may include both storage media and communication media.
[0047] The server device 100 also includes a storage interface bus 134 connected to the interface controller 130. The storage interface bus 134 is connected to a storage device 132, which is suitable for data storage. The exemplary storage device 132 may include a removable storage 136 (such as a CD, DVD, USB flash drive, removable hard disk, etc.) and a non-removable storage 138 (such as a hard disk drive HDD, etc.).
[0048] In the server device 100 according to the present invention, the program 122 includes instructions for executing the multi-machine communication data processing method 500 based on serial port implementation according to the present invention.
[0049] Figure 5 FIG. 5 is a flow chart showing a multi-machine communication data processing method 500 based on a serial port according to an embodiment of the present invention. Figure 5As shown, first in step S510, the server device and each controlled device perform power-on initialization and handshake synchronization, wherein the power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, so that the sending channel and the receiving channel of each serial port are respectively bound to a unique DMA channel, registering a receiving idle interrupt for each serial port, and creating a circular queue for storing the calculation results of the collected data of the controlled devices received after the summary processing in each cycle, and the queue elements of the circular queue at least include the packet ID, the packet group timestamp, the calculation result and the valid flag of the collected data of each controlled device.
[0050] Setting the system tick clock SysTick can obtain a stable time base for the system to synchronize data transmission and processing cycles. At the same time, it provides a trigger interrupt to notify the controlled device to generate an accurate timing cycle, ensuring the periodicity of receiving and collecting data.
[0051] During the power-on initialization process, a unique receive idle interrupt is registered for each serial port, and multiple DMA channels are applied for. The TX and RX channels of each serial port are bound to the transmission stream of the only DMA channel, that is, different serial port transmission streams are assigned to different DMA channels, which can make each serial port data channel independent, and transfer data transmission from CPU processing to DMA (direct memory access) controller to avoid the data transmission of one serial port affecting the transmission streams of other serial ports. Only DMA is used to send or receive serial port data to improve data transmission and reception efficiency and reduce CPU occupancy time. The receive idle interrupt processing function will only be entered after DMA receives a whole packet of data, reducing the number of interrupts in the data transmission and reception process.
[0052] The ring queue is used to store the data calculation results of each cycle so that the system can process data within a fixed time interval and keep the data in order. Among them, the queue elements of the ring queue include at least: Packet ID: uniquely identifies the head position ID of the data packet, which is convenient for tracking and managing data; Packet timestamp: records the time when the data packet is processed for time analysis or synchronization; Calculation results: contains the summary and calculation results of the data collected by the controlled device; Valid flag: indicates the validity of the data to ensure that the processed data meets expectations.
[0053] Then in step S520, the system tick clock is started to perform periodic timing, and a pulse is sent or an interrupt is triggered at the beginning of each timing cycle to notify each controlled device to start sending data.
[0054] After power-on initialization and handshake completion, the server can set the reload value of the system tick clock according to the system tick clock frequency, so that each reload cycle time of the system tick clock is equal to the periodic notification time required by the server. The reload value of SysTick can be set according to the required timing accuracy. This reload value determines the length of the timing cycle. For example, if an interrupt is required every 1 millisecond, set the reload value to the system tick clock frequency divided by 1 millisecond.
[0055] If you choose to notify the controlled device by sending a pulse, you can use the GPIO output pin to generate a pulse signal at the beginning of each SysTick timing cycle. The controlled device can listen to this pulse signal and start sending data when it receives the pulse.
[0056] If you choose to notify the controlled device by triggering an interrupt, the SysTick interrupt service routine (ISR) will trigger an interrupt at the beginning of each timing cycle. The interrupt service routine can send instructions or data to the controlled device through the serial port or other communication methods to inform it to start data transmission. After receiving the pulse or instruction generated by SysTick, the controlled device starts to send data. The server needs to configure the corresponding receiving mechanism to process the data sent from the controlled device.
[0057] In one embodiment of the present invention, the counter value of the system tick clock is cleared and the system tick clock timer is started, and the status register of the system tick clock is read repeatedly until the value of the reload flag COUNTFLAG in the read status register of the system tick clock is 1, the count value of the system tick clock counter is cleared and a pulse is sent to each controlled device to trigger a GPIO interrupt to notify each controlled device to send data, and the COUNTFLAG flag is automatically set to 1 by hardware when the count value decreases to 0, and the COUNTFLAG flag is automatically cleared by hardware when it is read.
[0058] By using the SysTick timer to synchronize the controlled devices, each device can start sending data at a precise time point, thereby achieving effective data collection and processing. This method can improve the synchronization accuracy of the system and ensure the timeliness of data transmission.
[0059] Figure 6 An example of code implementation of a system tick clock non-interrupt timing and generation of a timestamp according to an embodiment of the present invention is shown. Figure 6 As shown, the SysTimer_Start function calculates and sets the reload value of the system tick clock SysTick according to the incoming notification timing cycle us (the variable is in microseconds) and the system clock frequency to ensure that the cycle time of each SysTick count is reduced to 0 and reloaded is exactly the set value us.
[0060] The WaitSysTimerEnd() function is used to wait for the end of the notification timing cycle. This function is implemented by querying whether the COUNTFLAG bit in the status register of SysTick is 1. In this example, bit 0 and bit 16 of SysTick->CTRL represent the start bit of the system tick timing and the COUNTFLAG bit respectively. After COUNTFLAG is read, it will be automatically cleared by the hardware.
[0061] For specific code implementation examples of the functions GetTicksNow and Calc_dSysTimeToNow_us, refer to Figure 3 As shown, by calling the function GetTicksNow(&stTime) at the waiting start time and using the code while(Calc_dSysTimeToNow_us(&stTime)<WAIT_ACC1TX_US){} during the loop waiting, it is possible to generate a specified waiting time in a non-interrupt manner using the same SysTick as the notification timing. The reason for not using the interrupt timing method here is intentional because the data received by each serial port is received in the idle interrupt in DMA mode, and the main thread really needs to wait for a specified time in a polling manner. Figure 6 The function GetTime_us shown provides a method of how to generate a timestamp of the current moment using SysTick. The timestamp generated by this example function is in microseconds.
[0062] The packetization timestamp of the circular queue element is calculated from the system tick clock count value read during packetization and the reload count. That is, the calculation method of the packetization timestamp time_us is: time_us = [loadCnt+(load+1-val) / (load+1)] * TRIG_PERIOD, where TRIG_PERIOD is the notification period of the server, loadCnt is the reload count during packetization, and load is the reload count value of the system tick clock.
[0063] Therefore, this solution provides a way to trigger an interrupt to notify the controlled device to generate an accurate timing cycle on the premise of only using the non-interrupt timing method of the same system tick clock SysTick, and can generate an accurate timestamp during packetization transmission, ensuring the real-time and periodicity of the collected data received in summary.
[0064] Then in step S530, after receiving the data sent by the controlled device from the transmission stream of the DMA channel corresponding to each serial port, it enters the corresponding receive idle interrupt handling function. In the interrupt handling function, the received data is parsed and the parsed data is saved in the circular queue.
[0065] Specifically, after the server device completes handshake synchronization with each controlled device, a DMA receiving buffer is set for each serial port, DMA receiving is enabled, and the receiving first address is specified as the DMA receiving buffer first address, and the receiving length is specified as the buffer length size.
[0066] When the serial port receives an idle interrupt, the serial port DMA channel stops receiving, and the actual received data length is calculated based on the remaining length of the buffer and the total length of the buffer. That is, when the server enters the serial port receive idle interrupt processing function, it immediately stops the reception of the serial port DMA channel, and then calculates the actual amount of data received through the serial port rxLen = size - remain based on the remaining length of the DMA channel's receive transmission stream and the specified receive length size.
[0067] The transmission stream with a length of the actual received data length in the DMA receiving buffer is parsed according to a predetermined format and saved in a global variable. The transmission stream with a length of rxLen in the DMA receiving buffer can be parsed from left to right into the collected data according to the data format agreed with the controlled device and saved in a global variable.
[0068] Enable DMA receiving again, reconfigure the first address of the DMA receiving buffer and specify the receiving length to continue receiving subsequent data. The specified receiving length is greater than the maximum length of a single packet received from the serial port. Furthermore, the specified receiving length should be much greater than the maximum length of a single packet expected to be received.
[0069] In one embodiment of the present invention, when the serial port receives idle interrupts to receive and parse the transmission stream received in the current DMA receiving buffer whose length is the actual received data length, if errors of missing buffer packet format and missing packet length are detected, the data that failed to be parsed is abandoned and the next DMA reception is directly started. In this way, errors in the format and length of the received data packets can be effectively handled, and the system can continuously receive valid data.
[0070] The length of a single packet in the DMA buffer for a single receive cache is calculated based on the remaining length of the DMA channel transmission stream. After unpacking is completed, DMA reception is enabled again, which avoids the problem of receiving sticky packets, improves unpacking efficiency, and reduces CPU occupancy time during data transmission.
[0071] Figure 7 FIG. 2 shows an example of a serial port receiving idle interrupt processing function code according to an embodiment of the present invention. Figure 7 As shown, HAL_UARTEx_RxEventCallback is the serial port receiving idle interrupt processing function. Figure 7devNO in the figure is the number of the controlled device. Each controlled device creates an information handle gszhDev[devNO]. When the server enters the serial port receiving idle interrupt processing function, it immediately stops the reception of the DMA channel of the serial port, and then calculates the amount of data actually received through the serial port rxLen = size - remain based on the remaining length remain of the receiving transmission stream of the DMA channel and the specified receiving length size. According to the data format agreed with the controlled device, the transmission stream with a length of rxLen in the DMA receiving buffer is parsed from left to right into the collected data and saved in the global variable, and then the DMA reception is turned on again and the receiving first address is specified as the DMA receiving buffer first address and the receiving length is specified as the buffer length size. The specified receiving length size should be much larger than the maximum length of a single packet that may be received from the serial port.
[0072] If the specified receiving length size is large enough, theoretically, this round of DMA cannot receive all the data of length size, and the serial port receiving idle interrupt will be entered to stop DMA receiving, and the next round of DMA receiving will be started after unpacking. Therefore, theoretically, even if the DMA receiving completion interrupt is not implemented, it will not affect the implementation of the present invention. However, in order to prevent the situation where the pre-set size is not large enough, this callback function is still implemented.
[0073] Finally, step S540 is executed to wait for a specified time in each timing cycle, summarize and calculate the data collected by each controlled device, and send the calculation result to the client host computer through the serial port in DMA mode.
[0074] The designated waiting time of the server within the timing cycle is the notification cycle time minus the maximum estimated time required to receive, summarize and calculate the data collected by each serial port, that is, the designated waiting time is less than the notification cycle.
[0075] Waiting for the specified time in this round of timing cycle specifically includes: immediately reading SysTick and creating local variables to save SysTick's tick count value val1 and SysTick's reload count number loadCnt1 after the server notifies the controlled device by triggering a GPIO interrupt, and then repeatedly reading the current SysTick's tick count value val2 and SysTick's reload count number loadCnt2 until the time interval dTime between the current moment and the notification moment is calculated to be greater than or equal to the specified waiting time. Among them, the specified waiting time is the periodic notification time minus the maximum estimated time required to receive, summarize, and calculate and process the collected data of each serial port. The time interval dTime between the current moment and the notification moment is: dTime=[(val1-val2) / (load+1)+loadCnt2-loadCnt1]*TRIG_PERIOD, where load is the reload count value, TRIG_PERIOD is the notification period of the server, val1 is the initial count value of the system tick clock, val2 is the current count value of the system tick clock, loadCnt1 is the initial reload count, and loadCnt2 is the current reload count.
[0076] The circular queue is a first-in-first-out data structure. When writing to the queue, the queue element is inserted into the queue space indicated by the tail position number and the tail position number is updated to WrId = (WrId +1) % MAX. When reading the queue, the queue element indicated by the head position number is read and the head position number is updated to RdId = (RdId +1) % MAX, where MAX is the maximum number of queue elements that the circular queue can accommodate. When the main thread has not received the data collected by all controlled devices after waiting for the specified time in this round of timing cycle, the queue element saved by the summary calculation of the previous round of timing cycle is found through the queue tail position number. The packet ID of the queue element sent to the client host computer through the serial port in each timing cycle is always equal to the queue head position number RdId, so as to ensure that the client host computer can check whether there is any packet loss during the transmission process by checking whether the received packet ID is continuous.
[0077] By using a circular queue to cache calculation results and using the head position ID as the packet ID to be sent, when all collected data are not received within a timeout, the most recently sent data packet can be quickly found, and the data valid flag can be cleared and sent to the client host computer. This not only ensures the continuity of the client host computer's graphical display, but also facilitates the client host computer to quickly identify errors such as transmission packet loss and failure to receive collected data from a controlled device.
[0078] In summary, the multi-machine communication data processing method and multi-machine communication system based on serial port provided by the present invention can at least achieve the following beneficial effects: (1) Each serial port's Tx and Rx channels are bound to a transmission stream of a unique DMA channel, ensuring that each serial port data channel is independent and improving serial port data transmission efficiency; (2) Register the receive idle interrupt for each serial port respectively. In the receive idle interrupt processing function, the length of a single packet in the DMA buffer is calculated by the remaining length of the DMA channel transmission stream, and the DMA reception is enabled again after the unpacking is completed. This avoids the problem of receiving sticky packets, improves the unpacking efficiency, and reduces the CPU occupancy time during the data transmission process. (3) Under the premise of using only the non-interrupt timing method of the same system tick clock SysTick, it also provides a method for generating an accurate timing cycle for triggering an interrupt to notify the controlled device, a method for generating a fixed timeout specified time for waiting for packet reception within the timing cycle, and a method for generating an accurate timestamp when sending the packet, thereby ensuring the real-time and periodicity of the collected data received in aggregate; (4) The head position ID of the circular queue is used as the packet ID. When all collected data are not received within a timeout period, the most recently sent packet can be quickly found from the circular queue and the data valid flag can be cleared to zero before being sent to the client host computer. This ensures the continuity of the graphical display of the client host computer and facilitates the client to quickly identify errors such as packet loss and failure to receive collected data.
[0079] Therefore, this solution can periodically notify the controlled devices to collect data or signals, receive data sent by multiple controlled devices through the serial port in real time, and quickly and accurately summarize and calculate the data before sending it to the client host computer, solving the performance problem of using serial ports for multi-machine communication.
[0080] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0081] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0082] Those skilled in the art will appreciate that the modules or units or components of the devices in the examples disclosed herein may be arranged in the devices described in the embodiment, or alternatively may be located in one or more devices different from the devices in the examples. The modules in the foregoing examples may be combined into one module or may be divided into multiple submodules.
[0083] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and further may be divided into a plurality of submodules or subunits or subcomponents. All features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device so disclosed may be combined in any combination, except that at least some of such features and / or processes or units are mutually exclusive. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature that provides the same, equivalent or similar purpose.
[0084] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0085] In addition, some of the embodiments are described herein as a combination of methods or method elements that can be implemented by a processor of a computer system or by other devices that perform functions. Therefore, a processor with necessary instructions for implementing a method or method element forms a device for implementing the method or method element. In addition, the elements described herein of the device embodiment are examples of devices that are used to implement the functions performed by the elements for the purpose of implementing the invention.
[0086] As used herein, unless otherwise specified, the use of ordinal numbers "first," "second," "third," etc. to describe common objects merely indicates that different instances of similar objects are involved, and is not intended to imply that the objects so described must have a given order in time, space, order, or in any other manner.
[0087] Although the present invention has been described according to a limited number of embodiments, it will be apparent to those skilled in the art, with the benefit of the above description, that other embodiments may be envisioned within the scope of the invention thus described. In addition, it should be noted that the language used in this specification is selected primarily for readability and teaching purposes, rather than for explaining or defining the subject matter of the present invention. Therefore, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the present invention is illustrative and not restrictive with respect to the scope of the present invention, and the scope of the present invention is defined by the appended claims.
Claims
1. A multi-machine communication data processing method based on serial port, implemented based on a server device, wherein the server device communicates with a client host computer and one or more controlled devices through a serial port respectively, and the server device is used to periodically send pulses to trigger the one or more controlled devices to send collected data, and summarize and calculate the data received from the controlled devices in each cycle and then send them to the client host computer, characterized in that: The method comprises: The server device and each controlled device perform power-on initialization and handshake synchronization, wherein the power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, so that the sending channel and the receiving channel of each serial port are respectively bound to a transmission stream of a unique DMA channel, registering a receiving idle interrupt for each serial port, and creating a circular queue for storing the calculation results of the collected data of the controlled devices received after the summary processing in each cycle, wherein the queue elements of the circular queue at least include the packet ID, the packet grouping timestamp, the calculation results and the valid flag of the collected data of each controlled device; Starting the system tick clock to perform periodic timing, sending the pulse or triggering an interrupt at the beginning of each timing cycle to notify each controlled device to start sending data; After receiving the data sent by the controlled device from the transmission stream of the DMA channel corresponding to each serial port, the corresponding receiving idle interrupt processing function is entered, the received data is parsed in the interrupt processing function, and the parsed data is stored in the ring queue; After waiting for a specified time in each timing cycle, the data collected by each controlled device is summarized and processed, and the calculation results are sent to the client host computer through the serial port in DMA mode.
2. The method for processing multi-machine communication data based on serial port according to claim 1, characterized in that: The steps of handshake synchronization include: After the controlled device is powered on and initialized, the agreed value is written to the specified register; After the server device is powered on and initialized, it cyclically reads the designated register until the agreed value is read out, and the server device shakes hands with the controlled device successfully. When the server device shakes hands with all controlled devices successfully, the handshake synchronization is completed.
3. The method for processing multi-machine communication data based on serial port according to claim 1, characterized in that: The step of starting the system tick clock to perform periodic timing and sending the pulse or triggering an interrupt to notify each controlled device to start sending data at the beginning of each timing cycle includes: Set the reload value of the system tick clock according to the system tick clock frequency, so that the reload cycle time of each round of the system tick clock is equal to the periodic notification time required by the server; The counter value of the system tick clock is cleared and the system tick clock timer is started. The status register of the system tick clock is read repeatedly until the value of the reload flag COUNTFLAG in the status register of the system tick clock is 1. The count value of the system tick clock counter is cleared and a pulse is sent to each controlled device to trigger a GPIO interrupt to notify each controlled device to send data. The COUNTFLAG flag is automatically set to 1 by the hardware when the count value decreases to 0, and the COUNTFLAG flag is automatically cleared by the hardware when it is read.
4. The method for processing multi-machine communication data based on serial port according to claim 3, characterized in that: The packet assembly timestamp of the queue element is calculated by the system tick clock count value and the number of reloads read during packet assembly. The calculation method of the packet assembly timestamp is: time_us = [loadCnt+(load+1-val) / (load+1)] * TRIG_PERIOD, where time_us is the packet assembly timestamp, TRIG_PERIOD is the notification period of the server, loadCnt is the number of reloads during packet assembly, and load is the reload count value of the system tick clock.
5. The method for processing multi-machine communication data based on serial port according to claim 1, characterized in that: The step of parsing the received data in the interrupt processing function and storing the parsed data in the ring queue comprises: After the server device completes handshake synchronization with each controlled device, set up a DMA receive buffer for each serial port, start DMA reception, and specify the receiving first address as the DMA receive buffer first address and the receiving length as the buffer length; When the serial port receives an idle interrupt, the reception of the transmission stream of the serial port DMA channel is stopped, and the actual received data length rxLen of the serial port is calculated according to the specified receiving length size and the number of data units remaining in this DMA stream transmission HAL_DMA_GET_COUNTER, where rxLen=size-HAL_DMA_GET_COUNTER; Parse the data stream with the length rxLen starting from the first address of the DMA receiving buffer according to the protocol format predetermined with the sender, and save the parsing result to the global variable; The DMA receiving is enabled again, and the first address and the designated receiving length of the DMA receiving buffer are reconfigured to continue receiving subsequent data, wherein the designated receiving length is greater than the estimated maximum length of a single packet received from the serial port.
6. The method for processing multi-machine communication data based on serial ports according to claim 5, characterized in that: When the serial port receiving idle interrupt receives and parses the transmission stream received in this DMA receiving buffer with a length equal to the actual received data length, if errors such as missing cache packet format and missing packet length are detected, the data whose parsing failed is abandoned and the next DMA reception is directly started.
7. The method for processing multi-machine communication data based on serial ports according to claim 1, characterized in that: The steps of waiting for a specified time in each timing cycle, summarizing and calculating the data collected by each controlled device, and sending the calculation results to the client host computer through the serial port in DMA mode include: Wait for a specified time in this round of timing cycle. If the data sent by all controlled devices are successfully received and parsed within the specified time, the data collected by each controlled device is summarized and calculated and processed to generate a new queue element to be inserted into the circular queue. The head element of the circular queue is sent to the client host computer through the serial port in DMA mode. The queue element contains the packet ID, the packet group timestamp, the data calculation result and the valid flag bit of the data collected by the controlled device; If the data collected by all controlled devices are not received within the specified time, a new queue element is generated and inserted into the tail of the ring queue. The member values of the new queue element are the same as those of the previous queue element. The valid flag of the collected data of the controlled device that has not received the data is cleared to zero, and the package ID is updated. The head element of the ring queue is sent to the client host computer through the serial port in DMA mode; Wait for the timing cycle to end and continue to receive and process data in the next timing cycle.
8. The method for processing multi-machine communication data based on serial ports according to claim 7, characterized in that: The step of waiting for a specified time in each timing cycle includes: The server triggers a GPIO interrupt, notifies the controlled device, and immediately reads the system tick clock and creates a local variable to save the initial count value of the system tick clock and the initial reload count; Repeatedly read the current count value of the system tick clock and the current reload count until the calculated time interval between the current moment and the notification moment is greater than or equal to the waiting specified time, wherein the waiting specified time is the periodic notification time minus the maximum estimated time required to receive, summarize and calculate and process the collected data of each serial port, and the time interval between the current moment and the notification moment is: dTime=[(val1-val2) / (load+1)+ loadCnt2-loadCnt1] * TRIG_PERIOD, where load is the reload count value, TRIG_PERIOD is the notification period of the server, val1 is the initial count value of the system tick clock, val2 is the current count value of the system tick clock, loadCnt1 is the initial reload count, and loadCnt2 is the current reload count.
9. The method for processing multi-machine communication data based on serial ports according to claim 1, characterized in that: The circular queue is a first-in-first-out data structure. When writing to the queue, the queue element is inserted into the queue space indicated by the tail position number and the tail position number is updated to WrId = (WrId +1) % MAX. When reading the queue, the queue element indicated by the head position number is read and the head position number is updated to RdId = (RdId +1) % MAX, where MAX is the maximum number of queue elements that the circular queue can accommodate. When the main thread has waited for the specified time within the current timing cycle and still has not received the data collected by all controlled devices, the queue element saved by the summary calculation of the previous timing cycle is found through the queue tail position number. The packet ID of the queue element sent to the client host computer through the serial port in each timing cycle is always equal to the queue head position number.
10. A multi-machine communication system based on serial port, characterized in that: include: Client host computer, server device, multiple controlled devices and UART interface for multi-machine communication; The client host computer runs a user interface program for graphically displaying the data or signals after the summary calculation and processing; The controlled device is an embedded computer or a device for collecting data or signals. The controlled device has a serial port, which is used to collect data in real time and send it to the server device through the serial port after receiving a notification from the server device; The server device is provided with multiple serial ports, each of which is used to communicate with the client host computer or a unique controlled device. The server device runs server software, which is used to periodically send pulses to trigger one or more controlled devices to send real-time collected data, and summarize and calculate the data received from the controlled devices in each cycle and send them to the client host computer, specifically including: The server device and each controlled device perform power-on initialization and handshake synchronization, wherein the power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, so that the sending channel and the receiving channel of each serial port are respectively bound to a unique DMA channel, registering a receiving idle interrupt for each serial port, and creating a circular queue for storing the calculation results of the collected data of the controlled devices received after the summary processing in each cycle, wherein the queue elements of the circular queue at least include the packet ID, the packet grouping timestamp, the calculation results and the valid flag of the collected data of each controlled device; waiting for all controlled devices to be successfully powered on and initialized before the handshake is completed; Starting the system tick clock to perform periodic timing, sending the pulse or triggering an interrupt at the beginning of each timing cycle to notify each controlled device to start sending data; After receiving the data sent by the controlled device from the DMA channel corresponding to each serial port, the corresponding receiving idle interrupt processing function is entered, the received data is parsed in the interrupt processing function, and the parsed data is stored in the ring queue; After waiting for a specified time in each timing cycle, the data collected by each controlled device is summarized and processed, and the calculation results are sent to the client host computer through the serial port in DMA mode.
Citation Information
Patent Citations
Real-time, concurrent, multifunction digital signal processor subsystem for personal computers
CA2074633A1
Data bus bridge and its working method
CN101018179A
UART (universal asynchronous receiver / transmitter) serial port communication method based on GPIO (general purpose input / output) handshake and EDMA (enhanced direct memory access)
CN106155960A
Multi-channel HDLC control system and data uploading method and data issuing method thereof
CN116847007A
Time-triggered co-operative hardware scheduler
WO2007028942A1