Multi-device cross-cycle serial port multiplexing method based on state machine

By adopting the state machine-based serial port multiplexing method in the embedded system, the problems of difficulty in receiving data across cycles and sending time conflicts are solved, and the integrity of data reception and the reliability of communication are achieved.

CN119341858APending Publication Date: 2025-01-21BEIJING INST OF CONTROL ENG
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411084786.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-08
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

In the prior art, it is difficult to receive data across cycles, and the time when the MCU sends to the upper computer and the ground detection device may conflict, resulting in incomplete data transmission or time conflicts that last for multiple cycles.

Method used

A multi-device cross-cycle serial port multiplexing method based on a state machine is adopted. By presetting the control cycle and the state machine working mode, the state machine working mode is adjusted to achieve cross-cycle data reception and transmission to avoid time conflicts.

Benefits of technology

It ensures the completeness of data reception under cross-cycle conditions and avoids conflicts in the sending time of the MCU to the upper computer and ground inspection equipment, ensuring the accuracy of data and the reliability of communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119341858A_ABST
    Figure CN119341858A_ABST
Patent Text Reader

Abstract

A multi-device cross-cycle serial port multiplexing method based on a state machine comprises three processes of receiving, sending to an upper computer and sending to a ground detector, a serial port receiving and sending process is abstracted into the state machine, and state transfer is realized through adjustment of working modes of different control processes of the state machine so as to control a communication process. Conflicts during multi-device cross-period multiplexing can be effectively avoided, and the communication reliability is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a state machine-based multi-device cross-cycle serial port multiplexing method, belonging to the technical field of embedded device communication. Background Art

[0002] The processor MCU of the embedded system uses the RS422 asynchronous serial port to communicate with the host computer and the ground inspection device. The three form a star topology centered on the MCU. The MCU is the passive party in the communication with the host computer. After receiving the synchronization signal from the host computer, it prepares the data to be sent, and starts sending after receiving the data acquisition instruction from the host computer. In addition, the MCU also needs to receive other instructions from the host computer, and the length is not fixed. The communication between the MCU and the ground inspection device is unidirectional, and only the MCU sends to the ground inspection, and the ground inspection does not send to the MCU. The MCU has only one serial port resource, which needs to be multiplexed between the host computer and the ground inspection. The software sets the communication object through a multiplexing selection register MUX_REG.

[0003] The control cycle of the software on the MCU is T1 = 400us, the communication cycle with the host computer is T2 = 125ms, and the communication cycle with the ground inspection device is T3 = 10ms. From the communication cycle, it can be seen that the time when the MCU sends to the host computer and sends to the ground inspection may conflict. The size of the MCU's serial port send FIFO is 16 bytes, and the receive FIFO is 8 bytes. The length of the MCU's send and receive may be larger than the FIFO, so it must be able to meet the cross-cycle transmission and reception situation. The serial port baud rate is f baud =115.2kbps, the transmission format is 1 start bit, 8 data bits, 1 parity bit and 1 stop bit. It can be seen that the transmission time of a single byte of data is about 95.5us. In a control cycle T1 interval, only 4 bytes can be fully transmitted. The problems to be solved include:

[0004] (1) The software receives 4 bytes of data per cycle, and the size of the receive FIFO is 8 bytes, both of which are less than the data that should be received. The software needs multiple cycles to receive all the data, and the FIFO must be read in each cycle to avoid overflow. That is, it is necessary to ensure that the data is received completely in the case of cross-cycle reception;

[0005] (2) The time when the MCU sends data to the host computer and the ground detection device may conflict, and the conflict may last for multiple cycles. When switching the sending object at any stage of the sending, in addition to ensuring that the data in the sending FIFO is for the corresponding device, it is also necessary to consider whether there is still data on the shift register and the sending port. Therefore, a cross-cycle multiplexing strategy is required to ensure that the data can be sent accurately and completely. Summary of the invention

[0006] The technical problem solved by the present invention is: in view of the problems in the current prior art of difficulty in receiving data across cycles and conflict in data sending time between the host computer and ground inspection equipment, a multi-device cross-cycle serial port multiplexing method based on a state machine is proposed.

[0007] The present invention solves the above technical problems by the following technical solutions:

[0008] A multi-device cross-cycle serial port multiplexing method based on a state machine, comprising:

