Method and apparatus for real-time clock synchronization
By creating real-time tasks with the same priority and time slice in the switch, and adopting a round-robin mode and hardware interrupt mechanism, the problem of insufficient CPU processing performance is solved, high-frequency real-time clock synchronization is achieved, and the stability and reliability of time synchronization are ensured.
Patent Information
- Application Number
- CN202411746879.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2044-11-29
AI Technical Summary
In high-efficiency and high-reliability network scenarios, when PTP is implemented on a switch, the CPU processing performance is insufficient, making it difficult to achieve high-frequency time synchronization.
Real-time clock synchronization is achieved by creating real-time tasks with the same priority and time slice, executing clock synchronization tasks in a round-robin mode, and utilizing hardware interrupts and shared memory to ensure that all real-time tasks are scheduled within each clock synchronization interval.
It achieves high-frequency real-time clock synchronization, avoiding the problem of insufficient CPU processing performance and ensuring the stability and reliability of time synchronization.
Smart Images

Figure CN119628773B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of time synchronization, and in particular to a method and device for real-time clock synchronization. BACKGROUND
[0002] PTP (Precision Time Protocol) is a protocol for time synchronization, which can be used for high-precision time synchronization and frequency synchronization between network devices.
[0003] In a PTP network, for a pair of clock nodes that are synchronized with each other, there is a master-slave relationship as follows:
[0004] Master node and slave node: the clock node that publishes synchronization time is called a master node, and the clock node that receives synchronization time is called a slave node.
[0005] Master clock and slave clock: the clock on the master node is called a master clock, and the clock on the slave node is called a slave clock.
[0006] Master port and slave port: the PTP interface on the clock node that publishes synchronization time is called a master port, and the PTP interface that receives synchronization time is called a slave port. Both the master port and the slave port can exist on a BC (Boundary Clock) or an OC (Ordinary Clock).
[0007] The clock offset of the slave clock relative to the master clock is calculated through the one-way delay of the link between the master node and the slave node, and then the accurate time of the slave clock is calculated according to the current time of the slave clock and the calculated clock offset.
[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] Currently, all PTP protocol packets are sent to the CPU (Center Process Unit) for transceiving processing in the implementation of switch PTP. In the case where the number of ports participating in synchronization is large and the synchronization frequency is high, the processing performance of the CPU is likely to be insufficient. SUMMARY
[0010] Therefore, the present disclosure provides a method and device for real-time clock synchronization.
[0011] In a first aspect, the disclosure provides a method for real-time clock synchronization, the method comprising:
[0012] creating a configuration real-time task, a synchronization message real-time task, a follow message real-time task, a delay request message real-time task, a delay response message real-time task, and a timestamp update real-time task with the same priority and the same time slice;
[0013] based on the time slice, performing the configuration real-time task for reading PTP configuration information from shared memory and writing PTP configuration data table, performing the synchronization message real-time task for sending PTP synchronization message through a master port, performing the follow message real-time task for sending PTP follow message through the master port, performing the delay request message real-time task for receiving PTP delay request message through the master port, performing the delay response message real-time task for sending PTP delay response message through the master port, and performing the timestamp update real-time task for updating a synchronization timestamp table used by the follow message real-time task and a delay request timestamp table used by the delay response message real-time task, and the time of each round is less than a preset clock synchronization interval;
[0014] generating a hardware interrupt based on the clock synchronization interval;
[0015] in response to the hardware interrupt, identifying the master port used by the synchronization message real-time task from the PTP configuration data table, recording the master port in a synchronization port table and setting a synchronization identifier;
[0016] detecting a synchronization message sending event and a delay request message receiving event of the master port, recording synchronization message timestamp information for updating the synchronization timestamp table and delay request message timestamp information for updating the delay request timestamp table.
[0017] In a second aspect, the disclosure provides a device for real-time clock synchronization, the device comprising:
[0018] a timer;
[0019] a real-time task control module;
[0020] a hardware timestamp module;
[0021] a non-volatile storage medium for storing a set of machine executable instructions;
[0022] a processor for executing the machine executable instructions and writing PTP configuration information into shared memory;
[0023] the timer generates a hardware interrupt based on a preset clock synchronization interval;
[0024] The real-time task control module creates configuration tasks, synchronization message tasks, follow-up message tasks, delay request message tasks, delay response message tasks, and timestamp update tasks with the same priority and the same time slice, executes the configuration tasks to read the PTP configuration information from the shared memory and write PTP configuration data tables based on the time slice in a round robin mode, executes the synchronization message tasks to send PTP synchronization messages through the master port, executes the follow-up message tasks to send PTP follow-up messages through the master port, executes the delay request message tasks to receive PTP delay request messages through the master port, executes the delay response message tasks to send PTP delay response messages through the master port, executes the timestamp update tasks to update a synchronization timestamp table used by the follow-up message tasks and a delay request timestamp table used by the delay response message tasks, the time of each round is less than a preset high-frequency synchronization interval, and the master port used by the synchronization message tasks is identified from the PTP configuration data table record in response to the hardware interrupt, the master port is recorded in a synchronization port table, and a synchronization identifier is set.
[0025] The hardware timestamp module detects synchronization message sending events and delay request message receiving events of the master port, records synchronization message timestamp information for updating the synchronization timestamp table, and records delay request timestamp information for updating the delay request timestamp table.
[0026] In the technical solution of the present disclosure, the master port is updated in real time, and all real-time tasks for performing clock synchronization through the master port are scheduled in a round robin manner and ensured to be scheduled within each clock synchronization interval, so that real-time clock synchronization through the master port is realized. BRIEF DESCRIPTION OF DRAWINGS
[0027] Figure 1 is a schematic diagram of a method for real-time clock synchronization according to the present disclosure;
[0028] Figure 2 is a schematic diagram of a real-time clock synchronization system according to the present disclosure;
[0029] Figure 3 is a block diagram for showing real-time clock synchronization within a time node according to the present disclosure;
[0030] Figure 4 is a block diagram for showing PTP configuration information within a time node according to the present disclosure;
[0031] Figure 5 is a schematic diagram of a device for real-time clock synchronization according to the present disclosure. DETAILED DESCRIPTION
[0032] To enable those skilled in the art to better understand the technical solutions in the embodiments of this disclosure, and to make the above-mentioned objectives, features and advantages of the embodiments of this disclosure more apparent and understandable, the technical solutions in the embodiments of this disclosure will be further described in detail below with reference to the accompanying drawings.
[0033] Figure 1 This is a schematic diagram of an embodiment of the high-frequency synchronization method for precise time provided in this disclosure. The method includes the following processes:
[0034] Process 101: Create configuration tasks, synchronization message tasks, follow message tasks, delayed request message tasks, delayed response message tasks, and timestamp update tasks with the same priority and time slice.
[0035] Process 102, based on time slices and in round-robin mode, executes the following tasks: a configuration task to read PTP configuration information from shared memory and write it to the PTP configuration data table; a synchronization message task to send PTP synchronization messages through the master port; a follow message task to send PTP follow messages through the master port; a delay request message task to receive PTP delay request messages through the master port; a delay response message task to send PTP delay response messages through the master port; and a timestamp update task to update the synchronization timestamp table used by the follow message task and the delay request timestamp table used by the delay response message task. Each round-robin session lasts less than a preset clock synchronization interval.
[0036] Process 103, based on clock synchronization interval timing to generate a hardware interrupt.
[0037] Process 104, respond to hardware interrupt, identify the master port used by the synchronized message task from the PTP configuration data table, record the master port in the synchronization port table and set the synchronization flag.
[0038] Process 105, detect the synchronization message sending event and the delay request message receiving event of the main port, and record 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 main port is updated in real time, and all real-time tasks that perform clock synchronization through the main port are scheduled in a round-robin manner, and all real-time tasks are scheduled within each clock synchronization interval, thereby realizing real-time clock synchronization through the main port.
[0040] Figure 2 This is a schematic diagram of the architecture of a time synchronization system provided in an embodiment of this disclosure. Figure 2As shown, the time synchronization system can include an optimal clock 20, a clock node 30, and clock nodes 41, 42, 43.
[0041] The optimal clock 20 can be manually set or elected based on a BMC algorithm, without limitation of the present disclosure.
[0042] The clock node 30 and the clock nodes 41, 42, 43 each determine the master-slave relationship among the clock nodes in a PTP domain through a 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, 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 clock nodes 41, 42, and 43 each receive the synchronization time through the slave ports P421-P431.
[0045] Figure 2 In the example, the number of master ports through which the clock node 30 publishes 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 can be implemented by an integrated circuit in which an embedded real-time operating system is deployed.
[0047] Figure 3 is a block diagram for showing real-time clock synchronization in a clock node based on the present disclosure.
[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 in which an embedded real-time operating system is deployed, such as an MCU.
[0049] The processor 310 of the clock node 30 runs the BMC algorithm. In the partial existing PTP clock synchronization mode, the processor 310 of the clock node controls a plurality of transactional tasks, and sends PTP protocol packets through each master port, so that the time synchronization of high-frequency synchronization interval cannot be provided. Taking the request-response mechanism as an example, when the master node sends PTP protocol packets through 48 master ports at a frequency of 128 times per second, the number of transactional CPUs of the master node sending synchronization packets, follow-up packets, and delay response packets through transactional tasks within each second is 18432, that is, 128*3*48; and the number of delay request packets received is 6144, that is, 128*1*48. Therefore, once any one of the plurality of transactional tasks of the processor performing PTP synchronization is not ended, the subsequent other transactional tasks cannot be scheduled, and the high-frequency clock synchronization cannot be provided.
[0050] In the present disclosure, the processor 310 of the clock node 30 does not send PTP protocol packets through the master port, and synchronizes the PTP configuration information for sending PTP protocol packets through the master ports P1-P3 to the real-time clock synchronization device 320.
[0051] Figure 4 is a block diagram for showing the PTP configuration information in the time node provided based on the present disclosure;
[0052] The real-time clock synchronization device 320 initializes and allocates the shared memory 301, and writes the base address add1 of the shared memory 301 into a public 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 complete the interaction with the real-time clock synchronization device 320.
[0054] The descriptor "cmd" at the starting position of the shared memory 301 includes two flag bits, a first flag bit valid and a second flag bit done.
[0055] The flag bit valid is used to identify whether the PTP configuration information is stored in the shared memory 301. For example, the value of the flag bit valid is a binary value 1, which indicates that the shared memory 301 stores the PTP configuration information; and the value of the flag bit valid is a binary value 0, which indicates that the shared memory 301 does not store the PTP configuration information to be synchronized.
[0056] The flag done is used to identify whether the PTP configuration data in the shared memory 301 has been read. For example, the value of the flag done is binary value 1, indicating that the PTP configuration information in the shared memory 301 has been read; the value of the flag done is binary value 0, indicating that the PTP configuration information in the shared memory 301 has not been read.
[0057] The processor 310 can set the binary value of cmd.done to 0 as well in the case of cmd.valid = 0, and 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 the configuration 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] The processor 310 then 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 the configuration real-time task R1, the synchronization message real-time task R2, the follow-up message real-time task R3, the delay request message real-time task R4, the delay response message real-time task R5, and the timestamp update real-time task R6, all having 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 no available data is read in any execution time slice, the real-time task control module 322 switches the currently scheduled real-time task to a 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 a clock synchronization interval, so that all the real-time tasks R1-R6 are scheduled in each clock synchronization interval. Taking the example of 128 times of clock synchronization per second, the clock synchronization interval is 7.8 milliseconds (ms), and the same time slice 0.5 ms is configured for these real-time tasks R1-R6.
[0062] The timer 321 counts according to the clock synchronization interval 7.8 ms.
[0063] The real-time task control module 322 can schedule the real-time tasks R1-R6 in a round robin mode based on the time slice 0.5 ms.
[0064] The real-time task control module 322 executes the configuration real-time task R1, reads the PTP configuration information from the shared memory 301 and writes the PTP configuration data table table 101 in the data memory 303 according to the process shown in the table 100. Figure 4
[0065] The real-time task control module 322 executes the synchronization message real-time task R2, and if no master port is identified in the synchronization port table 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-up message real-time task R3, and if no timestamp information is read from the synchronization timestamp table table 103, the follow-up 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, and if no delay request message is received through the master ports P1-P3, the delay request message real-time task R4 is switched 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 delay response message real-time task R5, and if no delay request message receiving timestamp is obtained from the delay request timestamp table table 104, the delay response message real-time task R5 is switched to the ready state.
[0069] The real-time task control module 322 executes the timestamp update real-time task R6, and if no synchronization message timestamp information and delay request message timestamp information is read from the timestamp module 323, 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 for multiple rounds, the timer 321 counts to the clock synchronization interval 7.8 ms, and outputs a hardware interrupt to the task control module 322.
[0071] The real-time task control module 322 suspends the execution of the currently scheduled real-time task in the real-time tasks R1-R6 in response to the hardware interrupt of the timer 321.
[0072] In one example, the real-time task control module 322 suspends the execution of the currently scheduled timestamp update real-time task R6 in response to the hardware interrupt of the timer 321. 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 table 101 record, records the master ports P1-P3 in the synchronization port table table 102, and sets the synchronization identifiers 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 is determined whether the time slice of the suspended time stamp update real-time task R6 has ended, and if not, the time stamp update real-time task R6 is continued to be executed; if yes, the time stamp update real-time task R6 is switched to the ready state, and the round-robin scheduling configuration real-time task R1 is continued to be executed.
[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 master ports P1-P3 that are set from the synchronization port table table 102, reads the synchronization message filling data of the master ports P1-P3 from the PTP configuration information of the PTP configuration data table table 101, calls the synchronization message template of the message template storage module 304, generates the synchronization messages respectively sent by the master ports P1-P3 based on the synchronization message filling data of the master ports P1-P3 and the synchronization message template, and sends the synchronization messages through the master ports P1-P3.
[0075] In the present application, the PTP configuration information synchronized by the processor 310 contains all information for implementing the sending of PTP clock synchronization. In this way, when the synchronization message real-time task R2, the follow-up message real-time task R3, and the delay response message real-time task R5 call the various templates stored in the message template storage module 304, the data of the PTP protocol messages and the values of the message header fields for completing the encapsulation of the PTP protocol messages are obtained from the PTP configuration information.
[0076] The time stamp module 323 detects the synchronization message sending events of the master ports P1-P3, and records the synchronization message time stamp information of the master ports P1-P3 respectively. In an example, the synchronization message time stamp information of the master port P1 includes the identification and sending time stamp of the master port P1 and the synchronization message sent by the master port P1. The synchronization message time stamp information of the master port P2 includes the identification and sending time stamp of the master port P2 and the synchronization message sent by the master port P2. The synchronization message time stamp information of the master port P3 includes the identification and sending time stamp of the master port P3 and the synchronization message sent by the master port P3. The identification of the synchronization message can include a message serial number or a session identification, which is used for the matching of the synchronization message (sync packet) and the follow-up message (follow-up packet) of the PTP protocol.
[0077] When the time slice of the time stamp update real-time task R6 arrives, the real-time task control module 322 executes the time stamp update real-time task R6, reads the synchronization message time stamp information of the master ports P1, P2, and P3 from the time stamp module 323, updates to the synchronization time stamp table table 103, and clears the synchronization message time stamp information of the master ports P1, P2, and P3 recorded by the time stamp 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 the respective master ports P1-P3 from the synchronization timestamp table table 103, reads the follow-up message filling data of the respective master ports P1-P3 from the PTP configuration information of the PTP configuration data table table 101, and calls the follow-up message template of the message template storage module 304 to generate the follow-up messages respectively sent through the respective master ports P1-P3 based on the respective follow-up message filling data of the master ports P1-P3, the synchronization message identifier, the synchronization message sending timestamp, and the follow-up message template.
[0079] Figure 2 In the process, the clock nodes 41-43 receive the follow-up messages and respectively send delay request messages to the clock node 30.
[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 respective master ports P1, P2, and P3.
[0081] The timestamp module 323 detects the respective delay request message receiving events of the master ports P1, P2, and P3 and records the respective delay request message timestamp information of the master ports P1, P2, and P3. The delay request message timestamp information of the master port P1 includes the identifier and the receiving timestamp of the delay request message received by the master port P1. The delay request message timestamp information of the master port P2 includes the identifier and the receiving timestamp of the delay request message received by the master port P2. The delay request message timestamp information of the master port P3 includes the identifier and the receiving timestamp of the delay request message received by the master port P3.
[0082] When the time slice of the timestamp updating real-time task R6 arrives, the real-time task control module 322 executes the timestamp updating real-time task R6, reads the delay request message timestamp information of the master ports P1, P2, and P3 from the timestamp module 323, updates the delay request timestamp table table 104, and clears the delay request message timestamp information of the master 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, acquires the delay request message timestamp information of the master ports P1-P3 respectively from the delay request timestamp table 104, and acquires the delay response message filling data of the master ports P1-P3 respectively from the PTP configuration information of the PTP configuration data table 101; calls the delayed response message template of the message template storage module 304; generates the delay response messages respectively sent through the master ports P1-P3 based on the delay response message filling data, the delay request message timestamp information, and the delay response message template of the master ports P1-P3; and sends the delay response messages through the master ports P1-P3.
[0084] In the present disclosure, the real-time synchronization device 320 rotates to execute the real-time tasks R1-R6 in a time less than the interval of once high-frequency clock synchronization, so that the execution order of the real-time tasks R1-R6 is decoupled, and parallel processing is realized in an 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, without taking the mode of hardware interruption, ensures the absolute reliability of the hardware interruption of the hardware timer 321 in the real-time synchronization device 320, and ensures the stable execution of the real-time clock synchronization according to the always synchronization interval.
[0086] Please refer to Figure 5 The present disclosure also provides a network device, as shown in Figure 5 The real-time clock synchronization device deployed with the 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, and writes the PTP configuration information into the shared memory of the real-time clock synchronization device.
[0088] The timer generates a hardware interruption based on the preset clock synchronization interval;
[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. The real-time task control module executes the configuration tasks to read PTP configuration information from the shared memory and write PTP configuration data tables based on the time slice in a round robin mode. The real-time task control module executes the synchronization message tasks to send PTP synchronization messages through the master port. The real-time task control module executes the follow-up message tasks to send PTP follow-up messages through the master port. The real-time task control module executes the delay request message tasks to receive PTP delay request messages through the master port. The real-time task control module executes the delay response message tasks to send PTP delay response messages through the master port. The real-time task control module executes the timestamp update tasks to update a synchronization timestamp table used by the follow-up message tasks and a delay request timestamp table used by the delay response message tasks. The time of each round robin is less than a preset high-frequency synchronization interval. The real-time task control module identifies the master port used by the synchronization message tasks from the PTP configuration data table records and records the master port in the synchronization port table and sets a synchronization identifier in response to a hardware interrupt.
[0090] The hardware timestamp module detects synchronization message sending events and delay request message receiving events of the master port, records synchronization message timestamp information for updating the synchronization timestamp table, and records delay request timestamp information for updating the delay request timestamp table.
[0091] The clock synchronization data storage module is configured 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 configured to store a synchronization message template, a follow-up message template, and a delay response message template.
[0093] The real-time task control module executes the synchronization message real-time task to send PTP synchronization messages through the master port, including identifying the synchronization identifier of the master port in the synchronization port table, reading synchronization message filling data of the master port from the PTP configuration data table, calling the synchronization message template, generating a synchronization message based on the synchronization message filling data and the synchronization message template, sending the synchronization message through the master port, and 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 to send PTP follow-up messages through the master port, including obtaining a synchronization message identifier and a synchronization message sending timestamp of a synchronization message sent by the master port from the synchronization timestamp table, reading follow-up message filling data of the master 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 master port.
[0095] The real-time task control module executes a delay response packet real-time task by sending a PTP delay response packet through the master port, including: obtaining a delay request packet identifier and a delay request packet receiving timestamp of the delay request packet received by the master port from a delay request timestamp table; reading delay response packet filling data of the master port from a PTP configuration data table; calling a delay response packet template; generating a delay response packet based on the delay response packet filling data, the delay request packet identifier, the delay request packet receiving timestamp, and the delay response packet template; and sending the delay response packet through the master port.
[0096] The real-time task control module executes a timestamp update real-time task for updating a synchronization timestamp table used by the followed packet real-time task, including: reading a synchronization packet identifier and a synchronization packet sending timestamp associated with the master port from a synchronization packet timestamp information; updating the read synchronization packet identifier and the synchronization packet sending timestamp to the synchronization timestamp table; and deleting the synchronization packet timestamp information.
[0097] 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 packet real-time task, including: reading a delay request packet identifier and a delay request packet receiving timestamp associated with the master port from a delay request packet timestamp information; updating the read delay request packet identifier and the delay request packet receiving timestamp to the delay request timestamp table; and deleting the delay request timestamp information.
[0098] The real-time task control module is further configured to determine that any one of the configuration real-time task, the synchronization packet real-time task, the followed packet real-time task, the delay request packet real-time task, the delay response packet real-time task, and the timestamp update real-time task has not read available data in an execution time slice, and switch to the ready state.
[0099] The real-time task control module is further configured to determine that a time slice of any one of the configuration real-time task, the synchronization packet real-time task, the followed packet real-time task, the delay packet real-time task, the delay response packet real-time task, and the timestamp update real-time task interrupted after responding to a hardware interrupt ends, and switch to the ready state.
[0100] When the embedded real-time operating system is running, the specific implementation process of the chip for implementing time synchronization is specifically shown in the implementation process of the corresponding steps in the above method, and will not be described here.
Claims
1. A method for real-time clock synchronization, characterized in that, The method comprises: creating a configuration real-time task, a synchronization message real-time task, a follow-up message real-time task, a delay request message real-time task, a delay response message real-time task, and a timestamp update real-time task with the same priority and the same time slice; based on the time slice, performing the configuration real-time task for reading PTP configuration information from shared memory and writing a PTP configuration data table, performing the synchronization message real-time task for sending a PTP synchronization message through a master port, performing the follow-up message real-time task for sending a PTP follow-up message through the master port, performing the delay request message real-time task for receiving a PTP delay request message through the master port, performing the delay response message real-time task for sending a PTP delay response message through the master port, and performing the timestamp update real-time task for updating a synchronization timestamp table used by the follow-up message real-time task and a delay request timestamp table used by the delay response message real-time task, and the time of each round is less than a preset high-frequency clock synchronization interval; generating a hardware interrupt based on the clock synchronization interval; in response to the hardware interrupt, identifying the master port used by the synchronization message real-time task from the PTP configuration data table record, recording the master port in a synchronization port table and setting a synchronization identifier; detecting a synchronization message sending event and a delay request message receiving event of the master port, recording synchronization message timestamp information for updating the synchronization timestamp table and delay request message timestamp information for updating the delay request timestamp table.
2. The method of claim 1, wherein, performing the synchronization message real-time task for sending a PTP synchronization message through a master port comprises, identifying the synchronization identifier of the master port in the synchronization port table; reading synchronization message filling data of the master port from the PTP configuration data table; calling a 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.
3. The method of claim 1, wherein, performing the follow-up message real-time task for sending a PTP follow-up message through the master port comprises, obtaining synchronization message identifier and synchronization message sending timestamp of the synchronization message sent by the master port from the synchronization timestamp table; reading follow-up message filling data of the master port from the PTP configuration data table; calling a follow-up message template; generating 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; sending the follow-up message through the master port.
4. The method of claim 1, wherein, performing the delay response message real-time task for sending a PTP delay response message through the master port comprises, obtaining delay request message identifier and delay request message receiving timestamp of the delay request message received by the master port from the delay request timestamp table; reading delay response message filling data of the master port from the PTP configuration data table; calling a delay response message template; generating 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; sending the delay response message through the master port.
5. The method of claim 1, wherein, The timestamp updating real-time task is used to update a synchronization timestamp table used by the follow-up message real-time task, and includes: reading the synchronization message identifier and the synchronization message sending timestamp associated with the master port from the synchronization message timestamp information; updating the read synchronization message identifier and the synchronization message sending timestamp to the synchronization timestamp table; deleting the synchronization message timestamp information; The timestamp updating real-time task is used to update a delay request timestamp table used by the delay response message real-time task, and includes: reading the delay request message identifier and the delay request message receiving timestamp associated with the master port from the delay request message timestamp information; updating the read delay request message identifier and the delay request message receiving timestamp to the delay request timestamp table; deleting the delay request message timestamp information.
6. The method of claim 1, wherein, The method further includes, determining that any one of the configuration real-time task, the synchronization message real-time task, the follow-up message real-time task, the delay request message real-time task, the delay response message real-time task and the timestamp updating real-time task does not read available data in an execution time slice, and switching to a ready state.
7. The method of claim 1, wherein, The method further includes, after responding to the hardware interrupt, determining 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 delay request message real-time task, the delay response message real-time task and the timestamp updating real-time task ends, and switching to a ready state.
8. An apparatus for real-time clock synchronization, the apparatus comprising: The device includes: a timer; a real-time task control module; a hardware timestamp module; a non-volatile storage medium for storing a set of machine executable instructions; a processor for executing the machine executable instructions and writing PTP configuration information into shared memory; the timer, based on a preset clock synchronization interval, generates a hardware interrupt; The real-time task control module creates 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, the configuration real-time tasks are executed in a round robin mode to read the PTP configuration information from the shared memory and write PTP configuration data tables; the synchronization message real-time tasks are executed to send PTP synchronization messages through a master port; the follow-up message real-time tasks are executed to send PTP follow-up messages through the master port; the delay request message real-time tasks are executed to receive PTP delay request messages through the master port; the delay response real-time message tasks are executed to send PTP delay response messages through the master port; the timestamp update real-time tasks are executed to update a synchronization timestamp table used by the follow-up message real-time tasks and a delay request timestamp table used by the delay response message real-time tasks; the time of each round is less than a preset high-frequency clock synchronization interval; in response to the hardware interrupt, the master port used by the synchronization message real-time tasks is identified from the PTP configuration data table record, and the master port is recorded in a synchronization port table and a synchronization identifier is set. The hardware timestamp module detects synchronization message sending events and delay request message receiving events of the master port, records synchronization message timestamp information for updating the synchronization timestamp table, and records delay request message timestamp information for updating the delay request timestamp table.
9. The apparatus of claim 8, wherein, The device further comprises: a clock synchronization data storage module for storing the PTP configuration data table, the synchronization port table, the synchronization timestamp table, and the delay request timestamp table; a message template storage module for storing a synchronization message template, a follow-up message template, and a delay response message template.
10. The apparatus of claim 9, wherein, The real-time task control module executes the synchronization message real-time tasks to send PTP synchronization messages through a master port, including: identifying the synchronization identifier of the master port in the synchronization port table; reading 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.
11. The apparatus of claim 9, wherein, The real-time task control module executes the follow-up message real-time tasks to send PTP follow-up messages through the master port, including: obtaining a synchronization message identifier and a synchronization message sending timestamp of the synchronization message sent by the master port from the synchronization timestamp table; reading follow-up message filling data of the master port from the PTP configuration data table; calling the follow-up message template; generating 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; sending the follow-up message through the master port.
12. The apparatus of claim 9, wherein, The real-time task control module executes the delay response packet real-time task to send a PTP delay response packet through the master port, which includes: Obtaining a delay request packet identifier and a delay request packet receiving timestamp of the delay request packet received by the master port from the delay request timestamp table; Reading delay response packet filling data of the master port from the PTP configuration data table; Calling a delay response packet template; Generating the delay response packet based on the delay response packet filling data, the delay request packet identifier, the delay request packet receiving timestamp and the delay response packet template; Sending the delay response packet through the master port.
13. The device of claim 9, wherein The real-time task control module executes the timestamp update real-time task to update a synchronization timestamp table used by the follow-up packet real-time task, which includes: Reading the synchronization packet identifier and the synchronization packet sending timestamp associated with the master port from the synchronization packet timestamp information; Updating the read synchronization packet identifier and the synchronization packet sending timestamp to the synchronization timestamp table; Deleting the synchronization packet timestamp information; The real-time task control module executes the timestamp update real-time task to update a delay request timestamp table used by the delay response packet real-time task, which includes: Reading the delay request packet identifier and the delay request packet receiving timestamp associated with the master port from the delay request packet timestamp information; Updating the read delay request packet identifier and the delay request packet receiving timestamp to the delay request timestamp table; Deleting the delay request packet timestamp information.
14. The device of claim 9, wherein The real-time task control module is further configured to determine that any one of the configuration real-time task, the synchronization packet real-time task, the follow-up packet real-time task, the delay request packet real-time task, the delay response packet real-time task and the timestamp update real-time task does not read available data in an execution time slice, and switch to a ready state.
15. The device of claim 9, wherein The real-time task control module is further configured to determine that the execution time slice of any one of the configuration real-time task, the synchronization packet real-time task, the follow-up packet real-time task, the delay request packet real-time task, the delay response packet real-time task and the timestamp update real-time task interrupted in response to the hardware interrupt ends, and switch to a ready state.
Citation Information
Patent Citations
Clock synchronization method, system and equipment based on PTP
CN103441832A
Clock synchronization method and device
CN106533600A