Clock synchronization method, device, equipment, medium and product

By revising and sending RTC clock count values ​​into real-time tasks, using WiFi and/or Bluetooth clock sources, combined with PTP protocol and message discarding strategy, the clock synchronization error problem is solved and higher clock synchronization is achieved Accuracy, suitable for industrial control and real-time communication.

CN118466691BActive Publication Date: 2024-11-12深圳开鸿数字产业发展有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410912376.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-09
Publication Date
2024-11-12
Estimated Expiration
2044-07-09

AI Technical Summary

Technical Problem

In the prior art, there is millisecond error in clock synchronization, which is mainly due to the delay problem caused by switching of clock synchronization-related tasks in the operating system.

Method used

By revising the reading and sending tasks of RTC clock count values, adjusting their priority to real-time tasks, reducing switching delay, and using WiFi and/or Bluetooth clock sources to improve clock synchronization accuracy, using PTP protocol and If necessary, discard messages with excessive transmission delay.

Benefits of technology

It effectively reduces the delay caused by task switching, improves clock synchronization accuracy, and increases from millisecond-level error to microsecond-level, suitable for industrial control and real-time communication fields.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118466691B_ABST
    Figure CN118466691B_ABST
Patent Text Reader

Abstract

The present application discloses a clock synchronization method, device, equipment, medium and product, which relates to the technical field of clock synchronization, and discloses a clock synchronization method, a clock synchronization device, a clock synchronization device, a storage medium and a computer program product. By modifying the reading task and the sending task of the RTC clock count value, the switching delay from the reading task to the sending task is reduced to below the preset delay, so that clock synchronization is performed based on the modified reading task and the sending task, thereby reducing the delay caused by task switching, further reducing the error in clock synchronization, and finally improving the accuracy of clock synchronization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of clock synchronization, and in particular to a clock synchronization method, a clock synchronization apparatus, a clock synchronization device, a storage medium and a computer program product. Background Art

[0002] Currently, in conventional means of achieving clock synchronization, there is a millisecond error in clock synchronization due to the switching of clock synchronization-related tasks in the operating system and the delay caused by the switching of related tasks.

[0003] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0004] The main purpose of the present application is to provide a clock synchronization method, a clock synchronization device, a clock synchronization equipment, a storage medium and a computer program product, aiming to solve the technical problem of poor clock synchronization accuracy.

[0005] To achieve the above object, the present application proposes a clock synchronization method, the method comprising:

[0006] Determine the reading and sending tasks of the RTC clock count value;

[0007] By modifying the reading task and the sending task, the switching delay from the reading task to the sending task is reduced to below a preset delay;

[0008] Clock synchronization is performed based on the reading and sending tasks whose switching delay is reduced to below the preset delay.

[0009] In one embodiment, the step of transforming the reading task and the sending task includes:

[0010] By increasing the priorities of the reading task and the sending task, the reading task and the sending task are adjusted to real-time tasks, so as to reduce the switching delay from the reading task to the sending task to below the preset delay.

[0011] In one embodiment, the method further comprises:

[0012] Use WiFi and / or Bluetooth clock sources as RTC clock sources;

[0013] The RTC clock count value is read and obtained through the WiFi and / or Bluetooth clock source.

[0014] In one embodiment, the step of reading and obtaining the RTC clock count value through the WiFi and / or Bluetooth clock source includes:

[0015] The RTC clock count value is obtained by reading from the WiFi and / or Bluetooth clock source by connecting to the crystal oscillator port of the RTC clock counter and the WiFi and / or Bluetooth general IO port.

[0016] In one embodiment, the time synchronization protocol adopts the PTP protocol, and the method further includes:

[0017] Transmit PTP protocol messages via WiFi and / or Bluetooth.

[0018] In one embodiment, the step of transmitting the PTP protocol message via Bluetooth includes:

[0019] When the transmission delay of the PTP protocol message is greater than or equal to the frequency hopping duration of the Bluetooth transmission, the PTP protocol message is discarded.

[0020] In addition, to achieve the above purpose, the present application also proposes a clock synchronization device, the device comprising:

[0021] A determination module is used to determine the reading task and sending task of the RTC clock count value;

[0022] A transformation module, used for reducing the switching delay from the reading task to the sending task to less than a preset delay by transforming the reading task and the sending task;

[0023] The synchronization module is used to perform clock synchronization based on the reading task and the sending task whose switching delay is reduced to below the preset delay.

[0024] In addition, to achieve the above objectives, the present application also proposes a clock synchronization device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the clock synchronization method described above.

