Time synchronization method and electronic device

By using the timestamp information of request-response commands in the terminal to determine the correction compensation value, the problem of timestamp synchronization error between the main application processor and the microcontroller unit is solved, improving time synchronization accuracy and system stability, and optimizing user experience.

CN119254365BActive Publication Date: 2025-11-28HONOR DEVICE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410182507.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-02-18
Publication Date
2025-11-28
Estimated Expiration
2044-02-18

AI Technical Summary

Technical Problem

There is an error in the timestamp synchronization between the main application processor and the microcontroller unit in the terminal, and the error will increase over a long period of time, affecting system stability and communication consistency.

Method used

By carrying timestamp information in the request-response type instruction, a correction compensation value is determined, and the current timestamp of the processing unit to be synchronized is corrected using the correction compensation value, so as to achieve time synchronization between different processing units.

Benefits of technology

It improves the time synchronization accuracy between processing units, enhances the overall performance and operational stability of the system, and optimizes the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119254365B_ABST
    Figure CN119254365B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a time synchronization method and an electronic device. When sending a request-response type instruction between different processing units of the electronic device, a correction compensation value about a timestamp between the different processing units is determined according to timestamp information carried in the instruction. Furthermore, the current timestamp of a processing unit to be synchronized is corrected by using the correction compensation value, so as to realize time synchronization between the different processing units. The time synchronization precision between the different processing units can be effectively improved, and the overall performance and operation stability of the electronic device can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of terminal, and in particular, to a time synchronization method and electronic device. BACKGROUND

[0002] Taking a mobile phone terminal as an example, a main application processor (AP) and one or more microcontroller units (MCUs) are usually arranged in the terminal, and the AP and the MCU need to keep the timestamp synchronized to ensure the normal operation of terminal services and system functions.

[0003] However, the timestamp synchronization itself has errors, and with the long-time operation of the MCUs, the timestamp synchronization error is further expanded. SUMMARY

[0004] To solve the above technical problems, the present application provides a time synchronization method and electronic device. In the method, when sending a request-response type instruction between different processing units of an electronic device, according to the timestamp information carried in the instruction, a correction compensation value about the timestamp between different processing units is determined. And, the current timestamp of the processing unit to be synchronized is corrected by using the correction compensation value, so as to realize the time synchronization between different processing units.

[0005] In a first aspect, embodiments of the present application provide a time synchronization method applied to an electronic device, the electronic device comprising a first processing unit and a second processing unit, the first processing unit and the second processing unit transmitting data through a physical communication link, the method being executed by the first processing unit and comprising: sending a first service request to the second processing unit and recording a first sending timestamp when the first service request is sent; receiving first response data returned by the second processing unit in response to the first service request and recording a first receiving timestamp when the first response data is received; determining a correction compensation value according to the first sending timestamp, the first receiving timestamp and the first response data; and sending the correction compensation value to the second processing unit, so that the second processing unit updates the current timestamp by using the correction compensation value.

[0006] By using the timestamp information carried in the request-response type instruction, the correction compensation value about the timestamp between different processing units is determined, and the current timestamp of the processing unit to be synchronized is corrected by using the correction compensation value, which can effectively improve the time synchronization precision between different processing units, is conducive to improving the overall performance and operation stability of the electronic device, and is conducive to improving the user experience.

[0007] According to the first aspect, the determining the correction compensation value according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, the second receiving timestamp and the reference timestamp deviation comprises: parsing the first response data to obtain a second sending timestamp and a second receiving timestamp indicated by the first response data, the second sending timestamp being a time when the second processing unit sends the first response data, and the second receiving timestamp being a time when the second processing unit receives the first service request; and determining the correction compensation value according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, the second receiving timestamp and the reference timestamp deviation.

[0008] The historical timestamp deviation between the first processing unit and the second processing unit calculated when the timestamp correction is performed on the second processing unit last time constitutes the reference timestamp deviation when the timestamp correction is performed on the second processing unit this time.

[0009] By improving the timestamp alignment accuracy, the work of different processors can be better coordinated, the stability of system operation can be improved, and the overall performance of the electronic device can be optimized.

[0010] According to the first aspect, or any one of the implementation manners of the first aspect, the determining the correction compensation value according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, the second receiving timestamp and the reference timestamp deviation comprises: determining a link transmission delay between the first processing unit and the second processing unit according to the first sending timestamp, the first receiving timestamp, the second sending timestamp and the second receiving timestamp; in a case where the link transmission delay is within a preset time range, determining a current timestamp deviation between the first processing unit and the second processing unit according to the first sending timestamp, the first receiving timestamp, the second sending timestamp and the second receiving timestamp; and determining the correction compensation value according to the current timestamp deviation and the reference timestamp deviation.

[0011] If the link transmission delay is too large or too small (i.e., not within a reasonable range), it indicates that there may be an abnormal situation of the communication link, and other data has a high risk of error, so the other data is not adopted and is cleaned up. In a case where the link transmission delay is not within the preset time range, it is determined that the current link transmission delay is invalid, and the corresponding data record is cleared.

[0012] According to the first aspect, or any one of the implementation manners of the first aspect, the historical timestamp deviation between the first processing unit and the second processing unit calculated when the timestamp correction is performed on the second processing unit last time constitutes the reference timestamp deviation when the timestamp correction is performed on the second processing unit this time.

[0013] According to the first aspect, or any one of the implementations of the first aspect, the determining the correction compensation value according to the current timestamp deviation and the reference timestamp deviation comprises: determining whether a first difference between the current timestamp deviation and the reference timestamp deviation is greater than a preset precision threshold; in a case where the first difference is greater than the preset precision threshold, determining whether a second difference between a historical timestamp deviation between the first processing unit and the second processing unit calculated by any one of the adjacent previous M times and a corresponding historical reference deviation is greater than the preset precision threshold when the first processing unit sends the first service request to the second processing unit based on the current time, M being an integer greater than 1; and in a case where the M second differences are all greater than the preset precision threshold, taking the first difference as the correction compensation value.

[0014] If the difference between the current timestamp deviation and the reference timestamp deviation is not greater than the preset precision threshold, it indicates that the reference timestamp deviation generated when the timestamp correction is performed on the second processing unit last time is available, and does not need to be updated. The current timestamp deviation calculated this time is invalid, and the corresponding data record is cleared. In a case where the difference between the current timestamp deviation and the reference timestamp deviation is greater than the preset precision threshold, the number of times that the difference is greater than the preset precision threshold consecutively in the previous M service request-response processes based on the current time is counted.

[0015] According to the first aspect, or any one of the implementations of the first aspect, the method further comprises: in a case where the M second differences are all greater than the preset precision threshold, determining whether a first stability condition is met by the link transmission delay and a historical transmission delay between the first processing unit and the second processing unit calculated by any one of the adjacent previous M times, and determining whether a second stability condition is met by the current timestamp deviation and the M historical timestamp deviations; and in a case where the first stability condition and the second stability condition are both met, taking the first difference as the correction compensation value.

[0016] The unstable link transmission delay or the current timestamp deviation can be effectively avoided, so that the timestamp alignment precision is not affected, and the accuracy of clock synchronization between different processing units is facilitated.

[0017] According to the first aspect, or any one of the implementations of the first aspect, the method further comprises: in a case where the first stability condition and the second stability condition are both met, taking the current timestamp deviation as a reference timestamp deviation when the timestamp correction is performed on the second processing unit next time.

[0018] According to the first aspect, or any one of the implementations of the first aspect, the determining the link transmission delay between the first processing unit and the second processing unit according to the first sending timestamp, the first receiving timestamp, the second sending timestamp and the second receiving timestamp comprises: calculating a third difference between the first receiving timestamp and the first sending timestamp, and a fourth difference between the second receiving timestamp and the second sending timestamp; and taking an average of the third difference and the fourth difference as the link transmission delay.

[0019] According to the first aspect, or any one of the implementations of the first aspect, the determining the current timestamp deviation between the first processing unit and the second processing unit according to the first sending timestamp, the first receiving timestamp, the second sending timestamp and the second receiving timestamp comprises: calculating a fifth difference between the first sending timestamp and the second receiving timestamp, and a sixth difference between the first receiving timestamp and the second sending timestamp; and taking an average of the fifth difference and the sixth difference as the current timestamp deviation.

[0020] According to the first aspect, or any one of the implementations of the first aspect, the method further comprises: when performing timestamp correction on the second processing unit for the first time, sending a plurality of synchronization instructions to the second processing unit, and recording a third sending timestamp for each time of sending the synchronization instruction; receiving a response message returned by the second processing unit and matched with each of the synchronization instructions, and recording a third receiving timestamp for each time of receiving the response message; parsing each of the response messages to obtain a fourth receiving timestamp indicated by each of the response messages and a fourth sending timestamp of the second processing unit, the fourth receiving timestamp being a time when the second processing unit receives the corresponding synchronization instruction, and the fourth sending timestamp being a time when the second processing unit sends each of the response messages; determining a plurality of initial timestamp deviations between the first processing unit and the second processing unit according to the third sending timestamp, the third receiving timestamp, the fourth sending timestamp and the fourth receiving timestamp matched with each of the synchronization instructions; and taking an average of the plurality of initial timestamp deviations as a reference timestamp deviation when performing timestamp correction on the second processing unit next time.

[0021] According to the first aspect, or any one of the implementations of the first aspect, the method further comprises: sending the correction compensation value to a target client having a time synchronization requirement, so that the target client updates a current timestamp by using the correction compensation value.

[0022] The target client having a time synchronization requirement includes, for example, a real-time clock (RTC) application, a hardware control application, a sensor data processing application, and the like.

[0023] According to a first aspect, or any possible implementation mode of the above first aspect, the method further comprises: outputting, by the first processing unit, an electrical signal through a general input / output (GPIO) pin of the first processing unit before the first processing unit initiates a new inter-core communication facing the second processing unit, so as to make the second processing unit trigger an interrupt service based on the electrical signal; and recording a first output timestamp of the GPIO pin outputting the electrical signal, and sending the first output timestamp to the second processing unit, so as to make the second processing unit determine a current timestamp deviation between the first processing unit and the second processing unit according to the first output timestamp and a first trigger timestamp of triggering the interrupt service.

[0024] The electrical signal output by the GPIO pin includes, for example, a high level, a low level, a rising edge or a falling edge, etc.

[0025] In a second aspect, the embodiments of the present application provide a time synchronization method, applied to an electronic device, the electronic device comprising a first processing unit, a second processing unit and a third processing unit, the first processing unit and the second processing unit, and the second processing unit and the third processing unit respectively transmitting data through a physical communication chain, the method being executed by the first processing unit, comprising: sending a second service request to the second processing unit, and recording a fifth sending timestamp when the second service request is sent; receiving second response data returned by the second processing unit, and recording a fifth receiving timestamp when the second response data is received, wherein the second response data is response data generated by the third processing unit based on the second service request after the second processing unit forwards the second service request to the third processing unit; determining a correction compensation value according to the fifth sending timestamp, the fifth receiving timestamp and the second response data; and sending the correction compensation value to the second processing unit, so that the second processing unit forwards the correction compensation value to the third processing unit, so as to make the third processing unit update a current timestamp by using the correction compensation value.

