Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
clock.h
1
/*
2
* Copyright (c) 2004, 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
* Author: Adam Dunkels <adam@sics.se>
32
*
33
*/
34
35
/** \addtogroup timers
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 <inttypes.h>
73
74
/** \brief The clock size (in bytes). */
75
#ifdef CLOCK_CONF_SIZE
76
#define CLOCK_SIZE CLOCK_CONF_SIZE
77
#else
/* CLOCK_CONF_SIZE */
78
#define CLOCK_SIZE 8
79
#endif
/* CLOCK_CONF_SIZE */
80
81
/* Define clock_time_t before including contiki.h, so etimer.h
82
* and other header files have clock_time_t defined. */
83
#if CLOCK_SIZE == 4
84
typedef
uint32_t clock_time_t;
85
#define CLOCK_LT(a, b) ((int32_t)((a) - (b)) < 0)
86
#define CLOCK_PRI PRIu32
87
#elif CLOCK_SIZE == 8
88
typedef
uint64_t clock_time_t;
89
#define CLOCK_LT(a, b) ((int64_t)((a) - (b)) < 0)
90
#define CLOCK_PRI PRIu64
91
#else
92
#error Unsupported clock_time_t size (check CLOCK_CONF_SIZE)
93
#endif
94
95
#include "contiki.h"
96
97
/**
98
* A second, measured in system clock time.
99
*
100
* \hideinitializer
101
*/
102
#ifdef CLOCK_CONF_SECOND
103
#define CLOCK_SECOND CLOCK_CONF_SECOND
104
#else
105
#define CLOCK_SECOND (clock_time_t)32
106
#endif
107
108
/**
109
* Initialize the clock library.
110
*
111
* This function initializes the clock library and should be called
112
* from the main() function of the system.
113
*
114
*/
115
void
clock_init
(
void
);
116
117
/**
118
* Get the current clock time.
119
*
120
* This function returns the current system clock time.
121
*
122
* \return The current clock time, measured in system ticks.
123
*/
124
clock_time_t
clock_time
(
void
);
125
126
/**
127
* Get the current value of the platform seconds.
128
*
129
* This could be the number of seconds since startup, or
130
* since a standard epoch.
131
*
132
* \return The value.
133
*/
134
unsigned
long
clock_seconds
(
void
);
135
136
/**
137
* Set the value of the platform seconds.
138
* \param sec The value to set.
139
*
140
*/
141
void
clock_set_seconds
(
unsigned
long
sec);
142
143
/**
144
* Wait for a given number of ticks.
145
* \param t How many ticks.
146
*
147
*/
148
void
clock_wait
(clock_time_t t);
149
150
/**
151
* Delay a given number of microseconds.
152
* \param dt How many microseconds to delay.
153
*
154
* \note Interrupts could increase the delay by a variable amount.
155
*/
156
void
clock_delay_usec
(uint16_t dt);
157
158
/**
159
* Deprecated platform-specific routines.
160
*
161
*/
162
int
clock_fine_max
(
void
);
163
unsigned
short
clock_fine(
void
);
164
void
clock_delay
(
unsigned
int
delay);
165
166
#endif
/* CLOCK_H_ */
167
168
/** @} */
169
/** @} */
clock_set_seconds
void clock_set_seconds(unsigned long sec)
Set the value of the platform seconds.
Definition
clock.c:124
clock_seconds
unsigned long clock_seconds(void)
Get the current value of the platform seconds.
Definition
clock.c:130
clock_init
void clock_init(void)
Initialize the clock library.
Definition
clock.c:93
clock_wait
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
Definition
clock.c:136
clock_delay
void clock_delay(unsigned int delay)
Obsolete delay function but we implement it here since some code still uses it.
Definition
clock.c:164
clock_delay_usec
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
Definition
clock.c:150
clock_fine_max
int clock_fine_max(void)
Deprecated platform-specific routines.
Definition
clock.c:129
clock_time
clock_time_t clock_time(void)
Get the current clock time.
Definition
clock.c:118
os
sys
clock.h
Generated on
for Contiki-NG by
1.17.0