2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
5 * @addtogroup PIOS_DSM Spektrum/JR DSMx satellite receiver functions
6 * @brief PIOS interface to bind and read Spektrum/JR DSMx satellite receiver
9 * @file pios_dsm_priv.h
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011.
11 * @brief Spektrum/JR DSMx satellite receiver private structures.
12 * @see The GNU Public License (GPL) Version 3
14 *****************************************************************************/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #ifndef PIOS_DSM_PRIV_H
32 #define PIOS_DSM_PRIV_H
35 #include <pios_stm32.h>
36 #include <pios_usart_priv.h>
39 * Currently known DSMx (DSM2, DSMJ, DSMX) satellite serial port settings:
40 * 115200bps serial stream, 8 bits, no parity, 1 stop bit
41 * size of each frame: 16 bytes
42 * data resolution: 10 or 11 bits
43 * number of frames: 1 or 2
44 * frame period: 11ms or 22ms
46 * Currently known DSMx frame structure:
47 * 2 bytes - depend on protocol version:
49 * 1 byte - lost frame counter (8 bit)
50 * 1 byte - data format (for master receiver bound with 3 or 5 pulses),
51 * or unknown (for slave receiver bound with 4 or 6 pulses,
52 * some sources call it also the lost frame counter)
54 * 1 byte - unknown data (does not look like lost frame counter)
55 * 1 byte - unknown data, has been seen only 0xB2 so far
57 * 14 bytes - up to 7 channels (16 bit word per channel) with encoded channel
58 * number, channel value, the "2nd frame in a sequence" flag.
59 * Unused channels have FF FF instead of data bytes.
61 * Data format identification:
62 * - for DSM2/DSMJ: [0 0 0 R 0 0 N1 N0]
64 * R is data resolution (0 - 10 bits, 1 - 11 bits),
65 * N1..N0 is the number of frames required to receive all channel
66 * data (01 or 10 are known to the moment, which means 1 or 2 frames).
67 * Three values for the transmitter information byte have been seen
68 * thus far: 0x01, 0x02, 0x12.
69 * - for DSMX this byte contains just 0xB2 or 0xA2 value for any resolution.
70 * It is not known at the moment how to find the exact resolution from the
71 * DSMX data stream. The frame number (1 or 2) and 10/11 bit resolution were
72 * found in different data streams. So it is safer at the moment to ask user
73 * explicitly choose the resolution.
74 * Also some weird throttle channel (0) behavior was found in some streams
75 * from DX8 transmitter (all zeroes). Thus DSMX needs special processing.
78 * - for 10 bit: [F 0 C3 C2 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0]
79 * - for 11 bit: [F C3 C2 C1 C0 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0]
81 * F is normally 0 but set to 1 for the first channel of the 2nd frame,
82 * C3 to C0 is the channel number, 4 bit, zero-based, in any order,
83 * Dx..D0 - channel data (10 or 11 bits)
85 * DSM2 protocol bug: in some cases in 2-frame format some bytes of the
86 * frame can contain invalid values from the previous frame. They usually
87 * are the last 5 bytes and can be equal to FF or other data from last
88 * frame. There is no explicit workaround currently known.
90 * Binding: the number of pulses within bind window after power up defines
91 * if this receiver is a master (provides receiver capabilities info to
92 * the transmitter to choose data format) or slave (does not respond to
93 * the transmitter which falls back to the old DSM mode in that case).
94 * Currently known are 3(4) pulses for low resolution (10 bit) DSM2 mode,
95 * 5(6) pulses for high resolution (11 bit) DSM2 mode, and also 7(8) and
96 * 9(10) pulses for DSMX modes. Thus only 3, 5, 7 or 9 pulses should be
97 * used for stand-alone satellite receiver to be bound correctly as the
101 #define DSM_CHANNELS_PER_FRAME 7
102 #define DSM_FRAME_LENGTH (1 + 1 + DSM_CHANNELS_PER_FRAME * 2)
103 #define DSM_2ND_FRAME_MASK 0x8000
104 /* lower this value as needed if your satellite requires less delay to enter binding. */
105 #define DSM_BIND_MIN_DELAY_US 90000
107 * Include lost frame counter and provide it as a last channel value
108 * for debugging. Currently is not used by the receiver layer.
110 // #define DSM_LOST_FRAME_COUNTER
112 extern const struct pios_rcvr_driver pios_dsm_rcvr_driver
;
114 extern int32_t PIOS_DSM_Init(uint32_t *dsm_id
,
115 const struct pios_com_driver
*driver
,
119 #endif /* PIOS_DSM_PRIV_H */