00001 /* 00002 * Copyright Droids Corporation, Microb Technology, Eirbot (2006) 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Revision : $Id: timer_declarations.h,v 1.2 2007-05-01 15:35:53 zer0 Exp $ 00019 * 00020 */ 00021 00022 #ifndef _TIMER_DECLARATIONS_H 00023 #define _TIMER_DECLARATIONS_H_ 00024 00025 #define DECLARE_TIMER_FUNCS(x) \ 00026 \ 00027 \ 00028 void timer##x##_start(void); \ 00029 \ 00030 \ 00031 void timer##x##_stop(void); \ 00032 \ 00033 \ 00034 void timer##x##_set(uint16_t t); \ 00035 \ 00036 \ 00037 uint16_t timer##x##_get(void); \ 00038 \ 00039 \ 00040 \ 00041 /* every interrupt. If func is NULL, unregisters interrupt. */ \ 00042 void timer##x##_register_OV_intr(void (*func)(void)); \ 00043 \ 00044 \ 00045 /* called every output compare interrupt. Note that interruption */ \ 00046 /* will occur when the timer will reach the same value than t. If */ \ 00047 /* func is NULL, unregisters interrupt (other arg is useless). */ \ 00048 void timer##x##A_register_OC_intr_at_tics(void (*func)(void), uint16_t t); \ 00049 void timer##x##B_register_OC_intr_at_tics(void (*func)(void), uint16_t t); \ 00050 void timer##x##C_register_OC_intr_at_tics(void (*func)(void), uint16_t t); \ 00051 \ 00052 \ 00053 /* called every output compare interrupt. Note that interruption */ \ 00054 /* will occur when the timer will reach CURRENT_TIMER + t_us */ \ 00055 /* (parameter is in microseconds). If func is NULL, unregisters */ \ 00056 /* interrupt (other arg is useless). return 0 on success */ \ 00057 /* WARNING : this function can be slower due to float conversion */ \ 00058 /* If you are in static timer mode (no dynamic modifications of */ \ 00059 /* the prescaler), and if your value is a constant, you should use */ \ 00060 /* a code like this to allow beeing optmized by the preprocessor: */ \ 00061 /* timerxy_register_OC_intr_in_tics(timerx_us_to_tics(1000)); */ \ 00062 /* Indeed this code is optimized. In any case, it is better to */ \ 00063 /* them in 2 separated funcs, because you can save the result of */ \ 00064 /* timerx_us_to_tics() in a variable. */ \ 00065 int8_t timer##x##A_register_OC_intr_in_us(void (*func)(void), uint16_t t); \ 00066 int8_t timer##x##B_register_OC_intr_in_us(void (*func)(void), uint16_t t); \ 00067 int8_t timer##x##C_register_OC_intr_in_us(void (*func)(void), uint16_t t); \ 00068 \ 00069 \ 00070 /* is not defined, it only returns TIMERX_PRESCALER specified in */ \ 00071 /* configuration. If you use a dynamic configuration, it reads the */ \ 00072 /* current prescaler register value and converts it to divisor */ \ 00073 /* value. */ \ 00074 uint16_t timer##x##_get_prescaler_div(void); \ 00075 \ 00076 \ 00077 /* only defined if CONFIG_MODULE_TIMER_DYNAMIC is 'y' */ \ 00078 void timer##x##_set_prescaler_div(uint16_t); \ 00079 \ 00080 \ 00081 /* conversion from microseconds to tics (timer unit) */ \ 00082 /* Be carreful, this function is inline static, so if you use it */ \ 00083 /* quite often, you should include it in a standard function and call */ \ 00084 /* this function instead */ \ 00085 static inline float timer##x##_us_to_tics(float us); \ 00086 \ 00087 \ 00088 /* conversion from tics to microseconds */ \ 00089 /* Be carreful, this function is inline static, so if you use it */ \ 00090 /* quite often, you should include it in a standard function and call */ \ 00091 /* this function instead */ \ 00092 static inline float timer##x##_tics_to_us(float t); 00093 00094 #endif