WO2019075745A1 - Timing method of virtual timer, apparatus thereof, and electronic apparatus - Google Patents

Timing method of virtual timer, apparatus thereof, and electronic apparatus Download PDF

Info

Publication number
WO2019075745A1
WO2019075745A1 PCT/CN2017/107098 CN2017107098W WO2019075745A1 WO 2019075745 A1 WO2019075745 A1 WO 2019075745A1 CN 2017107098 W CN2017107098 W CN 2017107098W WO 2019075745 A1 WO2019075745 A1 WO 2019075745A1
Authority
WO
WIPO (PCT)
Prior art keywords
timer
virtual
timing
time
hardware
Prior art date
Application number
PCT/CN2017/107098
Other languages
French (fr)
Chinese (zh)
Inventor
周永林
杨柯
Original Assignee
深圳市汇顶科技股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市汇顶科技股份有限公司 filed Critical 深圳市汇顶科技股份有限公司
Priority to PCT/CN2017/107098 priority Critical patent/WO2019075745A1/en
Priority to CN201780001891.4A priority patent/CN109952560B/en
Publication of WO2019075745A1 publication Critical patent/WO2019075745A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements

Definitions

  • the embodiments of the present invention relate to the field of timer technologies, and in particular, to a timing method, a device, and an electronic device of a virtual timer.
  • one of the technical problems to be solved by the embodiments of the present application is to provide a timing method, a device, and an electronic device for a virtual timer, which overcome the above technical defects in the prior art.
  • the embodiment of the present application provides a timing device for a virtual timer, including:
  • An interrupt module configured to enter an interrupt phase and stop the hardware timer when a time counted by the hardware timer reaches a timing reference value thereof;
  • the timing module is configured to determine, in the virtual timer refreshing phase, whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, execute the corresponding application task; if not, the corresponding application task is not executed;
  • a refreshing module configured to determine, according to the elapsed time between the stop and the previous start of the hardware timer when entering the interrupt phase, entering the interrupt phase to start the virtual timer queue from a time when the hardware timer stops The shortest time in the middle;
  • a startup module configured to enter a hardware timer startup phase and update the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, and exit the interrupt phase to restart the hardware timer.
  • the embodiment of the present application provides an electronic device, including: a hardware timer, a plurality of virtual timers, and a processor, when the counted time of the hardware timer reaches its timing reference value, enters an interrupt phase and stops the hardware timing.
  • the processor is used to:
  • the virtual timer refresh phase it is determined whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, the corresponding application task is executed; if not, the corresponding application task is not executed;
  • the hardware timer is caused to enter a hardware timer start phase and the timing reference value is updated according to the shortest timing time and the longest timing time of the hardware timer, and the interrupt phase is exited to restart the hardware timer.
  • the interrupt phase is entered and the hardware timer is stopped; in the virtual timer refresh phase, it is determined whether there is an arrival timing in the virtual timer queue.
  • a virtual timer of time if so, executing a corresponding application task; if not, executing the corresponding application task; according to the consumption between the stop and the previous start before the hardware timer enters the interrupt phase Determining that the entry interrupt phase starts from the time when the hardware timer is stopped, the shortest timing time in the virtual timer queue; entering the hardware timer startup phase and according to the shortest timing time and the longest hardware timer The timing reference value is updated, and the interrupt phase is exited to restart the hardware timer, thereby reducing the refresh frequency of the virtual timer resource, thereby ensuring the lower usage rate of the CPU, thereby effectively improving the performance of the processor. Reduce the burden on the processor.
  • the timing of the virtual timer is separated from the operating system, and is common to different operating systems, thereby avoiding the need to use a virtual timer. A waste of CPU resources caused by the smallest kernel of the operating system.
  • Embodiment 1 is a schematic diagram of an initialization process in Embodiment 1 of the present application.
  • FIG. 2 is a schematic flowchart of a virtual timer starting phase in the second embodiment of the present application.
  • FIG. 3 is a schematic flowchart of stopping a hardware timer in Embodiment 3 of the present application.
  • FIG. 4 is a schematic flowchart of inserting a virtual timer in Embodiment 4 of the present application.
  • FIG. 5 is a schematic flowchart of a virtual timer refreshing phase in Embodiment 5 of the present application.
  • FIG. 7 is a schematic flowchart of a timing method of a virtual timer in Embodiment 7 of the present application.
  • FIG. 9 is a schematic structural diagram of a timing device of a virtual timer in Embodiment 9 of the present application.
  • the hardware timer provides a timing reference for the virtual timer.
  • Each virtual timer has a unique ID number and multiple virtual
  • the timer forms a virtual timer resource that can participate in the scheduled task.
  • the virtual timer that completes the scheduled task is deleted from the virtual timer queue and re-enters the virtual timer. In the resource.
  • the first structure body Before performing the following timing method, first defining a structure (for example, a first structure body) for each virtual timer, the first structure body includes a plurality of first attribute elements, for example, including: Whether the virtual timer has been used (indicated by used_flag), the attribute element that records the timing of any virtual timer (represented by remaining_ms), whether any virtual timer is a periodic virtual timer or a single-shot The flag bit of the virtual timer (represented by reload_flag), the attribute element (represented by reload_ms) that records the timing of the periodic virtual timer.
  • used_flag the attribute element that records the timing of any virtual timer
  • remaining_ms whether any virtual timer is a periodic virtual timer or a single-shot
  • the flag bit of the virtual timer represented by reload_flag
  • the attribute element represented by reload_ms
  • two global variables are exemplarily defined: virtual setting a timer variable (represented by sw_timer_head) and a time-consuming variable (represented by past_time_ms), wherein: the virtual timer header file includes at least one of the first structure body and the second structure header; the time-consuming variable is used for Record the time between the hardware timer and the most recent start before stopping.
  • the virtual timer and the hardware timer may be initialized first.
  • the specific initialization process refer to FIG. 1 .
  • the two global variables are: a virtual timer header variable sw_timer_head, and a time-consuming variable past_time_ms, since the virtual timer header file includes at least one of the first structure body and the second structure header, and the first structure body is Including the plurality of first attribute elements, the second structure body further includes the plurality of second attribute elements, and therefore, initializing the partial or all of the first attribute elements, part or all of the second attribute elements by initializing the global variables, This prepares for the timing execution of subsequent scheduled tasks.
  • the implementation of the virtual timer timing task is finally ensured, and the working mode of the hardware timer may be a comparison mode or an overflow mode.
  • the virtual timer is started. For details, see Figure 2. It should be noted that the new timed task includes the first timed task, or there is a timed task, and the new timed task is added.
  • FIG. 2 is a schematic flowchart of a virtual timer starting phase in the second embodiment of the present application; as shown in FIG. 2, the method includes the following steps S201 to S210:
  • the timing time threshold has an upper threshold and a lower threshold, and correspondingly, whether the timing time matched by the new timing task is reasonable according to the upper threshold and the lower threshold. If the timing time matched by the new timing task is within a range defined by the upper threshold and the lower threshold (including the endpoint), the timing of matching the new timing task is reasonable; otherwise, it is unreasonable.
  • the upper threshold and the lower threshold may be adjusted according to actual application requirements.
  • min_delay_ms represents a lower limit of the threshold
  • max_delay_ms represents an upper limit of the threshold
  • delay_ms represents a timing time at which the new timing task matches.
  • step S202 Determine whether there is an unused virtual timer in the virtual timer resource. If yes, execute step S203; otherwise, return a virtual timer resource that does not have an unused virtual timer;
  • the number of virtual timers for executing each timing task in the virtual timer queue is obtained by reading the value from the attribute element used_sw_timer, and the maximum number of virtual timers in the virtual timer resource is obtained from the attribute element SW_TIMER_CNT, if from the used_sw_timer If the read value is less than the value read from SW_TIMER_CNT, it is determined that there is an unused virtual timer in the virtual timer resource; if the value read from used_sw_timer is equal to the value read from SW_TIMER_CNT, the virtual timer is determined. There are no unused virtual timers in the resource.
  • the hardware timer is stopped in step S203 because a virtual timer is inserted in the virtual timer queue to redetermine the timing reference value of the hardware timer.
  • step S203 can be as shown in FIG. 3.
  • FIG. 3 is a schematic flowchart of stopping a hardware timer in Embodiment 3 of the present application. As shown in FIG. 3, it includes the following steps S213 to S223.
  • step S204 may be as shown in FIG. 4.
  • FIG. 4 is a schematic flowchart of inserting a virtual timer in Embodiment 4 of the present application. As shown in FIG. 4, it includes the following steps S214 to S244.
  • the virtual timers are sorted according to the timing time from short to long, the virtual timers with shorter timings are ranked in the virtual timer queue, and the virtual timers are long.
  • the unused virtual timer is searched in step S214, and the virtual timer queue is traversed from front to back until the first unused virtual timing is found.
  • the device can be used, and the unused virtual timer is used as the virtual timer used in the subsequent step S213.
  • the attribute element transmitted in step S234 includes: a flag bit used_flag of whether the virtual timer has been used, an attribute element remaining_ms of the timing time of the virtual timer, and an attribute element of the number of virtual timers participating in the timing task. Used_sw_timer and other attribute elements required to complete the above timing.
  • the registration process is actually equivalent to adding the incoming attribute element to the virtual timer queue to finally complete the insertion process of the virtual timer.
  • the timing time indicated by each virtual timer attribute element remaining_ms in the virtual timer queue when the hardware timer is stopped in step S203 is subtracted from the time-consuming variable past_time_ms used for recording in step S223.
  • the difference if the difference is less than or equal to 0, it means that the corresponding virtual timer is a virtual timer that reaches the timing time; in another specific application scenario, if the difference is smaller than the timing of the virtual timer Resolution, also indicates that the corresponding virtual The timer is a virtual timer that reaches the timing.
  • FIG. 5 is a schematic flowchart of a virtual timer refreshing phase in the fifth embodiment of the present application; as shown in FIG. 5, the method specifically includes the following steps S216 to S276:
  • step S226, traversing the difference between the virtual timers in the virtual timer queue, determine the virtual timer of the arrival time; if there is no virtual timer of the arrival time, then go to step S276;
  • the timing time of the arrival is configured as the timing time of the periodic virtual timer, and the process proceeds to step S276;
  • step S266 the virtual timer attribute of the arrival time is modified to have been used and is currently in the unused state, and the number of virtual timers used by the attribute element used_sw_timer is decreased by one; and the process proceeds to step S276;
  • step S276 may determine the shortest timing time in the virtual timer queue after inserting the virtual timer according to the minimum ID number of the virtual timer recorded by the attribute element latest_sw_timer_index.
  • step S208 can be omitted.
  • step S209 the specific implementation process of step S209 is as shown in FIG. 6.
  • S219 Determine the updated timing reference value according to a shortest timing time in the virtual timer queue after inserting the virtual timer and a maximum timing time of the hardware timer;
  • step S218 is specifically implemented by the following formula (2).
  • remain_ms is an attribute element for recording the virtual timer timing time
  • HARDWARE_MAX_DELAY_MS is an attribute element for recording the longest timing time of the hardware timer, and the updated minimum is obtained by obtaining the minimum values of the remaining_ms and HARDWARE_MAX_DELAY_MS.
  • the timing reference value is an attribute element for recording the virtual timer timing time
  • HARDWARE_MAX_DELAY_MS is an attribute element for recording the longest timing time of the hardware timer
  • the timing reference value of the hardware timer is related to the longest timing time of the hardware timer, and the timing reference value is related to the timing time of the virtual timer, the virtual timer resource has a longer timing time.
  • step S702 In the virtual timer refreshing phase, determine whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, execute step S703: execute the corresponding application task; if not, execute the corresponding application task, and then Go to step S705;
  • step S705 the process of entering the hardware timer startup phase in step S705 is similar to the above step S208. For details, refer to the related description above.
  • the interrupt phase when the interrupt phase is exited, the interrupt phase is exited according to the hardware interrupt flag after clearing. Since the hardware interrupt flag is cleared, after the update of the timing reference value is performed, the exit of the interrupt phase is ensured.
  • the virtual timer that arrives at the timing time and stops the timing is to be deleted from the virtual timer queue, correspondingly, the related attribute elements are to be maintained.
  • the timing module 902 is configured to determine, in the virtual timer refreshing phase, whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, execute the corresponding application task; if not, the corresponding application task is not executed;
  • the embodiment further provides an electronic device, comprising: a hardware timer, a plurality of virtual timers, and a processor, when the counting time of the hardware timer reaches its timing reference value, entering an interrupt phase and stopping the hardware a timer; the processor is used to:
  • the device embodiments described above are merely illustrative, wherein the modules described as separate components may or may not be physically separate, and the components displayed as modules may or may not be physical modules, ie may be located A place, or it can be distributed to multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment. Those of ordinary skill in the art can understand and implement without deliberate labor.
  • embodiments of the embodiments of the present application can be provided as a method, apparatus (device), or computer program product. Therefore, the embodiment of the present application can adopt an entirely hardware embodiment and is completely soft. An embodiment, or a combination of software and hardware aspects. Moreover, embodiments of the present application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) including computer usable program code.
  • computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

