better compilation on host
[aversive.git] / include / aversive / wait.h
1 /*  \r
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)\r
3  * \r
4  *  This program is free software; you can redistribute it and/or modify\r
5  *  it under the terms of the GNU General Public License as published by\r
6  *  the Free Software Foundation; either version 2 of the License, or\r
7  *  (at your option) any later version.\r
8  *\r
9  *  This program is distributed in the hope that it will be useful,\r
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  *  GNU General Public License for more details.\r
13  *\r
14  *  You should have received a copy of the GNU General Public License\r
15  *  along with this program; if not, write to the Free Software\r
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
17  *\r
18  *  Revision : $Id: wait.h,v 1.1.2.1 2007-05-23 17:18:09 zer0 Exp $\r
19  *\r
20  */\r
21 \r
22 /** \r
23  * This file is an interface for wait functions, in order to put the \r
24  * microcontroller in a loop state.\r
25  */\r
26 \r
27 /**********************************************************/\r
28 \r
29 #ifndef _AVERSIVE_WAIT_H_\r
30 #define _AVERSIVE_WAIT_H_\r
31 \r
32 #include <aversive.h>\r
33 \r
34 #ifdef HOST_VERSION\r
35 \r
36 #define wait_3cyc(n) do {} while(0)\r
37 #define wait_4cyc(n) do {} while(0)\r
38 #define wait_ms(n) do {} while(0)\r
39 \r
40 #else /* HOST_VERSION */\r
41 \r
42 #if __AVR_LIBC_VERSION__ < 10403UL\r
43 #include <avr/delay.h>\r
44 #else\r
45 #include <util/delay.h>\r
46 #endif\r
47 \r
48 /** wait n "3 cycles time" \r
49  * n is 8 bits */\r
50 #define wait_3cyc(n) _delay_loop_1(n)\r
51 \r
52 /** wait n "4 cycles time" \r
53  * n is 16 bits */\r
54 #define wait_4cyc(n) _delay_loop_2(n)\r
55 \r
56 /** wait n milliseconds \r
57  * n is 16 bits\r
58  */\r
59 static inline void wait_ms(uint16_t n) \r
60 {\r
61   while ( n -- ) \r
62     wait_4cyc(F_CPU/4000);\r
63\r
64 \r
65 #endif /* else HOST_VERSION */\r
66 \r
67 #endif /* _AVERSIVE_WAIT_ */\r