Time compensation method and device

By calculating and verifying the initial compensation value in the PTP message, the delay error problem between PTP message editing and device transmission is solved, thus improving the reliability of clock synchronization.

CN121567259APending Publication Date: 2026-02-24SUZHOU CENTEC COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511884157.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-15
Publication Date
2026-02-24

AI Technical Summary

Technical Problem

In Ethernet communication, there is a delay between the completion of PTP message editing and its dispatch by the device, resulting in inaccurate timestamps and affecting the reliability of clock synchronization.

Method used

By calculating the initial compensation value of the timestamp in the PTP message and adding it to the timestamp value, combined with verification and feedback adjustment, the accuracy of the PTP message timestamp is ensured, and the delay error from editing to device output is reduced.

Benefits of technology

It improves the timestamp accuracy of PTP messages, reduces delay errors, and enhances the reliability of clock synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121567259A_ABST
    Figure CN121567259A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a time compensation method and equipment, and relates to the technical field of communication, and the method comprises the steps: receiving a PTP message transmission request, and calculating an initial compensation value of a timestamp in a PTP message according to a preset compensation strategy; and adding the initial compensation value to the value of the timestamp in the PTP message to obtain a target PTP message. And performing verification and feedback adjustment on the initial compensation value in the target PTP message according to a preset verification strategy to obtain a target compensation value meeting an error requirement, thereby improving a delay error from the time when the PTP message is edited to the time when the device sends out the PTP message, and improving the clock synchronization reliability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, and more specifically, to a time compensation method and device. Background Technology

[0002] In Ethernet communication, Precision Timing Protocol (PTP) is commonly used as the mainstream clock synchronization scheme. By sending PTP messages carrying timestamps, the time or frequency deviations of various devices within the network are controlled within an acceptable range, thereby synchronizing the clocks. The timestamps in the PTP messages are used to calculate the offset and delay from the master clock and adjust the local clock to synchronize with the master clock. Therefore, the correctness and accuracy of the timestamps inserted into the PTP messages are particularly important in the PTP clock synchronization process.

[0003] Research has revealed that the timestamp inserted in a PTP message represents the time when the PTP message is sent from the local end. However, there is a delay between the completion of PTP message editing and its dispatch from the device. If there is too much logic and the delay is too long, the timestamp inserted in the PTP message will be inaccurate, which will affect the synchronization clock. Related technologies often ignore the delay error between the PTP message editing time and the device dispatch time, resulting in the clock synchronization reliability needing to be improved. Summary of the Invention

[0004] One of the objectives of this invention includes, for example, providing a time compensation method and apparatus to at least partially improve the delay error of PTP messages and enhance clock synchronization reliability.

[0005] The embodiments of the present invention can be implemented as follows: In a first aspect, embodiments of the present invention provide a time compensation method, comprising: Receive PTP message transmission request; Calculate the initial compensation value of the timestamp in the PTP message according to the preset compensation strategy; The initial compensation value is added to the timestamp value in the PTP message to obtain the target PTP message; The initial compensation value in the target PTP message is verified and adjusted according to the preset verification strategy to obtain the target compensation value that meets the error requirements.

[0006] In an optional implementation, calculating the initial compensation value of the timestamp in the PTP message according to a preset compensation strategy includes: Obtain information on factors affecting the transmission time of PTP packets in RTL, including packet transmission rate mode and flow control mode; The time compensation value corresponding to the influencing factor information is determined from the pre-configured time compensation values ​​and used as the initial compensation value.

[0007] In an optional implementation, calculating the initial compensation value of the timestamp in the PTP message according to a preset compensation strategy includes: Calculate the number of logical steps between the PTP message editing and the output of the sending device in the RTL; Multiply the clock cycle by the number of logical beats to obtain the initial compensation value for the timestamp in the PTP message.

[0008] In an optional implementation, the step of verifying and adjusting the initial compensation value in the target PTP message according to a preset verification strategy to obtain a target compensation value that meets the error requirements includes: Determine whether the delays of different message types are the same in the case of a self-loop; Based on the delay of PTP packets with PTP time compensation function disabled and the delay of target PTP packets with PTP time compensation function enabled, the target compensation value that meets the error requirements is obtained.

