Real-time operating system timer implementation method and device and electronic equipment

By updating the reload registers of the hardware timer in the real-time operating system, interrupts are only entered at the moment when corresponding timing actions need to be triggered, the problems of waste of resources and high system load rates caused by the implementation of timers in the prior art are solved, and more efficient system resource utilization is achieved.

CN119576491APending Publication Date: 2025-03-07JINGWEI HIRAIN (TIANJIN) RES&DEV CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411620248.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

The implementation of timers in existing real-time operating systems results in the hardware timer being interrupted multiple times, resulting in waste of resources and increased system load.

Method used

By setting and updating the reload value of the reload register in the hardware timer based on the trigger time corresponding to the timing action set in the real-time operating system, the hardware timer generates an interrupt processing request based on the reload value and triggers the corresponding timing action in response to the interrupt processing request.

Benefits of technology

Reduces resource waste caused by hardware timer interruption, reduces system load rate, and improves system resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576491A_ABST
    Figure CN119576491A_ABST
Patent Text Reader

Abstract

The invention discloses a method and a device for realizing a timer of a real-time operating system and electronic equipment, which can aperiodically update a reloading value of a reloading register in a hardware timer according to a triggering moment of each timing action needing to be triggered in the real-time operating system. Therefore, the real-time operating system can enter the hardware timer interruption only at the moment when the corresponding timing action needs to be triggered, and cannot enter the hardware timer interruption once per time unit, so that the effect of saving system resources is achieved, and the problem of high system load rate caused by frequent interruption can be avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of vehicle technology, and in particular, relates to a method, device and electronic device for implementing a timer of a real-time operating system. Background Art

[0002] Real-time operating system is a system software that manages and controls vehicle hardware and software resources, and plays a huge role in vehicles. The real-time operating system is based on the timer in the system, and can help users schedule timed tasks through timer interrupts.

[0003] The implementation method of timers in existing real-time operating systems is usually to use hardware timers to periodically generate interrupts according to fixed time units, and accumulate the number of interrupts generated by the hardware timer, and then execute the corresponding action when the accumulated number reaches the number threshold corresponding to a certain timing action.

[0004] In the existing timer implementation, the hardware timer needs to generate multiple interrupts to trigger the timing action, and each interrupt requires a certain amount of system resources to handle the interrupt request. Therefore, this implementation will lead to resource waste, and will also cause the system to frequently enter interrupts, resulting in an increase in the system load rate. Summary of the invention

[0005] The embodiments of the present application provide a real-time operating system timer implementation method, device, electronic device, medium and program, which can reduce the resource waste caused by hardware timer interrupts and improve the problem of increased system load rate due to frequent system interrupts.

[0006] In a first aspect, an embodiment of the present application provides a method for implementing a timer of a real-time operating system, the method comprising:

[0007] Based on the triggering time corresponding to the timing action set in the real-time operating system, setting and updating the reload value of the reload register in the hardware timer, wherein the hardware timer generates an interrupt processing request based on the reload value;

[0008] In response to an interrupt processing request generated by the hardware timer, a timing action corresponding to the reload value is triggered.

[0009] As a possible implementation, based on the triggering time corresponding to the timing action set in the real-time operating system, the reload value of the reload register in the hardware timer is set and updated, including:

[0010] Initializing a ready list and a reload value based on configuration data of the real-time operating system, wherein the ready list is used to store a trigger time corresponding to a timed action set in the real-time operating system;

[0011] Before the hardware timer generates an interrupt processing request based on the reload value, when the user data called by the real-time operating system includes a second scheduled task and a second trigger time corresponding to the second scheduled task, it is determined whether to update the ready list and / or the reload value according to the second trigger time until the hardware timer generates an interrupt processing request based on the reload value.

[0012] As a possible implementation, the ready list and the reload value are initialized based on the configuration data of the real-time operating system, including:

[0013] In a case where the configuration data includes a set first timed action and a first triggering time corresponding to the first timed action, inserting the first triggering time into the ready list;

[0014] The earliest trigger time in the ready list is used as the reload value after initialization.

[0015] As a possible implementation, the ready list and the reload value are initialized based on the configuration data of the real-time operating system, including:

[0016] In the case that the configuration data does not include the set first timed action and the first triggering time corresponding to the first timed action, the ready list is set to be empty;

[0017] Initialize the reload value to the maximum timing value of the reload register.

[0018] As a possible implementation manner, determining whether to update the ready list and / or the reload value based on the second triggering moment includes:

[0019] Insert the second trigger moment into the ready list;

[0020] When the second trigger time is the new earliest trigger time in the ready list, the reload value is updated based on the new earliest trigger time.

[0021] As a possible implementation, updating the reload value based on the new earliest trigger time includes:

[0022] Get the current time;

[0023] The difference between the new earliest trigger time and the current time is used as the updated reload value.

[0024] As a possible implementation, in response to an interrupt processing request generated by a hardware timer, after executing a timing action corresponding to the reload value, the method further includes:

[0025] Delete the target trigger time corresponding to the overload value from the ready list;

[0026] When the deletion is completed, the reload value is updated based on the new earliest trigger time in the ready list, and before the hardware timer generates an interrupt processing request based on the reload value, when the user data called by the real-time operating system includes a second scheduled task and a second trigger time corresponding to the second scheduled task, it is determined whether to update the ready list and / or the reload value according to the second trigger time, until the hardware timer generates an interrupt processing request based on the reload value.

[0027] As a possible implementation, updating the reload value based on the new earliest trigger time in the ready list includes:

[0028] Calculate the first difference between the new earliest trigger time and the target trigger time;

[0029] Calculate a second difference between the first difference and the current interrupt processing duration, where the current interrupt processing duration is the duration consumed by the real-time operating system to process the interrupt processing request corresponding to the target triggering moment;

[0030] The second difference is used as the updated reload value.

[0031] In a second aspect, an embodiment of the present application provides a real-time operating system timer implementation device, including:

[0032] A reload value setting module, used to set and update the reload value of the reload register in the hardware timer based on the triggering time corresponding to the timing action set in the real-time operating system, wherein the hardware timer generates an interrupt processing request based on the reload value;

[0033] The trigger module is used to respond to an interrupt processing request generated by the hardware timer and trigger a timing action corresponding to the reload value.

[0034] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising: a processor and a memory storing computer program instructions;

[0035] When the processor executes the computer program instructions, the real-time operating system timer implementation method as described in the first aspect is implemented.

[0036] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having computer program instructions stored thereon, and when the computer program instructions are executed by a processor, the real-time operating system timer implementation method as described in the first aspect is implemented.

[0037] In a fifth aspect, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the real-time operating system timer implementation method as described in the first aspect.

[0038] The real-time operating system timer implementation method, apparatus, device, medium and program of the embodiments of the present application can non-periodically update the reload value of the reload register in the hardware timer according to the triggering time of each timing action that needs to be triggered in the real-time operating system, so that the real-time operating system will only enter the hardware timer interrupt when the corresponding timing action needs to be triggered, and will not enter the hardware timer interrupt once per time unit, thereby achieving the effect of saving system resources and avoiding the problem of high system load rate caused by frequent interrupts. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0040] Figure 1 It is a flowchart of a method for implementing a timer of a real-time operating system provided in an embodiment of the present application;

[0041] Figure 2 is a schematic diagram of the reload register update principle provided in an embodiment of the present application;

[0042] Figure 3 is a schematic diagram of a real-time operating system timer implementation device provided in an embodiment of the present application;

[0043] Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0044] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.

[0045] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0046] The following is a description of the professional terms involved in the embodiments of the present application:

[0047] The reload register refers to the automatic reload register (Automatic Reload Register, ARR for short), also known as the reload value register.

[0048] The reload value refers to the initial value for timing stored in the reload register. The value of the reload register decreases from the reload value to 0. When the value of the reload register in the hardware timer decreases from the reload value to 0, the hardware timer generates an interrupt.

[0049] In order to at least solve the problems of resource waste and high system load rate in the real-time operating system timer implementation method in the prior art, the embodiments of the present application provide a real-time operating system timer implementation method, device, system, equipment, medium and program. First, a real-time operating system timer implementation method provided by the embodiments of the present application is described below.