[0009] Preset control cycle and state machine working mode corresponding to each control process;

[0010] In the first stage of the control process, the state machine working mode is adjusted by receiving the FIFO judgment result, and the first stage of the control process is ended when all the state machine working modes have been traversed;

[0011] In the second stage control process, the data acquisition instruction is judged, and the ground detection state machine flag is changed according to the judgment result and the state machine working mode is adjusted;

[0012] After setting the host computer, write the data and send it. After the data is sent, the second stage of the control process ends;

[0013] In the third stage control process, the state machine working mode is adjusted by sending the FIFO judgment result;

[0014] After setting up the ground inspection equipment, write the data and send it. After the data is sent, the third stage of the control process ends.

[0015] The control process includes a receiving process, a sending process to an upper computer, and a sending process to a ground inspection device;

[0016] The state machine working modes corresponding to the receiving process include idle mode, receiving mode, waiting mode, and completion mode;

[0017] The state machine working modes corresponding to the sending process to the upper computer include idle mode, ready mode, and sending mode;

[0018] The state machine working modes corresponding to the process of sending to the ground inspection equipment include idle mode, preparation mode, and sending mode;

[0019] The receiving process, the sending process to the upper computer, and the sending process to the ground inspection device are progressive processes. The adjustment of the state machine working mode corresponding to each control process is progressive. When the state machine working mode of any control process is completed, the current control process is reset and the next control process starts.

[0020] The specific state machine working mode adjustment method of the receiving process is as follows:

[0021] The default state machine is in idle mode. In idle mode, it determines whether the receive FIFO is empty. If it is not empty, it enters the receive mode. Otherwise, it stays in idle mode and waits for the receive FIFO.

[0022] In the receiving mode, determine whether the receiving FIFO is empty. If not, read the FIFO to empty and save the data in the RxBuf array, wait for the count CntRcv to be cleared, and maintain the state machine working mode in the receiving mode; if it is empty, enter the waiting mode;

[0023] In the waiting mode, determine whether the receiving FIFO is empty. If not, adjust the state machine working mode back to the receiving mode; otherwise, add 1 to the count CntRcv and determine that if the count CntRcv is not greater than the waiting threshold Lmt, maintain the state machine working mode in the waiting mode; if the count CntRcv is greater than the waiting threshold Lmt, adjust the state machine working mode to the completion mode;

[0024] In the completion mode, the count CntRcv is cleared to zero and the mode is restored to the idle mode, and the first control process is completed.

[0025] The waiting threshold Lmt is determined according to the communication timing and operation timing of the state machine;

[0026] In the completion mode, the count CntRcv is cleared to zero and then the correctness of the received data is judged. Regardless of whether the judgment result is correct or not, the state machine working mode is restored to the idle mode.

[0027] The specific method of adjusting the state machine working mode and sending data during the sending process to the upper computer is:

[0028] The default state machine is in idle mode. In idle mode, it determines whether a fetch instruction is received. If received, it enters the preparation mode; otherwise, it stays in idle mode and waits for receiving a fetch instruction.

[0029] In the preparation mode, the FlgGnd flag of the ground detection state machine is set to False, the ground detection state machine is set to idle, and the sending buffer is cleared to enter the sending mode;

[0030] In the sending mode, the register is selected and set to select the host computer, the received data is written into the sending FIFO, and the sending is enabled; during the sending process, the length of the sent data is recorded and the length is judged. If the length of the sent data is less than the length that should be sent, the sending mode is maintained until the length of the sent data is not less than the length that should be sent. The state machine working mode is adjusted to return to the idle mode to complete the second control process.

[0031] The sending cycle of the sending process to the upper computer is determined according to the data acquisition instruction. In the preparation mode, the FlgGnd flag of the ground detection state machine and the working mode of the ground detection state machine are adjusted to interrupt the sending of the ground detection state machine and make the sending process to the upper computer enter the next working mode.

[0032] The specific method of adjusting the state machine working mode and sending data during the sending process to the ground inspection device is:

[0033] The default state machine is in idle mode. In idle mode, it is determined whether the transmit FIFO is empty. If it is empty, the state machine working mode is adjusted to enter the ready mode.

[0034] Otherwise, the count GndCnt is cleared to stop the current transmission;

