Contiki 3.x
timesynch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Header file for a simple time synchronization mechanism
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup sys
42  * @{
43  */
44 
45 /**
46  * \defgroup timesynch Implicit network time synchronization
47  * @{
48  *
49  * This crude and simple network time synchronization module
50  * synchronizes clocks of all nodes in a network. The time
51  * synchronization is implicit in that no explicit time
52  * synchronization messages are sent: the module relies on the
53  * underlying network device driver to timestamp all radio messages,
54  * both outgoing and incoming. The code currently only works on the
55  * Tmote Sky platform and the cc2420 driver.
56  *
57  * Every node has an authority level, which is included in every
58  * outgoing packet. If a message is received from a node with higher
59  * authority (lower authority number), the node adjusts its clock
60  * towards the clock of the sending node.
61  *
62  * The timesynch module is implemented as a meta-MAC protocol, so that
63  * the module is invoked for every incoming packet.
64  *
65  */
66 
67 #ifndef TIMESYNCH_H_
68 #define TIMESYNCH_H_
69 
70 #include "net/mac/mac.h"
71 #include "sys/rtimer.h"
72 
73 /**
74  * \brief Initialize the timesynch module
75  *
76  * This function initializes the timesynch module. This
77  * function must not be called before rime_init().
78  *
79  */
80 void timesynch_init(void);
81 
82 /**
83  * \brief Get the current time-synchronized time
84  * \return The current time-synchronized time
85  *
86  * This function returns the current time-synchronized
87  * time.
88  *
89  */
90 rtimer_clock_t timesynch_time(void);
91 
92 /**
93  * \brief Get the current time-synchronized time, suitable for use with the rtimer module
94  * \return The current time-synchronized rtimer time
95  *
96  * This function returns the (local) rtimer-equivalent
97  * time corresponding to the current time-synchronized
98  * (global) time. The rtimer-equivalent time is used for
99  * setting rtimer timers that are synchronized to other
100  * nodes in the network.
101  *
102  */
103 rtimer_clock_t timesynch_time_to_rtimer(rtimer_clock_t synched_time);
104 
105 /**
106  * \brief Get the synchronized equivalent of an rtimer time
107  * \return The synchronized equivalent of an rtimer time
108  *
109  * This function returns the time synchronized equivalent
110  * time corresponding to a (local) rtimer time.
111  *
112  */
113 rtimer_clock_t timesynch_rtimer_to_time(rtimer_clock_t rtimer_time);
114 
115 /**
116  * \brief Get the current time-synchronized offset from the rtimer clock, which is used mainly for debugging
117  * \return The current time-synchronized offset from the rtimer clock
118  *
119  * This function returns the current time-synchronized
120  * offset from the rtimer arch clock. This is mainly
121  * useful for debugging the timesynch module.
122  *
123  */
124 rtimer_clock_t timesynch_offset(void);
125 
126 /**
127  * \brief Get the current authority level of the time-synchronized time
128  * \return The current authority level of the time-synchronized time
129  *
130  * This function returns the current authority level of
131  * the time-synchronized time. A node with a lower
132  * authority level is defined to have a better notion of
133  * time than a node with a higher authority
134  * level. Authority level 0 is best and should be used by
135  * a sink node that has a connection to an outside,
136  * "true", clock source.
137  *
138  */
139 int timesynch_authority_level(void);
140 
141 /**
142  * \brief Set the authority level of the current time
143  * \param level The authority level
144  */
145 void timesynch_set_authority_level(int level);
146 
147 #endif /* TIMESYNCH_H_ */
148 
149 /** @} */
150 /** @} */
void timesynch_init(void)
Initialize the timesynch module.
int timesynch_authority_level(void)
Get the current authority level of the time-synchronized time.
rtimer_clock_t timesynch_rtimer_to_time(rtimer_clock_t rtimer_time)
Get the synchronized equivalent of an rtimer time.
rtimer_clock_t timesynch_time(void)
Get the current time-synchronized time.
void timesynch_set_authority_level(int level)
Set the authority level of the current time.
Header file for the real-time timer module.
rtimer_clock_t timesynch_time_to_rtimer(rtimer_clock_t synched_time)
Get the current time-synchronized time, suitable for use with the rtimer module.
MAC driver header file
rtimer_clock_t timesynch_offset(void)
Get the current time-synchronized offset from the rtimer clock, which is used mainly for debugging...