[0050] A real-time operating system timer implementation method provided in an embodiment of the present application can be applied to a vehicle-mounted real-time operating system.

[0051] See also Figure 1 , is a flow chart of a method for implementing a timer of a real-time operating system provided in an embodiment of the present application, such as Figure 1 As shown, the method may include the following steps S11-S12, which are described in detail below.

[0052] S11. Based on the triggering time corresponding to the timing action set in the real-time operating system, set and update the reload value of the reload register in the hardware timer.

[0053] Wherein, the hardware timer generates an interrupt processing request based on the reload value.

[0054] In some embodiments of the present application, the timed actions set in the real-time operating system and the triggering time corresponding to the timed actions can be set by the user in at least one of the following data of the real-time operating system according to actual needs: configuration data and user data. The configuration data includes data set before the real-time operating system starts running, and the user data may include but is not limited to at least one of the user tasks and user interrupt processing functions after the real-time operating system starts running. Based on this, when executing the above step S11, the triggering time corresponding to the set timed action can be obtained according to the configuration data and / or user data of the real-time operating system. Figure 2 As shown, the timed action may include the to-be-triggered action configured before the system starts running, the to-be-triggered action in the user interrupt processing function, and the to-be-triggered action in the user task. The triggering moment corresponding to the timed action refers to the moment when the timed action is triggered. For each timed action, the real-time operating system may execute the triggering operation corresponding to the timed action when the triggering moment of the timed action is reached.

[0055] In some embodiments of the present application, the real-time operating system includes a ready list corresponding to the hardware timer for storing the timed actions set in the real-time operating system and the triggering time corresponding to the timed actions. Figure 2 As shown, when the triggering time corresponding to the set timed action is obtained, the obtained timed action and the triggering time corresponding to the timed action can be stored in the ready list. Then, based on the triggering time stored in the ready list, the reload register of the hardware timer is updated non-periodically.

[0056] In this embodiment, the reload value of the reload register in the hardware timer is set and updated based on the triggering time, so that the reload register of the hardware timer can be updated non-periodically according to the triggering time of each timing action to be triggered in the system. Since the hardware timer interrupts according to the reload value in the register, the reload value is updated based on the triggering time of the timing action, so that the hardware timer interrupt only enters the interruption at the time when the corresponding timing action needs to be triggered, and does not enter an interruption once in each time unit, thereby reducing the number of interruptions.

[0057] In this embodiment, the hardware timer may include but is not limited to a system timer. When the hardware timer enters an interrupt, it may generate an interrupt processing request, and the interrupt processing request is used to instruct the hardware timer to enter an interrupt.

[0058] S12. In response to the interrupt processing request generated by the hardware timer, trigger a timing action corresponding to the reload value.

[0059] In this embodiment, the hardware timer will enter an interrupt only when the corresponding timing action needs to be triggered. Therefore, when an interrupt processing request generated by the hardware timer is received, it can be determined that the corresponding timing action needs to be triggered at present, thereby triggering the timing action corresponding to the reload value based on this interrupt. The timing action corresponding to the reload value is the timing action corresponding to the triggering moment for setting the reload value.

[0060] In some embodiments of the present application, when an interrupt processing request is generated by a hardware timer, the timing action corresponding to the current reload value can be checked in the interrupt processing function of the hardware timer, and a corresponding action processing can be performed on it.

[0061] A real-time operating system timer implementation method provided in this embodiment can non-periodically update the reload value of the reload register in the hardware timer according to the triggering time of each timing action that needs to be triggered in the real-time operating system. This allows the real-time operating system to enter the hardware timer interrupt only when the corresponding timing action needs to be triggered, rather than entering the hardware timer interrupt once per time unit, thereby achieving the effect of saving system interrupt resources and avoiding the problem of high system load rate caused by frequent interrupts.

[0062] In addition, when dealing with the need for high time precision, the existing timer implementation method may result in inaccurate timing of the operating system timer due to frequent hardware timer interrupts. The real-time operating system timer implementation method provided in this embodiment uses a non-periodic update of the hardware timer's reload register to meet the need for high time precision without the need to manually configure a fixed reload value. This simplifies user configuration while improving the timer's timing accuracy, thereby improving system usability.

