Clock synchronization method, device and equipment, computer readable storage medium and vehicle
By receiving the number and frequency of the oscillation in the main clock message, the current time of the slave clock is calculated, and the clock synchronization of the control unit in the automotive network is realized, the problem of lack of reference time is solved, and the synchronization efficiency is improved.
Patent Information
- Application Number
- CN202310520741.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-09
- Publication Date
- 2024-11-12
AI Technical Summary
In automotive networks, many control units lack reference time and cannot perform clock synchronization, resulting in the inability to work in a coordinated and orderly manner, especially when using the GPTP protocol for time synchronization, there is a lack of unified and high-precision reference time.
By receiving the message sent by the main clock, we judge whether the current value of the clock count mark bit is a preset value, obtain the number of oscillations and oscillation frequency of the main clock, calculate the time expressed by the message, and calculate the slave clock based on the preset time difference At present time, the master and slave clock synchronization is realized to avoid dependence on the reference time.
In the absence of reference time, the precise synchronization of the slave clock is achieved, the synchronization efficiency of the master and slave clock is improved, and the problem of the microcontroller or chip that must rely on reference time when clock synchronization is achieved by microcontroller or chip.
Smart Images

Figure CN118944793A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of clocks, and in particular to the field of clock synchronization technology. Background Art
[0002] In the existing technology, when using the GPTP (general precise time protocol, a derivative of the PTP protocol) protocol for time synchronization, the time transmitted from the master clock to the slave clock is in seconds and nanoseconds, that is, the number of seconds and nanoseconds after a common time point. This requires that both clocks for time synchronization (the one that sends time is the master clock, such as the gateway; the one that receives time is the slave clock, such as the ECU (Electronic Control Unit)) need to have a common agreed time point as the reference time, usually 0:00 on January 1, 1970.
[0003] In the automotive network, there are many hardware devices with single control unit functions and extremely simplified operating systems. They do not have the time calibration function, nor the function of obtaining time through NTP (Network Time Protocol). However, according to the existing clock synchronization method, in order to ensure that these devices can work in coordination and order, there must be a unified, high-precision clock with a reference time to ensure the orderly coordination of various devices.
[0004] In fact, many components of a vehicle are relatively simple, such as a single-chip microcomputer, and there is no reference time, so clock synchronization is impossible. Summary of the invention
[0005] The present disclosure provides a clock synchronization method, apparatus, device, storage medium and vehicle.
[0006] According to a first aspect of the present disclosure, a clock synchronization method is provided. The method comprises:
[0007] Receive messages sent by the master clock;
[0008] Determine whether the current value of the clock count flag bit in the message is a preset value; wherein the clock count flag bit occupies a reserved field of the message, and the preset value is used to indicate that the message carries the number of oscillations and the oscillation frequency of the master clock;
[0009] If yes, obtaining the number of oscillations and the oscillation frequency of the master clock from the message;
[0010] Calculating the time expressed by the message based on the number of oscillations and the oscillation frequency;
[0011] The current time of the slave clock is calculated based on the time expressed in the message and a pre-calculated preset time difference, wherein the preset time difference is a time deviation of the slave clock relative to the master clock.
[0012] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein the method further includes:
[0013] If the current value of the clock count flag bit in the message is not a preset value, obtaining the original timestamp carried in the message;
[0014] The current time of the slave clock is calculated based on the original timestamp and the preset time difference.
[0015] According to the above aspects and any possible implementation manner, an implementation manner is further provided, before determining whether the current value of the clock count flag bit in the message is a preset value, the method further includes:
[0016] Searching for the reserved field in the message;
[0017] The current value of the clock count flag bit is read from the reserved field.
[0018] According to the above aspect and any possible implementation manner, an implementation manner is further provided, wherein obtaining the number of oscillations and the oscillation frequency of the master clock from the message includes:
[0019] Searching for a count field in the message; wherein the count field occupies N bytes;
[0020] Reading the oscillation number from the first n bytes of the count field;
[0021] The oscillation frequency is read from the last (Nn) bytes of the count field, wherein n and N are both positive integers, N is greater than 10, and n is less than N.
[0022] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein the calculating the time expressed by the message based on the number of oscillations and the oscillation frequency includes:
[0023] Calculating a ratio of the number of oscillations to the oscillation frequency;
[0024] If the message does not carry the reference time of the master clock, the ratio is used as the time expressed by the message.
[0025] If the message carries the reference time of the master clock, the sum of the ratio and the reference time is used as the time expressed by the message.
[0026] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein the current time of the slave clock is calculated based on the time expressed by the message and the pre-calculated preset time difference, including:
[0027] If both the master clock and the slave clock have a reference time, obtaining a pre-calculated time deviation of the slave clock relative to the master clock;
[0028] Determining the time deviation as the preset time difference;
[0029] The sum of the time expressed in the message and the preset time difference is calculated and used as the current time of the slave clock.
[0030] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein the current time of the slave clock is calculated based on the time expressed by the message and the pre-calculated preset time difference, including:
[0031] If the slave clock has no reference time, obtaining a pre-calculated unidirectional link transmission time between the slave clock and the master clock;
[0032] Determining the unidirectional link transmission time as the preset time difference;
[0033] The sum of the time expressed in the message and the preset time difference is calculated and used as the current time of the slave clock.
[0034] According to a second aspect of the present disclosure, a clock synchronization device is provided. The device comprises:
[0035] A receiving module, used for receiving messages sent by the master clock;
[0036] A judgment module, used to judge whether the current value of the clock count flag bit in the message is a preset value; wherein the clock count flag bit occupies a reserved field of the message, and the preset value is used to indicate that the message carries the number of oscillations and the oscillation frequency of the master clock;
[0037] An acquisition module, configured to acquire the number of oscillations and the oscillation frequency of the master clock from the message if yes;
[0038] A first calculation module, used for calculating the time expressed by the message based on the number of oscillations and the oscillation frequency;
[0039] The second calculation module is used to calculate the current time of the slave clock based on the time expressed by the message and a pre-calculated preset time difference, wherein the preset time difference is the time deviation of the slave clock relative to the master clock.
[0040] According to a third aspect of the present disclosure, an electronic device is provided, which includes a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the program, the method described above is implemented.
[0041] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method according to the first aspect of the present disclosure is implemented.
[0042] According to a fifth aspect of the present disclosure, a vehicle is provided, the vehicle comprising the clock synchronization device as described in the second aspect and / or the electronic device as described in the third aspect.
[0043] In the present disclosure, after receiving a message sent by the master clock, it can be determined whether the current value of the clock count mark in the message is a preset value. If so, the number of oscillations and the vibration frequency recorded in the message are read, and then based on the number of vibrations and the oscillation frequency, the time expressed by the message is automatically calculated, and then based on the time expressed by the message and the pre-calculated preset time difference, the current time of the slave clock can be automatically calculated. In this way, without the need for a reference time, an accurate slave clock that changes synchronously with the master clock can be calculated based on the number of vibrations and the vibration frequency of the master clock, thereby realizing the synchronization of the master and slave clocks, and solving the problem that a single-chip microcomputer or chip must rely on a reference time to achieve clock synchronization.
[0044] It should be understood that the contents described in the summary of the invention are not intended to limit the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, among which:
[0046] Figure 1 A flow chart of a clock synchronization method according to an embodiment of the present disclosure is shown;
[0047] Figure 2 A flow chart of a clock synchronization method in the prior art is shown;
[0048] Figure 3 The format of the Ethernet encapsulated PTP message PTP over Ethernet in the prior art is shown;
[0049] Figure 4The format of the gPTP packet header in the prior art is shown;
[0050] Figure 5 Shows Figure 4 The format of the Sync message in the Message Field field;
[0051] Figure 6 Shows Figure 4 The format of the Follow Up message in the Message Field field;
[0052] Figure 7 Shows Figure 4 The format of the PDelay_Req message in the Message Field field;
[0053] Figure 8 Shows Figure 4 The format of the PDelay_Resp message in the Message Field field;
[0054] Fig. 9 Shows Figure 4 The format of the PDelay_Resp_Follow_Up message in the Message Field field;
[0055] Fig.10 The format of the Origin Timestamp field in the prior art is shown;
[0056] Fig.11A The format of the Timestamp field in the present disclosure is shown;
[0057] Fig. 11B The format of the reference time in the present disclosure is shown;
[0058] Fig.12 A block diagram of a clock synchronization device according to an embodiment of the present disclosure is shown;
[0059] Fig.13 A block diagram of an exemplary electronic device capable of implementing embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0061] In addition, the term "and / or" in this article is only a description of the association relationship between the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0062] Figure 1 A flow chart of a clock synchronization method 100 according to an embodiment of the present disclosure is shown. The method 100 may include:
[0063] Step 110, receiving a message sent by the master clock;
[0064] The master clock is any device in the vehicle that sends time, such as a gateway; the slave clock is a device in the vehicle that receives time, such as an ECU.
[0065] Step 120, determining whether the current value of the clock count flag bit in the message is a preset value; wherein the clock count flag bit occupies the original reserved field in the message, and the preset value is used to indicate that the message carries the number of oscillations and the oscillation frequency of the master clock;
[0066] The clock count mark bit may be a reserved field in the message or a certain bit / bits in the reserved field.
[0067] For example, in a general message header, the reserved field of FlagField may be used as a clock count flag.
[0068] The current value of the clock count mark can be one of two types, 0 or 1, True or False, and the preset value can be 0 or 1, or, True or False.
[0069] For example: reserved field->Tick count flag, when set to TRUE, it means that the timestamp information of this message is represented by TickCount (that is, the number of vibrations and the vibration frequency); when set to FALSE, it means that the timestamp information is represented by seconds and nanoseconds.
[0070] Step 130: If yes, obtain the oscillation number and oscillation frequency of the master clock from the message;
[0071] Step 140, calculating the time expressed by the message based on the oscillation number and the oscillation frequency;
[0072] In some embodiments, the time expressed by the message=number of oscillations / oscillation frequency.
[0073] Step 150, calculating the current time of the slave clock based on the time expressed in the message and a pre-calculated preset time difference, wherein the preset time difference is the time deviation of the slave clock relative to the master clock.
[0074] In some embodiments, the current time of the slave clock = the time expressed by the message + the preset time difference.
[0075] What needs to be explained here is that the essence of synchronized clocks is to eliminate the time deviation between the master and slave clocks. After calculating the time expressed by the message, the elimination process is combined with the preset time difference, which ultimately ensures that the slave clock can have a current time that is synchronized with the time expressed by the master clock; that is, the purpose of synchronization is to make the slave clock time accurate and can change synchronously with the master clock, and the master clock already has a time, namely the time expressed by the message. At this time, as long as the current time of the slave clock is accurate, the synchronization is completed.
[0076] After receiving the message sent by the master clock, it can be determined whether the current value of the clock count mark in the message is a preset value. If so, the number of oscillations and the vibration frequency recorded in the message are read, and then based on the number of vibrations and the oscillation frequency, the time expressed by the message is automatically calculated, and then based on the time expressed by the message and the pre-calculated preset time difference, the current time of the slave clock can be automatically calculated. In this way, without the need for a reference time, an accurate slave clock that changes synchronously with the master clock can be calculated based on the number of vibrations and the vibration frequency of the master clock, thereby realizing the synchronization of the master and slave clocks and solving the problem that the single-chip microcomputer or chip must rely on the reference time when realizing clock synchronization.
[0077] In addition, since the present invention uses the number of oscillations and the oscillation frequency for clock synchronization and does not use the reference time, and the reference time can calculate the absolute time, the present invention does not rely on absolute time, seconds and nanoseconds when synchronizing the clock, thereby eliminating the conversion process between absolute time and seconds and nanoseconds when synchronizing the clock, and improving the efficiency of the master-slave clock synchronization.
[0078] The absolute time is the time calculated based on the reference time.
[0079] In some embodiments, the method further comprises:
[0080] If the current value of the clock count flag bit in the message is not a preset value, obtaining the original timestamp carried in the message;
[0081] The original timestamp is the Origin Timestamp field, which is 10 bytes. Fig.10As shown in the figure, the original timestamp occupies 10 bytes, but 8 bytes are actually used. The remaining 2 bytes are usually used to represent the high-order second to expand the counting range of seconds (Seconds), and can also be used to represent the fraction of nanoseconds (Nanoseconds) to improve accuracy. Currently, these 8 bytes of data are actually used.
[0082] The current time of the slave clock is calculated based on the original timestamp and the preset time difference.
[0083] In some embodiments, current time=original timestamp+preset time difference.
[0084] If the current value of the clock count mark is not the preset value, the original timestamp carried in the message is obtained, and then the sum of the original timestamp and the preset time difference is used as the current time of the slave clock, thereby achieving accurate synchronization of the master and slave clocks.
[0085] In some embodiments, before determining whether the current value of the clock count flag bit in the message is a preset value, the method further includes:
[0086] Searching for a reserved field in the message;
[0087] The current value of the clock count flag bit is read from the reserved field.
[0088] Table 1 is an introduction to each byte in the FlagField field in the message header in the message, wherein Table 1 is as follows. As can be seen from Table 1, this embodiment modifies the original Reserved of the third bit of the 0th byte in the FlagField field to the clock count flag bit TickCountFlag.
[0089] Table 1
[0090]
[0091]
[0092] By finding the reserved field in the message sent by the master clock, the current value of the clock count marked as can be automatically read from the reserved field.
[0093] For example: replace the reserved field Reserved at the 3rd bit of the 0th byte in the FlagField field shown in Table 1 above with TickCountFlag (clock count flag) (ie, Reserved->TickCountFlag), and then read the current value of the clock count flag bit to be True or False.
[0094] In some embodiments, the obtaining the number of oscillations and the oscillation frequency of the master clock from the message includes:
[0095] Searching for a count field in the message; wherein the count field occupies N bytes;
[0096] The count field is the Tickstamp field, and its content is as follows Fig.11A As shown ( Fig.11A Each narrow line is 32 bits, and each wide line is 64 bits). Specifically, the length of the Tickstamp field is 12 bytes, consisting of a 64-bit TickCount and a 32-bit TickFrequency. The number of ticks / frequency can be used to get the time in seconds. On different hardware clocks, the frequency is different, and the time precision is also different. For example, for a CPU with a frequency of 100 MHz, one tick is 10 ns.
[0097] Reading the oscillation number from the first n bytes of the count field;
[0098] N can be 12 and n can be 8.
[0099] The oscillation frequency is read from the last (Nn) bytes of the count field, wherein n and N are both positive integers, N is greater than 10, and n is less than N.
[0100] like Fig.11A As shown, if N = 12, n = 8, then from Fig.11A Read the oscillation count TickCount from the first 8 bytes of Fig.11A The oscillation frequency can be read from the last 4 bytes of the oscillation frequency register.
[0101] In addition, since the length of the count field is greater than the length of the original timestamp, a longer count can be stored. Therefore, the present disclosure can delay time flipping compared to the prior art. And since the count field stores the oscillation frequency and the number of oscillations rather than seconds or nanoseconds based on the reference time, the reference time of the present disclosure can be any time point such as the start time of the main clock, rather than the reference time. Therefore, this further extends the time flipping and avoids the clock having to flip in 2043, resulting in unpredictable errors.
[0102] The number of oscillations occupies the first n consecutive bytes, and the oscillation frequency occupies the last (Nn) consecutive bytes of the count field, which ensures that the number of oscillations and the oscillation frequency each occupy multiple consecutive bytes, avoiding the bytes occupied by the number of oscillations and the oscillation frequency from crossing each other, which is inconvenient to read.
[0103] In some embodiments, the calculating the time expressed by the message based on the number of oscillations and the oscillation frequency includes:
[0104] Calculating a ratio of the number of oscillations to the oscillation frequency;
[0105] The ratio = oscillation number / oscillation frequency, expressed in seconds or nanoseconds, refers to the time elapsed by the master clock. The time may be a duration based on any time point as a reference time, such as a duration based on the start time of the master clock as a reference time.
[0106] If the message does not carry the reference time of the master clock (e.g., the MessageField field of the message only carries Fig.11A Tick Count and Frequency shown), then the ratio is used as the time expressed by the message.
[0107] If the message carries the reference time of the master clock (such as Fig. 11B As shown, through Fig. 11B The format shown can record the reference time in the form of year, month, day, hour, minute, second, and nanosecond. For example, the MessageField field of the message not only carries Fig.11A The Tick Count and Frequency shown in the figure also carry Fig. 11B If the year-month-day-hour-minute-second-nanosecond is shown in the figure, the ratio and the time sum of the reference time are used as the time expressed by the message.
[0108] By calculating the ratio of the number of oscillations to the oscillation frequency, the elapsed time of the master clock can be obtained. If the message does not carry the reference time, it means that neither the master nor the slave clock has a reference time. The ratio is directly used as the time expressed by the message. If the message carries the reference time, it means that both the master and the slave clocks have a reference time or at least the master clock has a reference time. The ratio and the reference time are used as the time expressed by the message. In this way, regardless of whether there is a reference time, the master and the slave clocks can achieve clock synchronization.
[0109] In some embodiments, the calculating the current time of the slave clock based on the time expressed by the message and the pre-calculated preset time difference includes:
[0110] If the master clock and the slave clock both have a reference time (such as Fig. 11B As shown), then obtain the pre-calculated time deviation of the slave clock relative to the master clock;
[0111] The time deviation of the slave clock relative to the master clock is offset, and the offset can be a positive value or a negative value.
[0112] Determining the time deviation as the preset time difference;
[0113] The sum of the time expressed in the message and the preset time difference is calculated and used as the current time of the slave clock.
[0114] If both the master clock and the slave clock have a reference time, it means that the master and slave clocks have the same reference time, such as 0:00 on January 1, 1970. Therefore, the time deviation of the slave clock relative to the master clock can be obtained, and then the time deviation can be used for clock synchronization. Specifically, the sum of the time expressed by the message and the time deviation can be calculated, and then the sum of the time can be used as the current time of the slave clock, thereby achieving clock synchronization between the master clock and the slave clock.
[0115] In some embodiments, the calculating the current time of the slave clock based on the time expressed by the message and the pre-calculated preset time difference includes:
[0116] If the slave clock has no reference time, obtaining a pre-calculated unidirectional link transmission time between the slave clock and the master clock;
[0117] The one-way link transmission time refers to the time required for a single message transmission between the master clock and the slave clock.
[0118] Determining the unidirectional link transmission time as the preset time difference;
[0119] The sum of the time expressed in the message and the preset time difference is calculated and used as the current time of the slave clock.
[0120] If neither the master clock nor the slave clock has a reference time, the unidirectional link transmission time Delay between the slave clock and the master clock can be obtained, and then the unidirectional link transmission time can be used for clock synchronization. Specifically, the sum of the time expressed by the message and the unidirectional link transmission time can be calculated, and then the sum of the time can be used as the current time of the slave clock, thereby achieving clock synchronization between the master clock and the slave clock.
[0121] The following will be combined Figure 2 Detailed description of the calculation method of time offset offset and one-way link transmission time Delay:
[0122] (1) Figure 2 As shown in FIG. 1 , the master clock sends a Sync message to the slave clock and records the sending time t1; after the slave clock receives the message, it records the receiving time t2.
[0123] (2) After the master clock sends the Sync message, it immediately sends a Follow_Up message carrying t1.
[0124] (3) The slave clock sends a Pdelay_Req message to the master clock to initiate the calculation of the reverse transmission delay and records the sending time t3. After the master clock receives the message, it records the receiving time t4.
[0125] (4) After receiving the Pdelay_Req message, the master clock replies with a Pdelay_Resp message carrying t4 and records the sending time t5. After receiving the message, the slave clock records the receiving time t6.
[0126] (5) After the master clock replies with the Pdelay_Resp message, it immediately sends a Pdelay_Resp_Follow_Up message carrying t5.
[0127] At this point, the slave clock has six timestamps from t1 to t6, from which the total round-trip delay between the master and slave clocks can be calculated as [(t4–t3)+(t6–t5)]. Since the network is symmetrical, the one-way delay between the master and slave clocks is: Delay = [(t4–t3)+(t6–t5)] / 2. Therefore, the clock deviation of the slave clock relative to the master clock is: Offset = (t2–t1)-[(t4–t3)+(t6–t5)] / 2.
[0128] In addition, it should be noted that: Figure 3 It is the general format of PTP message. Figure 3 The first four boxes are the Ethernet headers of the PTP message. Figure 3 The fifth box 1588PAHLOD is the message body of the PTP message. Figure 4 for Figure 3 The message header of the message body, Figures 5 to 9 The originTimestamp is Figure 4 The content of the Message Field in Figures 5 to 9 They are the formats of the Message Field in the Sync message, Follow Up message, PDelay_Req message, PDelay_Resp message, and PDelay_Resp_Follow_Up message.
[0129] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present disclosure is not limited by the order of the actions described, because according to the present disclosure, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present disclosure.
[0130] The above is an introduction to the method embodiment. The following is a further explanation of the scheme disclosed in the present invention through an apparatus embodiment.
[0131] Fig.12 FIG. 1 is a block diagram of a clock synchronization device 1200 according to an embodiment of the present disclosure. The device 1200 includes:
[0132] The receiving module 1201 is used to receive the message sent by the master clock;
[0133] A judgment module 1202 is used to judge whether the current value of the clock count flag bit in the message is a preset value; wherein the clock count flag bit occupies a reserved field of the message, and the preset value is used to indicate that the message carries the number of oscillations and the oscillation frequency of the master clock;
[0134] The acquisition module 1203 is used to acquire the oscillation number and oscillation frequency of the master clock from the message if yes;
[0135] A first calculation module 1204, configured to calculate the time expressed by the message based on the number of oscillations and the oscillation frequency;
[0136] The second calculation module 1205 is used to calculate the current time of the slave clock based on the time expressed in the message and a pre-calculated preset time difference, wherein the preset time difference is the time deviation of the slave clock relative to the master clock.
[0137] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the described module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0138] According to an embodiment of the present disclosure, the present disclosure further provides an electronic device, including:
[0139] at least one processor; and
[0140] a memory communicatively connected to the at least one processor; wherein,
[0141] The memory stores instructions that can be executed 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 perform any of the above method embodiments.
[0142] According to an embodiment of the present disclosure, the present disclosure further provides a vehicle, comprising: the clock synchronization device as described in the above embodiment or the electronic device as described in the above embodiment.
[0143] According to an embodiment of the present disclosure, the present disclosure further provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute any one of the above method embodiments.
[0144] Fig.13 A schematic block diagram of an electronic device 1300 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0145] The device 1300 includes a computing unit 1301, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1302 or a computer program loaded from a storage unit 1308 into a random access memory (RAM) 1303. In the RAM 1303, various programs and data required for the operation of the device 1300 can also be stored. The computing unit 1301, the ROM 1302, and the RAM 1303 are connected to each other via a bus 1304. An input / output (I / O) interface 1305 is also connected to the bus 1304.
[0146] A number of components in the device 1300 are connected to the I / O interface 1305, including: an input unit 1306, such as a keyboard, a mouse, etc.; an output unit 1307, such as various types of displays, speakers, etc.; a storage unit 1308, such as a disk, an optical disk, etc.; and a communication unit 1309, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1309 allows the device 1300 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0147] The computing unit 1301 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1301 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1301 performs the various methods and processes described above, such as method 100. For example, in some embodiments, the method 100 may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 1308. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1300 via the ROM 1302 and / or the communication unit 1309. When the computer program is loaded into the RAM 1303 and executed by the computing unit 1301, one or more steps of the method 100 described above may be performed. Alternatively, in other embodiments, the computing unit 1301 may be configured to execute the method 100 in any other appropriate manner (eg, by means of firmware).
[0148] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0149] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0150] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0151] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0152] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0153] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0154] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0155] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A clock synchronization method, It is characterized in that include: Receive messages sent by the master clock; Determine whether the current value of the clock count flag bit in the message is a preset value; wherein the clock count flag bit occupies a reserved field of the message, and the preset value is used to indicate that the message carries the number of oscillations and the oscillation frequency of the master clock; If yes, obtaining the number of oscillations and the oscillation frequency of the master clock from the message; Calculating the time expressed by the message based on the number of oscillations and the oscillation frequency; The current time of the slave clock is calculated based on the time expressed in the message and a pre-calculated preset time difference, wherein the preset time difference is a time deviation of the slave clock relative to the master clock.
2. The method according to claim 1, It is characterized in that The method further comprises: If the current value of the clock count flag bit in the message is not a preset value, obtaining the original timestamp carried in the message; The current time of the slave clock is calculated based on the original timestamp and the preset time difference.
3. The method according to claim 1, It is characterized in that Before determining whether the current value of the clock count flag bit in the message is a preset value, the method further includes: Searching for the reserved field in the message; The current value of the clock count flag bit is read from the reserved field.
4. The method according to claim 1, It is characterized in that The obtaining the number of oscillations and the oscillation frequency of the master clock from the message includes: Searching for a count field in the message; wherein the count field occupies N bytes; Reading the oscillation number from the first n bytes of the count field; The oscillation frequency is read from the last (Nn) bytes of the count field, wherein n and N are both positive integers, N is greater than 10, and n is less than N.
5. The method according to claim 1, It is characterized in that The calculating the time expressed by the message based on the number of oscillations and the oscillation frequency includes: Calculating a ratio of the number of oscillations to the oscillation frequency; If the message does not carry the reference time of the master clock, the ratio is used as the time expressed by the message. If the message carries the reference time of the master clock, the sum of the ratio and the reference time is used as the time expressed by the message.
6. The method according to claim 1, It is characterized in that The calculating the current time of the slave clock based on the time expressed by the message and the pre-calculated preset time difference includes: If both the master clock and the slave clock have a reference time, obtaining a pre-calculated time deviation of the slave clock relative to the master clock; Determining the time deviation as the preset time difference; The sum of the time expressed in the message and the preset time difference is calculated and used as the current time of the slave clock.
7. The method according to any one of claims 1 to 6, It is characterized in that The calculating the current time of the slave clock based on the time expressed by the message and the pre-calculated preset time difference includes: If the slave clock has no reference time, obtaining a pre-calculated unidirectional link transmission time between the slave clock and the master clock; Determining the unidirectional link transmission time as the preset time difference; The sum of the time expressed in the message and the preset time difference is calculated and used as the current time of the slave clock.
8. A clock synchronization device, It is characterized in that include: A receiving module, used for receiving messages sent by the master clock; A judgment module, used to judge whether the current value of the clock count flag bit in the message is a preset value; wherein the clock count flag bit occupies a reserved field of the message, and the preset value is used to indicate that the message carries the number of oscillations and the oscillation frequency of the master clock; An acquisition module, configured to acquire the number of oscillations and the oscillation frequency of the master clock from the message if yes; A first calculation module, used for calculating the time expressed by the message based on the number of oscillations and the oscillation frequency; The second calculation module is used to calculate the current time of the slave clock based on the time expressed in the message and a pre-calculated preset time difference, wherein the preset time difference is the time deviation of the slave clock relative to the master clock.
9. An electronic device, It is characterized in that include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, It is characterized in that The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.
11. A vehicle, It is characterized in that include: The clock synchronization device as claimed in claim 8, and / or the electronic device as claimed in claim 9, and / or the readable storage medium as claimed in claim 10.