A timing method of a virtual timer, an apparatus thereof, and an electronic apparatus. The timing method comprises: if counting time of a hardware timer reaches its timing reference value, the hardware timer entering an interrupt phase and being stopped (S701); in a refresh phase of the virtual timer, determining whether there is a virtual timer in a virtual timer queue that reaches a timing time (S702); if so, executing a corresponding application task (S703); if not, the corresponding application task is not executed; determining, according to elapsed time between the stopping of the hardware timer and entering an interrupt phase and the previous latest start of the hardware timer, the shortest timing time for starting in the virtual timer queue from the time when the hardware timer is stopped entering the interrupt phase (S704); and entering a start-up phase of the hardware timer and updating, according to the shortest timing time and the longest timing time of the hardware timer, the timing reference value, and exiting the interrupt phase to restart the hardware timer (S705). By means of the method the performance of a processor is effectively improved and the burden of the processor is reduced.

Description

虚拟定时器的定时方法及其装置、电子装置Timing method of virtual timer, device thereof, and electronic device 技术领域Technical field
本申请实施例涉及定时器技术领域,尤其涉及一种虚拟定时器的定时方法及其装置、电子装置。The embodiments of the present invention relate to the field of timer technologies, and in particular, to a timing method, a device, and an electronic device of a virtual timer.
背景技术Background technique
常用的定时器可以分为硬件定时器和虚拟定时器(又称之为软件定时器)。硬件定时器具有精度高、实时性高的优点,但是对于处理器(CPU或者MCU)来说,硬件定时器的数量往往是有限的,因此难以满足需要大量定时器的场景;虚拟定时器可以满足需要大量定时器的场景,而不受硬件定时器个数的限制。Commonly used timers can be divided into hardware timers and virtual timers (also known as software timers). The hardware timer has the advantages of high precision and high real-time performance. However, for a processor (CPU or MCU), the number of hardware timers is often limited, so it is difficult to satisfy a scenario requiring a large number of timers; the virtual timer can satisfy A scenario that requires a large number of timers, and is not limited by the number of hardware timers.
在现有技术中,一方面,虚拟定时器需要按照其中作为基准时钟的硬件定时器的最小定时周期进行刷新,并判断虚拟定时器是否到达定时时间,由此可见,当硬件定时器的定时周期越小时,虚拟定时器刷新的就越为频繁,由此导致处理器资源的负担越大。另一方面,虚拟定时器常常是附带于操作系统之中,使用虚拟定时器资源往往需要移植操作系统的整个最小内核。而对于轻量级嵌入式应用来说,由于其处理器的资源有限,当应用在复杂应用场景下,使用虚拟定时器都得需要移植操作系统的整个最小内核的话,会加大处理器资源的浪费。In the prior art, on one hand, the virtual timer needs to be refreshed according to the minimum timing period of the hardware timer as the reference clock, and it is determined whether the virtual timer reaches the timing time, thereby showing that the timing period of the hardware timer is The smaller the hour, the more frequently the virtual timer is refreshed, thereby causing a greater burden on the processor resources. On the other hand, virtual timers are often attached to the operating system, and the use of virtual timer resources often requires the entire smallest kernel to be ported to the operating system. For lightweight embedded applications, due to the limited resources of the processor, when the application is used in a complex application scenario, the virtual timer needs to transplant the entire minimum kernel of the operating system, which will increase the processor resources. waste.
发明内容Summary of the invention
有鉴于此,本申请实施例所解决的技术问题之一在于提供一种虚拟定时器的定时方法及其装置、电子装置,用以克服现有技术中上述技术缺陷。In view of this, one of the technical problems to be solved by the embodiments of the present application is to provide a timing method, a device, and an electronic device for a virtual timer, which overcome the above technical defects in the prior art.
本申请实施例提供了一种虚拟定时器的定时方法,其包括:The embodiment of the present application provides a timing method for a virtual timer, including:
若硬件定时器的计数的时间到其定时基准值,则进入中断阶段并停止所述硬件定时器;If the time counted by the hardware timer reaches its timing reference value, the interrupt phase is entered and the hardware timer is stopped;
在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务;During the virtual timer refresh phase, it is determined whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, the corresponding application task is executed; if not, the corresponding application task is not executed;
根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;Determining the minimum timing time in the virtual timer queue from the time when the hardware timer stops from entering the interrupt phase according to the time between the stop and the previous start of the hardware timer when entering the interrupt phase ;
进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。Entering the hardware timer start phase and updating the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, exiting the interrupt phase to restart the hardware timer.
本申请实施例提供了一种虚拟定时器的定时装置,其包括:The embodiment of the present application provides a timing device for a virtual timer, including:
中断模块,用于当硬件定时器的计数的时间到其定时基准值时,进入中断阶段并停止所述硬件定时器; An interrupt module, configured to enter an interrupt phase and stop the hardware timer when a time counted by the hardware timer reaches a timing reference value thereof;
定时模块,用于在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务;The timing module is configured to determine, in the virtual timer refreshing phase, whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, execute the corresponding application task; if not, the corresponding application task is not executed;
刷新模块,用于根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;a refreshing module, configured to determine, according to the elapsed time between the stop and the previous start of the hardware timer when entering the interrupt phase, entering the interrupt phase to start the virtual timer queue from a time when the hardware timer stops The shortest time in the middle;
启动模块,用于进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。And a startup module, configured to enter a hardware timer startup phase and update the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, and exit the interrupt phase to restart the hardware timer.
本申请实施例提供了一种电子装置,其包括:硬件定时器、若干个虚拟定时器、处理器,当硬件定时器的计数的时间到其定时基准值时进入中断阶段并停止所述硬件定时器;所述处理器用于:The embodiment of the present application provides an electronic device, including: a hardware timer, a plurality of virtual timers, and a processor, when the counted time of the hardware timer reaches its timing reference value, enters an interrupt phase and stops the hardware timing. The processor is used to:
在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务;During the virtual timer refresh phase, it is determined whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, the corresponding application task is executed; if not, the corresponding application task is not executed;
根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;Determining the minimum timing time in the virtual timer queue from the time when the hardware timer stops from entering the interrupt phase according to the time between the stop and the previous start of the hardware timer when entering the interrupt phase ;
使得硬件定时器进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。The hardware timer is caused to enter a hardware timer start phase and the timing reference value is updated according to the shortest timing time and the longest timing time of the hardware timer, and the interrupt phase is exited to restart the hardware timer.
本申请实施例的中,若硬件定时器的计数的时间到其定时基准值,则进入中断阶段并停止所述硬件定时器;在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务;根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器,从而降低了虚拟定时器资源的刷新频率,从而保证CPU的使用率越低,因此有效提高了处理器的性能,减小处理器的负担。In the embodiment of the present application, if the counted time of the hardware timer reaches its timing reference value, the interrupt phase is entered and the hardware timer is stopped; in the virtual timer refresh phase, it is determined whether there is an arrival timing in the virtual timer queue. a virtual timer of time; if so, executing a corresponding application task; if not, executing the corresponding application task; according to the consumption between the stop and the previous start before the hardware timer enters the interrupt phase Determining that the entry interrupt phase starts from the time when the hardware timer is stopped, the shortest timing time in the virtual timer queue; entering the hardware timer startup phase and according to the shortest timing time and the longest hardware timer The timing reference value is updated, and the interrupt phase is exited to restart the hardware timer, thereby reducing the refresh frequency of the virtual timer resource, thereby ensuring the lower usage rate of the CPU, thereby effectively improving the performance of the processor. Reduce the burden on the processor.
另外,在可选实施例中,通过定义全局变量以及虚拟定时器属性元素,使得虚拟定时器的定时脱离了操作系统,而且通用于不同的操作系统,从而避免了要使用虚拟定时器就需要移植操作系统的最小内核导致的CPU资源浪费。In addition, in an optional embodiment, by defining a global variable and a virtual timer attribute element, the timing of the virtual timer is separated from the operating system, and is common to different operating systems, thereby avoiding the need to use a virtual timer. A waste of CPU resources caused by the smallest kernel of the operating system.
附图说明DRAWINGS
后文将参照附图以示例性而非限制性的方式详细描述本申请实施例的一些具体实施例。附图中相同的附图标记标示了相同或类似的部件或部分。本领域技术人员应该理解,这些附图未必是按比例绘制的。附图中:Some specific embodiments of the embodiments of the present application will be described in detail, by way of example, and not limitation, The same reference numbers in the drawings identify the same or similar parts. Those skilled in the art should understand that the drawings are not necessarily drawn to scale. In the figure:
图1为本申请实施例一中初始化流程示意图;1 is a schematic diagram of an initialization process in Embodiment 1 of the present application;
图2为本申请实施例二中虚拟定时器启动阶段的流程示意图; 2 is a schematic flowchart of a virtual timer starting phase in the second embodiment of the present application;
图3为本申请实施例三中停止硬件定时器的流程示意图;3 is a schematic flowchart of stopping a hardware timer in Embodiment 3 of the present application;
图4为本申请实施例四中插入虚拟定时器的流程示意图;4 is a schematic flowchart of inserting a virtual timer in Embodiment 4 of the present application;
图5为本申请实施例五中虚拟定时器刷新阶段的流程示意图;FIG. 5 is a schematic flowchart of a virtual timer refreshing phase in Embodiment 5 of the present application;
图6为本申请实施例六中硬件定时器启动阶段的流程示意图;6 is a schematic flowchart of a hardware timer startup phase in Embodiment 6 of the present application;
图7为本申请实施例七中虚拟定时器的定时方法流程示意图;7 is a schematic flowchart of a timing method of a virtual timer in Embodiment 7 of the present application;
图8为本申请实施例八中虚拟定时器的停止处理流程图;8 is a flowchart of stopping processing of a virtual timer in Embodiment 8 of the present application;
图9为本申请实施例九中虚拟定时器的定时装置的结构示意图。FIG. 9 is a schematic structural diagram of a timing device of a virtual timer in Embodiment 9 of the present application.
具体实施方式Detailed ways
实施本申请实施例的任一技术方案必不一定需要同时达到以上的所有优点。Any technical solution of implementing the embodiments of the present application necessarily does not necessarily need to achieve all the above advantages at the same time.
为了使本领域的人员更好地理解本申请实施例中的技术方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅是本申请实施例一部分实施例,而不是全部的实施例。基于本申请实施例中的实施例,本领域普通技术人员所获得的所有其他实施例,都应当属于本申请实施例保护的范围。For a better understanding of the technical solutions in the embodiments of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present application. The embodiments are only a part of the embodiments of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by those skilled in the art should be within the scope of protection of the embodiments of the present application based on the embodiments in the embodiments of the present application.
本申请下述实施例中,以具体应用为例,对本申请的技术按照应用的先后顺序进行说明,需要说明的是,下述示例性的先后顺序只是为了清楚地解释本本申请的技术方案,并非是具体限定为只能按照下述先后顺序执行。In the following embodiments of the present application, the specific application is taken as an example, and the technology of the present application is described in the order of application. It should be noted that the following exemplary sequence is only for clearly explaining the technical solution of the present application, and is not It is specifically limited to be executed in the following order.
以下以有一个硬件定时器以及多个可进行软件定时任务的虚拟定时器为例进行说明,硬件定时器为虚拟定时器提供定时基准,每个虚拟定时器具有一个唯一性ID号,多个虚拟定时器形成可参与定时任务的虚拟定时器资源,而当实际参与定时任务的部分虚拟定时器形成虚拟定时器队列,完成定时任务的虚拟定时器会从虚拟定时器队列中删除重新进入虚拟定时器资源中。The following is an example of a hardware timer and multiple virtual timers that can perform software timing tasks. The hardware timer provides a timing reference for the virtual timer. Each virtual timer has a unique ID number and multiple virtual The timer forms a virtual timer resource that can participate in the scheduled task. When a part of the virtual timer that actually participates in the scheduled task forms a virtual timer queue, the virtual timer that completes the scheduled task is deleted from the virtual timer queue and re-enters the virtual timer. In the resource.
需要说明的是,在具体应用场合,可以实际需要配置硬件定时器和虚拟定时器在数量上的对应关系,而具体的对应关系,本领域普通技术人员可以参照下述一个硬件定时器对应多个虚拟定时器的说明即可实现。It should be noted that, in a specific application, the corresponding relationship between the number of the hardware timers and the virtual timers may be actually configured, and the specific correspondence may be referred to by one of ordinary skill in the art by referring to one of the following hardware timers. A description of the virtual timer can be implemented.
在执行下述定时方法之前,首先定义了针对每一个虚拟定时器定一个结构体(比如称之为第一结构体),第一结构体包括多个第一属性元素,比如包括:表征任一虚拟定时器是否已经被使用的标志位(用used_flag表示)、记录任一虚拟定时器的定时时间的属性元素(用remain_ms表示)、表征任一虚拟定时器是周期性虚拟定时器还是单次性虚拟定时器的标志位(用reload_flag表示)、记录周期性虚拟定时器的定时时间的属性元素(用reload_ms表示)。Before performing the following timing method, first defining a structure (for example, a first structure body) for each virtual timer, the first structure body includes a plurality of first attribute elements, for example, including: Whether the virtual timer has been used (indicated by used_flag), the attribute element that records the timing of any virtual timer (represented by remaining_ms), whether any virtual timer is a periodic virtual timer or a single-shot The flag bit of the virtual timer (represented by reload_flag), the attribute element (represented by reload_ms) that records the timing of the periodic virtual timer.
为了方便对虚拟定时器进行管理,定义了另外一个结构体(比如称之为第二结构体),第二结构体也包括多个第二属性元素,比如包括:记录虚拟定时器队列中参与定时任务的虚拟定时器的个数的属性元素(用used_sw_timer表示)、记录虚拟定时器队列中参与定时任务的虚拟定时器的最小ID号的属性元素(用latest_sw_timer_index)、记录虚拟定时器资源中虚拟定时器最多个数的属性元素(用SW_TIMER_CNT表示)。In order to facilitate management of the virtual timer, another structure (such as a second structure) is defined, and the second structure also includes a plurality of second attribute elements, including, for example, recording the participation timing in the virtual timer queue. The attribute element of the number of virtual timers of the task (represented by used_sw_timer), the attribute element of the minimum ID number of the virtual timer participating in the scheduled task in the virtual timer queue (using latest_sw_timer_index), and the virtual timing in the virtual timer resource is recorded. The most number of attribute elements of the device (represented by SW_TIMER_CNT).
为了便于对上述结构体进行管理,示例性地定义了两个全局变量:虚拟定 时器头变量(用sw_timer_head表示)、耗时变量(用past_time_ms表示),其中:所述虚拟定时器头文件中包括上述第一结构体和第二结构头中至少其一;耗时变量用于记录硬件定时器在停止与该停止之前最近启动之间的耗时。In order to facilitate the management of the above structure, two global variables are exemplarily defined: virtual setting a timer variable (represented by sw_timer_head) and a time-consuming variable (represented by past_time_ms), wherein: the virtual timer header file includes at least one of the first structure body and the second structure header; the time-consuming variable is used for Record the time between the hardware timer and the most recent start before stopping.
本实施例中,通过定义上述全局变量以及第一结构体和第二结构体,使得虚拟定时器的定时脱离了操作系统,而且通用于不同的操作系统,从而避免了要使用虚拟定时器就需要移植操作系统的最小内核导致的CPU资源浪费。In this embodiment, by defining the global variable and the first structure and the second structure, the timing of the virtual timer is separated from the operating system, and is common to different operating systems, thereby avoiding the need to use a virtual timer. A waste of CPU resources caused by porting the smallest kernel of the operating system.
在利用本申请的定时方法时,可以首先对虚拟定时器和硬件定时器进行初始化,具体初始化流程请参见图1所示。When the timing method of the present application is utilized, the virtual timer and the hardware timer may be initialized first. For the specific initialization process, refer to FIG. 1 .
图1为本申请实施例一中初始化流程示意图;如图1所示,其包括如下步骤:1 is a schematic diagram of an initialization process in Embodiment 1 of the present application; as shown in FIG. 1, the method includes the following steps:
S101、初始化全局变量,其中包括第一结构体和第二结构体各自包括的属性元素;S101. Initialize a global variable, where the attribute element included in each of the first structure body and the second structure body is included;
具体地,两个全局变量分别为:虚拟定时器头变量sw_timer_head、耗时变量past_time_ms,由于虚拟定时器头文件包括上述第一结构体和第二结构头中至少其一,而第一结构体又包括上述多个第一属性元素、第二结构体又包括上述多个第二属性元素,因此,通过初始化全局变量从而实现上述部分或全部第一属性元素、部分或者全部第二属性元素的初始化,从而为后续有定时任务时的定时执行做好准备。Specifically, the two global variables are: a virtual timer header variable sw_timer_head, and a time-consuming variable past_time_ms, since the virtual timer header file includes at least one of the first structure body and the second structure header, and the first structure body is Including the plurality of first attribute elements, the second structure body further includes the plurality of second attribute elements, and therefore, initializing the partial or all of the first attribute elements, part or all of the second attribute elements by initializing the global variables, This prepares for the timing execution of subsequent scheduled tasks.
具体地,对全局变量进行初始化时,可以先对虚拟定时器头变量sw_timer_head进行初始化,再对耗时变量past_time_ms进行初始化;或者,也可以先对耗时变量past_time_ms进行初始化,再对虚拟定时器头变量sw_timer_head进行初始化;或者,还可以对虚拟定时器头变量sw_timer_head进行初始化和耗时变量past_time_ms同时进行初始化。Specifically, when the global variable is initialized, the virtual timer header variable sw_timer_head may be initialized first, and then the time-consuming variable past_time_ms may be initialized; or, the time-consuming variable past_time_ms may be initialized first, and then the virtual timer header is initialized. The variable sw_timer_head is initialized; alternatively, the virtual timer header variable sw_timer_head can be initialized and the time-consuming variable past_time_ms can be initialized at the same time.
S102、初始化硬件定时器的工作模式。S102. Initialize an operating mode of the hardware timer.
本实施例中,为了实现硬件定时器的定时功能,最终保证虚拟定时器定时任务的实现,硬件定时器的工作模式可以是比较模式,也可以是溢出模式。In this embodiment, in order to implement the timing function of the hardware timer, the implementation of the virtual timer timing task is finally ensured, and the working mode of the hardware timer may be a comparison mode or an overflow mode.
下述实施例中,以将硬件定时器的工作模式设置为硬件定时器计数的时间与设定的定时基准值进行比对,当到达硬件定时器的定时时间,进而进入比较中断阶段,最终实现虚拟定时器的定时任务。In the following embodiments, the time when the hardware timer is set to the hardware timer count is compared with the set timing reference value, and when the hardware timer is reached, the comparison interrupt phase is entered. The timing task of the virtual timer.
在一具体应用场景中,为了实现图1所示的初始化,可以预先定义一接口函数(比如void sw_timer_init(void)),通过该接口函数从而实现上述初始化过程。In a specific application scenario, in order to implement the initialization shown in FIG. 1, an interface function (such as void sw_timer_init(void)) may be defined in advance, and the initialization process is implemented by the interface function.
在完成上述图1的初始化流程后,若需要执行新定时任务时,则进入虚拟定时器启动阶段,详细过程请参见图2所示。需要说明的是,新定时任务包括首个定时任务,或者存在定时任务,而增加的新定时任务。After the initialization process of Figure 1 is completed, if a new scheduled task needs to be executed, the virtual timer is started. For details, see Figure 2. It should be noted that the new timed task includes the first timed task, or there is a timed task, and the new timed task is added.
图2为本申请实施例二中虚拟定时器启动阶段的流程示意图;如图2所示,其包括如下步骤S201至S210:2 is a schematic flowchart of a virtual timer starting phase in the second embodiment of the present application; as shown in FIG. 2, the method includes the following steps S201 to S210:
S201、判断所述新定时任务所需的定时时间是否合理,若是,则执行步骤 S202;若否,则返回所述新定时任务所需的定时时间无效的判断结果;S201. Determine whether the timing time required for the new scheduled task is reasonable. If yes, perform the step. S202; if not, returning a determination result that the timing time required for the new timing task is invalid;
本实施例中,具体根据设定的定时时间阈值判断所述新定时任务所匹配的定时时间是否合理。In this embodiment, it is determined whether the timing time matched by the new timing task is reasonable according to the set timing time threshold.
具体地,本实施例中,所述定时时间阈值具有阈值上限和阈值下限,对应地,根据所述阈值上限和阈值下限判断所述新定时任务所匹配的定时时间是否合理。若所述新定时任务所匹配的定时时间位于所述阈值上限和阈值下限限定的范围内(包括端点),则所述新定时任务所匹配的定时时间合理;否则,不合理。Specifically, in this embodiment, the timing time threshold has an upper threshold and a lower threshold, and correspondingly, whether the timing time matched by the new timing task is reasonable according to the upper threshold and the lower threshold. If the timing time matched by the new timing task is within a range defined by the upper threshold and the lower threshold (including the endpoint), the timing of matching the new timing task is reasonable; otherwise, it is unreasonable.
本实施例中,阈值上限和阈值下限可以实际应用需求进行调整。In this embodiment, the upper threshold and the lower threshold may be adjusted according to actual application requirements.
具体地,在一具体应用场景中可以如下公式(1)来进行所述新定时任务所需的定时时间是否合理的判断。Specifically, in a specific application scenario, whether the timing time required for the new timing task is reasonable may be determined by the following formula (1).
min_delay_ms<=delay_ms<=max_delay_ms     (1)Min_delay_ms<=delay_ms<=max_delay_ms (1)
公式(1)中,min_delay_ms表示阈值下限,max_delay_ms表示阈值上限,delay_ms表示所述新定时任务所匹配的定时时间。In the formula (1), min_delay_ms represents a lower limit of the threshold, max_delay_ms represents an upper limit of the threshold, and delay_ms represents a timing time at which the new timing task matches.
如公式(1)所示,新定时任务所匹配的定时时间等于阈值下限或者阈值上限,或者大于阈值下限而小于阈值上限,都可判定新定时任务所匹配的定时时间合理。As shown in the formula (1), the timing time matched by the new timing task is equal to the lower threshold or the upper threshold, or greater than the lower threshold and less than the upper threshold, and the timing time matched by the new timing task can be determined to be reasonable.
S202、判断虚拟定时器资源中是否还有未使用的虚拟定时器,若是,则执行步骤S203;否则,返回虚拟定时器资源不存在未使用的虚拟定时器;S202. Determine whether there is an unused virtual timer in the virtual timer resource. If yes, execute step S203; otherwise, return a virtual timer resource that does not have an unused virtual timer;
本实施例中,根据虚拟定时器队列中执行各定时任务的虚拟定时器数量以及虚拟定时器资源中虚拟定时器的最多个数,判断虚拟定时器资源中是否还有未使用的虚拟定时器。In this embodiment, it is determined whether there are any unused virtual timers in the virtual timer resource according to the number of virtual timers in each virtual timer queue and the maximum number of virtual timers in the virtual timer resource.
具体地,通过从属性元素used_sw_timer中读取数值获得虚拟定时器队列中执行各定时任务的虚拟定时器数量,从属性元素SW_TIMER_CNT中获得虚拟定时器资源中虚拟定时器的最多个数,若从used_sw_timer中读取数值小于从SW_TIMER_CNT中读取的数值,则判定虚拟定时器资源中还有未使用的虚拟定时器;若从used_sw_timer中读取数值等于从SW_TIMER_CNT中读取的数值,则判定虚拟定时器资源中没有未使用的虚拟定时器。Specifically, the number of virtual timers for executing each timing task in the virtual timer queue is obtained by reading the value from the attribute element used_sw_timer, and the maximum number of virtual timers in the virtual timer resource is obtained from the attribute element SW_TIMER_CNT, if from the used_sw_timer If the read value is less than the value read from SW_TIMER_CNT, it is determined that there is an unused virtual timer in the virtual timer resource; if the value read from used_sw_timer is equal to the value read from SW_TIMER_CNT, the virtual timer is determined. There are no unused virtual timers in the resource.
S203、在虚拟定时器启动阶段停止所述硬件定时器,并确定所述硬件定时器在虚拟定时器启动阶段停止到距离其最近的启动之间的耗时;S203. Stop the hardware timer in a virtual timer startup phase, and determine a time consuming between the hardware timer stopping in a virtual timer startup phase and a startup closest to it;
本实施例中,步骤S203中之所以要停止所述硬件定时器,是由于后续要在虚拟定时器队列中插入虚拟定时器,重新确定硬件定时器的定时基准值。In this embodiment, the hardware timer is stopped in step S203 because a virtual timer is inserted in the virtual timer queue to redetermine the timing reference value of the hardware timer.
具体地,本实施例中,步骤S203的详细示意性流程可如图3所示。Specifically, in this embodiment, the detailed schematic flow of step S203 can be as shown in FIG. 3.
图3为本申请实施例三中停止硬件定时器的流程示意图。如图3所示,其包括如下步骤S213至S223。FIG. 3 is a schematic flowchart of stopping a hardware timer in Embodiment 3 of the present application. As shown in FIG. 3, it includes the following steps S213 to S223.
S213、停止所述硬件定时器;S213. Stop the hardware timer.
本实施例中,具体可以通过使能信号停止所述硬件定时器或者关掉所述硬件定时器的时钟源。In this embodiment, the hardware timer may be stopped or the clock source of the hardware timer may be turned off by an enable signal.
S223、确定所述硬件定时器在虚拟定时器启动阶段停止到距离其最近的启动之间的耗时; S223. Determine a time consuming between the stopping of the hardware timer in a virtual timer startup phase and a startup from a closest time;
本实施例中,如果是加法计数的话,则在计算步骤S223中的耗时时,用步骤S213中的停止时间减去距离其最近的启动时间;如果是基于减法技术的话,则用距离其最近的启动时间减去步骤S213中的停止时间。In this embodiment, if it is the addition count, when the time consumption in step S223 is calculated, the start time from the nearest time is subtracted from the stop time in step S213; if it is based on the subtraction technique, the nearest distance is used. The start time is subtracted from the stop time in step S213.
进一步地,在得到步骤S223中的耗时,将对应的数值赋值给耗时变量past_time_ms。Further, when the time consumption in step S223 is obtained, the corresponding value is assigned to the time-consuming variable past_time_ms.
本实施例中,步骤S213在步骤S223之前执行,但是,在其他实施例中,步骤S223也可以在步骤S213执行。In this embodiment, step S213 is performed before step S223, but in other embodiments, step S223 may also be performed in step S213.
S204、从所述未使用的虚拟定时器中确定对应所述新定时任务的虚拟定时器并将其插入到所述虚拟定时器队列中。S204. Determine a virtual timer corresponding to the new timing task from the unused virtual timer and insert it into the virtual timer queue.
本实施例中,步骤S204的示例性具体流程可如图4所示。In this embodiment, an exemplary specific process of step S204 may be as shown in FIG. 4.
图4为本申请实施例四中插入虚拟定时器的流程示意图。如图4所示,其包括如下步骤S214至步骤S244。FIG. 4 is a schematic flowchart of inserting a virtual timer in Embodiment 4 of the present application. As shown in FIG. 4, it includes the following steps S214 to S244.
S214、在虚拟定时器队列中寻找未使用的虚拟定时器;S214. Search for an unused virtual timer in the virtual timer queue.
具体地,若虚拟定时器队列中按照定时时间由短到长对虚拟定时器进行排序的话,即定时时间较短的虚拟定时器在虚拟定时器队列中的排序靠前,而定时时间长的虚拟定时器在虚拟定时器队列中的排序靠后,则本实施例中,在步骤S214中寻找未使用的虚拟定时器,从前到后遍历虚拟定时器队列直至寻找到第一个未使用的虚拟定时器即可,并将该未使用的虚拟定时器作为后续步骤S213中使用的虚拟定时器。Specifically, if the virtual timers are sorted according to the timing time from short to long, the virtual timers with shorter timings are ranked in the virtual timer queue, and the virtual timers are long. After the timer is sorted in the virtual timer queue, in this embodiment, the unused virtual timer is searched in step S214, and the virtual timer queue is traversed from front to back until the first unused virtual timing is found. The device can be used, and the unused virtual timer is used as the virtual timer used in the subsequent step S213.
S224、更新虚拟定时器中虚拟定时器的使用个数;S224. Update the number of virtual timers used in the virtual timer.
具体地,如前所述,通过步骤S224相当于修改属性元素used_sw_timer的数值,本实施例,在更新前的基础上,增加属性元素used_sw_timer的数值;比如插入一个虚拟定时器的话,则属性元素used_sw_timer的数值加一。Specifically, as described above, the value of the attribute element used_sw_timer is modified by the step S224. In this embodiment, the value of the attribute element used_sw_timer is added on the basis of the update; for example, if a virtual timer is inserted, the attribute element used_sw_timer Add one to the value.
S234、根据步骤S214中确定的虚拟定时器以及传入的属性元素在虚拟定时器队列中注册新的虚拟定时器;S234. Register a new virtual timer in the virtual timer queue according to the virtual timer determined in step S214 and the incoming attribute element.
本实施例中,步骤S234中传输的属性元素包括:虚拟定时器是否已经被使用的标志位used_flag、虚拟定时器的定时时间的属性元素remain_ms、参与定时任务的虚拟定时器的个数的属性元素used_sw_timer等上述完成定时所需要的各属性元素。In this embodiment, the attribute element transmitted in step S234 includes: a flag bit used_flag of whether the virtual timer has been used, an attribute element remaining_ms of the timing time of the virtual timer, and an attribute element of the number of virtual timers participating in the timing task. Used_sw_timer and other attribute elements required to complete the above timing.
本实施例中,注册的过程实际上相当于将传入的属性元素添加到虚拟定时器队列中以最终完成虚拟定时器的插入处理。In this embodiment, the registration process is actually equivalent to adding the incoming attribute element to the virtual timer queue to finally complete the insertion process of the virtual timer.
S244、返回虚拟定时器插入成功的结果。S244. Return a successful result of the virtual timer insertion.
S205、在虚拟定时器刷新阶段判断虚拟定时器队列中是否有到达定时时间的虚拟定时器,若有,则执行步骤S206:执行对应的应用任务;若无,则不执行对应的应用任务;S205, determining, in the virtual timer refreshing phase, whether there is a virtual timer that reaches a timing time in the virtual timer queue, if yes, executing step S206: executing a corresponding application task; if not, executing the corresponding application task;
本实施例中,具体地,将在步骤S203中停止硬件定时器时虚拟定时器队列中各虚拟定时器属性元素remain_ms表示的定时时间减去用于记录步骤S223中得到耗时的耗时变量past_time_ms的数值;在一具体应用场景中,若差值小于等于0,则表示对应虚拟定会器为到达定时时间的虚拟定时器;在另外一具体应用场景中,若差值小于虚拟定时器的定时分辨率,同样也表示对应虚拟定 会器为到达定时时间的虚拟定时器。In this embodiment, specifically, the timing time indicated by each virtual timer attribute element remaining_ms in the virtual timer queue when the hardware timer is stopped in step S203 is subtracted from the time-consuming variable past_time_ms used for recording in step S223. In a specific application scenario, if the difference is less than or equal to 0, it means that the corresponding virtual timer is a virtual timer that reaches the timing time; in another specific application scenario, if the difference is smaller than the timing of the virtual timer Resolution, also indicates that the corresponding virtual The timer is a virtual timer that reaches the timing.
S207、根据所述硬件定时器在虚拟定时器启动阶段停止到距离该停止最近的启动之间的耗时,确定在插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间;S207. Determine a minimum timing time in the virtual timer queue after inserting the virtual timer according to a time interval between the stopping of the hardware timer in the virtual timer startup phase and the startup from the stop.
本实施例中,在一具体应用场景中,上述步骤S205和步骤S207可以在进入虚拟定时器刷新阶段;In this embodiment, in a specific application scenario, the foregoing step S205 and step S207 may be in a virtual timer refresh phase;
图5为本申请实施例五中虚拟定时器刷新阶段的流程示意图;如图5所示,其具体包括如下步骤S216至S276:FIG. 5 is a schematic flowchart of a virtual timer refreshing phase in the fifth embodiment of the present application; as shown in FIG. 5, the method specifically includes the following steps S216 to S276:
S216、遍历虚拟定时器队列,将在步骤S203中停止硬件定时器时虚拟定时器队列中各虚拟定时器属性元素remain_ms表示的定时时间减去用于记录步骤S223中得到耗时的耗时变量past_time_ms的数值得到若干个差值;S216. Traverse the virtual timer queue, and subtract the time-consuming variable past_time_ms used for recording the time-consuming variable obtained in step S223 from the timing time indicated by each virtual timer attribute element remaining_ms in the virtual timer queue when the hardware timer is stopped in step S203. The value of the obtained a number of differences;
S226、遍历虚拟定时器队列中各虚拟定时器对应的差值,确定到达定时时间的虚拟定时器;若无到达定时时间的虚拟定时器,则跳转到步骤S276;S226, traversing the difference between the virtual timers in the virtual timer queue, determine the virtual timer of the arrival time; if there is no virtual timer of the arrival time, then go to step S276;
在一具体应用场景中,若差值小于等于0,则表示对应虚拟定会器为到达定时时间的虚拟定时器;在另外一具体应用场景中,若差值小于虚拟定时器的定时分辨率,同样也表示对应虚拟定会器为到达定时时间的虚拟定时器。In a specific application scenario, if the difference is less than or equal to 0, it indicates that the virtual timer is a virtual timer that arrives at the timing time; in another specific application scenario, if the difference is smaller than the timing resolution of the virtual timer, It also indicates that the virtual timer is a virtual timer that arrives at the timing time.
S236、执行到达定时时间的虚拟定时器对应的应用任务;S236. Perform an application task corresponding to a virtual timer that reaches a timing time.
S246、判断到达定时时间的虚拟定时器是周期性虚拟定时器还是单次性虚拟定时器;若到达定时时间的虚拟定时器是周期性虚拟定时器,则执行步骤S256;否则执行步骤S266;S246, determining whether the virtual timer of the arrival time is a periodic virtual timer or a one-time virtual timer; if the virtual timer that reaches the timing is a periodic virtual timer, step S256 is performed; otherwise, step S266 is performed;
S256、将所述到达的定时时间配置为所述周期性虚拟定时器的定时时间,并跳转到步骤S276;S256, the timing time of the arrival is configured as the timing time of the periodic virtual timer, and the process proceeds to step S276;
本实施例中,步骤S256具体实现为:将所述到达的定时时间赋值给属性元素reload_ms再将属性元素reload_ms的数值赋值给用于记录所述周期性虚拟定时器定时时间的remain_ms。In this embodiment, step S256 is specifically implemented as: assigning the arrived timing time to the attribute element reload_ms and assigning the value of the attribute element reload_ms to the remaining_ms for recording the periodic virtual timer timing time.
S266、将到达定时时间的虚拟定时器属性修改为已使用结束且目前处于未使用状态,同时将属性元素used_sw_timer表示的虚拟定时器使用个数减一;并跳转到步骤S276;S266, the virtual timer attribute of the arrival time is modified to have been used and is currently in the unused state, and the number of virtual timers used by the attribute element used_sw_timer is decreased by one; and the process proceeds to step S276;
为虚拟定时器配置有是否使用的上述标志位used_flag,修改所述标志位used_flag的值,以表示到达定时时间的虚拟定时器配置为已使用结束且目前处于未使用状态。The virtual timer is configured with the above flag bit used_flag, and the value of the flag used_flag is modified to indicate that the virtual timer of the arrival timing is configured to be used and is currently in an unused state.
S276、所述硬件定时器在虚拟定时器启动阶段停止到距离该停止最近的启动之间的耗时,确定在插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间。S276. The time between the hardware timer stopping in the virtual timer startup phase and the startup closest to the stop, determining the shortest timing time in the virtual timer queue after inserting the virtual timer.
本实施例中,步骤S276的具体实现可根据属性元素latest_sw_timer_index记录的虚拟定时器的最小ID号确定在插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间。In this embodiment, the specific implementation of step S276 may determine the shortest timing time in the virtual timer queue after inserting the virtual timer according to the minimum ID number of the virtual timer recorded by the attribute element latest_sw_timer_index.
S208、判断所述虚拟定时器队列中是否还存在执行定时任务的虚拟定时器,若是,则执行步骤S209;否则,执行步骤S210;S208, determining whether there is still a virtual timer for executing the timing task in the virtual timer queue, and if yes, executing step S209; otherwise, executing step S210;
本实施例中,具体可以通过属性元素used_sw_timer的数值来判定,如果 其值非0,表示还存在执行的定时任务的虚拟定时器;如果其值为0则表示不存在执行定时任务的虚拟定时器。In this embodiment, the value of the attribute element used_sw_timer may be specifically determined. Its value is non-zero, indicating that there is still a virtual timer for the executed timing task; if its value is 0, it means that there is no virtual timer for executing the timing task.
在另外一实施例中,步骤S208可以省略。In another embodiment, step S208 can be omitted.
S209、重新进入硬件定时器启动阶段,并根据在插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,并在虚拟定时器启动阶段重新启动所述硬件定时器。S209. Re-enter the hardware timer startup phase, and update the timing reference value according to the shortest timing time in the virtual timer queue after inserting the virtual timer and the longest timing time of the hardware timer, and in the virtual The hardware timer is restarted during the timer start phase.
本实施例中,步骤S209的具体实现过程如图6所示。In this embodiment, the specific implementation process of step S209 is as shown in FIG. 6.
图6为本申请实施例六中硬件定时器启动阶段的流程示意图;如图6所示,器包括如下步骤S219至S239:6 is a schematic flowchart of a hardware timer startup phase in the sixth embodiment of the present application; as shown in FIG. 6, the device includes the following steps S219 to S239:
S219、根据在插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间以及所述硬件定时器的最长定时时间确定更新后的所述定时基准值;S219: Determine the updated timing reference value according to a shortest timing time in the virtual timer queue after inserting the virtual timer and a maximum timing time of the hardware timer;
本实施例中,具体通过如下公式(2)实现上述步骤S218。In the embodiment, the above step S218 is specifically implemented by the following formula (2).
cmp_val=MIN(remain_ms,HARDWARE_MAX_DELAY_MS)   (2)Cmp_val=MIN(remain_ms, HARDWARE_MAX_DELAY_MS) (2)
上述公式(2)中,remain_ms为记录虚拟定时器定时时间的属性元素,HARDWARE_MAX_DELAY_MS为记录硬件定时器的最长定时时间的属性元素,通过求取remain_ms和HARDWARE_MAX_DELAY_MS的最小值,从而得到更新后的所述定时基准值。In the above formula (2), remain_ms is an attribute element for recording the virtual timer timing time, and HARDWARE_MAX_DELAY_MS is an attribute element for recording the longest timing time of the hardware timer, and the updated minimum is obtained by obtaining the minimum values of the remaining_ms and HARDWARE_MAX_DELAY_MS. The timing reference value.
本实施例中,对于上述公式(2)来说,可能但不限于具有两种情形:In this embodiment, for the above formula (2), it may be, but is not limited to, having two situations:
一种情况下,当插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间大于硬件定时器的最长定时时间时,由于在执行定时任务时,当达到硬件定时器的最大定时,虚拟定时器的定时时间还没有统计完,此时也会产生上述的新定时任务,且之后需要刷新软件定时器资源。由于虚拟定时器队列会发生变化,因此,所以需要重新启动硬件定时器;另外一种情况下,当插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间大于硬件定时器的最长定时时间时,此时由于最短定时时间到达时,硬件定时器的最长定时时间还未到,同样由于虚拟定时器队列会发生变化,因此需要刷新软件定时器资源,并需要重新启动硬件定时器。In one case, when the shortest timing time in the virtual timer queue after inserting the virtual timer is greater than the longest timing time of the hardware timer, since the maximum timing of the hardware timer is reached when the timing task is executed, the virtual The timer time has not been counted yet. At this time, the new timing task described above is also generated, and the software timer resource needs to be refreshed later. Since the virtual timer queue changes, the hardware timer needs to be restarted. In another case, the shortest timing time in the virtual timer queue after inserting the virtual timer is greater than the longest timer of the hardware timer. At the time, when the shortest timing time arrives, the longest timer time of the hardware timer has not yet arrived. Also, since the virtual timer queue changes, it is necessary to refresh the software timer resource and restart the hardware timer.
由此可见,由于硬件定时器的定时基准值与硬件定时器的最长定时时间有关,而定时基准值由于虚拟定时器的定时时间有关,虚拟定时器的定时时间越长时,虚拟定时器资源的刷新频率越低,从而保证CPU的使用率越低,因此有效提高了处理器的性能,减小处理器的负担。It can be seen that since the timing reference value of the hardware timer is related to the longest timing time of the hardware timer, and the timing reference value is related to the timing time of the virtual timer, the virtual timer resource has a longer timing time. The lower the refresh rate, the lower the CPU usage, thus effectively improving the performance of the processor and reducing the burden on the processor.
S229、将所述更新后的所述定时基准值填入到硬件定期器包括的比较器中,以完成所述定时基准值的更新;S229. Fill the updated timing reference value into a comparator included in the hardware scheduler to complete the update of the timing reference value.
S239、使能所述硬件定时器。S239. Enable the hardware timer.
本实施例中,具体通过使能信号使能所述硬件定时器,以重新启动所述硬件定时器。In this embodiment, the hardware timer is specifically enabled by an enable signal to restart the hardware timer.
S210、跳转到生成虚拟定时器启动成功的结果。S210. Jump to the result that the generation of the virtual timer is successfully started.
本实施例中,在具体实现上述虚拟定时器的启动时,可以预先定义对应的接口函数,示例性地,比如uint16_t sw_timer_start(uint8_t reload_flag,uint32_t time_ms,uint8_t*p_timer_id),其中,reload_flag如前所述为表征任一虚拟定时 器是周期性虚拟定时器还是单次性虚拟定时器的标志位,time_ms表示新定时任务对应的定时时间,*p_timer_id表示插入的虚拟定时器器的ID号。在上述步骤S234传入属性元素也一并将这些属性元素添加到虚拟定时器队列中,其中需要说明的是,并将time_ms的数值赋值给remain_ms。In this embodiment, when the startup of the virtual timer is specifically implemented, a corresponding interface function may be defined in advance, for example, uint16_t sw_timer_start(uint8_t reload_flag, uint32_t time_ms, uint8_t*p_timer_id), where reload_flag is as described above. To characterize any virtual timing Whether it is a periodic virtual timer or a single-time virtual timer flag, time_ms indicates the timing time corresponding to the new timing task, and *p_timer_id indicates the ID number of the inserted virtual timer. The attribute elements are also passed in the above step S234 and added to the virtual timer queue. It should be noted that the value of time_ms is assigned to the remaining_ms.
在完成上述初始化相关之后,以及虚拟定时器和硬件定时器的启动之后,就可以执行完整的定时处理过程。After the above initialization correlation is completed, and after the start of the virtual timer and hardware timer, the complete timing process can be performed.
图7为本申请实施例七中虚拟定时器的定时方法流程示意图;如图7所示,其包括如下步骤S701至S705:FIG. 7 is a schematic flowchart of a method for timing a virtual timer according to Embodiment 7 of the present application; as shown in FIG. 7, the method includes the following steps S701 to S705:
S701、若所述硬件定时器的计数的时间到其定时基准值,则进入中断阶段并停止所述硬件定时器;S701. If the time of counting the hardware timer reaches its timing reference value, enter an interrupt phase and stop the hardware timer.
本实施例中,若所述硬件定时器的计数的时间与定时基准值的差值为0,则所述硬件定时器的计数的时间到其定时基准值。In this embodiment, if the difference between the counted time of the hardware timer and the timing reference value is 0, the counted time of the hardware timer reaches its timing reference value.
本实施例中,所述进入硬件中断阶段之后,停止所述硬件定时器之前,还包括:清除硬件中断标志位;In this embodiment, after the entering the hardware interrupt phase, before stopping the hardware timer, the method further includes: clearing a hardware interrupt flag bit;
S702、在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有则执行步骤S703:执行对应的应用任务;若无,则不执行对应的应用任务,之后进入步骤S705;S702: In the virtual timer refreshing phase, determine whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, execute step S703: execute the corresponding application task; if not, execute the corresponding application task, and then Go to step S705;
本步骤在刷新阶段判断虚拟定时器队列中是否有到达定时时间的虚拟定时器的实现类似上述步骤S205,详细请参见上述相关记载。In this step, it is determined that the virtual timer of the virtual timer queue has the arrival timing time in the refreshing phase. The implementation of the virtual timer is similar to the above step S205. For details, refer to the related description.
S704、根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;S704. Determine, according to the elapsed time between the stop and the previous start of the hardware timer when entering the interrupt phase, the entry interrupt phase starts from the time when the hardware timer stops, and the shortest in the virtual timer queue. Timing;
本实施例中,步骤S704确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间类似上述步骤S207,详细请参见上述相关记载。In this embodiment, the step S704 determines that the shortest timing time in the virtual timer queue from the time when the hardware timer is stopped in the interruption phase is similar to the above step S207. For details, refer to the related description.
S705、进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。S705. Enter a hardware timer startup phase and update the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, and exit the interrupt phase to restart the hardware timer.
本实施例中,步骤S705进入硬件定时器启动阶段的处理类似上述步骤S208,详细请参见上述相关记载。In this embodiment, the process of entering the hardware timer startup phase in step S705 is similar to the above step S208. For details, refer to the related description above.
本实施例中,退出中断阶段时根据清除后硬件中断标志位退出中断阶段,由于清除了硬件中断标志位,在执行完更新所述定时基准值后,从而保证了中断阶段的退出。In this embodiment, when the interrupt phase is exited, the interrupt phase is exited according to the hardware interrupt flag after clearing. Since the hardware interrupt flag is cleared, after the update of the timing reference value is performed, the exit of the interrupt phase is ensured.
需要说明的是,在其他一实施例中,所述执行对应的应用任务之后,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间之前,还包括:当到达定时时间的虚拟定时器为周期性虚拟定时器时,将所述到达的定时时间配置为所述周期性虚拟定时器的定时时间;当到达定时时间的虚拟定时器为单次性虚拟定时器时,将到达定时时间的虚拟定时器属性 修改为已使用结束且目前处于未使用状态。该属性修改依赖于对标志位used_flag的数值进行修改来实现。It should be noted that, in another embodiment, after the performing the corresponding application task, determining that the entering the interrupt phase starts from the time when the hardware timer stops, before the shortest timing time in the virtual timer queue, further includes When the virtual timer that reaches the timing is a periodic virtual timer, the timing of the arrival is configured as the timing of the periodic virtual timer; when the virtual timer that reaches the timing is a single virtual When the timer expires, the virtual timer attribute of the timed time will be reached. Modified to use ended and is currently in an unused state. This attribute modification is implemented by modifying the value of the flag used_flag.
进一步地,当到达定时时间的虚拟定时器为单次性虚拟定时器时,还包括:停止并从所述虚拟定时器队列中删除到达定时时间的虚拟定时器。Further, when the virtual timer that reaches the timing time is a one-time virtual timer, the method further includes: stopping and deleting the virtual timer that reaches the timing time from the virtual timer queue.
在一具体实现中,为实现上述图7的处理,可配置一函数,比如为void timerA_isr_handler(void)。In a specific implementation, to implement the processing of FIG. 7 above, a function may be configured, such as void timerA_isr_handler(void).
虚拟定时器的停止处理具体请参见图8所示的虚拟定时器处理流程实现。图8为本申请实施例八中虚拟定时器的停止处理流程图。如图8所示,其包括如下步骤S811-S817:For details on how to stop the virtual timer, see the virtual timer processing flow shown in Figure 8. FIG. 8 is a flowchart of stopping processing of a virtual timer in Embodiment 8 of the present application. As shown in FIG. 8, it includes the following steps S811-S817:
S811、进入虚拟定时器停止阶段并判断要停止的虚拟定时器的ID号是否有效;若有效,则执行步骤S812;若无效,则返回虚拟定时器的ID无效的结果;S811, entering a virtual timer stop phase and determining whether the ID number of the virtual timer to be stopped is valid; if valid, executing step S812; if invalid, returning a result that the virtual timer ID is invalid;
本实施例中,要停止的虚拟定时器的ID号若大于属性元素SW_TIMER_CNT表示的最大虚拟定时器数量,则判定无效。In this embodiment, if the ID number of the virtual timer to be stopped is greater than the maximum number of virtual timers indicated by the attribute element SW_TIMER_CNT, the determination is invalid.
比如,本实施例中,若停止的虚拟定时器的ID号与定时任务不匹配,则判定无效。For example, in this embodiment, if the ID number of the stopped virtual timer does not match the timing task, the determination is invalid.
S812、判断要停止的虚拟定时器的定时时间是否为进入中断阶段在所述硬件定时器停止时虚拟定时器队列中的最短定时时间;若是,则执行步骤S813;否则,要停止的虚拟定时器不为最短定时时间对应的虚拟定时器;S812. Determine whether the timing time of the virtual timer to be stopped is the shortest timing time in the virtual timer queue when the hardware timer is stopped in the entry interruption phase; if yes, execute step S813; otherwise, the virtual timer to be stopped a virtual timer that does not correspond to the shortest timing time;
本实施例中,通过属性元素latest_sw_timer_index可确定出在执行S812时虚拟定时器队列中的最短定时时间,该最短定时时间与要停止的虚拟定时器的定时时间进行不对,若两者相等,则要停止的虚拟定时器的定时时间为进入中断阶段在所述硬件定时器停止时虚拟定时器队列中的最短定时时间,即要停止的虚拟定时器为最短定时时间对应的虚拟定时器;若两者不相等,则要停止的虚拟定时器不为最短定时时间对应的虚拟定时器。In this embodiment, the shortest timing time in the virtual timer queue when S812 is executed is determined by the attribute element latest_sw_timer_index, and the shortest timing time is incorrect with the timing time of the virtual timer to be stopped, if the two are equal, The timing of the stopped virtual timer is the shortest timing time in the virtual timer queue when the hardware timer is stopped in the interrupt phase, that is, the virtual timer to be stopped is the virtual timer corresponding to the shortest timing time; If they are not equal, the virtual timer to be stopped is not the virtual timer corresponding to the shortest timing time.
若要停止的虚拟定时器为最短定时时间对应的虚拟定时器,因为后续要停止该虚拟定时器或者重新启动进行周期性定时,所以启动虚拟定时器刷新处理,重新确定虚拟定时器队列中的最短定时时间;若停止的虚拟定时器不为最短定时时间对应的虚拟定时器,由于虚拟定时器队列中的最短定时时间并不会发生变化,因此,可以直接从虚拟定时器队列中删除停止的虚拟定时器,从而避免重新去启动硬件定时器并更新定时基准,从而提高了效率,减小了延迟,减轻了CPU资源的负担。The virtual timer to be stopped is the virtual timer corresponding to the shortest timing time. Because the virtual timer is stopped or restarted for periodic timing, the virtual timer refresh processing is started, and the shortest in the virtual timer queue is re-determined. Timing time; if the stopped virtual timer is not the virtual timer corresponding to the shortest timing time, since the shortest timing time in the virtual timer queue does not change, the stopped virtual can be deleted directly from the virtual timer queue. The timer, thus avoiding the need to restart the hardware timer and update the timing reference, thereby improving efficiency, reducing latency, and reducing the burden on CPU resources.
S813、在虚拟定时器停止阶段停止硬件定时器,并所述硬件定时器在虚拟定时器停止阶段停止及该停止之前最近启动之间的耗时;S813. Stop the hardware timer in the virtual timer stop phase, and the time between the hardware timer stopping in the virtual timer stop phase and the most recent startup before the stopping;
本实施例中,步骤S813类似上述步骤S203。In this embodiment, step S813 is similar to step S203 described above.
S814、将步骤S811中ID有效的虚拟定时器的标志位used_flag修改为false,并将属性元素used_sw_timer表示的虚拟定时器使用个数减一;S814, modifying the flag set used_flag of the virtual timer valid in the step S811 to false, and reducing the number of virtual timers used by the attribute element used_sw_timer by one;
本实施例中,由于到达定时时间且停止定时的虚拟定时器要从虚拟定时器队列中删除,因此,对应地,要对相关的属性元素进行维护。 In this embodiment, since the virtual timer that arrives at the timing time and stops the timing is to be deleted from the virtual timer queue, correspondingly, the related attribute elements are to be maintained.
S815、在虚拟定时器刷新阶段执行到达定时时间的虚拟定时器对应的应用任务;S815. Perform an application task corresponding to a virtual timer that reaches a timing time in a virtual timer refresh phase.
S816、根据所述硬件定时器在虚拟定时器停止阶段停止及该停止之前最近启动之间的耗时,确定所述虚拟定时器队列中的最短定时时间;S816. Determine a minimum timing time in the virtual timer queue according to a time interval between the hardware timer stopping in a virtual timer stop phase and a recent start before the stopping.
本实施例中,步骤S816类似步骤S206。In this embodiment, step S816 is similar to step S206.
S817、进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。S817. Enter a hardware timer startup phase and update the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, and exit the interrupt phase to restart the hardware timer.
本实施例中,步骤S817类似上述实施例208。In this embodiment, step S817 is similar to the above embodiment 208.
在具体应用场景中,可以为实现图8所示的停止流程配置一函数,比如uint16_t sw_timer_stop(uint8_t timer_id)。In a specific application scenario, a function such as uint16_t sw_timer_stop(uint8_t timer_id) may be configured for implementing the stopping process shown in FIG.
在上述实施例中,对于嵌入式系统来说,在不同MCU平台下,硬件定时器的最长定时时间与硬件定时器的时钟、硬件定时器的位宽相关。在不考虑时钟的影响,那么对最长定时时间的影响就只有硬件定时器的位宽。通常我们的硬件定时器的位宽和MCU的平台相关,比如常用的是16位硬件定时器和32位硬件定时器,因此,由于在确定硬件定期的定时基准值时,取最短定时时间和最长定时时间的最小值,从而也就屏蔽了不同平台最长定时时间的差异性。In the above embodiment, for an embedded system, under different MCU platforms, the maximum timing of the hardware timer is related to the clock of the hardware timer and the bit width of the hardware timer. Regardless of the impact of the clock, the effect on the longest timing is only the bit width of the hardware timer. Usually the bit width of our hardware timer is related to the platform of the MCU. For example, the 16-bit hardware timer and the 32-bit hardware timer are commonly used. Therefore, since the hardware timing reference value is determined, the shortest timing time and the most The minimum time of long timing time, thus shielding the difference of the longest timing time of different platforms.
需要说明的是,在上述实施例中,当需要刷新或者重启或者停止虚拟定时器时,可以根据需要进行硬件中断,详细不再赘述。It should be noted that, in the foregoing embodiment, when a virtual timer needs to be refreshed or restarted or stopped, hardware interrupts may be performed as needed, and details are not described herein again.
图9为本申请实施例九中虚拟定时器的定时装置的结构示意图;如图9所示,其包括:9 is a schematic structural diagram of a timing device of a virtual timer in Embodiment 9 of the present application; as shown in FIG. 9, the method includes:
中断模块901,用于当所述硬件定时器的计数的时间到其定时基准值时,进入中断阶段并停止所述硬件定时器;The interrupting module 901 is configured to enter an interrupt phase and stop the hardware timer when the counted time of the hardware timer reaches a timing reference value thereof;
定时模块902,用于在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务;The timing module 902 is configured to determine, in the virtual timer refreshing phase, whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, execute the corresponding application task; if not, the corresponding application task is not executed;
刷新模块903,用于根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;a refreshing module 903, configured to determine, according to the elapsed time between the stop and the previous start of the hardware timer when entering the interrupt phase, the entering the interrupt phase starting from the moment when the hardware timer stops The shortest time in the queue;
启动模块904,用于进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。The startup module 904 is configured to enter a hardware timer startup phase and update the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, and exit the interrupt phase to restart the hardware timer.
中断模块901、定时模块902、刷新模块903、启动模块904可以执行在上述方法实施例各自对应的具体步骤或者进一步地的步骤。The interrupt module 901, the timing module 902, the refresh module 903, and the startup module 904 can perform specific steps or further steps corresponding to the respective method embodiments.
本实施例还提供一种电子装置,其包括:硬件定时器、若干个虚拟定时器、处理器,当所述硬件定时器的计数的时间到其定时基准值时进入中断阶段并停止所述硬件定时器;所述处理器用于:The embodiment further provides an electronic device, comprising: a hardware timer, a plurality of virtual timers, and a processor, when the counting time of the hardware timer reaches its timing reference value, entering an interrupt phase and stopping the hardware a timer; the processor is used to:
在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务; During the virtual timer refresh phase, it is determined whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, the corresponding application task is executed; if not, the corresponding application task is not executed;
根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;Determining the minimum timing time in the virtual timer queue from the time when the hardware timer stops from entering the interrupt phase according to the time between the stop and the previous start of the hardware timer when entering the interrupt phase ;
使得硬件定时器进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。The hardware timer is caused to enter a hardware timer start phase and the timing reference value is updated according to the shortest timing time and the longest timing time of the hardware timer, and the interrupt phase is exited to restart the hardware timer.
本实施例中,处理器可以CPU也可以是MCU。In this embodiment, the processor may be a CPU or an MCU.
本申请实施例的电子装置可以是具体的电路,也可以为整机电子设备,包括但不限于:The electronic device in the embodiment of the present application may be a specific circuit, or may be a complete electronic device, including but not limited to:
(1)移动通信设备:这类设备的特点是具备移动通信功能,并且以提供话音、数据通信为主要目标。这类终端包括:智能手机(例如iPhone)、多媒体手机、功能性手机,以及低端手机等。(1) Mobile communication devices: These devices are characterized by mobile communication functions and are mainly aimed at providing voice and data communication. Such terminals include: smart phones (such as iPhone), multimedia phones, functional phones, and low-end phones.
(2)超移动个人计算机设备:这类设备属于个人计算机的范畴,有计算和处理功能,一般也具备移动上网特性。这类终端包括:PDA、MID和UMPC设备等,例如iPad。(2) Ultra-mobile personal computer equipment: This type of equipment belongs to the category of personal computers, has computing and processing functions, and generally has mobile Internet access. Such terminals include: PDAs, MIDs, and UMPC devices, such as the iPad.
(3)便携式娱乐设备:这类设备可以显示和播放多媒体内容。该类设备包括:音频、视频播放器(例如iPod),掌上游戏机,电子书,以及智能玩具和便携式车载导航设备。(3) Portable entertainment devices: These devices can display and play multimedia content. Such devices include: audio, video players (such as iPod), handheld game consoles, e-books, and smart toys and portable car navigation devices.
(4)服务器:提供计算服务的设备,服务器的构成包括处理器、硬盘、内存、系统总线等,服务器和通用的计算机架构类似,但是由于需要提供高可靠的服务,因此在处理能力、稳定性、可靠性、安全性、可扩展性、可管理性等方面要求较高。(4) Server: A device that provides computing services. The server consists of a processor, a hard disk, a memory, a system bus, etc. The server is similar to a general-purpose computer architecture, but because of the need to provide highly reliable services, processing power and stability High reliability in terms of reliability, security, scalability, and manageability.
(5)其他具有数据交互功能的电子装置。(5) Other electronic devices with data interaction functions.
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理模块,即可以位于一个地方,或者也可以分布到多个网络模块上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are merely illustrative, wherein the modules described as separate components may or may not be physically separate, and the components displayed as modules may or may not be physical modules, ie may be located A place, or it can be distributed to multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment. Those of ordinary skill in the art can understand and implement without deliberate labor.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,所述计算机可读记录介质包括用于以计算机(例如计算机)可读的形式存储或传送信息的任何机制。例如,机器可读介质包括只读存储器(ROM)、随机存取存储器(RAM)、磁盘存储介质、光存储介质、闪速存储介质、电、光、声或其他形式的传播信号(例如,载波、红外信号、数字信号等)等,该计算机软件产品包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the various embodiments can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware. Based on such understanding, portions of the above technical solutions that contribute substantially or to the prior art may be embodied in the form of a software product that may be stored in a computer readable storage medium, the computer readable record The medium includes any mechanism for storing or transmitting information in a form readable by a computer (eg, a computer). For example, a machine-readable medium includes read only memory (ROM), random access memory (RAM), magnetic disk storage media, optical storage media, flash storage media, electrical, optical, acoustic, or other forms of propagation signals (eg, carrier waves) , an infrared signal, a digital signal, etc., etc., the computer software product comprising instructions for causing a computer device (which may be a personal computer, server, or network device, etc.) to perform the various embodiments or portions of the embodiments described Methods.
本领域的技术人员应明白,本申请实施例的实施例可提供为方法、装置(设备)、或计算机程序产品。因此,本申请实施例可采用完全硬件实施例、完全软 件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art will appreciate that embodiments of the embodiments of the present application can be provided as a method, apparatus (device), or computer program product. Therefore, the embodiment of the present application can adopt an entirely hardware embodiment and is completely soft. An embodiment, or a combination of software and hardware aspects. Moreover, embodiments of the present application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) including computer usable program code.
本申请实施例是参照根据本申请实施例的方法、装置(设备)和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, apparatus, and computer program products according to embodiments of the present application. It will be understood that each flow and/or block of the flowchart illustrations and/or FIG. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing device to produce a machine for the execution of instructions for execution by a processor of a computer or other programmable data processing device. Means for implementing the functions specified in one or more of the flow or in a block or blocks of the flow chart.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。The computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device. The apparatus implements the functions specified in one or more blocks of a flow or a flow and/or block diagram of the flowchart.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device such that a series of operational steps are performed on a computer or other programmable device to produce computer-implemented processing for execution on a computer or other programmable device. The instructions provide steps for implementing the functions specified in one or more of the flow or in a block or blocks of a flow diagram.
最后应说明的是:以上实施例仅用以说明本申请实施例的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。 Finally, it should be noted that the above embodiments are only used to explain the technical solutions of the embodiments of the present application, and are not limited thereto; although the present application is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that The technical solutions described in the foregoing embodiments may be modified, or some of the technical features may be equivalently replaced; and the modifications or substitutions do not deviate from the spirit of the technical solutions of the embodiments of the present application. range.