[0025] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the clock synchronization method described above are implemented.

[0026] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the clock synchronization method described above are implemented.

[0027] One or more technical solutions proposed in this application have at least the following technical effects:

[0028] In the present application, by modifying the reading task and sending task of the RTC clock count value, the switching delay from the reading task to the sending task is reduced to below the preset delay, so that clock synchronization is performed based on the modified reading task and sending task, thereby reducing the delay caused by task switching, further reducing the error in clock synchronization, and ultimately improving the clock synchronization accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0030] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0031] Figure 1 A schematic diagram of a process flow provided for Embodiment 1 of the clock synchronization method of the present application;

[0032] Figure 2 A schematic diagram of an RTC crystal oscillator provided in Embodiment 1 of the clock synchronization method of the present application;

[0033] Figure 3 A schematic diagram of the PTP clock synchronization principle provided in Embodiment 1 of the clock synchronization method of the present application;

[0034] Figure 4 A schematic diagram of current task switching provided in Embodiment 1 of the clock synchronization method of the present application;

[0035] Figure 5 A schematic diagram of task switching after modification provided in Embodiment 1 of the clock synchronization method of the present application;

[0036] Figure 6 A schematic diagram of a modified clock source provided in Embodiment 2 of the clock synchronization method of the present application;

[0037] Figure 7 This is a schematic diagram of the module structure of the clock synchronization device according to an embodiment of the present application;

[0038] Figure 8 A schematic diagram of the device structure of the hardware operating environment involved in the clock synchronization method in the embodiment of the present application.

[0039] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0040] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0041] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0042] The present application provides a clock synchronization method. Figure 1 , Figure 1 This is a flowchart of the first embodiment of the clock synchronization method of the present application.

[0043] In this embodiment, the clock synchronization method includes steps S10 to S30:

[0044] Step S10, determining the reading task and sending task of the RTC clock count value;

[0045] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device that can realize the above functions.

[0046] In addition, it should be noted that the RTC clock count value reading task refers to the task of reading the RTC clock count value, and the RTC clock count value sending task refers to the task of sending the read RTC clock count value in order to synchronize the read RTC clock count value.

[0047] In one embodiment, the RTC clock count value is obtained by reading the RTC clock counter through the crystal oscillator port. Figure 2 Generally, an external RTC crystal oscillator is used as the clock signal source of the CPU clock, and the RTC clock counter inside the CPU is used to calculate the time.

[0048] In one embodiment, the sending task is a PTP protocol task. The following further explains PTP. The operating system calculates the time synchronization protocol such as PTP. After confirming the optimal clock and the master-slave relationship between the clock nodes, the master clock and the slave clock exchange Sync synchronization messages to achieve frequency synchronization. The master clock periodically sends Sync synchronization messages to the slave clock. If the change of link delay is not considered, and the frequency of the slave clock is synchronized with the master clock, then in the same time interval, the accumulated time deviation of the master clock and the slave clock should be the same, such as Figure 3As shown, T(n + 1) - Tn = T(n + 1)' - Tn'. If the time deviations are not the same: 1. When T(n + 1) - Tn > T(n + 1)' - Tn', it indicates that the time of the slave clock is slower than that of the master clock and the frequency is faster than that of the master clock, so the frequency of the slave clock needs to be adjusted downwards; 2. When T(n + 1) - Tn < T(n + 1)' - Tn', it indicates that the time of the slave clock is faster than that of the master clock and the frequency is slower than that of the master clock, so the frequency of the slave clock needs to be adjusted upwards. Further, the frequency ratio calculation formula is: (T(n + 1) - Tn) / (T(n + 1)' - Tn'), and the slave clock adjusts the frequency of the local clock chip according to the calculated frequency ratio.

[0049] Step S20: By reforming the reading task and the sending task, reduce the switching delay from the reading task to the sending task to below a preset delay.

[0050] Refer to Figure 4 , currently, in the operating system, since the operating system needs to switch tasks to read the RTC clock count value Tn and then send it out through the network, there will be a phenomenon that the delay caused by task switching is accumulated into the RTC clock count value Tn. Moreover, because the time for task switching is generally between 10ms and 1ms, the current conventional means will introduce millisecond-level errors to time synchronization.

[0051] In one embodiment, the reading task and the sending task are reformed to be real-time tasks, thereby reducing the switching delay from the reading task to the sending task to below a preset delay, further reducing the switching delay from the reading task to the sending task, and thus reducing the error of time synchronization.

[0052] In a feasible implementation manner, step S20 includes:

[0053] By increasing the priorities of the reading task and the sending task, adjust the reading task and the sending task to real-time tasks to reduce the switching delay from the reading task to the sending task to below a preset delay.

[0054] In one embodiment, the system real-time reform method uses the RT Preempt patch to achieve real-time reform and reduces the switching time of high-priority tasks to below 30us. It should be noted that the RT Preempt patch will occasionally switch up to 500us, but the average delay is below 30us. Therefore, the delay can reach within 30us after averaging.

[0055] In one embodiment, the task of reading the RTC count value in the operating system, namely the reading task, is transformed into a real-time task, namely the real-time task, wherein the switching time of the real-time task can be less than 30 us.

[0056] In one embodiment, the time synchronization protocol uses the PTP protocol, and the priority of the task within the PTP protocol, that is, the sending task, is raised to a high priority to ensure that the delay of switching to the PTP protocol task is less than 30us. Figure 5 shown.

[0057] Step S30, performing clock synchronization based on the reading task and the sending task whose switching delay is reduced to below the preset delay.

[0058] In this embodiment, by modifying the reading task and sending task of the RTC clock count value, the switching delay from the reading task to the sending task is reduced to below the preset delay, so that clock synchronization is performed based on the modified reading task and sending task, thereby reducing the delay caused by task switching, further reducing the error in clock synchronization, and ultimately improving the clock synchronization accuracy. Thus, the problem of excessive clock synchronization error accuracy within the operating system is solved, and the real-time performance of industrial control and communication is achieved by designing a microsecond-level time synchronization solution.

[0059] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. On this basis, the method further includes the steps of:

[0060] Use WiFi and / or Bluetooth clock sources as RTC clock sources;

[0061] The RTC clock count value is read and obtained through the WiFi and / or Bluetooth clock source.

[0062] At present, the clock synchronization algorithm in the current operating system generally uses protocols such as NTP and PTP for clock synchronization. The synchronization clock source used by this synchronization protocol is generally adopted. Figure 2 The system RTC clock shown in the figure has an accuracy of ±10PPM, and the error can reach 0.864 seconds per day. In addition, the synchronization accuracy of protocols such as NTP and PTP is in the millisecond level, so this synchronization clock accuracy cannot be used for industrial control with microsecond synchronization accuracy.

[0063] Considering: 1. There are generally two wireless communication methods in existing IoT devices, WiFi and Bluetooth. These wireless communication methods are all carried out in the 2.4Ghz frequency band. This frequency band has a lot of communication means, so the devices that use this frequency band for communication generally have their own unique communication methods. For example, WiFi uses carrier sensing to solve the problem of air interface occupation. Carrier sensing will have an inter-frame interval, such as 10us in IEEE 802.11b / g and 16us in IEEE 802.11a. After the inter-frame interval, the devices start to listen to the time DIFS. The DCFInterframe Space (DIFS) is generally between 28us and 50us, so the time interval of WiFi carrier sensing requires the clock synchronization accuracy between WiFi devices to be less than 1us. 2. Bluetooth uses frequency hopping for P2P communication. The frequency hopping order is negotiated between the two devices. The time slot length of the frequency hopping time is 625us, so the synchronization accuracy between Bluetooth communication devices is also required to be synchronized to less than 1us for mutual frequency hopping operations.

[0064] Therefore, in this embodiment, the hardware RTC clock source is modified and changed to a WiFi and / or Bluetooth clock source with higher accuracy, that is, the CPU RTC clock source uses a WiFi and / or Bluetooth clock, and the RTC clock count value is obtained by reading the WiFi and / or Bluetooth clock source, thereby improving the clock source accuracy. Based on a higher accuracy clock source, the accuracy of time synchronization is further improved and the error of time synchronization is reduced.

[0065] Optionally, the step of reading and obtaining the RTC clock count value through the WiFi and / or Bluetooth clock source includes:

[0066] The RTC clock count value is obtained by reading from the WiFi and / or Bluetooth clock source by connecting to the crystal oscillator port of the RTC clock counter and the WiFi and / or Bluetooth general IO port.

[0067] In one embodiment, referring to Figure 6 , the WiFi and / or Bluetooth clock is brought out through a general IO port of the WiFi and / or Bluetooth chip and connected to the CPU crystal oscillator port. At the same time, the crystal oscillator port where the clock source is located is modified inside the CPU, and the newly introduced crystal oscillator port is used as the RTC counting clock source, thereby connecting the crystal oscillator port of the RTC clock counter and the WiFi and / or Bluetooth general IO port, and reading the RTC clock count value from the WiFi and / or Bluetooth clock source.