[0009] In an optional implementation, determining whether the delays of different types of messages are the same in the case of a self-loop includes: Based on the self-loop condition, the first delay is obtained by considering the delay between the sending end sending the non-PTP message SOP and the receiving end receiving the non-PTP message SOP. With PTP time compensation disabled, PTP packets are sent in a loop. The second delay is obtained based on the timestamp carried in the PTP packets and the time when the receiving end receives the PTP packets at SOP. Whether the delays of different types of messages are the same is determined by whether the first delay and the second delay are equal.

[0010] In an optional implementation, when the delays of different types of messages are the same, obtaining the target compensation value that meets the error requirements based on the delay of PTP messages with PTP time compensation function disabled and the delay of the target PTP message with PTP time compensation function enabled includes: With PTP time compensation enabled, the target PTP message after timestamp compensation based on the initial compensation value is sent in a loop. The third delay is obtained based on the timestamp carried by the target PTP message and the time when the target message SOP is received by the receiving end. Based on the second delay, the third delay, and the preset error threshold, determine whether the initial compensation value meets the requirements; If so, the initial compensation value shall be used as the target compensation value; If not, adjust the initial compensation value until the newly obtained initial compensation value meets the requirements, and use the newly obtained initial compensation value as the target compensation value.

[0011] In an optional implementation, the step of obtaining the first delay based on the delay between the sending end sending the non-PTP message SOP and the receiving end receiving the non-PTP message SOP in the self-loop case includes: In the case of a self-loop, the first delay is obtained by averaging the delays between the sending end sending a non-PTP message SOP and the receiving end receiving a non-PTP message SOP. The step of obtaining the second delay based on the timestamp carried in the PTP message and the time when the receiver receives the PTP message SOP from the receiving end includes: The second delay is obtained by calculating the difference between the timestamp carried in the PTP message and the time when the receiver receives the PTP message SOP. The step of obtaining the third delay based on the timestamp carried in the target PTP message and the time when the receiver receives the target message SOP from the receiving end includes: The third delay is obtained by calculating the difference between the timestamp carried by the target PTP message and the time when the target message SOP is received by the receiving end.

[0012] In an optional implementation, determining whether the initial compensation value meets the requirements based on the second delay, the third delay, and a preset error threshold includes: Calculate the delay difference between the second delay and the third delay; Determine the error between the delay difference and the initial compensation value; Determine whether the error is within a preset error threshold; If so, determine that the initial compensation value meets the requirements; If not, it is determined that the initial compensation value does not meet the requirements.

[0013] In an optional implementation, adding the initial compensation value to the timestamp value in the PTP message to obtain the target PTP message includes: The target PTP message is obtained by adding the timestamp value to the initial compensation value.

[0014] In a second aspect, embodiments of the present invention provide an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the time compensation method described in any of the foregoing embodiments.

[0015] Thirdly, embodiments of the present invention provide a computer-readable storage medium, the computer-readable storage medium including a computer program, wherein when the computer program is executed, it controls the electronic device in which the computer-readable storage medium is located to perform the time compensation method described in any of the foregoing embodiments.

[0016] The beneficial effects of the embodiments of the present invention include, for example, for PTP message transmission requests, by calculating the initial compensation value of the timestamp in the PTP message and adding it to the value of the timestamp in the PTP message, a certain margin is added to the value of the timestamp in the PTP message in advance, compensating for the accuracy of the timestamp carried by the PTP message, reducing the error caused by the delay from the PTP message editing time to the device exit, and by combining the verification and feedback adjustment of the initial compensation value, the reliability of time compensation is effectively ensured, thereby improving the reliability of clock synchronization. Attached Figure Description

[0017] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 The diagram illustrates an application scenario provided by an embodiment of the present invention.

[0019] Figure 2 A flowchart illustrating a time compensation method provided by an embodiment of the present invention is shown.

[0020] Figure 3 The diagram shows an architecture schematic of a time compensation method provided by an embodiment of the present invention.

[0021] Figure 4 A schematic diagram of a first-delay confirmation architecture provided by an embodiment of the present invention is shown.

[0022] Figure 5 A schematic diagram of a second-delay confirmation architecture provided by an embodiment of the present invention is shown.

[0023] Figure 6 A schematic diagram of a third-delay confirmation architecture provided by an embodiment of the present invention is shown.

