NIBObee Library 1.4
|
00001 /* BSD-License: 00002 00003 Copyright (c) 2007 by Nils Springob, nicai-systems, Germany 00004 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, 00008 are permitted provided that the following conditions are met: 00009 00010 * Redistributions of source code must retain the above copyright notice, 00011 this list of conditions and the following disclaimer. 00012 * Redistributions in binary form must reproduce the above copyright notice, 00013 this list of conditions and the following disclaimer in the documentation 00014 and/or other materials provided with the distribution. 00015 * Neither the name nicai-systems nor the names of its contributors may be 00016 used to endorse or promote products derived from this software without 00017 specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00023 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00024 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00025 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 00031 */ 00032 00039 #ifndef _IODEFS_H_ 00040 #define _IODEFS_H_ 00041 00042 00043 #ifdef _NIBOBEE_ 00044 # include "iodefs_nibobee.h" 00045 #else 00046 # error "no robot platform defined" 00047 #endif 00048 00049 #ifdef __AVR_ATmega644__ 00050 #define _NIBOBEE_MEGAxx4_ 00051 #endif 00052 00053 #ifdef __AVR_ATmega324__ 00054 #define _NIBOBEE_MEGAxx4_ 00055 #endif 00056 00057 #ifdef __AVR_ATmega164__ 00058 #define _NIBOBEE_MEGAxx4_ 00059 #endif 00060 00061 00062 #include <avr/io.h> 00063 #include <avr/interrupt.h> 00064 00065 00066 /******************************************************************************/ 00067 00068 #define LOBYTE(x) (uint8_t)((uint16_t)x) 00069 #define HIBYTE(x) (uint8_t)(((uint16_t)x)>>8) 00070 #define MAKE_WORD(hi,lo) ((hi*0x100)+lo) 00071 00072 #define enable_interrupts() sei() 00073 #define disable_interrupts() cli() 00074 00075 /* helper macro */ 00076 #define _PPCAT(a,b) a##b 00077 #define _PPCAT3(a,b,c) a##b##c 00078 00079 /* Macro-functions for IO-bits */ 00080 #define activate_output_bit(NAME) _PPCAT(NAME,_DDR)|=_BV(_PPCAT(NAME,_BIT)) 00081 #define deactivate_output_bit(NAME) _PPCAT(NAME,_DDR)&=~(unsigned char)_BV(_PPCAT(NAME,_BIT)) 00082 #define set_output_bit(NAME) _PPCAT(NAME,_PORT)|=_BV(_PPCAT(NAME,_BIT)) 00083 #define clear_output_bit(NAME) _PPCAT(NAME,_PORT)&=~(unsigned char)_BV(_PPCAT(NAME,_BIT)) 00084 #define set_output_bitval(NAME, VAL) _PPCAT(NAME,_PORT)=(_PPCAT(NAME,_PORT)&~(unsigned char)_BV(_PPCAT(NAME,_BIT)))|((VAL)?_BV(_PPCAT(NAME,_BIT)):0) 00085 00086 #define get_input_bit(NAME) (_PPCAT(NAME,_PIN)&_BV(_PPCAT(NAME,_BIT))) 00087 #define get_output_bit(NAME) (_PPCAT(NAME,_PORT)&_BV(_PPCAT(NAME,_BIT))) 00088 00089 /* Macro-functions for IO-groups */ 00090 #define activate_output_groupbit(NAME,BIT) _PPCAT(NAME,_DDR)|=_BV(_PPCAT3(NAME,_BIT_,BIT)) 00091 #define deactivate_output_groupbit(NAME,BIT) _PPCAT(NAME,_DDR)&=~(unsigned char)_BV(_PPCAT3(NAME,_BIT_,BIT)) 00092 #define set_output_groupbit(NAME,BIT) _PPCAT(NAME,_PORT)|=_BV(_PPCAT3(NAME,_BIT_,BIT)) 00093 #define clear_output_groupbit(NAME,BIT) _PPCAT(NAME,_PORT)&=~(unsigned char)_BV(_PPCAT3(NAME,_BIT_,BIT)) 00094 #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) 00095 00096 #define get_input_groupbit(NAME,BIT) (_PPCAT(NAME,_PIN)&_BV(_PPCAT3(NAME,_BIT_,BIT))) 00097 #define get_output_groupbit(NAME,BIT) (_PPCAT(NAME,_PORT)&_BV(_PPCAT3(NAME,_BIT_,BIT))) 00098 00099 #define activate_output_group(NAME) _PPCAT(NAME,_DDR)|=_PPCAT(NAME,_MASK) 00100 #define deactivate_output_group(NAME) _PPCAT(NAME,_DDR)&=~(unsigned char)_PPCAT(NAME,_MASK) 00101 #define set_output_group(NAME) _PPCAT(NAME,_PORT)|=_PPCAT(NAME,_MASK) 00102 #define clear_output_group(NAME) _PPCAT(NAME,_PORT)&=~(unsigned char)_PPCAT(NAME,_MASK) 00103 00104 00105 00106 #endif