[0026] According to a second aspect, the determining the correction compensation value according to the fifth sending timestamp, the fifth receiving timestamp and the second response data comprises: parsing the second response data to obtain a sixth receiving timestamp indicating a time when the second processing unit receives the second service request, a sixth sending timestamp indicating a time when the second processing unit forwards the second service request, a seventh receiving timestamp indicating a time when the third processing unit receives the second service request, a seventh sending timestamp indicating a time when the third processing unit sends the second response data, an eighth receiving timestamp indicating a time when the second processing unit receives the second response data, and an eighth sending timestamp indicating a time when the second processing unit forwards the second response data; and determining the correction compensation value according to the fifth sending timestamp, the fifth receiving timestamp, the sixth sending timestamp, the sixth receiving timestamp, the seventh sending timestamp, the seventh receiving timestamp, the eighth sending timestamp, the eighth receiving timestamp and a reference timestamp deviation.

[0027] According to the second aspect, or any possible implementation mode of the second aspect, the determining the correction compensation value according to the fifth sending timestamp, the fifth receiving timestamp, the sixth sending timestamp, the sixth receiving timestamp, the seventh sending timestamp, the seventh receiving timestamp, the eighth sending timestamp, the eighth receiving timestamp and the reference timestamp deviation comprises: determining a link transmission delay between the first processing unit and the third processing unit according to the fifth sending timestamp, the fifth receiving timestamp, the sixth sending timestamp, the sixth receiving timestamp, the seventh sending timestamp, the seventh receiving timestamp, the eighth sending timestamp and the eighth receiving timestamp; in a case where the link transmission delay is within a preset time range, determining a current timestamp deviation between the first processing unit and the third processing unit according to the fifth sending timestamp, the fifth receiving timestamp, the sixth sending timestamp, the sixth receiving timestamp, the seventh sending timestamp, the seventh receiving timestamp, the eighth sending timestamp and the eighth receiving timestamp; and determining the correction compensation value according to the current timestamp deviation and the reference timestamp deviation.

[0028] In a third aspect, the embodiments of the present application provide a time synchronization method applied to an electronic device, characterized in that the electronic device comprises a first processing unit and a second processing unit, the first processing unit and the second processing unit transmit data through a physical communication link, the method is executed by the second processing unit, and comprises the following steps: receiving a first service request sent by the first processing unit and recording a second receiving timestamp when the first service request is received; filling response content based on the first service request and timestamp information into a return packet to form first response data, wherein the timestamp information comprises the second receiving timestamp and a second sending timestamp when the second processing unit returns the first response data; returning the first response data to the first processing unit, so that the first processing unit determines a correction compensation value according to the first response data; and receiving a correction compensation value sent by the first processing unit and updating a current timestamp by using the correction compensation value.

[0029] According to the third aspect, the method further comprises: correcting a timestamp of a to-be-processed event in a cache queue by using the correction compensation value.

[0030] When the cache queue is not empty, the timestamp of the to-be-processed event in the cache queue needs to be updated by using a new correction compensation value, so as to ensure correct timing relationship and relative precision.

[0031] According to the third aspect or any one of the third aspect and the third aspect, the method further comprises: filling the response content based on the first service request, the second sending timestamp, and a differential timestamp between the second sending timestamp and the second receiving timestamp into the return packet to form the first response data.

[0032] According to the third aspect or any one of the third aspect and the third aspect, the method further comprises: in a case where the second processing unit comprises other timestamps in addition to the second receiving timestamp and the second sending timestamp, filling the response content based on the first service request, the second sending timestamp, a differential timestamp between the second sending timestamp and the second receiving timestamp, and a differential timestamp between the second sending timestamp and each of the other timestamps into the return packet to form the first response data.

[0033] According to a third aspect, or any possible implementation mode of the third aspect, the filling the response content based on the first service request and the timestamp information into the return packet to form the first response data comprises: in the case that the second processing unit comprises other timestamps in addition to the second receiving timestamp and the second sending timestamp, filling the response content based on the first service request, the second sending timestamp, a differential timestamp between the second sending timestamp and the second receiving timestamp, and a to-be-transmitted timestamp corresponding to each of the other timestamps into the return packet to form the first response data, wherein a highest mark bit of the differential timestamp indicates that the to-be-transmitted timestamp is original timestamp content of the corresponding other timestamp or a differential value between the second sending timestamp and the corresponding other timestamp.

[0034] According to a third aspect, or any possible implementation mode of the third aspect, the updating the current timestamp by using the correction compensation value comprises: summing the current timestamp and the correction compensation value to obtain a compensated current timestamp.

[0035] According to a third aspect, or any possible implementation mode of the third aspect, the method further comprises: performing timestamp correction on other nodes connected to the second processing unit by using the compensated current timestamp, wherein the other nodes and the second processing unit transmit data through a physical communication link.

[0036] According to a fourth aspect, an electronic device is provided, comprising a first processing unit and a second processing unit, wherein the first processing unit and the second processing unit transmit data through a physical communication link, and the electronic device further comprises one or more processors, a memory, and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device performs the following steps: the first processing unit sends a first service request to the second processing unit and records a first sending timestamp when the first service request is sent; the first processing unit receives first response data returned by the second processing unit in response to the first service request and records a first receiving timestamp when the first response data is received; the first processing unit determines a correction compensation value according to the first sending timestamp, the first receiving timestamp, and the first response data; and the first processing unit sends the correction compensation value to the second processing unit, so that the second processing unit updates a current timestamp by using the correction compensation value.

[0037] The fourth aspect and any possible implementation manner of the fourth aspect correspond to the first aspect and any possible implementation manner of the first aspect respectively. The technical effects of the fourth aspect and any possible implementation manner of the fourth aspect correspond to the technical effects of the first aspect and any possible implementation manner of the first aspect, which are not described herein again.

[0038] In a fifth aspect, an embodiment of the present application provides a computer readable medium for storing a computer program, the computer program comprising instructions for executing the method in the first aspect or any possible implementation manner of the first aspect.

[0039] In a sixth aspect, an embodiment of the present application provides a computer program comprising instructions for executing the method in the first aspect or any possible implementation manner of the first aspect.

[0040] In a seventh aspect, an embodiment of the present application provides a chip, comprising a processing circuit, a transceiving pin. The transceiving pin and the processing circuit communicate with each other through an internal connection path. The processing circuit executes the method in the first aspect or any possible implementation manner of the first aspect to control the receiving pin to receive a signal and control the sending pin to send a signal. BRIEF DESCRIPTION OF DRAWINGS

[0041] Figure 1 A structural schematic diagram of an electronic device provided by an embodiment of the present application is provided.

[0042] Figure 2 A software structural block diagram of an electronic device provided by an embodiment of the present application is provided.

[0043] Figure 3 A connection schematic diagram between an AP and an MCU provided by an embodiment of the present application is provided.

[0044] Figure 4 An interaction schematic diagram between a first processing unit and a second processing unit provided by an embodiment of the present application is provided.

[0045] Figure 5 A flowchart of timestamp synchronization between an AP and an MCU provided by an embodiment of the present application is provided.

[0046] Figure 6 A flowchart of determining a correction compensation value provided by an embodiment of the present application is provided.

[0047] Figure 7 A flowchart of first timestamp synchronization provided by an embodiment of the present application is provided.

[0048] Figure 8 An interaction schematic diagram of modules in a first processing unit and a second processing unit provided by an embodiment of the present application is provided.

[0049] Figure 9 Another interaction schematic diagram between the first processing unit and the second processing unit provided by the embodiment of the present application is shown;

[0050] Figure 10 Another connection schematic diagram between the AP and the MCU provided by the embodiment of the present application is shown;

[0051] Figure 11 An interaction schematic diagram between the AP and the MCU is shown;

[0052] Figure 12 Another interaction schematic diagram between the AP and the MCU is shown. DETAILED DESCRIPTION

[0053] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of the present application.

[0054] The term “and / or” in the present application is only used to describe the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B can mean that there are three cases of A alone, A and B together, and B alone.

[0055] The terms “first” and “second” and the like in the description and claims of the embodiments of the present application are used to distinguish different objects, and are not used to describe the specific order of the objects. For example, the first target object and the second target object are used to distinguish different target objects, and are not used to describe the specific order of the target objects.

[0056] In the embodiments of the present application, the words “exemplarily” or “for example” are used to mean as an example, illustration or description. Any embodiment or design scheme described as “exemplarily” or “for example” in the embodiments of the present application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. Rather, the words “exemplarily” or “for example” are intended to present the relevant concept in a specific manner.

[0057] In the description of the embodiments of the present application, unless otherwise specified, the meaning of “a plurality of” is two or more. For example, a plurality of processing units means two or more processing units; a plurality of systems means two or more systems.

[0058] Taking a mobile phone terminal as an example, a terminal usually has a main application processor (AP) and one or more microcontroller units (MCU). The AP is mainly responsible for running the operating system, executing application programs, processing graphics, connecting to the network, and other complex computing and communication tasks. The MCU can be designed to handle specific hardware control tasks, such as power management, hardware control, sensor data processing, etc.

[0059] Timestamps are widely used in computer systems and applications to record the time of event occurrence. If the timestamps of the AP and the MCU in the terminal are not synchronized, it may affect communication, data consistency, log recording, system security, and the normal operation of applications, etc.

[0060] For example, timestamps are often used in communication protocols to determine the sending and receiving time of messages. If the timestamps in the terminal are not synchronized, it may cause the order of messages to be chaotic or other communication problems. For another example, in a distributed system, timestamps are used to ensure data consistency. If the timestamps of different processing units are not synchronized, it may cause data synchronization errors or consistency problems. In addition, software systems and applications may use timestamps to record events, and timestamp synchronization may cause the time order of logs to be chaotic, increasing the difficulty of troubleshooting and auditing. Therefore, ensuring the synchronization of the timestamps of the AP and the MCU in the terminal is a key factor in maintaining the stability of the system and the application.

[0061] However, the timestamp synchronization itself has errors, and as the MCUs run for a long time, there is a problem of further expanding the timestamp synchronization error.

[0062] Embodiments of the present application provide a time synchronization method, which can be applied to an electronic device. The electronic device includes a first processing unit and a second processing unit, and the first processing unit and the second processing unit transmit data through a physical communication link. The first processing unit may, for example, be a main processor AP in the electronic device, and the timestamp of the main processor is usually accurate enough to be used as a reference timestamp for timestamp synchronization between the AP and the MCU. The second processing unit may, for example, be an MCU in the electronic device, which can be a processor extended by the chip manufacturer or a coprocessor integrated by the chip manufacturer.