[0063] In some embodiments, in the above step S11, based on the trigger time corresponding to the timing action set in the real-time operating system, setting and updating the reload value of the reload register in the hardware timer can include the following steps S111-S112, which are described in detail below.

[0064] S111. Initialize the ready list and the reload value based on the configuration data of the real-time operating system. The ready list is used to store the triggering time corresponding to the timed action set in the real-time operating system.

[0065] In some embodiments of the present application, a ready list corresponding to a hardware timer may be maintained in the real-time operating system at all times. The ready list is used to store the triggering time corresponding to the timed action set in the real-time operating system. When the real-time operating system is started or shut down, all information in the ready list may be cleared. In this way, after each startup of the real-time operating system, only the triggering time related to the current operation may be stored in the ready list.

[0066] In other embodiments of the present application, the real-time operating system can also create a blank ready list corresponding to the hardware timer each time it is started, and delete the ready list each time it is shut down. In this way, after the real-time operating system is started each time, the ready list can only store the triggering time related to this operation.

[0067] In some embodiments of the present application, the real-time operating system may initialize the ready list and the reload value based on the configuration data of the real-time operating system before starting to run. The real-time operating system may check whether there are set timed actions and trigger times corresponding to the timed actions in the configuration data before starting to run, and initialize the reload value based on the detection result. For ease of distinction, the timed action set in the configuration data is referred to as the first timed action, and the trigger time corresponding to the first timed action is referred to as the first trigger time. In some embodiments of the present application, when the configuration data includes a set first timed action and a first trigger time corresponding to the first timed action, initializing the ready list and the reload value based on the configuration data of the real-time operating system may include:

[0068] Insert the first trigger moment into the ready list;

[0069] Initializes the reload value based on the earliest trigger time in the ready list.

[0070] Here, if there is a set first timing action and a first triggering moment corresponding to the first timing action in the configuration data, all the first triggering moments in all the configuration data can be inserted into the ready list, and the reload value of the reload register can be initialized based on the earliest triggering moment in the ready list. After the initialization is completed, the hardware timer can be enabled to start timing and the hardware timer interrupt can be enabled, so that the hardware timer can generate a hardware timer interrupt when the timing reaches the earliest triggering moment.

[0071] Among them, when inserting the trigger time into the ready list, it can be inserted in order from early to late. In this way, the trigger time in the ready list will be stored in order from early to late, and the trigger time ranked first is the earliest trigger time. In this way, the earliest trigger time in the ready list can be quickly found according to the storage order of the trigger time in the ready list.

[0072] In some embodiments of the present application, the triggering time corresponding to each scheduled task in the real-time operating system is the system time, and the reload value can be initialized according to the following formula (1):

[0073] reload=newTick- counterTick (1)

[0074] In the formula, reload represents the reload value, newTick represents the earliest trigger time in the current ready list, and counterTick represents the current time, that is, the time when the reload value is calculated.

[0075] The real-time operating system can initialize the reload value before starting to run. Before the real-time operating system starts to run, the system time is always the timing starting point of the real-time operating system, that is, the zero time. Therefore, the current time counterTick when the reload value is initialized is the zero time. Based on this, when the reload value is initialized based on the earliest trigger time in the ready list according to the above formula (1), it can include:

[0076] The earliest trigger time is used as the reload value after initialization.

[0077] In this way, the reload value can be initialized quickly.

[0078] In some embodiments of the present application, when the configuration data does not include the set first timed action and the first triggering time corresponding to the first timed action, initializing the ready list and the reload value based on the configuration data of the real-time operating system may include:

[0079] Set the ready list to empty;

[0080] Initialize the reload value to the maximum timing value of the reload register.

[0081] The maximum timing value of the reload register refers to the maximum reload value that can be set for the reload register, which is an inherent property of the reload register and can be directly obtained.

[0082] After initializing the reload value of the hardware timer's reload register to the maximum timing value, you can enable the hardware timer to start timing, and enable the hardware timer's interrupt. In this way, the hardware timer will not generate an interrupt signal when timing to the maximum value, so that it can count in a loop.

