# board_muse231.h

Go to the documentation of this file.

    00001 /* Copyright (c) 2011
    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$ */
    00088 #ifndef BOARD_MUSE231_H
    00089 #define BOARD_MUSE231_H  (1)
    00090
    00092 # define BOARD_TYPE (BOARD_MUSE231)
    00093 # define BOARD_NAME "Multisensor 231"
    00094 # define RADIO_TYPE (RADIO_AT86RF231)
    00096 /*=== Compile time parameters ========================================*/
    00097
    00098 #ifndef DEFAULT_SPI_RATE
    00099 # define DEFAULT_SPI_RATE  (SPI_RATE_1_2)
    00100 #endif
    00101
    00102 /*=== Hardware Components ============================================*/
    00103
    00104 /*=== TRX pin access macros ==========================================*/
    00105
    00106 #define DDR_TRX_RESET   DDRC
    00107 #define PORT_TRX_RESET  PORTC
    00108 #define MASK_TRX_RESET  (_BV(1))
    00109 /* check in board.h if standard definitions of TRX_RESET_INIT,
    00110    TRX_RESET_HIGH, TRX_RESET_LOW are Ok, otherwise define here */
    00111
    00112 #define PORT_TRX_SLPTR  PORTC
    00113 #define DDR_TRX_SLPTR   DDRC
    00114 #define MASK_TRX_SLPTR  (_BV(0))
    00115 /* check in board.h if standard definitions of TRX_SLPTR_INIT,
    00116    TRX_SLPTR_HIGH, TRX_SLPTR_LOW are Ok, otherwise define here */
    00117
    00118
    00119 /*=== ACC pin access macros ==========================================*/
    00120
    00121 #define ACC_IRQ_DDR      DDRD
    00122 #define ACC_IRQ_PORT     PORTD
    00123 #define ACC_IRQ_PIN      PIND
    00124 #define ACC_IRQ_bp       (2)
    00125 #define ACC_IRQ_ASIN()   do{ ACC_IRQ_DDR &= ~_BV(ACC_IRQ_bp);  }while(0)
    00126 #define ACC_IRQ_ASOUT()  do{ ACC_IRQ_DDR |= _BV(ACC_IRQ_bp);   }while(0)
    00127 #define ACC_IRQ_LO()     do{ ACC_IRQ_PORT &= ~_BV(ACC_IRQ_bp); }while(0)
    00128 #define ACC_IRQ_HI()     do{ ACC_IRQ_PORT |= _BV(ACC_IRQ_bp);  }while(0)
    00129 #define ACC_IRQ_STATE() ( (ACC_IRQ_PIN & _BV(ACC_IRQ_bp)) != 0)
    00130
    00131 /*=== IRQ access macros ==============================================*/
    00132
    00133 #define TRX_IRQ_PORT (PORTD)
    00134 #define TRX_IRQ_DDR (DDRD)
    00135 #define TRX_IRQ_PIN (PIND)
    00136 #define TRX_IRQ_bp  (5)
    00137
    00138 # define TRX_IRQ         0x00
    00139 # define TRX_IRQ_vect    PCINT2_vect
    00140 # define ACC_IRQ_vect    INT0_vect
    00145 # define TRX_IRQ_INIT()  do{ PCICR |= _BV(PCIE2); } while(0)
    00146
    00147 #define DI_TRX_IRQ() { PCMSK2 &= ~_BV(PCINT21); }
    00148
    00149 #define EI_TRX_IRQ() { PCMSK2 |= _BV(PCINT21); }
    00150
    00151 /*=== SPI access macros ==============================================*/
    00152 #define SPI_TYPE  SPI_TYPE_SPI
    00153 #define DDR_SPI  (DDRB)
    00154 #define PORT_SPI (PORTB)
    00156 #define SPI_MOSI _BV(PB3)
    00157 #define SPI_MISO _BV(PB4)
    00158 #define SPI_SCK  _BV(PB5)
    00159 #define SPI_SS   _BV(PB0)
    00162 #define SPI_DATA_REG SPDR
    00168 static inline void SPI_INIT(uint8_t spirate)
    00169 {
    00170     /* first configure SPI Port, then SPCR */
    00171
    00172     /* pullup for SS of SPI unit to prevent setting to SLAVE, not TRX_SELN! */
    00173     PORT_SPI |= _BV(PB2);
    00174
    00175     PORT_SPI |= SPI_SS | SPI_MISO | SPI_MOSI | SPI_SCK;
    00176     DDR_SPI  |= SPI_MOSI | SPI_SCK | SPI_SS;
    00177     DDR_SPI  &= ~SPI_MISO;
    00178
    00179     SPCR = (_BV(SPE) | _BV(MSTR));
    00180
    00181     SPCR &= ~(_BV(SPR1) | _BV(SPR0) );
    00182     SPSR &= ~_BV(SPI2X);
    00183
    00184     SPCR |= (spirate & 0x03);
    00185     SPSR |= ((spirate >> 2) & 0x01);
    00186 }
    00187
    00189 #define SPI_SELN_LOW()       uint8_t sreg = SREG; cli(); PORT_SPI &=~SPI_SS
    00190
    00191 #define SPI_SELN_HIGH()      PORT_SPI |= SPI_SS; SREG = sreg
    00192
    00193 #define SPI_WAITFOR()        do { while((SPSR & _BV(SPIF)) == 0);} while(0)
    00194
    00195 /*=== LED access macros ==============================================*/
    00196
    00197 #define LED_PORT      PORTD
    00198 #define LED_DDR       DDRD
    00199 #define LED_MASK      (0x18)
    00200 #define LED_SHIFT     (3)
    00201 #define LEDS_INVERSE  (0)
    00203 #define LED_NUMBER    (2)
    00205 /* special handling for this board to enable light measurement */
    00206 #define LED_PIN       PIND
    00207 #define LED_ANODE_bp   (3)
    00208 #define LED_CATHODE_bp (4)
    00210 /*=== KEY access macros ==============================================*/
    00211 #define NO_KEYS       (1)
    00213 /*=== Host Interface ================================================*/
    00214
    00215 #define HIF_TYPE    HIF_NONE
    00216
    00217 /*=== TIMER Interface ===============================================*/
    00218
    00219 /* setup timer with a tick of 1ms (assuming F_CPU = 8MHz fixed) */
    00220
    00221 #define HWTMR_PRESCALE  (8)
    00222 #define HWTIMER_TICK    ((1.0*HWTMR_PRESCALE)/F_CPU)
    00223 #define HWTIMER_TICK_NB (1000UL)
    00224 #define HWTIMER_REG     (TCNT1)
    00225 #define TIMER_TICK      (HWTIMER_TICK_NB * HWTIMER_TICK)
    00226 #define TIMER_POOL_SIZE (4)
    00227 #define TIMER_INIT() \
    00228     do{ \
    00229         TCCR1B = 0; \
    00230         OCR1A = HWTIMER_TICK_NB; \
    00231         TCCR1B |= (_BV(WGM12) | _BV(CS11)); \
    00232         TIMSK1 |= _BV(OCIE1A); \
    00233     }while(0)
    00234 # define TIMER_IRQ_vect   TIMER1_COMPA_vect
    00235
    00236 /*=== Special Hardware Ressources ===================================*/
    00237
    00238 #endif /* BOARD_MUSE231_H */