[0063] When sending a request-response type of instruction between the AP and the MCU, according to the timestamp information carried in the instruction, a correction compensation value between the AP and the MCU about the timestamp is determined. The current timestamp of the MCU is corrected using the correction compensation value to achieve time synchronization between the AP and the MCU.

[0064] Exemplarily, the first processing unit sends a first service request to the second processing unit, and records a first sending timestamp when the first service request is sent. The first processing unit receives first response data returned by the second processing unit in response to the first service request, and records a first receiving timestamp when the first response data is received. The first processing unit determines a correction compensation value according to the first sending timestamp, the first receiving timestamp, and the first response data. The first processing unit sends the correction compensation value to the second processing unit, so that the second processing unit updates the current timestamp by using the correction compensation value. The timestamp alignment accuracy in the terminal can be effectively improved, and the stability of the system and the application program can be effectively maintained.

[0065] The electronic device can include a mobile phone, a tablet computer, a smart watch, a notebook computer, an autonomous driving vehicle, a smart home, a machine navigation device, a virtual-real fusion device, etc. The embodiments of the present application can be applied to various scenes requiring time synchronization.

[0066] As Figure 1 Fig. 1 shows a structural schematic diagram of an electronic device 100. Optionally, the electronic device 100 can be referred to as a terminal, and can also be referred to as a terminal device. The specific product form of the electronic device 100 can be a smart terminal, such as a mobile phone, a tablet computer, a wearable device, an augmented reality / virtual reality device, a notebook computer, a vehicle-mounted device, a personal digital assistant (PDA), etc. having a time synchronization function. Specifically, the functional modules involved in the present application can be deployed on the DSP chip of the related device, and specifically can be an application program or software therein. The time synchronization function can be realized through software installation or upgrading, and through the calling and cooperation of hardware.

[0067] It should be understood that Figure 1 Fig. 1 shows an electronic device 100, which is only an example of an electronic device, and the electronic device 100 can have more or fewer components than those shown in the figure, can combine two or more components, or can have a different component configuration. Figure 1 The various components shown in Fig. 1 can be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0068] The electronic device 100 can include a processor 110, a memory 200, a mobile communication module 130, a wireless communication module 140, a sensor module 150, a button 160, a motor 161, an indicator 162, a camera 163, and a display screen 164. The sensor module 150 can include a pressure sensor, a gyro sensor, an acceleration sensor, a temperature sensor, a motion sensor, an air pressure sensor, a magnetic sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.

[0069] The processor 110 can include one or more processing units, for example: the processor 110 can include an application processor, a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices, or can be integrated in one or more processors.

[0070] The processor 110 can include a main application processor AP 111 and a microcontroller unit MCU 112. There can be one or more MCUs 112 in the electronic device 100, and the MCU 112 and the AP 111 can be integrated in the same chip or can be independently arranged in different chips. The MCU 112 can be used to perform specific tasks, such as power management, hardware control, sensor data processing, etc.

[0071] The processor 110 can also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory.

[0072] The wireless communication function of the electronic device 100 can be realized through the antenna 1, the antenna 2, the mobile communication module 130, the wireless communication module 140, the modem processor, and the baseband processor, etc.

[0073] The antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization rate of the antennas.

[0074] The mobile communication module 130 can provide a solution for wireless communication including 2G / 3G / 4G / 5G, etc. applied to the electronic device 100. The mobile communication module 130 can include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc.

[0075] The wireless communication module 140 can provide a solution for wireless communication including wireless local area networks (WLAN) (e.g., wireless fidelity (Wi-Fi) network), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) technology, etc. applied to the electronic device 100.

[0076] In some embodiments, the antenna 1 and the mobile communication module 130 of the electronic device 100 are coupled, and the antenna 2 and the wireless communication module 140 are coupled, so that the electronic device 100 can communicate with a network and other devices through wireless communication technology.

[0077] The electronic device 100 implements a display function through a GPU, a display screen 164, and an application processor, etc. The processor 110 can include one or more GPUs that execute program instructions to generate or change display information.

[0078] The display screen 164 is used to display images, videos, etc. The display screen 164 includes a display panel. In some embodiments, the electronic device 100 can include 1 or N display screens 164, N being a positive integer greater than 1.

[0079] The electronic device 100 can implement a shooting function through an ISP, a camera 163, a video codec, a GPU, a display screen 164, and an application processor, etc.

[0080] The ISP is used to process data fed back by the camera 163. For example, when taking a photo, the shutter is opened, the light is transmitted to the camera photosensitive element through the lens, the light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing to convert it into an image visible to the naked eye. The ISP can also optimize the algorithm of the noise, brightness, and skin color of the image. The ISP can also optimize the exposure, color temperature, etc. of the shooting scene. In some embodiments, the ISP can be disposed in the camera 163.

[0081] The camera 163 is configured to capture still images or videos. An object projects an optical image through a lens to a photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, which is then transmitted to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into an image signal in a standard format, such as RGB, YUV, or the like. In some embodiments, the electronic device 100 can include one or N cameras 163, where N is a positive integer greater than 1.

[0082] The camera 163 can be located at an edge region of the electronic device, and can be an under-screen camera or a liftable camera. The camera 163 can include a front-facing camera and can also include a rear-facing camera. The specific position and form of the camera 163 are not limited in the embodiments of the present application. The electronic device 100 can include one or more focal length cameras, such as a long-focus camera, a wide-angle camera, an ultra-wide-angle camera, or a panoramic camera.

[0083] The memory 120 can be configured to store computer-executable program code including instructions. The processor 110 executes various function applications and data processing of the electronic device 100 by running the instructions stored in the memory 120, such as enabling the electronic device 100 to implement the time synchronization method in the embodiments of the present application. The memory 120 can include a program storage area and a data storage area. The program storage area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, etc.), and the like. The data storage area can store data created during use of the electronic device 100, and the like. In addition, the memory 120 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, a universal flash storage (UFS), and the like.

[0084] The time synchronization module 121 can be stored in the memory 120, and the time synchronization module 121 is a program code module storing the time synchronization method provided in the embodiments of the present application. The time synchronization module 121 can be configured to perform pose estimation on an input image, and perform confidence evaluation on the pose estimation result to determine the reliability of the pose estimation result. The SLAM module 112 can perform real-time tracking of the pose of the electronic device based on the pose estimation result and the confidence evaluation result of the time synchronization module 121, thereby realizing autonomous positioning and navigation of the electronic device.

[0085] The touch sensor, also referred to as a "touch panel". The touch sensor can be disposed on the display screen 164, and the touch sensor and the display screen 164 form a touch screen, also referred to as a "touch screen". The touch sensor is configured to detect a touch operation applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operation to the application processor to determine a touch event type. Visual output related to the touch operation can be provided through the display screen 164.

[0086] The pressure sensor is configured to sense a pressure signal and convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor can be disposed on the display screen 164. The electronic device 100 can also calculate the position of the touch based on the detection signal of the pressure sensor.

[0087] The gyroscope sensor can be configured to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyroscope sensor.

[0088] The acceleration sensor can detect the magnitude of acceleration of the electronic device 100 in each direction (typically three axes). When the electronic device 100 is stationary, the acceleration sensor can detect the magnitude and direction of gravity. The acceleration sensor can also be used to identify the posture of the electronic device, and can be applied to applications such as screen rotation and pedometer.

[0089] The keys 160 include a power key (or power button), a volume key, and the like. The keys 160 can be mechanical keys or touch keys. The electronic device 100 can receive key inputs and generate key signal inputs related to user settings and function control of the electronic device 100.

[0090] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservices architecture, or a cloud architecture. Embodiments of the present application take the Android system with a layered architecture as an example to illustrate the software structure of the electronic device 100.

[0091] As Figure 2 The software structure block diagram of the electronic device 100 is shown as an example. The layered architecture of the electronic device 100 divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, the application layer, the application framework layer, the Android runtime, the system layer, and the kernel layer.

[0092] The application layer can include a series of application packages, such as Figure 2As shown, the application package can include a power management application, a hardware control application, a communication control application, etc. The power management application communicates with the MCU to manage the power supply, such as controlling battery charging, power switch, standby mode, etc. The hardware control application can be used to control various hardware components of the electronic device, such as screen brightness, volume control, vibrator, LED indicator, etc. The communication control application communicates with the MCU to control the communication module in the electronic device, such as Bluetooth, Wi-Fi, NFC, etc.

[0093] The application framework layer provides application programming interfaces (APIs) and programming frameworks for the applications of the application layer, including various components and services to support Android development for developers. The application framework layer includes some pre-defined functions. For example, Figure 2 As shown, the application framework layer can include a window manager, a content provider, a notification manager, and a resource manager, etc.

[0094] The window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, take a screenshot, etc.

[0095] The content provider is used to store and obtain data, and make the data accessible to the application. The data can include videos, images, audio, dialed and received calls, browsing history and bookmarks, phonebook, etc.

[0096] The resource manager can provide various resources for the application, such as localized strings, icons, pictures, layout files, video files, etc.

[0097] The notification manager enables the application to display notification information in the status bar, which can be used to convey notification type messages that can automatically disappear after a short stay without user interaction. For example, notification information is used to notify download completion, message reminders, etc. Notification information can also be a notification in the form of a chart or a scroll bar text appearing in the top status bar of the system, such as a notification of an application running in the background, or a notification in the form of a dialog window appearing on the screen. For example, prompting text information in the status bar, issuing a prompt sound, the electronic device vibrating, the indicator light flashing, etc.

[0098] The system layer includes system libraries and an Android Runtime. The system libraries can include a plurality of functional modules, such as an image rendering library, an image synthesis library, a function library, and a media library. The Android Runtime includes a core library and a virtual machine, and is responsible for scheduling and management of the Android system. The core library includes two parts: one part is a function function that needs to be called by the java language, and the other part is the core library of Android. The application program layer and the application program framework layer run in the virtual machine, and the virtual machine executes the java files of the application program layer and the application program framework layer into binary files. The virtual machine is used to perform functions such as management of object life cycle, stack management, thread management, security and exception management, and garbage collection.

[0099] It can be understood that, Figure 2 The components included in the system framework layer, the system library, and the runtime layer shown do not constitute a specific limitation on the electronic device 100. In some other embodiments of the present application, the electronic device 100 can include more or fewer components than those shown, or combine certain components, or split certain components, or different arrangement of components.

[0100] The kernel layer is a layer between the hardware and the above-mentioned software layers. The kernel layer at least includes an AP kernel, MCU drivers, display drivers, camera drivers, and sensor drivers. The hardware can include a camera, a display screen, a microphone, a processor, and a memory, and the like.

[0101] Embodiments of the present application provide a time synchronization method applied to an electronic device. The electronic device includes a first processing unit and a second processing unit, and the first processing unit and the second processing unit transmit data through a physical communication link. The first processing unit may, for example, be an application processor (AP) in the electronic device, and the second processing unit may, for example, be a microcontroller unit (MCU) in the electronic device.