[0035] In the preparation mode, it is determined again whether the transmit FIFO is empty. If it is empty, the current data has not been sent to the host computer, and the transmit mode is entered; otherwise, the current data is already in the transmit mode, and the state machine working mode is adjusted to enter the idle mode;

[0036] In the transmit mode, the select register is set to select the ground detection device, the data is written into the transmit FIFO, the transmission is enabled, and the state machine working mode is adjusted back to the idle mode, completing the third stage of the control process.

[0037] The total control cycle of the control process consisting of the receiving process, the sending process to the upper computer, and the sending process to the ground inspection device is T1; the control cycle of the sending process to the upper computer is T2, which is determined according to the data acquisition instruction; the control cycle of the sending process to the ground inspection device is T3, and the count GndCnt is increased by 1 in each control cycle T1. When the GndCnt value reaches When the ground inspection device is detected, data is sent once.

[0038] In the preparation mode of the sending process to the upper computer, the sending buffer is cleared by writing a register to prohibit or send the ongoing data to the ground inspection device at the big end; in the idle state of the sending process to the ground inspection device, it is determined whether the sending FIFO is empty, and the interruption of the ongoing data sending process to the upper computer is avoided according to the judgment result.

[0039] In the sending mode of the process of sending to the upper computer, the selection register MUX_REG is set to select the upper computer; in the sending mode of the process of sending to the ground detection device, the selection register MUX_REG is set to select the ground detection device.

[0040] The advantages of the present invention compared with the prior art are:

[0041] The present invention provides a multi-device cross-cycle serial port multiplexing method based on a state machine, which includes three processes of receiving, sending to a host computer and sending to a ground detection device. The serial port receiving and sending process is abstracted into a state machine, and the communication process is controlled by the transfer of states. The method can effectively avoid conflicts during cross-cycle multiplexing of multiple devices, and can ensure complete data reception in the case of cross-cycle reception. At the same time, it can avoid time conflicts in MCU sending to a host computer and a ground detection device, ensure the data in the sending FIFO is related to the device, and there is no need to consider data omissions in the shift register and the sending port, thereby ensuring the reliability of communication. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A schematic diagram of the system communication structure provided for the invention;

[0043] Figure 2 A schematic diagram of a receiving process state machine provided for the invention;

[0044] Figure 3 A schematic diagram of a state machine for sending a process to a host computer provided by the invention;

[0045] Figure 4 A schematic diagram of a state machine for the process of sending to ground inspection provided by the invention; DETAILED DESCRIPTION

[0046] A multi-device cross-cycle serial port multiplexing method based on a state machine includes three processes: receiving, sending to an upper computer, and sending to a ground detector. By abstracting the receiving and sending process of the serial port into a state machine and adjusting the working mode of different control processes of the state machine to realize state transfer to control the communication process, conflicts when multiple devices are multiplexed across cycles can be effectively avoided, thereby ensuring the reliability of communication.

[0047] The method for multiplexing serial ports across cycles of multiple devices based on a state machine has the following specific steps:

[0048] Preset control cycle and state machine working mode corresponding to each control process;

[0049] In the first stage of the control process, the state machine working mode is adjusted by receiving the FIFO judgment result, and the first stage of the control process is ended when all the state machine working modes have been traversed;

[0050] In the second stage control process, the data acquisition instruction is judged, and the ground detection state machine flag is changed according to the judgment result and the state machine working mode is adjusted;

[0051] After setting the host computer, write the data and send it. After the data is sent, the second stage of the control process ends;

[0052] In the third stage control process, the state machine working mode is adjusted by sending the FIFO judgment result;

[0053] After setting up the ground inspection equipment, write the data and send it. After the data is sent, the third stage of the control process ends.

[0054] Specifically, the control process includes the receiving process, the sending process to the upper computer, and the sending process to the ground inspection equipment;

[0055] The state machine working modes corresponding to the receiving process include idle mode, receiving mode, waiting mode, and completion mode;

[0056] The state machine working modes corresponding to the sending process to the upper computer include idle mode, ready mode, and sending mode;

[0057] The state machine working modes corresponding to the process of sending to the ground inspection equipment include idle mode, preparation mode, and sending mode;

[0058] The receiving process, the sending process to the upper computer, and the sending process to the ground inspection device are progressive processes. The adjustment of the state machine working mode corresponding to each control process is progressive. When the state machine working mode of any control process is completed, the current control process is reset and the next control process starts.