[0083] S112. Before the hardware timer generates an interrupt processing request based on the reload value, when the user data called by the real-time operating system includes a second scheduled task and a second trigger time corresponding to the second scheduled task, determine whether to update the ready list and / or the reload value based on the second trigger time until the hardware timer generates an interrupt processing request based on the reload value.

[0084] In some embodiments of the present application, the real-time operating system can start running after completing the initialization of the ready list and the reload value. After starting to run, for each reload value set, the real-time operating system can update the ready list and / or the reload value according to the called user data before the hardware timer generates an interrupt processing request based on the reload value until the hardware timer generates an interrupt processing request based on the reload value.

[0085] After the real-time operating system starts running, the timing value of the reload register can be decremented from the set reload value until it is decremented to 0, and the hardware timer enters an interrupt to generate an interrupt processing request. In the process of the timing value of the reload register being decremented from the reload value to 0, that is, in the process of the hardware timer generating an interrupt processing request based on the reload value, the real-time operating system keeps running and calls the corresponding user data. During this process, if the real-time operation data detects that a timed action and a trigger time corresponding to the timed action are set in the called user data, the ready list and / or the reload value can be updated based on the trigger time in the called user data to avoid missing a timed task. For ease of distinction, the timed action set in the user data is referred to as the second timed action, and the trigger time corresponding to the second timed action is referred to as the second trigger time.

[0086] In some embodiments of the present application, determining whether to update the ready list and / or the reload value according to the second triggering moment includes:

[0087] Insert the second trigger moment into the ready list;

[0088] In the case where the second trigger time is inserted as the new earliest trigger time in the ready list, the reload value is updated based on the new earliest trigger time.

[0089] Here, in the case where the second trigger time is earlier than the original earliest time in the ready list, after the second trigger time is inserted into the ready list, the earliest trigger time in the ready list will be updated, that is, updated from the original earliest time to the inserted second trigger time. At this time, the reload value can be updated according to the updated earliest time according to the above formula (1). In this way, the real earliest trigger time in the ready list can always be maintained in the reload register of the hardware timer, thereby reducing task omissions.

[0090] In addition, after the second trigger time is inserted into the ready list, if the earliest trigger time in the ready list has not been updated, that is, the newly inserted second trigger time is after the original earliest trigger time in the ready list, there is no need to update the reload value of the reload register in the hardware timer, and the interrupt can be performed according to the original reload value.

[0091] In addition, before the hardware timer generates an interrupt processing request based on the reload value, if the user data called by the real-time operating system does not include the second scheduled task and the second trigger time corresponding to the second scheduled task, there is no need to update the ready list and the reload value.

[0092] In some embodiments, after the above step S12, the following steps may also be performed:

[0093] Delete the target trigger time corresponding to the reload value based on which this interrupt is based from the ready list;

[0094] In case the deletion is complete, the reload value is updated based on the new earliest trigger time in the ready list.

[0095] In this embodiment, the target trigger time corresponding to the reload value is the trigger time for setting the reload value. For example, if the reload value A is calculated based on the trigger time B in the ready list, then the trigger time B is the target trigger time corresponding to the reload value A.

[0096] After performing above-mentioned steps S12, the target triggering moment corresponding to the reload value is deleted from the ready list, so that the earliest triggering moment in the ready list can be updated to the triggering moment that is located after the target triggering moment and is closest to the target triggering moment. Because each triggering moment in the ready list is aperiodic, namely the intervals between each triggering moment are unequal, and the reload register of the hardware timer can only maintain a reload value, so after the target triggering moment corresponding to the reload value based on which this interruption is based is deleted from the ready list, it is necessary to update the reload value of the reload register in the hardware timer according to the new earliest triggering moment updated in the ready list in the interrupt handling function of the hardware timer. In this way, the earliest triggering moment corresponding to the timed task that has never been triggered maintained in the reload register of the hardware timer can be made, so that each timing action can be triggered according to the chronological order of time.

