root / branches / simulator / lib / include / libdragonfly / time.h @ 1073
History | View | Annotate | Download (4.07 KB)
1 | 7 | bcoltin | /**
|
---|---|---|---|
2 | 241 | bcoltin | * Copyright (c) 2007 Colony Project
|
3 | *
|
||
4 | * Permission is hereby granted, free of charge, to any person
|
||
5 | * obtaining a copy of this software and associated documentation
|
||
6 | * files (the "Software"), to deal in the Software without
|
||
7 | * restriction, including without limitation the rights to use,
|
||
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
9 | * copies of the Software, and to permit persons to whom the
|
||
10 | * Software is furnished to do so, subject to the following
|
||
11 | * conditions:
|
||
12 | *
|
||
13 | * The above copyright notice and this permission notice shall be
|
||
14 | * included in all copies or substantial portions of the Software.
|
||
15 | *
|
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||
23 | * OTHER DEALINGS IN THE SOFTWARE.
|
||
24 | **/
|
||
25 | |||
26 | |||
27 | /**
|
||
28 | 7 | bcoltin | * @file time.h
|
29 | * @brief Contains time-related functions and definitions
|
||
30 | *
|
||
31 | * Contains functions and definitions for dealing with time,
|
||
32 | * namely delay_ms and the realtime clock.
|
||
33 | *
|
||
34 | * @author Colony Project, CMU Robotics Club
|
||
35 | **/
|
||
36 | |||
37 | #ifndef _TIME_H_
|
||
38 | #define _TIME_H_
|
||
39 | |||
40 | /* Predefined times for prescale_opt in time.c.
|
||
41 | To make you own, know that a pulse is 1/16th of a second. You cannot get less than this. To get more, you need
|
||
42 | to know how many 16ths of a second are in the time you want. (Time_desired * 16 = prescaler_opt)
|
||
43 | */
|
||
44 | 893 | bcoltin | |
45 | 7 | bcoltin | /**
|
46 | 893 | bcoltin | * @defgroup time Time
|
47 | * @brief Time functions
|
||
48 | *
|
||
49 | * Functions dealing with time.
|
||
50 | *
|
||
51 | 7 | bcoltin | * @{
|
52 | **/
|
||
53 | 893 | bcoltin | |
54 | 7 | bcoltin | /** @brief A sixteenth of a second **/
|
55 | #define SIXTEENTH_SECOND 1 |
||
56 | /** @brief An eighth of a second **/
|
||
57 | #define EIGTH_SECOND 2 |
||
58 | /** @brief A quarter of a second **/
|
||
59 | #define QUARTER_SECOND 4 |
||
60 | /** @brief Half of a second **/
|
||
61 | #define HALF_SECOND 8 |
||
62 | /** @brief One second **/
|
||
63 | #define SECOND 16 |
||
64 | /** @brief Two seconds **/
|
||
65 | #define TWO_SECOND 32 |
||
66 | /** @brief Four seconds **/
|
||
67 | #define FOUR_SECOND 64 |
||
68 | |||
69 | 893 | bcoltin | /**
|
70 | * @brief Delay execution for the specified time
|
||
71 | *
|
||
72 | * Delays for the specified number of milliseconds.
|
||
73 | * It depends on F_CPU to be defined in order to calculate how many cycles
|
||
74 | * it should delay. If it is not defined, a default clock of 8MHz is assumed.
|
||
75 | *
|
||
76 | * We use _delay_loop_2 which will run assembly instructions that should be
|
||
77 | * 4 cycles long. Optimizations must be enabled for this to be true.
|
||
78 | * That function is called to ensure around 1ms per execution. To generate
|
||
79 | * multiple ms we run a for loop of how many milliseconds are desired.
|
||
80 | *
|
||
81 | * The error should be just the skew on the oscillator as the formula to
|
||
82 | * calculate delay cycles should always be a whole number. The is some skew
|
||
83 | * in practice though it is unavoidable. Delaying for less than 1s should make
|
||
84 | * the error negligable.
|
||
85 | *
|
||
86 | * @param ms the number of milliseconds to delay for
|
||
87 | **/
|
||
88 | 7 | bcoltin | void delay_ms(int ms) ; |
89 | 893 | bcoltin | /**
|
90 | * @brief Enable the realtime clock
|
||
91 | *
|
||
92 | * Initializes the real time clock. Prescales are defined in time.h.
|
||
93 | * For example, SECOND will give 1 second. The specified function is
|
||
94 | * called every clock tick. For the real time clock to activate,
|
||
95 | * interrupts must be enabled. (through sei() )
|
||
96 | *
|
||
97 | * @param prescale_opt the period with which the timer is triggered
|
||
98 | * @param rtc_func the function called when the timer is triggered
|
||
99 | *
|
||
100 | * @see rtc_get, rtc_reset
|
||
101 | *
|
||
102 | **/
|
||
103 | 7 | bcoltin | void rtc_init(int prescale_opt, void (*rtc_func)(void)); |
104 | 893 | bcoltin | /**
|
105 | * @brief Reset the counter of the realtime clock
|
||
106 | *
|
||
107 | * Resets the real time clock counter to 0.
|
||
108 | *
|
||
109 | * @see rtc_init, rtc_get
|
||
110 | **/
|
||
111 | 7 | bcoltin | void rtc_reset(void); |
112 | 893 | bcoltin | /**
|
113 | * @brief Get the value of the realtime clock.
|
||
114 | *
|
||
115 | * Returns the time elapsed in seconds since the last call to
|
||
116 | * rtc_init or rtc_reset.
|
||
117 | *
|
||
118 | * @return the number of seconds since the last call to rtc_init or rtc_reset
|
||
119 | *
|
||
120 | * @see rtc_init, rtc_reset
|
||
121 | **/
|
||
122 | 7 | bcoltin | int rtc_get(void); |
123 | |||
124 | /** @} **/
|
||
125 | |||
126 | #endif
|