Contiki-NG
clock.h
1 /*
2  * Copyright (c) 2004, Swedish Institute of Computer Science.
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  *
32  *
33  */
34
36  * @{
37  */
38
39 /**
40  * \defgroup clock Clock library
41  *
42  * The clock library is the interface between Contiki and the platform
43  * specific clock functionality. The clock library defines a macro,
44  * CLOCK_SECOND, to convert seconds into the tick resolution of the platform.
45  * Typically this is 1-10 milliseconds, e.g. 4*CLOCK_SECOND could be 512.
46  * A 16 bit counter would thus overflow every 1-10 minutes.
47  * Platforms use the tick interrupt to maintain a long term count
48  * of seconds since startup.
49  *
50  * Platforms may also implement rtimers for greater time resolution
51  * and for real-time interrupts, These use a corresponding RTIMER_SECOND.
52  *
53  * \note These timers do not necessarily have a common divisor or are phase locked.
54  * One may be crystal controlled and the other may not. Low power operation
55  * or sleep will often use one for wake and disable the other, then give
56  * it a tick correction after wakeup.
57  *
58  * \note The clock library need in many cases not be used
59  * directly. Rather, the \ref timer "timer library", \ref etimer
60  * "event timers", or \ref rtimer "rtimer library" should be used.
61  *
62  * \sa \ref timer "Timer library"
63  * \sa \ref etimer "Event timers"
64  * \sa \ref rtimer "Realtime library"
65  *
66  * @{
67  */
68
69 #ifndef CLOCK_H_
70 #define CLOCK_H_
71
72 #include "contiki.h"
73
74 /**
75  * A second, measured in system clock time.
76  *
77  * \hideinitializer
78  */
79 #ifdef CLOCK_CONF_SECOND
80 #define CLOCK_SECOND CLOCK_CONF_SECOND
81 #else
82 #define CLOCK_SECOND (clock_time_t)32
83 #endif
84
85 /**
86  * Initialize the clock library.
87  *
88  * This function initializes the clock library and should be called
89  * from the main() function of the system.
90  *
91  */
92 void clock_init(void);
93
94 /**
95  * Get the current clock time.
96  *
97  * This function returns the current system clock time.
98  *
99  * \return The current clock time, measured in system ticks.
100  */
101 clock_time_t clock_time(void);
102
103 /**
104  * Get the current value of the platform seconds.
105  *
106  * This could be the number of seconds since startup, or
107  * since a standard epoch.
108  *
109  * \return The value.
110  */
111 unsigned long clock_seconds(void);
112
113 /**
114  * Set the value of the platform seconds.
115  * \param sec The value to set.
116  *
117  */
118 void clock_set_seconds(unsigned long sec);
119
120 /**
121  * Wait for a given number of ticks.
122  * \param t How many ticks.
123  *
124  */
125 void clock_wait(clock_time_t t);
126
127 /**
128  * Delay a given number of microseconds.
129  * \param dt How many microseconds to delay.
130  *
131  * \note Interrupts could increase the delay by a variable amount.
132  */
133 void clock_delay_usec(uint16_t dt);
134
135 /**
136  * Deprecated platform-specific routines.
137  *
138  */
139 int clock_fine_max(void);
140 unsigned short clock_fine(void);
141 void clock_delay(unsigned int delay);
142
143 #endif /* CLOCK_H_ */
144
145 /** @} */
146 /** @} */
unsigned long clock_seconds(void)
Get the current value of the platform seconds.
Definition: clock.c:130
clock_time_t clock_time(void)
Get the current clock time.
Definition: clock.c:118
int clock_fine_max(void)
Deprecated platform-specific routines.
Definition: clock.c:129
void clock_init(void)
Initialize the clock library.
Definition: clock.c:93
void clock_delay(unsigned int delay)
Obsolete delay function but we implement it here since some code still uses it.
Definition: clock.c:164
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
Definition: clock.c:150
void clock_set_seconds(unsigned long sec)
Set the value of the platform seconds.
Definition: clock.c:124
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
Definition: clock.c:136