board.h

Go to the documentation of this file.
00001 /* Copyright (c) 2007-2009 Axel Wachtler
00002    All rights reserved.
00003 
00004    Redistribution and use in source and binary forms, with or without
00005    modification, are permitted provided that the following conditions
00006    are met:
00007 
00008    * Redistributions of source code must retain the above copyright
00009      notice, this list of conditions and the following disclaimer.
00010    * Redistributions in binary form must reproduce the above copyright
00011      notice, this list of conditions and the following disclaimer in the
00012      documentation and/or other materials provided with the distribution.
00013    * Neither the name of the authors nor the names of its contributors
00014      may be used to endorse or promote products derived from this software
00015      without specific prior written permission.
00016 
00017    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027    POSSIBILITY OF SUCH DAMAGE. */
00028 
00029 /* $Id: board.h,v 1.33 2010/12/05 20:21:54 awachtler Exp $ */
00035 #ifndef BOARD_H
00036 #define BOARD_H
00037 
00038 #ifndef F_CPU
00039 # error "F_CPU is undefined"
00040 #endif
00041 
00042 /* === includes ============================================================ */
00043 #include <stdlib.h>
00044 #include <stdint.h>
00045 #include <inttypes.h>
00046 #include <avr/io.h>
00047 #include <avr/sleep.h>
00048 #include <avr/interrupt.h>
00049 #include <util/delay.h>
00050 #include <avr/pgmspace.h>
00051 #include "const.h"
00052 #include "board_cfg.h"
00053 
00059 /* === macros ============================================================== */
00072 #define DELAY_US(x)  _delay_ms(x/1000.0)
00073 
00076 #define DELAY_MS(x)  _delay_ms(x)
00077 
00078 #ifndef PULLUP_KEYS
00079 
00082 # define PULLUP_KEYS (0)
00083 #endif
00084 
00085 
00089 #define SLEEP_ON_IDLE()\
00090         do{\
00091             set_sleep_mode(SLEEP_MODE_IDLE);\
00092             sleep_mode();\
00093         }while(0);
00094 
00095 
00096 #ifdef NO_TIMER
00097 //# define HAVE_MALLOC_TIMERS
00099 # define TIMER_POOL_SIZE  (0)
00100 # define TIMER_INIT() do{}while(0)
00101 # define TIMER_IRQ   TIMER1_OVF_vect
00102 #endif
00103 
00104 #ifndef HIF_TYPE
00105 
00106 # define NO_HIF (1)
00107 # define HIF_TYPE (HIF_NONE)
00108 #endif
00109 
00110 #ifndef HIF_IO_ENABLE
00111 
00112 # define HIF_IO_ENABLE() do{}while(0)
00113 #endif
00114 
00115 #define HIF_TYPE_IS_UART  ((HIF_TYPE >= HIF_UART_0) && ( HIF_TYPE <= HIF_UART_1))
00116 #define HIF_TYPE_IS_USB   ((HIF_TYPE == HIF_FT245) || (HIF_TYPE == HIF_AT90USB))
00117 
00118 /* === Radio Control Pins === */
00119 #ifndef TRX_RESET_INIT
00120 
00121 # define TRX_RESET_INIT() DDR_TRX_RESET |= MASK_TRX_RESET
00122 #endif
00123 
00124 #ifndef TRX_RESET_HIGH
00125 
00126 # define TRX_RESET_HIGH() PORT_TRX_RESET |= MASK_TRX_RESET
00127 #endif
00128 
00129 #ifndef TRX_RESET_LOW
00130 
00131 # define TRX_RESET_LOW()  PORT_TRX_RESET &= ~MASK_TRX_RESET
00132 #endif
00133 
00134 #ifndef TRX_SLPTR_INIT
00135 
00136 # define TRX_SLPTR_INIT() DDR_TRX_SLPTR |= MASK_TRX_SLPTR
00137 #endif
00138 
00139 #ifndef TRX_SLPTR_HIGH
00140 
00141 # define TRX_SLPTR_HIGH() PORT_TRX_SLPTR |= MASK_TRX_SLPTR
00142 #endif
00143 
00144 #ifndef TRX_SLPTR_LOW
00145 
00146 # define TRX_SLPTR_LOW()  PORT_TRX_SLPTR &= ~MASK_TRX_SLPTR
00147 #endif
00148 
00149 
00150 #if defined (DBG_PORT) && defined (DBG_DDR) && defined (DBG_PIN)
00151 # define DBG_INIT() do{DBG_DDR |= DBG_PIN; DBG_PORT &= ~DBG_PIN;}while(0)
00152 # define DBG_SET() do{DBG_PORT |= DBG_PIN;}while(0)
00153 # define DBG_CLR() do{DBG_PORT &= ~DBG_PIN;}while(0)
00154 # define DBG_TOGGLE() do{DBG_PORT ^= DBG_PIN;}while(0)
00155 #else
00156 # define DBG_INIT() do{}while(0)
00157 # define DBG_SET() do{}while(0)
00158 # define DBG_CLR() do{}while(0)
00159 # define DBG_TOGGLE() do{}while(0)
00160 #endif
00161 /* === types =============================================================== */
00162 
00168 typedef struct
00169 {
00170     uint16_t short_addr;
00171     uint16_t pan_id;
00172     uint64_t ieee_addr;
00173     uint8_t _reserved_[3];
00174     uint8_t crc;
00175 } node_config_t;
00176 
00177 static inline void get_node_config(node_config_t *ncfg)
00178 {
00179     uint8_t i = sizeof(node_config_t);
00180     uint8_t *pram = (uint8_t*)ncfg;
00181     do
00182     {
00183     #if FLASHEND > 0xffffL
00184         *pram++ = pgm_read_byte_far(((long)FLASHEND - i + 1));
00185     #else
00186         *pram++ = pgm_read_byte_near((FLASHEND - i + 1));
00187     #endif
00188     }
00189     while(--i);
00190 }
00191 
00192 /* === prototypes ========================================================== */
00193 #ifdef __cplusplus
00194 extern "C" {
00195 #endif
00196 
00197 #ifdef __cplusplus
00198 } /* extern "C" */
00199 #endif
00200 
00202 #endif /* #ifndef BOARD_H */

This documentation for µracoli was generated on Wed Feb 2 2011 by  doxygen 1.7.1