A method, apparatus, device, and medium for time compensation
Patent Information
- Application Number
- CN202510374052.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-26
- Publication Date
- 2026-09-29
AI Technical Summary
[0005]本申请提供了一种时间补偿的方法、装置、设备及介质,以解决心跳信号中断导致的车载实时系统时钟出现偏差的问题
[0028]本申请通过根据心跳信号的实际触发时间和心跳信号的标准触发时间确定时间补偿量;根据所述时间补偿量动态调整心跳触发周期,即通过调整心跳触发周期使得所述车载实时系统的所述实际触发时间与所述标准触发时间同步,能够提高车辆驾驶的安全性。
Smart Images

Figure CN122845006A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of vehicle-mounted real-time system technology, and in particular to a method, apparatus, device and medium for time compensation. Background Technology
[0002] In a vehicle real-time system, the system is typically used to control, monitor, and optimize various vehicle functions to ensure vehicle safety.
[0003] The scheduling, task execution, and timing of in-vehicle real-time systems typically rely on heartbeat signals periodically sent by the system's timer to monitor the system's operational status.
[0004] Critical section protection is a crucial mechanism in automotive real-time systems to ensure correct access to shared resources in multi-tasking or multi-threaded environments. A critical section shared resource can only be accessed by one task or thread at a time. Common critical section protection methods include interrupt disabling, mutexes, semaphores, and spinlocks. When an automotive real-time system performs operations such as interrupt disabling, it causes the heartbeat signal to be interrupted, preventing the system from responding to the heartbeat signal. This results in a clock deviation between the heartbeat signal transmission time and the standard parameter time (physical time), affecting vehicle driving safety. Summary of the Invention
[0005] This application provides a method, apparatus, device, and medium for time compensation to solve the problem of clock deviation in vehicle-mounted real-time systems caused by interruption of heartbeat signals.
[0006] To address the aforementioned problems, this application discloses a time compensation method, comprising:
[0007] The time compensation amount is determined based on the actual trigger time of the heartbeat signal and the standard trigger time of the heartbeat signal.
[0008] Adjust the heartbeat trigger interval based on the time compensation amount.
[0009] Optionally, the method further includes: after adjusting the heartbeat trigger cycle once, restoring the subsequent cycle in which the heartbeat signal is located to the standard cycle.
[0010] Optionally, adjusting the heartbeat triggering period according to the time compensation amount includes:
[0011] Determine whether the time compensation amount is greater than zero;
[0012] If the time compensation is greater than zero, the next heartbeat trigger cycle will be shortened.
[0013] Optionally, adjusting the heartbeat triggering period according to the time compensation amount includes:
[0014] Determine whether the time compensation amount is less than zero;
[0015] If the time compensation is less than zero, the next heartbeat triggering cycle will be extended.
[0016] Optionally, the heartbeat triggering period is determined based on the standard heartbeat period and the time compensation amount.
[0017] To address the aforementioned problems, this application also discloses a time compensation device, comprising:
[0018] The time compensation module is used to determine the time compensation amount based on the actual trigger time of the heartbeat signal and the standard trigger time of the heartbeat signal.
[0019] The adjustment module is used to adjust the heartbeat trigger interval time according to the time compensation amount.
[0020] Optionally, the device further includes: a recovery module;
[0021] The recovery module is used to restore the subsequent cycle in which the heartbeat signal is located to the standard cycle after adjusting the heartbeat trigger cycle once.
[0022] Optionally, the adjustment module includes:
[0023] The judgment unit is used to determine whether the time compensation amount is greater than zero;
[0024] A shortened interval time unit is used to shorten the next heartbeat trigger cycle if the time compensation amount is greater than zero.
[0025] To address the aforementioned problems, this application also discloses an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the aforementioned time compensation method.
[0026] To address the aforementioned problems, this application also discloses a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned time compensation method.
[0027] Compared with the prior art, this application has the following advantages:
[0028] This application determines the time compensation amount based on the actual trigger time and the standard trigger time of the heartbeat signal; and dynamically adjusts the heartbeat trigger cycle based on the time compensation amount, that is, by adjusting the heartbeat trigger cycle, the actual trigger time of the vehicle real-time system is synchronized with the standard trigger time, which can improve the safety of vehicle driving.
[0029] Of course, any product implementing this application does not necessarily need to achieve all of the advantages described above at the same time. Attached Figure Description
[0030] Figure 1 This is a schematic diagram of the clock skew of the system in this application;
[0031] Figure 2 This is a schematic diagram of the clock after compensation based on the compensation amount in the system of this application embodiment;
[0032] Figure 3 This is a flowchart of a time compensation method described in an embodiment of this application;
[0033] Figure 4 This is a flowchart of a time compensation method described in an embodiment of this application;
[0034] Figure 5 This is a schematic diagram of the clock after compensation based on the compensation amount in the system of this application embodiment;
[0035] Figure 6 This is a structural diagram of a time compensation device described in an embodiment of this application. Detailed Implementation
[0036] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0037] In related technologies, when an operation such as disabling an interrupt occurs in the vehicle-mounted real-time system, the heartbeat signal is interrupted, preventing the vehicle-mounted real-time system from responding to the heartbeat signal. This results in a clock deviation between the heartbeat signal transmission time of the vehicle-mounted real-time system and the standard parameter time (physical time). Figure 1 As shown, in Figure 1 When timer trigger point 3 in the system is disabled, timer trigger points 4 and 5 will show clock deviations from physical time 4 and physical time 5, respectively.
[0038] To address the aforementioned technical problems, this application proposes determining a time compensation amount based on the actual trigger time and the standard trigger time of the heartbeat signal; adjusting the heartbeat trigger cycle based on the time compensation amount; that is, synchronizing the actual trigger time of the vehicle-mounted real-time system with the standard trigger time by adjusting the heartbeat trigger cycle. Figure 2 As shown, in Figure 2The interval between timer trigger points 1 and 2 is one cycle; the interval between timer trigger points 2 and 3 is one cycle; the interval between timer trigger points 3 and 4 is one cycle; and the interval between timer trigger points 4 and 5 is one cycle. The cycle between timer trigger points 2 and 3 is inconsistent with the standard cycle corresponding to the standard trigger time, indicating that an interrupt occurred at timer trigger point 3. This leads to a desynchronization between subsequent trigger points and physical time. To solve this problem, this application adjusts the heartbeat trigger cycle and time compensation amount to... Figure 2 After the interruption occurs at timer trigger point 3, timer trigger points 4 and 5 are synchronized with physical time 4 and physical time 5, respectively. That is, the time compensation between timer trigger point 4 and physical time point 4 is calculated, and the heartbeat trigger cycle between timer trigger point 3 and timer trigger point 4 is adjusted according to the time compensation.
[0039] refer to Figure 3 The flowchart of the time compensation method provided in the embodiment of this application is shown, which specifically includes:
[0040] Step 301: Determine the time compensation amount based on the actual trigger time of the heartbeat signal and the standard trigger time of the heartbeat signal.
[0041] In practical applications, this time compensation method can be applied to various systems, preferably to in-vehicle real-time systems. The following uses an in-vehicle real-time system as an example to explain the time compensation method of this application in detail.
[0042] In practical applications, the timer of the vehicle-mounted real-time system periodically sends heartbeat signals to monitor its operating status. When the heartbeat signal is interrupted, the system cannot respond. Therefore, it is necessary to obtain both the actual trigger time and the standard trigger time of the heartbeat signal. The standard trigger time is the physical time at which the heartbeat signal is triggered, which is used to determine the time compensation amount. In practice, the time compensation amount Δt is determined based on the difference between the actual and standard trigger times. This time compensation is an adjustment value introduced to correct deviations in the vehicle-mounted real-time system. This time compensation amount is stored in a scrollable buffer for easy analysis later.
[0043] In practical applications, a moving average algorithm or an exponentially weighted moving average algorithm can be used to filter the time compensation amount in the buffer to eliminate the interference of occasional jitter on the time compensation amount. By analyzing the filtered time compensation amount, a smoother time compensation amount trend can be obtained. Based on the time compensation amount trend, the heartbeat stability of the vehicle real-time system can be determined, which can be used to optimize the interrupt handling process of the vehicle real-time system.
[0044] Step 302: Adjust the heartbeat triggering cycle according to the time compensation amount.
[0045] The next heartbeat trigger cycle is adjusted based on the time compensation amount, either by shortening or lengthening it. This time compensation ensures that the actual trigger time of the vehicle-mounted real-time system is synchronized with the standard trigger time. The time compensation corrects the deviation between the actual and standard trigger times, thus synchronizing the trigger time with the standard reference time.
[0046] In practical applications, the range of time compensation can also be limited by a decision threshold, that is, the adjustment range of time compensation can be limited by a decision threshold, thereby avoiding the instability of the heartbeat of the vehicle real-time system. The decision threshold is used to determine whether the heartbeat of the vehicle real-time system is normal.
[0047] Among them, the decision thresholds include: the upper limit threshold and the lower limit threshold.
[0048] The core idea of limiting the range of time compensation through decision thresholds is to restrict the adjustment range of compensation when the detected time compensation exceeds or falls below a set threshold, thus preventing drastic fluctuations in the system's heartbeat due to extreme deviations. The specific process is as follows:
[0049] Set an upper threshold (maximum allowable compensation), a lower threshold (minimum allowable compensation), and a time compensation range. This means that compensation is required if the time compensation exceeds the upper threshold or falls below the lower threshold. The time compensation range represents the maximum adjustment range for the compensation amount.
[0050] Determine whether the time compensation amount exceeds the decision threshold. If the time compensation amount exceeds the decision threshold range, then the decision threshold is used as the time compensation amount. That is, determine whether the time compensation amount exceeds the upper decision threshold. If it does, the upper decision threshold is used as the time compensation amount. Alternatively, determine whether the time compensation amount exceeds the lower decision threshold. If it does, the lower decision threshold is used as the time compensation amount.
[0051] The heartbeat signal correction of the vehicle-mounted real-time system in this application mainly corrects the sending and receiving time of the heartbeat signal to ensure the periodicity and accuracy of the heartbeat signal, thereby ensuring that the task time on the vehicle-mounted real-time system scheduling and software timer is synchronized with the set physical time. In contrast, the system time correction mainly corrects the system's time base to ensure that the system time is synchronized with the physical time. The two are fundamentally different.
[0052] In this embodiment, the time compensation amount is determined based on the actual trigger time and the standard trigger time of the heartbeat signal; the heartbeat trigger cycle is dynamically adjusted according to the time compensation amount, that is, by adjusting the heartbeat trigger cycle, the actual trigger time of the vehicle real-time system is synchronized with the standard trigger time, which can improve the safety of vehicle driving.
[0053] refer to Figure 4 The flowchart of a time compensation method provided in an embodiment of this application is shown, which specifically includes:
[0054] Step 401: Determine the time compensation amount based on the actual trigger time of the heartbeat signal and the standard trigger time of the heartbeat signal.
[0055] In practical applications, the actual trigger time is determined based on the interruption of the heartbeat signal. That is, the actual trigger time is obtained when the heartbeat signal is interrupted. Then, the time compensation amount of each heartbeat signal is obtained by subtracting the actual trigger time of each heartbeat signal from the standard trigger time of each heartbeat signal.
[0056] exist Figure 2 For example, the standard period of a heartbeat signal is T = 100ms, and the standard trigger times corresponding to the timer trigger points 1-5 of the heartbeat signal are 0ms, 100ms, 200ms, 300ms, and 400ms, respectively.
[0057] Heartbeat 1: Standard trigger time: 0ms, actual trigger time: 0ms, time compensation: 0-0=0ms, normal trigger without deviation.
[0058] Heartbeat 2: Standard trigger time: 100ms, actual trigger time: 100ms, time compensation: 0-0=0ms, normal trigger without deviation.
[0059] Heartbeat 3: Standard trigger time: 200ms, actual trigger time: 230ms, time compensation: 230-200=30ms. It is necessary to compensate for the actual trigger time of subsequent heartbeat signals in order to adjust the heartbeat trigger cycle.
[0060] Heartbeat 4: Standard trigger time: 300ms. If the actual trigger time of heartbeat 3 is used to calculate the standard period, the actual trigger time will be 330ms. This will cause the actual trigger time to be inconsistent with the standard trigger time, resulting in error accumulation. However, by using the time compensation amount obtained above to adjust the heartbeat trigger period after heartbeat 3, the heartbeat trigger period becomes 70ms, so that the actual trigger time of heartbeat 4 is 300ms, thus ensuring that the actual trigger time is consistent with the standard trigger time.
[0061] Heartbeat 5: Standard trigger time: 400ms. Since the heartbeat trigger cycle was adjusted once before heartbeat 4, and the subsequent cycle has been restored to the standard cycle, the actual trigger time of heartbeat 5 can be determined to be 400ms based on the actual trigger time of heartbeat 4 using the standard cycle.
[0062] Step 402: Determine whether the time compensation amount is greater than zero. If the time compensation amount is greater than zero, proceed to step 403. If the time compensation amount is less than zero, proceed to step 404.
[0063] Step 403: Shorten the next heartbeat trigger cycle.
[0064] Step 404: Extend the next heartbeat trigger cycle.
[0065] The system determines whether the time compensation amount is greater than zero. If the time compensation amount is greater than zero, it means that the time compensation amount is positive, and the next heartbeat trigger cycle is shortened. If the time compensation amount is less than zero, it means that the time compensation amount is negative, and the next heartbeat trigger cycle is extended. By dynamically adjusting the heartbeat trigger cycle, it can be ensured that the adjustment process will not interfere with the processing tasks of the vehicle real-time system.
[0066] The heartbeat trigger cycle is determined based on the standard heartbeat cycle and the time compensation amount. That is, after a heartbeat is triggered, the trigger cycle for the next heartbeat is dynamically updated through the timer interface. The heartbeat trigger interval is calculated using the following formula:
[0067] Tnext = Tdefault - B, where Tnext is the next heartbeat trigger cycle, Tdefault is the standard heartbeat cycle, and B is the time compensation amount.
[0068] by Figure 5For example, the inconsistency between the period between timer trigger point 2 and timer trigger point 3 and the standard trigger time indicates that timer trigger point 3 has experienced interruption or clock source inaccuracy, resulting in subsequent trigger points being out of sync with physical time. Therefore, by adjusting the heartbeat trigger period, the actual trigger time of the vehicle real-time system is made consistent with the standard trigger time. For example, if the standard period of the heartbeat signal is T = 100ms, the standard trigger times corresponding to timer trigger points 1-5 of the heartbeat signal are 0ms, 100ms, 200ms, 300ms, and 400ms, respectively.
[0069] Heartbeat 1: Standard trigger time: 0ms, actual trigger time: 0ms, time compensation: 0-0=0ms, normal trigger without deviation.
[0070] Heartbeat 2: Standard trigger time: 100ms, actual trigger time: 100ms, time compensation: 0-0=0ms, normal trigger without deviation.
[0071] Heartbeat 3: Standard trigger time: 200ms, actual trigger time: 170ms, time compensation: 170-200=-30ms. It is necessary to compensate for the actual trigger time of subsequent heartbeat signals in order to adjust the heartbeat trigger cycle.
[0072] The heartbeat trigger period Tnext (new period) = 100ms - (-30ms) = 130ms, that is, the heartbeat trigger period is 130ms.
[0073] Heartbeat 4: Standard trigger time: 300ms. If the actual trigger time of heartbeat 3 is used to calculate the standard period, the actual trigger time would be 270ms. This would cause the actual trigger time to be inconsistent with the standard trigger time, resulting in accumulated errors. However, by using the time compensation amount obtained earlier, the heartbeat trigger period after heartbeat 3 is adjusted to 130ms, making the actual trigger time of heartbeat 4 300ms, thus ensuring that the actual trigger time is consistent with the standard trigger time. The actual trigger time becomes 170 + 130 = 300ms, aligned with the original plan.
[0074] Heartbeat 5: Standard trigger time: 400ms. Since the heartbeat trigger cycle was adjusted once before heartbeat 4, and the subsequent cycle has been restored to the standard cycle, the actual trigger time of heartbeat 5 can be determined to be 400ms based on the actual trigger time of heartbeat 4 using the standard cycle.
[0075] If the period between timer trigger point 4 and timer trigger point 5 is inconsistent with the standard period corresponding to the standard trigger time, it indicates that timer trigger point 5 has an interrupt disabled or an inaccurate clock source, causing a problem of subsequent trigger points being out of sync with physical time. In this case, continue to correct subsequent trigger points in the manner described above:
[0076] Heartbeat 5: Standard trigger time: 400ms, actual trigger time: 360ms, time compensation: 360-400=-40ms. It is necessary to compensate for the actual trigger time of subsequent heartbeat signals in order to complete the adjustment of the heartbeat trigger cycle.
[0077] The heartbeat trigger period Tnext (new period) = 100ms - (-40ms) = 140ms, that is, the heartbeat trigger period is 140ms. The subsequent trigger points are aligned with the original plan by adjusting the heartbeat trigger period.
[0078] Step 405: Based on the time compensation amount, synchronize the trigger time of the vehicle real-time system with the standard reference time.
[0079] Based on the time compensation amount, negative or positive compensation can be applied to the vehicle real-time system. Through the aforementioned negative or positive compensation, the actual trigger time of the vehicle real-time system can be synchronized with the standard trigger time.
[0080] After adjusting the heartbeat trigger cycle, the subsequent cycle in which the heartbeat signal is located is restored to the standard cycle of the actual trigger time of the heartbeat signal.
[0081] In this embodiment, based on the time compensation amount, the actual trigger time of the vehicle real-time system is synchronized with the standard trigger time. That is, the heartbeat timing of the vehicle real-time system is accurately compensated, which greatly reduces the accumulation of clock deviation caused by interruption delay and ensures the scheduling accuracy and real-time performance of the system.
[0082] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to this application.
[0083] Based on the description of the above method embodiments, this application also provides corresponding device embodiments to implement the content described in the above method embodiments.
[0084] Reference Figure 6It shows a structural diagram of a time compensation device according to an embodiment of this application, including:
[0085] The time compensation module 601 is used to determine the time compensation amount based on the actual trigger time of the heartbeat signal and the standard trigger time of the heartbeat signal.
[0086] The adjustment module 602 is used to adjust the heartbeat triggering cycle according to the time compensation amount.
[0087] Optionally, the device further includes: a recovery module;
[0088] The recovery module is used to restore the subsequent period in which the heartbeat signal is located to the standard period of the actual trigger time of the heartbeat signal after adjusting the heartbeat trigger period once.
[0089] Optionally, the adjustment module includes:
[0090] The judgment unit is used to determine whether the time compensation amount is greater than zero;
[0091] A shortened interval time unit is used to shorten the next heartbeat trigger cycle if the time compensation amount is greater than zero.
[0092] Optionally, the adjustment module includes:
[0093] The judgment unit is also used to determine whether the time compensation amount is less than zero;
[0094] An interval time unit is added to extend the next heartbeat triggering cycle if the time compensation amount is less than zero.
[0095] Optionally, the heartbeat triggering period is determined based on the standard heartbeat period and the time compensation amount.
[0096] This application determines the time compensation amount based on the actual trigger time and the standard trigger time of the heartbeat signal; and dynamically adjusts the heartbeat trigger cycle based on the time compensation amount. That is, by adjusting the heartbeat trigger cycle, the actual trigger time of the vehicle real-time system is synchronized with the standard trigger time, thereby improving the safety of vehicle driving.
[0097] The above-described apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple. For relevant details, please refer to the description of the method embodiments shown.
[0098] This invention also provides an electronic device, comprising:
[0099] A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the aforementioned time compensation method.
[0100] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned time compensation method.
[0101] Optionally, the computer-readable storage medium may be a non-transitory computer-readable storage medium, such as a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device. The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably.
[0102] It will be readily apparent to those skilled in the art that any combination of the above embodiments is feasible, and therefore any combination of the above embodiments constitutes an implementation of the present invention. However, due to space limitations, each embodiment will not be described in detail here. Although preferred embodiments of the present invention have been described, those skilled in the art, once they understand the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the present invention.
[0103] The present invention has provided a detailed description of a time compensation method, apparatus, device, and medium. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A time compensation method, characterized in that, include: The time compensation amount is determined based on the actual trigger time of the heartbeat signal and the standard trigger time of the heartbeat signal. Adjust the heartbeat trigger cycle according to the time compensation amount.
2. The method according to claim 1, characterized in that, The method further includes: after adjusting the heartbeat trigger cycle once, the subsequent cycle in which the heartbeat signal is located is restored to the standard cycle.
3. The method according to claim 1, characterized in that, The adjustment of the heartbeat triggering period based on the time compensation amount includes: Determine whether the time compensation amount is greater than zero; If the time compensation is greater than zero, the next heartbeat trigger cycle will be shortened.
4. The method according to claim 1, characterized in that, The adjustment of the heartbeat triggering period based on the time compensation amount includes: Determine whether the time compensation amount is less than zero; If the time compensation is less than zero, the next heartbeat triggering cycle will be extended.
5. The method according to any one of claims 3-4, characterized in that, The heartbeat triggering cycle is determined based on the standard heartbeat cycle and the time compensation amount.
6. A time compensation device, characterized in that, include: The time compensation module is used to determine the time compensation amount based on the actual trigger time of the heartbeat signal and the standard trigger time of the heartbeat signal. The adjustment module is used to adjust the heartbeat triggering cycle according to the time compensation amount.
7. The apparatus according to claim 6, characterized in that, The device further includes: a recovery module; The recovery module is used to restore the subsequent cycle in which the heartbeat signal is located to the standard cycle after adjusting the heartbeat trigger cycle once.
8. The apparatus according to claim 6, characterized in that, The adjustment module includes: The judgment unit is used to determine whether the time compensation amount is greater than zero; A shortened interval time unit is used to shorten the next heartbeat trigger cycle if the time compensation amount is greater than zero.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements a time compensation method according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements a time compensation method according to any one of claims 1 to 6.