[0102] Since the timestamp of the AP is usually accurate enough, the timestamp of the AP can be used as a reference timestamp when synchronizing the timestamp between the AP and the MCU. The AP is a more powerful processor relative to the MCU, which can be used to run an operating system, process application programs, and complex computing tasks. The MCU is different from the AP and is mainly used to control the basic hardware functions of the electronic device and perform specific low-level tasks.

[0103] The physical communication link can be a communication path for transmitting data through a physical medium, such as an interface or a bus for connecting the AP and the MCU. The connection between the AP and the MCU is usually realized through a specific interface or bus, which allows data exchange and communication between the AP and the MCU.

[0104] The interface or bus for connecting the AP and the MCU, for example, includes UART (Universal Asynchronous Receiver-Transmitter), I2C (Inter-Integrated Circuit), SPI (Serial Peripheral Interface), GPIO (General Purpose Input / Output pin), etc.

[0105] The UART is a serial communication protocol, usually used for communication between devices in short distance, which can use two lines (TX and RX) to realize bidirectional serial communication. The I2C is a serial communication bus, usually used for connection between devices in short distance, which can use two lines (SDA and SCL) to realize bidirectional serial communication. The SPI is a serial communication protocol, usually used for high-speed communication between devices, which can use multiple lines (MISO, MOSI, SCK, etc.) to realize full-duplex communication. The GPIO can be used for simple digital signal transmission, which can interact using specific protocols or negotiated communication methods.

[0106] The connection mode between the AP and the MCU depends on the terminal design requirements, hardware architecture and communication requirements. In some cases, the communication between the AP and the MCU can be realized through a direct hardware interface. In other cases, the communication between the AP and the MCU can need to be realized through a protocol at the software level.

[0107] It is easy to understand that the first processing unit can also be a MCU or other processor in the electronic device, and the second processing unit can also be an AP or other processor in the electronic device. That is, the time synchronization method shown in the embodiment can be used for timestamp alignment between the AP and the MCU, and can also be used for timestamp alignment between different MCUs, which is not limited in the embodiment.

[0108] Figure 3 An exemplary connection diagram between the AP and the MCU is shown. As shown in Figure 3 The AP is directly connected to the MCU1 and the MCU2 through a physical bus. The MCU1 and the MCU2 need to complete timestamp synchronization with the AP. Exemplarily, the timestamp of the AP side can be used as a reference timestamp for timestamp synchronization between the AP, the MCU1 or the AP, the MCU2.

[0109] Figure 4 An exemplary interaction diagram between the first processing unit and the second processing unit is shown. As shown in Figure 4As shown, the first processing unit AP is used as the execution subject for illustration. The first processing unit AP and the second processing unit MCU interact based on request-response type instructions.

[0110] The AP sends a first service request to the MCU and records the first transmission timestamp t1. The MCU receives the first service request and records the second reception timestamp t2. The MCU responds to the first service request and generates first response data. The MCU returns the first response data to the AP and records the second transmission timestamp t3.

[0111] The AP receives the first response data returned by the MCU and records the first reception timestamp t4 when the first response data is received. The AP parses the received first response data and obtains the second reception timestamp t2 and the second transmission timestamp t3 indicated by the first response data.

[0112] The AP determines the correction compensation value based on the first transmission timestamp t1, the first reception timestamp t4, the second transmission timestamp t3, the second reception timestamp t2, and the reference timestamp deviation. The AP sends the correction compensation value to the MCU so that the MCU can update the current timestamp based on the correction compensation value.

[0113] Figure 5 The diagram illustrates the process of timestamp synchronization between the AP and the MCU. Taking a mobile terminal product as an example, the link transmission delay between the AP and the MCU includes the processing time of related software, which increases the calculation error of the link transmission delay. This error can be mitigated by repeatedly calculating the average value. Considering that after a user turns on the phone and uses it for a long time, there may be some error in the timestamps between different MCUs, if timestamp synchronization is only performed once (e.g., once upon startup), the timestamp synchronization error will accumulate and increase with longer usage time, affecting the accuracy of timestamp alignment.

[0114] like Figure 5 As shown, before synchronizing the MCU's timestamp, the AP first determines whether this synchronization is the first synchronization. If the result indicates that this synchronization is the first synchronization, the AP calculates deta and offset according to the formulas deta = 1 / 2 × [(t4 – t1) + (t2 – t3)] and offset = 1 / 2 × [(t1 – t2) + (t4 – t3)] respectively, and uses the calculation results as the initial deta and initial offset. The MCU performs its first synchronization based on the initial deta and initial offset.

[0115] If the assessment result indicates that this synchronization is not the first synchronization, the AP inputs the calculated deta and offset to the monitoring module for deta and offset. The monitoring module determines whether the offset needs to be updated. If the assessment result indicates that the offset does not need to be updated, it waits for the next timestamp synchronization. If the assessment result indicates that the offset needs to be updated, the AP updates the offset and records the timestamp T.

[0116] The AP can also send correction compensation values ​​to target clients that require time synchronization, enabling these clients to update their current timestamps. For example, clients that have subscribed to the correction compensation values ​​constitute the target clients. Upon receiving the correction compensation values ​​published by the AP, the target clients update their current timestamps using the values ​​and compensate for the timestamps of pending events cached before time T.

[0117] As an optional embodiment, the AP calculates the link transmission delay deta between the AP and the MCU based on the first transmission timestamp t1, the first reception timestamp t4, the second transmission timestamp t3, and the second reception timestamp t2. The AP determines whether the link transmission delay deta is within a preset time range. If it is determined that the link transmission delay deta is within the preset time range, the AP determines the current timestamp offset offset between the AP and the MCU based on the first transmission timestamp t1, the first reception timestamp t4, the second transmission timestamp t3, and the second reception timestamp t2. The AP determines whether deta is within the preset time range; the link transmission delay deta must be within a reasonable range, that is, the communication link latency should not be too large or too small.

[0118] If deta is too large or too small (i.e., outside a reasonable range), it indicates a possible communication link anomaly, and other data may have significant errors. Therefore, other data is not accepted and is cleaned up. For example, if deta is outside a preset time range, the AP determines that the current link transmission delay deta is invalid, clears the cnt count and corresponding data record, invalidates the first receive timestamp t4 and the current timestamp offset offset for large data records.

[0119] After determining the current timestamp offset between the AP and the MCU, the AP determines whether a difference between the current timestamp offset and a reference timestamp offset is greater than a preset precision threshold. The reference timestamp offset can be a historical timestamp offset between the AP and the MCU calculated when the MCU was last corrected for timestamp. If the difference between the current timestamp offset and the reference timestamp offset is not greater than the preset precision threshold, it indicates that the reference timestamp offset generated when the MCU was last corrected for timestamp is available and does not need to be updated, the offset calculated in the current time is invalid, and the cnt counter and corresponding data record t are cleared.

[0120] In a case where the difference between the current timestamp offset and the reference timestamp offset is greater than the preset precision threshold, the AP determines whether differences between historical timestamp offsets between the AP and the MCU calculated in any of the previous M times and corresponding historical reference offsets are all greater than the preset precision threshold when the AP sends the first service request to the MCU based on the current time.

[0121] In a case where the M differences are all greater than the preset precision threshold, the AP determines whether a link transmission delay deta and historical transmission delays between the AP and the MCU calculated in any of the previous M times satisfy a first stability condition, and whether the current timestamp offset and the M historical timestamp offsets satisfy a second stability condition. For example, the AP can determine whether the deta and the M historical deta satisfy the first stability condition, or whether the offset and the M historical offset satisfy the second stability condition, based on algorithms such as standard deviation, variance, maximum value and minimum value deviation.

[0122] When both the first stability condition and the second stability condition are met, the AP takes the difference between the current timestamp offset and the base timestamp offset as the correction compensation value corr. Meanwhile, the AP can also take the current timestamp offset as the base timestamp offset for the next timestamp correction of the MCU, and obtain the timestamp T with the new base timestamp offset. The AP can also notify the target client subscribed to the correction compensation value corr, so that the target client learns that the correction compensation value corr has changed, and updates the current timestamp with the new correction compensation value corr. The AP can also save the related data (for example, deta, offset and timestamp t4) to the big data cache to be reported, for reporting dotting, so as to analyze the reason for the offset error.

[0123] In an optional implementation, the AP calculates the difference between the first receiving timestamp t4 and the first sending timestamp t1, and the difference between the second receiving timestamp t2 and the second sending timestamp t3, and takes the average of the two differences as the link transmission delay deta. Specifically, the AP calculates the link transmission delay deta according to the following formula:

[0124] deta = 1 / 2 × [(t4-t1) + (t2-t3)].

[0125] In another optional implementation, the AP calculates the difference between the first sending timestamp t1 and the second receiving timestamp t2, and the sixth difference between the first receiving timestamp t4 and the second sending timestamp t3, and takes the average of the two differences as the current timestamp offset offset. Specifically, the AP calculates the current timestamp offset offset according to the following formula:

[0126] offset = 1 / 2 × [(t1+t4) - (t2+t3)] = 1 / 2 × [(t1-t2) + (t4-t3)].

[0127] The derivation process of the calculation method of deta and offset in the embodiment is described below. In the following derivation process, t1a refers to the timestamp corresponding to timestamp t1 of the MCU, and satisfies the relationship t1 = t1a + offset. t3a refers to the timestamp corresponding to timestamp t3 of the AP, and satisfies the relationship t3a = t3 + offset. In the derivation process, it is assumed that the timestamp offset between the AP and the MCU is stable and unchanged between a single service request and a data response. Of course, if offset remains unchanged for a longer period of time, it also meets the condition.

[0128] Based on the above timestamp and related definitions, the following relationship holds:

[0129] Relationship 1: t1 = t1a + offset;

[0130] Relationship 2: t3a = t3 + offset;

[0131] Let the link transmission delay from AP to MCU be Relationship 3: deta12 = t2 - t1a;

[0132] Let the link transmission delay from MCU to AP be Relationship 4: deta21 = t4 - t3a;

[0133] Subtract the equalities on both sides of Relationship 1 and Relationship 2, respectively, to obtain Relationship 5: t1 - t3a = t1a - t3;

[0134] From Relationship 3, Relationship 6 is obtained: t1a = t2 - deta12;

[0135] From Relationship 4, Relationship 7 is obtained: t3a = t4 - deta21;

[0136] Substitute Relationship 6 and 7 into Relationship 5 to obtain Relationship 8: t1 - (t4 - deta21) = t2 - (deta12 + t3);

[0137] From Relationship 8, Relationship 9 is obtained: deta21 + deta12 = (t4 - t1) + (t2 - t3);

[0138] Assume that the link transmission delay between AP and MCU is symmetrically equal (if the time consumption of service request and data response on the link is not symmetric, an alignment error will be introduced. It is not required that the link communication time consumption is continuously stable and equal, but it is required that the link time consumption of a single round trip is as symmetrically equal as possible), denoted as deta, then deta = deta12 = deta21;

