Method and apparatus for real-time clock synchronization
By creating and scheduling real-time tasks with the same priority and time slices in the switch, the problem of insufficient CPU processing performance in the PTP network is solved, and clock synchronization with high frequency and high reliability is achieved.
Patent Information
- Application Number
- CN202411746879.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-11-29
AI Technical Summary
In high-frequency and multi-port PTP networks, the switch's CPU processing performance is insufficient, making it difficult to achieve efficient and highly reliable clock synchronization.
By creating real-time tasks with the same priority and time slices, including configuration tasks, synchronous message tasks, follow-up messages tasks, delay request messages tasks, delay response messages tasks, and timestamp update tasks, and performing these tasks in rotation mode, ensuring that all real-time tasks are scheduled within each clock synchronization interval.
Real-time clock synchronization through the main port is realized, ensuring high frequency and high reliability time synchronization, and avoiding the problem of insufficient CPU processing performance.
Smart Images

Figure CN119628773A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of time synchronization, and in particular to a method and a device for real-time clock synchronization. Background Art
[0002] PTP (Precision Time Protocol) is a time synchronization protocol that can be used for high-precision time synchronization and frequency synchronization between network devices.
[0003] In a PTP network, for a pair of mutually synchronized clock nodes, there is the following master-slave relationship:
[0004] Master Node and Slave Node: The clock node that publishes the synchronized time is called the master node, and the clock node that receives the synchronized time is called the slave node.
[0005] Master clock and slave clock: The clock on the master node is called the master clock, and the clock on the slave node is called the slave clock.
[0006] Master port and slave interface: The PTP interface that publishes the synchronized time on the clock node is called the master port, and the PTP interface that receives the synchronized time is called the slave port. Both the master port and the slave port can exist on the BC (Boundary Clock) or OC (Ordinary Clock).
[0007] The clock deviation of the slave clock relative to the master clock is calculated through the one-way delay of the link between the master and slave nodes, and then the accurate time of the slave clock is calculated based on the current time of the slave clock and the calculated clock deviation.
[0008] In a network scenario that provides efficient and highly reliable services, high-frequency time synchronization is required between clock nodes, and the time accuracy of the slave clock is higher.
[0009] At present, the switch PTP implementation sends all PTP protocol messages to the CPU (Center Process Unit) for transceiver processing. When there are a large number of ports involved in synchronization and the synchronization frequency is high, the CPU processing performance is likely to be insufficient. Summary of the invention
[0010] In view of this, the present disclosure provides a method and device for real-time clock synchronization.
[0011] In a first aspect, the present disclosure provides a method for real-time clock synchronization, the method comprising:
[0012] Create configuration real-time tasks, synchronization message real-time tasks, follow-up message real-time tasks, delay request message real-time tasks, delay response message real-time tasks, and timestamp update real-time tasks with the same priority and the same time slice;
[0013] Based on the time slice, in a rotation mode, the configuration real-time task is executed to read the PTP configuration information from the shared memory and write it into the PTP configuration data table; the synchronization message real-time task is executed to send the PTP synchronization message through the master port; the follow-up message real-time task is executed to send the PTP follow-up message through the master port; the delay request message real-time task is executed to receive the PTP delay request message through the master port; the delay response message real-time task is executed to send the PTP delay response message through the master port; the timestamp update real-time task is executed to update the synchronization timestamp table used by the follow-up message real-time task and the delay request timestamp table used by the delay response message real-time task; the time of each rotation is less than the preset clock synchronization interval;
[0014] generating a hardware interrupt based on the clock synchronization interval timing;
[0015] In response to the hardware interrupt, identify the primary port used by the synchronization message real-time task from the PTP configuration data table record, record the primary port in the synchronization port table and set a synchronization flag;
[0016] Detect the synchronization message sending event and the delay request message receiving event of the master port, and record the synchronization message timestamp information used to update the synchronization timestamp table and the delay request message timestamp information used to update the delay request timestamp table.
[0017] In a second aspect, the present disclosure provides a device for real-time clock synchronization, the device comprising:
[0018] Timer;
[0019] Real-time mission control module;
[0020] Hardware timestamp module;
[0021] A non-volatile storage medium for storing a set of machine executable instructions;
[0022] Processor; used to execute the machine executable instructions and write the PTP configuration information into the shared memory;
[0023] The timer is configured to generate a hardware interrupt based on a preset clock synchronization interval;
[0024] The real-time task control module creates a configuration task, a synchronization message task, a follow-up message task, a delay message task, a delay response message task, and a timestamp update task with the same priority and the same time slice; based on the time slice, in a round robin mode, executes the configuration task to read the PTP configuration information from the shared memory and write it into the PTP configuration data table; executes the synchronization message task to send the PTP synchronization message through the main port; executes the follow-up message task to send the PTP follow-up message through the main port; executes the delay request message task to receive the PTP delay request message through the main port; executes the delay response message task to send the PTP delay response message through the main port; executes the timestamp update task to update the synchronization timestamp table used by the follow-up message task and the delay request timestamp table used by the delay response message task; the time of each rotation is less than the preset high-frequency synchronization interval; responds to the hardware interrupt, identifies the main port used by the synchronization message task from the PTP configuration data table record, records the main port in the synchronization port table and sets the synchronization flag;
[0025] The hardware timestamp module detects the synchronization message sending event and the delay request message receiving event of the master port, and records the synchronization message timestamp information used to update the synchronization timestamp table and the delay request timestamp information used to update the delay request timestamp table.
[0026] In the technical solution disclosed in the present invention, the master port is updated in real time, and all real-time tasks that execute clock synchronization through the master port are scheduled in a round-robin manner and it is ensured that all real-time tasks are scheduled within each clock synchronization interval, thereby achieving real-time clock synchronization through the master port. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 is a schematic diagram of an example of a method for real-time clock synchronization disclosed herein;
[0028] Figure 2 is a schematic diagram of a real-time clock synchronization system provided by the present disclosure;
[0029] Figure 3 It is a block diagram for illustrating real-time clock synchronization within a time node provided based on the present disclosure;
[0030] Figure 4 It is a block diagram for illustrating PTP configuration information within a time node provided based on the present disclosure;
[0031] Figure 5 is a schematic diagram of a device for real-time clock synchronization disclosed in the present invention. DETAILED DESCRIPTION
[0032] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present disclosure and to make the above-mentioned purposes, features and advantages of the embodiments of the present disclosure more obvious and understandable, the technical solutions in the embodiments of the present disclosure are further described in detail below in conjunction with the accompanying drawings.
[0033] Figure 1 Schematic diagram of an embodiment of a high frequency synchronization method for precise time provided by the present disclosure. The method includes the following processing:
[0034] Processing 101, creating a configuration task, a synchronization message task, a follow-up message task, a delay request message task, a delay response message task, and a timestamp update task with the same priority and the same time slice.
[0035] Processing 102, based on the time slice, in a rotation mode, executes the configuration task to read the PTP configuration information from the shared memory and write it into the PTP configuration data table; executes the synchronization message task to send the PTP synchronization message through the main port; executes the follow-up message task to send the PTP follow-up message through the main port; executes the delay request message task to receive the PTP delay request message through the main port; executes the delay response message task to send the PTP delay response message through the main port; executes the timestamp update task to update the synchronization timestamp table used by the follow-up message task and the delay request timestamp table used by the delayed response message task; the time of each rotation is less than the preset clock synchronization interval.
[0036] Process 103 , generating a hardware interrupt based on the clock synchronization interval timing.
[0037] Process 104, responding to the hardware interrupt, identifying the primary port used by the synchronization message task from the PTP configuration data table record, recording the primary port in the synchronization port table and setting the synchronization flag.
[0038] Processing 105 , detecting the synchronization message sending event and the delay request message receiving event of the primary port, and recording the synchronization message timestamp information used to update the synchronization timestamp table and the delay request timestamp information used to update the delay request timestamp table.
[0039] Figure 1 The beneficial effect of the embodiment is that the master port is updated in real time, and all real-time tasks that perform clock synchronization through the master port are scheduled in a round-robin manner and all real-time tasks are ensured to be scheduled within each clock synchronization interval, thereby achieving real-time clock synchronization through the master port.
[0040] Figure 2 The following is a schematic diagram of the architecture of a time synchronization system provided by an embodiment of the present disclosure. Figure 2As shown, the time synchronization system may include an optimal clock 20 , a clock node 30 , and clock nodes 41 , 42 , and 43 .
[0041] The optimal clock 20 may be set manually or selected based on the BMC algorithm, which is not limited in the present disclosure.
[0042] The clock node 30 and the clock nodes 41, 42, and 43 each determine the master-slave relationship between the clock nodes in the PTP domain through the BMC algorithm.
[0043] The clock node 30 is a master node, and the clock nodes 41-43 are slave nodes. The PTP ports P1-P3 of the clock node 30 are master ports. The PTP ports P411, P421, and P431 of the clock nodes 41-43 are slave ports.
[0044] The real-time clock synchronization device of the clock node 30 publishes the synchronization time in real time through the master ports P1, P2 and P3. The time nodes 41, 42 and 43 receive the synchronization time through the slave ports P421-P431 respectively.
[0045] Figure 2 In the figure, the number of master ports of the clock node 30 for publishing the synchronization time in real time is only an example. The clock node 30 can also publish the synchronization time in real time through multiple master ports, such as 48 master ports, through the real-time clock synchronization device.
[0046] The real-time clock synchronization device of the clock node 30 may be implemented by an integrated circuit deployed with an embedded real-time operating system.
[0047] Figure 3 The block diagram provided based on the present disclosure is used to illustrate the real-time clock synchronization within a time node.
[0048] The processor 310 of the clock node 30 is a transactional CPU, and the real-time clock synchronization device 320 is an integrated circuit deployed with an embedded real-time operating system, such as an MCU.
[0049] The processor 310 of the clock node 30 runs the BMC algorithm. In some existing PTP clock synchronization methods, the processor 310 of the clock node controls multiple transactional tasks and sends PTP protocol messages through each master port, so it is impossible to provide time synchronization with a high-frequency synchronization interval. Taking the request-response mechanism as an example, when the master node sends PTP protocol messages through 48 master ports at a frequency of 128 times per second, the transactional CPU of the master node sends 18432 synchronization messages, follow-up messages, and delay response messages (delay response packets) through transactional tasks per second, i.e., 128*3*48; and receives 6144 delay request packets (delay request packets), i.e., 128*1*48. Therefore, once any of the multiple transactional tasks of the processor executing PTP synchronization is not completed, the subsequent other transactional tasks cannot be scheduled, and high-frequency clock synchronization cannot be achieved.
[0050] In the present disclosure, the processor 310 of the clock node 30 does not send the PTP protocol message through the master port, but synchronizes the PTP configuration information used for the master ports P1-P3 to send the PTP protocol message to the real-time clock synchronization device 320.
[0051] Figure 4 It is a block diagram for illustrating PTP configuration information within a time node provided based on the present disclosure;
[0052] When the real-time clock synchronization device 320 is initialized, a shared memory 301 is allocated and a base address add1 of the shared memory 301 is written into a common register 302 .
[0053] The processor 310 reads the base address add1 of the shared memory 301 from the public register 302, locates the shared memory 301 based on the base address add1, and writes the PTP configuration information into the shared memory 301 to the real-time clock synchronization device 320 to complete the interaction.
[0054] The descriptor “cmd” at the start position of the shared memory 301 includes two flag bits, a first flag bit valid, and a second flag bit done.
[0055] The flag valid is used to identify whether PTP configuration information is stored in the shared memory 301. For example, if the value of the flag valid is a binary value of 1, it indicates that the shared memory 301 stores PTP configuration information; if the value of the flag valid is a binary value of 0, it indicates that the shared memory 301 does not have PTP configuration information that needs to be synchronized.
[0056] The flag bit done is used to identify whether the PTP configuration data in the shared memory 301 has been read. For example, if the value of the flag bit done is a binary value 1, it indicates that the PTP configuration information in the shared memory 301 has been read; if the value of the flag bit done is a binary value 0, it indicates that the PTP configuration information in the shared memory 301 has not been read.
[0057] When cmd.valid=0, the processor 310 may also set the binary value of cmd.done to 0, write the PTP configuration information to the shared memory 301, and then set the value of cmd.valid to 1.
[0058] The real-time clock synchronization device 320 schedules and configures the real-time task R1, reads cmd.valid=1 of the shared memory 301, reads the PTP configuration information from the shared memory 301, sets the value of cmd.done to 1, and sets the value of cmd.valid to 0.
[0059] Then, the processor 310 reads the binary value of cmd.done of the shared memory 301 as 1, and determines that the synchronized PTP configuration information has been read.
[0060] Figure 3 The real-time task control module 322 of the real-time clock synchronization device 320 creates a configuration real-time task R1, a synchronization message real-time task R2, a follow-up message real-time task R3, a delay request message real-time task R4, a delay response message real-time task R5, and a timestamp update real-time task R6 with the same priority and the same time slice. The real-time task control module 322 schedules these real-time tasks R1-R6 in a round robin mode. If the real-time task control module 322 does not read available data in any execution time slice, the currently scheduled real-time task is switched to the ready state, allowing the currently scheduled real-time task to exit early.
[0061] In the present disclosure, the time slices of these real-time tasks of the same priority can be planned according to the clock synchronization interval, so that in each clock synchronization interval, all real-time tasks R1-R6 are scheduled. Taking the clock synchronization of 128 times per second as an example, the clock synchronization interval is 7.8 milliseconds (ms), and the same time slice of 0.5ms is configured for these real-time tasks R1-R6.
[0062] The timer 321 counts according to the clock synchronization interval of 7.8 ms.
[0063] The real-time task control module 322 may schedule the real-time tasks R1 - R6 in a round robin mode based on a time slice of 0.5 ms.
[0064] The real-time task control module 322 executes the configuration real-time task R1 according to Figure 4 The illustrated process reads the PTP configuration information from the shared memory 301 and writes it into the PTP configuration data table 101 in the data memory 303 .
[0065] The real-time task control module 322 executes the synchronization message real-time task R2. If no set master port is identified from the synchronization port table 102, the synchronization message real-time task R2 is switched to the ready state.
[0066] The real-time task control module 322 executes the follow-message real-time task R3, and does not read the timestamp information from the synchronization timestamp table table 103, so the follow-message real-time task R3 is switched to the ready state.
[0067] The real-time task control module 322 executes the delay request message real-time task R4, does not receive the delay request message through the main port P1-P3, and switches the delay request message real-time task R4 to the ready state after the time slice of the delay request message real-time task R4 arrives.
[0068] The real-time task control module 322 executes the delayed response message real-time task R5, fails to obtain the delayed request message receiving timestamp from the delayed request timestamp table table104, and switches the delayed response message real-time task R5 to the ready state.
[0069] The real-time task control module 322 executes the timestamp update real-time task R6, and does not read the synchronization message timestamp information and the delay request message timestamp information from the timestamp module 323, so the timestamp update real-time task R6 is switched to the ready state.
[0070] After the real-time task control module 322 executes the real-time tasks R1 - R6 in rotation for multiple times, the timer 321 reaches the clock synchronization interval of 7.8 ms and outputs a hardware interrupt to the task control module 322 .
[0071] The real-time task control module 322 responds to the hardware interrupt of the timer 321 and suspends the execution of the currently scheduled real-time task among the real-time tasks R1 - R6 .
[0072] In one example, the real-time task control module 322 responds to the hardware interrupt of the timer 321 and suspends the execution of the currently scheduled timestamp update real-time task R6. The real-time task control module 322 identifies the master ports P1-P3 used by the synchronization message real-time task R2 from the PTP configuration data table table101 record, records the master ports P1-P3 in the synchronization port table table102, and sets synchronization flags for the master ports P1-P3 respectively.
[0073] After the real-time task control module 322 responds to the hardware interrupt of the timer 321, it determines whether the time slice of the suspended timestamp update real-time task R6 has ended. If not, it continues to execute the timestamp update real-time task R6; if it has ended, it switches the timestamp update real-time task R6 to the ready state and continues to rotate the scheduling configuration real-time task R1.
[0074] When the time slice of the synchronization message real-time task R2 arrives, the real-time task control module 322 executes the synchronization message real-time task R2, identifies the set master ports P1-P3 from the synchronization port table table102, and reads the synchronization message filling data of the master ports P1-P3 from the PTP configuration information of the PTP configuration data table table101; calls the synchronization message template of the message template storage module 304; based on the synchronization message filling data and the synchronization message template read from the master ports P1-P3, generates the synchronization messages sent by the master ports P1-P3 respectively, and sends them through the master ports P1-P3.
[0075] In the present application, the PTP configuration information synchronized by the processor 310 includes all information for implementing the synchronization of the PTP clock. In this way, when the synchronization message real-time task R2, the follow-up message real-time task R3, and the delayed response message real-time task R5 call the message template storage module 304 to store various templates, the data of the PTP protocol message and the message header field value for completing the PTP protocol message encapsulation are obtained from the PTP configuration information.
[0076] The timestamp module 323 detects the synchronization message sending event of the master ports P1-P3, and records the synchronization message timestamp information of each of the master ports P1-P3. In one example, the synchronization message timestamp information of the master port P1 includes: the master port P1 and the identifier of the synchronization message sent by the master port P1 and the sending timestamp. The synchronization message timestamp information of the master port P2 includes: the master port P2 and the identifier of the synchronization message sent by the master port P2 and the sending timestamp. The synchronization timestamp information of the master port P3 includes: the master port P3 and the identifier of the synchronization message sent by the master port P3 and the sending timestamp. The identifier of the synchronization message may include a message sequence number or a session identifier, which is used for matching the synchronization message (sync packet) and the follow-up message (follow-up packet) of the PTP protocol.
[0077] When the time slice of the timestamp update real-time task R6 arrives, the real-time task control module 322 executes the timestamp update real-time task R6, reads the synchronization message timestamp information of the main ports P1, P2, and P3 from the timestamp module 323, updates it to the synchronization timestamp table table103, and clears the synchronization message timestamp information of the main ports P1, P2, and P3 recorded by the timestamp module 323.
[0078] When the time slice of the follow-up message real-time task R3 arrives, the real-time task control module 322 executes the follow-up message real-time task R3, obtains the synchronization message timestamp information of each main port P1-P3 from the synchronization timestamp table table103; reads the follow-up message filling data of the main ports P1-P3 respectively from the PTP configuration information of the PTP configuration data table table101; calls the follow-up message template of the message template storage module 304, and generates the follow-up messages sent by each main port P1-P3 based on the follow-up message filling data, synchronization message identifier, synchronization message sending timestamp and follow-up message template of each main port P1-P3.
[0079] Figure 2 In the example, after receiving the follow-up message, the clock nodes 41-43 send delay request messages to the clock node 30 respectively.
[0080] When the time slice of the delay request message real-time task R4 arrives, the real-time task control module 322 executes the delay request message real-time task R4, and receives the PTP delay request messages from the clock nodes 41-43 through the main ports P1, P2, and P3 respectively.
[0081] The timestamp module 323 detects the delay request message reception event of each of the master ports P1, P2, and P3, and records the delay request message timestamp information of each of the master ports P1, P2, and P3. Among them, the delay request message timestamp information of the master port P1 includes: the master port P1 and the identifier of the delay request message received by the master port P1 and the receiving timestamp. The delay request message timestamp information of the master port P2 includes: the master port P2 and the identifier of the delay request message received by the master port P2 and the receiving timestamp. The delay request message timestamp information of the master port P3 includes: the master port P3 and the identifier of the delay request message received by the master port P3 and the receiving timestamp.
[0082] When the time slice of the timestamp update real-time task R6 arrives, the real-time task control module 322 executes the timestamp update real-time task R6, reads the delay request message timestamp information of the main ports P1, P2, and P3 from the timestamp module 323, updates it to the delay request timestamp table table104, and clears the delay request message timestamp information of the main ports P1, P2, and P3 recorded by the timestamp module 323.
[0083] When the time slice of the delayed response message real-time task R5 arrives, the real-time task control module 322 executes the delayed response message real-time task R5, obtains the delayed request message timestamp information of each main port P1-P3 from the delayed request timestamp table104, and obtains the delayed response message filling data of the main ports P1-P3 from the PTP configuration information of the PTP configuration data table table101; calls the delayed response message template of the message template storage module 304; based on the respective delayed response message filling data of the main ports P1-P3, the delayed request message timestamp information, and the delayed response message template, generates delayed response messages sent respectively through the main ports P1-P3; and sends these delayed response messages through the main ports P1-P3.
[0084] In the present disclosure, the time for the real-time synchronization device 320 to rotate and execute real-time tasks R1-R6 is less than the interval of a high-frequency clock synchronization, so that the execution order of these real-time tasks R1-R6 is decoupled, and parallel processing is achieved with extremely fast rotation scheduling time.
[0085] In the present disclosure, the real-time synchronization device 320 reads the synchronization message timestamp information and the delay request message timestamp information from the timestamp module 323 by executing the timestamp update real-time task R6 instead of taking the hardware interrupt method, thereby ensuring the absolute reliability of the hardware interrupt of the hardware timer 321 in the real-time synchronization device 320 and ensuring that the real-time clock synchronization is stably performed according to the synchronization interval.
[0086] See also Figure 5 The present disclosure also provides a network device, such as Figure 5 As shown, the network device includes a processor, a non-volatile storage medium and a real-time clock synchronization device. The real-time clock synchronization device deployed with an embedded real-time operating system has a hardware timer, a real-time task control module, a hardware timestamp module, a clock synchronization data storage module, and a message template storage module.
[0087] The processor executes the machine executable instructions stored in the non-volatile storage medium to write the PTP configuration information into the shared memory of the real-time clock synchronization device.
[0088] Timers, which are used to generate hardware interrupts based on preset clock synchronization intervals;
[0089] The real-time task control module creates configuration tasks, synchronization message tasks, follow-up message tasks, delay message tasks, delay response message tasks, and timestamp update tasks with the same priority and the same time slice; based on the time slice, in round robin mode, executes the configuration task to read the PTP configuration information from the shared memory and write it into the PTP configuration data table; executes the synchronization message task to send the PTP synchronization message through the main port; executes the follow-up message task to send the PTP follow-up message through the main port; executes the delay request message task to receive the PTP delay request message through the main port; executes the delay response message task to send the PTP delay response message through the main port; executes the timestamp update task to update the synchronization timestamp table used by the follow-up message task and the delay request timestamp table used by the delayed response message task; the time of each rotation is less than the preset high-frequency synchronization interval; responds to the hardware interrupt, identifies the main port used by the synchronization message task from the PTP configuration data table record, records the main port in the synchronization port table and sets the synchronization flag.
[0090] The hardware timestamp module detects the synchronization message sending event and the delay request message receiving event of the master port, and records the synchronization message timestamp information used to update the synchronization timestamp table and the delay request timestamp information used to update the delay request timestamp table.
[0091] The clock synchronization data storage module is used to store the PTP configuration data table, the synchronization port table, the synchronization timestamp table, and the delay request timestamp table.
[0092] The message template storage module is used to store synchronization message templates, follow-up message templates, and delayed response message templates.
[0093] The real-time task control module executes the synchronization message real-time task for sending the PTP synchronization message through the master port, including identifying the synchronization identifier of the master port in the synchronization port table; reading the synchronization message filling data of the master port from the PTP configuration data table; calling the synchronization message template; generating the synchronization message based on the synchronization message filling data and the synchronization message template; sending the synchronization message through the master port; deleting the synchronization identifier of the master port in the synchronization port table.
[0094] The real-time task control module executes the follow-up message real-time task for sending the PTP follow-up message through the main port, including: obtaining the synchronization message identifier and the synchronization message sending timestamp of the synchronization message sent by the main port from the synchronization timestamp table; reading the follow-up message filling data of the main port from the PTP configuration data table; calling the follow-up message template; generating a follow-up message based on the follow-up message filling data, the synchronization message identifier, the synchronization message sending timestamp and the follow-up message template; and sending the follow-up message through the main port.
[0095] The real-time task control module executes the delayed response message real-time task to send the PTP delayed response message through the main port, including: obtaining the delayed request message identifier and the delayed request message receiving timestamp of the delayed request message received by the main port from the delayed request timestamp table; reading the delayed response message filling data of the main port from the PTP configuration data table; calling the delayed response message template; generating the delayed response message based on the delayed response message filling data, the delayed request message identifier, the delayed request message receiving timestamp and the delayed response message template; and sending the delayed response message through the main port.
[0096] The real-time task control module executes the timestamp update real-time task to update the synchronization timestamp table used by the follow-up message real-time task, including: reading the synchronization message identifier and synchronization message sending timestamp associated with the main port from the synchronization message timestamp information; updating the read synchronization message identifier and synchronization message sending timestamp to the synchronization timestamp table; deleting the synchronization message timestamp information.
[0097] The real-time task control module executes a timestamp update real-time task for updating a delayed request timestamp table used by a delayed response message real-time task, including: reading a delayed request message identifier and a delayed request message receiving timestamp associated with a main port from the delayed request message timestamp information; updating the read delayed request message identifier and delayed request message receiving timestamp to the delayed request timestamp table; and deleting the delayed request timestamp information.
[0098] The real-time task control module is also used to determine that if any of the configuration real-time tasks, synchronization message real-time tasks, follow-up message real-time tasks, delayed request message real-time tasks, delayed response message real-time tasks, and timestamp update real-time tasks fails to read available data within the execution time slice, it will switch to the ready state.
[0099] The real-time task control module is also used to determine the end of the time slice of any one of the interrupted configuration real-time task, synchronization message real-time task, follow-up message real-time task, delayed message real-time task, delayed response message real-time task, and timestamp update real-time task after responding to the hardware interrupt, and switch to the ready state.
[0100] Among them, when the embedded real-time operating system is running, the specific implementation process of the chip to achieve time synchronization is detailed in the implementation process of the corresponding steps in the above method, and will not be repeated here.
Claims
1. A method for real-time clock synchronization, characterized in that: The method comprises: Create configuration real-time tasks, synchronization message real-time tasks, follow-up message real-time tasks, delay request message real-time tasks, delay response message real-time tasks, and timestamp update real-time tasks with the same priority and the same time slice; Based on the time slice, in a round robin mode, the configuration real-time task is executed to read the PTP configuration information from the shared memory and write it into the PTP configuration data table; the synchronization message real-time task is executed to send the PTP synchronization message through the master port; the follow-up message real-time task is executed to send the PTP follow-up message through the master port; the delay request message real-time task is executed to receive the PTP delay request message through the master port; the delay response message real-time task is executed to send the PTP delay response message through the master port; the timestamp update real-time task is executed to update the synchronization timestamp table used by the follow-up message real-time task and the delay request timestamp table used by the delay response message real-time task; the time of each rotation is less than the preset clock synchronization interval; generating a hardware interrupt based on the clock synchronization interval timing; In response to the hardware interrupt, identify the primary port used by the synchronization message real-time task from the PTP configuration data table record, record the primary port in the synchronization port table and set a synchronization flag; Detect the synchronization message sending event and the delay request message receiving event of the master port, and record the synchronization message timestamp information used to update the synchronization timestamp table and the delay request message timestamp information used to update the delay request timestamp table.
2. The method according to claim 1, characterized in that Executing the synchronization message real-time task for sending the PTP synchronization message through the master port includes: Identify the synchronization identifier of the master port in the synchronization port table; Read the synchronization message filling data of the master port from the PTP configuration data table; Call the synchronous message template; Generating the synchronization message based on the synchronization message filling data and the synchronization message template; Sending the synchronization message through the primary port; The synchronization identifier of the master port in the synchronization port table is deleted.
3. The method according to claim 1, characterized in that Executing the follow message real-time task for sending the PTP follow message through the master port includes: Acquire a synchronization message identifier and a synchronization message sending timestamp of the synchronization message sent by the master port from the synchronization timestamp table; Read the follow message filling data of the master port from the PTP configuration data table; Call the follow message template; Generate the follow-up message based on the follow-up message filling data, the synchronization message identifier, the synchronization message sending timestamp and the follow-up message template; The follow message is sent through the primary port.
4. The method according to claim 1, characterized in that Executing the delay response message real-time task to send the PTP delay response message through the master port includes: Acquire a delay request message identifier and a delay request message receiving timestamp of the delay request message received by the master port from the delay request timestamp table; Read the delayed response message filling data of the master port from the PTP configuration data table; Call the delayed response message template; Generate the delay response message based on the delay response message filling data, the delay request message identifier, the delay request message receiving timestamp and the delay response message template; The delay response message is sent through the primary port.
5. The method according to claim 1, characterized in that Executing a timestamp update real-time task for updating a synchronization timestamp table used by the follow-up message real-time task includes: Reading the synchronization message identifier and the synchronization message sending timestamp associated with the master port from the synchronization message timestamp information; Update the read synchronization message identifier and the synchronization message sending timestamp to the synchronization timestamp table; Deleting the synchronization message timestamp information; Executing a timestamp update real-time task for updating a delayed request timestamp table used by the delayed response message real-time task includes: Reading the delay request message identifier and the delay request message receiving timestamp associated with the primary port from the delay request message timestamp information; Update the read delay request message identifier and the delay request message receiving timestamp to the delay request timestamp table; The delayed request timestamp information is deleted.
6. The method according to claim 1, characterized in that The method further comprises, Determine that if any one of the configuration real-time task, the synchronization message real-time task, the follow-up message real-time task, the delayed request message real-time task, the delayed response message real-time task, and the timestamp update real-time task fails to read available data within the execution time slice, then switch to the ready state.
7. The method according to claim 1, characterized in that The method further comprises, After responding to the hardware interrupt, Determine that the time slice of any one of the interrupted configuration real-time task, the synchronization message real-time task, the follow-up message real-time task, the delayed message real-time task, the delayed response message real-time task, and the timestamp update real-time task ends, and switch to the ready state.
8. A device for real-time clock synchronization, characterized in that: The device comprises: Timer; Real-time mission control module; Hardware timestamp module; A non-volatile storage medium for storing a set of machine executable instructions; Processor; used to execute the machine executable instructions and write the PTP configuration information into the shared memory; The timer is configured to generate a hardware interrupt based on a preset clock synchronization interval; The real-time task control module creates a configuration task, a synchronization message task, a follow-up message task, a delay message task, a delay response message task, and a timestamp update task with the same priority and the same time slice; based on the time slice, in a round robin mode, executes the configuration task to read the PTP configuration information from the shared memory and write it into the PTP configuration data table; executes the synchronization message task to send the PTP synchronization message through the main port; executes the follow-up message task to send the PTP follow-up message through the main port; executes the delay request message task to receive the PTP delay request message through the main port; executes the delay response message task to send the PTP delay response message through the main port; executes the timestamp update task to update the synchronization timestamp table used by the follow-up message task and the delay request timestamp table used by the delay response message task; the time of each rotation is less than the preset high-frequency synchronization interval; responds to the hardware interrupt, identifies the main port used by the synchronization message task from the PTP configuration data table record, records the main port in the synchronization port table and sets the synchronization flag; The hardware timestamp module detects the synchronization message sending event and the delay request message receiving event of the master port, and records the synchronization message timestamp information used to update the synchronization timestamp table and the delay request timestamp information used to update the delay request timestamp table.
9. The device according to claim 8, characterized in that The device also includes: A clock synchronization data storage module, used to store the PTP configuration data table, the synchronization port table, the synchronization timestamp table, and the delay request timestamp table; The message template storage module is used to store synchronization message templates, follow-up message templates, and delayed response message templates.
10. The device according to claim 9, characterized in that The real-time task control module executes the synchronization message real-time task for sending the PTP synchronization message through the master port, including: Identify the synchronization identifier of the master port in the synchronization port table; Read the synchronization message filling data of the master port from the PTP configuration data table; Calling the synchronization message template; Generating the synchronization message based on the synchronization message filling data and the synchronization message template; Sending the synchronization message through the primary port; The synchronization identifier of the master port in the synchronization port table is deleted.
11. The device according to claim 9, characterized in that The real-time task control module executes the follow-up message real-time task for sending the PTP follow-up message through the master port, including: Acquire a synchronization message identifier and a synchronization message sending timestamp of the synchronization message sent by the master port from the synchronization timestamp table; Read the follow message filling data of the master port from the PTP configuration data table; Call the follow message template; Generate the follow-up message based on the follow-up message filling data, the synchronization message identifier, the synchronization message sending timestamp and the follow-up message template; The follow message is sent through the primary port.
12. The device according to claim 9, characterized in that The real-time task control module executes the delay response message real-time task to send the PTP delay response message through the master port, including: Acquire a delay request message identifier and a delay request message receiving timestamp of the delay request message received by the master port from the delay request timestamp table; Read the delayed response message filling data of the master port from the PTP configuration data table; Call the delayed response message template; Generate the delay response message based on the delay response message filling data, the delay request message identifier, the delay request message receiving timestamp and the delay response message template; The delay response message is sent through the primary port.
13. The device according to claim 9, characterized in that The real-time task control module executes a timestamp update real-time task for updating a synchronization timestamp table used by the follow-up message real-time task, including: Reading the synchronization message identifier and the synchronization message sending timestamp associated with the master port from the synchronization message timestamp information; Update the read synchronization message identifier and the synchronization message sending timestamp to the synchronization timestamp table; Deleting the synchronization message timestamp information; The real-time task control module executes a timestamp update real-time task for updating a delay request timestamp table used by the delay response message real-time task, including: Reading the delay request message identifier and the delay request message receiving timestamp associated with the primary port from the delay request message timestamp information; Update the read delay request message identifier and the delay request message receiving timestamp to the delay request timestamp table; The delayed request timestamp information is deleted.
14. The device according to claim 9, characterized in that The real-time task control module is also used to determine that if any one of the configuration real-time task, the synchronization message real-time task, the follow-up message real-time task, the delayed request message real-time task, the delayed response message real-time task, and the timestamp update real-time task fails to read available data within the execution time slice, it will switch to the ready state.
15. The device according to claim 9, characterized in that The real-time task control module is also used to determine the end of the time slice of any one of the interrupted configuration real-time task, the synchronization message real-time task, the follow-up message real-time task, the delayed message real-time task, the delayed response message real-time task, and the timestamp update real-time task after responding to the hardware interrupt, and switch to the ready state.
Citation Information
Patent Citations
Clock synchronization method, system and equipment based on PTP
CN103441832A
Clock synchronization method and device
CN106533600A
Clock synchronization method and device and storage medium
CN112838903A
Method, device and equipment for supporting high-precision clock service
CN115632736A
Method and apparatus for PTP synchronous network
EP2991250A1