A clock offset correction method and a clock loss detection method

By calculating and adjusting the clock interrupt interval in the clock interrupt handler, the problems of clock offset and loss in civil aviation aircraft systems are solved, real-time correction and fault detection are achieved, and the time certainty and reliability of the system are improved.

CN119882933BActive Publication Date: 2025-10-21XIAN AVIATION COMPUTING TECH RES INST OF AVIATION IND CORP OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411957016.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-29
Publication Date
2025-10-21
Estimated Expiration
2044-12-29

AI Technical Summary

Technical Problem

The onboard systems and equipment of civil aircraft are prone to clock offset or loss due to long-term shutdown or other reasons, affecting the time determinism of the operating system. Clock loss is usually not directly perceived, resulting in silent failures.

Method used

By calculating the expected next clock interrupt time point in the clock interrupt handler, adjusting the clock interrupt interval to correct the offset, and detecting clock loss based on the time difference, global variables and clock interrupt cycles are used for periodic processing to achieve clock offset correction and loss detection.

Benefits of technology

It realizes real-time correction of clock offset, improves system time certainty, and promptly detects clock loss failures, thus improving system reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119882933B_ABST
    Figure CN119882933B_ABST
Patent Text Reader

Abstract

The present application belongs to the technical field of computer system software, and particularly relates to a clock offset correction method and a clock loss detection method, which are applied to an embedded real-time operating system. In a clock interrupt processing program, an expected next clock interrupt processing time point is calculated, a difference between a current clock interrupt processing time point and the expected next clock interrupt processing time point is calculated, and the next clock interrupt triggering time point is adjusted according to the difference to complete clock offset correction. Meanwhile, whether clock loss occurs is judged according to the difference between the expected time and the current actual time. The method solves the problems of clock offset correction and clock loss detection in the running process of the embedded real-time operating system, and improves the time determinacy of the real-time operating system running.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of computer system software, and in particular relates to a clock offset correction method and a clock loss detection method. Background Art

[0002] Civil aircraft have extremely high safety requirements for onboard systems and equipment, including the time determinism of software running on these systems and devices. For example, IMA systems require that resident application partitions strictly adhere to the absolute time windows configured in the time schedule. However, during system operation, clock interrupts may not be captured in a timely manner due to factors such as long interrupt disabling, resulting in clock skew or even clock loss. This prevents the operating system from scheduling partitions or tasks according to the correct time, affecting the time determinism of application software.

[0003] Typically, a clock interrupt relies on a count in a specific register. When the count meets a certain condition, such as when it decrements to 0, a clock interrupt is triggered. The register value determines the next clock interrupt interval. You can correct clock skew by setting the register value.

[0004] Typically, when clock loss occurs, the operating system and application software are unaware of it, resulting in silent failures. Therefore, the operating system needs to promptly detect clock loss failures and report them to the user, allowing them to troubleshoot and resolve the issue promptly. Summary of the Invention

[0005] In light of this, the present invention provides a clock offset correction method and a clock loss detection method, providing both clock offset correction and clock loss detection capabilities. During the clock interrupt processing process, the clock interrupt interval is calculated and corrected to achieve clock offset correction. Furthermore, clock loss failures are detected based on the difference between the expected time and the actual time.

[0006] The technical solution of the present invention:

[0007] A clock offset correction method and a clock loss detection method are applied to embedded real-time operating systems;

[0008] The clock offset correction method includes:

[0009] When a clock interrupt occurs, the expected next clock interrupt processing time point is calculated in the clock interrupt processing program, and the difference between the current clock interrupt processing time point and the expected next clock interrupt processing time point is calculated. The next clock interrupt triggering time point is adjusted according to the difference to complete the clock offset correction;

[0010] The clock loss detection method comprises:

[0011] Based on the difference between the expected time and the current actual time, it is determined whether clock loss has occurred before the current clock interrupt processing.

[0012] Furthermore, when the clock interrupt is initialized, a global variable is defined to save the expected first clock interrupt triggering time point. The calculation method of the first clock interrupt triggering time point is: calculate the clock interrupt period according to the system clock frequency, add the current timestamp and the clock interrupt period as the initial value of the global variable, and the initial value is used as the expected first clock interrupt processing time point.

[0013] Furthermore, the clock offset correction method periodically processes the clock interrupt of the embedded real-time operating system, specifically:

[0014] In a clock interrupt processing: the global variable is accumulated with the clock interrupt period until it is not less than the current timestamp; at this time, the global variable is updated to the expected next clock interrupt trigger time point, and the interval time from the current time to the expected next clock interrupt trigger time point is calculated, and the value of the clock interrupt counter is adjusted according to the interval time value to complete the correction of the clock offset.

