control servo 0 with axis 0
[protos/xbee-avr.git] / clock_time.h
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: time.h,v 1.3.4.2 2007-05-23 17:18:11 zer0 Exp $
19  *
20  */
21
22 /* Droids-corp, Eirbot, Microb Technology 2005 - Zer0
23  * Interface of the time module
24  */
25
26 /**
27  *  This module can be used to get a human readable time. It uses the
28  *  scheduler module. Its goal is not to be very precise, but just
29  *  simple to use.  provides two timers: one in s and us, and one in
30  *  us which doesn't overflow on seconds (better to substract two
31  *  times)
32  */
33
34 #ifndef _CLOCK_TIME_H_
35 #define _CLOCK_TIME_H_
36
37 #include <aversive.h>
38
39 /* a 16 bit variable cannot cover one day */
40 typedef int32_t seconds; 
41 typedef int32_t microseconds;
42
43 /** the time structure */
44 typedef struct 
45 {
46   microseconds us;
47   seconds s;
48 } time_h;
49
50
51
52 /**********************************************************/
53
54 /** init time module : schedule the event with the givent priority */
55 void time_init(uint8_t priority);
56
57 /**********************************************************/
58
59 /** get time in second since last init/reset */
60 seconds time_get_s(void);
61
62 /**********************************************************/
63
64 /** get time in microsecond since last init/reset */
65 microseconds time_get_us(void);
66
67 /**********************************************************/
68
69 /** get the complete time struct since last init/reset */
70 time_h time_get_time(void); 
71
72 /**********************************************************/
73
74 /** reset time counter */
75 void time_reset(void);
76
77 /**********************************************************/
78
79 /** set time */
80 void time_set(seconds s, microseconds us);
81
82 /**********************************************************/
83
84 /** This is an equivalent of 'wait_ms(x)', but uses time value, so it
85  *  is independant of CPU load. Warning, you should not use this
86  *  function in a irq locked context, or in a scheduled function with
87  *  higher priority than time module */
88 void time_wait_ms(uint16_t ms);
89
90 /**********************************************************/
91
92 /** get a microsecond timer that overflows naturally */
93 microseconds time_get_us2(void);
94
95 #endif