[0059] The specific state machine working mode adjustment method of the receiving process is as follows:

[0060] The default state machine is in idle mode. In idle mode, it determines whether the receive FIFO is empty. If it is not empty, it enters the receive mode. Otherwise, it stays in idle mode and waits for the receive FIFO.

[0061] In the receiving mode, determine whether the receiving FIFO is empty. If not, read the FIFO to empty and save the data in the RxBuf array, wait for the count CntRcv to be cleared, and maintain the state machine working mode in the receiving mode; if it is empty, enter the waiting mode;

[0062] In the waiting mode, determine whether the receiving FIFO is empty. If not, adjust the state machine working mode back to the receiving mode; otherwise, add 1 to the count CntRcv and determine that if the count CntRcv is not greater than the waiting threshold Lmt, maintain the state machine working mode in the waiting mode; if the count CntRcv is greater than the waiting threshold Lmt, adjust the state machine working mode to the completion mode;

[0063] In the completion mode, the count CntRcv is cleared to zero and the mode is restored to the idle mode, and the first control process is completed.

[0064] The waiting threshold Lmt is determined according to the communication timing and operation timing of the state machine;

[0065] In the completion mode, the count CntRcv is cleared to zero and then the correctness of the received data is judged. Regardless of whether the judgment result is correct or not, the state machine working mode is restored to the idle mode.

[0066] The specific method of adjusting the state machine working mode and sending data to the upper computer is as follows:

[0067] The default state machine is in idle mode. In idle mode, it determines whether a fetch instruction is received. If received, it enters the preparation mode; otherwise, it stays in idle mode and waits for receiving a fetch instruction.

[0068] In the preparation mode, the FlgGnd flag of the ground detection state machine is set to False, the ground detection state machine is set to idle, and the sending buffer is cleared to enter the sending mode;

[0069] In the sending mode, the register is selected and set to select the host computer, the received data is written into the sending FIFO, and the sending is enabled; during the sending process, the length of the sent data is recorded and the length is judged. If the length of the sent data is less than the length that should be sent, the sending mode is maintained until the length of the sent data is not less than the length that should be sent. The state machine working mode is adjusted to return to the idle mode to complete the second control process.

[0070] The sending cycle of the sending process to the upper computer is determined according to the data acquisition instruction. In the preparation mode, the FlgGnd flag of the ground detection state machine and the working mode of the ground detection state machine are adjusted to interrupt the sending of the ground detection state machine and make the sending process to the upper computer enter the next working mode.

[0071] The specific method of sending data to the ground inspection device to adjust the state machine working mode and send data is:

[0072] The default state machine is in idle mode. In idle mode, it is determined whether the transmit FIFO is empty. If it is empty, the state machine working mode is adjusted to enter the ready mode.

[0073] Otherwise, the count GndCnt is cleared to stop the current transmission;

[0074] In the preparation mode, it is determined again whether the transmit FIFO is empty. If it is empty, the current data has not been sent to the host computer, and the transmit mode is entered; otherwise, the current data is already in the transmit mode, and the state machine working mode is adjusted to enter the idle mode;

[0075] In the transmit mode, the select register is set to select the ground detection device, the data is written into the transmit FIFO, the transmission is enabled, and the state machine working mode is adjusted back to the idle mode, completing the third stage of the control process.

[0076] The total control cycle of the control process consisting of the receiving process, the sending process to the upper computer, and the sending process to the ground inspection device is T1; the control cycle of the sending process to the upper computer is T2, which is determined according to the data acquisition instruction; the control cycle of the sending process to the ground inspection device is T3, and the count GndCnt is increased by 1 in each control cycle T1. When the GndCnt value reaches When the ground inspection device is detected, data is sent once.

[0077] In the preparation mode of the sending process to the upper computer, the sending buffer is cleared by writing a register to prohibit or send the ongoing data to the ground inspection device at the big end; in the idle state of the sending process to the ground inspection device, it is determined whether the sending FIFO is empty, and the interruption of the ongoing data sending process to the upper computer is avoided according to the judgment result.

[0078] In the sending mode of the process of sending to the upper computer, the selection register MUX_REG is set to select the upper computer; in the sending mode of the process of sending to the ground detection device, the selection register MUX_REG is set to select the ground detection device.

[0079] The following is further described in conjunction with the accompanying drawings and preferred embodiments of the specification:

