NiboRoboLib 3.6 - NIBO burger Library
iodefs.h
gehe zur Dokumentation dieser Datei
1 /* BSD-License:
2 
3 Copyright (c) 2015 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 
37 #ifndef _IODEFS_H_
38 #define _IODEFS_H_
39 
40 #ifdef ARDUINO
41 # define _NIBOBURGER_
42 #endif
43 
44 
45 #ifdef _NIBOBURGER_
46 # include "iodefs_niboburger.h"
47 #else
48 # error "no robot platform defined"
49 #endif
50 
51 #ifdef __AVR_ATmega644__
52 #define _NIBOBURGER_MEGAxx4_
53 #endif
54 
55 #ifdef __AVR_ATmega324__
56 #define _NIBOBURGER_MEGAxx4_
57 #endif
58 
59 #ifdef __AVR_ATmega164__
60 #define _NIBOBURGER_MEGAxx4_
61 #endif
62 
63 
64 #include <avr/io.h>
65 #include <avr/interrupt.h>
66 
67 
68 /******************************************************************************/
69 
70 #define LOBYTE(x) (uint8_t)((uint16_t)x)
71 #define HIBYTE(x) (uint8_t)(((uint16_t)x)>>8)
72 #define MAKE_WORD(hi,lo) ((hi*0x100)+lo)
73 
74 #define enable_interrupts() sei()
75 #define disable_interrupts() cli()
76 
77 /* helper macro */
78 #define _PPCAT(a,b) a##b
79 #define _PPCAT3(a,b,c) a##b##c
80 
81 /* Macro-functions for IO-bits */
82 #define activate_output_bit(NAME) _PPCAT(NAME,_DDR)|=_BV(_PPCAT(NAME,_BIT))
83 #define deactivate_output_bit(NAME) _PPCAT(NAME,_DDR)&=~(unsigned char)_BV(_PPCAT(NAME,_BIT))
84 #define set_output_bit(NAME) _PPCAT(NAME,_PORT)|=_BV(_PPCAT(NAME,_BIT))
85 #define clear_output_bit(NAME) _PPCAT(NAME,_PORT)&=~(unsigned char)_BV(_PPCAT(NAME,_BIT))
86 #define toggle_output_bit(NAME) _PPCAT(NAME,_PORT)^=_BV(_PPCAT(NAME,_BIT))
87 #define set_output_bitval(NAME, VAL) _PPCAT(NAME,_PORT)=(_PPCAT(NAME,_PORT)&~(unsigned char)_BV(_PPCAT(NAME,_BIT)))|((VAL)?_BV(_PPCAT(NAME,_BIT)):0)
88 
89 #define get_input_bit(NAME) (_PPCAT(NAME,_PIN)&_BV(_PPCAT(NAME,_BIT)))
90 #define get_output_bit(NAME) (_PPCAT(NAME,_PORT)&_BV(_PPCAT(NAME,_BIT)))
91 
92 /* Macro-functions for IO-groups */
93 #define activate_output_groupbit(NAME,BIT) _PPCAT(NAME,_DDR)|=_BV(_PPCAT3(NAME,_BIT_,BIT))
94 #define deactivate_output_groupbit(NAME,BIT) _PPCAT(NAME,_DDR)&=~(unsigned char)_BV(_PPCAT3(NAME,_BIT_,BIT))
95 #define set_output_groupbit(NAME,BIT) _PPCAT(NAME,_PORT)|=_BV(_PPCAT3(NAME,_BIT_,BIT))
96 #define clear_output_groupbit(NAME,BIT) _PPCAT(NAME,_PORT)&=~(unsigned char)_BV(_PPCAT3(NAME,_BIT_,BIT))
97 #define toggle_output_groupbit(NAME,BIT) _PPCAT(NAME,_PORT)^=_BV(_PPCAT3(NAME,_BIT_,BIT))
98 #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)
99 
100 #define get_input_groupbit(NAME,BIT) (_PPCAT(NAME,_PIN)&_BV(_PPCAT3(NAME,_BIT_,BIT)))
101 #define get_output_groupbit(NAME,BIT) (_PPCAT(NAME,_PORT)&_BV(_PPCAT3(NAME,_BIT_,BIT)))
102 
103 #define activate_output_group(NAME) _PPCAT(NAME,_DDR)|=_PPCAT(NAME,_MASK)
104 #define deactivate_output_group(NAME) _PPCAT(NAME,_DDR)&=~(unsigned char)_PPCAT(NAME,_MASK)
105 #define set_output_group(NAME) _PPCAT(NAME,_PORT)|=_PPCAT(NAME,_MASK)
106 #define clear_output_group(NAME) _PPCAT(NAME,_PORT)&=~(unsigned char)_PPCAT(NAME,_MASK)
107 
108 /* Helper Macro for atomic Blocks in C90 compiler mode */
109 #define ATOMIC_C90_BEGIN() {uint8_t _sreg_bak__ = SREG; cli(); {
110 #define ATOMIC_C90_END() } SREG = _sreg_bak__;}
111 
112 
113 #endif
Zuordnung der physikalischen Pins zu symbolischen Namen.