[0097] Further, for the updated reload value, the above step S112 can also be performed, that is, before the hardware timer generates an interrupt processing request based on the updated reload value, in the case where the user data called by the real-time operating system includes the second timed task and the second triggering time corresponding to the second timed task, it is determined whether to update the ready list and / or the reload value according to the second triggering time until the hardware timer generates an interrupt processing request based on the reload value. This can avoid missing timing actions, thereby improving the accuracy of system task scheduling.

[0098] In some embodiments, the number of timed tasks is limited, and the number of triggering moments stored in the ready list is also limited. After deleting the target triggering moment from the ready list, before updating the reload value based on the new earliest triggering moment in the ready list, it can be determined whether there are still triggering moments stored in the ready list. If there are still triggering moments stored in the ready list, the step of updating the reload value based on the earliest triggering moment in the ready list is executed. If there are no triggering moments in the ready list, that is, the ready list is empty, it is determined that all the timed actions in the current system have been triggered. At this time, the reload value can be set to the maximum timing value of the reload register until a new triggering moment is stored in the ready list. Then, the reload value is set according to formula (1) based on the earliest triggering moment in the new triggering moments, and this cycle is repeated. In this way, the number of interrupts of the hardware timer can be reduced.

[0099] In some embodiments, when the target trigger time is deleted from the ready list, updating the reload value based on the new earliest trigger time in the ready list may include:

[0100] Calculate the first difference between the new earliest trigger time and the target trigger time;

[0101] Calculate a second difference between the first difference and the current interrupt processing duration, where the current interrupt processing duration is the duration consumed by the real-time operating system to process the interrupt processing request corresponding to the target triggering moment;

[0102] The second difference is used as the updated reload value.

[0103] In this implementation, the interrupt processing request corresponding to the target triggering time refers to an interrupt processing request generated by the hardware timer based on the reload value corresponding to the target triggering time.

[0104] In some embodiments of the present application, when the target trigger time is deleted from the ready list, the reload value may be updated according to the following formula (2) based on the new earliest trigger time in the ready list:

[0105] reload = newTick – oldTick – processTime (2)

[0106] In the formula, reload represents the reload value, newTick represents the new earliest trigger time in the current ready list, oldTick represents the target trigger time, and processTime represents the current interrupt processing duration.

[0107] When the overload value is updated in the above manner, the time required for the real-time operating system to process the interrupt processing request is taken into consideration. This can avoid the problem that the distance between the earliest trigger time after the update and the target trigger time is too close, resulting in the interrupt processing request corresponding to the target trigger time being missed when the earliest trigger time after the update is processed, causing the timing action corresponding to the earliest trigger time to fail to be triggered, thereby improving the accuracy of system task scheduling.

[0108] In summary, the real-time operating system timer implementation method provided by the embodiment of the present application can non-periodically update the reload register of the hardware timer according to the triggering time of each timing action that needs to be triggered in the real-time operating system, so that the operating system will only enter the hardware timer interrupt at the moment when the corresponding timing action needs to be triggered, and will not enter the hardware timer interrupt once per time unit, thereby achieving the effect of saving system interrupt resources. In addition, when dealing with the needs of high time accuracy, the existing typical method will reduce the time unit for generating interrupts set by the hardware timer, causing the operating system to enter interrupts more frequently, resulting in inaccurate timer timing. The method of non-periodically updating the reload register of the hardware timer provided by the embodiment of the present application can achieve the needs of high time accuracy without manually configuring fixed time units, simplifying user configuration while improving the accuracy of timer timing, and improving system usability.

[0109] Based on the real-time operating system timer implementation method provided in the above embodiment, the present application also provides a specific implementation method of a real-time operating system timer implementation device. Please refer to the following embodiment.

[0110] See also Figure 3 , is a schematic diagram of a real-time operating system timer implementation device provided in an embodiment of the present application, such as Figure 3 As shown, the real-time operating system timer implementation device 300 may include the following modules:

[0111] A reload value setting module 301, for setting and updating a reload value of a reload register in a hardware timer based on a triggering time corresponding to a timing action set in a real-time operating system, wherein the hardware timer generates an interrupt processing request based on the reload value;

[0112] The trigger module 302 is used to trigger a timing action corresponding to the reload value in response to an interrupt processing request generated by the hardware timer.

