2 * Copyright Droids Corporation (2008)
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.
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.
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
21 * Author : Julien LE GUEN - jlg@jleguen.info
27 #include <time_ext_config.h>
30 * Since we want the maximum resolution available,
31 * the prescaler of timer2 is set to 1.
32 * Thus counter2 is incremented every positive edge of the external quartz.
33 * You can define the frequency of your quartz in time_ext_config.h
37 /* Number of NANOSECONDS */
38 #define NANO_PER_US 1000UL
39 #define NANO_PER_MS 1000000UL
40 #define NANO_PER_S 1000000000UL
44 #define TIMER2_PRESCALER_OFF 0
45 #define TIMER2_PRESCALER_1 1
46 #define TIMER2_PRESCALER_8 2
47 #define TIMER2_PRESCALER_32 3
48 #define TIMER2_PRESCALER_64 4
49 #define TIMER2_PRESCALER_128 5
50 #define TIMER2_PRESCALER_256 6
51 #define TIMER2_PRESCALER_1024 7
55 #define NANO_PER_QUARTZ_TICK TIME_EXT_QUARTZ_PERIOD
62 * We want to have the best resolution possible.
63 * Thus, we store nano-seconds and seconds.
65 typedef struct _time_ext
72 /* Initialize the module */
73 void time_ext_init(void);
76 * Setter and getter for the prescaler
77 * By default, it is set to 1
79 inline void time_ext_set_prescaler(uint8_t p);
80 inline uint8_t time_ext_get_prescaler(void);
83 * Get time (seconds only, nanos only, or both)
85 inline uint32_t time_ext_get_s(void);
86 inline uint32_t time_ext_get_ns(void);
87 time_ext_t time_ext_get(void);
90 * Sets the global time.
91 * This resets TCNT2 as well
93 inline void time_ext_set(uint32_t sec, uint32_t nano);
95 #endif /* _TIME_EXT_H_ */