Claims (17)

  1. 一种虚拟定时器的定时方法,其特征在于,包括:A timing method for a virtual timer, comprising:
    若硬件定时器的计数的时间到其定时基准值,则进入中断阶段并停止所述硬件定时器;If the time counted by the hardware timer reaches its timing reference value, the interrupt phase is entered and the hardware timer is stopped;
    在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务;During the virtual timer refresh phase, it is determined whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, the corresponding application task is executed; if not, the corresponding application task is not executed;
    根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;Determining the minimum timing time in the virtual timer queue from the time when the hardware timer stops from entering the interrupt phase according to the time between the stop and the previous start of the hardware timer when entering the interrupt phase ;
    进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。Entering the hardware timer start phase and updating the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, exiting the interrupt phase to restart the hardware timer.
  2. 根据权利要求1所述的定时方法,其特征在于,所述进入硬件中断阶段之后,停止所述硬件定时器之前,还包括:清除硬件中断标志位;对应地,退出中断阶段包括根据清除后硬件中断标志位退出中断阶段。The timing method according to claim 1, wherein after the entering the hardware interrupt phase, before stopping the hardware timer, the method further comprises: clearing a hardware interrupt flag bit; correspondingly, exiting the interrupt phase comprises: The interrupt flag bit exits the interrupt phase.
  3. 根据权利要求1所述的定时方法,其特征在于,在所述硬件定时器的计数的时间到其定时基准值之前,还包括:初始化虚拟定时器资源中各虚拟定时器中的属性元素、所述硬件定时器的工作模式中至少之一。The timing method according to claim 1, wherein before the counting of the hardware timer reaches the timing reference value, the method further comprises: initializing an attribute element in each virtual timer in the virtual timer resource, At least one of the working modes of the hardware timer.
  4. 根据权利要求3所述的定时方法,其特征在于,所述属性元素包括:表征任一虚拟定时器是否已经被使用的标志位、记录任一虚拟定时器的定时时间、表征任一虚拟定时器是周期性虚拟定时器还是单次性虚拟定时器的标志位。The timing method according to claim 3, wherein the attribute element comprises: a flag bit indicating whether any virtual timer has been used, a timing time for recording any virtual timer, and characterizing any virtual timer Whether it is a periodic virtual timer or a single virtual timer.
  5. 根据权利要求1所述的定时方法,其特征在于,若需要执行新定时任务,进入虚拟定时器启动阶段,并判断所述新定时任务所需的定时时间是否合理,若是,则进一步判断虚拟定时器资源中是否还有未使用的虚拟定时器,若是,从所述未使用的虚拟定时器中确定对应所述新定时任务的虚拟定时器并将其插入到所述虚拟定时器队列中。The timing method according to claim 1, wherein if a new timing task needs to be executed, the virtual timer startup phase is entered, and it is determined whether the timing time required for the new timing task is reasonable, and if so, the virtual timing is further determined. Whether there are unused virtual timers in the resource, and if so, a virtual timer corresponding to the new timing task is determined from the unused virtual timers and inserted into the virtual timer queue.
  6. 根据权利要求5中的所述定时方法,其特征在于,根据虚拟定时器队列中执行各定时任务的虚拟定时器数量以及虚拟定时器资源中虚拟定时器的最多个数,判断虚拟定时器资源中是否还有未使用的虚拟定时器。The timing method according to claim 5, wherein the virtual timer resource is determined according to the number of virtual timers for executing each timing task in the virtual timer queue and the maximum number of virtual timers in the virtual timer resource. Are there any unused virtual timers?
  7. 根据权利要求5所述的定时方法,其特征在于,根据设定的定时时间阈值判断所述新定时任务所匹配的定时时间是否合理。The timing method according to claim 5, wherein it is determined whether the timing time matched by the new timing task is reasonable according to the set timing time threshold.
  8. 根据权利要求7所述的定时方法,其特征在于,所述定时时间阈值具有阈值上限和阈值下限,对应地,根据所述阈值上限和阈值下限判断所述新定时任务所匹配的定时时间是否合理。The timing method according to claim 7, wherein the timing time threshold has an upper threshold value and a lower threshold value, and correspondingly, determining whether the timing time matched by the new timing task is reasonable according to the upper threshold value and the lower threshold value .
  9. 根据权利要求5所述的定时方法,其特征在于,在将对应所述新定时任务的虚拟定时器插入到所述虚拟定时器队列中之前,还包括:在虚拟定时器启动阶段停止所述硬件定时器,并确定所述硬件定时器在虚拟定时器启动阶段停止到距离其最近的启动之间的耗时;The timing method according to claim 5, wherein before inserting the virtual timer corresponding to the new timing task into the virtual timer queue, the method further comprises: stopping the hardware during a virtual timer startup phase a timer, and determining a time consuming between the hardware timer stopping at a virtual timer start phase and a start from its nearest start;
    在将所述新定时任务对应的虚拟定时器插入到所述虚拟定时器队列之后, 还包括:After inserting the virtual timer corresponding to the new timing task into the virtual timer queue, Also includes:
    在虚拟定时器刷新阶段判断虚拟定时器队列中是否有到达定时时间的虚拟定时器,若有,则执行对应的应用任务;若无,则不执行对应的应用任务;Determining, in the virtual timer refreshing phase, whether there is a virtual timer that reaches the timing time in the virtual timer queue, and if so, executing the corresponding application task; if not, executing the corresponding application task;
    根据所述硬件定时器在虚拟定时器启动阶段停止到距离该停止最近的启动之间的耗时,确定在插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间;Determining a minimum timing time in the virtual timer queue after inserting the virtual timer according to a time consuming between the hardware timer stopping in the virtual timer startup phase and starting from the stop;
    重新进入硬件定时器启动阶段,并根据在插入虚拟定时器之后所述虚拟定时器队列中的最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,并在虚拟定时器启动阶段重新启动所述硬件定时器。Re-entering the hardware timer startup phase, and updating the timing reference value according to the shortest timing time in the virtual timer queue after inserting the virtual timer and the longest timing time of the hardware timer, and in the virtual timer The hardware phase is restarted during the startup phase.
  10. 根据权利要求9所述的定时方法,其特征在于,在虚拟定时器启动阶段判断虚拟定时器队列中是否有到达定时时间的虚拟定时器之后,还包括:判断所述虚拟定时器队列中是否还存在执行定时任务的虚拟定时器,若是,则重新进入硬件定时器启动阶段。The timing method according to claim 9, wherein after determining, in the virtual timer startup phase, whether there is a virtual timer that reaches a timing time in the virtual timer queue, the method further includes: determining whether the virtual timer queue is still There is a virtual timer that executes the scheduled task, and if so, re-enters the hardware timer startup phase.
  11. 根据权利要求1所述的定时方法,其特征在于,所述执行对应的应用任务之后,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间之前,还包括:The timing method according to claim 1, wherein after the executing the corresponding application task, determining that the entering the interrupt phase starts from the time when the hardware timer stops, before the shortest timing time in the virtual timer queue, Also includes:
    当到达定时时间的虚拟定时器为周期性虚拟定时器时,将所述到达的定时时间配置为所述周期性虚拟定时器的定时时间;When the virtual timer that reaches the timing is a periodic virtual timer, the timing of the arrival is configured as the timing of the periodic virtual timer;
    当到达定时时间的虚拟定时器为单次性虚拟定时器时,将到达定时时间的虚拟定时器属性修改为已使用结束且目前处于未使用状态。When the virtual timer that reaches the timing is a one-time virtual timer, the virtual timer attribute that reaches the timing is modified to be used and is currently in an unused state.
  12. 根据权利要求11所述的定时方法,其特征在于,当到达定时时间的虚拟定时器为单次性虚拟定时器时,还包括:停止并从所述虚拟定时器队列中删除到达定时时间的虚拟定时器。The timing method according to claim 11, wherein when the virtual timer that reaches the timing time is a one-time virtual timer, the method further includes: stopping and deleting the virtual time of arrival from the virtual timer queue Timer.
  13. 根据权利要求12所述的定时方法,其特征在于,停止到达定时时间的虚拟定时器包括:The timing method according to claim 12, wherein the stopping the virtual timer of the arrival timing time comprises:
    进入虚拟定时器停止阶段并判断要停止的虚拟定时器的ID号是否有效;Entering the virtual timer stop phase and determining whether the ID number of the virtual timer to be stopped is valid;
    若有效,则判断要停止的虚拟定时器的定时时间是否为进入中断阶段在所述硬件定时器停止时虚拟定时器队列中的最短定时时间;若是,则在虚拟定时器停止阶段停止硬件定时器,并进入虚拟定时器刷新阶段;If it is valid, it is determined whether the timing time of the virtual timer to be stopped is the shortest timing time in the virtual timer queue when the hardware timer is stopped in the entry interruption phase; if yes, the hardware timer is stopped in the virtual timer stop phase And enter the virtual timer refresh phase;
    在虚拟定时器刷新阶段执行到达定时时间的虚拟定时器对应的应用任务;Executing an application task corresponding to a virtual timer that reaches a timing time in a virtual timer refresh phase;
    根据所述硬件定时器在虚拟定时器停止阶段停止及该停止之前最近启动之间的耗时,确定所述虚拟定时器队列中的最短定时时间;Determining a minimum timing time in the virtual timer queue according to a time consuming between the hardware timer stopping in the virtual timer stop phase and the most recent start before the stopping;
    进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。Entering the hardware timer start phase and updating the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, exiting the interrupt phase to restart the hardware timer.
  14. 根据权利要求11所述的定时方法,其特征在于,为虚拟定时器配置有是否使用的标志位,当到达定时时间的虚拟定时器为单次性虚拟定时器时,将到达定时时间的虚拟定时器属性修改为已使用结束且目前处于未使用状态包括:修改所述标志位的值,以表示到达定时时间的虚拟定时器配置为已使用结束且目前处于未使用状态。The timing method according to claim 11, wherein the virtual timer is configured with a flag bit that is used, and when the virtual timer that reaches the timing time is a one-time virtual timer, the virtual timing of the timing time is reached. Modifying the attribute to use ended and currently in an unused state includes modifying the value of the flag bit to indicate that the virtual timer of the arrival time is configured to be used and is currently in an unused state.
  15. 根据权利要求1所述的定时方法,其特征在于,停止所述硬件定时器 之后,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器之前还包括:The timing method according to claim 1, wherein said hardware timer is stopped After that, it is determined whether there is a virtual timer that reaches the timing time in the virtual timer queue before:
    遍历所述虚拟定时器队列中的所有虚拟定时器并确定其中每个虚拟定时器的定时时间与所述耗时的差值,以根据所述差值判断虚拟定时器队列中是否有到达定时时间的虚拟定时器。Traversing all virtual timers in the virtual timer queue and determining a difference between a timing time of each virtual timer and the time consuming to determine whether there is an arrival timing time in the virtual timer queue according to the difference Virtual timer.
  16. 一种虚拟定时器的定时装置,其特征在于,包括:A timing device for a virtual timer, comprising:
    中断模块,用于当硬件定时器的计数的时间到其定时基准值时,进入中断阶段并停止所述硬件定时器;An interrupt module, configured to enter an interrupt phase and stop the hardware timer when a time counted by the hardware timer reaches a timing reference value thereof;
    定时模块,用于在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务;The timing module is configured to determine, in the virtual timer refreshing phase, whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, execute the corresponding application task; if not, the corresponding application task is not executed;
    刷新模块,用于根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;a refreshing module, configured to determine, according to the elapsed time between the stop and the previous start of the hardware timer when entering the interrupt phase, entering the interrupt phase to start the virtual timer queue from a time when the hardware timer stops The shortest time in the middle;
    启动模块,用于进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。And a startup module, configured to enter a hardware timer startup phase and update the timing reference value according to the shortest timing time and the longest timing time of the hardware timer, and exit the interrupt phase to restart the hardware timer.
  17. 一种电子装置,其特征在于,包括:硬件定时器、若干个虚拟定时器、处理器,若硬件定时器的计数的时间到其定时基准值,则进入中断阶段并停止所述硬件定时器;所述处理器用于:An electronic device, comprising: a hardware timer, a plurality of virtual timers, and a processor, if the counted time of the hardware timer reaches its timing reference value, entering an interrupt phase and stopping the hardware timer; The processor is used to:
    在虚拟定时器刷新阶段,判断虚拟定时器队列中是否有到达定时时间的虚拟定时器;若有,则执行对应的应用任务;若无,则不执行对应的应用任务;During the virtual timer refresh phase, it is determined whether there is a virtual timer that reaches the timing time in the virtual timer queue; if yes, the corresponding application task is executed; if not, the corresponding application task is not executed;
    根据所述硬件定时器从进入中断阶段时所述停止及其之前最近启动之间的耗时,确定进入中断阶段从所述硬件定时器停止的时刻开始所述虚拟定时器队列中的最短定时时间;Determining the minimum timing time in the virtual timer queue from the time when the hardware timer stops from entering the interrupt phase according to the time between the stop and the previous start of the hardware timer when entering the interrupt phase ;
    使得硬件定时器进入硬件定时器启动阶段并根据所述最短定时时间以及所述硬件定时器的最长定时时间更新所述定时基准值,退出中断阶段以重新启动所述硬件定时器。 The hardware timer is caused to enter a hardware timer start phase and the timing reference value is updated according to the shortest timing time and the longest timing time of the hardware timer, and the interrupt phase is exited to restart the hardware timer.