[0015] Furthermore, the method for determining whether clock loss has occurred is as follows:

[0016] If the number of times the global variable increases by the clock interrupt cycle is greater than 1 during this clock interrupt processing, it means that the current actual time differs from the expected time by more than one clock interrupt cycle, and a clock loss fault is determined to have occurred.

[0017] Furthermore, when the embedded real-time operating system is initialized, the clock interrupt handler is attached to the clock interrupt. After the clock interrupt is triggered, the processor running the embedded real-time operating system enters the clock interrupt handler when the clock interrupt is enabled.

[0018] Furthermore, the counter is a specific register that the clock interrupt depends on, and when the count in the register is decremented to 0, the clock interrupt is triggered.

[0019] Furthermore, the processing flow of the clock offset correction method and the clock loss detection method is as follows:

[0020] S101: When the operating system clock interrupt is initialized, define the first global variable to save the expected next clock interrupt trigger time point; calculate the clock interrupt period according to the system clock frequency, add the current timestamp and the clock interrupt period as the initial value of the global variable; set the clock interrupt counter according to the clock interrupt period;

[0021] S102: Hardware triggers a clock interrupt;

[0022] S103: In the clock interrupt processing program, add the clock interrupt period to the global variable and record the number of times the clock interrupt period is increased.

[0023] S104: Obtain the timestamp of the current clock interrupt processing and compare the updated global variable with the current timestamp;

[0024] If the updated global variable is less than the current timestamp, return to S103;

[0025] If the updated global variable is not less than the current timestamp, the difference between the global variable and the current timestamp is calculated, and the difference is used as the corrected clock interrupt interval time;

[0026] S105: Setting a clock interruption counter according to the corrected clock interruption interval to complete the current clock offset correction;

[0027] S106: Determine whether the recorded number of increased clock interruption cycles is greater than 1;

[0028] If it is greater than 1, it means that clock loss has occurred. The number of times minus 1 is the number of clocks lost. In this case, the corresponding fault handling is performed;

[0029] If it is not greater than 1, it means that no clock loss has occurred and this processing is completed.

[0030] Beneficial effects of the present invention:

[0031] After the detection method of the present invention is implemented, the clock offset can be corrected in real time, the system time certainty can be improved, and the clock loss fault can be detected in time, thereby improving the reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0033] Figure 1 Schematic diagram for clock offset correction and clock loss detection;

[0034] Figure 2 Flowchart for clock offset correction and clock loss detection. DETAILED DESCRIPTION

[0035] The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.

[0036] The following describes the embodiments of the present disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments can be combined with each other. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present disclosure.

[0037] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein can be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on this disclosure, it should be understood by those skilled in the art that an aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects described herein can be used to implement an apparatus and / or practice a method. In addition, other structures and / or functionalities other than one or more of the aspects described herein can be used to implement this apparatus and / or practice this method.

[0038] It should also be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present disclosure. The illustrations only show components related to the present disclosure and are not drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component can be changed at will, and the component layout type may also be more complicated.

[0039] Additionally, in the following description, specific details are provided to provide a thorough understanding of the examples. However, one skilled in the art will appreciate that the aspects described can be practiced without these specific details.

[0040] In one embodiment of the present invention, a clock offset correction method and a clock loss detection method are provided for embedded real-time operating systems; Figure 1-Figure 2 ,

[0041] The clock offset correction method includes:

[0042] When a clock interrupt occurs, the expected next clock interrupt processing time point is calculated in the clock interrupt processing program, and the difference between the current clock interrupt processing time point and the expected next clock interrupt processing time point is calculated. The next clock interrupt triggering time point is adjusted according to the difference to complete the clock offset correction;

[0043] The clock loss detection method comprises:

[0044] Based on the difference between the expected time and the current actual time, it is determined whether clock loss has occurred before the current clock interrupt processing.

[0045] In this embodiment, when the clock interrupt is initialized, a global variable is defined to save the expected first clock interrupt triggering time point. The calculation method of the first clock interrupt triggering time point is: calculate the clock interrupt period according to the system clock frequency, add the current timestamp and the clock interrupt period as the initial value of the global variable, and the initial value is used as the expected first clock interrupt processing time point.

[0046] In this embodiment, the clock offset correction method periodically processes the clock interrupt of the embedded real-time operating system, specifically:

[0047] In a clock interrupt processing: the global variable is accumulated with the clock interrupt period until it is not less than the current timestamp; at this time, the global variable is updated to the expected next clock interrupt trigger time point, and the interval time from the current time to the expected next clock interrupt trigger time point is calculated, and the value of the clock interrupt counter is adjusted according to the interval time value to complete the correction of the clock offset.