[0080] In the current embodiment, when the MCU is receiving, there are two situations for the receiving FIFO: the FIFO is empty and the FIFO is not empty. The change from empty to not empty indicates that the data is being received, and the change from not empty to empty may be because the reception is completed, or it may be because the sender has a long interval. Therefore, the reception is considered to be completed only when the receiving FIFO is continuously judged to be empty, otherwise it continues to receive. The software uses a state machine to abstract the process of the MCU receiving data from the host computer, and divides the state into four states: idle, receiving, waiting, and receiving completed. Initially, it is "idle". When the query finds that the receiving FIFO is not empty, it is converted to "receiving" and the FIFO is read empty. When the FIFO is found to be empty in "receiving", it enters "waiting". After staying in "waiting" for N consecutive operating cycles, it enters "complete", decodes the data, and sets the state to idle to prepare for the next reception.

[0081] For the sending process, the MCU stipulates that the priority of the host computer is higher than that of the ground detection device. The sending activity to the host computer can interrupt the ground detection, but not allowed. The state machine is used to abstract the sending process, and the states are divided into idle, ready and sending. For sending to the host computer, when the MCU receives the data acquisition instruction sent by the host computer, it changes from idle to "ready"; in "ready", the sending FIFO is cleared and the FlgGnd flag is set to False. The purpose is to prohibit or interrupt the ongoing ground detection sending activity and turn to "send". In "send", all data is written to the sending FIFO, and then it turns to "idle". For sending to the ground detection, when the sending FIFO is checked to be empty, it changes from idle to ready; otherwise, it stays in idle, and no more sending to the ground detection is done in this communication cycle. In the ready state, if the sending FIFO is found to be empty, it enters the sending state, writes the data into the FIFO and starts sending; if the sending FIFO is found to be not empty, it returns to the idle state, and no more sending to the ground detection is done in this communication cycle. The purpose of the ready state is to wait for one more control cycle T1 between idle and sending to ensure that there is no content in the shift register, and then switch MUX_REG to perform ground detection and sending.

[0082] like Figure 1 As shown, it is a schematic diagram of the communication structure applied in this embodiment, and the process of the serial port multiplexing method of multiple devices across cycles is as follows:

[0083] It includes the process of receiving, sending to the upper computer and sending to the ground inspection device, and is executed in this order with the control cycle of T1.

[0084] The state machine of the receiving process includes idle S0, receiving S1, waiting S2 and completion S3, such as Figure 2 As shown:

[0085] (1) By default, it is in S0. When it is determined that the receive FIFO is not empty in S0, it will transfer to S1; otherwise, it will stop in S0 and continue to wait for reception;

[0086] (2) If it is determined in S1 that the receive FIFO is not empty, the FIFO is read empty and the data is saved in the RxBuf array, and the count CntRcv is waited for to be cleared, and the state stops at S1; if it is determined that the receive FIFO is empty, it is transferred to S2;

[0087] (3) In S2, if it is determined that the FIFO is not empty, then transfer to S1; otherwise, add 1 to CntRcv and determine that if CntRcv is not greater than the waiting threshold Lmt, then stop in S2, otherwise transfer to S3. The value of the threshold Lmt should be selected according to the communication and operation timing of the system. In this method, the calling interval of the receiving process is T1. Under normal communication conditions, the sender's data is continuous and 4 bytes of data should be received, so Lmt is set to 1;

[0088] (4) In S3, CntRcv is cleared to zero, and the correctness of the data is determined. Regardless of whether the data is correct or not, the data is transferred to S0.

[0089] After receiving, the process of sending to the high-priority host computer is executed. The state machine includes idle S0, ready S1 and send S2, such as Figure 3 As shown:

[0090] (5) By default, it is in S0. When it is determined that a data fetch instruction is received in S0, the state is transferred to S1. The data fetch instruction determines that the period sent to the upper computer is T2;

[0091] (6) In S1, the ground detection state machine is set to idle by setting the FlgGnd flag of the ground detection state machine to False, and the register is written to clear the send buffer, in order to prohibit or interrupt the ongoing ground detection transmission, and then the state is transferred to S2. The role of S1 is to leave a period of time T1 between idle and transmission. If the ground detection is being sent at this time, then the shift register and the serial port transmission port are the information sent to the ground detection, and after T1, these data can be sent;

