Time synchronization method and electronic equipment
By determining the correction compensation value using the timestamp information in the instruction of the request-response type in the terminal device, the problem of timestamp synchronization error between processing units is solved, and the time synchronization accuracy and system stability are improved.
Patent Information
- Application Number
- CN202410182507.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-18
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2044-02-18
AI Technical Summary
There is an error in the timestamp synchronization between processing units in the terminal device. As the MCU runs for a long time, the error further expands, affecting the system stability and performance.
By sending request-response type instructions between processing units, determining the correction compensation value using the carried timestamp information, and updating the current timestamp of the processing unit to be synchronized to achieve higher time synchronization accuracy.
It effectively improves the time synchronization accuracy between processing units, improves the overall performance and operation stability of electronic devices, and improves the user experience.
Smart Images

Figure CN119254365A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of terminal technology, and in particular to a time synchronization method and electronic device. Background Art
[0002] Taking a mobile phone terminal as an example, a main application processor (AP) and one or more microcontroller units (MCU) are usually set in the terminal. The AP and the MCU need to maintain timestamp synchronization to ensure the normal operation of the terminal business and system functions.
[0003] However, there are errors in the timestamp synchronization itself, and as each MCU runs for a long time, there is a problem that the timestamp synchronization error is further expanded. Summary of the invention
[0004] In order to solve the above technical problems, the present application provides a time synchronization method and an electronic device. In the method, when a request-response type instruction is sent between different processing units of the electronic device, a correction compensation value for the timestamp between the different processing units is determined according to the timestamp information carried in the instruction. And, using the correction compensation value, the current timestamp of the processing unit to be synchronized is corrected to achieve time synchronization between the different processing units.
[0005] In a first aspect, an embodiment of the present application provides a time synchronization method, which is applied to an electronic device, wherein the electronic device includes a first processing unit and a second processing unit, and data is transmitted between the first processing unit and the second processing unit via a physical communication link. The method is executed by the first processing unit, and includes: 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 based on 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 using the correction compensation value.
[0006] By utilizing the timestamp information carried in the request-response type instructions, the correction compensation value regarding the timestamp between different processing units is determined, and the current timestamp of the processing unit to be synchronized is corrected using the correction compensation value. This can effectively improve the time synchronization accuracy between different processing units, which is beneficial to improving the overall performance and operating stability of electronic equipment, and is beneficial to improving the user experience.
[0007] According to the first aspect, determining the correction compensation value based on the first sending timestamp, the first receiving timestamp and the first response data includes: parsing the first response data to obtain the second receiving timestamp when the second processing unit receives the first service request indicated by the first response data, and the second sending timestamp when the second processing unit sends the first response data; and determining the correction compensation value based on the first sending timestamp, the first receiving timestamp, the second sending timestamp, the second receiving timestamp and the reference timestamp deviation.
[0008] When the timestamp correction is performed on the second processing unit last time, the historical timestamp deviation between the first processing unit and the second processing unit calculated constitutes the reference timestamp deviation for the current timestamp correction of the second processing unit.
[0009] By improving the timestamp alignment accuracy, the work of different processors can be better coordinated, which is beneficial to improving the stability of system operation and optimizing the overall performance of electronic devices.
[0010] According to the first aspect, or any implementation method of the first aspect above, the correction compensation value is determined according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, the second receiving timestamp and the reference timestamp deviation, including: 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; when the link transmission delay is within a preset time range, 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; 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 abnormality in the communication link, and other data may have a large risk of error. Other data will not be accepted and will be cleared. If the link transmission delay is not within the preset time range, the current link transmission delay is determined to be invalid and the corresponding data record is cleared.
[0012] According to the first aspect, or any implementation of the first aspect above, the historical timestamp deviation between the first processing unit and the second processing unit calculated when the timestamp correction was performed on the second processing unit last time constitutes the benchmark timestamp deviation for the current timestamp correction of the second processing unit.
[0013] According to the first aspect, or any implementation method of the first aspect above, the correction compensation value is determined based on the current timestamp deviation and the reference timestamp deviation, including: determining whether a first difference between the current timestamp deviation and the reference timestamp deviation is greater than a preset accuracy threshold; in a case where the first difference is greater than the preset accuracy threshold, determining whether, when the first processing unit sends the first service request to the second processing unit based on the adjacent previous M times of the current time, the second difference between the historical timestamp deviation between the first processing unit and the second processing unit calculated at any time in the adjacent previous M times and the corresponding historical benchmark deviation is greater than the preset accuracy threshold, where M is an integer greater than 1; and in a case where M of the second differences are all greater than the preset accuracy threshold, using 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 accuracy threshold, it means that the reference timestamp deviation generated when the timestamp correction was 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 the case where the difference between the current timestamp deviation and the reference timestamp deviation is greater than the preset accuracy threshold, the number of times the aforementioned difference is continuously greater than the preset accuracy threshold in the M consecutive service request-response processes based on the current time is counted.
[0015] According to the first aspect, or any implementation of the first aspect above, the method also includes: when the M second differences are all greater than a preset accuracy threshold, determining whether the link transmission delay and the historical transmission delay between the first processing unit and the second processing unit calculated at any of the previous M adjacent times satisfy a first stability condition, and determining whether the current timestamp deviation and the M historical timestamp deviations satisfy a second stability condition; when both the first stability condition and the second stability condition are met, using the first difference as the correction compensation value.
[0016] It can effectively avoid the situation where unstable link transmission delay or current timestamp deviation affects the timestamp alignment accuracy, which is conducive to ensuring the accuracy of clock synchronization between different processing units.
[0017] According to the first aspect, or any implementation of the first aspect above, the method also includes: when both the first stability condition and the second stability condition are met, using the current timestamp deviation as a reference timestamp deviation for the next time a timestamp correction is performed on the second processing unit.
[0018] According to the first aspect, or any implementation method of the first aspect above, 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: 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 the average of the third difference and the fourth difference as the link transmission delay.
[0019] According to the first aspect, or any implementation method of the first aspect above, 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: calculating 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 taking the average of the fifth difference and the sixth difference as the current timestamp deviation.
[0020] According to the first aspect, or any implementation of the first aspect above, the method also includes: when the timestamp correction is performed on the second processing unit for the first time, sending synchronization instructions to the second processing unit multiple times, and recording the third sending timestamp when the synchronization instructions are sent each time; receiving a response message returned by the second processing unit that matches each of the synchronization instructions, and recording the third receiving timestamp when each of the response messages is received; parsing each of the response messages to obtain a fourth receiving timestamp when the second processing unit receives the corresponding synchronization instruction indicated by each of the response messages, and a fourth sending timestamp when the second processing unit sends each of the response messages; determining multiple initial timestamp deviations between the first processing unit and the second processing unit based on the third sending timestamp, the third receiving timestamp, the fourth sending timestamp and the fourth receiving timestamp that match each of the synchronization instructions; and using the average of the multiple initial timestamp deviations as the reference timestamp deviation when the timestamp correction is performed on the second processing unit next time.
[0021] According to the first aspect, or any implementation of the first aspect above, the method further includes: sending the correction compensation value to a target client having a time synchronization requirement, so that the target client updates a current timestamp using the correction compensation value.
[0022] Target clients with time synchronization requirements include, for example, real-time clock (RTC) applications, hardware control applications, sensor data processing applications, etc.
[0023] According to the first aspect, or any implementation of the first aspect above, the method also includes: before the first processing unit initiates a new inter-core communication to the second processing unit, outputting an electrical signal through a 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 recording a first output timestamp of the electrical signal output by the GPIO pin, and sending the first output timestamp 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 that triggers 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.
[0025] In a second aspect, an embodiment of the present application provides a time synchronization method, which is applied to an electronic device, wherein the electronic device includes a first processing unit, a second processing unit and a third processing unit, and data is transmitted between the first processing unit and the second processing unit, and between the second processing unit and the third processing unit through a physical communication link, respectively. The method is executed by the first processing unit, and includes: 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 based on 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 that the third processing unit updates the current timestamp using the correction compensation value.
[0026] According to the second aspect, determining the correction compensation value based on the fifth sending timestamp, the fifth receiving timestamp and the second response data includes: parsing the second response data to obtain the sixth receiving timestamp when the second processing unit receives the second business request indicated by the second response data, the sixth sending timestamp when the second processing unit forwards the second business request, the seventh receiving timestamp when the third processing unit receives the second business 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; and determining the correction compensation value based on 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.
[0027] According to the second aspect, or any implementation method of the second aspect above, the correction compensation value is determined 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, including: determining the 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; when the link transmission delay is within a preset time range, determining the 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 the third aspect, an embodiment of the present application provides a time synchronization method, which is applied to an electronic device, characterized in that the electronic device includes a first processing unit and a second processing unit, and data is transmitted between the first processing unit and the second processing unit through a physical communication link. The method is executed by the second processing unit, including: 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 a response content and timestamp information based on the first service request into a return packet to form a 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; returning the first response data to the first processing unit, so that the first processing unit determines a correction compensation value based on the first response data; and receiving the correction compensation value sent by the first processing unit, and using the correction compensation value to update the current timestamp.
[0029] According to the third aspect, the method further comprises: using the correction compensation value to correct the timestamps of the pending events in the cache queue.
[0030] When the cache queue is not empty, the timestamps of the pending events in the cache queue need to be updated with new correction calibration values to ensure their correct timing relationship and relative accuracy.
[0031] According to the third aspect, or any implementation method of the third aspect above, the response content and timestamp information based on the first business request are filled in the return packet to form the first response data, including: the response content based on the first business request, the second sending timestamp, and the differential timestamp between the second sending timestamp and the second receiving timestamp are filled in the return packet to form the first response data.
[0032] According to the third aspect, or any implementation method of the third aspect above, the response content and timestamp information based on the first business request are filled in the return packet to form the first response data, including: when the second processing unit includes other timestamps except the second receiving timestamp and the second sending timestamp, the response content based on the first business request, the second sending timestamp, the differential timestamp between the second sending timestamp and the second receiving timestamp, and the differential timestamp between the second sending timestamp and each of the other timestamps are filled in the return packet to form the first response data.
[0033] According to the third aspect, or any implementation method of the third aspect above, the response content and timestamp information based on the first service request are filled in the return packet to form the first response data, including: when the second processing unit includes other timestamps except 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 timestamp to be transmitted corresponding to each of the other timestamps are filled in the return packet to form the first response data, wherein the highest mark bit of the differential timestamp indicates that the timestamp to be transmitted is the original timestamp content corresponding to the other timestamps, or is the differential value between the second sending timestamp and the corresponding other timestamps.
[0034] According to the third aspect, or any implementation of the third aspect above, the updating of the current timestamp using the correction compensation value includes: summing the current timestamp and the correction compensation value to obtain a compensated current timestamp.
[0035] According to the third aspect, or any implementation of the third aspect above, the method also includes: using the compensated current timestamp to perform timestamp correction on other nodes connected to the second processing unit, and transmitting data between the other nodes and the second processing unit via a physical communication link.
[0036] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising a first processing unit and a second processing unit, wherein data is transmitted between the first processing unit and the second processing unit via 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 based on 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 the current timestamp using the correction compensation value.
[0037] The fourth aspect and any implementation of the fourth aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the fourth aspect and any implementation of the fourth aspect can refer to the technical effects corresponding to the above-mentioned first aspect and any implementation of the first aspect, which will not be repeated here.
[0038] In a fifth aspect, an embodiment of the present application provides a computer-readable medium for storing a computer program, wherein the computer program includes instructions for executing the method in the first aspect or any possible implementation 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 of the first aspect.
[0040] In a seventh aspect, an embodiment of the present application provides a chip, the chip comprising a processing circuit and a transceiver pin, wherein the transceiver pin and the processing circuit communicate with each other through an internal connection path, and the processing circuit executes the method in the first aspect or any possible implementation 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 THE DRAWINGS
[0041] Figure 1 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0042] Figure 2 A software structure block diagram of an electronic device provided in an embodiment of the present application;
[0043] Figure 3 A schematic diagram of a connection between an AP and an MCU provided in an embodiment of the present application;
[0044] Figure 4 A schematic diagram of interaction between a first processing unit and a second processing unit provided in an embodiment of the present application;
[0045] Figure 5 A schematic diagram of a process for synchronizing timestamps between an AP and an MCU provided in an embodiment of the present application;
[0046] Figure 6 A schematic diagram of a process for determining a correction compensation value provided in an embodiment of the present application;
[0047] Figure 7 A schematic diagram of the process of performing timestamp synchronization for the first time provided in an embodiment of the present application;
[0048] Figure 8 A schematic diagram of the interaction between the first processing unit and the modules in the second processing unit provided in an embodiment of the present application;
[0049] Fig. 9 Another schematic diagram of interaction between the first processing unit and the second processing unit provided in an embodiment of the present application;
[0050] Fig.10 Another connection diagram between the AP and the MCU provided in an embodiment of the present application;
[0051] Fig.11 The diagram schematically shows the interaction between the AP and the MCU;
[0052] Fig.12 Another interaction diagram between the AP and the MCU is schematically shown. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0054] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0055] The terms "first" and "second" in the description and claims of the embodiments of the present application are used to distinguish different objects rather than to describe a specific order of objects. For example, a first target object and a second target object are used to distinguish different target objects rather than to describe a specific order of target objects.
[0056] In the embodiments of the present application, the words "exemplarily" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplarily" or "for example" is intended to present related concepts in a specific way.
[0057] In the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more than two. For example, multiple processing units refer to two or more processing units; multiple systems refer to two or more systems.
[0058] Taking a mobile phone terminal as an example, a main application processor (AP) and one or more microcontroller units (MCU) are usually set in the terminal. The AP is mainly responsible for running the operating system, executing applications, processing graphics, connecting to the network and other complex computing and communication tasks. The MCU may 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 when an event occurs. If the timestamps of the AP and MCU in the terminal are not synchronized, it may affect communication, data consistency, logging, system security, and normal operation of applications.
[0060] For example, timestamps are often used in communication protocols to determine the time when a message is sent and received. If the timestamps in the terminal are not synchronized, the order of messages may be disrupted or other communication problems may occur. For another example, in a distributed system, timestamps are used to ensure data consistency. If the timestamps of different processing units are not synchronized, data synchronization errors or consistency issues may occur. In addition, software systems and applications may use timestamps to record events. Timestamps that are not synchronized may cause the time order of logs to be disrupted, increasing the difficulty of troubleshooting and auditing. Therefore, ensuring the synchronization of timestamps between the AP and the MCU in the terminal is a key factor in maintaining the stability of the system and applications.
[0061] However, there are errors in the timestamp synchronization itself, and as each MCU runs for a long time, there is a problem that the timestamp synchronization error is further expanded.
[0062] The embodiment of the present application provides 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 data is transmitted between the first processing unit and the second processing unit via a physical communication link. The first processing unit can be, for example, a main processor AP in the electronic device, and the timestamp of the main processor is usually sufficiently accurate and can be used as a reference timestamp for timestamp synchronization between the AP and the MCU. The second processing unit can be, for example, an MCU in the electronic device, and the MCU can be a processor extended by the chip manufacturer itself, or a coprocessor integrated by the chip manufacturer.
[0063] When a request-response type command is sent between the AP and the MCU, the correction compensation value of the timestamp between the AP and the MCU is determined according to the timestamp information carried in the command. 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 sending the first service request. 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 based on 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 using the correction compensation value. The timestamp alignment accuracy in the terminal can be effectively improved, and the stability of the system and application can be effectively maintained.
[0065] Electronic devices may include mobile phones, tablet computers, smart watches, laptop computers, self-driving vehicles, smart homes, machine navigation devices, virtual-reality fusion devices, etc. The embodiments of the present application may be applied to various scenarios where time synchronization is required.
[0066] like Figure 1 The structure diagram of the electronic device 100 is shown. Optionally, the electronic device 100 can be called a terminal or 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 laptop computer, a vehicle-mounted device, a personal digital assistant (PDA), and other electronic devices with a time synchronization function. Specifically, the functional modules involved in the present application can be deployed on the DSP chip of the relevant device, and specifically can be the application program or software therein. A time synchronization function can be realized through software installation or upgrade, and through the call and coordination of hardware.
[0067] It should be understood that Figure 1 The electronic device 100 shown is only one example of an electronic device, and the electronic device 100 may have more or fewer components than shown in the figure, may combine two or more components, or may have a different configuration of components. Figure 1 The various components shown in the EMBODIMENTS 2000 may 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 may 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 may include a pressure sensor, a gyroscope 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, and the like.
[0069] The processor 110 may include one or more processing units, for example, the processor 110 may 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. Different processing units may be independent devices or integrated into one or more processors.
[0070] The processor 110 may include a main application processor AP111 and a microcontroller unit MCU112. The electronic device 100 may include one or more MCU112, and the MCU112 and the AP 111 may be integrated into the same chip or independently set in different chips. The MCU 112 may be responsible for performing specific tasks, such as power management, hardware control, sensor data processing, etc.
[0071] A memory may also be provided in the processor 110 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 implemented through the antenna 1, the antenna 2, the mobile communication module 130, the wireless communication module 140, the modem processor, the baseband processor, and the like.
[0073] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antennas.
[0074] The mobile communication module 130 may provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 130 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc.
[0075] The wireless communication module 140 can provide wireless communication solutions for application in the electronic device 100, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication technology (NFC), infrared technology (IR), etc.
[0076] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 130, and antenna 2 is coupled to wireless communication module 140, so that electronic device 100 can communicate with the network and other devices through wireless communication technology.
[0077] The electronic device 100 implements display functions through a GPU, a display screen 164, and an application processor, etc. The processor 110 may 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 may include 1 or N display screens 164, where N is 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.
[0080] The ISP is used to process the data fed back by the camera 163. For example, when taking a photo, the shutter is opened, and 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 and converts it into an image visible to the naked eye. The ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. The ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, the ISP can be set in the camera 163.
[0081] The camera 163 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the 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, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 163, where N is a positive integer greater than 1.
[0082] Among them, the camera 163 can be located in the edge area of the electronic device, can be an under-screen camera, or can be a liftable camera. The camera 163 can include a front camera and a rear camera. The embodiment of the present application does not limit the specific position and form of the camera 163. The electronic device 100 can include cameras of one or more focal lengths. For example, cameras of different focal lengths can include a telephoto camera, a wide-angle camera, an ultra-wide-angle camera, or a panoramic camera.
[0083] The memory 120 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the memory 120, for example, enabling the electronic device 100 to implement the time synchronization method in the embodiment of the present application. The memory 120 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0084] The memory 120 may store a time synchronization module 121, which is a program code module storing the time synchronization method provided in the embodiment of the present application, and may be used to estimate the pose of the input image and to perform confidence assessment on the pose estimation result to determine the reliability of the pose estimation result. The SLAM module 112 may perform real-time tracking of the pose of the electronic device based on the pose estimation result and confidence assessment result of the time synchronization module 121, thereby realizing autonomous positioning and navigation of the electronic device.
[0085] The touch sensor is also called a "touch panel". The touch sensor can be set on the display screen 164. The touch sensor and the display screen 164 form a touch screen, also called a "touch screen". The touch sensor is used to detect a touch operation acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 164.
[0086] The pressure sensor is used to sense the pressure signal and can 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 touch position according to the detection signal of the pressure sensor.
[0087] The gyro sensor may be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (ie, x, y, and z axes) may be determined by the gyro sensor.
[0088] The accelerometer can detect the magnitude of the acceleration of the electronic device 100 in all directions (generally three axes). When the electronic device 100 is stationary, the accelerometer can detect the magnitude and direction of gravity. The accelerometer can also be used to identify the posture of the electronic device, and is applied to applications such as horizontal and vertical screen switching and pedometers.
[0089] The key 160 includes a power key (or power key), a volume key, etc. The key 160 can be a mechanical key or a touch key. The electronic device 100 can receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0090] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture or a cloud architecture. In the embodiment of the present invention, the Android system of the layered architecture is taken as an example to exemplify the software structure of the electronic device 100.
[0091] like Figure 2 The software structure 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, and 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, which are the application layer, the application framework layer, the Android runtime (Android runtime), the system layer, and the kernel layer from top to bottom.
[0092] The application layer can include a series of application packages, such as Figure 2As shown, the application package may include power management applications, hardware control applications, communication control applications, 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 modules 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 applications in the application layer, including various components and services to support developers' Android development. The application framework layer includes some predefined functions. Figure 2 As shown, the application framework layer may include a window manager, a content provider, a notification manager, a resource manager, and the like.
[0094] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0095] Content providers are used to store and retrieve data and make it accessible to applications. The data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0096] The resource manager can provide various resources for the application, such as localized strings, icons, images, layout files, video files, and so on.
[0097] The notification manager allows applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, notification information is used to inform the completion of downloads, message reminders, etc. Notification information can also appear in the system top status bar in the form of icons or scroll bar text, such as notifications of applications running in the background, or in the form of dialog windows on the screen. For example, text messages are displayed in the status bar, prompts sound, electronic devices vibrate, indicator lights flash, etc.
[0098] The system layer includes the system library and the Android Runtime. The system library can include multiple functional modules, such as image rendering library, image synthesis library, function library and media library. The Android Runtime includes the core library and the virtual machine. The Android Runtime is responsible for the scheduling and management of the Android system. The core library contains two parts: one part is the function functions that need to be called by the Java language, and the other part is the Android core library. The application layer and the application framework layer run in the virtual machine, and the virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0099] Understandably, Figure 2 The components included in the system framework layer, system library and runtime layer shown do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown, or combine some components, or split some components, or arrange the components differently.
[0100] The kernel layer is the layer between the hardware and the above software layers. The kernel layer contains at least the AP kernel, MCU driver, display driver, camera driver, and sensor driver. The hardware may include devices such as cameras, displays, microphones, processors, and memory.
[0101] The embodiment of the present application provides a time synchronization method, which is applied to an electronic device. The electronic device includes a first processing unit and a second processing unit, and data is transmitted between the first processing unit and the second processing unit via 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 microcontroller unit MCU in the electronic device.
[0102] Since the AP's timestamp is usually accurate enough, the AP's timestamp can be used as the reference timestamp when synchronizing the timestamps between the AP and the MCU. The AP is a more powerful processor than the MCU and can be used to run operating systems, process applications, and complex computing tasks. Unlike the AP, the MCU is mainly used to control the basic hardware functions of electronic devices and perform specific low-level tasks.
[0103] The physical communication link can be a communication path for data transmission through a physical medium, and the physical medium can be, for example, an interface or bus for connecting the AP and the MCU. The connection between the AP and the MCU is usually achieved through a specific interface or bus, which allows data exchange and communication between the AP and the MCU.
[0104] The interface or bus used to connect the AP and the MCU includes, for example, UART (Universal Asynchronous Receiver-Transmitter), I2C (Inter-Integrated Circuit), SPI (Serial Peripheral Interface), GPIO (General Purpose Input / Output), etc.
[0105] UART is a serial communication protocol, usually used for communication between short-distance devices. It can use two wires (TX and RX) to achieve bidirectional serial communication. I2C is a serial communication bus, usually used for connection between short-distance devices. It can use two wires (SDA and SCL) to achieve bidirectional serial communication. SPI is a serial communication protocol, usually used for high-speed communication between devices. It can use multiple wires (MISO, MOSI, SCK, etc.) to achieve full-duplex communication. GPIO can be used for simple digital signal transmission, and can interact using specific protocols or negotiated communication methods.
[0106] The connection method between AP and MCU depends on the terminal design requirements, hardware architecture and communication needs. In some cases, the communication between AP and MCU can be achieved through a direct hardware interface. In other cases, the communication between AP and MCU may require a protocol at the software level.
[0107] It is easy to understand that the first processing unit may be, for example, an MCU or other processor in an electronic device, and the second processing unit may be, for example, an AP or other processor in an electronic device. That is, the time synchronization method shown in this embodiment can be used for timestamp alignment between an AP and an MCU, and can also be used for timestamp alignment between different MCUs, which is not limited in this embodiment.
[0108] Figure 3 The figure schematically shows a connection diagram between AP and MCU. Figure 3 As shown, the AP is directly connected to MCU1 and MCU2 through a physical bus. MCU1 and MCU2 need to complete timestamp synchronization with the AP. For example, the timestamp on the AP side can be used as a reference timestamp to synchronize the timestamp between AP and MCU1 or AP and MCU2.
[0109] Figure 4 Schematically shows an interaction diagram between the first processing unit and the second processing unit. Figure 4As shown, taking the first processing unit AP as an execution subject as an example, 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 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 responds to the first service request and generates first response data. The MCU returns the first response data to the AP and records a second sending timestamp t3 when the first response data is returned.
[0111] The AP receives the first response data returned by the MCU and records the first receiving timestamp t4 when the first response data is received. The AP parses the received first response data and obtains the second receiving timestamp t2 and the second sending timestamp t3 indicated by the first response data.
[0112] The AP determines the correction compensation value according to the first sending timestamp t1, the first receiving timestamp t4, the second sending timestamp t3, the second receiving timestamp t2 and the reference timestamp deviation. The AP sends the correction compensation value to the MCU so that the MCU updates the current timestamp based on the correction compensation value.
[0113] Figure 5 The schematic diagram shows the process flow of timestamp synchronization between AP and MCU. Taking mobile terminal products as an example, the link transmission delay between AP and MCU includes the processing time of related software, which will increase the calculation error of link transmission delay. For this kind of error, the method of repeatedly calculating the average can be used to reduce some uncertainties. Considering that after the user turns on the mobile phone and uses it for a long time, there may be a certain error in the timestamps between different MCUs. If only one timestamp synchronization is performed (for example, synchronization once when the phone is turned on), the timestamp synchronization error will accumulate and expand as the usage time increases, affecting the accuracy of timestamp alignment.
[0114] like Figure 5 As shown in the figure, before synchronizing the MCU with the timestamp, the AP first determines whether this synchronization is the first synchronization. If the judgment result shows that this synchronization is the first synchronization, the AP calculates deta and offset according to the formula deta = 1 / 2 × [(t4–t1) + (t2–t3)] and offset = 1 / 2 × [(t1–t2) + (t4–t3)], and uses the calculation results as the initial deta and initial offset. The MCU performs the first synchronization based on the initial deta and initial offset.
[0115] If the judgment result shows that this synchronization is not the first synchronization, the AP inputs the calculated deta and offset into the monitoring module for deta and offset. The monitoring module determines whether the offset needs to be updated. If the judgment result shows that the offset does not need to be updated, wait for the next timestamp synchronization. If the judgment result shows that the offset needs to be updated, the AP updates the offset and records the timestamp T.
[0116] The AP may also send a correction compensation value to a target client with a time synchronization requirement, so that the target client updates the current timestamp using the correction compensation value. For example, a client that has subscribed to the correction compensation value, for example, constitutes a target client. After listening to the correction compensation value published by the AP, the target client updates the current timestamp using the correction compensation value, and performs compensation processing on the timestamps of the events to be processed that are 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 sending timestamp t1, the first receiving timestamp t4, the second sending timestamp t3, and the second receiving timestamp t2. The AP determines whether the link transmission delay deta is within a preset time range. When it is determined that the link transmission delay deta is within the preset time range, the AP determines the current timestamp deviation offset between the AP and the MCU based on the first sending timestamp t1, the first receiving timestamp t4, the second sending timestamp t3, and the second receiving timestamp t2. The AP determines whether deta is within the preset time range. The link transmission delay deta needs to be within a reasonable range, that is, the communication link time consumption should not be too large or too small.
[0118] If deta is too large or too small (i.e., not within a reasonable range), it indicates that there may be an abnormality in the communication link, and other data may have a large error risk, so other data will not be accepted and will be cleaned up. For example, when 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, and the invalid first reception timestamp t4 and the current timestamp offset of the large data record.
[0119] After determining the current timestamp deviation offset between the AP and the MCU, the AP determines whether the difference between the current timestamp deviation offset and the reference timestamp deviation base_offset is greater than a preset accuracy threshold. The reference timestamp deviation base_offset may be the historical time deviation between the AP and the MCU calculated when the timestamp correction was last performed on the MCU. If the difference between the current timestamp deviation offset and the reference timestamp deviation base_offset is not greater than the preset accuracy threshold, it means that the reference timestamp deviation base_offset generated when the timestamp correction was last performed on the MCU is available and does not need to be updated. The offset calculated this time is invalid, and the cnt count and the corresponding data record t are cleared.
[0120] When the difference between the current timestamp deviation offset and the benchmark timestamp deviation base_offset is greater than the preset accuracy threshold, determine whether the difference between the historical timestamp deviation between the AP and the MCU calculated at any of the previous M times and the corresponding historical benchmark deviation when the AP sends the first service request to the MCU based on the previous M times of the current time is greater than the preset accuracy threshold, where M is an integer greater than 1.
[0121] When all M differences are greater than a preset accuracy threshold, the AP determines whether the link transmission delay deta and the historical transmission delay between the AP and the MCU calculated at any of the previous M times meet the first stability condition, and determines whether the current timestamp deviation offset and the M historical timestamp deviations meet the second stability condition. Exemplarily, the AP can determine whether deta and the M historical detas meet the first stability condition, or whether offset and the M historical offsets meet the second stability condition based on algorithms such as standard deviation, variance, and deviation between the maximum and minimum values.
[0122] When both the first stability condition and the second stability condition are met, the AP uses the difference between the current timestamp deviation offset and the reference timestamp deviation base_offset as the correction compensation value corr. At the same time, the AP can also use 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 for enabling the new reference timestamp deviation base_offset. The AP can also notify the target client that subscribes to the correction compensation value corr so that the target client is informed of the change in the correction compensation value corr and updates the current timestamp with the new correction compensation value corr. The AP can also save relevant data (such as deta, offset, and timestamp t4) to the big data cache to be reported for reporting and marking, so that R&D can analyze the cause of 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 uses 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 uses the average of the two differences as the current timestamp offset. Specifically, the AP calculates the current timestamp offset according to the following formula:
[0126] offset=1 / 2×[(t1+t4)–(t2+t3)]=1 / 2×[(t1–t2)+(t4–t3)].
[0127] The following is an explanation of the derivation process of the calculation method of deta and offset in this embodiment. In the following derivation process, t1a refers to the timestamp corresponding to the MCU and the timestamp t1, and satisfies the relationship t1=t1a+offset. t3a refers to the timestamp corresponding to the AP and the timestamp t3, and satisfies the relationship t3a=t3+offset. In the derivation process, it is assumed that the timestamp deviation offset between the AP and the MCU is stable and unchanged between a single service request and a data response. Of course, if the offset remains unchanged for a longer period of time, the same conditions are met.
[0128] Based on the above timestamps and related definitions, the following relationship holds:
[0129] Relationship 1: t1 = t1a + offset;
[0130] Relationship 2: t3a = t3 + offset;
[0131] The link transmission delay from AP to MCU is recorded as equation 3: deta12 = t2 – t1a;
[0132] The link transmission delay from MCU to AP is recorded as equation 4: deta21 = t4 – t3a;
[0133] Subtracting both sides of the equal sign of equation 1 and equation 2, we get equation 5: t1–t3a=t1a–t3;
[0134] From equation 3, we get equation 6: t1a = t2 – deta12;
[0135] From equation 4, we get equation 7: t3a = t4 – deta21;
[0136] Substituting equations 6 and 7 into equation 5, we get equation 8: t1–(t4–deta21)=t2–(deta12+t3);
[0137] From equation 8, equation 9 is obtained: deta21+deta12=(t4–t1)+(t2–t3);
[0138] Assume that the link transmission delay between the AP and the MCU is symmetrical and equal (if the time consumption of the service request and the data response on the link is asymmetrical, alignment error will be introduced. It is not required that the link communication time consumption is continuously and stably equal, but the link time consumption of a single round trip is required to be as symmetrical and equal as possible), recorded as deta, then deta = deta12 = deta21;
[0139] Substituting deta into equation 9, we obtain equation 10: 2×deta=(t4–t1)+(t2–t3);
[0140] From equation 10, we get equation 11: deta = 1 / 2 × [(t4–t1) + (t2–t3)];
[0141] Substituting equation 11 into equation 3, we get equation 12:
[0142] 1 / 2×[(t4–t1)+(t2–t3)]=t2–t1a;
[0143] From equation 1, we get equation 13: t1a = t1 – offset;
[0144] Substituting equation 13 into equation 12, we get equation 14:
[0145] 1 / 2×(t4–t1)+1 / 2×(t2–t3)=t2–(t1–offset);
[0146] From equation 14, we get equation 15:
[0147] Offset=1 / 2×[(t1+t4)–(t2+t3)].
[0148] To ensure the stability of offset and deta, each time t1, t2, t3, and t4 involved in offset and deta calculation uses an uncompensated native timestamp.
[0149] Figure 6 A schematic diagram of a process for determining a correction compensation value is shown schematically. Figure 6 As shown, the AP calculates the link transmission delay deta between the AP and the MCU based on the first sending timestamp t1, the first receiving timestamp t4, the second sending timestamp t3 and the second receiving timestamp t2. The AP determines whether the link transmission delay deta is within the preset time range. When the link transmission delay deta is within the preset time range, the AP determines the current timestamp deviation offset between the AP and the MCU based on t1, t2, t3 and t4. When 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, and the large data records the invalid first receiving timestamp t4 and the current timestamp deviation offset.
[0150] After determining the current timestamp deviation offset between the AP and the MCU, the AP determines whether the difference between the current timestamp deviation offset and the reference timestamp deviation base_offset is greater than the preset accuracy threshold. If the difference is greater than the preset accuracy threshold, the AP records the t4 timestamp corresponding to the offset and deta, and counts plus 1 (the first time can be recorded as cnt=0, for example). If the difference is not greater than the preset accuracy threshold, the AP determines that the offset is invalid, and clears the cnt count and the corresponding data record.
[0151] The AP determines whether the count cnt reaches a preset number threshold M. If it reaches M, the AP determines whether the stability of offset and deta meets the standard. If it does not reach M, the operation of calculating deta is returned to the next step.
[0152] Exemplarily, the AP may determine whether the link transmission delay between the AP and the MCU calculated in M+1 times satisfies a first stability condition, and whether the timestamp deviation between the AP and the MCU calculated in M+1 times satisfies a second stability condition.
[0153] When both the first stability condition and the second stability condition are satisfied, the AP uses the difference between the current timestamp deviation offset and the reference timestamp deviation base_offset calculated at any time in M+1 times as the correction compensation value corr. In addition, the AP may also use the average of the differences between the current timestamp deviation offset and the reference timestamp deviation base_offset in M+1 times as the correction compensation value corr.
[0154] At the same time, the AP can also use the current timestamp deviation offset as the base timestamp deviation base_offset for the next timestamp correction of the MCU, and obtain the timestamp T that enables the new base timestamp deviation base_offset. The AP can also notify the target client that subscribes 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 relevant data (such as deta, offset, and timestamp t4) to the big data cache to be reported for reporting and analysis, so as to provide research and development with the cause of the offset error.
[0155] Figure 7 The schematic diagram shows the process of performing timestamp synchronization for the first time. Figure 7 As shown, after the AP determines that this timestamp synchronization is the first synchronization, it starts the first timestamp synchronization mechanism. During the first timestamp synchronization process, in order to eliminate the error caused by the unstable communication link, the offset and deta can be calculated multiple times (for example, 3 times), and finally the average of the multiple calculations is used as the offset_base and deta_base to perform the first synchronization of the timestamp, ensuring that the alignment error is relatively small.
[0156] Specifically, when the timestamp correction is performed on the MCU for the first time, the AP sends synchronization instructions to the MCU multiple times, and records the third sending timestamp when the synchronization instructions are sent each time. The AP receives a response message returned by the MCU that matches each synchronization instruction, and records the third receiving timestamp when each response message is received. The AP parses each of the response messages to obtain the fourth receiving timestamp when the MCU indicated by each response message receives the corresponding synchronization instruction, and the fourth sending timestamp when the MCU sends each response message. The AP determines multiple initial timestamp deviations between the AP and the MCU based on the third sending timestamp, the third receiving timestamp, the fourth sending timestamp, and the fourth receiving timestamp that match each instruction. The AP uses the average of the multiple initial timestamp deviations as the reference timestamp deviation when the timestamp correction is performed on the MCU next time.
[0157] For the situation where the first synchronization of timestamps is required, taking a mobile phone as an example, when the mobile phone starts from the off state, the first synchronization of timestamps between AP and MCU will be triggered. When the MCU restarts and causes the offset and deta in the timestamp synchronization process to become invalid, the timestamp synchronization mechanism between AP and MCU also needs to be re-triggered.
[0158] For the first synchronization and alignment of timestamps, based on the handshake instructions between MCUs or the design of special synchronization instructions, the peer MCU can return the values of t2 and t3 in the response data packet to calculate the relevant values of timestamp synchronization. For the first generated deta_base and offset_base and their related information, the AP can report them to big data to monitor abnormalities such as power-on timing or link communication time consumption for further big data statistical analysis.
[0159] Figure 8 The schematic diagram of the interaction between the modules in the first processing unit and the second processing unit is shown schematically. Figure 8 As shown, the first processing unit may 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 may include an instruction receiving module, a data response module, and a timestamp update module.
[0160] When timestamp synchronization is required, the first synchronization judgment module detects whether a power-on event or a processor restart event occurs to determine whether this synchronization is the first synchronization. When this synchronization is not the first synchronization, the instruction sending module sends a first service request to the instruction receiving module of the second processing unit, and records the t1 timestamp when the first service request is issued. The instruction receiving module receives the first service request and records the t2 timestamp when the first service request is received. The instruction receiving module sends the first service request and the t2 timestamp to the 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 timestamp and the t3 timestamp when the data response module sends the first response data.
[0161] The data receiving module receives the first response data and records the t4 timestamp when the first response data is received. The data receiving module sends the received first response data and the t1 and t4 timestamps to the data parsing module. The data parsing module parses the first response data and obtains the t2 and t3 timestamps. The data parsing module sends the t1, t2, t3, and t4 timestamps to the deta calculation module.
[0162] The deta calculation module receives the t1, t2, t3, and t4 timestamps, and calculates the deta value according to the t1, t2, t3, and t4 timestamps. The deta calculation module sends the calculated deta value to the deta rationality judgment module. The deta rationality judgment module determines whether the deta value is within the preset time range. When the deta value is within the preset time range, the offset calculation module calculates the offset value according to the t1, t2, t3, and t4 timestamps. The offset calculation module sends the calculated offset value to the offset rationality judgment module.
[0163] The offset rationality judgment module judges whether the difference between the offset value and the base_offset value meets the preset accuracy threshold, and whether the difference between the M historical offset values and the corresponding historical base_offset values meets the preset accuracy threshold. When the difference values meet the preset accuracy threshold, the deta and offset stability judgment module judges whether the deta value meets the M historical deta values, and the offset value meets the M historical offset values.
[0164] When both the deta value and the offset value meet the stability condition, the corr calculation module calculates the difference between the offset value and the base_offset value to obtain the corr value. The corr calculation module sends the calculated corr value to the timestamp update module of the second processing unit. The timestamp update module uses the corr value to update the current timestamp of the second processing unit.
[0165] Next, the execution subject is the second processing unit in the electronic device. The first processing unit and the second processing unit transmit data via 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 microcontroller unit MCU in the electronic device.
[0166] The second processing unit receives the first service request sent by the first processing unit, and records the second receiving timestamp when the first service request is received. The second processing unit fills the response content and timestamp information based on the first service request into the return packet to form the first response data, and the timestamp information includes the second receiving timestamp and the 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 the correction compensation value according to the first response data. And, the second processing unit receives the correction compensation value sent by the first processing unit, and updates the current timestamp using the correction compensation value.
[0167] Fig. 9 Another schematic diagram of interaction between the first processing unit and the second processing unit is shown schematically. Fig. 9 As shown, the AP sends a first service request to the MCU and records the first sending timestamp t1 when sending the first service request. The MCU receives the first service request and records the second receiving timestamp t2 when receiving the first service request. The MCU fills the response content and timestamp information based on the first service request in the return packet to form the first response data. The timestamp information, for example, includes the second receiving timestamp t2 and the second sending timestamp t3 when the MCU returns the first response data. The AP receives the first response data and records the first receiving timestamp t4 when receiving the first response data.
[0168] Since the algorithm for calculating offset and deta relies on carrying the timestamp information of t2 and t3 in the business or handshake response packet, and carrying the timestamp information of t2 and t3 requires increasing the occupancy of inter-core communication bandwidth, the design of t2 and t3 transmission should minimize the occupancy of system bandwidth.
[0169] This embodiment uses a differential method to transmit t2 and t3, and uses the t3 timestamp with the largest value as the base timestamp, and diff = t3-t2 as the differential timestamp. After the AP receives the base and diff, the formula t3 = base, 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 will be relatively small. By using fewer bytes to carry diff information, the consumption of communication bandwidth can be effectively reduced.
[0170] As a feasible embodiment, when the MCU side includes other timestamps except t2 and t3, the response content based on the first service request, the second sending timestamp t3, the differential timestamp between the second sending timestamp t3 and the second receiving timestamp t2, and the differential timestamp between 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, when the MCU side includes other timestamps except t2 and t3, the response content based on the first service request, the second sending timestamp t3, the differential timestamp between the second sending timestamp t3 and the second receiving timestamp t2, and the to-be-transmitted timestamps corresponding to the other timestamps 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 aforementioned to-be-transmitted timestamp is the original timestamp content corresponding to the other timestamps, or is the differential value between the second sending timestamp t3 and the corresponding other timestamps.
[0172] like Fig. 9 As shown, in addition to the t2 and t3 timestamps, the MCU side may also include t0 and t5 timestamps. The t0 and t5 timestamps can be the timestamps when a certain event on the MCU side is generated. After receiving the first service request, the MCU fills the response content and timestamp information based on the first service request into the response packet. Since the t0 and t5 timestamps are obtained before the response data sends back the timestamp t3, the t3 timestamp is the largest timestamp. Therefore, the t3 timestamp can be used as the base timestamp, followed by the differential values of t3 and t2, t3 and other timestamps. After the AP side receives the base and the corresponding diff values, the base and the corresponding diff values are used to restore the original values of the t3, t2, t0 and t5 timestamps.
[0173] Considering that the t0 timestamp may have been generated with an event before the MCU receives the request, the value of diff_t0 = t3-t0 will be relatively large in extreme scenarios, which may cause the field reserved for diff to overflow, resulting in anomalies, which limits the scope of application of the differential protocol. Since the time interval from the time t2 when the MCU receives the AP request to the time t3 when the MCU responds to the AP is very short, the field where 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 means that except for t3, other timestamps are transmitted using the differential timestamp with t3. If the MSB is 1, it means that other timestamps except t2 are transmitted in the form of non-differential timestamps. If diff_t2 is too large (i.e., the MCU takes a long time to send a response packet back to the AP after receiving the request), and exceeds the data range that can be represented by the differential value, all bits except the MSB are set to 1 to indicate that diff_t2 is out of bounds, which is used to notify the AP that the timestamp synchronization data carried this time is invalid (non-timestamp synchronization data can continue to be restored and used according to the recovery rules), 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 pending events in the cache queue. The main reason for correcting the timestamps of pending events is that if the correction compensation value is not used to uniformly update the cached historical data, there is a risk of timestamp confusion (for example, the timestamp of an earlier received event is later than the timestamp of a later received event, or although the relative relationship is correct, the time error is further widened). This poses a risk of data processing anomalies for fusion or timestamp-sliced services. Therefore, when the cache queue is not empty, the timestamps of pending events in the cache queue need to be updated with new correction calibration values to ensure their correct timing relationship and relative accuracy.
[0176] Fig.10 Another connection diagram between AP and MCU is shown schematically. Fig.10 As shown, MCU1 and MCU2 are directly connected through a physical bus, and MCU1 and AP are also directly connected through a physical bus. MCU2 needs to complete the timestamp with the AP.
[0177] As an optional method, the timestamp synchronization between AP and MCU1 can be performed first, and then the timestamp synchronization between MCU1 and MCU2 (MCU1 uses the timestamp after synchronization compensation with AP), and finally the timestamp synchronization between MCU2 and AP is achieved. As another optional method, MCU1 can be regarded as part of the physical communication link, and the processing time of the intermediate MCU1 can be compensated to MCU2, so as to achieve the decoupling of the link transmission delay and the processing time of MCU1.
[0178] The embodiment of the present application provides another time synchronization method, which is applied to an electronic device, wherein the electronic device includes a first processing unit, a second processing unit, and a third processing unit, and data is transmitted between the first processing unit and the second processing unit, and between the second processing unit and the third processing unit respectively through a physical communication link. The first processing unit, the second processing unit, and the third processing unit can be, for example, Fig.10 AP, MCU1 and MCU2 are shown.
[0179] Taking the execution subject as the first processing unit as an example, the first processing unit sends a second service request to the second processing unit, and records the fifth sending timestamp when sending the second service request. The first processing unit receives the second response data returned by the second processing unit, and records the fifth receiving timestamp when receiving the second response data, wherein 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 first processing unit determines the correction compensation value according to the fifth sending timestamp, the fifth receiving timestamp and the second response data. And, 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 using the correction compensation value.
[0180] Exemplarily, the first processing unit parses the second response data to obtain the sixth receiving timestamp when the second processing unit receives the second service request indicated by the second response data, 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. 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 the 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. When the link transmission delay is within the preset time range, the first processing unit determines the 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, according to the current timestamp deviation and the reference timestamp deviation, a correction compensation value is determined.
[0182] Fig.11 The schematic diagram of the interaction between AP and MCU is shown as follows: Fig.11 The AP, MCU1 and MCU2 shown in the figure constitute, for example, a first processing unit, a second processing unit and a third processing unit. MCU1 is regarded as a part of the physical communication link, and the processing time consumption of MCU1 is counted and compensated.
[0183] The fifth sending timestamp is recorded as t1, where t1 is the timestamp when the AP sends the second service request to MCU1;
[0184] The sixth receiving timestamp is recorded as t5, where t5 is the timestamp when MCU1 receives the second service request;
[0185] The sixth sending timestamp is recorded as t6, where t6 is the timestamp when MCU1 forwards the second service request to MCU2 after MCU1 receives and processes the second service request;
[0186] The seventh receiving timestamp is recorded as t2', t2': the timestamp when MCU2 receives the second service request;
[0187] The seventh sending timestamp is recorded as t3′, where t3′ is the timestamp when MCU2 sends the second response data to MCU1 after generating the second response data based on the second service request;
[0188] The eighth receiving timestamp is recorded as t7, where t7 is the timestamp when MCU1 receives the second response data;
[0189] The eighth sending timestamp is recorded as t8, where t8 is the timestamp when MCU1 forwards the second response data to the AP;
[0190] The fifth receiving timestamp is recorded as t4′: the timestamp when the AP receives the second response data.
[0191] The AP parses the second response data to obtain the timestamps t5, t6, t2′, t3′, t7, and t8 indicated by the second response data.
[0192] Considering MCU1 as part of the physical communication link and ignoring the processing time of MCU1, the relationship between deta and offset derived previously still holds:
[0193] Relationship 11: deta = 1 / 2*[(t4, –t1,)+(t2, –t3,)]
[0194] Relationship 15: Offset = 1 / 2*[(t1, + t4,) – (t2, + t3,)]
[0195] Consider the need to remove the time spent in MCU1 from the timestamps of t2 and t3:
[0196] t2a=t2,-(t6-t5)
[0197] t3a=t3,-(t6-t5)
[0198] t4a=t4,–(t8–t7)-(t6-t5)
[0199] Substituting t2a, t3a, t4a for t2′, t3′, t4′ in equations 11 and 15, we can obtain the following equation:
[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 equations 16 and 17, for the solution using the intermediate MCU compensation, for t2, the time of delay of the intermediate MCU is pushed forward (eliminating the delay time), and for t3, the time of delay in the middle is pushed back (compensating for the delay time). Therefore, the time of delay of the intermediate MCU is compensated to t2 and t3 of MCU2 respectively, which is equivalent to increasing the processing time of MCU2 and ensuring the decoupling of link transmission delay and intermediate MCU processing time. In principle, considering that different instructions consume different processing times at the intermediate MCU, when synchronizing timestamps, it is necessary to eliminate the processing time of the intermediate MCU to improve the accuracy of timestamp synchronization.
[0203] Based on equation 16, AP determines the link transmission delay deta between AP and MCU2 according to t1, t4, t5, t6, t2, t3, t7 and t8. AP determines whether deta is within the preset time range. The link transmission delay deta needs to be within a reasonable range, that is, the communication link time should not be too large or too small. If deta is too large or too small (that is, not within a reasonable range), it means that there may be an abnormality in the communication link, and there is a risk of large errors in other data. Other data will not be accepted and will be cleaned up.
[0204] When the communication link duration is within a reasonable range, based on equation 17, the AP determines the current timestamp deviation offset between the AP and MCU2 according to t1, t4, t5, t6, t2, t3, t7 and t8. The AP determines whether the deviation of the current timestamp deviation offset relative to the reference timestamp deviation base_offset exceeds a threshold. The historical timestamp deviation between the AP and MCU2 calculated when the timestamp correction was performed on MCU2 last time constitutes the reference timestamp deviation for the current timestamp correction of MCU2.
[0205] If the deviation is within the accuracy threshold, it means that the accuracy of the base_offset generated by the previous timestamp alignment is available and does not need to be updated. If the deviation exceeds the accuracy threshold, the number of times the deviation exceeds the accuracy threshold continuously is counted. If the number of times the accuracy threshold is exceeded continuously exceeds the preset threshold, the stability of deta and offset is checked (standard deviation, variance, or algorithms such as the deviation between the maximum and minimum values can be used, which are 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 current offset is used as base_offset. At the same time, the relevant data is saved in the big data cache to be reported, and the big data is reported in batches according to the predetermined specifications for analyzing the causes of the offset deviation.
[0206] Fig.12 Another interaction diagram between AP and MCU is schematically shown. Fig.12 The AP shown, for example, constitutes a first processing unit, and the MCU, for example, constitutes a second processing unit. Data is transmitted between the AP and the MCU via a physical communication link.
[0207] For example, before the AP initiates a new inter-core communication to the MCU, the AP pulls up the general input / output GPIO, that is, outputs an electrical signal through the GPIO pin of the AP, and records the first output timestamp t1 when the GPIO pin outputs the electrical signal, and sends the first output timestamp t1 to the MCU. After receiving the electrical signal, the MCU interrupts the service and records the first trigger timestamp t2 that triggers the interrupt service. After receiving the timestamp t1, the MCU calculates the current timestamp deviation offset between the AP and the MCU based on the timestamps t1 and t2. For example, offset = t1-t2.
[0208] The electrical signal output by the GPIO pin includes, for example, high level, low level, rising edge or falling edge, etc. Taking high level as an example, the method of this embodiment requires the processor hardware to support the action of pulling up the GPIO to trigger the opposite MCU to interrupt the service before initiating a new inter-core communication each time.
[0209] Inter-core communication refers to the process of data exchange and communication between different processors or computing cores. The methods of inter-core communication include shared memory, message passing, DMA (direct memory access), etc. For example, when multiple processors share the same memory area, they can communicate by reading and writing shared memory. Alternatively, processors can communicate by sending and receiving messages, for example, through a communication library or a message passing interface.
[0210] Assume that the time consumed by the whole process from pulling up GPIO to obtaining timestamp t1 on the MCU side, to MCU interrupting service, to MCU obtaining timestamp t2 is stable and close to 0, which is considered to be basically negligible. Then, it is considered that timestamp t1 and timestamp t2 are timestamps based on the same time point. Therefore, the timestamp conversion from t2 to t1 is offset = t2-t1. For any time point ti on the MCU side, the corresponding timestamp converted to the AP side is Ti = ti + offset = ti + t2-t1 = t2 + (ti-t1). Therefore, the timestamp conversion formula from MCU to AP at time ti is: Ti = t2 + (ti-t1) The MCU can directly convert the timestamp at any time on the local side into the timestamp on the AP side, and then send it to the AP side.
[0211] The method of this embodiment requires that the processor hardware supports the action of pulling up the GPIO to trigger the interrupt service of the MCU on the other end before initiating each new inter-core communication. In the case of continuous slice transmission, the GPIO can be pulled up only once when the communication is first initiated, and there is no need to repeatedly pull up the GPIO during the subsequent multiple slice transmissions. This design can wake up the other party through the GPIO interrupt to prevent the other party from being in a dormant state. Pulling up the GPIO before initiating each new inter-core communication can effectively ensure that the other party is woken up in time.
[0212] The timestamp alignment method in the aforementioned embodiment is implemented based on a one-way communication of request and response, while the timestamp alignment scheme performed by raising GPIO is implemented based on raising GPIO and one inter-core communication (only the request message needs to carry the timestamp, and there is no need to add the timestamp in the response packet). This embodiment triggers the interrupt service of the other end by relying on hardware actions, so the communication link time deta of the inter-core communication can be ignored. The timing of the first timestamp alignment in this embodiment is consistent with the general scheme, except that the calculation of deta and deta_base may not be 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 responding to the interrupt, so it does not involve deta-related statistics and monitoring. It can be determined whether the update of the offset needs to be triggered only by monitoring the change of the offset. 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 that subscribes to the precision compensation event. After the target client receives the precision compensation notification, its timestamp compensation algorithm is consistent with the aforementioned embodiment, which will not be repeated here. Since the scheme of this embodiment only needs to transmit one timestamp information, the compression algorithm of the timestamp data can be ignored. For instructions that need to transmit timestamps due to business demands, the timestamp data compression scheme in the aforementioned embodiment can be referred to to reduce the communication bandwidth occupied by the timestamp data, which will not be repeated here.
[0214] It is understandable that, in order to realize the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving 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 to be beyond the scope of the present application.
[0215] All relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, and will not be repeated here.
[0216] This embodiment also provides an electronic device, comprising: a first processing unit and a second processing unit, data is transmitted between the first processing unit and the second processing unit via a physical communication link, the electronic device also 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 based on 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 the current timestamp using the correction compensation value.
[0217] This embodiment further provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the time synchronization method in the above-mentioned embodiment.
[0218] This embodiment further provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the above-mentioned related steps to implement the time synchronization method in the above-mentioned embodiment.
[0219] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory so that the chip executes the time synchronization method in the above-mentioned method embodiments.
[0220] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above and will not be repeated here.
[0221] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0222] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0223] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0224] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0225] Any content of each embodiment of the present application, as well as any content of the same embodiment, can be freely combined. Any combination of the above content is within the scope of the present application.
[0226] If the integrated unit is implemented 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 solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0227] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
[0228] The steps of the method or algorithm described in conjunction with the disclosure of the embodiments of the present application can be implemented in a hardware manner, or can be implemented by a processor executing a software instruction. The software instruction can be composed of corresponding software modules, and the software module can be stored in a random access memory (Random Access Memory, RAM), a flash memory, a read-only memory (Read Only Memory, ROM), an erasable programmable read-only memory (Erasable Programmable ROM, EPROM), an electrically erasable programmable read-only memory (Electrically EPROM, EEPROM), a register, a hard disk, a mobile hard disk, a read-only compact disk (CD-ROM) or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and can write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.
[0229] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented with hardware, software, firmware, or any combination thereof. When implemented using 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. Computer-readable media include computer storage media and communication media, wherein the communication media include any media that facilitates the transmission of a computer program from one place to another. The storage medium can be any available medium that a general or special-purpose computer can access.
[0230] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within 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, data is transmitted between the first processing unit and the second processing unit via a physical communication link, and the method is executed by the first processing unit, including: Sending a first service request to the second processing unit, and recording a first sending timestamp when sending the first service request; 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 The correction compensation value is sent to the second processing unit, so that the second processing unit updates a current timestamp using the correction compensation value.
2. The method according to claim 1, characterized in that The determining the correction compensation value according to the first sending timestamp, the first receiving timestamp and the first response data includes: Parsing the first response data to obtain a second receiving timestamp indicated by the first response data when the second processing unit receives the first service request and a second sending timestamp when the second processing unit sends the first response data; and A correction compensation value is determined according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, the second receiving timestamp and a reference timestamp deviation.
3. The method according to claim 2, characterized in that The step of determining a correction compensation value according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, the second receiving timestamp, and a reference timestamp deviation includes: Determine 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; When 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 The correction compensation value is determined according to the current timestamp deviation and the reference timestamp deviation.
4. The method according to claim 2, characterized in that: When the timestamp correction is performed on the second processing unit last time, the historical timestamp deviation between the first processing unit and the second processing unit calculated constitutes the reference timestamp deviation for the current timestamp correction is performed on the second processing unit.
5. The method according to claim 3, characterized in that: The step of determining the correction compensation value according to the current timestamp deviation and the reference timestamp deviation includes: Determining whether a first difference between the current timestamp deviation and the reference timestamp deviation is greater than a preset accuracy threshold; In a case where the first difference is greater than a preset accuracy threshold, determining whether, when the first processing unit sends the first service request to the second processing unit based on the M adjacent previous times of the current time, a second difference between the historical timestamp deviation between the first processing unit and the second processing unit and the corresponding historical reference deviation calculated at any time of the M adjacent previous times is greater than a preset accuracy threshold, where M is an integer greater than 1; and When all M second difference values are greater than a preset accuracy threshold, the first difference value is used as the correction compensation value.
6. The method according to claim 5, characterized in that The method further comprises: In a case where the M second differences are all greater than a preset accuracy threshold, determining whether the link transmission delay and the historical transmission delay between the first processing unit and the second processing unit calculated at any of the previous M adjacent times meet a first stability condition, and determining whether the current timestamp deviation and the M historical timestamp deviations meet a second stability condition; When both the first stability condition and the second stability condition are satisfied, the first difference is used as the correction compensation value.
7. The method according to claim 6, characterized in that The method further comprises: When both the first stability condition and the second stability condition are satisfied, the current timestamp deviation is used as a reference timestamp deviation when performing timestamp correction on the second processing unit next time.
8. The method according to claim 3, characterized in that The determining, according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp, of a link transmission delay between the first processing unit and the second processing unit includes: 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 An average of the third difference and the fourth difference is used as the link transmission delay.
9. The method according to claim 3, characterized in that: The determining, according to the first sending timestamp, the first receiving timestamp, the second sending timestamp, and the second receiving timestamp, a current timestamp deviation between the first processing unit and the second processing unit includes: 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 An average of the fifth difference and the sixth difference is used as the current timestamp deviation.
10. The method according to claim 1, characterized in that The method further comprises: When performing timestamp correction on the second processing unit for the first time, sending synchronization instructions to the second processing unit multiple times, and recording a third sending timestamp when sending the synchronization instruction each time; receiving a response message returned by the second processing unit and matching each of the synchronization instructions, and recording a third receiving timestamp when each of the response messages is received; Parse each of the response messages to obtain a fourth receiving timestamp when the second processing unit receives the corresponding synchronization instruction indicated by each of the response messages, and a fourth sending timestamp when the second processing unit sends each of the response messages; Determine 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 that match the synchronization instructions; and The average of the multiple initial timestamp deviations is used as a reference timestamp deviation when performing timestamp correction on the second processing unit next time.
11. The method according to claim 1, characterized in that: The method further comprises: The correction compensation value is sent to a target client having a time synchronization requirement, so that the target client updates a current timestamp using the correction compensation value.
12. The method according to claim 1, characterized in that The method further comprises: Before the first processing unit initiates a new inter-core communication with respect to the second processing unit, outputting an electrical signal through a 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 Record a first output timestamp of the GPIO pin output electrical signal, and send the first output timestamp to the second processing unit, so that the second processing unit determines a current timestamp deviation between the first processing unit and the second processing unit based on the first output timestamp and the first trigger timestamp that triggers the interrupt service.
13. A time synchronization method, characterized in that: Applied to an electronic device, the electronic device includes a first processing unit, a second processing unit and a third processing unit, the first processing unit and the second processing unit, the second processing unit and the third processing unit transmit data respectively through a physical communication link, and the method is executed by the first processing unit, including: Sending a second service request to the second processing unit, and recording a fifth sending timestamp when sending the second service request; 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 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, so that the third processing unit updates the current timestamp by using the correction compensation value.
14. The method according to claim 13, characterized in that The step of determining a correction compensation value according to the fifth sending timestamp, the fifth receiving timestamp, and the second response data includes: parsing the second response data to obtain a sixth receiving timestamp indicated by the second response data 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; and The correction compensation value is determined 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.
15. The method according to claim 14, characterized in that 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: Determine 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; When 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 The correction compensation value is determined according to the current timestamp deviation and the reference timestamp deviation.
16. 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, data is transmitted between the first processing unit and the second processing unit via a physical communication link, and the method is executed by the second processing unit, including: 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 the response content and timestamp information based on the first service request into the return packet to form first response data, wherein the timestamp information includes 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 The correction compensation value sent by the first processing unit is received, and a current timestamp is updated using the correction compensation value.
17. The method according to claim 16, characterized in that The method further comprises: The timestamps of the pending events in the cache queue are corrected using the correction compensation value.
18. The method according to claim 16, characterized in that Filling the response content and timestamp information based on the first service request into the return packet to form first response data includes: Fill 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 into the return packet to form the first response data.
19. The method according to claim 16, characterized in that Filling the response content and timestamp information based on the first service request into the return packet to form first response data includes: In the case where the second processing unit includes other timestamps in addition to 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 differential timestamp between the second sending timestamp and each of the other timestamps are filled in the return packet to form the first response data.
20. The method according to claim 16, characterized in that Filling the response content and timestamp information based on the first service request into the return packet to form first response data includes: In the case where the second processing unit includes other timestamps except 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 to-be-transmitted timestamps corresponding to the other timestamps are filled into the return packet to form the first response data, The highest mark bit of the differential timestamp indicates that the timestamp to be transmitted is the original timestamp content of the corresponding other timestamp, or is the difference value between the second sending timestamp and the corresponding other timestamp.
21. The method according to claim 16, characterized in that The updating of the current timestamp by using the correction compensation value comprises: The current timestamp and the correction compensation value are summed to obtain a compensated current timestamp.
22. The method according to claim 21, characterized in that The method further comprises: The compensated current timestamp is used to perform timestamp correction 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.
23. An electronic device, characterized in that: The electronic device comprises a first processing unit and a second processing unit, wherein data is transmitted between the first processing unit and the second processing unit via 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 using the correction compensation value.
24. A computer-readable storage medium, characterized in that: It comprises a computer program, which, when executed on an electronic device, enables the electronic device to execute the time synchronization method as claimed in any one of claims 1 to 23.
Citation Information
Patent Citations
SOPC (System on a Programmable Chip) networking based sub-microsecond level clock synchronizing method and system
CN105429725A
Synchronous time comparing equipment of redundant Ethernet, system and method thereof
CN105978652A
Multimedia information processing method and device and storage medium
CN112118527A
Time synchronization method, system and related device
CN114222360A
Clock synchronization method, device, equipment and medium
CN115361084A
Cited By
Audio playing method and system, sending equipment and storage medium
CN121334561A