[0113] The real-time operating system timer implementation device of the embodiment of the present application can non-periodically update the reload value of the reload register in the hardware timer according to the triggering time of each timing action that needs to be triggered in the real-time operating system. This allows the real-time operating system to enter the hardware timer interrupt only when the corresponding timing action needs to be triggered, rather than entering the hardware timer interrupt once per time unit, thereby achieving the effect of saving system resources and avoiding the problem of high system load rate caused by frequent interrupts.

[0114] In some embodiments, the reload value setting module 301 may include:

[0115] An initialization submodule, used to initialize the ready list and the reload value based on the configuration data of the real-time operating system, the ready list is used to store the trigger time corresponding to the timed action set in the real-time operating system;

[0116] The first update submodule is used to determine whether to update the ready list and / or the reload value according to the second trigger time before the hardware timer generates an interrupt processing request based on the reload value, when the user data called by the real-time operating system includes a second scheduled task and a second trigger time corresponding to the second scheduled task, until the hardware timer generates an interrupt processing request based on the reload value.

[0117] In some embodiments, the initialization submodule is used to:

[0118] A first initialization unit, configured to insert the first triggering time into the ready list when the configuration data includes a set first timed action and a first triggering time corresponding to the first timed action;

[0119] The second initialization unit is used to use the earliest trigger time in the ready list as the initialized reload value.

[0120] In some embodiments, the first initialization unit is further configured to set the ready list to empty if the configuration data does not include the set first timed action and the first triggering time corresponding to the first timed action;

[0121] The second initialization unit is further used for initializing the reload value to the maximum timing value of the reload register when the configuration data does not include the set first timing action and the first triggering time corresponding to the first timing action.

[0122] In some embodiments, the first update submodule may include:

[0123] A first updating unit, configured to insert a second triggering moment into a ready list;

[0124] The second updating unit is used to update the reload value based on the new earliest trigger time when the second trigger time is the new earliest trigger time in the ready list.

[0125] In some embodiments, the second updating unit is configured to:

[0126] Get the current time;

[0127] The difference between the new earliest trigger time and the current time is used as the updated reload value.

[0128] In some embodiments, the reload value setting module 301 may further include:

[0129] A deletion submodule, for responding to an interrupt processing request generated by a hardware timer, and after executing a timing action corresponding to the reload value, deleting the target trigger time corresponding to the reload value from the ready list;

[0130] The second update submodule is used to update the reload value based on the new earliest trigger time in the ready list when the deletion is completed, and to execute the step of determining whether to update the ready list and / or the reload value according to the second trigger time when the user data called by the real-time operating system includes a second scheduled task and a second trigger time corresponding to the second scheduled task before the hardware timer generates an interrupt processing request based on the reload value, until the hardware timer generates an interrupt processing request based on the reload value.

[0131] In some embodiments, the second updating submodule is used to:

[0132] Calculate the first difference between the new earliest trigger time and the target trigger time;

[0133] Calculate a second difference between the first difference and the current interrupt processing duration, where the current interrupt processing duration is the duration consumed by the real-time operating system to process the interrupt processing request corresponding to the target triggering moment;

[0134] The second difference is used as the updated reload value.

[0135] The real-time operating system timer implementation device provided in the embodiment of the present application can implement each process implemented by any of the above-mentioned method embodiments. To avoid repetition, they will not be described here.

[0136] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown.

[0137] The electronic device 400 may include a processor 401 and a memory 402 storing computer program instructions.

[0138] Specifically, the processor 401 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.

[0139] The memory 402 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 402 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. Where appropriate, the memory 402 may include a removable or non-removable (or fixed) medium. Where appropriate, the memory 402 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 402 is a non-volatile solid-state memory. The memory 402 may include a read-only memory (ROM), a random access memory (RAM), a disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical, or other physical / tangible memory storage device. Therefore, typically, the memory 402 includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer executable instructions, and when the software is executed (e.g., by one or more processors), it may perform the operations described in any of the above-mentioned embodiments of the real-time operating system timer implementation method.

[0140] The processor 401 implements any one of the real-time operating system timer implementation methods in the above embodiments by reading and executing computer program instructions stored in the memory 402 .

