work on hostsim
[aversive.git] / modules / base / time / 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 _TIME_H_
35 #define _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
44 /** the time structure */
45 typedef struct 
46 {
47   microseconds us;
48   seconds s;
49 } time_h;
50
51
52
53 /**********************************************************/
54
55 /** init time module : schedule the event with the givent priority */
56 void time_init(uint8_t priority);
57
58 /**********************************************************/
59
60 /** get time in second since last init/reset */
61 seconds time_get_s(void);
62
63 /**********************************************************/
64
65 /** get time in microsecond since last init/reset */
66 microseconds time_get_us(void);
67
68 /**********************************************************/
69
70 /** get the complete time struct since last init/reset */
71 time_h time_get_time(void); 
72
73 /**********************************************************/
74
75 /** reset time counter */
76 void time_reset(void);
77
78 /**********************************************************/
79
80 /** set time */
81 void time_set(seconds s, microseconds us);
82
83 /**********************************************************/
84
85 /** This is an equivalent of 'wait_ms(x)', but uses time value, so it
86  *  is independant of CPU load. Warning, you should not use this
87  *  function in a irq locked context, or in a scheduled function with
88  *  higher priority than time module */
89 void time_wait_ms(uint16_t ms);
90
91 /**********************************************************/
92
93 /** get a microsecond timer that overflows naturally */
94 microseconds time_get_us2(void);
95
96 #endif