[0068] It should be noted that in the networking and industrial control fields of multiple wireless devices, the clock synchronization accuracy is often required to reach a clock synchronization accuracy of tens of microseconds. In order to achieve this synchronization accuracy, a hardware clock synchronization chip can also be used to complete the clock synchronization, such as the 1588v2 clock synchronization related protocol. This protocol requires the addition of another hardware clock synchronization chip in the system to complete the clock synchronization. This undoubtedly adds additional costs for general IoT devices. In this embodiment, WiFi and / or Bluetooth chips that are generally available in IoT devices are used to improve the accuracy of time synchronization while reducing the cost of improving time synchronization.

[0069] In addition, it should be noted that if the above hardware clock synchronization chip is used to run reading tasks and sending tasks such as PTP protocol, when there is no problem of operating system task switching, the accuracy can be improved to microsecond level by increasing the hardware cost. Figure 2 Based on the hardware problem of low precision of the system RTC clock shown, the software method in the first embodiment can be further adopted to solve the software error caused by the task switching of the operating system and further improve the precision of time synchronization.

[0070] Optionally, the time synchronization protocol adopts the PTP protocol, and the method further includes:

[0071] Transmit PTP protocol messages via WiFi and / or Bluetooth.

[0072] Optionally, the step of transmitting the PTP protocol message via Bluetooth includes:

[0073] When the transmission delay of the PTP protocol message is greater than or equal to the frequency hopping duration of the Bluetooth transmission, the PTP protocol message is discarded.

[0074] Since the WiFi air interface sends data after carrier sensing, the length of time is uncertain, which will introduce network transmission delay, so the time synchronization protocol will have less conflict when using Bluetooth transmission.

[0075] Bluetooth uses frequency hopping to transmit data. Each Bluetooth frequency hopping time is 625us. Therefore, when the transmission delay of the PTP protocol message is greater than or equal to the frequency hopping duration of the Bluetooth transmission, that is, when the transmission delay exceeds the 625us network transmission time, the data packet is discarded in the PTP protocol and is not used for the calculation of the protocol time to avoid introducing frequency hopping delay.

[0076] Through Bluetooth transmission, the Bluetooth network transmission delay is generally around 125us. By calculating (T(n+1)-Tn) / (T(n+1)'-Tn') multiple times, it can be seen that the network transmission delay calculation error can be reduced to less than 125us.

[0077] By accumulating several delay errors, namely task switching error 30us + transmission delay error 125us + WiFi and / or Bluetooth crystal oscillator error 1us, the total error of clock synchronization accuracy can be controlled below 200us, thereby improving the time synchronization accuracy between operating systems from milliseconds to microseconds, and providing higher-precision clock synchronization in the fields of industrial control and real-time communication.

[0078] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the clock synchronization method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0079] This application also provides a clock synchronization device, please refer to Figure 7 , the clock synchronization device comprises:

[0080] A determination module 10 is used to determine a reading task and a sending task of an RTC clock count value;

[0081] A transformation module 20, configured to reduce a switching delay from the reading task to the sending task to less than a preset delay by transforming the reading task and the sending task;

[0082] The synchronization module 30 is used to perform clock synchronization based on the reading task and the sending task whose switching delay is reduced to less than the preset delay.

[0083] In one embodiment, the transformation module is further used for:

[0084] By increasing the priorities of the reading task and the sending task, the reading task and the sending task are adjusted to real-time tasks, so as to reduce the switching delay from the reading task to the sending task to below the preset delay.

[0085] In one embodiment, the clock synchronization device further includes a clock module, which is used to:

[0086] Use WiFi and / or Bluetooth clock sources as RTC clock sources;

[0087] The RTC clock count value is read and obtained through the WiFi and / or Bluetooth clock source.

[0088] In one embodiment, the clock module is further used for:

[0089] The RTC clock count value is obtained by reading from the WiFi and / or Bluetooth clock source by connecting to the crystal oscillator port of the RTC clock counter and the WiFi and / or Bluetooth general IO port.

[0090] In one embodiment, the time synchronization protocol adopts the PTP protocol, and the clock module is further used for:

[0091] Transmit PTP protocol messages via WiFi and / or Bluetooth.

[0092] In one embodiment, the clock module is further used for:

[0093] When the transmission delay of the PTP protocol message is greater than or equal to the frequency hopping duration of the Bluetooth transmission, the PTP protocol message is discarded.