[0141] In one example, the electronic device 400 may further include a communication interface 403 and a bus 410. Figure 4 As shown, the processor 401, the memory 402, and the communication interface 403 are connected via a bus 410 and communicate with each other.

[0142] The communication interface 403 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.

[0143] Bus 410 includes hardware, software or both, and the parts of online data flow billing equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front-side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 410 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.

[0144] In addition, in combination with the real-time operating system timer implementation method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any real-time operating system timer implementation method in the above embodiment is implemented.

[0145] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.

[0146] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.

[0147] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.

[0148] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.

[0149] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.

Claims

1. A method for implementing a timer in a real-time operating system, characterized in that: include: Based on the triggering time corresponding to the timing action set in the real-time operating system, setting and updating the reload value of the reload register in the hardware timer, wherein the hardware timer generates an interrupt processing request based on the reload value; In response to an interrupt processing request generated by the hardware timer, a timing action corresponding to the reload value is triggered.

2. The method according to claim 1, characterized in that The step of setting and updating the reload value of the reload register in the hardware timer based on the triggering time corresponding to the timing action set in the real-time operating system includes: Initializing a ready list and the reload value based on configuration data of the real-time operating system, wherein the ready list is used to store a trigger time corresponding to a timed action set in the real-time operating system; Before the hardware timer generates an interrupt processing request based on the reload value, when the user data called by the real-time operating system includes a second scheduled task and a second trigger time corresponding to the second scheduled task, it is determined whether to update the ready list and / or the reload value according to the second trigger time until the hardware timer generates an interrupt processing request based on the reload value.

3. The method according to claim 2, characterized in that Initializing the ready list and the reload value based on the configuration data of the real-time operating system includes: In a case where the configuration data includes a set first timed action and a first triggering time corresponding to the first timed action, inserting the first triggering time into the ready list; The earliest triggering time in the ready list is used as the initialized reload value.

4. The method according to claim 2, characterized in that: Initializing the ready list and the reload value based on the configuration data of the real-time operating system includes: In a case where the configuration data does not include a set first timed action and a first triggering time corresponding to the first timed action, setting the ready list to empty; The reload value is initialized to the maximum timing value of the reload register.

5. The method according to claim 2, characterized in that: The determining whether to update the ready list and / or the reload value based on the second triggering moment includes: inserting the second triggering time into the ready list; In a case where the second triggering time is a new earliest triggering time in the ready list, the reload value is updated based on the new earliest triggering time.

6. The method according to claim 5, characterized in that The updating of the reload value based on the new earliest triggering time comprises: Get the current time; The difference between the new earliest trigger time and the current time is used as the updated reload value.

7. The method according to claim 2, characterized in that After executing the timing action corresponding to the reload value in response to the interrupt processing request generated by the hardware timer, the method further includes: Deleting the target trigger time corresponding to the reload value from the ready list; When the deletion is completed, the reload value is updated based on the new earliest trigger time in the ready list, and the step of determining whether to update the ready list and / or the reload value according to the second trigger time before the hardware timer generates an interrupt processing request based on the reload value, when the user data called by the real-time operating system includes a second scheduled task and a second trigger time corresponding to the second scheduled task, is executed until the hardware timer generates an interrupt processing request based on the reload value.

8. The method according to claim 7, characterized in that The updating of the reload value based on the new earliest trigger time in the ready list includes: Calculating a first difference between the new earliest trigger time and the target trigger time; Calculating a second difference between the first difference and a current interrupt processing duration, wherein the current interrupt processing duration is a duration consumed by the real-time operating system to process an interrupt processing request corresponding to the target triggering moment; The second difference is used as the updated reload value.

9. A real-time operating system timer implementation device, characterized in that: include: A reload value setting module, used to set and update the reload value of the reload register in the hardware timer based on the triggering time corresponding to the timing action set in the real-time operating system, wherein the hardware timer generates an interrupt processing request based on the reload value; The trigger module is used to trigger a timing action corresponding to the reload value in response to an interrupt processing request generated by the hardware timer.

10. An electronic device, characterized in that: The electronic device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the real-time operating system timer implementation method according to any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Timing method of software timer, electronic equipment and storage medium

    CN120029737A