Contiki 2.5
cc1020-internal.h
1 #ifndef CC1020_INTERNAL_H
2 #define CC1020_INTERNAL_H
3 
4 #include <signal.h>
5 
6 #define CC1020_MAIN 0x00
7 #define CC1020_INTERFACE 0x01
8 #define CC1020_RESET 0x02
9 #define CC1020_SEQUENCING 0x03
10 #define CC1020_FREQ_2A 0x04
11 #define CC1020_FREQ_1A 0x05
12 #define CC1020_FREQ_0A 0x06
13 #define CC1020_CLOCK_A 0x07
14 #define CC1020_FREQ_2B 0x08
15 #define CC1020_FREQ_1B 0x09
16 #define CC1020_FREQ_0B 0x0A
17 #define CC1020_CLOCK_B 0x0B
18 #define CC1020_VCO 0x0C
19 #define CC1020_MODEM 0x0D
20 #define CC1020_DEVIATION 0x0E
21 #define CC1020_AFC_CONTROL 0x0F
22 #define CC1020_FILTER 0x10
23 #define CC1020_VGA1 0x11
24 #define CC1020_VGA2 0x12
25 #define CC1020_VGA3 0x13
26 #define CC1020_VGA4 0x14
27 #define CC1020_LOCK 0x15
28 #define CC1020_FRONTEND 0x16
29 #define CC1020_ANALOG 0x17
30 #define CC1020_BUFF_SWING 0x18
31 #define CC1020_BUFF_CURRENT 0x19
32 #define CC1020_PLL_BW 0x1A
33 #define CC1020_CALIBRATE 0x1B
34 #define CC1020_PA_POWER 0x1C
35 #define CC1020_MATCH 0x1D
36 #define CC1020_PHASE_COMP 0x1E
37 #define CC1020_GAIN_COMP 0x1F
38 #define CC1020_POWERDOWN 0x20
39 #define CC1020_TEST1 0x21
40 #define CC1020_TEST2 0x22
41 #define CC1020_TEST3 0x23
42 #define CC1020_TEST4 0x24
43 #define CC1020_TEST5 0x25
44 #define CC1020_TEST6 0x26
45 #define CC1020_TEST7 0x27
46 #define CC1020_STATUS 0x40
47 #define CC1020_RESET_DONE 0x41
48 #define CC1020_RSS 0x42
49 #define CC1020_AFC 0x43
50 #define CC1020_GAUSS_FILTER 0x44
51 #define CC1020_STATUS1 0x45
52 #define CC1020_STATUS2 0x46
53 #define CC1020_STATUS3 0x47
54 #define CC1020_STATUS4 0x48
55 #define CC1020_STATUS5 0x49
56 #define CC1020_STATUS6 0x4A
57 #define CC1020_STATUS7 0x4B
58 
59 /* Flags for the MAIN register. */
60 #define RESET_N 1
61 #define BIAS_PD (1<<1)
62 #define XOSC_PD (1<<2)
63 #define FS_PD (1<<3)
64 #define PD_MODE_1 (1<<4)
65 #define PD_MODE_2 (1<<5)
66 #define F_REG (1<<6)
67 #define RXTX (1<<7)
68 
69 /* In power up mode, the MAIN register modifies some flags to the following. */
70 #define SEQ_PD (1<<1)
71 #define SEQ_CAL_1 (1<<2)
72 #define SEQ_CAL_2 (1<<3)
73 
74 // For CC1020_STATUS
75 #define CARRIER_SENSE 0x08
76 #define LOCK_CONTINUOUS 0x10
77 #define LOCK_INSTANT 0x20
78 #define SEQ_ERROR 0x40
79 #define CAL_COMPLETE 0x80
80 
81 #define PA_POWER 0x0F // initial default for output power
82 #define LOCK_NOK 0x00
83 #define LOCK_OK 0x01
84 #define LOCK_RECAL_OK 0x02
85 #define CAL_TIMEOUT 0x7FFE
86 #define LOCK_TIMEOUT 0x7FFE
87 #define RESET_TIMEOUT 0x7FFE
88 #define TX_CURRENT 0x87
89 #define RX_CURRENT 0x86
90 
91 // CC1020 driver configuration
92 
93 // PDI (Data in) is on P21
94 #define PDO (P2IN & 0x01)
95 
96 // PSEL is on P30 and low active
97 #define PSEL_ON do { P3OUT &= ~0x01; } while(0)
98 #define PSEL_OFF do { P3OUT |= 0x01; } while(0)
99 #define PCLK_HIGH do { P2OUT |= 0x08; } while(0)
100 #define PCLK_LOW do { P2OUT &= ~0x08; } while(0)
101 
102 // PDO (Data out) is on P22
103 #define PDI_HIGH do { P2OUT |= 0x02; } while(0)
104 
105 #define PDI_LOW do { P2OUT &= ~0x02; } while(0)
106 
107 // Enable power for LNA (P24, low-active)
108 #define LNA_POWER_ON() do { P2OUT &= ~0x10; } while(0)
109 
110 #define LNA_POWER_OFF() do { P2OUT |= 0x10; } while(0)
111 
112 #define CC_LOCK (P2IN & 0x04)
113 
114 #define DISABLE_RX_IRQ() \
115  do { IE1 &= ~(URXIE0); } while(0)
116 
117 #define ENABLE_RX_IRQ() \
118  do { IFG1 &= ~URXIFG0; IE1 |= URXIE0; } while(0)
119 
120 #define ACK_TIMEOUT_115 4 // In RADIO_STROKE ticks
121 #define ACK_TIMEOUT_19 16
122 
123 #define MHZ_869525 1
124 
125 const uint8_t cc1020_config_19200[41] = {
126  0x01, // 0x00, MAIN
127  0x0F, // 0x01, INTERFACE
128  0xFF, // 0x02, RESET
129  0x8F, // 0x03, SEQUENCING
130  // 869.525 at 50kHz
131  0x3A, // 0x04, FREQ_2A
132  0x32, // 0x05, FREQ_1A
133  0x97, // 0x06, FREQ_0A // 19200
134  0x38, // 0x07, CLOCK_A // 19200
135  0x3A, // 0x08, FREQ_2B
136  0x37, // 0x09, FREQ_1B
137  0xEB, // 0x0A, FREQ_0B // 19200
138  0x38, // 0x0B, CLOCK_B // 19200
139  0x44, // 0x0C, VCO 44
140  0x51, // 0x0D, MODEM Manchester
141  0x2B, // 0x0E, DEVIATION // FSK
142  0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
143  0x25, // 0x10, FILTER Bandwith 51.2 kHz i.e. channel spacing 100kHz
144  0x61, // 0x11, VGA1
145  0x55, // 0x12, VGA2
146  0x2D, // 0x13, VGA3
147  0x37, // 0x14, VGA4 // 0x29, VGA4 ADJUSTED CS to 23!
148  0x40, // 0x15, LOCK is Carrier SENSE
149  0x76, // 0x16, FRONTEND
150  0x87, // 0x17, ANALOG, RX=86/TX=87
151  0x10, // 0x18, BUFF_SWING
152  0x25, // 0x19, BUFF_CURRENT
153  0xAE, // 0x1A, PLL_BW
154  0x34, // 0x1B, CALIBRATE
155  PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
156  0xF0, // 0x1D, MATCH
157  0x00, // 0x1E, PHASE_COMP
158  0x00, // 0x1F, GAIN_COMP
159  0x00, // 0x20, POWERDOWN
160  0x4d, // 0x4d, // 0x21,
161  0x10, // 0x10, // 0x22,
162  0x06, // 0x06, // 0x23,
163  0x00, // 0x00, // 0x24,
164  0x40, // 0x40, // 0x25,
165  0x00, // 0x00, // 0x26,
166  0x00, // 0x00, // 0x27,
167  // Not in real config of chipCon from here!!!
168  ACK_TIMEOUT_19
169 };
170 
171 const uint8_t cc1020_config_115200[41] = {
172  0x01, // 0x00, MAIN
173  0x0F, // 0x01, INTERFACE
174  0xFF, // 0x02, RESET
175  0x8F, // 0x03, SEQUENCING
176  // 869.525 at 200kHz
177  0x3A, // 0x04, FREQ_2A
178  0x32, // 0x05, FREQ_1A
179  0x97, // 0x06, FREQ_0A // 19200
180  0x29, // 0x07, CLOCK_A // 19200
181  0x3A, // 0x08, FREQ_2B
182  0x37, // 0x09, FREQ_1B
183  0xEB, // 0x0A, FREQ_0B // 19200
184  0x29, // 0x0B, CLOCK_B // 19200
185  0x44, // 0x0C, VCO 44
186  0x51, // 0x0D, MODEM Manchester
187  0x58, // 0x0E, DEVIATION // FSK
188  0x4C, // 0x0F, AFC_CONTROL Ruetten 0xCC
189  0x80, // 0x10, FILTER Bandwith 307.2kHz, i.e. channel spacing 500 kHz
190  0x61, // 0x11, VGA1
191  0x57, // 0x12, VGA2
192  0x30, // 0x13, VGA3
193  0x35, // 0x14, VGA4
194  0x20, // 0x15, LOCK is Carrier SENSE
195  0x76, // 0x16, FRONTEND
196  0x87, // 0x17, ANALOG, RX=86/TX=87
197  0x10, // 0x18, BUFF_SWING
198  0x25, // 0x19, BUFF_CURRENT
199  0xAE, // 0x1A, PLL_BW
200  0x34, // 0x1B, CALIBRATE
201  PA_POWER, // 0x1C, PA_POWER AN025 = 0xA0
202  0xF0, // 0x1D, MATCH
203  0x00, // 0x1E, PHASE_COMP
204  0x00, // 0x1F, GAIN_COMP
205  0x00, // 0x20, POWERDOWN
206  0x4d, // 0x21,
207  0x10, // 0x22,
208  0x06, // 0x23,
209  0x00, // 0x24,
210  0x40, // 0x25,
211  0x00, // 0x26,
212  0x00, // 0x27,
213  // Not in real config of chipCon from here!!!
214  ACK_TIMEOUT_115
215 };
216 
217 /// cc1020 state
218 enum cc1020_state {
219  CC1020_OFF = 0,
220  CC1020_RX = 0x01,
221  CC1020_TX = 0x02,
222 
223  CC1020_RX_SEARCHING = 0x10, // searching for preamble + sync word
224  CC1020_RX_RECEIVING = 0x20, // receiving bytes
225  CC1020_RX_PROCESSING = 0x40, // processing data in buffer
226 
227  CC1020_OP_STATE = 0x73,
228 
229  CC1020_TURN_OFF = 0x80,
230 };
231 
232 #define CC1020_SET_OPSTATE(opstate) cc1020_state = ((cc1020_state & ~CC1020_OP_STATE) | (opstate))
233 
234 /******************************************************************************
235  * @name Packet specification
236  * @{
237  */
238 
239 // header: number of bytes in packet including header
240 struct cc1020_header {
241  uint8_t pad;
242  uint8_t length;
243 } __attribute__((packed));
244 
245 
246 #define CC1020_BUFFERSIZE 128
247 
248 
249 #define PREAMBLE_SIZE 6
250 #define PREAMBLE 0xAA
251 
252 #define SYNCWORD_SIZE 2
253 #define HDR_SIZE (sizeof (struct cc1020_header))
254 
255 #define CRC_SIZE 2
256 
257 #define TAIL_SIZE 2
258 #define TAIL 0xFA
259 
260 
261 ///@}
262 
263 #endif /* CC1020_INTERNAL_H */