dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_openlrs_priv.h
Go to the documentation of this file.
1 
16 /*
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.
21  *
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.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 #ifndef PIOS_OPENLRS_PRIV_H
32 #define PIOS_OPENLRS_PRIV_H
33 
34 #include "pios_openlrs.h"
35 
36 #ifdef PIOS_INCLUDE_OPENLRS
37 
38 extern const struct pios_com_driver pios_openlrs_com_driver;
39 
40 #include "openlrs.h"
41 
42 #define OPENLRSNG_VERSION 0x0382
43 
44 #define MAXHOPS 24
45 #define OPENLRS_PPM_NUM_CHANNELS 20
46 
47 // Factory setting values, modify via the CLI
48 
49 //####### RADIOLINK RF POWER (beacon is always 100/13/1.3mW) #######
50 // 7 == 100mW (or 1000mW with M3)
51 // 6 == 50mW (use this when using booster amp), (800mW with M3)
52 // 5 == 25mW
53 // 4 == 13mW
54 // 3 == 6mW
55 // 2 == 3mW
56 // 1 == 1.6mW
57 // 0 == 1.3mW
58 #define DEFAULT_RF_POWER 7
59 
60 #define DEFAULT_CHANNEL_SPACING 5 // 50kHz
61 #define DEFAULT_HOPLIST 22,10,19,34,49,41
62 #define DEFAULT_RF_MAGIC 0xDEADFEED
63 
64 // 0 -- 4800bps, best range
65 // 1 -- 9600bps, medium range
66 // 2 -- 19200bps, medium range
67 #define DEFAULT_DATARATE 2
68 
69 // BIND_DATA flag masks
70 #define TELEMETRY_OFF 0x00
71 #define TELEMETRY_PASSTHRU 0x08
72 #define TELEMETRY_FRSKY 0x10 // covers smartport if used with &
73 #define TELEMETRY_SMARTPORT 0x18
74 #define TELEMETRY_MASK 0x18
75 #define CHANNELS_4 0x00
76 #define CHANNELS_4_4 0x01
77 #define CHANNELS_8 0x02
78 #define CHANNELS_8_4 0x03
79 #define CHANNELS_12 0x04
80 #define CHANNELS_12_4 0x05
81 #define CHANNELS_16 0x06
82 #define CHANNELS_16_4 0x07
83 
84 #define DIVERSITY_ENABLED 0x80
85 #define DEFAULT_FLAGS (CHANNELS_8 | TELEMETRY_PASSTHRU)
86 #define EXT_FLAG_FASTDATA 0x80
87 
88 // helper macro for European PMR channels
89 #define EU_PMR_CH(x) (445993750L + 12500L * (x)) // valid for ch1-ch8
90 
91 // helper macro for US FRS channels 1-7
92 #define US_FRS_CH(x) (462537500L + 25000L * (x)) // valid for ch1-ch7
93 
94 #define DEFAULT_BEACON_FREQUENCY 0 // disable beacon
95 #define DEFAULT_BEACON_DEADTIME 30 // time to wait until go into beacon mode (30s)
96 #define DEFAULT_BEACON_INTERVAL 10 // interval between beacon transmits (10s)
97 
98 #define TELEMETRY_PACKETSIZE 9
99 
100 #define BIND_MAGIC (0xDEC1BE15 + (OPENLRSNG_VERSION & 0xfff0))
101 #define BINDING_VERSION ((OPENLRSNG_VERSION & 0x0ff0)>>4)
102 
103 // HW frequency limits
104 #define MIN_RFM_FREQUENCY_868 848000000
105 #define MAX_RFM_FREQUENCY_868 888000000
106 #define DEFAULT_CARRIER_FREQUENCY_868 868000000 // Hz (ch 0)
107 #define BINDING_FREQUENCY_868 868000000 // Hz
108 
109 #define MIN_RFM_FREQUENCY_915 895000000
110 #define MAX_RFM_FREQUENCY_915 935000000
111 #define DEFAULT_CARRIER_FREQUENCY_915 915000000 // Hz (ch 0)
112 #define BINDING_FREQUENCY_915 915000000 // Hz
113 
114 #define MIN_RFM_FREQUENCY_433 413000000
115 #define MAX_RFM_FREQUENCY_433 463000000
116 #define DEFAULT_CARRIER_FREQUENCY_433 435000000 // Hz (ch 0)
117 #define BINDING_FREQUENCY_433 435000000 // Hz
118 
119 #define RFM22_DEVICE_TYPE 0x00 // R
120 #define RFM22_DT_MASK 0x1F
121 
122 const static uint8_t openlrs_pktsizes[8] = { 6, 7, 11, 12, 16, 17, 21, 22 };
123 #define MAX_PACKET_SIZE 22
124 
125 struct bind_data {
126  uint8_t hdr;
127  uint8_t version;
128 
129  /* This was serial_baudrate, which we don't use. It's an RX parameter
130  * and not really something specific to the link.
131  */
132  uint8_t reserved[3];
133  uint8_t ext_flags;
134 
135  uint32_t rf_frequency;
136  uint32_t rf_magic;
137  uint8_t rf_power;
138  uint8_t rf_channel_spacing;
139  uint8_t hopchannel[MAXHOPS];
140  uint8_t modem_params;
141  uint8_t flags;
142 } __attribute__((packed));
143 
144 enum RF_MODE {
145  Available, Transmit, Receive, Transmitted, Received,
146 };
147 
148 enum pios_openlrs_dev_magic {
149  PIOS_OPENLRS_DEV_MAGIC = 0x18c97ab6,
150 };
151 
152 struct pios_openlrs_dev {
153  enum pios_openlrs_dev_magic magic;
154  struct pios_openlrs_cfg cfg;
155 
156  // The SPI bus information
157  pios_spi_t spi_id;
158  uint32_t slave_num;
159 
160  HwSharedRfBandOptions band;
161  HwSharedMaxRfPowerOptions max_power;
162 
163  // The task handle
164  struct pios_thread *taskHandle;
165 
166  // The COM callback functions.
167  // Expected to be nailed down prior to PIOS_OpenLRS_Start.
168  // (Not volatile, etc.).
169  pios_com_callback rx_in_cb;
170  uintptr_t rx_in_context;
171  pios_com_callback tx_out_cb;
172  uintptr_t tx_out_context;
173 
174  // The event queue handle
175  struct pios_semaphore *sema_isr;
176 
177  // The channel value buffer
178  int16_t ppm[OPENLRS_PPM_NUM_CHANNELS];
179 
180  // RFM22B RCVR interface
181  uintptr_t openlrs_rcvr_id;
182 
183  // Active bound information data
184  struct bind_data bind_data;
185 
186  // Beacon settings
187  uint32_t beacon_frequency;
188  uint8_t beacon_delay;
189  uint8_t beacon_period;
190  bool beacon_armed;
191 
192  // Flag to indicate if link ever acquired
193  bool link_acquired;
194 
195  volatile enum RF_MODE rf_mode;
196  uint32_t rf_channel;
197 
198  uint8_t it_status1;
199  uint8_t it_status2;
200 
201  // Variables from OpenLRS for radio control
202  uint8_t hopcount;
203  uint32_t lastPacketTimeUs;
204  uint32_t numberOfLostPackets;
205  uint16_t lastAFCCvalue;
206  uint32_t nextBeaconTimeMs;
207  uint32_t linkLossTimeMs;
208  uint32_t failsafeDelay;
209  uint32_t beacon_rssi_avg;
210 
211  // Scaling values for input controls in transmitter path
212  uint16_t scale_min, scale_max;
213 
214  OpenLRStx_sourceOptions tx_source;
215  bool tx_ok_to_telemeter;
216  uint8_t tx_prev_rxtelem_hdr;
217  uint8_t tx_startup_bind_duration;
218  uint8_t tx_bind_button_duration;
219  uint8_t telem_len;
220  uint8_t tx_buf[MAX_PACKET_SIZE];
221 };
222 
223 #endif /* PIOS_INCLUDE_OPENLRS */
224 
225 #endif /* PIOS_OPENLRS_PRIV_H */
226 
static struct pios_thread * taskHandle
Definition: actuator.c:83
uint16_t flags
Definition: uavtalk_priv.h:52
static struct flyingpicmd_cfg_fa cfg
Definition: main.c:49
uint32_t magic
Implements an OpenLRS driver for the RFM22B.
uint8_t version
Definition: msp_messages.h:96
uint16_t(* pios_com_callback)(uintptr_t context, uint8_t *buf, uint16_t buf_len, uint16_t *headroom, bool *task_woken)
Definition: pios_com.h:41
typedef __attribute__
Definition: serial_4way.h:43