[0024] Figure 7 A schematic diagram of a fourth delay confirmation architecture provided by an embodiment of the present invention is shown.

[0025] Icons: 100 - Electronic device; 110 - Memory; 120 - Processor; 130 - Communication module. Detailed Implementation

[0026] Some terms are defined as follows:

[0027] In related technologies, there is a delay between the time a PTP message is edited and the time it is sent by the device, which means that the reliability of clock synchronization needs to be improved.

[0028] Research has shown that, in order to reduce delay errors and improve clock synchronization reliability, a high-precision network time synchronization scheme using PTP timestamps can be designed. For example, PTP messages can be edited at the MAC layer, and the PTP synchronization message and timestamp can be obtained through network driver software. The time deviation and clock frequency difference between the local system time and the time of the synchronization device can be calculated. After the software completes the calculation, the internal clock of the MAC controller can be calibrated.

[0029] However, the essence of this PTP timestamp high-precision network time synchronization scheme is still to calculate the timestamp error of the PTP synchronized message and compensate for it through subsequent calculations. Therefore, the timestamp of the PTP synchronized message is still inaccurate.

[0030] Based on the above research, this invention provides a time compensation scheme that supports applications in Ethernet environments with high requirements for message transmission time accuracy. Compared to related technologies that insert timestamps into messages according to a precise time protocol, the logical time point from which the timestamp is inserted into a PTP message to its dispatch from the slave device requires a certain time delay, resulting in inaccurate timestamps in the dispatched messages. This invention compensates for the timestamps of time-synchronized PTP messages in advance by adding a certain value to the message editing logic for time accuracy compensation, ensuring that the timestamps of the dispatched PTP messages are the accuracy-compensated values, thereby improving PTP timestamp accuracy, reducing logical delay errors, and providing a method for verifying this accuracy compensation scheme.

[0031] The shortcomings of the above solutions are the result of the inventors' practical experience and careful research. Therefore, the discovery process of the above problems and the solutions proposed by the embodiments of the present invention in the following text should be considered as contributions made by the inventors during the invention process.

[0032] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0033] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0034] It should be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0035] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0036] It should be noted that, where there is no conflict, the features in the embodiments of the present invention can be combined with each other.

[0037] Please refer to Figure 1 This is a block diagram of an electronic device 100 provided in this embodiment. The electronic device 100 in this embodiment can be a server, processing device, processing platform, etc., capable of data interaction and processing. For example, the electronic device 100 can be a network device for message transmission. The electronic device 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, processor 120, and communication module 130 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.

[0038] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.

[0039] The processor 120 is used to read / write data or programs stored in the memory 110 and to perform corresponding functions.

[0040] The communication module 130 is used to establish a communication connection between the electronic device 100 and other communication terminals through the network, and to send and receive data through the network.

[0041] It should be understood that, Figure 1 The structure shown is only a schematic diagram of the electronic device 100. The electronic device 100 may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.

[0042] Please refer to the following: Figure 2 This is a flowchart illustrating a time compensation method provided in an embodiment of the present invention. It can be derived from... Figure 1 The electronic device 100 performs the operation, for example, by the processor 120 within the electronic device 100. The time compensation method includes steps S110, S120, S130, and S140. S110 receives PTP message transmission requests.

[0043] S120, calculate the initial compensation value of the timestamp in the PTP message according to the preset compensation strategy.

[0044] S130, the initial compensation value is added to the timestamp value in the PTP message to obtain the target PTP message.

[0045] S140, the initial compensation value in the target PTP message is verified and adjusted according to the preset verification strategy to obtain the target compensation value that meets the error requirements.

[0046] Please refer to the following: Figure 3,use Figure 2 The time compensation method shown compensates for the time stamp accuracy carried in the PTP message by adding a certain margin (initial compensation value) to the timestamp value in the PTP message in advance. This improves the time accuracy of the timestamp carried in the PTP message, reduces the PTP error caused by the time delay from PTP message editing to device exit, and makes the PTP message used when the local clock is synchronized with the master clock more accurate, thus synchronizing the clock more reliably.

[0047] In S120, the initial compensation value of the timestamp in the PTP message can be flexibly calculated according to the preset compensation strategy.

