Summary of the invention
The object of the present invention is to provide the regularly software timing method of length of a kind of dynamic heavy duty, the advantage such as it is many that it has resource, and timing is long, and is flexible and convenient to use.
Another object of the present invention is to provide the regularly software timing method of length of a kind of dynamic heavy duty, to solve the problem of hardware resource deficiency, greatly simplify software complexity, accelerate design process.
The objective of the invention is to be achieved through the following technical solutions.
A kind of dynamic heavy duty is the software timing method of length regularly, comprises step:
A: create a hardware timer, base when setting minimum reference simultaneously, and to the hardware timer initialization;
B: after obtaining the object success of a hardware timer, the soft timer module of initialization service layer;
C: create a soft timer, timing is set, start soft timer;
D: according to timing, carry out corresponding thread process, in the task of corresponding software timer, the message that receives is judged, if timer message, just process the message of soft timer.
Preferably, step b specifically comprises: the action listener of registration soft timer, base when benchmark is set is for the service layer soft timer creates semaphore, mutual exclusion institute and creates the task of processing soft timer message.
Preferably, step c specifically comprises:
C1: judge whether it is that hardware is timed to, if regularly be less than, just continue timing and wait for; If so, enter step c2;
C2: whether the chained list of judging software timer is empty, if be empty, just gets back to the judgement that hardware is timed to; If be not empty, then enter step c3;
C3: take out the software timer of an assigned I D in the chained list, the count value of software timer subtracts one;
C4: judge that whether current count value is zero, if non-vanishing, then gets back to the judgement that hardware is timed to; If be zero, then enter step c5;
C5: the task of sending the corresponding software timer of Message Processing of a soft timer.
Preferably, in the steps d, the message that receives is judged, if not timer message, other message of respective handling then.
The present invention compared with prior art, beneficial effect is: dynamic heavy duty provided by the invention is software timing method and the software timer of length regularly, is the basis by hardware timer, utilizes the Interruption of hardware timer to realize.Software timer need to take cpu resource, but its resource is many, and timing is long, and is flexible and convenient to use, in the application scenario of complication system or timer working method complexity, solves the problem of hardware resource deficiency, greatly simplifies software complexity, accelerates design process.
Embodiment
Core concept of the present invention: the present invention adds priority in software timer, and the mechanism of a kind of event notice-monitoring is provided, for the interrupt management module of operating system is used.After interrupting generation, the interrupt management module can be adjusted back user's function, and the user judges whether and need to go distribution by the task of interrupt management, if do not need then processed by the user, otherwise it can trigger interrupt management module distributed tasks, and this task can be gone out the corresponding event notice of this interrupt number.It is directly to adjust back user's processing function or be put in the task to process that the interrupt management module can be gone according to different needs to dispatch when interrupting producing.And to timer estimation ﹠ disposing then, created a timer management task that priority ratio is higher, in this task, carry out then judgement and the processing of timer.The action listener function is given the task of this high priority by the signal release semaphore, make its picked up signal amount.This method has shortened the execution time of interrupt service routine, thereby improves the real-time of system.
In order to make purpose of the present invention, technical scheme and advantage clearer, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein 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 categorical data structure of carrying out unified management for the different timing service.Software timer can make system carry out assigned operation in a certain definite moment.It is take programmable Timer/counter or single stabilization delay circuit as the basis, and the Interruption that utilizes hardware timer to produce is realized.
See also shown in Figure 1ly, software timer of the present invention comprises:
1, the establishment of software timer: create a software timer, obtain simultaneously ID number an of software timer, within 0-128, can not surpass, otherwise be considered as creating unsuccessful for ID number.There is single to use or recycle dual mode.
Base when 2, the benchmark of soft timer being set: minimum timing unit.Can set requirement regularly according to system.The timing of same time span, different time bases have different timing accuracies.
3, start soft timer: obtain corresponding ID number beginning timework after having created a timer.There is different entry conditions different application scenarios: pulse, level, event, interruption etc.
4, stop soft timer: stop the timing of software timer, namely reset.
5, the prevalue of software timer: set the timing initial value to soft timer.After starting soft timer, begin on this basis timing.
6, obtain the soft timer currency: the count value that obtains soft timer current time in timing course.Can be used for testing timing etc.
The realization of software timer mainly is the Interruption that is produced by hardware timer, hardware timer provides two kinds of Interrupt Processing Models, a kind of is at the next direct call back function of Direct Model, another member function that is non-Direct Model then needs to call the interrupt management class adds event functions, just enters event-monitoring mechanism and realizes interrupt mechanism.And the mode of software timer realization here mainly is event-monitoring mechanism.It is by processing release semaphore in the function in event interrupt, and the picked up signal amount is processed variety of event in thread.
Software timer is before creating, base value when arranging one by hardware timer first (minimum Tick), then generate a software timer, designated software timer timing time is set, start timer, if timing has arrived, just enter and go in the corresponding thread to process, at first by judging whether it is the message of timer, if the message of timer just removes to process the Message function of timer, if not, just do other processing.
See also shown in Figure 2ly, the present invention is the heavy duty software timing method of length regularly dynamically, comprising:
Step 201: create a hardware timer, base when setting minimum reference simultaneously.Start hardware timer, simultaneously given hard timer base class sub-object is carried out timer encapsulation initialization.
Step 202: after obtaining the object success of a hardware timer, the soft timer module of initialization service layer.Comprise the action listener of registering soft timer, base when benchmark is set is for the service layer soft timer creates semaphore, mutual exclusion institute and creates task of processing soft timer message etc.
Step 203: create a soft timer, timing is set, start soft timer.
Step 204: according to timing, carry out corresponding thread process.
As shown in Figure 3, concrete thread process comprises:
Step 301: judge whether it is that hardware is timed to, if regularly be less than, just continue timing and wait for; If so, enter step 302.
Step 302: whether the chained list of judging software timer is empty, if be empty, just gets back to the judgement that hardware is timed to; If be not empty, then enter step 303.
Step 303: take out the software timer of an assigned I D in the chained list, the count value of software timer subtracts one.
Step 304: judge that whether current count value is zero, if non-vanishing, then gets back to the judgement that hardware is timed to; If be zero, then enter step 305.
Step 305: the task of sending the corresponding software timer of Message Processing of a soft timer.
Step 205: in the task of corresponding software timer, the message that receives is judged, if timer message, just processed the message of soft timer; If not, with regard to other message of respective handling.
Among the present invention, hardware timer (OMAP-L137) is for having the processor of ARM926EJ-S and C674x Floating-point DSP kernel, each examines dominant frequency can reach the 300MHz clock, and the timer/counter module of this hardware timer contains two the identical 64 bit timings device of function/counter passages.This timer has four kinds of timing modes: 64 general timing mode, two 32 general timing modes of non-chain type, two 32 chain type timing modes, house dog timing mode; Timing mode of the present invention adopts two 32 general timing modes of non-chain type, two 64 timers is divided into four 32 timer.
Dynamic heavy duty provided by the invention is software timing method and the software timer of length regularly, is the basis by hardware timer, utilizes the Interruption of hardware timer to realize.Software timer need to take cpu resource, but its resource is many, and timing is long, and is flexible and convenient to use, in the application scenario of complication system or timer working method complexity, solves the problem of hardware resource deficiency, greatly simplifies software complexity, accelerates design process.
The above only is preferred embodiment of the present invention, not in order to limiting the present invention, all any modifications of doing within the spirit and principles in the present invention, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.