[0139] Substitute deta into Relationship 9 to obtain Relationship 10: 2 x deta = (t4 - t1) + (t2 - t3);

[0140] From Relationship 10, Relationship 11 is obtained: deta = 1 / 2 x [(t4 - t1) + (t2 - t3)];

[0141] Substitute Relationship 11 into Relationship 3 to obtain Relationship 12:

[0142] 1 / 2 x [(t4 - t1) + (t2 - t3)] = t2 - t1a;

[0143] From Relationship 1, Relationship 13 is obtained: t1a = t1 - offset;

[0144] Substituting relation 13 into relation 12, we obtain relation 14:

[0145] 1 / 2×(t4–t1)+1 / 2×(t2–t3)=t2–(t1–offset);

[0146] From relation 14, we obtain relation 15:

[0147] Offset=1 / 2×[(t1+t4)–(t2+t3)].

[0148] To ensure the stability of offset and deta, t1, t2, t3 and t4, which are involved in offset and deta calculations, use uncompensated raw timestamps each time.

[0149] Figure 6 A schematic diagram illustrating a process for determining correction compensation values ​​is shown. Figure 6 As shown, the AP calculates the link transmission delay *deta* between the AP and the MCU based on the first transmission timestamp *t1*, the first reception timestamp *t4*, the second transmission timestamp *t3*, and the second reception timestamp *t2*. The AP determines whether the link transmission delay *deta* is within a preset time range. If the link transmission delay *deta* is within the preset time range, the AP determines the current timestamp offset *offset* between the AP and the MCU based on *t1*, *t2*, *t3*, and *t4*. If the link transmission delay *deta* is outside the preset time range, the AP determines that the current link transmission delay *deta* is invalid, clears the *cnt* count and the corresponding data record, invalidates the first reception timestamp *t4*, and sets the current timestamp offset *offset*.

[0150] After determining the current timestamp offset between the AP and the MCU, the AP checks whether the difference between the current timestamp offset and the base timestamp offset (base_offset) is greater than a preset precision threshold. If the difference is greater than the preset precision threshold, the AP records the t4 timestamp corresponding to offset and deta, and increments the count by 1 (for example, cnt = 0 for the first time). If the difference is not greater than the preset precision threshold, the AP determines that this offset is invalid, and clears the cnt count and the corresponding data record.

[0151] The AP checks if the count cnt has reached a preset threshold M. If it has, the AP checks if the stability of both offset and deta meets the criteria. If it has not reached M, the AP returns to the operation of recalculating deta.

[0152] Exemplarily, the AP can determine whether the link transmission delay between the AP and the MCU calculated in the M+1 times satisfies a first stability condition, and whether the timestamp deviation between the AP and the MCU calculated in the M+1 times satisfies a second stability condition.

[0153] In a case where both the first stability condition and the second stability condition are satisfied, the AP takes the difference between the current timestamp deviation offset calculated in any of the M+1 times and the reference timestamp deviation base_offset as the correction compensation value corr. In addition, the AP can also take the average of the difference between the current timestamp deviation offset in the M+1 times and the reference timestamp deviation base_offset as the correction compensation value corr.

[0154] Meanwhile, the AP can also take the current timestamp deviation offset as the reference timestamp deviation base_offset for the next timestamp correction of the MCU, and obtain the timestamp T with the new reference timestamp deviation base_offset. The AP can also notify the target client subscribing to the correction compensation value corr, so that the target client updates the current timestamp with the new correction compensation value corr. The AP can also save the related data (for example, deta, offset and timestamp t4) to the big data cache to be reported, for reporting and dotting, so as to analyze the reason for the offset error.

[0155] Figure 7 The flowchart of the first timestamp synchronization is schematically shown. As shown in Figure 7 After determining that the current timestamp synchronization is the first synchronization, the AP starts the first timestamp synchronization mechanism. In the first timestamp synchronization process, in order to eliminate the error caused by the unstable communication link, offset and deta can be calculated for multiple times (for example, 3 times), and the average of the multiple times is finally taken as offset_base and deta_base for the first synchronization of the timestamp, so as to ensure that the alignment error is relatively small.

[0156] Specifically, when the MCU is first time-stamped, the AP sends multiple synchronization instructions to the MCU and records the third sending time stamp of each time the synchronization instruction is sent. The AP receives the response message returned by the MCU matching each synchronization instruction and records the third receiving time stamp when each response message is received. The AP parses each of the response messages to obtain the fourth receiving time stamp of the MCU when the corresponding synchronization instruction is received and the fourth sending time stamp of the MCU when each response message is sent. The AP determines multiple initial time stamp deviations between the AP and the MCU according to the third sending time stamp, the third receiving time stamp, the fourth sending time stamp and the fourth receiving time stamp matching each instruction. The AP takes the mean of the multiple initial time stamp deviations as the reference time stamp deviation when the MCU is next time-stamped.

[0157] For the case of time stamp first synchronization, for example, when the mobile phone starts from the off state, it will trigger the time stamp first synchronization between the AP and the MCU. When the MCU restarts, the offset and deta in the time stamp synchronization process are invalid, and the time stamp synchronization mechanism between the AP and the MCU needs to be retriggered.

[0158] For the event of time stamp first synchronization alignment, the t2 and t3 values returned by the opposite MCU in the response data packet can be based on the handshake instruction between the MCUs or a special synchronization instruction designed to calculate the related values of time stamp synchronization. For the first generated deta_base and offset_base and their related information, the AP can report them to the big data to monitor similar power-on timing or link communication time-consuming abnormalities for further big data statistical analysis.

[0159] Figure 8 The interaction between the modules in the first processing unit and the second processing unit is schematically shown as follows: Figure 8 As shown, the first processing unit can include a first synchronization judgment module, an instruction sending module, a data receiving module, a data parsing module, a deta calculation module, a deta rationality judgment module, an offset calculation module, an offset rationality judgment module, a deta and offset stability judgment module, and a corr calculation module. The second processing unit can include an instruction receiving module, a data response module, and a time stamp updating module.

[0160] In the case that time stamp synchronization is needed, the first synchronization judging module detects whether a power-on event or a processor restart event occurs to determine whether the current synchronization is a first synchronization. In the case that the current synchronization is not a first synchronization, the instruction sending module sends a first service request to an instruction receiving module of the second processing unit, and records a t1 time stamp when the first service request is sent. The instruction receiving module receives the first service request, and records a t2 time stamp when the first service request is received. The instruction receiving module sends the first service request and the t2 time stamp to a data response module of the second processing unit. The data response module generates first response data based on the first service request, and sends the first response data to the data receiving module. The first response data carries the t2 time stamp and a t3 time stamp when the data response module sends the first response data.

[0161] The data receiving module receives the first response data, and records a t4 time stamp when the first response data is received. The data receiving module sends the received first response data and the t1 and t4 time stamps to a data parsing module. The data parsing module parses the first response data to obtain the t2 and t3 time stamps. The data parsing module sends the t1, t2, t3 and t4 time stamps to a deta calculation module.

[0162] The deta calculation module receives the t1, t2, t3 and t4 time stamps, and calculates a deta value according to the t1, t2, t3 and t4 time stamps. The deta calculation module sends the calculated deta value to a deta rationality judging module. The deta rationality judging module determines whether the deta value is within a preset time range. In the case that the deta value is within the preset time range, an offset calculation module calculates an offset value according to the t1, t2, t3 and t4 time stamps. The offset calculation module sends the calculated offset value to an offset rationality judging module.

[0163] The offset rationality judging module determines whether a difference between the offset value and a base_offset value satisfies a preset accuracy threshold, and whether differences between M historical offset values and corresponding historical base_offset values satisfy the preset accuracy threshold. In the case that the differences satisfy the preset accuracy threshold, a deta and offset stability judging module determines whether the deta value and the M historical deta values, and the offset value and the M historical offset values satisfy a preset stability condition.

[0164] In the case that the values of deta and offset satisfy the stability condition, the corr calculation module calculates the difference between the value of offset and the value of base_offset to obtain the value of corr. The corr calculation module sends the calculated value of corr to the timestamp updating module of the second processing unit. The timestamp updating module updates the current timestamp of the second processing unit by using the value of corr.

[0165] Next, taking the second processing unit in the electronic device as an example, the interaction between the first processing unit and the second processing unit is described. The first processing unit and the second processing unit transmit data through a physical communication link. The first processing unit may be, for example, a main processor (AP) in the electronic device, and the second processing unit may be, for example, a micro controller unit (MCU) in the electronic device.

[0166] The second processing unit receives the first service request sent by the first processing unit and records a second receiving timestamp when the first service request is received. The second processing unit fills the response content based on the first service request and timestamp information into a return packet to form first response data, and the timestamp information includes the second receiving timestamp and a second sending timestamp when the second processing unit returns the first response data. The second processing unit returns the first response data to the first processing unit, so that the first processing unit determines a correction compensation value according to the first response data. In addition, the second processing unit receives the correction compensation value sent by the first processing unit and updates the current timestamp by using the correction compensation value.

[0167] Figure 9 Another interaction diagram between the first processing unit and the second processing unit is schematically shown. As shown in Figure 9 The AP sends a first service request to the MCU and records a first sending timestamp t1 when the first service request is sent. The MCU receives the first service request and records a second receiving timestamp t2 when the first service request is received. The MCU fills the response content based on the first service request and timestamp information into a return packet to form first response data. The timestamp information includes, for example, the second receiving timestamp t2 and a second sending timestamp t3 when the MCU returns the first response data. The AP receives the first response data and records a first receiving timestamp t4 when the first response data is received.

[0168] Since the algorithm for calculating offset and deta relies on carrying the timestamp information of t2 and t3 in the service or handshake response packet, and carrying the timestamp information of t2 and t3 needs to increase the occupation of the inter-core communication bandwidth, the design of t2 and t3 transmission can be optimized to reduce the occupation of the system bandwidth as much as possible.

[0169] The embodiment adopts differential mode to deliver t2 and t3, and takes the t3 timestamp with the largest value as the base timestamp, and takes the diff=t3-t2 as the differential timestamp. After the AP receives the base and the diff, the formula t3=base and t2=base-diff is used to restore t3 and t2. Since the time interval between the request and the response is very close, the diff value is relatively small. By using less bytes to carry the diff information, the consumption of the communication bandwidth can be effectively reduced.

[0170] As a feasible embodiment, in the case that the MCU side includes other timestamps in addition to t2 and t3, the response content based on the first service request, the second sending timestamp t3, the differential timestamp of the second sending timestamp t3 and the second receiving timestamp t2, and the differential timestamp of the second sending timestamp t3 and each other timestamp are filled in the return packet to form the first response data.