[0048] For example, information on factors affecting the transmission time of PTP messages in RTL can be obtained, and the time compensation value corresponding to the information on the influencing factors can be determined from the pre-configured time compensation values ​​as the initial compensation value.

[0049] The influencing factors information may include message transmission rate mode and flow control mode.

[0050] For example, relevant logic can be added to the RTL according to the rate mode, such as message transmission rate and flow control. By incorporating factors affecting the transmission time of messages in the RTL into the calculation logic of the time compensation scheme, different time compensation values ​​Ts can be configured for different transmission rate modes, different types of messages, and different flow control modes. 补偿 This allows for the acquisition of a matching time compensation value as the initial compensation value. This makes the PTP time accuracy more precise, and the obtained time compensation value closer to the actual logic delay. Through this compensation scheme, RTL can achieve high PTP time accuracy and smaller errors in different modes.

[0051] For example, the number of logical beats between the PTP message editing and the sending end device output in the RTL can be calculated, and the clock period can be multiplied by the number of logical beats to obtain the initial compensation value of the timestamp in the PTP message.

[0052] For example, a fixed initial compensation value can be selected. By calculating the number of logical steps between the PTP message editing in the RTL and the Tx direction device output, the clock period multiplied by the number of logical steps is the initial compensation value required by the time compensation scheme, thus achieving a simple and fixed initial compensation value acquisition.

[0053] In step S130, the initial compensation value is added to the timestamp value in the PTP message to obtain the target PTP message. This includes adding the initial compensation value to the timestamp value in the PTP message to obtain the target PTP message. In step S140, the initial compensation value in the target PTP message is verified and adjusted according to a preset verification strategy to obtain a target compensation value that meets the error requirements. This can be achieved by: determining whether the delays of different types of messages are the same under a self-loop condition; and obtaining a target compensation value that meets the error requirements based on the delay of the PTP message when the PTP time compensation function is disabled and the delay of the target PTP message when the PTP time compensation function is enabled.

[0054] In the case of a self-loop, determining whether the delays of different message types are the same can be achieved as follows: Based on the delay between the sending end's transmission of a non-PTP message SOP and the receiving end's receipt of the non-PTP message SOP in the self-loop scenario, a first delay is obtained. With PTP time compensation disabled, PTP messages are transmitted in a self-loop, and a second delay is obtained based on the timestamp carried in the PTP message and the time the receiving end receives the PTP message SOP. Whether the delays of different message types are the same is determined by whether the first delay and the second delay are equal.

[0055] Please refer to the following: Figure 4 It provides an architecture for obtaining the first delay. In the case of a self-loop, the first delay is obtained by averaging the delays of sending a non-PTP SOP message in the sending direction and receiving a non-PTP SOP message in the receiving direction.

[0056] like Figure 4 As shown, the delays in the TX and RX directions of the device's self-loop are calculated. In the RTL code self-loop configuration, normal messages are sent, and the average delay between receiving a normal message SOP in the RX direction and sending a normal message SOP in the TX direction is recorded as the first delay T1, where T1 = T out -T in T1 includes the total delay of all logic codes in the TX and RX directions of the device.

[0057] Please refer to the following: Figure 5 It provides a second delay acquisition architecture. When the PTP time compensation function is disabled, the PTP message is sent in a loop. The difference between the timestamp carried by the PTP message and the time when the receiving end receives the PTP message SOP is calculated to obtain the second delay.

[0058] like Figure 5 As shown, with PTP time compensation disabled, PTP messages are sent in a loop. The timestamp Ts carried in the PTP message is compared with the time T when the SOP message is received in the RX direction. outThe difference, taken as the second delay T2, T2=T out -Ts.

[0059] By determining whether T1 equals T2, it can be verified whether the timestamp inserted at the start of the PTP message was inserted at the message's SOP. This verifies whether the timestamp insertion behavior is consistent for different types of messages, such as ordinary messages and PTP messages, eliminating the influence of additional factors such as message length and timestamp insertion behavior. If they are equal, it proves that the timestamp inserted during PTP editing is equal to the timestamp at the start of the PTP message's SOP.

