# board_stkm8.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$ */
    00076 #ifndef BOARD_STK_M8_H
    00077 #define BOARD_STK_M8_H
    00078
    00079 #define BOARD_TYPE  (BOARD_STKM8)
    00080 #define BOARD_NAME "stkm8"
    00081
    00082 /*=== Compile time parameters ========================================*/
    00083 #ifndef DEFAULT_SPI_RATE
    00084 # define DEFAULT_SPI_RATE  (SPI_RATE_1_2)
    00085 #endif
    00086
    00087 /*=== Hardware Components ============================================*/
    00088 #define RADIO_TYPE (RADIO_AT86RF230B)
    00089
    00090 /*=== TRX pin access macros ==========================================*/
    00091
    00092 #define DDR_TRX_RESET   DDRD
    00093 #define PORT_TRX_RESET  PORTD
    00094 #define MASK_TRX_RESET  (_BV(PD6))
    00095 #define TRX_RESET_INIT() DDR_TRX_RESET |= MASK_TRX_RESET
    00096 #define TRX_RESET_HIGH() PORT_TRX_RESET |= MASK_TRX_RESET
    00097 #define TRX_RESET_LOW()  PORT_TRX_RESET &= ~MASK_TRX_RESET
    00098
    00099 #define PORT_TRX_SLPTR  PORTD
    00100 #define DDR_TRX_SLPTR   DDRD
    00101 #define MASK_TRX_SLPTR  (_BV(PD7))
    00102
    00103 #define TRX_SLPTR_INIT() DDR_TRX_SLPTR |= MASK_TRX_SLPTR
    00104 #define TRX_SLPTR_HIGH() PORT_TRX_SLPTR |= MASK_TRX_SLPTR
    00105 #define TRX_SLPTR_LOW()  PORT_TRX_SLPTR &= ~MASK_TRX_SLPTR
    00106
    00107
    00108 /*=== IRQ access macros ==============================================*/
    00109 # define TRX_IRQ_vect    TIMER1_CAPT_vect
    00115 # define TRX_IRQ_INIT()  do{\
    00116                             /* TCCR1B |= (_BV(ICNC1) | _BV(ICES1) | _BV(CS12) | _BV(CS10)); */\
    00117                             TCCR1B |= (_BV(ICNC1) | _BV(ICES1));\
    00118                             TIFR = _BV(ICF1);\
    00119                           } while(0)
    00120
    00122 #define DI_TRX_IRQ() {TIMSK &= ~_BV(TICIE1);}
    00123
    00125 #define EI_TRX_IRQ() {TIMSK |= _BV(TICIE1);}
    00126
    00128 #define TRX_TSTAMP_REG TCNT1
    00129 /*=== SPI access macros ==============================================*/
    00130 #define DDR_SPI  (DDRB)
    00131 #define PORT_SPI (PORTB)
    00132
    00133 #define SPI_MOSI _BV(PB3)
    00134 #define SPI_MISO _BV(PB4)
    00135 #define SPI_SCK  _BV(PB5)
    00136 #define SPI_SS   _BV(PB2)
    00137
    00138 #define SPI_DATA_REG SPDR
    00139
    00140 static inline void SPI_INIT(uint8_t spirate)
    00141 {
    00142     /* first configure SPI Port, then SPCR */
    00143     PORT_SPI |= SPI_SCK | SPI_SS;
    00144     DDR_SPI  |= SPI_MOSI | SPI_SCK | SPI_SS;
    00145     DDR_SPI  &= ~SPI_MISO;
    00146
    00147     SPCR = (_BV(SPE) | _BV(MSTR));
    00148
    00149     SPCR &= ~(_BV(SPR1) | _BV(SPR0) );
    00150     SPSR &= ~_BV(SPI2X);
    00151
    00152     SPCR |= (spirate & 0x03);
    00153     SPSR |= ((spirate >> 2) & 0x01);
    00154
    00155 }
    00156
    00157 #define SPI_SELN_LOW()       uint8_t sreg = SREG; cli(); PORT_SPI &=~SPI_SS
    00158 #define SPI_SELN_HIGH()      PORT_SPI |= SPI_SS; SREG = sreg
    00159 #define SPI_WAITFOR()        do { while((SPSR & _BV(SPIF)) == 0);} while(0)
    00160
    00161 /*=== LED access macros ==============================================*/
    00162 #define LED_PORT      PORTC
    00163 #define LED_DDR       DDRC
    00164 #define LED_MASK      (0x03)
    00165 #define LED_SHIFT     (0)
    00166 #define LED_NUMBER    (2)
    00167 #define LEDS_INVERSE  (1)
    00168
    00169 /*=== KEY access macros ==============================================*/
    00170 #define PORT_KEY      PORTD
    00171 #define PIN_KEY       PIND
    00172 #define DDR_KEY       DDRD
    00173 #define MASK_KEY     (0x0c)
    00174 #define SHIFT_KEY    (2)
    00175 #define INVERSE_KEYS (1)
    00176 #define PULLUP_KEYS  (1)
    00177
    00178 /*=== Host Interface ================================================*/
    00179 #define HIF_TYPE    HIF_UART_0
    00180
    00181
    00182 /*=== TIMER Interface ===============================================*/
    00188 #define HWTMR_PRESCALE  (1)
    00189 #define HWTIMER_TICK    ((1.0*HWTMR_PRESCALE)/F_CPU)
    00190 #define HWTIMER_TICK_NB (0xFFFFUL)
    00191 #define HWTIMER_REG     (TCNT1)
    00192 #define TIMER_TICK      (HWTIMER_TICK_NB * HWTIMER_TICK)
    00193 #define TIMER_POOL_SIZE (4)
    00194 #define TIMER_INIT() \
    00195     do{ \
    00196         TCCR1B |= (_BV(CS10)); \
    00197         TIMSK |= _BV(TOIE1); \
    00198     }while(0)
    00199 # define TIMER_IRQ_vect   TIMER1_OVF_vect
    00200
    00201 #endif /* BOARD_STK_M8_H */