prepare cobboard and ballboard
[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 #include <unistd.h>\r
37 \r
38 #define wait_3cyc(n) do { volatile int a = 0; a++; } while (0)\r
39 #define wait_4cyc(n) do { volatile int a = 0; a++; } while (0)\r
40 #define wait_ms(n) host_wait_ms(n)\r
41 \r
42 #else /* HOST_VERSION */\r
43 \r
44 #if __AVR_LIBC_VERSION__ < 10403UL\r
45 #include <avr/delay.h>\r
46 #else\r
47 #include <util/delay.h>\r
48 #endif\r
49 \r
50 /** wait n "3 cycles time" \r
51  * n is 8 bits */\r
52 #define wait_3cyc(n) _delay_loop_1(n)\r
53 \r
54 /** wait n "4 cycles time" \r
55  * n is 16 bits */\r
56 #define wait_4cyc(n) _delay_loop_2(n)\r
57 \r
58 /** wait n milliseconds \r
59  * n is 16 bits\r
60  */\r
61 static inline void wait_ms(uint16_t n) \r
62 {\r
63   while ( n -- ) \r
64     wait_4cyc(F_CPU/4000);\r
65\r
66 \r
67 #endif /* else HOST_VERSION */\r
68 \r
69 #endif /* _AVERSIVE_WAIT_ */\r