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  ((1<<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  ((1<<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 &= ~(1<<ACC_IRQ_bp);  }while(0)
    00126 #define ACC_IRQ_ASOUT()  do{ ACC_IRQ_DDR |= (1<<ACC_IRQ_bp);   }while(0)
    00127 #define ACC_IRQ_LO()     do{ ACC_IRQ_PORT &= ~(1<<ACC_IRQ_bp); }while(0)
    00128 #define ACC_IRQ_HI()     do{ ACC_IRQ_PORT |= (1<<ACC_IRQ_bp);  }while(0)
    00129 #define ACC_IRQ_STATE() ( (ACC_IRQ_PIN & (1<<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 |= (1<<PCIE2); } while(0)
    00146
    00147 #define DI_TRX_IRQ() { PCMSK2 &= ~(1<<PCINT21); }
    00148
    00149 #define EI_TRX_IRQ() { PCMSK2 |= (1<<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 (1<<PB3)
    00157 #define SPI_MISO (1<<PB4)
    00158 #define SPI_SCK  (1<<PB5)
    00159 #define SPI_SS   (1<<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 |= (1<<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 = ((1<<SPE) | (1<<MSTR));
    00180
    00181     SPCR &= ~((1<<SPR1) | (1<<SPR0) );
    00182     SPSR &= ~(1<<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 & (1<<SPIF)) == 0);} while(0)
    00194
    00195 /*=== LED access macros ==============================================*/
    00196
    00197 #define LED_PORT      PORTD
    00198 #define LED_DDR       DDRD
    00199 #define LED_MASK      (0x08)
    00200 #define LED_SHIFT     (3)
    00201 #define LEDS_INVERSE  (0)
    00203 #define LED_NUMBER    (1)
    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 /* special handling required */
    00211 #define LED_INIT() do{ LED_PORT &= ~((1<<LED_CATHODE_bp) | (1<<LED_ANODE_bp)); \
    00212             LED_DDR |= ((1<<LED_CATHODE_bp) | (1<<LED_ANODE_bp)); }while(0)
    00213
    00214 /*=== KEY access macros ==============================================*/
    00215 #define NO_KEYS       (1)
    00217 /*=== Host Interface ================================================*/
    00218
    00219 #define HIF_TYPE    HIF_NONE
    00220
    00221 /*=== TIMER Interface ===============================================*/
    00222
    00223 /* setup timer with a tick of 1ms (assuming F_CPU = 8MHz fixed) */
    00224
    00225 #define HWTMR_PRESCALE  (8)
    00226 #define HWTIMER_TICK    ((1.0*HWTMR_PRESCALE)/F_CPU)
    00227 #define HWTIMER_TICK_NB (1000UL)
    00228 #define HWTIMER_REG     (TCNT1)
    00229 #define TIMER_TICK      (HWTIMER_TICK_NB * HWTIMER_TICK)
    00230 #define TIMER_POOL_SIZE (4)
    00231 #define TIMER_INIT() \
    00232     do{ \
    00233         TCCR1B = 0; \
    00234         OCR1A = HWTIMER_TICK_NB; \
    00235         TCCR1B |= ((1<<WGM12) | (1<<CS11)); \
    00236         TIMSK1 |= (1<<OCIE1A); \
    00237     }while(0)
    00238 # define TIMER_IRQ_vect   TIMER1_COMPA_vect
    00239
    00240 /*=== Special Hardware Ressources ===================================*/
    00241
    00242 #endif /* BOARD_MUSE231_H */