- Main Page
- Related Pages
- Modules
- Data Structures
- Files

# 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: board_stkm8.h,v 1.12 2009/11/22 19:06:49 awachtler Exp $ */
    00075 #define BOARD_NAME_STKM8 "stkm8"
    00076
    00077 #ifndef BOARD_STK_M8_H
    00078 #define BOARD_STK_M8_H
    00079
    00080 #define BOARD_TYPE  (STK500_MEGA8)
    00081 #define BOARD_NAME  BOARD_NAME_STKM8
    00082
    00083 /*=== Compile time parameters ========================================*/
    00084 #ifndef MAX_FRAME_SIZE
    00085 # define MAX_FRAME_SIZE (127)
    00086 #endif
    00087
    00088 #ifndef DEFAULT_SPI_RATE
    00089 # define DEFAULT_SPI_RATE  (SPI_RATE_1_2)
    00090 #endif
    00091
    00092 /*=== Hardware Components ============================================*/
    00093 #define CPU_TYPE   (CPU_M8)
    00094 #define RADIO_TYPE (RADIO_AT86RF230B)
    00095
    00096 /*=== TRX pin access macros ==========================================*/
    00097
    00098 #define DDR_TRX_RESET   DDRD
    00099 #define PORT_TRX_RESET  PORTD
    00100 #define MASK_TRX_RESET  (_BV(PD6))
    00101 #define TRX_RESET_INIT() DDR_TRX_RESET |= MASK_TRX_RESET
    00102 #define TRX_RESET_HIGH() PORT_TRX_RESET |= MASK_TRX_RESET
    00103 #define TRX_RESET_LOW()  PORT_TRX_RESET &= ~MASK_TRX_RESET
    00104
    00105 #define PORT_TRX_SLPTR  PORTD
    00106 #define DDR_TRX_SLPTR   DDRD
    00107 #define MASK_TRX_SLPTR  (_BV(PD7))
    00108
    00109 #define TRX_SLPTR_INIT() DDR_TRX_SLPTR |= MASK_TRX_SLPTR
    00110 #define TRX_SLPTR_HIGH() PORT_TRX_SLPTR |= MASK_TRX_SLPTR
    00111 #define TRX_SLPTR_LOW()  PORT_TRX_SLPTR &= ~MASK_TRX_SLPTR
    00112
    00113
    00114 /*=== IRQ access macros ==============================================*/
    00115 # define TRX_IRQ_vect    TIMER1_CAPT_vect
    00121 # define TRX_IRQ_INIT()  do{\
    00122                             /* TCCR1B |= (_BV(ICNC1) | _BV(ICES1) | _BV(CS12) | _BV(CS10)); */\
    00123                             TCCR1B |= (_BV(ICNC1) | _BV(ICES1));\
    00124                             TIFR = _BV(ICF1);\
    00125                           } while(0)
    00126
    00128 #define DI_TRX_IRQ() {TIMSK &= ~_BV(TICIE1);}
    00129
    00131 #define EI_TRX_IRQ() {TIMSK |= _BV(TICIE1);}
    00132
    00134 #define TRX_TSTAMP_REG TCNT1
    00135 /*=== SPI access macros ==============================================*/
    00136 #define DDR_SPI  (DDRB)
    00137 #define PORT_SPI (PORTB)
    00138
    00139 #define SPI_MOSI _BV(PB3)
    00140 #define SPI_MISO _BV(PB4)
    00141 #define SPI_SCK  _BV(PB5)
    00142 #define SPI_SS   _BV(PB2)
    00143
    00144 #define SPI_DATA_REG SPDR
    00145
    00146 static inline void SPI_INIT(uint8_t spirate)
    00147 {
    00148     /* first configure SPI Port, then SPCR */
    00149     PORT_SPI |= SPI_SCK | SPI_SS;
    00150     DDR_SPI  |= SPI_MOSI | SPI_SCK | SPI_SS;
    00151     DDR_SPI  &= ~SPI_MISO;
    00152
    00153     SPCR = (_BV(SPE) | _BV(MSTR));
    00154
    00155     SPCR &= ~(_BV(SPR1) | _BV(SPR0) );
    00156     SPSR &= ~_BV(SPI2X);
    00157
    00158     SPCR |= (spirate & 0x03);
    00159     SPSR |= ((spirate >> 2) & 0x01);
    00160
    00161 }
    00162
    00163 #define SPI_SELN_LOW()       uint8_t sreg = SREG; cli(); PORT_SPI &=~SPI_SS
    00164 #define SPI_SELN_HIGH()      PORT_SPI |= SPI_SS; SREG = sreg
    00165 #define SPI_WAITFOR()        do { while((SPSR & _BV(SPIF)) == 0);} while(0)
    00166
    00167 /*=== LED access macros ==============================================*/
    00168 #define LED_PORT      PORTC
    00169 #define LED_DDR       DDRC
    00170 #define LED_MASK      (0x03)
    00171 #define LED_SHIFT     (0)
    00172 #define LED_NUMBER    (2)
    00173 #define LEDS_INVERSE  (1)
    00174
    00175 /*=== KEY access macros ==============================================*/
    00176 #define PORT_KEY      PORTD
    00177 #define PIN_KEY       PIND
    00178 #define DDR_KEY       DDRD
    00179 #define MASK_KEY     (0x0c)
    00180 #define SHIFT_KEY    (2)
    00181 #define INVERSE_KEYS (1)
    00182 #define PULLUP_KEYS  (1)
    00183
    00184 /*=== Host Interface ================================================*/
    00185 #define HIF_TYPE    HIF_UART_0
    00186
    00187
    00188 /*=== TIMER Interface ===============================================*/
    00194 #define HWTMR_PRESCALE  (1)
    00195 #define HWTIMER_TICK    ((1.0*HWTMR_PRESCALE)/F_CPU)
    00196 #define HWTIMER_TICK_NB (0xFFFFUL)
    00197 #define HWTIMER_REG     (TCNT1)
    00198 #define TIMER_TICK      (HWTIMER_TICK_NB * HWTIMER_TICK)
    00199 #define TIMER_POOL_SIZE (4)
    00200 #define TIMER_INIT() \
    00201     do{ \
    00202         TCCR1B |= (_BV(CS10)); \
    00203         TIMSK |= _BV(TOIE1); \
    00204     }while(0)
    00205 # define TIMER_IRQ_vect   TIMER1_OVF_vect
    00206
    00207 /*=== OSCCAL tuning =================================================*/
    00208
    00209 #ifndef TUNED_OSCCAL
    00210 # define TUNED_OSCCAL (0xbf)  /* default is 0xb1, but @2.9V 0xbf is better */
    00211 #endif
    00212 #endif /* BOARD_STK_M8_H */