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

This documentation for µracoli was generated on Wed Feb 2 2011 by  doxygen 1.7.1