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