NiboRoboLib 3.1 - NIBObee Library
iodefs.h
gehe zur Dokumentation dieser Datei
1 /* BSD-License:
2 
3 Copyright (c) 2007 by Nils Springob, nicai-systems, Germany
4 
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright notice,
13  this list of conditions and the following disclaimer in the documentation
14  and/or other materials provided with the distribution.
15  * Neither the name nicai-systems nor the names of its contributors may be
16  used to endorse or promote products derived from this software without
17  specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 */
32 
39 #ifndef _IODEFS_H_
40 #define _IODEFS_H_
41 
42 
43 #ifdef _NIBOBEE_
44 # include "iodefs_nibobee.h"
45 #else
46 # error "no robot platform defined"
47 #endif
48 
49 #ifdef __AVR_ATmega644__
50 #define _NIBOBEE_MEGAxx4_
51 #endif
52 
53 #ifdef __AVR_ATmega324__
54 #define _NIBOBEE_MEGAxx4_
55 #endif
56 
57 #ifdef __AVR_ATmega164__
58 #define _NIBOBEE_MEGAxx4_
59 #endif
60 
61 
62 #include <avr/io.h>
63 #include <avr/interrupt.h>
64 
65 
66 /******************************************************************************/
67 
68 #define LOBYTE(x) (uint8_t)((uint16_t)x)
69 #define HIBYTE(x) (uint8_t)(((uint16_t)x)>>8)
70 #define MAKE_WORD(hi,lo) ((hi*0x100)+lo)
71 
72 #define enable_interrupts() sei()
73 #define disable_interrupts() cli()
74 
75 /* helper macro */
76 #define _PPCAT(a,b) a##b
77 #define _PPCAT3(a,b,c) a##b##c
78 
79 /* Macro-functions for IO-bits */
80 #define activate_output_bit(NAME) _PPCAT(NAME,_DDR)|=_BV(_PPCAT(NAME,_BIT))
81 #define deactivate_output_bit(NAME) _PPCAT(NAME,_DDR)&=~(unsigned char)_BV(_PPCAT(NAME,_BIT))
82 #define set_output_bit(NAME) _PPCAT(NAME,_PORT)|=_BV(_PPCAT(NAME,_BIT))
83 #define clear_output_bit(NAME) _PPCAT(NAME,_PORT)&=~(unsigned char)_BV(_PPCAT(NAME,_BIT))
84 #define set_output_bitval(NAME, VAL) _PPCAT(NAME,_PORT)=(_PPCAT(NAME,_PORT)&~(unsigned char)_BV(_PPCAT(NAME,_BIT)))|((VAL)?_BV(_PPCAT(NAME,_BIT)):0)
85 
86 #define get_input_bit(NAME) (_PPCAT(NAME,_PIN)&_BV(_PPCAT(NAME,_BIT)))
87 #define get_output_bit(NAME) (_PPCAT(NAME,_PORT)&_BV(_PPCAT(NAME,_BIT)))
88 
89 /* Macro-functions for IO-groups */
90 #define activate_output_groupbit(NAME,BIT) _PPCAT(NAME,_DDR)|=_BV(_PPCAT3(NAME,_BIT_,BIT))
91 #define deactivate_output_groupbit(NAME,BIT) _PPCAT(NAME,_DDR)&=~(unsigned char)_BV(_PPCAT3(NAME,_BIT_,BIT))
92 #define set_output_groupbit(NAME,BIT) _PPCAT(NAME,_PORT)|=_BV(_PPCAT3(NAME,_BIT_,BIT))
93 #define clear_output_groupbit(NAME,BIT) _PPCAT(NAME,_PORT)&=~(unsigned char)_BV(_PPCAT3(NAME,_BIT_,BIT))
94 #define set_output_groupbitval(NAME,BIT,VAL) _PPCAT(NAME,_PORT)=(_PPCAT(NAME,_PORT)&~(unsigned char)_BV(_PPCAT3(NAME,_BIT_,BIT)))|((VAL)?_BV(_PPCAT3(NAME,_BIT_,BIT)):0)
95 
96 #define get_input_groupbit(NAME,BIT) (_PPCAT(NAME,_PIN)&_BV(_PPCAT3(NAME,_BIT_,BIT)))
97 #define get_output_groupbit(NAME,BIT) (_PPCAT(NAME,_PORT)&_BV(_PPCAT3(NAME,_BIT_,BIT)))
98 
99 #define activate_output_group(NAME) _PPCAT(NAME,_DDR)|=_PPCAT(NAME,_MASK)
100 #define deactivate_output_group(NAME) _PPCAT(NAME,_DDR)&=~(unsigned char)_PPCAT(NAME,_MASK)
101 #define set_output_group(NAME) _PPCAT(NAME,_PORT)|=_PPCAT(NAME,_MASK)
102 #define clear_output_group(NAME) _PPCAT(NAME,_PORT)&=~(unsigned char)_PPCAT(NAME,_MASK)
103 
104 
105 
106 #endif
Zuordnung der physikalischen Pins zu symbolischen Namen.