[RTT routine exercises] 4.4 Timer control

Source: Internet
Author: User

The timer can pass throughrt_timer_control() To change some features of the timer, such as the timer time.

Here, the scheduled cycle starts from 100 and is used in the program

rt_tick_get()-tick

To check whether the scheduled cycle is as scheduled. After 8 times, usert_timer_control(), Change the scheduled period to 3000. The actual effect can be verified by printed tick information and intuitive feelings.

Program:

#include <rtthread.h>static rt_timer_t timer1;//static rt_timer_t timer2;static rt_uint8_t count;static rt_tick_t tick;static void timeout1(void* parameter){    rt_tick_t timeout = 3000;    rt_kprintf("periodic timer is timeout\n");        rt_kprintf("the time set is %d\n", (rt_tick_get()-tick));    tick = rt_tick_get();    count ++;       if (count >= 8)    {        rt_timer_control(timer1, RT_TIMER_CTRL_SET_ONESHOT, (void *)&timeout);            rt_timer_control(timer1, RT_TIMER_CTRL_SET_TIME, (void *)&timeout);        count = 0;    }}int rt_application_init(){    timer1 = rt_timer_create("timer1",        timeout1,        RT_NULL,        100,        RT_TIMER_FLAG_PERIODIC);        if (timer1 != RT_NULL)        rt_timer_start(timer1);      return 0;}

Result:

periodic timer is timeoutthe time set is 100periodic timer is timeoutthe time set is 100periodic timer is timeoutthe time set is 100periodic timer is timeoutthe time set is 100periodic timer is timeoutthe time set is 100periodic timer is timeoutthe time set is 100periodic timer is timeoutthe time set is 100periodic timer is timeoutthe time set is 100periodic timer is timeoutthe time set is 3000periodic timer is timeoutthe time set is 3000periodic timer is timeoutthe time set is 3000periodic timer is timeoutthe time set is 3000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.