[0092] (7) In S2, the select register MUX_REG is set to select the host computer, write the data into the transmit FIFO, and enable transmission. During the transmission process, the transmitted length is recorded. If it is less than the length to be transmitted, it stops in S2, otherwise it transfers to S0;

[0093] After sending to the upper computer, the low priority sending process to the ground is executed. The state machine includes idle S0, ready S1 and send S2, such as Figure 4 As shown, the communication cycle of the ground detection is T3. In each control cycle T1, GndCnt is increased by 1. When the value of GndCnt reaches When the data is sent to the ground inspection station, the sending process is as follows:

[0094] (8) The default state is S0. When the send FIFO is judged to be empty, the state is transferred to S1; otherwise, it stays in S0 and clears GndCnt to stop the current transmission. In order to avoid interrupting the ongoing transmission process to the upper computer when the FIFO is judged to be empty;

[0095] (9) In S1, the transmit FIFO is checked again. If it is empty, it means that it has not been sent to the upper computer. After the transfer from S0 to S1, it can be ensured that there is no data in the shift register and the transmit port, and the state is transferred to S2. Otherwise, it means that the transmission to the upper computer has started at this time, and the state is transferred to S0. At the same time, GndCnt is cleared to stop the current ground detection transmission.

[0096] (10) In S2, the select register MUX_REG is set to select the ground detection device, write the data to the transmit FIFO, enable transmission, and then the state is transferred to S0.

[0097] Although the present invention has been disclosed as above in the form of a preferred embodiment, it is not intended to limit the present invention. Any person skilled in the art may make possible changes and modifications to the technical solution of the present invention by using the methods and technical contents disclosed above without departing from the spirit and scope of the present invention. Therefore, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention shall fall within the protection scope of the technical solution of the present invention.

[0098] The contents not described in detail in the specification of the present invention belong to the common knowledge of those skilled in the art.

Claims

1. A method for multiple-device cross-cycle serial port multiplexing based on a state machine, characterized in that include: Preset control cycle and state machine working mode corresponding to each control process; In the first stage of the control process, the state machine working mode is adjusted by receiving the FIFO judgment result, and the first stage of the control process is ended when all the state machine working modes have been traversed; In the second stage control process, the data acquisition instruction is judged, and the ground detection state machine flag is changed according to the judgment result and the state machine working mode is adjusted; After setting the host computer, write the data and send it. After the data is sent, the second stage of the control process ends; In the third stage control process, the state machine working mode is adjusted by sending the FIFO judgment result; After setting up the ground inspection equipment, write the data and send it. After the data is sent, the third stage of the control process ends.

2. According to the state machine-based multi-device cross-cycle serial port multiplexing method according to claim 1, it is characterized in that: The control process includes a receiving process, a sending process to an upper computer, and a sending process to a ground inspection device; The state machine working modes corresponding to the receiving process include idle mode, receiving mode, waiting mode, and completion mode; The state machine working modes corresponding to the sending process to the upper computer include idle mode, ready mode, and sending mode; The state machine working modes corresponding to the process of sending to the ground inspection equipment include idle mode, preparation mode, and sending mode; The receiving process, the sending process to the upper computer, and the sending process to the ground inspection device are progressive processes. The adjustment of the state machine working mode corresponding to each control process is progressive. When the state machine working mode of any control process is completed, the current control process is reset and the next control process starts.

3. According to a state machine-based multi-device cross-cycle serial port multiplexing method according to claim 1, it is characterized in that: The specific state machine working mode adjustment method of the receiving process is as follows: The default state machine is in idle mode. In idle mode, it determines whether the receive FIFO is empty. If it is not empty, it enters the receive mode. Otherwise, it stays in idle mode and waits for the receive FIFO. In the receiving mode, determine whether the receiving FIFO is empty. If not, read the FIFO to empty and save the data in the RxBuf array, wait for the count CntRcv to be cleared, and maintain the state machine working mode in the receiving mode; if it is empty, enter the waiting mode; In the waiting mode, determine whether the receiving FIFO is empty. If not, adjust the state machine working mode back to the receiving mode. Otherwise, the count CntRcv is increased by 1 and judged. If the count CntRcv is not greater than the waiting threshold Lmt, the state machine working mode is maintained in the waiting mode; if the count CntRcv is greater than the waiting threshold Lmt, the state machine working mode is adjusted to the completion mode; In the completion mode, the count CntRcv is cleared to zero and the mode is restored to the idle mode, and the first control process is completed.

