Contiki 2.5
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 performs a single
10  * function: measuring time. Additionally, the clock library provides
11  * a macro, CLOCK_SECOND, which corresponds to one second of system
12  * time.
13  *
14  * \note The clock library need in many cases not be used
15  * directly. Rather, the \ref timer "timer library" or the \ref etimer
16  * "event timers" should be used.
17  *
18  * \sa \ref timer "Timer library"
19  * \sa \ref etimer "Event timers"
20  *
21  * @{
22  */
23 
24 /*
25  * Copyright (c) 2004, Swedish Institute of Computer Science.
26  * All rights reserved.
27  *
28  * Redistribution and use in source and binary forms, with or without
29  * modification, are permitted provided that the following conditions
30  * are met:
31  * 1. Redistributions of source code must retain the above copyright
32  * notice, this list of conditions and the following disclaimer.
33  * 2. Redistributions in binary form must reproduce the above copyright
34  * notice, this list of conditions and the following disclaimer in the
35  * documentation and/or other materials provided with the distribution.
36  * 3. Neither the name of the Institute nor the names of its contributors
37  * may be used to endorse or promote products derived from this software
38  * without specific prior written permission.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * This file is part of the Contiki operating system.
53  *
54  * Author: Adam Dunkels <adam@sics.se>
55  *
56  * $Id: clock.h,v 1.11 2009/01/24 15:20:11 adamdunkels Exp $
57  */
58 #ifndef __CLOCK_H__
59 #define __CLOCK_H__
60 
61 #include "contiki-conf.h"
62 
63 #if 0 /* XXX problems with signedness and use in timer_expired(). #if:ed it out for now. */
64 /**
65  * Check if a clock time value is less than another clock time value.
66  *
67  * This macro checks if a clock time value is less than another clock
68  * time value. This macro is needed to correctly handle wrap-around of
69  * clock time values.
70  *
71  */
72 #define CLOCK_LT(a, b) ((clock_time_t)((a) - (b)) < ((clock_time_t)(~((clock_time_t)0)) >> 1))
73 #endif /* 0 */
74 
75 /**
76  * Initialize the clock library.
77  *
78  * This function initializes the clock library and should be called
79  * from the main() function of the system.
80  *
81  */
82 void clock_init(void);
83 
84 /**
85  * Get the current clock time.
86  *
87  * This function returns the current system clock time.
88  *
89  * \return The current clock time, measured in system ticks.
90  */
91 CCIF clock_time_t clock_time(void);
92 
93 void clock_delay(unsigned int);
94 
95 /**
96  * A second, measured in system clock time.
97  *
98  * \hideinitializer
99  */
100 #ifdef CLOCK_CONF_SECOND
101 #define CLOCK_SECOND CLOCK_CONF_SECOND
102 #else
103 #define CLOCK_SECOND (clock_time_t)32
104 #endif
105 
106 int clock_fine_max(void);
107 unsigned short clock_fine(void);
108 
109 CCIF unsigned long clock_seconds(void);
110 
111 
112 #endif /* __CLOCK_H__ */
113 
114 /** @} */
115 /** @} */