Contiki-Inga 3.x
rtimer.c
Go to the documentation of this file.
1 /**
2  * \addtogroup rt
3  * @{
4  */
5 
6 /**
7  * \file
8  * Implementation of the architecture-agnostic parts of the real-time timer module.
9  * \author
10  * Adam Dunkels <adam@sics.se>
11  *
12  */
13 
14 
15 /*
16  * Copyright (c) 2005, Swedish Institute of Computer Science
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  * 1. Redistributions of source code must retain the above copyright
23  * notice, this list of conditions and the following disclaimer.
24  * 2. Redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in the
26  * documentation and/or other materials provided with the distribution.
27  * 3. Neither the name of the Institute nor the names of its contributors
28  * may be used to endorse or promote products derived from this software
29  * without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
35  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41  * SUCH DAMAGE.
42  *
43  * This file is part of the Contiki operating system.
44  *
45  */
46 
47 #include "sys/rtimer.h"
48 #include "contiki.h"
49 
50 #define DEBUG 0
51 #if DEBUG
52 #include <stdio.h>
53 #define PRINTF(...) printf(__VA_ARGS__)
54 #else
55 #define PRINTF(...)
56 #endif
57 
58 static struct rtimer *next_rtimer;
59 
60 /*---------------------------------------------------------------------------*/
61 void
63 {
65 }
66 /*---------------------------------------------------------------------------*/
67 int
68 rtimer_set(struct rtimer *rtimer, rtimer_clock_t time,
69  rtimer_clock_t duration,
70  rtimer_callback_t func, void *ptr)
71 {
72  int first = 0;
73 
74  PRINTF("rtimer_set time %d\n", time);
75 
76  if(next_rtimer == NULL) {
77  first = 1;
78  }
79 
80  rtimer->func = func;
81  rtimer->ptr = ptr;
82 
83  rtimer->time = time;
84  next_rtimer = rtimer;
85 
86  if(first == 1) {
88  }
89  return RTIMER_OK;
90 }
91 /*---------------------------------------------------------------------------*/
92 void
94 {
95  struct rtimer *t;
96  if(next_rtimer == NULL) {
97  return;
98  }
99  t = next_rtimer;
100  next_rtimer = NULL;
101  t->func(t, t->ptr);
102  if(next_rtimer != NULL) {
103  rtimer_arch_schedule(next_rtimer->time);
104  }
105  return;
106 }
107 /*---------------------------------------------------------------------------*/