Contiki 2.6

clock.h

00001 /** \addtogroup sys
00002  * @{
00003  */
00004 
00005 /**
00006  * \defgroup clock Clock library
00007  *
00008  * The clock library is the interface between Contiki and the platform
00009  * specific clock functionality. The clock library defines a macro,
00010  * CLOCK_SECOND, to convert seconds into the tick resolution of the platform.
00011  * Typically this is 1-10 milliseconds, e.g. 4*CLOCK_SECOND could be 512.
00012  * A 16 bit counter would thus overflow every 1-10 minutes.
00013  * Platforms use the tick interrupt to maintain a long term count
00014  * of seconds since startup.
00015  *
00016  * Platforms may also implement rtimers for greater time resolution
00017  * and for real-time interrupts, These use a corresponding RTIMER_SECOND.
00018  *
00019  * \note These timers do not necessarily have a common divisor or are phase locked.
00020  * One may be crystal controlled and the other may not. Low power operation
00021  * or sleep will often use one for wake and disable the other, then give
00022  * it a tick correction after wakeup.
00023  *
00024  * \note The clock library need in many cases not be used
00025  * directly. Rather, the \ref timer "timer library", \ref etimer
00026  * "event timers", or \ref trimer "rtimer library" should be used.
00027  *
00028  * \sa \ref timer "Timer library"
00029  * \sa \ref etimer "Event timers"
00030  * \sa \ref rtimer "Realtime library"
00031  *
00032  * @{
00033  */
00034 
00035 /*
00036  * Copyright (c) 2004, Swedish Institute of Computer Science.
00037  * All rights reserved.
00038  *
00039  * Redistribution and use in source and binary forms, with or without
00040  * modification, are permitted provided that the following conditions
00041  * are met:
00042  * 1. Redistributions of source code must retain the above copyright
00043  *    notice, this list of conditions and the following disclaimer.
00044  * 2. Redistributions in binary form must reproduce the above copyright
00045  *    notice, this list of conditions and the following disclaimer in the
00046  *    documentation and/or other materials provided with the distribution.
00047  * 3. Neither the name of the Institute nor the names of its contributors
00048  *    may be used to endorse or promote products derived from this software
00049  *    without specific prior written permission.
00050  *
00051  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00052  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00053  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00054  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00055  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00056  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00057  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00058  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00059  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00060  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00061  * SUCH DAMAGE.
00062  *
00063  * This file is part of the Contiki operating system.
00064  *
00065  * Author: Adam Dunkels <adam@sics.se>
00066  *
00067  */
00068 #ifndef __CLOCK_H__
00069 #define __CLOCK_H__
00070 
00071 #include "contiki-conf.h"
00072 
00073 /**
00074  * A second, measured in system clock time.
00075  *
00076  * \hideinitializer
00077  */
00078 #ifdef CLOCK_CONF_SECOND
00079 #define CLOCK_SECOND CLOCK_CONF_SECOND
00080 #else
00081 #define CLOCK_SECOND (clock_time_t)32
00082 #endif
00083 
00084 /**
00085  * Initialize the clock library.
00086  *
00087  * This function initializes the clock library and should be called
00088  * from the main() function of the system.
00089  *
00090  */
00091 void clock_init(void);
00092 
00093 /**
00094  * Get the current clock time.
00095  *
00096  * This function returns the current system clock time.
00097  *
00098  * \return The current clock time, measured in system ticks.
00099  */
00100 CCIF clock_time_t clock_time(void);
00101 
00102 /**
00103  * Get the current value of the platform seconds.
00104  *
00105  * This could be the number of seconds since startup, or
00106  * since a standard epoch.
00107  *
00108  * \return The value.
00109  */
00110 CCIF unsigned long clock_seconds(void);
00111 
00112 /**
00113  * Set the value of the platform seconds.
00114  * \param sec   The value to set.
00115  *
00116  */
00117 void clock_set_seconds(unsigned long sec);
00118 
00119 /**
00120  * Wait for a given number of ticks.
00121  * \param t   How many ticks.
00122  *
00123  */
00124 void clock_wait(clock_time_t t);
00125 
00126 /**
00127  * Delay a given number of microseconds.
00128  * \param dt   How many microseconds to delay.
00129  *
00130  * \note Interrupts could increase the delay by a variable amount.
00131  */
00132 void clock_delay_usec(uint16_t dt);
00133 
00134 /**
00135  * Deprecated platform-specific routines.
00136  *
00137  */
00138 int clock_fine_max(void);
00139 unsigned short clock_fine(void);
00140 void clock_delay(unsigned int delay);
00141 
00142 #endif /* __CLOCK_H__ */
00143 
00144 /** @} */
00145 /** @} */