# board_lgee.h

Go to the documentation of this file.

    00001 /* Copyright (c) 2009
    00002     Daniel Thiele,
    00003     Axel Wachtler
    00004    All rights reserved.
    00005
    00006    Redistribution and use in source and binary forms, with or without
    00007    modification, are permitted provided that the following conditions
    00008    are met:
    00009
    00010    * Redistributions of source code must retain the above copyright
    00011      notice, this list of conditions and the following disclaimer.
    00012    * Redistributions in binary form must reproduce the above copyright
    00013      notice, this list of conditions and the following disclaimer in the
    00014      documentation and/or other materials provided with the distribution.
    00015    * Neither the name of the authors nor the names of its contributors
    00016      may be used to endorse or promote products derived from this software
    00017      without specific prior written permission.
    00018
    00019    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00020    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00021    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00022    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00023    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    00024    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    00025    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    00026    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    00027    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    00028    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    00029    POSSIBILITY OF SUCH DAMAGE. */
    00030
    00031 /* $Id$ */
    00081 #if defined(lgee231)
    00082 # define BOARD_TYPE (BOARD_LGEE231)
    00083 # define BOARD_NAME "littleGee/v3"
    00084 # define RADIO_TYPE (RADIO_AT86RF231)
    00085 # define BOARDVERSION (3)
    00086 #elif defined(lgee231_v2)
    00087 # define BOARD_TYPE (BOARD_LGEE231_V2)
    00088 # define BOARD_NAME "littleGee/v2"
    00089 # define RADIO_TYPE (RADIO_AT86RF231)
    00090 # define BOARDVERSION (2)
    00091 #endif
    00092
    00093 #ifndef BOARD_LGEE231_H
    00094 #define BOARD_LGEE231_H  (1)
    00095 /*=== Compile time parameters ========================================*/
    00096
    00097 #ifndef DEFAULT_SPI_RATE
    00098 # define DEFAULT_SPI_RATE  (SPI_RATE_1_2)
    00099 #endif
    00100
    00101 /*=== Hardware Components ============================================*/
    00102
    00103 /*=== TRX pin access macros ==========================================*/
    00104
    00105 #if BOARDVERSION == 2
    00106
    00107 #define DDR_TRX_RESET   DDRC
    00108 #define PORT_TRX_RESET  PORTC
    00109 #define MASK_TRX_RESET  (_BV(1))
    00110 /* check in board.h if standard definitions of TRX_RESET_INIT,
    00111    TRX_RESET_HIGH, TRX_RESET_LOW are Ok, otherwise define here */
    00112
    00113 #define PORT_TRX_SLPTR  PORTC
    00114 #define DDR_TRX_SLPTR   DDRC
    00115 #define MASK_TRX_SLPTR  (_BV(0))
    00116 /* check in board.h if standard definitions of TRX_SLPTR_INIT,
    00117    TRX_SLPTR_HIGH, TRX_SLPTR_LOW are Ok, otherwise define here */
    00118
    00119 #elif BOARDVERSION == 3
    00120
    00121 #define DDR_TRX_RESET   DDRC
    00122 #define PORT_TRX_RESET  PORTC
    00123 #define MASK_TRX_RESET  (_BV(3))
    00124 /* check in board.h if standard definitions of TRX_RESET_INIT,
    00125    TRX_RESET_HIGH, TRX_RESET_LOW are Ok, otherwise define here */
    00126
    00127 #define PORT_TRX_SLPTR  PORTC
    00128 #define DDR_TRX_SLPTR   DDRC
    00129 #define MASK_TRX_SLPTR  (_BV(0))
    00130 /* check in board.h if standard definitions of TRX_SLPTR_INIT,
    00131    TRX_SLPTR_HIGH, TRX_SLPTR_LOW are Ok, otherwise define here */
    00132
    00133 #else
    00134 #error "Unknown BOARDVERSION, set to 2 or 3"
    00135
    00136 #endif /* BOARDVERSION == */
    00137
    00138
    00139
    00140 /*=== ACC pin access macros ==========================================*/
    00141
    00142 #if BOARDVERSION == 2
    00143
    00144 #define ACC_SELN_DDR      DDRB
    00145 #define ACC_SELN_PORT     PORTB
    00146 #define ACC_SELN_PIN      PINB
    00147 #define ACC_SELN_bp       (2)
    00148 #define ACC_SELN_ASIN()   do{ ACC_SELN_DDR &= ~_BV(ACC_SELN_bp);  }while(0)
    00149 #define ACC_SELN_ASOUT()  do{ ACC_SELN_DDR |= _BV(ACC_SELN_bp);   }while(0)
    00150 #define ACC_SELN_LO()     do{ ACC_SELN_PORT &= ~_BV(ACC_SELN_bp); }while(0)
    00151 #define ACC_SELN_HI()     do{ ACC_SELN_PORT |= _BV(ACC_SELN_bp);  }while(0)
    00152
    00153 #elif BOARDVERSION == 3
    00154
    00155 #define ACC_SELN_DDR      DDRD
    00156 #define ACC_SELN_PORT     PORTD
    00157 #define ACC_SELN_PIN      PIND
    00158 #define ACC_SELN_bp       (6)
    00159 #define ACC_SELN_ASIN()   do{ ACC_SELN_DDR &= ~_BV(ACC_SELN_bp);  }while(0)
    00160 #define ACC_SELN_ASOUT()  do{ ACC_SELN_DDR |= _BV(ACC_SELN_bp);   }while(0)
    00161 #define ACC_SELN_LO()     do{ ACC_SELN_PORT &= ~_BV(ACC_SELN_bp); }while(0)
    00162 #define ACC_SELN_HI()     do{ ACC_SELN_PORT |= _BV(ACC_SELN_bp);  }while(0)
    00163
    00164 #define ACC_IRQ_DDR      DDRD
    00165 #define ACC_IRQ_PORT     PORTD
    00166 #define ACC_IRQ_PIN      PIND
    00167 #define ACC_IRQ_bp       (7)
    00168 #define ACC_IRQ_ASIN()   do{ ACC_IRQ_DDR &= ~_BV(ACC_IRQ_bp);  }while(0)
    00169 #define ACC_IRQ_ASOUT()  do{ ACC_IRQ_DDR |= _BV(ACC_IRQ_bp);   }while(0)
    00170 #define ACC_IRQ_LO()     do{ ACC_IRQ_PORT &= ~_BV(ACC_IRQ_bp); }while(0)
    00171 #define ACC_IRQ_HI()     do{ ACC_IRQ_PORT |= _BV(ACC_IRQ_bp);  }while(0)
    00172 #define ACC_IRQ_STATE() ( (ACC_IRQ_PIN & _BV(ACC_IRQ_bp)) != 0)
    00173
    00174 #else
    00175 #error "Unknown BOARDVERSION, set to 2 or 3"
    00176
    00177 #endif /* BOARDVERSION == */
    00178
    00179 /*=== IRQ access macros ==============================================*/
    00180
    00181 #if BOARDVERSION == 2
    00182
    00183 # define TRX_IRQ         0x00
    00184 # define TRX_IRQ_vect    PCINT2_vect
    00189 # define TRX_IRQ_INIT()  do{ PCICR |= _BV(PCIE2); } while(0)
    00190
    00192 #define DI_TRX_IRQ() { PCMSK2 &= ~_BV(PCINT18); }
    00193
    00194 #define EI_TRX_IRQ() { PCICR |= _BV(PCIE2); PCMSK2 |= _BV(PCINT18); }
    00195
    00196 #elif BOARDVERSION == 3
    00197
    00198 #define TRX_IRQ_PORT (PORTB)
    00199 #define TRX_IRQ_DDR (DDRB)
    00200 #define TRX_IRQ_PIN (PINB)
    00201 #define TRX_IRQ_bp (1)
    00202
    00203 # define TRX_IRQ         0x00
    00204 # define TRX_IRQ_vect    PCINT0_vect
    00205 # define ACC_IRQ_vect    PCINT2_vect
    00210 # define TRX_IRQ_INIT()  do{ PCICR |= _BV(PCIE0); } while(0)
    00211
    00212 #define DI_TRX_IRQ() { PCMSK0 &= ~_BV(PCINT1); }
    00213
    00214 #define EI_TRX_IRQ() { PCMSK0 |= _BV(PCINT1); }
    00215
    00217 #define ACC_IRQ_INIT() do{ PCICR |= _BV(PCIE2); }while(0)
    00218
    00219 #define EI_ACC_IRQ()   do{ PCMSK2 |= _BV(PCINT23); }while(0)
    00220
    00221 #define DI_ACC_IRQ()   do{ PCMSK2 &= ~_BV(PCINT23); }while(0)
    00222
    00223 #else
    00224 #error "Unknown BOARDVERSION, set to 2 or 3"
    00225
    00226 #endif /* BOARDVERSION == */
    00227
    00228
    00230 #define TRX_TSTAMP_REG TCNT1
    00231
    00232 /*=== SPI access macros ==============================================*/
    00233 #define SPI_TYPE  SPI_TYPE_SPI
    00234 #define DDR_SPI  (DDRB)
    00235 #define PORT_SPI (PORTB)
    00237 #if BOARDVERSION == 2
    00238
    00239 #define SPI_MOSI _BV(PB3)
    00240 #define SPI_MISO _BV(PB4)
    00241 #define SPI_SCK  _BV(PB5)
    00242 #define SPI_SS   _BV(PB0)
    00244 #elif BOARDVERSION == 3
    00245
    00246 #define SPI_MOSI _BV(PB3)
    00247 #define SPI_MISO _BV(PB4)
    00248 #define SPI_SCK  _BV(PB5)
    00249 #define SPI_SS   _BV(PB2)
    00251 #else
    00252 #error "Unknown BOARDVERSION, set to 2 or 3"
    00253
    00254 #endif /* BOARDVERSION == */
    00255
    00256
    00257 #define SPI_DATA_REG SPDR
    00263 static inline void SPI_INIT(uint8_t spirate)
    00264 {
    00265     /* first configure SPI Port, then SPCR */
    00266     DDR_SPI  |= SPI_MOSI | SPI_SCK | SPI_SS;
    00267     DDR_SPI  &= ~SPI_MISO;
    00268     PORT_SPI |= SPI_SCK | SPI_SS;
    00269
    00270     SPCR = (_BV(SPE) | _BV(MSTR));
    00271
    00272     SPCR &= ~(_BV(SPR1) | _BV(SPR0) );
    00273     SPSR &= ~_BV(SPI2X);
    00274
    00275     SPCR |= (spirate & 0x03);
    00276     SPSR |= ((spirate >> 2) & 0x01);
    00277
    00278 }
    00279
    00281 #define SPI_SELN_LOW()       uint8_t sreg = SREG; cli(); PORT_SPI &=~SPI_SS
    00282
    00283 #define SPI_SELN_HIGH()      PORT_SPI |= SPI_SS; SREG = sreg
    00284
    00285 #define SPI_WAITFOR()        do { while((SPSR & _BV(SPIF)) == 0);} while(0)
    00286
    00287 /*=== LED access macros ==============================================*/
    00288
    00289 #if BOARDVERSION == 2
    00290
    00291 #define LED_PORT      PORTD
    00292 #define LED_DDR       DDRD
    00293 #define LED_MASK      (0x60)
    00294 #define LED_SHIFT     (5)
    00295 #define LEDS_INVERSE  (1)
    00297 #define LED_NUMBER    (2)
    00299 #elif BOARDVERSION == 3
    00300
    00301 #define LED_PORT      PORTC
    00302 #define LED_DDR       DDRC
    00303 #define LED_MASK      (0x30)
    00304 #define LED_SHIFT     (4)
    00305 #define LEDS_INVERSE  (1)
    00307 #define LED_NUMBER    (2)
    00309 #else
    00310 #error "Unknown BOARDVERSION, set to 2 or 3"
    00311
    00312 #endif /* BOARDVERSION == */
    00313
    00314
    00315 /*=== KEY access macros ==============================================*/
    00316 #define NO_KEYS       (1)
    00318 /*=== Host Interface ================================================*/
    00319
    00320 #if BOARDVERSION == 2
    00321 #define HIF_TYPE    HIF_NONE
    00322 #elif BOARDVERSION == 3
    00323 #define HIF_TYPE    (HIF_UART_0)
    00324 #else
    00325 #error "Unknown BOARDVERSION, set to 2 or 3"
    00326
    00327 #endif /* BOARDVERSION == */
    00328
    00329 /*=== TIMER Interface ===============================================*/
    00330 #define HWTMR_PRESCALE  (1)
    00331 #define HWTIMER_TICK    ((1.0*HWTMR_PRESCALE)/F_CPU)
    00332 #define HWTIMER_TICK_NB (0xFFFFUL)
    00333 #define HWTIMER_REG     (TCNT1)
    00334 #define TIMER_TICK      (HWTIMER_TICK_NB * HWTIMER_TICK)
    00335 #define TIMER_POOL_SIZE (4)
    00336 #define TIMER_INIT() \
    00337     do{ \
    00338         TCCR1B |= (_BV(CS10)); \
    00339         TIMSK1 |= _BV(TOIE1); \
    00340     }while(0)
    00341 # define TIMER_IRQ_vect   TIMER1_OVF_vect
    00342
    00343 /*=== Special Hardware Ressources ===================================*/
    00344
    00345 #endif /* BOARD_LGEE231_H */