dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_dsm_priv.h
Go to the documentation of this file.
1 
17 /*
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful, but
24  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26  * for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with this program; if not, see <http://www.gnu.org/licenses/>
30  */
31 
32 #ifndef PIOS_DSM_PRIV_H
33 #define PIOS_DSM_PRIV_H
34 
35 #include <pios.h>
36 
37 #ifndef FLIGHT_POSIX
38 #include <pios_stm32.h>
39 #include <pios_usart_priv.h>
40 #endif
41 
42 // for HwSharedDSMxModeOptions
43 #include <uavobjectmanager.h>
44 #include <hwshared.h>
45 
46 /*
47  * Currently known DSMx (DSM2, DSMJ, DSMX) satellite serial port settings:
48  * 115200bps serial stream, 8 bits, no parity, 1 stop bit
49  * size of each frame: 16 bytes
50  * data resolution: 10 or 11 bits
51  * number of frames: 1 or 2
52  * frame period: 11ms or 22ms
53  *
54  * Currently known DSMx frame structure:
55  * 2 bytes - depend on protocol version:
56  * for DSM2/DSMJ:
57  * 1 byte - lost frame counter (8 bit)
58  * 1 byte - data format (for master receiver bound with 3 or 5 pulses),
59  * or unknown (for slave receiver bound with 4 or 6 pulses,
60  * some sources call it also the lost frame counter)
61  * for DSMX:
62  * 1 byte - unknown data (does not look like lost frame counter)
63  * 1 byte - unknown data, has been seen only 0xB2 so far
64 
65  * 14 bytes - up to 7 channels (16 bit word per channel) with encoded channel
66  * number, channel value, the "2nd frame in a sequence" flag.
67  * Unused channels have FF FF instead of data bytes.
68  *
69  * Data format identification:
70  * - for DSM2/DSMJ: [0 0 0 R 0 0 N1 N0]
71  * where
72  * R is data resolution (0 - 10 bits, 1 - 11 bits),
73  * N1..N0 is the number of frames required to receive all channel
74  * data (01 or 10 are known to the moment, which means 1 or 2 frames).
75  * Three values for the transmitter information byte have been seen
76  * thus far: 0x01, 0x02, 0x12.
77  * - for DSMX this byte contains just 0xB2 or 0xA2 value for any resolution.
78  * It is not known at the moment how to find the exact resolution from the
79  * DSMX data stream. The frame number (1 or 2) and 10/11 bit resolution were
80  * found in different data streams. So it is safer at the moment to ask user
81  * explicitly choose the resolution.
82  * Also some weird throttle channel (0) behavior was found in some streams
83  * from DX8 transmitter (all zeroes). Thus DSMX needs special processing.
84  *
85  * Channel data are:
86  * - for 10 bit: [F 0 C3 C2 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0]
87  * - for 11 bit: [F C3 C2 C1 C0 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0]
88  * where
89  * F is normally 0 but set to 1 for the first channel of the 2nd frame,
90  * C3 to C0 is the channel number, 4 bit, zero-based, in any order,
91  * Dx..D0 - channel data (10 or 11 bits)
92  *
93  * DSM2 protocol bug: in some cases in 2-frame format some bytes of the
94  * frame can contain invalid values from the previous frame. They usually
95  * are the last 5 bytes and can be equal to FF or other data from last
96  * frame. There is no explicit workaround currently known.
97  *
98  * Binding: the number of pulses within bind window after power up defines
99  * if this receiver is a master (provides receiver capabilities info to
100  * the transmitter to choose data format) or slave (does not respond to
101  * the transmitter which falls back to the old DSM mode in that case).
102  * Currently known are 3(4) pulses for low resolution (10 bit) DSM2 mode,
103  * 5(6) pulses for high resolution (11 bit) DSM2 mode, and also 7(8) and
104  * 9(10) pulses for DSMX modes. Thus only 3, 5, 7 or 9 pulses should be
105  * used for stand-alone satellite receiver to be bound correctly as the
106  * master.
107  */
108 
109 #define DSM_CHANNELS_PER_FRAME 7
110 #define DSM_FRAME_LENGTH (1+1+DSM_CHANNELS_PER_FRAME*2)
111 #define DSM_2ND_FRAME_MASK 0x8000
112 
113 /*
114  * Include lost frame counter and provide it as a last channel value
115  * for debugging. Currently is not used by the receiver layer.
116  */
117 //#define DSM_LOST_FRAME_COUNTER
118 
119 /* DSM receiver instance configuration */
120 struct pios_dsm_cfg {
121 #ifndef FLIGHT_POSIX
122  struct stm32_gpio bind;
123 #else
124  char unused;
125 #endif
126 };
127 
128 extern const struct pios_rcvr_driver pios_dsm_rcvr_driver;
129 
130 extern int32_t PIOS_DSM_Init(uintptr_t *dsm_id,
131  const struct pios_dsm_cfg *cfg,
132  const struct pios_com_driver *driver,
133  uintptr_t lower_id,
134  HwSharedDSMxModeOptions mode);
135 
136 #endif /* PIOS_DSM_PRIV_H */
137 
Types that are specific to the STM32 peripherals.
int32_t PIOS_DSM_Init(uintptr_t *dsm_id, const struct pios_dsm_cfg *cfg, const struct pios_com_driver *driver, uintptr_t lower_id, HwSharedDSMxModeOptions mode)
Main PiOS header to include all the compiled in PiOS options.
struct stm32_gpio bind
USART private definitions.
static struct flyingpicmd_cfg_fa cfg
Definition: main.c:49
enum channel_mode mode
Definition: pios_servo.c:58
const struct pios_rcvr_driver pios_dsm_rcvr_driver
uint8_t unused[4]
Definition: bl_messages.h:70