PCT/CN2017/107098 2017-10-20 2017-10-20 Timing method of virtual timer, apparatus thereof, and electronic apparatus WO2019075745A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2017/107098 WO2019075745A1 (en) 2017-10-20 2017-10-20 Timing method of virtual timer, apparatus thereof, and electronic apparatus
CN201780001891.4A CN109952560B (en) 2017-10-20 2017-10-20 Timing method and device of virtual timer and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2017/107098 WO2019075745A1 (en) 2017-10-20 2017-10-20 Timing method of virtual timer, apparatus thereof, and electronic apparatus

Publications (1)

Publication Number Publication Date
WO2019075745A1 true WO2019075745A1 (en) 2019-04-25

Family

ID=66173979

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/107098 WO2019075745A1 (en) 2017-10-20 2017-10-20 Timing method of virtual timer, apparatus thereof, and electronic apparatus

Country Status (2)

Country Link
CN (1) CN109952560B (en)
WO (1) WO2019075745A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112559117A (en) * 2019-09-25 2021-03-26 阿里巴巴集团控股有限公司 Timer processing method and device, electronic equipment and computer storage medium
CN112463125B (en) * 2020-12-09 2023-09-15 百富计算机技术(深圳)有限公司 Timing method and equipment of virtual timer

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1996030841A1 (en) * 1995-03-30 1996-10-03 Motorola Inc. Method and system for remote procedure call via an unreliable communication channel using multiple retransmission timers
CN101320337A (en) * 2008-07-16 2008-12-10 北京中星微电子有限公司 Timer and its implementing method
CN101840353A (en) * 2010-05-14 2010-09-22 陈冬岩 Dynamic timing method for real-time embedded operating system
CN102541616A (en) * 2010-12-17 2012-07-04 北京凯思昊鹏软件工程技术有限公司 Embedded operating system virtual machine and implementation method thereof
CN103034480A (en) * 2011-09-30 2013-04-10 重庆重邮信科通信技术有限公司 Embedded system timer realizing method

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7475002B1 (en) * 2004-02-18 2009-01-06 Vmware, Inc. Method and apparatus for emulating multiple virtual timers in a virtual computer system when the virtual timers fall behind the real time of a physical computer system
JP2008181392A (en) * 2007-01-25 2008-08-07 Hitachi Ltd Virtual timer control method
CN101566956A (en) * 2008-04-25 2009-10-28 北京闻言科技有限公司 Method for interrupting overtime task by using timer
US10534421B2 (en) * 2013-06-13 2020-01-14 Microsoft Technology Licensing, Llc Virtual per-processor timers for multiprocessor systems
CN104166585A (en) * 2014-08-19 2014-11-26 Tcl通讯(宁波)有限公司 Terminal timer control method and system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1996030841A1 (en) * 1995-03-30 1996-10-03 Motorola Inc. Method and system for remote procedure call via an unreliable communication channel using multiple retransmission timers
CN101320337A (en) * 2008-07-16 2008-12-10 北京中星微电子有限公司 Timer and its implementing method
CN101840353A (en) * 2010-05-14 2010-09-22 陈冬岩 Dynamic timing method for real-time embedded operating system
CN102541616A (en) * 2010-12-17 2012-07-04 北京凯思昊鹏软件工程技术有限公司 Embedded operating system virtual machine and implementation method thereof
CN103034480A (en) * 2011-09-30 2013-04-10 重庆重邮信科通信技术有限公司 Embedded system timer realizing method

