EVE 1.0
clock.h
1 /** \addtogroup sys
2  * @{
3  */
4 
5 /**
6  * \defgroup clock Clock library
7  *
8  * The clock library is the interface between Contiki and the platform
9  * specific clock functionality. The clock library defines a macro,
10  * CLOCK_SECOND, to convert seconds into the tick resolution of the platform.
11  * Typically this is 1-10 milliseconds, e.g. 4*CLOCK_SECOND could be 512.
12  * A 16 bit counter would thus overflow every 1-10 minutes.
13  * Platforms use the tick interrupt to maintain a long term count
14  * of seconds since startup.
15  *
16  * Platforms may also implement rtimers for greater time resolution
17  * and for real-time interrupts, These use a corresponding RTIMER_SECOND.
18  *
19  * \note These timers do not necessarily have a common divisor or are phase locked.
20  * One may be crystal controlled and the other may not. Low power operation
21  * or sleep will often use one for wake and disable the other, then give
22  * it a tick correction after wakeup.
23  *
24  * \note The clock library need in many cases not be used
25  * directly. Rather, the \ref timer "timer library", \ref etimer
26  * "event timers", or \ref trimer "rtimer library" should be used.
27  *
28  * \sa \ref timer "Timer library"
29  * \sa \ref etimer "Event timers"
30  * \sa \ref rtimer "Realtime library"
31  *
32  * @{
33  */
34 
35 /*
36  * Copyright (c) 2004, Swedish Institute of Computer Science.
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  * notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  * notice, this list of conditions and the following disclaimer in the
46  * documentation and/or other materials provided with the distribution.
47  * 3. Neither the name of the Institute nor the names of its contributors
48  * may be used to endorse or promote products derived from this software
49  * without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
55  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61  * SUCH DAMAGE.
62  *
63  * This file is part of the Contiki operating system.
64  *
65  * Author: Adam Dunkels <adam@sics.se>
66  *
67  */
68 #ifndef CLOCK_H_
69 #define CLOCK_H_
70 
71 #include "contiki-conf.h"
72 
73 /**
74  * A second, measured in system clock time.
75  *
76  * \hideinitializer
77  */
78 #ifdef CLOCK_CONF_SECOND
79 #define CLOCK_SECOND CLOCK_CONF_SECOND
80 #else
81 #define CLOCK_SECOND (clock_time_t)32
82 #endif
83 
84 #define MS_TO_TICKS(x) ((x) * CLOCK_SECOND / 1000)
85 #define S_TO_TICKS(x) ((x) * CLOCK_SECOND)
86 
87 /**
88  * Initialize the clock library.
89  *
90  * This function initializes the clock library and should be called
91  * from the main() function of the system.
92  *
93  */
94 void clock_init(void);
95 
96 /**
97  * Get the current clock time.
98  *
99  * This function returns the current system clock time.
100  *
101  * \return The current clock time, measured in system ticks.
102  */
103 CCIF clock_time_t clock_time(void);
104 
105 /**
106  * Get the current value of the platform seconds.
107  *
108  * This could be the number of seconds since startup, or
109  * since a standard epoch.
110  *
111  * \return The value.
112  */
113 CCIF unsigned long clock_seconds(void);
114 
115 #ifdef CLOCK_CONF_TICKLESS
116 /**
117  * Update wakeup interval for tickless system
118  */
119 CCIF void arch_update_time(void);
120 #endif
121 
122 /**
123  * Set the value of the platform seconds.
124  * \param sec The value to set.
125  *
126  */
127 void clock_set_seconds(unsigned long sec);
128 
129 /**
130  * Wait for a given number of ticks.
131  * \param t How many ticks.
132  *
133  */
134 void clock_wait(clock_time_t t);
135 
136 /**
137  * Delay a given number of microseconds.
138  * \param dt How many microseconds to delay.
139  *
140  * \note Interrupts could increase the delay by a variable amount.
141  */
142 void clock_delay_usec(uint16_t dt);
143 
144 /**
145  * Deprecated platform-specific routines.
146  *
147  */
148 int clock_fine_max(void);
149 unsigned short clock_fine(void);
150 void clock_delay(unsigned int delay);
151 
152 #endif /* CLOCK_H_ */
153 
154 /** @} */
155 /** @} */
CCIF clock_time_t clock_time(void)
Definition: clock.c:195
int clock_fine_max(void)
void clock_init(void)
Definition: clock.c:170
void clock_delay_usec(uint16_t dt)
Definition: clock.c:244
void clock_set_seconds(unsigned long sec)
Definition: clock.c:207
CCIF unsigned long clock_seconds(void)
Definition: clock.c:201
void clock_wait(clock_time_t t)
Definition: clock.c:214