uC / OS-III software timer (III)

Software timer is a kernel object uC / OS operating system, the software is based on software timer tick of the timer clock and system management to create, in theory, you can create an unlimited number, simple operation, but the timing accuracy is certainly a little more than hardware Johnson the edge.

Principles and implementation process

To use the function:

OSTmrCreate () // Create a timer

OSTmrDel () // delete timer

OSTmrStart () // starts a timer

OSTmrStop () // stop timer

 

Before using a timer to enable the software to enable timer located "os_cfg.h".

 

 

 Its configuration parameters located about "os_cpu_app.h".

 

 

OSTmrCreate ()

To use uC / OS software timer must declare and create software timers, call OSTmrCreate () function to create a software timer. OSTmrCreate () function in the following table information.

 

 

 

 

 

OSTmrDel ()

OSTmrDel () function is used to delete a software timer. OSTmrDel () function in the following table information.

 

 

 

 

 

OSTmrStart ()

After creating a software timer, the timer if you want to use the software, you need to call OSTmrStart () function to start the software timer. OSTmrStart () function in the following table information.

 

OSTmrStop ()

OSTmrStop () function is used to stop a software timer. Software timer can be stopped calling after OSTmrStart () function to restart, but after the restart timer is counting from the beginning, rather than the last stop and then continue timing the moment. OSTmrStop () function in the following table information.

 

to sum up:

1. To use the software timers, we must first declare a OS_TMR object and function to create the software timer by OSTmrCreate (). Software Timer sub OS_OPT_TMR_ONE_SHOT and OS_OPT_TMR_PERIODIC two types. The former is equivalent to burst mode is equivalent to a hardware timer, the timing of the implementation of a one-time, after time to complete a software timer to stop working, you need to start to work again again. The latter is equivalent to a hardware timer cycle mode, with a heavy duty cycle values, the cycle can continue to work without restarting.

2.软件定时器创建完成之后,还无法立即工作,需要调用OSTmrStart()函数来启动它投入工作。OSTmrStop()函数可以停止一个软件定时器,但它只是被停止了定时,而并没有被删除。如果还想继续使用该软件定时器定时,调用OSTmrStart()函数启动它即可,但启动后是重新定时,而不是紧接着停止时的时间继续计时。

3.OSTmrDel()函数用于删除一个软件定时器,删除之后该软件定时器不能再被使用。

软件定时和延时任务的区别:

调用OSTimeDl()或者OSTimeDlyHMSM(),意味着该任务CPU使用权会被没收,然而你开启一个定时器之后,该任务还可以使用CPU。例如:有延时任务A和普通任务B,任务A延时后就被剥夺CPU使用权了,直到任务A的延时时间到来。而在任务B中,开启了一个软件定时器,任务B还会继续执行下去,直到定时器的到来,程序去执行软件定时器调用的函数,执行完之后再回来接着执行任务B。所以总的区别就是,是否还拥有CPU的使用权利。

 

Guess you like

Origin www.cnblogs.com/lailai-laird/p/11628265.html