[0094] The clock synchronization device provided by the present application adopts the clock synchronization method in the above embodiment, which can solve the technical problem of poor clock synchronization accuracy. Compared with the prior art, the beneficial effects of the clock synchronization device provided by the present application are the same as the beneficial effects of the clock synchronization method provided by the above embodiment, and other technical features in the clock synchronization device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0095] The present application provides a clock synchronization device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the clock synchronization method in the above-mentioned embodiment one.

[0096] Reference below Figure 8 , which shows a schematic diagram of the structure of a clock synchronization device suitable for implementing the embodiment of the present application. The clock synchronization device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The clock synchronization device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0097] like Figure 8As shown, the clock synchronization device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the clock synchronization device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the clock synchronization device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a clock synchronization device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0098] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0099] The clock synchronization device provided by the present application adopts the clock synchronization method in the above embodiment, which can solve the technical problem of poor clock synchronization accuracy. Compared with the prior art, the beneficial effects of the clock synchronization device provided by the present application are the same as the beneficial effects of the clock synchronization method provided by the above embodiment, and other technical features in the clock synchronization device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0100] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0101] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0102] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the clock synchronization method in the above-mentioned embodiment.

[0103] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0104] The computer-readable storage medium may be included in the clock synchronization device; or may exist independently without being assembled into the clock synchronization device.

[0105] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the clock synchronization device, the clock synchronization device: determines the reading task and the sending task of the RTC clock count value; by modifying the reading task and the sending task, the switching delay from the reading task to the sending task is reduced to below the preset delay; based on the reading task and the sending task whose switching delay is reduced to below the preset delay, clock synchronization is performed.

[0106] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0107] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0108] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0109] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned clock synchronization method, and can solve the technical problem of poor clock synchronization accuracy. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the clock synchronization method provided in the above-mentioned embodiment, and will not be described in detail here.

[0110] The present application also provides a computer program product, including a computer program, which implements the steps of the clock synchronization method as described above when executed by a processor.

[0111] The computer program product provided by the present application can solve the technical problem of poor clock synchronization accuracy. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the clock synchronization method provided by the above embodiment, which will not be repeated here.

[0112] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A clock synchronization method, characterized in that: The method includes: Determine the reading and sending tasks of the RTC clock count value in the same device operating system; By modifying the reading task and the sending task, the switching delay from the reading task to the sending task is reduced to below a preset delay; Based on the switching delay being reduced to below the preset delay, clock synchronization is performed for the reading task and the sending task; The method further comprises: Use WiFi and / or Bluetooth clock sources as RTC clock sources; Read and obtain the RTC clock count value through the WiFi and / or Bluetooth clock source; The step of transforming the reading task and the sending task includes: By increasing the priorities of the reading task and the sending task, the reading task and the sending task are adjusted to real-time tasks, so as to reduce the switching delay from the reading task to the sending task to below the preset delay.

2. The method according to claim 1, characterized in that The step of reading and obtaining the RTC clock count value through the WiFi and / or Bluetooth clock source includes: The RTC clock count value is obtained by reading from the WiFi and / or Bluetooth clock source by connecting to the crystal oscillator port of the RTC clock counter and the WiFi and / or Bluetooth general IO port.

3. The method according to claim 1, characterized in that The time synchronization protocol adopts the PTP protocol, and the method further includes: Transmit PTP protocol messages via WiFi and / or Bluetooth.

4. The method according to claim 3, characterized in that The step of transmitting the PTP protocol message via Bluetooth comprises: When the transmission delay of the PTP protocol message is greater than or equal to the frequency hopping duration of the Bluetooth transmission, the PTP protocol message is discarded.

5. A clock synchronization device, characterized in that: The device comprises: A determination module, used to determine the reading task and sending task of the RTC clock count value in the same device operating system; A transformation module, used for reducing the switching delay from the reading task to the sending task to less than a preset delay by transforming the reading task and the sending task; A synchronization module, used for clock synchronization based on the reading task and the sending task whose switching delay is reduced to below the preset delay; The clock synchronization device further comprises a clock module, which is used for: Use WiFi and / or Bluetooth clock sources as RTC clock sources; Read and obtain the RTC clock count value through the WiFi and / or Bluetooth clock source; The transformation module is also used for: By increasing the priorities of the reading task and the sending task, the reading task and the sending task are adjusted to real-time tasks, so as to reduce the switching delay from the reading task to the sending task to below the preset delay.

6. A clock synchronization device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the clock synchronization method according to any one of claims 1 to 4.

7. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the clock synchronization method according to any one of claims 1 to 4 are implemented.

8. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the clock synchronization method according to any one of claims 1 to 4 are implemented.