Summary of the invention
It is an object of the invention to provide a kind of software timing method of dynamic heavy duty timed length, the advantages such as it is many that it has resource, and timing is long, flexible and convenient to use.
Another object of the present invention is to provide a kind of software timing method of dynamic heavy duty timed length, the problem not enough to solve hardware resource, be greatly simplified software complexity, accelerate design process.
It is an object of the invention to be achieved through the following technical solutions.
A kind of software timing method of dynamic heavy duty timed length, including step:
A: create a hardware timer, concurrently sets base during minimum reference, and hardware timer is initialized;
B: after obtaining the object success of a hardware timer, the software timer of initialization services layer;
C: create a software timer, arranges timing, starts software timer;
D: according to timing, carries out corresponding thread process, in the task of corresponding software timer, the message received is judged, if timer message, just processes the message of software timer.
Preferably, step b specifically includes: the action listener of registration software timer, arranges base during benchmark, creates semaphore, mutual exclusion lock and establishment for service layer's software timer and processes the task of software timer message.
Preferably, step c specifically includes:
C1: judge whether it is that hardware is timed to, if timing is less than, continues to timing and waits;If it is, enter step c2;
C2: whether the chained list judging software timer is empty, if be sky, returns to the judgement that hardware is timed to;If not being empty, then enter step c3;
C3: take out the software timer of an assigned I D from chain the exterior and the interior, the count value of software timer subtracts one;
C4: judge whether current count value is zero, if be not zero, then returns to the judgement that hardware is timed to;If being zero, then enter step c5;
C5: send the message of a software timer, processes the task of corresponding software timer.
Preferably, in step d, the message received is judged, if not timer message, then other message of respective handling.
The present invention compared with prior art, has the beneficial effects that: the software timing method of dynamic heavy duty timed length provided by the invention and software timer, based on hardware timer, utilizes the Interruption of hardware timer to realize.Software timer needs to take cpu resource, but its resource is many, and timing is long, flexible and convenient to use, in the application scenario that complication system or runs mode are complicated, solves the problem that hardware resource is not enough, is greatly simplified software complexity, accelerate design process.
Detailed description of the invention
Core concept of the present invention: the present invention adds priority in software timer, it is provided that the mechanism of a kind of event notice-monitoring, the interrupt management module for operating system uses.After interrupting generation, interrupt management module can adjust back the function of user, and user judges whether that the task of requiring over interrupt management goes distribution, if need not, user process, otherwise it can manage module distributed tasks by triggered interrupts, and this task can notify away corresponding for this interrupt number event.Interrupt management module can to need Schedule Interrupt be directly adjust back the process function of user or being put in task processes when producing according to different.And intervalometer is then judged and process, create a higher timer management task of priority ratio, this task is timed then judgement and the process of device.Action listener function gives the task of this high priority by signal release semaphore so that it is obtain semaphore.This method shortens the execution time of interrupt service routine, thus improving the real-time of system.
In order to make the purpose of the present invention, technical scheme and advantage clearly understand, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein is only in order to explain the present invention, is not intended to limit the present invention.
Software timer is the set of one group of timer entity, is a kind of multitask chained list type data structure carrying out unified management for different timing service.Software timer can make system determine that the moment performs assigned operation a certain.It is based on programmable Timer/enumerator or single stabilization delay circuit, utilizes the Interruption that hardware timer produces to realize.
Referring to shown in Fig. 1, invention software intervalometer includes:
1, the establishment of software timer: create a software timer, obtains No. ID of a software timer simultaneously, and No. ID within 0-128, it is impossible to exceed, and is otherwise considered as establishment unsuccessful.There is single use or recycle two ways.
2, the base during benchmark of software timer is set: minimum timing unit.According to system, the requirement of timing can be set.The timing of same time span, different time bases has different timing accuracies.
3, software timer is started: obtain corresponding No. ID after creating an intervalometer and start timework.There is different entry conditions different application scenarios: pulse, level, event, interruption etc..
4, software timer is stopped: stopping the timing of software timer, namely reset.
5, the preset value of software timer: set timing initial value to software timer.After starting software timer, start timing on this basis.
6, software timer currency is obtained: obtain software timer count value of current time in timing course.Can be used to test timing etc..
The Interruption realizing mainly being produced by hardware timer of software timer, hardware timer provides two kinds of Interrupt Processing Models, one is then direct call back function in the direct, mode, another is the member function interpolation event functions that non-Direct Model then needs to call interrupt management class, is put into event-monitoring mechanism and realizes interrupt mechanism.And the mode that here software timer realizes is mainly event-monitoring mechanism.It is by processing release semaphore in function at event interrupt, obtains semaphore and process various event in thread.
Software timer is before creating, first pass through hardware timer and base value when one (minimum Tick) is set, then generate a software timer, designated software intervalometer timing time is set, start intervalometer, if timing arrives, it is put in corresponding thread going processing, first passes through and judge whether it is the message of intervalometer, if the message of intervalometer just removes to process the Message function of intervalometer, if it is not, just do other process.
Refer to shown in Fig. 2, the software timing method of the present invention dynamically heavy duty timed length, including:
Step 201: create a hardware timer, concurrently set base during minimum reference.Start hardware timer, given hard intervalometer base class sub-object is timed device encapsulation simultaneously and initializes.
Step 202: after obtaining the object success of a hardware timer, the software timer of initialization services layer.Including the action listener of registration software timer, base during benchmark is set, creates semaphore, mutual exclusion lock and the establishment task of processing software timer message etc. for service layer's software timer.
Step 203: create a software timer, arranges timing, starts software timer.
Step 204: according to timing, carries out corresponding thread process.
As it is shown on figure 3, concrete thread process includes:
Step 301: judge whether it is that hardware is timed to, if timing is less than, continues to timing and waits;If it is, enter step 302.
Step 302: whether the chained list judging software timer is empty, if be sky, returns to the judgement that hardware is timed to;If not being empty, then enter step 303.
Step 303: take out the software timer of an assigned I D from chain the exterior and the interior, the count value of software timer subtracts one.
Step 304: judge whether current count value is zero, if be not zero, then returns to the judgement that hardware is timed to;If being zero, then enter step 305.
Step 305: send the message of a software timer, processes the task of corresponding software timer.
Step 205: in the task of corresponding software timer, judges the message received, if timer message, just processes the message of software timer;If it is not, with regard to other message of respective handling.
In the present invention, hardware timer (OMAP-L137) is the processor with ARM926EJ-S and C674x Floating-point DSP kernel, each core dominant frequency can reach 300MHz clock, and the timer/counter module of this hardware timer contains two identical 64 bit timing devices/enumerator passages of function.This intervalometer has four kinds of timing modes: the general timing mode of 64, double; two 32 general timing modes of non-chain type, double; two 32 chain type timing modes, house dog timing mode;Timing mode of the present invention adopts double; two 32 general timing modes of non-chain type, the intervalometers of two 64 is divided into the intervalometer of four 32.
The software timing method of dynamic heavy duty timed length provided by the invention and software timer, based on hardware timer, utilize the Interruption of hardware timer to realize.Software timer needs to take cpu resource, but its resource is many, and timing is long, flexible and convenient to use, in the application scenario that complication system or runs mode are complicated, solves the problem that hardware resource is not enough, is greatly simplified software complexity, accelerate design process.
The foregoing is only presently preferred embodiments of the present invention, not in order to limit the present invention, all any amendment, equivalent replacement and improvement etc. made within the spirit and principles in the present invention, should be included within protection scope of the present invention.