FreeRTOS Software Timers

Source: Internet
Author: User

API Functions

Create
timerhandle_t xtimercreate (const char * const PCTIMERNAME,
                            const ticktype_t xtimerperiodinticks,
                            Const ubasetype_t Uxautoreload,
                            void * Const Pvtimerid,
                            timercallbackfunction_t pxcallbackfunction)

//Start
#define Xtimerstart (Xtimer, xtickstowait) Xtimergenericcommand ((Xtimer), Tmrcommand_start, 
    ( Xtaskgettickcount ()), NULL, (xtickstowait))
basetype_t Xtimergenericcommand (timerhandle_t xtimer, const BASETYPE _t Xcommandid, 
    const ticktype_t xoptionalvalue, basetype_t * Const Pxhigherprioritytaskwoken, 
    const TICKTYPE _t xtickstowait)

//Stop
#define XTIMERSTOP (Xtimer, xtickstowait) Xtimergenericcommand ((Xtimer), Tmrcommand_ STOP, 
    0U, NULL, (xtickstowait))

Example

void Start_task (void *pvparameters) {//Create software cycle timers.
                                        Cycle 1s (1000 clock beats), Cycle mode autoreloadtimer_handle=xtimercreate ((const char*) "Autoreloadtimer",
                                        (ticktype_t), (ubasetype_t) Pdtrue, (void*) 1, (timercallbackfunction_t)

    Autoreloadcallback); Create a one-time timer.
                                     Cycle 2s (2000 clock beats), single-mode oneshottimer_handle=xtimercreate ((const char*) "Oneshottimer",
                                     (ticktype_t), (ubasetype_t) Pdfalse, (void*) 2, (timercallbackfunction_t) Onesh
Otcallback);
    }//Cycle timer callback function void Autoreloadcallback (timerhandle_t xtimer) {static U8 tmr1_num=0;     tmr1_num++; Cycle timer execution times plus 1 printf ("Autoreloadcallback%d\r\n", tMr1_num);
    }//single-timer callback function void Oneshotcallback (timerhandle_t xtimer) {static U8 Tmr2_num = 0;     tmr2_num++;
Single timer execution times plus 1 printf ("Oneshotcallback%d\r\n", tmr2_num);
        } void Timercontrol_task (void *pvparameters) {while (1) {key = Key_scan (0); Switch (key) {case Wkup_pres://When KEY_UP is pressed, turn on the cycle timer Xtimerstart (Autoreloadtimer_han  dle,0);
                Open Cycle Timer printf ("Turn on Timer 1\r\n");
            Break     Case Key0_pres://When KEY0 is pressed, a single timer xtimerstart (oneshottimer_handle,0) is opened;
                Turn on single timer printf ("Turn on Timer 2\r\n");
            Break   Case Key1_pres://When Key1 is pressed, the timer xtimerstop (autoreloadtimer_handle,0) is turned off;      Close Cycle Timer xtimerstop (oneshottimer_handle,0);
                Turn off the single timer printf ("Off timer 1 and 2\r\n");  
        Break } vtaskdelay (10); Delay 10ms, i.e. 10 clock ticks}}

experimental phenomenon

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.