Also Published As

Publication number Publication date
CN109952560B (en) 2022-12-23
CN109952560A (en) 2019-06-28

Similar Documents

Publication Publication Date Title
WO2017166650A1 (en) Voice recognition method and device
WO2019085658A1 (en) Method for resource allocation and terminal device
CN107562660B (en) visual SLAM system-on-chip and data processing method
US9286084B2 (en) Adaptive hardware reconfiguration of configurable co-processor cores for hardware optimization of functionality blocks based on use case prediction, and related methods, circuits, and computer-readable media
CN106484848B (en) Application recommendation method and device
TW201436426A (en) Battery charge management for electronic device
US10565064B2 (en) Effective data change based rule to enable backup for specific VMware virtual machine
TW201725502A (en) Data compression using accelerator with multiple search engines
RU2635044C2 (en) Tracking mode in the processing device of the tracing commands systems
US10684859B2 (en) Providing memory dependence prediction in block-atomic dataflow architectures
US10725924B2 (en) Low-latency hybrid client-server cooperation
KR20180048993A (en) Systems and methods for dynamically adjusting memory state transition timers
WO2019075745A1 (en) Timing method of virtual timer, apparatus thereof, and electronic apparatus
JP2021022379A (en) Autonomous job queueing system for hardware accelerators
CN111111201A (en) Skill creating method, skill creating device, skill creating server and skill creating medium based on game
US10175716B2 (en) Technologies for low-power and high-accuracy timestamps
CN113923519A (en) Video rendering method and device, computer equipment and storage medium
CN111290786B (en) Information processing method, device and storage medium
WO2015188589A1 (en) User data update method and device
CN116048834A (en) Method, device and storage medium for updating integrated ranking list in real time
WO2019041625A1 (en) Dual-camera focusing method and apparatus, and electronic device
WO2017028728A1 (en) Determining method and device for click through rate (ctr)
CN110019657B (en) Processing method, apparatus and machine-readable medium
US10803123B2 (en) Automatic generation of variations of search criteria for use in a predictive search engine
US20200372060A1 (en) Facilitating merging of concept hierarchies

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17929003

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17929003

Country of ref document: EP

Kind code of ref document: A1