4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
30 * All Rights Reserved.
33 * \brief Some simple delay routines.
35 * Simple serial driver
37 * \author Francesco Sacchi <batt@develer.com>
42 *#* Revision 1.2 2006/07/19 12:56:26 bernie
43 *#* Convert to new Doxygen style.
45 *#* Revision 1.1 2005/04/12 01:37:50 bernie
46 *#* Import into DevLib.
48 *#* Revision 1.8 2005/04/12 01:18:09 bernie
49 *#* time_t -> mtime_t.
51 *#* Revision 1.7 2005/03/20 04:18:41 bernie
52 *#* Fixes for CONFIG_WATCHDOG == 0.
54 *#* Revision 1.6 2004/10/27 09:38:07 aleph
55 *#* Bootloader working with watchdog enabled
57 *#* Revision 1.5 2004/10/20 10:00:37 customer_pw
58 *#* Add newline at eof
60 *#* Revision 1.4 2004/10/14 14:13:09 batt
63 *#* Revision 1.3 2004/10/14 13:29:20 batt
64 *#* Fix 0ms delay bug.
66 *#* Revision 1.2 2004/10/13 17:53:05 batt
67 *#* Delay with hw timer.
69 *#* Revision 1.1 2004/10/13 16:36:32 batt
70 *#* Simplified timer delay routines.
74 #include "timer_simple.h"
78 #include <macros.h> /* BV() */
83 #define MS_PER_SEC 1000UL
84 #define TIMER_PRESCALER 64UL
85 #define TIMER_DELAY_1MS (255 - CLOCK_FREQ / TIMER_PRESCALER / MS_PER_SEC)
88 * Wait \a time ms using timer 0.
91 void timer_delay(mtime_t time)
93 /* Set timer clock to clock_freq/64 */
98 /* Initialize timer counter register */
99 TCNT0 = TIMER_DELAY_1MS;
100 /* Clear overflow bit. */
103 while (!(TIFR & BV(TOV0)));