2 * Copyright Droids Corporation, Microb Technology, Eirbot (2006)
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
18 * Revision : $Id: timer_declarations.h,v 1.1.2.2 2006-12-04 23:48:22 zer0 Exp $
22 #ifndef _TIMER_DECLARATIONS_H
23 #define _TIMER_DECLARATIONS_H_
25 #define DECLARE_TIMER_FUNCS(x) \
27 /** start the timer at initial prescaler */ \
28 void timer##x##_start(void); \
30 /** stop the timer */ \
31 void timer##x##_stop(void); \
33 /** Set the timer value */ \
34 void timer##x##_set(uint16_t t); \
36 /** return the value of the timer */ \
37 uint16_t timer##x##_get(void); \
40 /** Enable overflow interruption, and register a function to be called */ \
41 /* every interrupt. If func is NULL, unregisters interrupt. */ \
42 void timer##x##_register_OV_intr(void (*func)(void)); \
44 /** Enable output compare interruption, and register a function to be */ \
45 /* called every output compare interrupt. Note that interruption */ \
46 /* will occur when the timer will reach the same value than t. If */ \
47 /* func is NULL, unregisters interrupt (other arg is useless). */ \
48 void timer##x##A_register_OC_intr_at_tics(void (*func)(void), uint16_t t); \
49 void timer##x##B_register_OC_intr_at_tics(void (*func)(void), uint16_t t); \
50 void timer##x##C_register_OC_intr_at_tics(void (*func)(void), uint16_t t); \
52 /** Enable output compare interruption, and register a function to be */ \
53 /* called every output compare interrupt. Note that interruption */ \
54 /* will occur when the timer will reach CURRENT_TIMER + t_us */ \
55 /* (parameter is in microseconds). If func is NULL, unregisters */ \
56 /* interrupt (other arg is useless). return 0 on success */ \
57 /* WARNING : this function can be slower due to float conversion */ \
58 /* If you are in static timer mode (no dynamic modifications of */ \
59 /* the prescaler), and if your value is a constant, you should use */ \
60 /* a code like this to allow beeing optmized by the preprocessor: */ \
61 /* timerxy_register_OC_intr_in_tics(timerx_us_to_tics(1000)); */ \
62 /* Indeed this code is optimized. In any case, it is better to */ \
63 /* them in 2 separated funcs, because you can save the result of */ \
64 /* timerx_us_to_tics() in a variable. */ \
65 int8_t timer##x##A_register_OC_intr_in_us(void (*func)(void), uint16_t t); \
66 int8_t timer##x##B_register_OC_intr_in_us(void (*func)(void), uint16_t t); \
67 int8_t timer##x##C_register_OC_intr_in_us(void (*func)(void), uint16_t t); \
69 /** Return current prescaler divisor. If CONFIG_MODULE_TIMER_DYNAMIC */ \
70 /* is not defined, it only returns TIMERX_PRESCALER specified in */ \
71 /* configuration. If you use a dynamic configuration, it reads the */ \
72 /* current prescaler register value and converts it to divisor */ \
74 uint16_t timer##x##_get_prescaler_div(void); \
76 /** Configure the prescaler register depending on divisor param. */ \
77 /* only defined if CONFIG_MODULE_TIMER_DYNAMIC is 'y' */ \
78 void timer##x##_set_prescaler_div(uint16_t); \
80 /** Use timerX_get_prescaler_div() and CONFIG_QUARTZ to do the */ \
81 /* conversion from microseconds to tics (timer unit) */ \
82 /* Be carreful, this function is inline static, so if you use it */ \
83 /* quite often, you should include it in a standard function and call */ \
84 /* this function instead */ \
85 static inline float timer##x##_us_to_tics(float us); \
87 /** Use timerX_get_prescaler_div() and CONFIG_QUARTZ to do the */ \
88 /* conversion from tics to microseconds */ \
89 /* Be carreful, this function is inline static, so if you use it */ \
90 /* quite often, you should include it in a standard function and call */ \
91 /* this function instead */ \
92 static inline float timer##x##_tics_to_us(float t);