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 LED1_PORT PORTE
35 #define LED2_PORT PORTE
38 #define LED3_PORT PORTB
41 #define LED_DDR_INIT() do { \
42 LED1_DDR |= _BV(LED1_BIT); \
43 LED2_DDR |= _BV(LED2_BIT); \
44 LED3_DDR |= _BV(LED3_BIT); \
46 #define LED1_ON() sbi(LED1_PORT, LED1_BIT)
47 #define LED1_OFF() cbi(LED1_PORT, LED1_BIT)
48 #define LED1_TOGGLE() LED_TOGGLE(LED_PORT, LED1_BIT)
49 #define LED2_ON() sbi(LED2_PORT, LED2_BIT)
50 #define LED2_OFF() cbi(LED2_PORT, LED2_BIT)
51 #define LED2_TOGGLE() LED_TOGGLE(LED2_PORT, LED2_BIT)
52 #define LED3_ON() sbi(LED3_PORT, LED3_BIT)
53 #define LED3_OFF() cbi(LED3_PORT, LED3_BIT)
54 #define LED3_TOGGLE() LED_TOGGLE(LED3_PORT, LED3_BIT)
58 #define EICRx_TSOP EICRB /* EICRA is not ok, cannot do intr on any edge */
60 #define INTx_TSOP_OPP INT6
61 #define ISCx0_TSOP_OPP ISC60
62 #define ISCx1_TSOP_OPP ISC61
63 #define SIG_TSOP_OPP SIG_INTERRUPT6
64 #define TSOP_OPP_READ() (!(PINE & 0x40))
66 #define INTx_TSOP_STA INT7
67 #define ISCx0_TSOP_STA ISC70
68 #define ISCx1_TSOP_STA ISC71
69 #define SIG_TSOP_STA SIG_INTERRUPT7
70 #define TSOP_STA_READ() (!(PINE & 0x80))
72 #define TSOP_FREQ_455_KHZ 0.455
73 #define N_PERIODS_455 10.
74 #define TSOP_FREQ_38_KHZ 0.038
75 #define N_PERIODS_38 15.
76 #define TSOP_FREQ_30_KHZ 0.030
77 #define N_PERIODS_30 15.
78 #define TSOP_FREQ_56_KHZ 0.056
79 #define N_PERIODS_56 15.
83 #define TSOP_STA_PERIOD_US (1./TSOP_FREQ_38_KHZ)
84 #define TSOP_STA_N_PERIODS (N_PERIODS_38)
86 #define TSOP_STA_TIME_SHORT_US (1.5 * TSOP_STA_N_PERIODS * TSOP_STA_PERIOD_US)
87 #define TSOP_STA_TIME_LONG_US (2.5 * TSOP_STA_N_PERIODS * TSOP_STA_PERIOD_US)
89 #define TSOP_STA_TIME_SHORT ((uint16_t)(TSOP_STA_TIME_SHORT_US/4))
90 #define TSOP_STA_TIME_LONG ((uint16_t)(TSOP_STA_TIME_LONG_US/4))
92 #define TSOP_STA_FRAME_LEN 16
93 #define TSOP_STA_FRAME_MASK ((1UL << TSOP_STA_FRAME_LEN) - 1)
95 #define TSOP_STA_BEACON_ID_MASK 0x7
96 #define TSOP_STA_BEACON_ID_SHIFT 0
97 #define TSOP_STA_FRAME_DATA_MASK 0xFF8
98 #define TSOP_STA_FRAME_DATA_SHIFT 3
100 #define TSOP_STA_BEACON_ID0 0x03
101 #define TSOP_STA_BEACON_ID1 0x05
105 #define TSOP_OPP_PERIOD_US (1./TSOP_FREQ_455_KHZ)
106 #define TSOP_OPP_N_PERIODS (N_PERIODS_455)
108 #define TSOP_OPP_TIME_SHORT_US (1.5 * TSOP_OPP_N_PERIODS * TSOP_OPP_PERIOD_US)
109 #define TSOP_OPP_TIME_LONG_US (2.5 * TSOP_OPP_N_PERIODS * TSOP_OPP_PERIOD_US)
111 #define TSOP_OPP_TIME_SHORT ((uint16_t)(TSOP_OPP_TIME_SHORT_US/4))
112 #define TSOP_OPP_TIME_LONG ((uint16_t)(TSOP_OPP_TIME_LONG_US/4))
114 #define TSOP_OPP_FRAME_LEN 16
115 #define TSOP_OPP_FRAME_MASK ((1UL << TSOP_OPP_FRAME_LEN) - 1)
117 #define TSOP_OPP_BEACON_ID_MASK 0x7
118 #define TSOP_OPP_BEACON_ID_SHIFT 0
119 #define TSOP_OPP_FRAME_DATA_MASK 0xFF8
120 #define TSOP_OPP_FRAME_DATA_SHIFT 3
122 #define TSOP_OPP_BEACON_ID 0x01