Contiki 2.5
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
core
sys
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
* @(#)$Id: rtimer.c,v 1.7 2010/01/19 13:08:24 adamdunkels Exp $
46
*/
47
48
#include "
sys/rtimer.h
"
49
#include "contiki.h"
50
51
#define DEBUG 0
52
#if DEBUG
53
#include <stdio.h>
54
#define PRINTF(...) printf(__VA_ARGS__)
55
#else
56
#define PRINTF(...)
57
#endif
58
59
static
struct
rtimer
*next_rtimer;
60
61
/*---------------------------------------------------------------------------*/
62
void
63
rtimer_init
(
void
)
64
{
65
rtimer_arch_init();
66
}
67
/*---------------------------------------------------------------------------*/
68
int
69
rtimer_set
(
struct
rtimer
*
rtimer
, rtimer_clock_t time,
70
rtimer_clock_t duration,
71
rtimer_callback_t func,
void
*ptr)
72
{
73
int
first = 0;
74
75
PRINTF(
"rtimer_set time %d\n"
, time);
76
77
if
(next_rtimer ==
NULL
) {
78
first = 1;
79
}
80
81
rtimer->func = func;
82
rtimer->ptr = ptr;
83
84
rtimer->time = time;
85
next_rtimer = rtimer;
86
87
if
(first == 1) {
88
rtimer_arch_schedule(time);
89
}
90
return
RTIMER_OK;
91
}
92
/*---------------------------------------------------------------------------*/
93
void
94
rtimer_run_next
(
void
)
95
{
96
struct
rtimer
*t;
97
if
(next_rtimer ==
NULL
) {
98
return
;
99
}
100
t = next_rtimer;
101
next_rtimer =
NULL
;
102
t->func(t, t->ptr);
103
if
(next_rtimer !=
NULL
) {
104
rtimer_arch_schedule(next_rtimer->time);
105
}
106
return
;
107
}
108
/*---------------------------------------------------------------------------*/
Generated on Fri Aug 30 2013 12:34:07 for Contiki 2.5 by
1.8.3.1