[0060] When T1 equals T2, meaning the delays for different types of messages are the same, the target compensation value that meets the error requirements can be obtained as follows: With PTP time compensation enabled, the target PTP message, after timestamp compensation based on the initial compensation value, is sent in a loop. The third delay is obtained based on the timestamp carried in the target PTP message and the time the receiving end receives the target message at its SOP. Based on the second delay, the third delay, and a preset error threshold, it is determined whether the initial compensation value meets the requirements. If yes, the initial compensation value is used as the target compensation value. If not, the initial compensation value is adjusted until a newly obtained initial compensation value meets the requirements, and this newly obtained initial compensation value is used as the target compensation value.

[0061] Please refer to the following: Figure 6 It provides a third delay acquisition architecture. When the PTP time compensation function is enabled, the target PTP message after time stamp compensation according to the initial compensation value is sent in a loop. The difference between the timestamp carried by the target PTP message and the time when the target message SOP is received by the receiving end is calculated to obtain the third delay.

[0062] like Figure 6 As shown, the PTP time compensation function is enabled, and the target PTP packet after time compensation is sent in a loop. The timestamp value of the target PTP packet in the loop state is calculated and denoted as Ts. 补偿 The exit time T in the RX direction out The difference is denoted as T3, and T3 = T out -Ts 补偿 Since the timestamp of the target PTP message has already incorporated a time compensation scheme, the time corresponding to the compensated timestamp includes the expected logical delay between the PTP message editing in the TX direction and the device output in the TX direction. Therefore, T2-T3 represents the actual tested logical delay between the PTP message editing and the device output in the TX direction. Comparing the value of T2-T3 with the initial compensation value, if the error is within the tolerance range (e.g., 5%), it proves that the initial compensation value obtained according to the time compensation scheme is equal to the actual RTL logical delay, thus verifying the correctness of the PTP time compensation scheme.

[0063] Based on the determination of each delay, and according to the second delay, the third delay, and a preset error threshold, determining whether the initial compensation value meets the requirements can be achieved in the following way: calculate the delay difference between the second delay and the third delay, determine the error between the delay difference and the initial compensation value, and determine whether the error is within the preset error threshold. If yes, determine that the initial compensation value meets the requirements. If no, determine that the initial compensation value does not meet the requirements.

[0064] Please refer to the following: Figure 7 This invention provides an architecture diagram for calculating the theoretical delay T4 between PTP message editing and the TX direction device exit by using logical timing calculations in the code. It is understood that the target compensation value determined by the time compensation scheme in this embodiment is expected to be the theoretical delay T4. The method checks whether T4 is equal to T2-T3; if they are equal, it proves that under the time compensation scheme in this embodiment, the timestamp compensation value is the delay between PTP message editing and the TX direction device exit. This compensation scheme can effectively control the timestamp accuracy of PTP.

[0065] Based on the above, embodiments of the present invention also provide a computer-readable storage medium, the computer-readable storage medium including a computer program, wherein the computer program, when running, controls the electronic device in which the computer-readable storage medium is located to execute the above-described time compensation method.

[0066] This invention provides precision compensation for the easily overlooked error of delay from PTP message editing to device output, offering multiple time compensation schemes and a verification method. By using a loopback approach, the delay of the PTP message at each stage in the RTL code is calculated to determine the correctness and rationality of the compensation behavior. This verification from both positive and negative perspectives improves the reliability and robustness of functional verification.

[0067] This method employs a control variable approach, sending messages in a loop to eliminate the influence of factors unrelated to PTP message timestamp insertion. The delays of each part of the message transmission are calculated to verify the rationality of the precision compensation value. By using a loopback mechanism, the delays of ordinary messages, PTP messages, and the compensated target PTP message are recorded. By controlling variables, the influence of irrelevant factors such as message editing time and message timestamp sampling time between different message types is eliminated in stages. The delays of the PTP message at each stage in the RTL code are then calculated separately. This verifies whether the error between the compensation value and the actual RTL logical delay is within the allowable range, thus verifying the correctness of the compensation scheme. This improves the delay error from PTP message editing to device transmission, enhancing clock synchronization reliability.

[0068] In the several embodiments provided by this invention, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of devices, methods, and computer program products according to various embodiments of the invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0069] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0070] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0071] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A time compensation method, characterized in that, include: Receive PTP message transmission request; Calculate the initial compensation value of the timestamp in the PTP message according to the preset compensation strategy; The initial compensation value is added to the timestamp value in the PTP message to obtain the target PTP message; The initial compensation value in the target PTP message is verified and adjusted according to the preset verification strategy to obtain the target compensation value that meets the error requirements.