[0171] As another feasible embodiment, in the case that the MCU side includes other timestamps in addition to t2 and t3, the response content based on the first service request, the second sending timestamp t3, the differential timestamp of the second sending timestamp t3 and the second receiving timestamp t2, and the to-be-transmitted timestamp corresponding to each other timestamp are filled in the return packet to form the first response data. The highest mark bit of the differential timestamp diff_t2=t3-t2 indicates that the to-be-transmitted timestamp is the original timestamp content of the corresponding other timestamp, or is the differential value of the second sending timestamp t3 and the corresponding other timestamp.

[0172] As shown in Figure 9 , the MCU side may also include t0 and t5 timestamps in addition to the t2 and t3 timestamps, and the t0 and t5 timestamps can be the timestamps when certain events on the MCU side are generated. After receiving the first service request, the MCU fills the response content based on the first service request and the timestamp information into the response packet. Since the t0 and t5 timestamps are acquired before the response data return timestamp t3, the t3 timestamp is the largest timestamp. Therefore, the t3 timestamp can be taken as the base timestamp, and then the differential values of t3 and t2 and t3 and other timestamps are taken in sequence. After the AP side receives the base and the corresponding diff value, the original values of the t3, t2, t0 and t5 timestamps are restored by using the base and the corresponding diff value.

[0173] Considering that the t0 timestamp can have been generated along with the event before the MCU receives the request, the value of diff_t0 = t3 - t0 can be relatively large in an extreme scenario, which can cause the field reserved for diff to overflow, thus causing an exception, which limits the scope of application of the differential protocol. Since the time interval from the time point t2 at which the MCU receives the AP request to the time point t3 at which the MCU sends the response to the AP is short, the field in which diff_t2 is located can be reused to carry some flag information. For example, the MSB (most significant bit) of diff_t2 is used as a flag. If the MSB is 0, it indicates that all the timestamps except t3 are transmitted in the form of differential timestamps with t3. If the MSB is 1, it indicates that all the timestamps except t2 are transmitted in the form of non-differential timestamps. If diff_t2 is too large (that is, the MCU receives the request and then takes a long time to send a response packet to the AP), it exceeds the data range that can be represented by the differential value, and all the bits except the MSB bit are set to 1 to indicate that diff_t2 is out of range and overflow, to notify the AP that the timestamp synchronization data carried this time is invalid (non-timestamp synchronization data can continue to be recovered and used according to the recovery rule), and the AP side does not perform follow-up calculation and calibration compensation analysis of deta and offset.

[0174] The MCU receives the correction compensation value returned by the AP, and corrects the current timestamp using the correction compensation value. For example, the MCU sums the current timestamp and the correction compensation value to obtain the compensated current timestamp.

[0175] In addition, the MCU can also use the correction compensation value to correct the timestamps of the to-be-processed events in the cache queue. The main reason for correcting the timestamps of the to-be-processed events is that if the correction compensation value is not used to update the historical data in the cache, there is a risk of timestamp disorder (for example, the timestamp of an early-received event is later than that of a late-received event, or although the relative relationship is correct, the time error is further enlarged). This poses a risk of abnormal data processing for fusion-type or timestamp-slice-based services. Therefore, when the cache queue is not empty, the timestamps of the to-be-processed events in the cache queue need to be updated using the new correction compensation value to ensure their correct time sequence relationship and relative accuracy.

[0176] Figure 10 Another connection diagram between the AP and the MCU is schematically shown. As shown in Figure 10 MCU1 and MCU2 are directly connected through a physical bus, and MCU1 and the AP are also directly connected through a physical bus. The MCU2 side needs to complete timestamp

[0177] As an optional way, the timestamp synchronization between the AP and the MCU1 is performed first, and then the timestamp synchronization between the MCU1 and the MCU2 (the MCU1 uses the timestamp compensated by the AP) is performed, and finally the timestamp synchronization between the MCU2 and the AP is realized. As another optional way, the MCU1 can be regarded as a part of the physical communication link, and the processing time consumption of the intermediate MCU1 is compensated to the MCU2, so as to decouple the link transmission delay and the processing time of the MCU1.

[0178] Another time synchronization method is provided in the embodiments of the present application, which is applied to an electronic device including a first processing unit, a second processing unit and a third processing unit. The first processing unit and the second processing unit, and the second processing unit and the third processing unit respectively transmit data through physical communication links. The first processing unit, the second processing unit and the third processing unit can be, for example, the AP, the MCU1 and the MCU2 as shown in the above. Figure 10

[0179] Taking the first processing unit as an example, the first processing unit sends a second service request to the second processing unit and records a fifth sending timestamp when the second service request is sent. The first processing unit receives second response data returned by the second processing unit, and records a fifth receiving timestamp when the second response data is received. The second response data is response data generated by the third processing unit based on the second service request after the second processing unit forwards the second service request to the third processing unit. The first processing unit determines a correction compensation value according to the fifth sending timestamp, the fifth receiving timestamp and the second response data. In addition, the first processing unit sends the correction compensation value to the second processing unit, so that the second processing unit forwards the correction compensation value to the third processing unit, so that the third processing unit updates the current timestamp by using the correction compensation value.

[0180] For example, the first processing unit parses the second response data to obtain a sixth receiving timestamp when the second processing unit receives the second service request, a sixth sending timestamp when the second processing unit forwards the second service request, a seventh receiving timestamp when the third processing unit receives the second service request, a seventh sending timestamp when the third processing unit sends the second response data, an eighth receiving timestamp when the second processing unit receives the second response data, and an eighth sending timestamp when the second processing unit forwards the second response data. The first processing unit determines the correction compensation value according to the fifth sending timestamp, the fifth receiving timestamp, the sixth sending timestamp, the sixth receiving timestamp, the seventh sending timestamp, the seventh receiving timestamp, the eighth sending timestamp, the eighth receiving timestamp and the reference timestamp deviation.

[0181] ​Specifically, the first processing unit determines a link transmission delay between the first processing unit and the third processing unit according to the fifth sending timestamp, the fifth receiving timestamp, the sixth sending timestamp, the sixth receiving timestamp, the seventh sending timestamp, the seventh receiving timestamp, the eighth sending timestamp, and the eighth receiving timestamp. In a case where the link transmission delay is within a preset time length range, the first processing unit determines a current timestamp deviation between the first processing unit and the third processing unit according to the fifth sending timestamp, the fifth receiving timestamp, the sixth sending timestamp, the sixth receiving timestamp, the seventh sending timestamp, the seventh receiving timestamp, the eighth sending timestamp, and the eighth receiving timestamp. And determines a correction compensation value according to the current timestamp deviation and the reference timestamp deviation.

[0182] Figure 11 An interaction schematic diagram between the AP and the MCU is schematically shown as Figure 11 The AP, MCU1 and MCU2 shown in the figure, for example, constitute the first processing unit, the second processing unit and the third processing unit. The MCU1 is regarded as a part of the physical communication link, and the processing time consumption of the MCU1 is counted and compensated.

[0183] The fifth sending timestamp is denoted as t1, t1: the timestamp when the AP sends the second service request to the MCU1;

[0184] The sixth receiving timestamp is denoted as t5, t5: the timestamp when the MCU1 receives the second service request;

[0185] The sixth sending timestamp is denoted as t6, t6: the timestamp when the MCU1 forwards the second service request to the MCU2 after receiving and processing the second service request, and the MCU1 forwards the second service request to the MCU2;

[0186] The seventh receiving timestamp is denoted as t2, t2: the timestamp when the MCU2 receives the second service request;

[0187] The seventh sending timestamp is denoted as t3, t3: the timestamp when the MCU2 sends the second response data to the MCU1 after generating the second response data based on the second service request;

[0188] The eighth receiving timestamp is denoted as t7, t7: the timestamp when the MCU1 receives the second response data;

[0189] The eighth sending timestamp is denoted as t8, t8: the timestamp when the MCU1 forwards the second response data to the AP;

[0190] The fifth receiving timestamp is denoted as t4, t4: the timestamp when the AP receives the second response data.

[0191] The AP parses the second response data to obtain t5, t6, t2, t3, t7, and t8 time stamps indicated by the second response data.

[0192] The MCU1 is regarded as a part of the physical communication link, and the processing time of the MCU1 is ignored, and the relationship of deta and offset derived before is still valid:

[0193] Relationship 11: deta = 1 / 2 * [(t4, - t1, ) + (t2, - t3,)]

[0194] Relationship 15: Offset = 1 / 2 * [(t1, + t4, ) - (t2, + t3,)]

[0195] The time stamps of t2, and t3, need to be removed from the time spent in the MCU1:

[0196] t2a = t2, - (t6 - t5)

[0197] t3a = t3, - (t6 - t5)

[0198] t4a = t4, - (t8 - t7) - (t6 - t5)

[0199] The relationship can be obtained by replacing t2, t3, and t4, in the relationship 11 and 15 with t2a, t3a, and t4a:

[0200] Relationship 16: deta = 1 / 2 * {(t4, - t1, ) + [t2, - (t6 - t5) - (t3, + (t8 - t7))]}

[0201] Relationship 17: Offset = 1 / 2 * {t1, + t4, - [t2, - (t6 - t5) + t3, + (t8 - t7)]}

[0202] From the relationship 16 and 17, for the scheme using the intermediate MCU compensation, for t2, the time spent by the intermediate MCU is pushed forward (eliminating the time spent), and for t3, the time spent by the intermediate MCU is pushed backward (compensating for the time spent). Thus, the time spent by the intermediate MCU is compensated to t2, and t3, of the MCU2, respectively, which is equivalent to enlarging the processing time of the MCU2, and ensuring the decoupling of the link transmission delay and the intermediate MCU processing time. In principle, considering that different instructions consume different processing times at the intermediate MCU, when synchronizing the time stamps, the time spent by the intermediate MCU needs to be removed to improve the accuracy of the time stamp synchronization.

[0203] Based on the relationship 16, the AP determines the link transmission delay deta between the AP and the MCU2 according to t1, t4, t5, t6, t2, t3, t7 and t8. The AP determines whether the deta is within a preset time range. The link transmission delay deta should be within a reasonable range, i.e., the communication link time should not be too large or too small. If the deta is too large or too small (i.e., not within the reasonable range), it indicates that there may be an abnormal situation of the communication link, and other data has a high risk of error. The AP does not accept other data and cleans up.

[0204] When the communication link time is within the reasonable range, based on the relationship 17, the AP determines the current timestamp offset between the AP and the MCU2 according to t1, t4, t5, t6, t2, t3, t7 and t8. The AP determines whether the deviation of the current timestamp offset offset relative to the reference timestamp offset base_offset exceeds a threshold. The historical timestamp offset between the AP and the MCU2 calculated when the timestamp correction of the MCU2 was performed last time constitutes the reference timestamp offset base_offset for the timestamp correction of the MCU2 this time.

