# board_wimod.h

Go to the documentation of this file.

    00001 /* Copyright (c) 2007 - 2011 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$ */
    00126 #ifndef BOARD_WIMOD_H
    00127 #define BOARD_WIMOD_H (1)
    00128 #if defined(im240a)
    00129 # define BOARD_NAME "im240a"
    00130 # define BOARD_TYPE BOARD_IM240A
    00131 #elif defined(im240a_eval)
    00132 # define BOARD_NAME "im240a_eval"
    00133 # define BOARD_TYPE BOARD_IM240A_EVAL
    00134 #endif
    00135 /*=== Compile time parameters ========================================*/
    00136 #ifndef DEFAULT_SPI_RATE
    00137 # define DEFAULT_SPI_RATE  (SPI_RATE_1_2)
    00138 #endif
    00139
    00140 /*=== Hardware Components ============================================*/
    00141 #define RADIO_TYPE (RADIO_AT86RF230B)
    00142
    00143 /*=== TRX pin access macros ==========================================*/
    00144
    00145 #define DDR_TRX_RESET   DDRD
    00146 #define PORT_TRX_RESET  PORTD
    00147 #define MASK_TRX_RESET  (_BV(PD6))
    00148 #define TRX_RESET_INIT() DDR_TRX_RESET |= MASK_TRX_RESET
    00149 #define TRX_RESET_HIGH() PORT_TRX_RESET |= MASK_TRX_RESET
    00150 #define TRX_RESET_LOW()  PORT_TRX_RESET &= ~MASK_TRX_RESET
    00151
    00152 #define PORT_TRX_SLPTR  PORTB
    00153 #define DDR_TRX_SLPTR   DDRB
    00154 #define MASK_TRX_SLPTR  (_BV(PB1))
    00155
    00156 #define TRX_SLPTR_INIT() DDR_TRX_SLPTR |= MASK_TRX_SLPTR
    00157 #define TRX_SLPTR_HIGH() PORT_TRX_SLPTR |= MASK_TRX_SLPTR
    00158 #define TRX_SLPTR_LOW()  PORT_TRX_SLPTR &= ~MASK_TRX_SLPTR
    00159
    00160
    00161 /*=== IRQ access macros ==============================================*/
    00162 # define TRX_IRQ_vect    TIMER1_CAPT_vect
    00170 # define TRX_IRQ_INIT()  do{\
    00171                             /* TCCR1B |= (_BV(ICNC1) | _BV(ICES1) | _BV(CS12) | _BV(CS10)); */\
    00172                             TCCR1B |= (_BV(ICNC1) | _BV(ICES1));\
    00173                             TIFR1 = _BV(ICF1);\
    00174                           } while(0)
    00175
    00177 #define DI_TRX_IRQ() {TIMSK1 &= ~_BV(ICIE1);}
    00178
    00180 #define EI_TRX_IRQ() {TIMSK1 |= _BV(ICIE1);}
    00181
    00183 #define TRX_TSTAMP_REG TCNT1
    00184 /*=== SPI access macros ==============================================*/
    00185 #define DDR_SPI  (DDRB)
    00186 #define PORT_SPI (PORTB)
    00187
    00188 #define SPI_MOSI _BV(PB3)
    00189 #define SPI_MISO _BV(PB4)
    00190 #define SPI_SCK  _BV(PB5)
    00191 #define SPI_SS   _BV(PB2)
    00192
    00193 #define SPI_DATA_REG SPDR
    00194
    00195 static inline void SPI_INIT(uint8_t spirate)
    00196 {
    00197     /* first configure SPI Port, then SPCR */
    00198     PORT_SPI |= SPI_SCK | SPI_SS;
    00199     DDR_SPI  |= SPI_MOSI | SPI_SCK | SPI_SS;
    00200     DDR_SPI  &= ~SPI_MISO;
    00201
    00202     SPCR = (_BV(SPE) | _BV(MSTR));
    00203
    00204     SPCR &= ~(_BV(SPR1) | _BV(SPR0) );
    00205     SPSR &= ~_BV(SPI2X);
    00206
    00207     SPCR |= (spirate & 0x03);
    00208     SPSR |= ((spirate >> 2) & 0x01);
    00209
    00210 }
    00211
    00212 #define SPI_SELN_LOW()       uint8_t sreg = SREG; cli(); PORT_SPI &=~SPI_SS
    00213 #define SPI_SELN_HIGH()      PORT_SPI |= SPI_SS; SREG = sreg
    00214 #define SPI_WAITFOR()        do { while((SPSR & _BV(SPIF)) == 0);} while(0)
    00215
    00216 /*=== LED access macros ==============================================*/
    00217 #if (BOARD_TYPE == BOARD_IM240A_EVAL)
    00218 /* need to implement bit reversed LED mapping,
    00219  * Current Usage
    00220  * LSB : LED4, LSB+1 : LED3, MSB : LED2
    00221  */
    00222 # define LED_PORT      PORTD
    00223 # define LED_DDR       DDRD
    00224 # define LED_MASK      (0x1c)
    00225 # define LED_SHIFT     (2)
    00226 # define LED_NUMBER    (3)
    00227 # define LEDS_INVERSE  (1)
    00228 #else
    00229 # define NO_LEDS       (1)
    00230 #endif
    00231
    00232 /*=== KEY access macros ==============================================*/
    00233 #if (BOARD_TYPE == BOARD_IM240A_EVAL)
    00234 # define PORT_KEY      PORTC
    00235 # define PIN_KEY       PINC
    00236 # define DDR_KEY       DDRC
    00237 # define MASK_KEY      (0x07)
    00238 # define SHIFT_KEY     (0)
    00239 # define INVERSE_KEYS  (1)
    00240 # define PULLUP_KEYS   (1)
    00241 #else
    00242 # define NO_KEYS       (1)
    00243 #endif
    00244
    00245
    00246 /*=== Host Interface ================================================*/
    00247 #define HIF_TYPE    HIF_UART_0
    00248
    00249
    00250 /*=== TIMER Interface ===============================================*/
    00256 #define HWTMR_PRESCALE  (1)
    00257 #define HWTIMER_TICK    ((1.0*HWTMR_PRESCALE)/F_CPU)
    00258 #define HWTIMER_TICK_NB (0xFFFFUL)
    00259 #define HWTIMER_REG     (TCNT1)
    00260 #define TIMER_TICK      (HWTIMER_TICK_NB * HWTIMER_TICK)
    00261 #define TIMER_POOL_SIZE (4)
    00262 #define TIMER_INIT() \
    00263     do{ \
    00264         TCCR1B |= (_BV(CS10)); \
    00265         TIMSK1 |= _BV(TOIE1); \
    00266     }while(0)
    00267 # define TIMER_IRQ_vect   TIMER1_OVF_vect
    00268
    00269 #endif /* BOARD_WIMOD_H */