2. The time compensation method according to claim 1, characterized in that, The calculation of the initial compensation value for the timestamp in the PTP message according to the preset compensation strategy includes: Obtain information on factors affecting the transmission time of PTP packets in RTL, including packet transmission rate mode and flow control mode; The time compensation value corresponding to the influencing factor information is determined from the pre-configured time compensation values ​​and used as the initial compensation value.

3. The time compensation method according to claim 1, characterized in that, The calculation of the initial compensation value for the timestamp in the PTP message according to the preset compensation strategy includes: Calculate the number of logical steps between the PTP message editing and the output of the sending device in the RTL; Multiply the clock cycle by the number of logical beats to obtain the initial compensation value for the timestamp in the PTP message.

4. The time compensation method according to claim 2 or 3, characterized in that, The step of verifying and adjusting the initial compensation value in the target PTP message according to a preset verification strategy to obtain a target compensation value that meets the error requirements includes: Determine whether the delays of different message types are the same in the case of a self-loop; Based on the delay of PTP packets with PTP time compensation function disabled and the delay of target PTP packets with PTP time compensation function enabled, the target compensation value that meets the error requirements is obtained.

5. The time compensation method according to claim 4, characterized in that, In the case of a self-loop, determining whether the delays of different types of messages are the same includes: Based on the self-loop condition, the first delay is obtained by considering the delay between the sending end sending the non-PTP message SOP and the receiving end receiving the non-PTP message SOP. With PTP time compensation disabled, PTP packets are sent in a loop. The second delay is obtained based on the timestamp carried in the PTP packets and the time when the receiving end receives the PTP packets at SOP. Whether the delays of different types of messages are the same is determined by whether the first delay and the second delay are equal.

6. The time compensation method according to claim 5, characterized in that, When different types of messages have the same delay, the step of obtaining a target compensation value that meets the error requirements based on the delay of PTP messages with PTP time compensation function disabled and the delay of the target PTP message with PTP time compensation function enabled includes: With PTP time compensation enabled, the target PTP message after timestamp compensation based on the initial compensation value is sent in a loop. The third delay is obtained based on the timestamp carried by the target PTP message and the time when the target message SOP is received by the receiving end. Based on the second delay, the third delay, and the preset error threshold, determine whether the initial compensation value meets the requirements; If so, the initial compensation value shall be used as the target compensation value; If not, adjust the initial compensation value until the newly obtained initial compensation value meets the requirements, and use the newly obtained initial compensation value as the target compensation value.

7. The time compensation method according to claim 6, characterized in that, The first delay is obtained by considering the delay between the sending end sending the non-PTP message SOP and the receiving end receiving the non-PTP message SOP under the self-loop condition, including: In the case of a self-loop, the first delay is obtained by averaging the delays between the sending end sending a non-PTP message SOP and the receiving end receiving a non-PTP message SOP. The step of obtaining the second delay based on the timestamp carried in the PTP message and the time when the receiver receives the PTP message SOP from the receiving end includes: The second delay is obtained by calculating the difference between the timestamp carried in the PTP message and the time when the receiver receives the PTP message SOP. The step of obtaining the third delay based on the timestamp carried in the target PTP message and the time when the receiver receives the target message SOP from the receiving end includes: The third delay is obtained by calculating the difference between the timestamp carried by the target PTP message and the time when the target message SOP is received by the receiving end.

8. The time compensation method according to claim 7, characterized in that, The step of determining whether the initial compensation value meets the requirements based on the second delay, the third delay, and a preset error threshold includes: Calculate the delay difference between the second delay and the third delay; Determine the error between the delay difference and the initial compensation value; Determine whether the error is within a preset error threshold; If so, determine that the initial compensation value meets the requirements; If not, it is determined that the initial compensation value does not meet the requirements.

9. The time compensation method according to claim 1, characterized in that, The step of adding the initial compensation value to the timestamp value in the PTP message to obtain the target PTP message includes: The target PTP message is obtained by adding the timestamp value to the initial compensation value.

10. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the time compensation method according to any one of claims 1 to 9.