[0048] In this embodiment, the method for determining whether clock loss has occurred is specifically as follows:

[0049] If the number of times the global variable increases by the clock interrupt cycle is greater than 1 during this clock interrupt processing, it means that the current actual time differs from the expected time by more than one clock interrupt cycle, and a clock loss fault is determined to have occurred.

[0050] In this embodiment, when the embedded real-time operating system is initialized, the clock interrupt handler is attached to the clock interrupt. After the clock interrupt is triggered, the processor running the embedded real-time operating system enters the clock interrupt handler when the clock interrupt is enabled.

[0051] In this embodiment, the counter is a specific register that the clock interrupt relies on, and when the count in the register is decremented to 0, the clock interrupt is triggered.

[0052] In this embodiment, the processing flow of the clock offset correction method and the clock loss detection method is as follows:

[0053] S101: When the operating system clock interrupt is initialized, define the first global variable to save the expected next clock interrupt trigger time point; calculate the clock interrupt period according to the system clock frequency, add the current timestamp and the clock interrupt period as the initial value of the global variable; set the clock interrupt counter according to the clock interrupt period;

[0054] S102: Hardware triggers a clock interrupt;

[0055] S103: In the clock interrupt processing program, add the clock interrupt period to the global variable and record the number of times the clock interrupt period is increased.

[0056] S104: Obtain the timestamp of the current clock interrupt processing and compare the updated global variable with the current timestamp;

[0057] If the updated global variable is less than the current timestamp, return to S103;

[0058] If the updated global variable is not less than the current timestamp, the difference between the global variable and the current timestamp is calculated, and the difference is used as the corrected clock interrupt interval time;

[0059] S105: Setting a clock interruption counter according to the corrected clock interruption interval to complete the current clock offset correction;

[0060] S106: Determine whether the recorded number of increased clock interruption cycles is greater than 1;

[0061] If it is greater than 1, it means that clock loss has occurred. The number of times minus 1 is the number of clocks lost. In this case, the corresponding fault handling is performed;

[0062] If it is not greater than 1, it means that no clock loss has occurred and this processing is completed.

[0063] Figure 1 This is a schematic diagram of the clock offset correction and clock loss detection principle of this embodiment. By calculating the expected next clock interrupt trigger time point and comparing it with the current timestamp, the corrected clock interrupt interval time and the number of clock losses are calculated.

[0064] In this embodiment, when the operating system clock interrupt is initialized, a global variable is defined to store the expected first clock interrupt triggering time point, the clock interrupt period is calculated based on the system clock frequency, the current timestamp is added to the clock interrupt period to serve as the initial value of the global variable, and a clock interrupt counter is set according to the clock interrupt period;

[0065] In this embodiment, when entering the clock interrupt handler, the clock interrupt period is first added to the global variable and then compared with the current timestamp:

[0066] If the former is not less than the latter, the value of the global variable is the expected next clock interrupt processing time, and the difference between it and the current timestamp is the corrected clock interrupt interval time;

[0067] If the former is less than the latter, the clock interrupt period is continued to be increased for the global variable until the value of the global variable is no less than the current timestamp. At this time, the value of the global variable is the expected next clock interrupt processing time, and the difference between it and the current timestamp is the corrected clock interrupt interval.

[0068] In this embodiment, a clock interruption counter is set according to the corrected clock interruption interval time, thereby completing the current clock offset correction.

[0069] In this embodiment, the number of times the clock interrupt cycle is added to the global variable during the current clock interrupt processing is determined. If the number is greater than 1, it indicates that clock loss has occurred, and the number minus 1 is the number of lost clocks. Otherwise, it indicates that no clock loss failure has occurred.

[0070] Figure 2 This is a flowchart of the operating system clock offset correction and clock loss detection in this embodiment, as shown in FIG. Figure 2 As shown, the method flow provided in this embodiment is as follows:

[0071] ①_x0001_ When the operating system clock interrupt is initialized, the first global variable is defined to store the expected time point of the next clock interrupt trigger. The clock interrupt period is calculated based on the system clock frequency, and the current timestamp is added to the clock interrupt period to be used as the initial value of the global variable. The clock interrupt counter is set according to the clock interrupt period;

[0072] ②_x0001_Hardware triggers a clock interrupt;

[0073] ③_x0001_In the clock interrupt handler, add the clock interrupt cycle to the global variable and record the number of times the clock interrupt cycle is increased;

[0074] ④_x0001_Get the timestamp of the current clock interrupt processing and compare the updated global variable with the current timestamp;

[0075] ⑤_x0001_If the updated global variable is less than the current timestamp, return to step 3;

