Contiki rtimer Module

Source: Internet
Author: User
I. rtimer Overview

The contiki rtimer Library provides scheduling and execution of real-time tasks (Predictable execution times)

Data structure:

struct rtimer {  rtimer_clock_t time;  rtimer_callback_t func;  void *ptr;};
typedef void (* rtimer_callback_t)(struct rtimer *t, void *ptr);
1. rtimer_init
voidrtimer_init(void){  rtimer_arch_init();}

Rtimer_arch_initIs related to the platform,Rtimer_arch_init ()Is called by the rtimer library to initialize the rtimer architecture code.

2. rtimer_set
Intrtimer_set (struct rtimer * rtimer, interval time, Interval Duration, rtimer_callback_t func, void * PTR) {int first = 0; printf ("rtimer_set time % d \ n", time ); if (next_rtimer = NULL) {// null, set first to 1 first = 1;} rtimer-> func = func; // set the callback function rtimer-> PTR = PTR; // The first parameter of the callback function, rtimer-> time = time; // sets next_rtimer = rtimer; // sets next_rtimer if (first = 1) {// if it is 1 rtimer_arch_schedule (time );}}

 

Rtimer is used to set rtimer, that is, to execute a specific callback function (func) at a specific time ).

The rtimer_arch_schedule function is platform-related and is used at the underlying layer to determine the time for calling rtimer_run_next. rtimer_run_next will execute the callback function at a specific time.

3. rtimer_run_next
Voidrtimer_run_next (void) {struct rtimer * t; If (next_rtimer = NULL) {return ;}t = next_rtimer; next_rtimer = NULL; // reset to null T-> func (t, t-> PTR); // execute the callback function if (next_rtimer! = NULL) {// rtimer set exists during callback function execution. rtimer_arch_schedule (next_rtimer-> time) is called once;} return ;}

 

Rtimer_run_next calls the specific next_rtimer callback function.

Rtimer_run_next is called at the underlying layer.

 

Intuitive process:

Rtimer_set (set rtimer) ---> rtimer_arch_schedule (inform the underlying layer at a specific time) ------> rtimer_run_next (execute the callback function at a specific time) -------> rtimer_set

 

Note: rtimer_now () rtimer_second rtimer_arch_init () rtimer_arch_now () rtimer_arch_schedule () and so on are all platform-related.

Contiki rtimer Module

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.