2 * Copyright Droids Corporation (2009)
3 * Olivier Matz <zer0@droids-corp.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Revision : $Id: main.c,v 1.8 2009-05-02 10:08:09 zer0 Exp $
25 #define LED_TOGGLE(port, bit) do { \
26 if (port & _BV(bit)) \
32 #define LED_PORT PORTA
40 #define LED_DDR_INIT() do { \
41 LED_DDR |= (_BV(LED1_BIT) | _BV(LED2_BIT) | _BV(LED3_BIT) | \
42 _BV(LED4_BIT) | _BV(LED5_BIT) | _BV(LED6_BIT)); \
44 #define LED1_ON() sbi(LED_PORT, LED1_BIT)
45 #define LED1_OFF() cbi(LED_PORT, LED1_BIT)
46 #define LED1_TOGGLE() LED_TOGGLE(LED_PORT, LED1_BIT)
47 #define LED2_ON() sbi(LED_PORT, LED2_BIT)
48 #define LED2_OFF() cbi(LED_PORT, LED2_BIT)
49 #define LED2_TOGGLE() LED_TOGGLE(LED_PORT, LED2_BIT)
50 #define LED3_ON() sbi(LED_PORT, LED3_BIT)
51 #define LED3_OFF() cbi(LED_PORT, LED3_BIT)
52 #define LED3_TOGGLE() LED_TOGGLE(LED_PORT, LED3_BIT)
53 #define LED4_ON() sbi(LED_PORT, LED4_BIT)
54 #define LED4_OFF() cbi(LED_PORT, LED4_BIT)
55 #define LED4_TOGGLE() LED_TOGGLE(LED_PORT, LED4_BIT)
56 #define LED5_ON() sbi(LED_PORT, LED5_BIT)
57 #define LED5_OFF() cbi(LED_PORT, LED5_BIT)
58 #define LED5_TOGGLE() LED_TOGGLE(LED_PORT, LED5_BIT)
59 #define LED6_ON() sbi(LED_PORT, LED6_BIT)
60 #define LED6_OFF() cbi(LED_PORT, LED6_BIT)
61 #define LED6_TOGGLE() LED_TOGGLE(LED_PORT, LED6_BIT)
65 #define EICRx_TSOP EICRB /* EICRA is not ok, cannot do intr on any edge */
67 #define INTx_TSOP_OPP INT6
68 #define ISCx0_TSOP_OPP ISC60
69 #define ISCx1_TSOP_OPP ISC61
70 #define SIG_TSOP_OPP SIG_INTERRUPT6
71 #define TSOP_OPP_READ() (!(PINE & 0x40))
73 #define INTx_TSOP_STA INT5
74 #define ISCx0_TSOP_STA ISC50
75 #define ISCx1_TSOP_STA ISC51
76 #define SIG_TSOP_STA SIG_INTERRUPT5
77 #define TSOP_STA_READ() (!(PINE & 0x20))
79 #define TSOP_FREQ_455_MHZ 0.455
80 #define N_PERIODS_455 15.
81 #define TSOP_FREQ_38_MHZ 0.038
82 #define N_PERIODS_38 15.
83 #define TSOP_FREQ_30_MHZ 0.030
84 #define N_PERIODS_30 15.
85 #define TSOP_FREQ_56_MHZ 0.056
86 #define N_PERIODS_56 15.
90 #define TSOP_STA_PERIOD_US (1./TSOP_FREQ_455_MHZ)
91 #define TSOP_STA_N_PERIODS (N_PERIODS_455)
93 #define TSOP_STA_TIME_SHORT_US (1.5 * TSOP_STA_N_PERIODS * TSOP_STA_PERIOD_US)
94 #define TSOP_STA_TIME_LONG_US (2.5 * TSOP_STA_N_PERIODS * TSOP_STA_PERIOD_US)
96 #define TSOP_STA_TIME_SHORT ((uint16_t)(TSOP_STA_TIME_SHORT_US/4))
97 #define TSOP_STA_TIME_LONG ((uint16_t)(TSOP_STA_TIME_LONG_US/4))
99 #define TSOP_STA_FRAME_LEN 16
100 #define TSOP_STA_FRAME_MASK ((1UL << TSOP_STA_FRAME_LEN) - 1)
102 #define TSOP_STA_BEACON_ID_MASK 0x7
103 #define TSOP_STA_BEACON_ID_SHIFT 0
104 #define TSOP_STA_FRAME_DATA_MASK 0xFF8
105 #define TSOP_STA_FRAME_DATA_SHIFT 3
107 #define TSOP_STA_BEACON_ID0 0x03
108 #define TSOP_STA_BEACON_ID1 0x05
112 #define TSOP_OPP_PERIOD_US (1./TSOP_FREQ_455_MHZ)
113 #define TSOP_OPP_N_PERIODS (N_PERIODS_455)
115 #define TSOP_OPP_TIME_SHORT_US (1.5 * TSOP_OPP_N_PERIODS * TSOP_OPP_PERIOD_US)
116 #define TSOP_OPP_TIME_LONG_US (2.5 * TSOP_OPP_N_PERIODS * TSOP_OPP_PERIOD_US)
118 #define TSOP_OPP_TIME_SHORT ((uint16_t)(TSOP_OPP_TIME_SHORT_US/4))
119 #define TSOP_OPP_TIME_LONG ((uint16_t)(TSOP_OPP_TIME_LONG_US/4))
121 #define TSOP_OPP_FRAME_LEN 16
122 #define TSOP_OPP_FRAME_MASK ((1UL << TSOP_OPP_FRAME_LEN) - 1)
124 #define TSOP_OPP_BEACON_ID_MASK 0x7
125 #define TSOP_OPP_BEACON_ID_SHIFT 0
126 #define TSOP_OPP_FRAME_DATA_MASK 0xFF8
127 #define TSOP_OPP_FRAME_DATA_SHIFT 3
129 #define TSOP_OPP_BEACON_ID 0x01