board_airdmx.h
Go to the documentation of this file.

    00001 /* Copyright (c) 2013 Axel Wachtler, Daniel Thiele, Charles Goyard
    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$ */
    00060 #ifndef BOARD_AIRDMX_H
    00061 #define BOARD_AIRDMX_H
    00062
    00063 #if defined(dracula)
    00064 # define BOARD_TYPE BOARD_DRACULA
    00065 # define BOARD_NAME "dracula"
    00066 #define RADIO_TYPE (RADIO_ATMEGA128RFA1_D)
    00067 #elif defined(bat)
    00068 # define BOARD_TYPE BOARD_BAT
    00069 # define BOARD_NAME "bat"
    00070 #define RADIO_TYPE (RADIO_ATMEGA128RFA1_C)
    00071 #else
    00072 #error "Undefined board"
    00073 #endif
    00074 /*=== Compile time parameters ========================================*/
    00075
    00076 /*=== Hardware Components ============================================*/
    00077
    00079 #define TRX_TSTAMP_REG TCNT1
    00080 #if BOARD_TYPE == BOARD_DRACULA || \
    00081     BOARD_TYPE == BOARD_BAT
    00082 # define LED_PORT      PORTG
    00083 # define LED_DDR       DDRG
    00084 # define LED_MASK      (0x06)
    00085 # define LED_SHIFT     (1)
    00086 # define LEDS_INVERSE  (0)
    00087 # define LED_NUMBER    (2)
    00088 #endif
    00089
    00090 #define NO_KEYS        (1)
    00091
    00092 #if defined(dracula)
    00093 #define UNUSED_PINS_INIT() do{}while(0)
    00094 #elif defined(bat)
    00095 #define UNUSED_PINS_INIT() do{      \
    00096     DDRD &= ~0xFC;  \
    00097     PORTD |= 0xFC;  \
    00098     DDRE &= ~0xF0;  \
    00099     PORTE |= 0xF0;  \
    00100     DDRG &= ~0x10;  \
    00101     PORTG |= 0x10;  \
    00102 }while(0)
    00103 #else
    00104 #error "Undefined board"
    00105 #endif
    00106
    00107 #define DMX_DRIVER_INIT()       do{ PORTE &= ~(1<<PE2); DDRE |= (1<<PE2); }while(0)
    00108 #define DMX_DRIVER_TX_ENABLE()  do{ PORTE |= (1<<PE2);  }while(0)
    00109 #define DMX_DRIVER_TX_DISABLE() do{ PORTE &= ~(1<<PE2); }while(0)
    00110
    00111 #define DMX_ADDR_MASK_B (0xEF)
    00112 #define DMX_ADDR_MASK_D (0x03)
    00113
    00114 /*
    00115  * \brief DIP-switch 9-bit
    00116  *
    00117  */
    00118 static inline uint16_t dmx_get_address(void)
    00119 {
    00120     uint16_t rv = 0;
    00121     uint8_t tmppd, tmppb;
    00122     // on 22C00 tmp = pd0 pd1 pb3 pb2 pb1 pb0 pb4 pb5 pb6 pb7
    00123     //                sw9 sw8 sw7 sw6 sw5 sw4 sw3 sw2 sw1 who
    00124
    00125     // that is:       pd1 pd0 pb7 pb6 pb5 pb4 pb3 pb2 pb1 pb0
    00126     //                sw8 sw9 who sw1 sw2 sw3 sw7 sw6 sw5 sw4
    00127
    00128     /* Address decoding */
    00129     DDRB &= ~(DMX_ADDR_MASK_B);
    00130     DDRD &= ~(DMX_ADDR_MASK_D);
    00131     PORTB |= (DMX_ADDR_MASK_B); /* enable pullups */
    00132     PORTD |= (DMX_ADDR_MASK_D); /* enable pullups */
    00133     _delay_ms(10); /* charge pins */
    00134
    00135     tmppb = PINB;
    00136     tmppd = PIND;
    00137     //                                __w______987654321
    00138     rv  |= (tmppb & (1 << PB0)) ? 0 : 0b0000000001000000;
    00139     rv  |= (tmppb & (1 << PB1)) ? 0 : 0b0000000000100000;
    00140     rv  |= (tmppb & (1 << PB2)) ? 0 : 0b0000000000010000;
    00141     rv  |= (tmppb & (1 << PB3)) ? 0 : 0b0000000000001000;
    00142     rv  |= (tmppb & (1 << PB4)) ? 0 : 0b0000000000000100;
    00143     rv  |= (tmppb & (1 << PB5)) ? 0 : 0b0000000000000010;
    00144     rv  |= (tmppb & (1 << PB6)) ? 0 : 0b0000000000000001;
    00145     rv  |= (tmppd & (1 << PD0)) ? 0 : 0b0000000100000000;
    00146     rv  |= (tmppd & (1 << PD1)) ? 0 : 0b0000000010000000;
    00147
    00148     return rv;
    00149 }
    00150
    00151 /*=== Host Interface ================================================*/
    00152 #if BOARD_TYPE == BOARD_DRACULA || \
    00153     BOARD_TYPE == BOARD_BAT
    00154 # define HIF_TYPE    HIF_UART_1
    00155 #endif
    00156
    00157 #define TRX_RESET_LOW()   do { TRXPR &= ~_BV(TRXRST); } while (0)
    00158 #define TRX_RESET_HIGH()  do { TRXPR |= _BV(TRXRST); } while (0)
    00159 #define TRX_SLPTR_LOW()   do { TRXPR &= ~_BV(SLPTR); } while (0)
    00160 #define TRX_SLPTR_HIGH()  do { TRXPR |= _BV(SLPTR); } while (0)
    00161
    00162 /*=== TIMER Interface ===============================================*/
    00163 #define HWTMR_PRESCALE  (1)
    00164 #define HWTIMER_TICK    ((1.0*HWTMR_PRESCALE)/F_CPU)
    00165 #define HWTIMER_TICK_NB (0xFFFFUL)
    00166 #define HWTIMER_REG     (TCNT1)
    00167 #define TIMER_TICK      (HWTIMER_TICK_NB * HWTIMER_TICK)
    00168 #define TIMER_POOL_SIZE (4)
    00169 #define TIMER_INIT() \
    00170     do{ \
    00171         TCCR1B |= (_BV(CS10)); \
    00172         TIMSK1 |= _BV(TOIE1); \
    00173     }while(0)
    00174 #define TIMER_IRQ_vect   TIMER1_OVF_vect
    00175
    00176 #endif /* BOARD_AIRDMX_H */