Cooperative cycle control method and device for non-real-time operating system and real-time operating system
By employing a combined hardware and software periodic synchronization mechanism, the timing synchronization and data consistency issues between non-real-time operating systems and real-time operating systems are resolved, thereby improving the reliability and stability of complex control systems. This technology is applicable to fields such as industrial automation and intelligent driving.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANJING NRIET IND CORP
- Filing Date
- 2025-12-22
- Publication Date
- 2026-04-10
AI Technical Summary
In complex control systems, the collaborative control between non-real-time operating systems and real-time operating systems faces challenges such as timing synchronization difficulties, data consistency risks, and a lack of anomaly handling mechanisms, leading to reduced system reliability.
Through a hardware and software combined periodic synchronization mechanism, the non-real-time operating system calculates the target control cycle based on the system real-time clock and generates periodic interrupt signals through a hardware timer. The real-time operating system records the cycle start time and length, performs cycle identification comparison and exception handling, and ensures the integrity and consistency of data transmission.
It achieves timing consistency and data reliability in hybrid control systems, reduces the probability of system failure, adapts to complex control scenarios with load changes, and improves system stability and fault tolerance.
Smart Images

Figure CN121833172A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer operating system technology, and specifically to a method and apparatus for coordinated cycle control of a non-real-time operating system and a real-time operating system. Background Technology
[0002] In complex control systems, non-real-time operating systems (such as Linux and Windows) and real-time operating systems (such as VxWorks and FreeRTOS) are often deployed simultaneously. Non-real-time operating systems possess powerful management capabilities and a rich application ecosystem, but their task scheduling is unpredictable and cannot guarantee strict timing requirements. Real-time operating systems, on the other hand, can achieve precise task scheduling through hardware interrupt mechanisms, but lack advanced service support, such as file systems and network protocol stacks.
[0003] In existing technologies, the coordinated control of the two types of systems faces the following problems: 1) Difficulty in timing synchronization. The non-real-time system calculates the cycle based on a software clock, while the real-time system controls the cycle based on hardware interrupts. The asynchrony of their clock sources leads to cycle deviations; 2) Data consistency risks. When the non-real-time system experiences processing delays, the real-time system may use outdated data, causing control logic errors; 3) Lack of anomaly handling mechanisms: Existing solutions do not effectively handle cycle out-of-synchronization scenarios, resulting in reduced system reliability. For example, in an industrial robot control system, when the cycle of motion commands sent by the host computer (non-real-time system) is inconsistent with the execution cycle of the slave computer (real-time system), it may cause robot motion stuttering or trajectory deviation. Therefore, there is an urgent need for a control method that can achieve precise cycle coordination between the two types of systems. Summary of the Invention
[0004] In view of the shortcomings of the existing technology, the purpose of this invention is to provide a collaborative periodic control method and device for non-real-time operating systems and real-time operating systems. Through a periodic synchronization mechanism combining software and hardware, the invention solves the problems of timing inconsistency and data asynchrony in the existing technology, thereby improving the reliability and stability of the hybrid control system.
[0005] The technical solution disclosed in this invention is: a collaborative cycle control method between a non-real-time operating system and a real-time operating system, comprising: the non-real-time operating system calculating a target control cycle based on the system real-time clock, and setting a cycle start time and cycle length; the non-real-time operating system sending the cycle start time and cycle length to the real-time operating system; the real-time operating system generating a periodic interrupt signal based on a hardware timer, and controlling the execution of the local cycle based on the interrupt signal; the real-time operating system recording the received cycle start time and cycle length, and maintaining an expected cycle identifier of the non-real-time operating system processing result to be received in the current cycle; when the real-time operating system receives the processing result of the non-real-time operating system, comparing the cycle identifier carried in the result with the expected cycle identifier, and triggering a preset exception handling process if they are inconsistent.
[0006] Furthermore, the non-real-time operating system calculates the target control cycle based on the system's real-time clock, including: the non-real-time operating system obtaining the current system time as a reference point; calculating the starting time of the next cycle according to preset task scheduling rules, wherein the starting time is the first integer multiple timestamp after the reference point; and dynamically adjusting the cycle length according to system load and task priority to generate variable cycle parameters.
[0007] Furthermore, the real-time operating system generates periodic interrupt signals based on a hardware timer, including: configuring the interrupt trigger frequency of the hardware timer so that the interrupt period is an integer proportional relationship with the period length sent by the non-real-time operating system; and updating the local period counter and the expected period identifier of the real-time operating system when each hardware interrupt is triggered.
[0008] Furthermore, the exception handling process includes: when the period identifier of the received result is earlier than the expected period identifier, discarding the current result and maintaining the current period execution; when the period identifier of the received result is later than the expected period identifier, triggering the period synchronization mechanism, recalculating the current period parameters based on the latest result; recording period exception events, and generating log information containing timestamps and period deviation values.
[0009] Furthermore, the non-real-time operating system and the real-time operating system transmit data through shared memory or message queues. The transmitted content includes: cycle start time, cycle length, and cycle identifier; control instruction data and status feedback data within the corresponding cycle; and cyclic redundancy check codes used to verify data integrity.
[0010] Accordingly, a collaborative cycle control device for a non-real-time operating system and a real-time operating system includes: a cycle calculation module on the non-real-time operating system side, configured to calculate the target control cycle based on the system real-time clock, and generate the cycle start time and cycle length; a communication transmission module, configured to transmit cycle parameters and processing results between the non-real-time operating system and the real-time operating system; an interrupt control module on the real-time operating system side, configured to generate periodic interrupt signals based on a hardware timer to control the execution of the local cycle; a cycle synchronization module, configured to record the received cycle start time and cycle length, and maintain the expected cycle identifier; and a result verification module, configured to compare the cycle identifier of the received result with the expected cycle identifier, and trigger exception handling when they are inconsistent.
[0011] Furthermore, the interrupt control module on the real-time operating system side includes: a programmable hardware timer configured to generate hardware interrupt signals at a fixed frequency; an interrupt service subroutine configured to update the local cycle counter and generate a new expected cycle identifier each time an interrupt is triggered; and a synchronization lock mechanism configured to ensure the atomicity of data access during cycle switching.
[0012] Furthermore, the period synchronization module includes: a dual-buffer storage unit configured to store the current period parameters and the next period parameters respectively; a timestamp calibration unit configured to calculate the clock offset based on the period start time and hardware interrupt time of the non-real-time operating system; and a prediction compensation unit configured to predict the synchronization error of the future period based on the historical clock offset and perform compensation adjustment.
[0013] Furthermore, the result verification module includes: a period identifier comparator, configured to compare the period identifier of the received result with the expected period identifier; a state machine controller, configured to switch different processing states according to the comparison result; and an exception handling execution unit, configured to execute the exception handling process as described in claim 4.
[0014] Furthermore, the device is integrated into an industrial automation control system, intelligent driving system, or avionics system, wherein: a non-real-time operating system runs on the main control unit and is responsible for advanced decision-making algorithms and human-machine interaction processing; a real-time operating system runs on the embedded control unit and is responsible for executing critical control loops and safety-sensitive tasks; the device achieves timing consistency and data synchronization of cross-system tasks through coordinated periodic control.
[0015] The beneficial effects of this invention are as follows: This invention solves the problem of cycle synchronization loss caused by clock source differences between two types of operating systems, improves the timing consistency and data reliability of the hybrid control system, can control the cycle synchronization error to the microsecond level through the coordination of hardware interrupts and software clocks, and has a complete cycle verification and anomaly handling mechanism to reduce the probability of system failure caused by timing synchronization loss, increase the fault tolerance capability, support dynamic adjustment of cycle length, adapt to complex control scenarios with load changes, and is suitable for scenarios with high real-time requirements such as industrial automation and intelligent driving. Attached Figure Description
[0016] Figure 1 This is a diagram of the architecture of the non-real-time operating system and the real-time operating system collaborative cycle control system of the present invention.
[0017] Figure 2 This is a flowchart illustrating the periodic control method of the present invention.
[0018] Figure 3 This is a state machine diagram of the exception handling process of this invention.
[0019] Figure 4 This is a block diagram of the module structure of the collaborative control device of the present invention. Detailed Implementation
[0020] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0021] Example 1
[0022] This embodiment describes a collaborative cycle control method between a non-real-time operating system and a real-time operating system. Its system architecture is as follows: Figure 1 As shown, the specific steps are as follows: Figure 2 As shown, the details are as follows: S101: The non-real-time operating system calculates the target control cycle based on the system's real-time clock and sets the cycle start time and cycle length. S102: The non-real-time operating system sends the period parameters (i.e., the period start time and period length) to the real-time operating system; S103: The real-time operating system generates periodic interrupt signals based on hardware timers, and uses the interrupt signals as a reference to control the execution of local cycles; S104: The real-time operating system records the received cycle start time and cycle length, and maintains the expected cycle identifier of the non-real-time operating system processing results that should be received in the current cycle. S105: When the real-time operating system receives the processing result from the non-real-time operating system, it compares the period identifier carried in the result with the expected period identifier. If they are inconsistent, it triggers the preset exception handling process.
[0023] In this embodiment, the non-real-time operating system in S101 calculates the target control cycle based on the system real-time clock, including: the non-real-time operating system obtains the current system time as a reference point; calculates the starting time of the next cycle according to the preset task scheduling rules, the starting time being the first integer multiple timestamp after the reference point; and dynamically adjusts the cycle length according to the system load and task priority to generate variable cycle parameters.
[0024] In this embodiment, the real-time operating system in S103 generates periodic interrupt signals based on a hardware timer, including: configuring the interrupt trigger frequency of the hardware timer so that the interrupt period is an integer proportional relationship with the period length sent by the non-real-time operating system; and updating the local period counter and the expected period identifier of the real-time operating system when each hardware interrupt is triggered.
[0025] In this embodiment, the preset exception handling process is as follows: Figure 3 As shown, the system includes: when the period identifier of the received result is earlier than the expected period identifier, discarding the current result and maintaining the current period execution; when the period identifier of the received result is later than the expected period identifier, triggering the period synchronization mechanism, recalculating the current period parameters based on the latest result, such as predicting the current state through linear interpolation; recording period exception events, and generating log information containing timestamps and period deviation values. When three consecutive periods are out of sync, the system safety mode can be further triggered to ensure the continued operation of critical control loops.
[0026] In this embodiment, the non-real-time operating system and the real-time operating system transmit data through shared memory or message queues. The transmitted content includes: cycle start time, cycle length and cycle identifier; control instruction data and status feedback data within the corresponding cycle; and cyclic redundancy check code used to verify data integrity.
[0027] Example 2
[0028] This embodiment is a collaborative cycle control device for a non-real-time operating system and a real-time operating system, and its structure is as follows: Figure 4 As shown, the system includes a cycle calculation module on the non-real-time operating system side, configured to calculate the target control cycle based on the system's real-time clock, and generate the cycle start time and cycle length; a communication transmission module, configured to transmit cycle parameters and processing results between the non-real-time operating system and the real-time operating system; an interrupt control module on the real-time operating system side, configured to generate periodic interrupt signals based on a hardware timer to control the execution of the local cycle; a cycle synchronization module, configured to record the received cycle start time and cycle length, and maintain the expected cycle identifier; and a result verification module, configured to compare the cycle identifier of the received result with the expected cycle identifier, and trigger exception handling when they are inconsistent.
[0029] In this embodiment, the interrupt control module includes a programmable hardware timer configured to generate hardware interrupt signals at a fixed frequency; an interrupt service subroutine configured to update the local cycle counter and generate a new expected cycle identifier each time an interrupt is triggered; and a synchronization lock mechanism configured to ensure the atomicity of data access during cycle switching.
[0030] In this embodiment, the period synchronization module includes a dual-buffer storage unit configured to store the current period parameters and the next period parameters respectively; a timestamp calibration unit configured to calculate the clock offset based on the period start time and hardware interrupt time of the non-real-time operating system; and a prediction compensation unit configured to predict the synchronization error of the future period based on the historical clock offset and perform compensation adjustment.
[0031] In this embodiment, the result verification module includes a period identifier comparator, configured to compare the period identifier of the received result with the expected period identifier; a state machine controller, configured to switch different processing states according to the comparison result; and an exception handling execution unit, configured to execute the exception handling process of the pre-screening.
[0032] The device in this embodiment can be integrated into an industrial automation control system, intelligent driving system, or avionics system. The non-real-time operating system runs on the main control unit, responsible for advanced decision-making algorithms and human-machine interaction processing; the real-time operating system runs on the embedded control unit, responsible for executing critical control loops and safety-sensitive tasks. The device achieves timing consistency and data synchronization across system tasks through collaborative cycle control. Taking the collaborative control of an industrial automated production line as an example: the non-real-time operating system (PLC main controller) runs a production scheduling algorithm, calculating the execution cycle of each process (e.g., 100ms); the real-time operating system (servo controller) generates a 10ms baseline interrupt through a hardware timer, with every 10 interrupts constituting a control cycle; when the main controller experiences cycle delays due to load fluctuations, the servo controller detects inconsistencies in cycle identifiers and automatically switches to a preset safe movement trajectory to avoid equipment collisions.
[0033] The following demonstrates the implementation process of the corresponding module: Non-real-time operating system side cycle calculation process: Python # Example code: Periodic calculation logic def calculate_cycle(): base_time = get_system_time() # Get the system real-time clock cycle_length = adjust_cycle_length(get_system_load()) # Dynamically adjust cycle length start_time = round_to_next_multiple(base_time, MIN_CYCLE_UNIT) # Calculate the starting point of the cycle return {"start_time": start_time, "length": cycle_length} Interrupt control process on the real-time operating system side: c / / Example code: Hardware interrupt service routine void timer_interrupt_handler() { current_cycle++; expected_result_cycle = current_cycle + CYCLE_DELAY; / / Update the expected cycle flag / / Trigger periodic task execution execute_cycle_task(); } Non-real-time operating systems send periodic parameters via shared memory: json { "start_time": 1632564000000, / / Millisecond-level timestamp "length": 100, / / Period length (milliseconds) "cycle_id": 42, / / Cycle identifier "data": {...}, / / Control data "crc": "A1B2C3D4" / / Checksum } Real-time operating system verification cycle identifier: c / / Example code: Periodic verification logic void verify_result_cycle(uint32_t received_cycle) { if (received_cycle <expected_result_cycle) { discard_outdated_result(); / / Discard outdated results } else if (received_cycle>expected_result_cycle) { trigger_resynchronization(); / / Trigger resynchronization } else { process_valid_result(); / / Process valid results } } The above description is merely a preferred embodiment of the present invention and does not constitute a limitation on the scope of protection of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the claims of the present invention.
Claims
1. A method for coordinated cycle control of a non-real-time operating system and a real-time operating system, characterized in that, The method includes: The non-real-time operating system calculates the target control cycle based on the system's real-time clock and sets the cycle start time and cycle length. The non-real-time operating system sends the cycle start time and cycle length to the real-time operating system; The real-time operating system generates periodic interrupt signals based on hardware timers, and uses these interrupt signals as a reference to control the execution of local cycles. The real-time operating system records the received cycle start time and cycle length, and maintains the expected cycle identifier of the non-real-time operating system processing results that should be received in the current cycle. When the real-time operating system receives the processing result from the non-real-time operating system, it compares the period identifier carried in the result with the expected period identifier. If they are inconsistent, a preset exception handling process is triggered.
2. The coordinated periodic control method according to claim 1, characterized in that, The non-real-time operating system calculates the target control cycle based on the system's real-time clock, including: Non-real-time operating systems obtain the current system time as a reference point; The start time of the next cycle is calculated according to the preset task scheduling rules, and the start time is the first integer multiple timestamp after the reference point; The cycle length is dynamically adjusted based on system load and task priority to generate variable cycle parameters.
3. The coordinated periodic control method according to claim 1, characterized in that, The real-time operating system generates periodic interrupt signals based on a hardware timer, including: Configure the interrupt trigger frequency of the hardware timer so that the interrupt period is an integer proportional to the period length sent by the non-real-time operating system. When each hardware interrupt is triggered, the local cycle counter and expected cycle flag of the real-time operating system are updated.
4. The coordinated periodic control method according to claim 1, characterized in that, The exception handling process includes: If the period identifier of the received result is earlier than the expected period identifier, discard the current result and maintain the execution of the current period. When the period identifier of the received result is later than the expected period identifier, the period synchronization mechanism is triggered, and the current period parameter is recalculated based on the latest result. Record periodic abnormal events and generate log information including timestamps and periodic deviation values.
5. The coordinated periodic control method according to claim 1, characterized in that, The non-real-time operating system and the real-time operating system transmit data via shared memory or message queues, and the transmitted content includes: Period start time, period length, and period identifier; Control command data and status feedback data within the corresponding cycle; Cyclic redundancy check (CRC) codes are used to verify data integrity.
6. A collaborative cycle control device for a non-real-time operating system and a real-time operating system, characterized in that, The device includes: The cycle calculation module on the non-real-time operating system side is configured to calculate the target control cycle based on the system real-time clock and generate the cycle start time and cycle length; The communication transmission module is configured to transmit periodic parameters and processing results between a non-real-time operating system and a real-time operating system. The interrupt control module on the real-time operating system side is configured to generate periodic interrupt signals based on a hardware timer to control the execution of local cycles. The period synchronization module is configured to record the received period start time and period length, and maintain the expected period identifier; The result verification module is configured to compare the period identifier of the received result with the expected period identifier, and trigger exception handling when they are inconsistent.
7. The coordinated cycle control device according to claim 6, characterized in that, The interrupt control module on the real-time operating system side includes: A programmable hardware timer configured to generate hardware interrupt signals at a fixed frequency; The interrupt service routine is configured to update the local cycle counter and generate a new expected cycle flag each time an interrupt is triggered. A synchronization lock mechanism is configured to ensure the atomicity of data access during period switching.
8. The coordinated cycle control device according to claim 6, characterized in that, The periodic synchronization module includes: A dual-buffer storage unit is configured to store the current cycle parameters and the next cycle parameters respectively. The timestamp calibration unit is configured to calculate the clock offset based on the cycle start time and hardware interrupt time of the non-real-time operating system. The predictive compensation unit is configured to predict the synchronization error of future cycles based on historical clock offsets and perform compensation adjustments.
9. The coordinated cycle control device according to claim 6, characterized in that, The result verification module includes: A period identifier comparator is configured to compare the period identifier of the received result with the expected period identifier. The state machine controller is configured to switch between different processing states based on the comparison result. An exception handling execution unit is configured to execute the exception handling process as described in claim 4.
10. The coordinated cycle control device according to claim 6, characterized in that, The device is integrated into an industrial automation control system, intelligent driving system, or avionics system, wherein: The non-real-time operating system runs on the main control unit and is responsible for advanced decision-making algorithms and human-computer interaction processing. The real-time operating system runs on the embedded control unit and is responsible for executing critical control loops and security-sensitive tasks. The device achieves timing consistency and data synchronization for cross-system tasks through coordinated periodic control.