# board_stb.h

Go to the documentation of this file.

    00001 /* Copyright (c) 2008 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$ */
    00099 #if defined(stb230)
    00100 # define BOARD_TYPE (BOARD_STB230)
    00101 # define BOARD_NAME "stb230"
    00102 # define RADIO_TYPE (RADIO_AT86RF230A)
    00103 #elif defined(stb230b)
    00104 # define BOARD_TYPE (BOARD_STB230B)
    00105 # define BOARD_NAME "stb230b"
    00106 # define RADIO_TYPE (RADIO_AT86RF230B)
    00107 #elif defined(stb231)
    00108 # define BOARD_TYPE (BOARD_STB231)
    00109 # define BOARD_NAME "stb231"
    00110 # define RADIO_TYPE (RADIO_AT86RF231)
    00111 #elif defined(stb212)
    00112 # define BOARD_TYPE (BOARD_STB212)
    00113 # define BOARD_NAME "stb212"
    00114 # define RADIO_TYPE (RADIO_AT86RF212)
    00115 #elif defined(stb232)
    00116 # define BOARD_TYPE (BOARD_STB232)
    00117 # define BOARD_NAME "stb232"
    00118 # define RADIO_TYPE (RADIO_AT86RF232)
    00119 #elif defined(stb233)
    00120 # define BOARD_TYPE (BOARD_STB233)
    00121 # define BOARD_NAME "stb233"
    00122 # define RADIO_TYPE (RADIO_AT86RF233)
    00123 #endif
    00124
    00125 #ifndef BOARD_STB2XX_H
    00126 #define BOARD_STB2XX_H
    00127
    00128 /*=== Compile time parameters ========================================*/
    00129 #ifndef DEFAULT_SPI_RATE
    00130 # define DEFAULT_SPI_RATE  (SPI_RATE_1_2)
    00131 #endif
    00132
    00133 /*=== radio interface definition =====================================*/
    00134 #if BOARD_TYPE == BOARD_STB230 || BOARD_TYPE == BOARD_STB230B
    00135 # include "base_rdk230.h"
    00136 #else
    00137 # include "base_rdk2xx.h"
    00138 #endif
    00139
    00140 /*
    00141  * The IO subsystem of the Sensor Terminal Board is, a little
    00142  * cumbersome to operate.  Besides the LEDs that are operated on an
    00143  * MMIO register and cannot be read back, the FT245 is attached to the
    00144  * external memory bus through a 74VHC245MTC bus driver which is by
    00145  * default enabled to drive the bus (rather than to read it).  Thus,
    00146  * much care must be taken to avoid a bus contention where both, the
    00147  * 74VHC245MTC and the AVR drive the multiplexed address/data bus.
    00148  *
    00149  * We avoid that bus contention by swapping the meaning of the chip
    00150  * select signal for the FT245 and the actual /WR line: both are ORed
    00151  * together, so for the actual effect towards the FT245, it does not
    00152  * matter whether we pulse /WR, or we pulse the correct high address
    00153  * selection.
    00154  */
    00155
    00156 static inline void hif_mmio_init(void)
    00157 {
    00158     DDRC |= 0xc0;               /* xmem A14...A15 */
    00159     PORTC = (PORTC & ~0xc0) | 0x80; /* high addr 0x80 => external
    00160                                      * SRAM */
    00161     PORTG &= ~0x05;             /* PG0: xmem /WR, activate to make the
    00162                                  * 74VHC245MTC not drive the bus
    00163                                  * PG2: xmem ALE; not used but keep
    00164                                  * low all the time */
    00165     PORTG |= 0x02;              /* PG1: xmem /RD, deactivate */
    00166     DDRG |= 0x07;               /* make /RD, /WR, and ALE outputs */
    00167 }
    00168
    00169 static inline void hif_usb_write(uint8_t val)
    00170 {
    00171     DDRA = 0xFF;
    00172     PORTA = val;
    00173     PORTC = (PORTC & ~0xc0);    /* select FT245 -> /WR pulse */
    00174     __asm volatile("nop");
    00175     PORTC = (PORTC & ~0xc0) | 0x80; /* re-select SRAM */
    00176     DDRA = 0;
    00177     PORTA = 0;                  /* avoid pullups */
    00178 }
    00179
    00180 static inline uint8_t hif_usb_read(void)
    00181 {
    00182     PORTG |= 0x01;              /* de-assert /WR */
    00183     PORTC = (PORTC & ~0xc0);    /* select FT245 */
    00184     PORTG &= ~0x02;             /* /RD pulse */
    00185     PORTG |= 0x02;
    00186     __asm volatile("nop");
    00187     uint8_t rv = PINA;
    00188     PORTC = (PORTC & ~0xc0) | 0x80; /* re-select SRAM */
    00189     PORTG &= ~0x01;                 /* re-assert /WR */
    00190
    00191     return rv;
    00192 }
    00193
    00194
    00195 static inline void hif_led_write(uint8_t val)
    00196 {
    00197     PORTG |= 0x01;              /* de-assert /WR */
    00198     DDRA = 0xFF;
    00199     PORTA = val;
    00200     PORTC = (PORTC & ~0xc0) | 0x40; /* select IO address */
    00201     PORTG &= ~0x01;                 /* /WR pulse */
    00202     PORTG |= 0x01;
    00203     __asm volatile("nop");
    00204     PORTC = (PORTC & ~0xc0) | 0x80; /* re-select SRAM */
    00205     DDRA = 0;
    00206     PORTA = 0;                  /* avoid pullups */
    00207     PORTG &= ~0x01;             /* re-assert /WR */
    00208 }
    00209
    00210 static inline uint8_t hif_key_read(void)
    00211 {
    00212     PORTG |= 0x01;              /* de-assert /WR */
    00213     PORTC = (PORTC & ~0xc0) | 0x40; /* select IO address */
    00214     PORTG &= ~0x02;             /* /RD pulse */
    00215     PORTG |= 0x02;
    00216     __asm volatile("nop");
    00217     uint8_t rv = PINA;
    00218     PORTC = (PORTC & ~0xc0) | 0x80; /* re-select SRAM */
    00219     PORTG &= ~0x01;                 /* re-assert /WR */
    00220
    00221     return rv;
    00222 }
    00223
    00224 /*=== LED access macros ==============================================*/
    00225 #if !defined(USE_RCB_LEDS)
    00226 /*=== use LEDs on STB (Memory Mapped) ===*/
    00227
    00228 # define LED_SHADOW    GPIOR2
    00229 # define LED_MASK      (0x03)
    00230 # define LED_SHIFT     (0)
    00231 # define LEDS_INVERSE  (1)
    00232 # define LED_NUMBER    (2)
    00233
    00234 # define LED_INIT()\
    00235         do{\
    00236             hif_mmio_init(); \
    00237             LED_SHADOW = LED_MASK;\
    00238             hif_led_write(LED_SHADOW);        \
    00239         }while(0)
    00240
    00241 # define LED_SET_VALUE(x) \
    00242         do{\
    00243             LED_SHADOW = (LED_SHADOW & ~LED_MASK) | ((~x<<LED_SHIFT) & LED_MASK);\
    00244             hif_led_write(LED_SHADOW);\
    00245         }while(0)
    00246
    00247 # define LED_GET_VALUE()\
    00248         ((~LED_SHADOW & LED_MASK) >> LED_SHIFT)
    00249
    00250 # define LED_SET(ln)\
    00251         do{\
    00252             LED_SHADOW &= ~(_BV(ln+LED_SHIFT) & LED_MASK);\
    00253             hif_led_write(LED_SHADOW);\
    00254         }while(0)
    00255
    00256 # define LED_CLR(ln)\
    00257         do{\
    00258             LED_SHADOW |= (_BV(ln+LED_SHIFT) & LED_MASK);\
    00259             hif_led_write(LED_SHADOW);\
    00260         }while(0)
    00261
    00262 # define LED_VAL(msk,val)\
    00263         do{\
    00264             LED_SHADOW &= ~(LED_MASK|(msk<<LED_SHIFT)); \
    00265             LED_SHADOW |= ~(val & (LED_MASK|msk));\
    00266             hif_led_write(LED_SHADOW);\
    00267         }while(0)
    00268
    00269
    00270 # define LED_TOGGLE(ln)\
    00271         do{\
    00272             LED_SHADOW ^= (_BV(ln+LED_SHIFT) & LED_MASK);\
    00273             hif_led_write(LED_SHADOW);\
    00274         }while(0)
    00275
    00276 #else
    00277 /*=== use LEDs on RCB (IO Mapped) ===*/
    00278 # define LED_PORT      PORTE
    00279 # define LED_DDR       DDRE
    00280 # define LED_MASK      (0x1c)
    00281 # define LED_SHIFT     (2)
    00282 # define LEDS_INVERSE  (1)
    00283 # define LED_NUMBER    (3)
    00284 #endif
    00285 /*=== KEY access macros ==============================================*/
    00286 #define PIN_KEY       (hif_key_read())
    00287 #define MASK_KEY      (0x1)
    00288 #define SHIFT_KEY     (0)
    00289 #define INVERSE_KEYS  (0)
    00290 #define PULLUP_KEYS   (0)
    00291 #define KEY_INIT      hif_mmio_init
    00292
    00293 /*=== Host Interface ================================================*/
    00294 #define HIF_TYPE      (HIF_FT245)
    00295 #define HIF_IO_ENABLE hif_mmio_init
    00296 #define HIF_USB_READ()  hif_usb_read()
    00297 #define HIF_USB_WRITE(x) hif_usb_write(x)
    00298 #define HIF_NO_DATA   (0x0100)
    00299 #define FT245_DDR    DDRE
    00300 #define FT245_PIN    PINE
    00301 #define FT245_TXE    _BV(6)
    00302 #define FT245_RXF    _BV(7)
    00303 #define FT245_INIT() do { \
    00304            FT245_DDR &= ~(FT245_TXE|FT245_RXF);\
    00305         } while(0)
    00306
    00307 #define FT245_TX_IS_BLOCKED()    (0 != (FT245_PIN & FT245_TXE))
    00308 #define FT245_RX_HAS_DATA()      (0 == (FT245_PIN & FT245_RXF))
    00309
    00310 /*=== TIMER Interface ===============================================*/
    00311 #define HWTMR_PRESCALE  (1)
    00312 #define HWTIMER_TICK    ((1.0*HWTMR_PRESCALE)/F_CPU)
    00313 #define HWTIMER_TICK_NB (0xFFFFUL+1)
    00314 #define HWTIMER_REG     (TCNT1)
    00315 #define TIMER_TICK      (HWTIMER_TICK_NB * HWTIMER_TICK)
    00316 #define TIMER_POOL_SIZE     (4)
    00317
    00319 #define TIMER_IRQ_vect   TIMER1_OVF_vect
    00320
    00330 # define TIMER_INIT() \
    00331     do{ \
    00332         TCCR1B |= _BV(CS10); \
    00333         TIMSK1 |= _BV(TOIE1); \
    00334     }while(0)
    00335
    00336 #endif /* BOARD_STB_H*/