[0205] If the deviation is within the accuracy threshold, it indicates that the base_offset generated by the previous timestamp alignment is accurate and does not need to be updated. If the deviation exceeds the accuracy threshold, the number of times the deviation exceeds the accuracy threshold consecutively is counted. If the number of times the deviation exceeds the accuracy threshold consecutively exceeds a preset threshold, the stability of deta and offset is checked (standard deviation, variance, or the deviation between the maximum value and the minimum value can be used, which is not limited here). If the stability of deta and offset also meets the preset requirements, the calibration compensation value corr = offset-base_offset is calculated, and the offset of the current time is taken as the base_offset. At the same time, the related data is saved to the big data cache to be reported, and the big data is reported in batches according to the predetermined specification, so as to analyze the cause of the offset deviation.

[0206] Figure 12 Another interaction diagram between the AP and the MCU is schematically shown, as shown in Figure 12 The AP, for example, constitutes a first processing unit, and the MCU, for example, constitutes a second processing unit. The AP and the MCU transmit data through a physical communication link.

[0207] Exemplarily, before the AP initiates a new inter-core communication facing the MCU, the AP pulls up a general-purpose input / output (GPIO), i.e., outputs an electrical signal through a GPIO pin of the AP, records a first output timestamp t1 of the electrical signal output by the GPIO pin, and sends the first output timestamp t1 to the MCU. After receiving the electrical signal, the MCU interrupts a service and records a first trigger timestamp t2 of triggering the interrupt service. After receiving the timestamp t1, the MCU calculates a current timestamp offset between the AP and the MCU according to the timestamps t1 and t2. For example, offset = t1-t2.

[0208] The electrical signal output by the GPIO pin includes, for example, a high level, a low level, a rising edge, or a falling edge, etc. Taking the high level as an example, the method of the embodiment requires that the processor hardware supports pulling up the GPIO before initiating a new inter-core communication each time to trigger the interrupt service of the MCU at the other end.

[0209] Inter-core communication refers to a process of data exchange and communication between different processors or computing cores. The inter-core communication manner includes, for example, shared memory, message passing, DMA (direct memory access), etc. For example, when multiple processors share the same memory region, communication can be performed by reading and writing the shared memory. Alternatively, processors can communicate by sending and receiving messages, for example, through a communication library or a message passing interface.

[0210] It is assumed that the time consumed in the whole process from pulling up the GPIO to obtaining the timestamp t1 at the MCU side, to interrupting the service at the MCU, to obtaining the timestamp t2 at the MCU, is stable and close to 0, which is considered to be basically negligible, so that the timestamp t1 and the timestamp t2 are considered to be timestamps based on the same time point. Therefore, the timestamp conversion from t2 to t1 is offset = t2-t1. For any time point ti at the MCU side, the corresponding timestamp at the AP side is Ti = ti+offset = ti+t2-t1 = t2+(ti-t1). Therefore, the timestamp conversion formula from the MCU to the AP at the time point ti is Ti = t2+(ti-t1). The MCU can directly convert the timestamp at any time point at the local end into the timestamp at the AP side and then send it to the AP side.

[0211] The method of the embodiment requires that the processor hardware supports pulling up the GPIO before initiating a new inter-core communication each time to trigger the interrupt service of the MCU at the other end. For the case of continuous slice transmission, the GPIO can be pulled up only once when the communication is initiated at the beginning, and the GPIO does not need to be repeatedly pulled up in the subsequent multiple slice transmissions. This design can wake up the other end through the GPIO interrupt to prevent the other end from being in a sleep state. Pulling up the GPIO before initiating a new inter-core communication each time can effectively ensure timely wake-up of the other end.

[0212] The timestamp alignment method in the foregoing embodiments is implemented based on a request and a response of a round trip communication, while the timestamp alignment scheme by pulling up the GPIO is implemented based on pulling up the GPIO and an inter-core communication (only the request message carries the timestamp, and no timestamp needs to be added in the response packet). In this embodiment, the communication link time deta of the inter-core communication can be ignored by triggering the interrupt service of the peer end by means of the hardware action. In this embodiment, the timing of the first timestamp alignment is consistent with the general scheme, and the calculation of deta and deta_base can also be not involved in the first alignment process.

[0213] In this embodiment, the algorithm for updating the offset and calculating the compensation value corr based on the service request does not consider the time consumption of pulling up the GPIO and the response interrupt, and thus does not involve the statistics and monitoring related to deta. The change of the offset can be monitored to determine whether the update of the offset needs to be triggered. If the update of the offset needs to be triggered, the precision compensation notification corresponding to the update time T is synchronously sent to the target client subscribed to the precision compensation event. After receiving the precision compensation notification, the timestamp compensation algorithm of the target client is consistent with that in the foregoing embodiments, which will not be described herein again. Since the scheme in this embodiment only needs to transmit one timestamp information, the compression algorithm of the timestamp data can be not considered. For the instruction that needs to transmit the timestamp due to the service demand, the timestamp data compression scheme in the foregoing embodiments can be referred to to reduce the communication bandwidth occupied by the timestamp data, which will not be described herein again.

[0214] It can be understood that, in order to implement the above functions, the electronic device contains hardware and / or software modules corresponding to each function. The algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is implemented in hardware or computer software driven hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered beyond the scope of the present application.

[0215] All related contents of each step involved in the above method embodiments can be referred to the function description of the corresponding function module, which will not be described herein again.

[0216] The embodiment also provides an electronic device, comprising a first processing unit and a second processing unit, data being transmitted between the first processing unit and the second processing unit through a physical communication link, the electronic device further comprising one or more processors, a memory and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device performs the following steps: the first processing unit sends a first service request to the second processing unit, and records a first sending timestamp when the first service request is sent; the first processing unit receives first response data returned by the second processing unit in response to the first service request, and records a first receiving timestamp when the first response data is received; the first processing unit determines a correction compensation value according to the first sending timestamp, the first receiving timestamp and the first response data; and the first processing unit sends the correction compensation value to the second processing unit, so that the second processing unit updates a current timestamp by using the correction compensation value.

[0217] The embodiment also provides a computer storage medium, which stores computer instructions, and when the computer instructions are executed on an electronic device, the electronic device performs the related method steps to implement the time synchronization method in the above embodiment.

[0218] The embodiment also provides a computer program product, and when the computer program product is executed on a computer, the computer performs the related steps to implement the time synchronization method in the above embodiment.

[0219] In addition, the embodiment of the present application also provides a device, which can be a chip, a component or a module, and the device can comprise a processor and a memory connected to each other; wherein the memory is used for storing computer execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory to enable the chip to perform the time synchronization method in the above method embodiments.

[0220] The electronic device, the computer storage medium, the computer program product or the chip provided by the embodiment are used to execute the corresponding method provided above, and thus the beneficial effects achieved by the electronic device, the computer storage medium, the computer program product or the chip can refer to the beneficial effects of the corresponding method provided above, which will not be described herein again.

[0221] Through the above description of the embodiments, those skilled in the art can understand that, for the convenience and brevity of description, only the division of the above functional modules is taken as an example for illustration, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.

[0222] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented by other manners. For example, the apparatus embodiments described above are merely illustrative, for example, the division of the modules or units is merely a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another apparatus, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or components shown or discussed can be indirect coupling or communication connection through some interfaces, apparatuses or units, and can be electrical, mechanical or other forms.

[0223] The units described as separate components can or can not be physically separate, and the components shown as units can be one physical unit or a plurality of physical units, that is, can be located in one place, or can be distributed to a plurality of different places. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.

[0224] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0225] Any content of each embodiment of the present application, and any content of the same embodiment, can be freely combined. Any combination of the above is within the scope of the present application.

[0226] If the integrated unit is realized in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a plurality of instructions for making an apparatus (which can be a single-chip microcomputer, a chip, etc.) or a processor execute all or part of the steps of the method of the embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various program code storage media.

[0227] The embodiments of the present application are described above with reference to the accompanying drawings, but the present application is not limited to the above-described specific embodiments, and the above-described specific embodiments are merely illustrative, but not restrictive, and a person of ordinary skill in the art can make many forms without departing from the purpose of the present application and the scope protected by the claims under the inspiration of the present application, and all of them belong to the protection of the present application.

[0228] The steps of methods or algorithms described in connection with the embodiments disclosed herein can be implemented in hardware, or as software executed by a processor. The software instructions can be stored in a memory, such as a Random Access Memory (RAM), a flash memory, a Read Only Memory (ROM), an Erasable Programmable ROM (EPROM), an Electrically EPROM (EEPROM), a register, a hard disk, a floppy disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor such that the processor can read information from, and write information to, the storage medium. Of course, the storage medium can be a component of the processor. Suitable processors for the execution of instructions can be a complex instruction set computing (CISC) microprocessor, a reduced instruction set computing (RISC) microprocessor, or a very long instruction word (VLIW) microprocessor, depending on the overall design of the processor.

[0229] Those skilled in the art should be aware that, in one or more examples described above, the functions described in the embodiments of the present application can be implemented in hardware, software, firmware or any combination thereof. When implemented in software, these functions can be stored in a computer readable medium or transmitted as one or more instructions or codes on a computer readable medium. The computer readable medium includes computer storage medium and communication medium, wherein the communication medium includes any medium that facilitates the transfer of computer programs from one place to another. The storage medium can be any available medium accessible by a general or special purpose computer.

[0230] The embodiments of the present application are described above with reference to the accompanying drawings, but the present application is not limited to the above-described specific embodiments, and the above-described specific embodiments are merely illustrative, but not restrictive, and a person of ordinary skill in the art can make many forms without departing from the purpose of the present application and the scope protected by the claims under the inspiration of the present application, and all of them belong to the protection of the present application.

Claims

1. A time synchronization method, characterized in that, Applied to an electronic device, the electronic device includes a first processing unit and a second processing unit, the first processing unit being a main application processor (AP) and the second processing unit being a microcontroller unit (MCU), the method being executed by the first processing unit, including: Send a first service request to the second processing unit and record the first sending timestamp when sending the first service request; Receive the first response data returned by the second processing unit in response to the first service request, and record the first receiving timestamp when the first response data is received; The first response data is parsed to obtain the second receiving timestamp when the second processing unit receives the first service request, and the second sending timestamp when the second processing unit sends the first response data; When the first processing unit and the second processing unit perform initial time synchronization, the initial link transmission delay and initial timestamp deviation between the first processing unit and the second processing unit are determined according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp, respectively, and a correction compensation value is determined based on the initial link transmission delay and initial timestamp deviation. When the first processing unit and the second processing unit perform non-first time synchronization, the link transmission delay between the first processing unit and the second processing unit is determined based on the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp. If the link transmission delay is within a preset time range, the current timestamp deviation between the first processing unit and the second processing unit is determined based on the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp. A correction compensation value is determined based on the current timestamp deviation and the reference timestamp deviation. Before the first processing unit initiates new inter-core communication with the second processing unit, an electrical signal is output through the general purpose input / output (GPIO) pin of the first processing unit, so that the second processing unit triggers an interrupt service based on the electrical signal; and a first output timestamp of the electrical signal output by the GPIO pin is recorded and sent to the second processing unit, so that the second processing unit determines the current timestamp deviation between the first processing unit and the second processing unit based on the first output timestamp and the first trigger timestamp of the interrupt service. The correction compensation value is sent to the second processing unit so that the second processing unit updates the current timestamp using the correction compensation value.

