Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00035 #ifndef BOARD_H
00036 #define BOARD_H
00037
00038 #ifndef F_CPU
00039 # error "F_CPU is undefined"
00040 #endif
00041
00042
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 <avr/eeprom.h>
00052 #include <util/crc16.h>
00053 #include "const.h"
00054 #include "board_cfg.h"
00055
00061
00074 #define DELAY_US(x) _delay_ms(x/1000.0)
00075
00078 #define DELAY_MS(x) _delay_ms(x)
00079
00080 #ifndef PULLUP_KEYS
00081
00084 # define PULLUP_KEYS (0)
00085 #endif
00086
00087
00091 #define SLEEP_ON_IDLE()\
00092 do{\
00093 set_sleep_mode(SLEEP_MODE_IDLE);\
00094 sleep_mode();\
00095 }while(0);
00096
00097
00098 #ifdef NO_TIMER
00099
00101 # define TIMER_POOL_SIZE (0)
00102 # define TIMER_INIT() do{}while(0)
00103 # define TIMER_IRQ TIMER1_OVF_vect
00104 #endif
00105
00106 #ifndef HIF_TYPE
00107
00108 # define NO_HIF (1)
00109 # define HIF_TYPE (HIF_NONE)
00110 #endif
00111
00112 #ifndef HIF_IO_ENABLE
00113
00114 # define HIF_IO_ENABLE() do{}while(0)
00115 #endif
00116
00117 #define HIF_TYPE_IS_UART ((HIF_TYPE >= HIF_UART_0) && ( HIF_TYPE <= HIF_UART_1))
00118 #define HIF_TYPE_IS_USB ((HIF_TYPE == HIF_FT245) || (HIF_TYPE == HIF_AT90USB))
00119
00120
00121 #ifndef TRX_RESET_INIT
00122
00123 # define TRX_RESET_INIT() DDR_TRX_RESET |= MASK_TRX_RESET
00124 #endif
00125
00126 #ifndef TRX_RESET_HIGH
00127
00128 # define TRX_RESET_HIGH() PORT_TRX_RESET |= MASK_TRX_RESET
00129 #endif
00130
00131 #ifndef TRX_RESET_LOW
00132
00133 # define TRX_RESET_LOW() PORT_TRX_RESET &= ~MASK_TRX_RESET
00134 #endif
00135
00136 #ifndef TRX_SLPTR_INIT
00137
00138 # define TRX_SLPTR_INIT() DDR_TRX_SLPTR |= MASK_TRX_SLPTR
00139 #endif
00140
00141 #ifndef TRX_SLPTR_HIGH
00142
00143 # define TRX_SLPTR_HIGH() PORT_TRX_SLPTR |= MASK_TRX_SLPTR
00144 #endif
00145
00146 #ifndef TRX_SLPTR_LOW
00147
00148 # define TRX_SLPTR_LOW() PORT_TRX_SLPTR &= ~MASK_TRX_SLPTR
00149 #endif
00150
00151 #if ! defined(DI_TRX_IRQ) && ! defined(EI_TRX_IRQ)
00152
00153 # define DI_TRX_IRQ disable_all_trx_irqs
00154 # define EI_TRX_IRQ enable_all_trx_irqs
00155 #endif
00156
00157 #if defined (DBG_PORT) && defined (DBG_DDR) && defined (DBG_PIN)
00158 # define DBG_INIT() do{DBG_DDR |= DBG_PIN; DBG_PORT &= ~DBG_PIN;}while(0)
00159 # define DBG_SET() do{DBG_PORT |= DBG_PIN;}while(0)
00160 # define DBG_CLR() do{DBG_PORT &= ~DBG_PIN;}while(0)
00161 # define DBG_TOGGLE() do{DBG_PORT ^= DBG_PIN;}while(0)
00162 #else
00163 # define DBG_INIT() do{}while(0)
00164 # define DBG_SET() do{}while(0)
00165 # define DBG_CLR() do{}while(0)
00166 # define DBG_TOGGLE() do{}while(0)
00167 #endif
00168
00169
00175 typedef struct
00176 {
00177 uint16_t short_addr;
00178 uint16_t pan_id;
00179 uint64_t ieee_addr;
00180 uint8_t channel;
00181 uint8_t _reserved_[2];
00182 uint8_t crc;
00183 } node_config_t;
00184
00185 static inline uint8_t get_node_config(node_config_t *ncfg)
00186 {
00187 uint8_t i = sizeof(node_config_t);
00188 uint8_t *pram = (uint8_t*)ncfg;
00189 uint8_t crc = 0;
00190 do
00191 {
00192 #if FLASHEND > 0xffffL
00193 *pram = pgm_read_byte_far(((long)FLASHEND - i + 1));
00194 #else
00195 *pram = pgm_read_byte_near((FLASHEND - i + 1));
00196 #endif
00197
00198 crc = _crc_ibutton_update(crc, *pram++);
00199 }
00200 while(--i);
00201 return crc;
00202 }
00203
00204 static inline uint8_t get_node_config_eeprom(node_config_t *ncfg, uint8_t * offset)
00205 {
00206 uint8_t i = sizeof(node_config_t);
00207 uint8_t *pram = (uint8_t*)ncfg;
00208 uint8_t crc = 0;
00209 do
00210 {
00211 *pram = eeprom_read_byte( (const uint8_t *) offset++ );
00212 crc = _crc_ibutton_update(crc, *pram++);
00213 }
00214 while(--i);
00215 return crc;
00216 }
00217
00218 static inline void jump_to_bootloader(void)
00219 {
00220 typedef void (*func_ptr_t)(void) __attribute__((noreturn));
00221 const func_ptr_t jmp_boot = (func_ptr_t)(BOOT_LOADER_ADDRESS * 2);
00222 jmp_boot();
00223 }
00224
00225
00226 #ifdef __cplusplus
00227 extern "C" {
00228 #endif
00229
00230 #ifdef __cplusplus
00231 }
00232 #endif
00233
00235 #endif