[0076] ⑥_x0001_If the updated global variable is not less than the current timestamp, the difference between the global variable and the current timestamp is calculated, and the difference is the corrected clock interrupt interval time;

[0077] ⑦_x0001_ sets the clock interrupt counter according to the corrected clock interrupt interval time, thereby completing this clock offset correction;

[0078] ⑧_x0001_ Determine whether the recorded number of increased clock interrupt cycles is greater than 1;

[0079] ⑨_x0001_ If it is greater than 1, it means that clock loss has occurred. The number of times minus 1 is the number of clocks lost. In this case, the corresponding fault processing is performed;

[0080] ⑩_x0001_ If it is not greater than 1, it means that no clock loss has occurred and this processing is completed.

[0081] The above description is merely a specific embodiment of the present disclosure, but the scope of protection of the present disclosure is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this disclosure should be included in the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure should be based on the scope of protection of the claims.

Claims

1. A clock offset correction method and a clock loss detection method, characterized in that: Applied to embedded real-time operating systems; The clock offset correction method includes: When a clock interrupt occurs, the expected next clock interrupt processing time point is calculated in the clock interrupt processing program, and the difference between the current clock interrupt processing time point and the expected next clock interrupt processing time point is calculated. The next clock interrupt triggering time point is adjusted according to the difference to complete the clock offset correction; The clock loss detection method comprises: Based on the difference between the expected time and the current actual time, determine whether clock loss occurred before the current clock interrupt processing; The processing flow of the clock offset correction method and the clock loss detection method is as follows: S101: When the operating system clock interrupt is initialized, define the first global variable to save the expected next clock interrupt trigger time point; calculate the clock interrupt period according to the system clock frequency, add the current timestamp and the clock interrupt period as the initial value of the global variable; set the clock interrupt counter according to the clock interrupt period; S102: Hardware triggers a clock interrupt; S103: In the clock interrupt processing program, add the clock interrupt period to the global variable and record the number of times the clock interrupt period is increased. S104: Obtain the timestamp of the current clock interrupt processing and compare the updated global variable with the current timestamp; If the updated global variable is less than the current timestamp, return to S103; If the updated global variable is not less than the current timestamp, the difference between the global variable and the current timestamp is calculated, and the difference is used as the corrected clock interrupt interval time; S105: Setting a clock interruption counter according to the corrected clock interruption interval to complete the current clock offset correction; S106: Determine whether the recorded number of increased clock interruption cycles is greater than 1; If it is greater than 1, it means that clock loss has occurred. The number of times minus 1 is the number of clocks lost. In this case, the corresponding fault handling is performed; If it is not greater than 1, it means that no clock loss has occurred and this processing is completed.

2. The clock offset correction method and clock loss detection method according to claim 1, characterized in that: When the clock interrupt is initialized, a global variable is defined to save the expected first clock interrupt triggering time point. The calculation method of the first clock interrupt triggering time point is: calculate the clock interrupt period according to the system clock frequency, add the current timestamp and the clock interrupt period as the initial value of the global variable, and the initial value is used as the expected first clock interrupt processing time point.

3. The clock offset correction method and clock loss detection method according to claim 2, characterized in that: The clock offset correction method periodically processes the clock interrupt of the embedded real-time operating system, specifically: In a clock interrupt processing: the clock interrupt period is accumulated on the global variable until it is not less than the current timestamp; At this time, the global variable is updated to the expected next clock interrupt trigger time point, and the interval time from the current time to the expected next clock interrupt trigger time point is calculated. The value of the clock interrupt counter is adjusted according to the interval time value to complete the correction of clock offset.

4. The clock offset correction method and clock loss detection method according to claim 3, characterized in that: The method for determining whether clock loss has occurred is as follows: If the number of times the global variable increases by the clock interrupt cycle is greater than 1 during this clock interrupt processing, it means that the current actual time differs from the expected time by more than one clock interrupt cycle, and a clock loss fault is determined to have occurred.

5. The clock offset correction method and clock loss detection method according to claim 4, characterized in that: When the embedded real-time operating system is initialized, the clock interrupt processing program is hooked to the clock interrupt. After the clock interrupt is triggered, the processor running the embedded real-time operating system enters the clock interrupt processing program when the clock interrupt is enabled.

6. The clock offset correction method and clock loss detection method according to claim 5, characterized in that: The counter is a specific register that the clock interrupt depends on. When the count in the register is decremented to 0, the clock interrupt is triggered.

Citation Information

Patent Citations

  • Method and device for measuring system manager interrupt time

    CN107423206A

  • Clock tick processing and maintaining method for multiple processor cores

    CN115686902A