4. According to the state machine-based multi-device cross-cycle serial port multiplexing method of claim 3, it is characterized by: The waiting threshold Lmt is determined according to the communication timing and operation timing of the state machine; In the completion mode, the count CntRcv is cleared to zero and then the correctness of the received data is judged. Regardless of whether the judgment result is correct or not, the state machine working mode is restored to the idle mode.

5. According to the state machine-based multi-device cross-cycle serial port multiplexing method of claim 3, it is characterized in that: The specific method of adjusting the state machine working mode and sending data during the sending process to the upper computer is: The default state machine is in idle mode. In idle mode, it determines whether a fetch instruction is received. If received, it enters the preparation mode; otherwise, it stays in idle mode and waits for receiving a fetch instruction. In the preparation mode, the FlgGnd flag of the ground detection state machine is set to False, the ground detection state machine is set to idle, and the sending buffer is cleared to enter the sending mode; In the sending mode, the register is selected and set to select the host computer, the received data is written into the sending FIFO, and the sending is enabled; during the sending process, the length of the sent data is recorded and the length is judged. If the length of the sent data is less than the length that should be sent, the sending mode is maintained until the length of the sent data is not less than the length that should be sent. The state machine working mode is adjusted to return to the idle mode to complete the second control process.

6. The method for multiple-device cross-cycle serial port multiplexing based on a state machine according to claim 1, characterized in that: The sending cycle of the sending process to the upper computer is determined according to the data acquisition instruction. In the preparation mode, the FlgGnd flag of the ground detection state machine and the working mode of the ground detection state machine are adjusted to interrupt the sending of the ground detection state machine and make the sending process to the upper computer enter the next working mode.

7. The method for multiple-device cross-cycle serial port multiplexing based on a state machine according to claim 1, characterized in that: The specific method of adjusting the state machine working mode and sending data during the sending process to the ground inspection device is: The default state machine is in idle mode. In idle mode, it is determined whether the transmit FIFO is empty. If it is empty, the state machine working mode is adjusted to enter the ready mode. Otherwise, the count GndCnt is cleared to stop the current transmission; In the preparation mode, it is determined again whether the transmit FIFO is empty. If it is empty, the current data has not been sent to the host computer, and the transmit mode is entered; otherwise, the current data is already in the transmit mode, and the state machine working mode is adjusted to enter the idle mode; In the transmit mode, the select register is set to select the ground detection device, the data is written into the transmit FIFO, the transmission is enabled, and the state machine working mode is adjusted back to the idle mode, completing the third stage of the control process.

8. The method for multiple-device cross-cycle serial port multiplexing based on a state machine according to claim 7, characterized in that: The total control cycle of the control process consisting of the receiving process, the sending process to the upper computer, and the sending process to the ground inspection device is T1; the control cycle of the sending process to the upper computer is T2, which is determined according to the data acquisition instruction; the control cycle of the sending process to the ground inspection device is T3, and the count GndCnt is increased by 1 in each control cycle T1. When the GndCnt value reaches When the ground inspection device is detected, data is sent once.

9. The method for multiple-device cross-cycle serial port multiplexing based on a state machine according to claim 1, characterized in that: In the preparation mode of sending to the upper computer, the sending buffer is cleared by writing registers to prohibit or send the data in progress at the big end to the ground inspection device; In the idle state of the sending process to the ground inspection device, it is judged whether the sending FIFO is empty, and the ongoing data sending process to the upper computer is avoided to be interrupted according to the judgment result.

10. A method for multiple-device cross-cycle serial port multiplexing based on a state machine according to claim 9, characterized in that: In the sending mode of the process of sending to the upper computer, the selection register MUX_REG is set to select the upper computer; in the sending mode of the process of sending to the ground detection device, the selection register MUX_REG is set to select the ground detection device.

Citation Information

Patent Citations

  • Double data rate 2 (DDR2) memory failure injecting tool and injecting method based on field programmable gate array (FPGA)

    CN101783184A

  • Control method for multiple heterogeneous inverters based on RS485 serial communication network

    CN102541038A

  • SDLC (System Development Life Cycle) protocol bus communication testing device based on FPGA (Field-Programmable Gate Array)

    CN102571503A