update credits
[librepilot.git] / flight / pios / inc / pios_openlrs_priv.h
blob46458e50fc624008255167fe079d13506dbe2309
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
4 * @{
5 * @addtogroup PIOS_RFM22B Radio Functions
6 * @brief PIOS OpenLRS interface for for the RFM22B radio
7 * @{
9 * @file pios_openlrs_priv.h
10 * @author Tau Labs, http://taulabs.org, Copyright (C) 2015
11 * @author dRonin, http://dronin.org Copyright (C) 2015
12 * @brief Implements an OpenLRS driver for the RFM22B
13 * @see The GNU Public License (GPL) Version 3
15 *****************************************************************************/
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifndef PIOS_OPENLRS_PRIV_H
33 #define PIOS_OPENLRS_PRIV_H
35 #include "pios_openlrs.h"
37 #define OPENLRSNG_VERSION 0x0382
39 #define MAXHOPS 24
40 #define OPENLRS_PPM_NUM_CHANNELS 16
42 // Factory setting values, modify via the CLI
44 // ####### RADIOLINK RF POWER (beacon is always 100/13/1.3mW) #######
45 // 7 == 100mW (or 1000mW with M3)
46 // 6 == 50mW (use this when using booster amp), (800mW with M3)
47 // 5 == 25mW
48 // 4 == 13mW
49 // 3 == 6mW
50 // 2 == 3mW
51 // 1 == 1.6mW
52 // 0 == 1.3mW
53 #define DEFAULT_RF_POWER 7
55 #define DEFAULT_CHANNEL_SPACING 5 // 50kHz
56 #define DEFAULT_HOPLIST 22, 10, 19, 34, 49, 41
57 #define DEFAULT_RF_MAGIC 0xDEADFEED
59 // 0 -- 4800bps, best range
60 // 1 -- 9600bps, medium range
61 // 2 -- 19200bps, medium range
62 #define DEFAULT_DATARATE 2
64 // BIND_DATA flag masks
65 #define TELEMETRY_OFF 0x00
66 #define TELEMETRY_PASSTHRU 0x08
67 #define TELEMETRY_FRSKY 0x10 // covers smartport if used with &
68 #define TELEMETRY_SMARTPORT 0x18
69 #define TELEMETRY_MASK 0x18
70 #define CHANNELS_4_4 0x01
71 #define CHANNELS_8 0x02
72 #define CHANNELS_8_4 0x03
73 #define CHANNELS_12 0x04
74 #define CHANNELS_12_4 0x05
75 #define CHANNELS_16 0x06
76 #define DIVERSITY_ENABLED 0x80
77 #define DEFAULT_FLAGS (CHANNELS_8 | TELEMETRY_PASSTHRU)
79 // helper macro for European PMR channels
80 #define EU_PMR_CH(x) (445993750L + 12500L * (x)) // valid for ch1-ch8
82 // helper macro for US FRS channels 1-7
83 #define US_FRS_CH(x) (462537500L + 25000L * (x)) // valid for ch1-ch7
85 #define DEFAULT_BEACON_FREQUENCY 0 // disable beacon
86 #define DEFAULT_BEACON_DEADTIME 30 // time to wait until go into beacon mode (30s)
87 #define DEFAULT_BEACON_INTERVAL 10 // interval between beacon transmits (10s)
89 #define BINDING_POWER 0x06 // not lowest since may result fail with RFM23BP
91 #define TELEMETRY_PACKETSIZE 9
93 #define BIND_MAGIC (0xDEC1BE15 + (OPENLRSNG_VERSION & 0xfff0))
94 #define BINDING_VERSION ((OPENLRSNG_VERSION & 0x0ff0) >> 4)
96 // HW frequency limits
97 #define MIN_RFM_FREQUENCY_868 848000000
98 #define MAX_RFM_FREQUENCY_868 888000000
99 #define DEFAULT_CARRIER_FREQUENCY_868 868000000 // Hz (ch 0)
100 #define BINDING_FREQUENCY_868 868000000 // Hz
102 #define MIN_RFM_FREQUENCY_915 895000000
103 #define MAX_RFM_FREQUENCY_915 935000000
104 #define DEFAULT_CARRIER_FREQUENCY_915 915000000 // Hz (ch 0)
105 #define BINDING_FREQUENCY_915 915000000 // Hz
107 #define MIN_RFM_FREQUENCY_433 413000000
108 #define MAX_RFM_FREQUENCY_433 463000000
109 #define DEFAULT_CARRIER_FREQUENCY_433 435000000 // Hz (ch 0)
110 #define BINDING_FREQUENCY_433 435000000 // Hz
112 #define RFM22_DEVICE_TYPE 0x00 // R
113 #define RFM22_DT_MASK 0x1F
115 struct bind_data {
116 uint8_t version;
117 uint32_t serial_baudrate;
118 uint32_t rf_frequency;
119 uint32_t rf_magic;
120 uint8_t rf_power;
121 uint8_t rf_channel_spacing;
122 uint8_t hopchannel[MAXHOPS];
123 uint8_t modem_params;
124 uint8_t flags;
125 } __attribute__((packed));
127 enum RF_MODE {
128 Available, Transmit, Receive, Transmitted, Received,
131 enum pios_openlrs_dev_magic {
132 PIOS_OPENLRS_DEV_MAGIC = 0x18c97ab6,
135 struct pios_openlrs_dev {
136 enum pios_openlrs_dev_magic magic;
137 struct pios_openlrs_cfg cfg;
139 // The SPI bus information
140 uint32_t spi_id;
141 uint32_t slave_num;
143 double band;
145 // The task handle
146 struct pios_thread *taskHandle;
148 // The COM callback functions.
149 pios_com_callback rx_in_cb;
150 uint32_t rx_in_context;
151 pios_com_callback tx_out_cb;
152 uint32_t tx_out_context;
154 // The event queue handle
155 struct pios_semaphore *sema_isr;
157 // The PPM buffer
158 int16_t ppm[OPENLRS_PPM_NUM_CHANNELS];
160 // PPM callback.
161 PIOS_OpenLRS_PPMReceivedCallback ppm_callback;
162 // PPM context
163 uint32_t ppm_context;
165 // Flag to indicate if link every acquired
166 bool link_acquired;
168 // Active bound information data
169 struct bind_data bind_data;
171 // Beacon settings
172 uint32_t beacon_frequency;
173 uint8_t beacon_delay;
174 uint8_t beacon_period;
175 bool beacon_armed;
177 enum RF_MODE rf_mode;
178 uint32_t rf_channel;
180 uint8_t it_status1;
181 uint8_t it_status2;
183 uint8_t rx_buf[64];
184 uint8_t tx_buf[9];
186 uint8_t rssi;
187 uint16_t link_quality;
189 // Variables from OpenLRS for radio control
190 uint8_t hopcount;
191 uint32_t lastPacketTimeUs;
192 uint32_t numberOfLostPackets;
193 uint16_t lastAFCCvalue;
194 uint32_t lastRSSITimeUs;
195 bool willhop;
196 uint32_t nextBeaconTimeMs;
197 uint32_t linkLossTimeMs;
198 uint32_t failsafeDelay;
199 uint32_t beacon_rssi_avg;
202 bool PIOS_OpenLRS_EXT_Int(void);
204 #endif /* PIOS_OPENLRS_PRIV_H */
206 * @}
207 * @}