2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include "ao_bringup.h"
21 /* Values from SmartRF® Studio for:
23 * Deviation: 20.507812 kHz
24 * Datarate: 38.360596 kBaud
26 * RF Freq: 434.549927 MHz
27 * Channel: 99.975586 kHz
29 * RX filter: 93.75 kHz
33 * For 434.550MHz, the frequency value is:
35 * 434.550e6 / (24e6 / 2**16) = 1186611.2
38 #define FREQ_CONTROL 1186611
41 * For IF freq of 140.62kHz, the IF value is:
43 * 140.62e3 / (24e6 / 2**10) = 6
46 #define IF_FREQ_CONTROL 6
49 * For channel bandwidth of 93.75 kHz, the CHANBW_E and CHANBW_M values are
51 * BW = 24e6 / (8 * (4 + M) * 2 ** E)
60 * For a symbol rate of 38360kBaud, the DRATE_E and DRATE_M values are:
62 * R = (256 + M) * 2** E * 24e6 / 2**28
64 * So M is 163 and E is 10
71 * For a channel deviation of 20.5kHz, the DEVIATION_E and DEVIATION_M values are:
73 * F = 24e6/2**17 * (8 + DEVIATION_M) * 2**DEVIATION_E
75 * So M is 6 and E is 3
82 * For our RDF beacon, set the symbol rate to 2kBaud (for a 1kHz tone),
83 * so the DRATE_E and DRATE_M values are:
87 * To make the tone last for 200ms, we need 2000 * .2 = 400 bits or 50 bytes
91 #define RDF_DRATE_M 94
92 #define RDF_PACKET_LEN 50
95 * RDF deviation should match the normal NFM value of 5kHz
101 #define RDF_DEVIATION_M 6
102 #define RDF_DEVIATION_E 1
104 /* This are from the table for 433MHz */
106 #define RF_POWER_M30_DBM 0x12
107 #define RF_POWER_M20_DBM 0x0e
108 #define RF_POWER_M15_DBM 0x1d
109 #define RF_POWER_M10_DBM 0x34
110 #define RF_POWER_M5_DBM 0x2c
111 #define RF_POWER_0_DBM 0x60
112 #define RF_POWER_5_DBM 0x84
113 #define RF_POWER_7_DBM 0xc8
114 #define RF_POWER_10_DBM 0xc0
116 #define RF_POWER RF_POWER_10_DBM
118 static __code uint8_t radio_setup[] = {
119 RF_PA_TABLE7_OFF, RF_POWER,
120 RF_PA_TABLE6_OFF, RF_POWER,
121 RF_PA_TABLE5_OFF, RF_POWER,
122 RF_PA_TABLE4_OFF, RF_POWER,
123 RF_PA_TABLE3_OFF, RF_POWER,
124 RF_PA_TABLE2_OFF, RF_POWER,
125 RF_PA_TABLE1_OFF, RF_POWER,
126 RF_PA_TABLE0_OFF, RF_POWER,
128 RF_FREQ2_OFF, (FREQ_CONTROL >> 16) & 0xff,
129 RF_FREQ1_OFF, (FREQ_CONTROL >> 8) & 0xff,
130 RF_FREQ0_OFF, (FREQ_CONTROL) & 0xff,
132 RF_FSCTRL1_OFF, (IF_FREQ_CONTROL << RF_FSCTRL1_FREQ_IF_SHIFT),
133 RF_FSCTRL0_OFF, (0 << RF_FSCTRL0_FREQOFF_SHIFT),
135 RF_MDMCFG4_OFF, ((CHANBW_E << RF_MDMCFG4_CHANBW_E_SHIFT) |
136 (CHANBW_M << RF_MDMCFG4_CHANBW_M_SHIFT) |
137 (DRATE_E << RF_MDMCFG4_DRATE_E_SHIFT)),
138 RF_MDMCFG3_OFF, (DRATE_M << RF_MDMCFG3_DRATE_M_SHIFT),
139 RF_MDMCFG2_OFF, (RF_MDMCFG2_DEM_DCFILT_OFF |
140 RF_MDMCFG2_MOD_FORMAT_GFSK |
141 RF_MDMCFG2_SYNC_MODE_15_16_THRES),
142 RF_MDMCFG1_OFF, (RF_MDMCFG1_FEC_EN |
143 RF_MDMCFG1_NUM_PREAMBLE_4 |
144 (2 << RF_MDMCFG1_CHANSPC_E_SHIFT)),
145 RF_MDMCFG0_OFF, (17 << RF_MDMCFG0_CHANSPC_M_SHIFT),
149 RF_DEVIATN_OFF, ((DEVIATION_E << RF_DEVIATN_DEVIATION_E_SHIFT) |
150 (DEVIATION_M << RF_DEVIATN_DEVIATION_M_SHIFT)),
152 /* SmartRF says set LODIV_BUF_CURRENT_TX to 0
153 * And, we're not using power ramping, so use PA_POWER 0
155 RF_FREND0_OFF, ((1 << RF_FREND0_LODIV_BUF_CURRENT_TX_SHIFT) |
156 (0 << RF_FREND0_PA_POWER_SHIFT)),
158 RF_FREND1_OFF, ((1 << RF_FREND1_LNA_CURRENT_SHIFT) |
159 (1 << RF_FREND1_LNA2MIX_CURRENT_SHIFT) |
160 (1 << RF_FREND1_LODIV_BUF_CURRENT_RX_SHIFT) |
161 (2 << RF_FREND1_MIX_CURRENT_SHIFT)),
172 /* default sync values */
176 /* max packet length */
179 RF_PKTCTRL1_OFF, ((1 << PKTCTRL1_PQT_SHIFT)|
180 PKTCTRL1_APPEND_STATUS|
181 PKTCTRL1_ADR_CHK_NONE),
182 RF_PKTCTRL0_OFF, (RF_PKTCTRL0_WHITE_DATA|
183 RF_PKTCTRL0_PKT_FORMAT_NORMAL|
185 RF_PKTCTRL0_LENGTH_CONFIG_FIXED),
187 RF_MCSM2_OFF, (RF_MCSM2_RX_TIME_END_OF_PACKET),
188 RF_MCSM1_OFF, (RF_MCSM1_CCA_MODE_RSSI_BELOW_UNLESS_RECEIVING|
189 RF_MCSM1_RXOFF_MODE_IDLE|
190 RF_MCSM1_TXOFF_MODE_IDLE),
191 RF_MCSM0_OFF, (RF_MCSM0_FS_AUTOCAL_FROM_IDLE|
193 RF_MCSM0_CLOSE_IN_RX_0DB),
194 RF_FOCCFG_OFF, (RF_FOCCFG_FOC_PRE_K_3K,
195 RF_FOCCFG_FOC_POST_K_PRE_K,
196 RF_FOCCFG_FOC_LIMIT_BW_OVER_4),
197 RF_BSCFG_OFF, (RF_BSCFG_BS_PRE_K_2K|
198 RF_BSCFG_BS_PRE_KP_3KP|
199 RF_BSCFG_BS_POST_KI_PRE_KI|
200 RF_BSCFG_BS_POST_KP_PRE_KP|
201 RF_BSCFG_BS_LIMIT_0),
202 RF_AGCCTRL2_OFF, 0x43,
203 RF_AGCCTRL1_OFF, 0x40,
204 RF_AGCCTRL0_OFF, 0x91,
210 RF_MDMCFG4_OFF, ((CHANBW_E << RF_MDMCFG4_CHANBW_E_SHIFT) |
211 (CHANBW_M << RF_MDMCFG4_CHANBW_M_SHIFT) |
212 (DRATE_E << RF_MDMCFG4_DRATE_E_SHIFT)),
213 RF_MDMCFG3_OFF, (DRATE_M << RF_MDMCFG3_DRATE_M_SHIFT),
214 RF_MDMCFG2_OFF, (RF_MDMCFG2_DEM_DCFILT_OFF |
215 RF_MDMCFG2_MOD_FORMAT_GFSK |
216 RF_MDMCFG2_SYNC_MODE_15_16_THRES),
217 RF_MDMCFG1_OFF, (RF_MDMCFG1_FEC_EN |
218 RF_MDMCFG1_NUM_PREAMBLE_4 |
219 (2 << RF_MDMCFG1_CHANSPC_E_SHIFT)),
221 RF_DEVIATN_OFF, ((DEVIATION_E << RF_DEVIATN_DEVIATION_E_SHIFT) |
222 (DEVIATION_M << RF_DEVIATN_DEVIATION_M_SHIFT)),
224 /* max packet length */
226 RF_PKTCTRL1_OFF, ((1 << PKTCTRL1_PQT_SHIFT)|
227 PKTCTRL1_APPEND_STATUS|
228 PKTCTRL1_ADR_CHK_NONE),
229 RF_PKTCTRL0_OFF, (RF_PKTCTRL0_WHITE_DATA|
230 RF_PKTCTRL0_PKT_FORMAT_NORMAL|
232 RF_PKTCTRL0_LENGTH_CONFIG_FIXED),
238 if (RF_MARCSTATE != RF_MARCSTATE_IDLE)
243 } while (RF_MARCSTATE != RF_MARCSTATE_IDLE);
248 ao_radio_init(void) {
250 for (i = 0; i < sizeof (radio_setup); i += 2)
251 RF[radio_setup[i]] = radio_setup[i+1];