2. The method according to claim 1, characterized in that, The historical timestamp deviation between the first processing unit and the second processing unit calculated during the last timestamp correction of the second processing unit constitutes the reference timestamp deviation for the current timestamp correction of the second processing unit.

3. The method according to claim 1, characterized in that, The step of determining the correction compensation value based on the current timestamp deviation and the reference timestamp deviation includes: Determine whether a first difference between the current timestamp deviation and the reference timestamp deviation is greater than a preset accuracy threshold. If the first difference is greater than a preset precision threshold, it is determined whether the second difference between the historical timestamp deviation and the corresponding historical reference deviation calculated in any of the previous M times when the first processing unit sends the first service request to the second processing unit based on the current time is greater than the preset precision threshold, where M is an integer greater than 1; and If all M second differences are greater than a preset accuracy threshold, the first difference is used as the correction compensation value.

4. The method according to claim 3, characterized in that, The method further includes: If all M second differences are greater than a preset precision threshold, determine whether the link transmission delay and the historical transmission delay between the first processing unit and the second processing unit calculated in any of the M adjacent previous times satisfy the first stability condition, and determine whether the current timestamp deviation and the M historical timestamp deviations satisfy the second stability condition. If both the first stability condition and the second stability condition are satisfied, the first difference is used as the correction compensation value.

5. The method according to claim 4, characterized in that, The method further includes: If both the first stability condition and the second stability condition are met, the current timestamp deviation is used as the reference timestamp deviation for the next timestamp correction of the second processing unit.

6. The method according to claim 1, characterized in that, The step of determining the link transmission delay between the first processing unit and the second processing unit based on the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp includes: Calculate the third difference between the first received timestamp and the first sent timestamp, and the fourth difference between the second received timestamp and the second sent timestamp; and The average of the third difference and the fourth difference is used as the link transmission delay.

7. The method according to claim 1, characterized in that, The step of determining the current timestamp deviation between the first processing unit and the second processing unit based on the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp includes: Calculate the fifth difference between the first sending timestamp and the second receiving timestamp, and the sixth difference between the first receiving timestamp and the second sending timestamp; and The average of the fifth difference and the sixth difference is taken as the current timestamp deviation.

8. The method according to claim 1, characterized in that, The method further includes: When performing timestamp correction on the second processing unit for the first time, multiple synchronization instructions are sent to the second processing unit, and the third sending timestamp of each time the synchronization instruction is sent is recorded. Receive the response message returned by the second processing unit that matches each of the synchronization instructions, and record the third receiving timestamp when each of the response messages is received; Parse each of the response messages to obtain the fourth receiving timestamp when the second processing unit receives the corresponding synchronization instruction as indicated by each of the response messages, and the fourth sending timestamp when the second processing unit sends each of the response messages; Based on the third transmission timestamp, the third reception timestamp, the fourth transmission timestamp, and the fourth reception timestamp that match each of the synchronization instructions, a plurality of initial timestamp deviations between the first processing unit and the second processing unit are determined; and The average of the multiple initial timestamp deviations is used as the reference timestamp deviation for the next timestamp correction of the second processing unit.

9. The method according to claim 1, characterized in that, The method further includes: The correction compensation value is sent to the target client that has time synchronization requirements, so that the target client can update its current timestamp using the correction compensation value.

10. A time synchronization method, characterized in that, The method is applied to an electronic device, which includes a first processing unit, a second processing unit, and a third processing unit. The first processing unit is a main application processor (AP), and the second and third processing units are microcontroller units (MCUs). Data is transmitted between the first and second processing units, and between the second and third processing units, via physical communication links. The method is executed by the first processing unit and includes: Send a second service request to the second processing unit and record the fifth sending timestamp when sending the second service request; The system receives the second response data returned by the second processing unit and records the fifth receiving timestamp when the second response data is received. The second response data is the response data generated by the third processing unit based on the second service request after the second processing unit forwards the second service request to the third processing unit. The second response data is parsed to obtain the sixth receiving timestamp when the second processing unit receives the second service request, the sixth sending timestamp when the second processing unit forwards the second service request, the seventh receiving timestamp when the third processing unit receives the second service request, the seventh sending timestamp when the third processing unit sends the second response data, the eighth receiving timestamp when the second processing unit receives the second response data, and the eighth sending timestamp when the second processing unit forwards the second response data. When the first processing unit and the third processing unit perform initial time synchronization, the initial link transmission delay and initial timestamp deviation between the first processing unit and the third processing unit are determined according to the fifth transmission timestamp, the fifth reception timestamp, the sixth transmission timestamp, the sixth reception timestamp, the seventh transmission timestamp, the seventh reception timestamp, the eighth transmission timestamp, and the eighth reception timestamp, respectively. Based on the initial link transmission delay and initial timestamp deviation, a correction compensation value is determined. When the first processing unit and the third processing unit perform non-first time synchronization, the link transmission delay between the first processing unit and the third processing unit is determined based on the fifth transmission timestamp, the fifth reception timestamp, the sixth transmission timestamp, the sixth reception timestamp, the seventh transmission timestamp, the seventh reception timestamp, the eighth transmission timestamp, and the eighth reception timestamp. If the link transmission delay is within a preset time range, the current timestamp deviation between the first processing unit and the third processing unit is determined based on the fifth transmission timestamp, the fifth reception timestamp, the sixth transmission timestamp, the sixth reception timestamp, the seventh transmission timestamp, the seventh reception timestamp, the eighth transmission timestamp, and the eighth reception timestamp. A correction compensation value is determined based on the current timestamp deviation and the reference timestamp deviation. The correction compensation value is sent to the second processing unit so that the second processing unit forwards the correction compensation value to the third processing unit, thereby enabling the third processing unit to update the current timestamp using the correction compensation value. Before the first processing unit initiates new inter-core communication with the second processing unit, an electrical signal is output through the general purpose input / output (GPIO) pin of the first processing unit so that the second processing unit triggers an interrupt service based on the electrical signal; and a first output timestamp of the electrical signal output by the GPIO pin is recorded and sent to the second processing unit so that the second processing unit determines the current timestamp deviation between the first processing unit and the second processing unit based on the first output timestamp and the first trigger timestamp of the interrupt service.

11. A time synchronization method, characterized in that, Applied to an electronic device, the electronic device includes a first processing unit and a second processing unit, the first processing unit being a main application processor (AP) and the second processing unit being a microcontroller unit (MCU), the method being executed by the second processing unit, including: Receive a first service request sent by the first processing unit and record a second receiving timestamp when the first service request is received; The response content and timestamp information based on the first service request are filled into the return packet to form the first response data. The timestamp information includes the second receiving timestamp and the second sending timestamp when the second processing unit returns the first response data. The system returns the first response data to the first processing unit, enabling the first processing unit to determine, based on the first response data, the second receiving timestamp when the second processing unit receives the first service request, and the second sending timestamp when the second processing unit sends the first response data. Furthermore, in the case of initial time synchronization between the first and second processing units, the first processing unit determines the initial link transmission delay and initial timestamp deviation between the first and second processing units based on the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp, and determines a correction compensation value based on the initial link transmission delay and initial timestamp deviation. In the case of non-initial synchronization between the first and second processing units, the first processing unit determines the link transmission delay between the first and second processing units based on the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp. If the link transmission delay is within a preset duration range, the first processing unit determines the current timestamp deviation between the first and second processing units based on the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp, and determines a correction compensation value based on the current timestamp deviation and the reference timestamp deviation. Before the first processing unit initiates new inter-core communication with the second processing unit, an electrical signal is output through the general purpose input / output (GPIO) pin of the first processing unit, so that the second processing unit triggers an interrupt service based on the electrical signal; and a first output timestamp of the electrical signal output by the GPIO pin is recorded and sent to the second processing unit, so that the second processing unit determines the current timestamp deviation between the first processing unit and the second processing unit based on the first output timestamp and the first trigger timestamp of the interrupt service. The system receives the correction compensation value sent by the first processing unit and updates the current timestamp using the correction compensation value.

12. The method according to claim 11, characterized in that, The method further includes: The timestamps of pending events in the cache queue are corrected using the correction compensation value.

13. The method according to claim 11, characterized in that, The step of filling the response content and timestamp information based on the first service request into the return packet to form the first response data includes: The response content based on the first service request, the second sending timestamp, and the differential timestamp between the second sending timestamp and the second receiving timestamp are filled into the return packet to form the first response data.

14. The method according to claim 11, characterized in that, The step of filling the response content and timestamp information based on the first service request into the return packet to form the first response data includes: If the second processing unit includes timestamps other than the second receiving timestamp and the second sending timestamp, the response content based on the first service request, the second sending timestamp, the difference timestamp between the second sending timestamp and the second receiving timestamp, and the difference timestamp between the second sending timestamp and each of the other timestamps are filled into the return packet to form the first response data.

15. The method according to claim 11, characterized in that, The step of filling the response content and timestamp information based on the first service request into the return packet to form the first response data includes: If the second processing unit includes timestamps other than the second receiving timestamp and the second sending timestamp, the response content based on the first service request, the second sending timestamp, the differential timestamp between the second sending timestamp and the second receiving timestamp, and the timestamps to be transmitted corresponding to each of the other timestamps are filled into the return packet to form the first response data. The highest flag bit of the differential timestamp indicates that the timestamp to be transmitted is the original timestamp content corresponding to other timestamps, or is the difference between the second sending timestamp and other corresponding timestamps.

16. The method according to claim 11, characterized in that, The step of updating the current timestamp using the correction compensation value includes: The current timestamp and the correction compensation value are summed to obtain the compensated current timestamp.

17. The method according to claim 16, characterized in that, The method further includes: Using the compensated current timestamp, timestamp correction is performed on other nodes connected to the second processing unit, and data is transmitted between the other nodes and the second processing unit via a physical communication link.

18. An electronic device, characterized in that, The electronic device includes a first processing unit and a second processing unit, wherein the first processing unit is a main application processor (AP) and the second processing unit is a microcontroller unit (MCU). The electronic device further includes one or more processors, a memory, and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device performs the time synchronization method as described in any one of claims 1 to 17.

19. A computer-readable storage medium, characterized in that, Includes a computer program that, when run on an electronic device, causes the electronic device to perform the time synchronization method as described in any one of claims 1 to 17.

Citation Information

Patent Citations

  • SOPC (System on a Programmable Chip) networking based sub-microsecond level clock synchronizing method and system

    CN105429725A

  • Multimedia information processing method and device and storage medium

    CN112118527A

  • Clock synchronization method, device, equipment and medium

    CN115361084A

  • Time synchronization correction method and device, equipment and storage medium

    CN117560758A