1b3f67caa6b8a36370bf98f2c5450931fdb192ef
[aversive.git] / projects / microb2010 / tests / beacon_tsop / board2006.h
1 /*  
2  *  Copyright Droids Corporation (2009)
3  *  Olivier Matz <zer0@droids-corp.org>
4  * 
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.
9  *
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.
14  *
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
18  *
19  *  Revision : $Id: main.c,v 1.8 2009-05-02 10:08:09 zer0 Exp $
20  *
21  */
22
23 /* LEDs */
24
25 #define LED_TOGGLE(port, bit) do {              \
26                 if (port & _BV(bit))            \
27                         port &= ~_BV(bit);      \
28                 else                            \
29                         port |= _BV(bit);       \
30         } while(0)
31
32 #define LED1_PORT PORTE
33 #define LED1_DDR  DDRE
34 #define LED1_BIT  2
35 #define LED2_PORT PORTE
36 #define LED2_DDR  DDRE
37 #define LED2_BIT  3
38 #define LED3_PORT PORTB
39 #define LED3_DDR  DDRB
40 #define LED3_BIT  3
41 #define LED_DDR_INIT()  do {                                            \
42                 LED1_DDR |= _BV(LED1_BIT);                              \
43                 LED2_DDR |= _BV(LED2_BIT);                              \
44                 LED3_DDR |= _BV(LED3_BIT);                              \
45         } while(0)
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)
55
56 /* TSOP */
57
58 #define EICRx_TSOP EICRB /* EICRA is not ok, cannot do intr on any edge */
59
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))
65
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))
71
72 #define TSOP_FREQ_455_MHZ 0.455
73 #define N_PERIODS_455   10.
74 #define TSOP_FREQ_38_MHZ 0.038
75 #define N_PERIODS_38   15.
76 #define TSOP_FREQ_30_MHZ 0.030
77 #define N_PERIODS_30   15.
78 #define TSOP_FREQ_56_MHZ 0.056
79 #define N_PERIODS_56   15.
80
81 /* TSOP STATIC */
82
83 #define TSOP_STA_PERIOD_US (1./TSOP_FREQ_38_MHZ)
84 #define TSOP_STA_N_PERIODS  (N_PERIODS_38)
85
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)
88
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))
91
92 #define TSOP_STA_FRAME_LEN 16
93 #define TSOP_STA_FRAME_MASK ((1UL << TSOP_STA_FRAME_LEN) - 1)
94
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
99
100 #define TSOP_STA_BEACON_ID0 0x03
101 #define TSOP_STA_BEACON_ID1 0x05
102
103 /* TSOP OPP */
104
105 #define TSOP_OPP_PERIOD_US (1./TSOP_FREQ_455_MHZ)
106 #define TSOP_OPP_N_PERIODS  (N_PERIODS_455)
107
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)
110
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))
113
114 #define TSOP_OPP_FRAME_LEN 16
115 #define TSOP_OPP_FRAME_MASK ((1UL << TSOP_OPP_FRAME_LEN) - 1)
116
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
121
122 #define TSOP_OPP_BEACON_ID 0x01