Paparazzi UAS  v5.15_devel-81-gd13dafb
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
spektrum.c File Reference

Spektrum sattelite receiver implementation. More...

+ Include dependency graph for spektrum.c:

Go to the source code of this file.

Macros

#define SPEKTRUM_MASTER_RECEIVER_PULSES   5
 
#define SPEKTRUM_SLAVE_RECEIVER_PULSES   6
 
#define RC_SET_POLARITY   gpio_clear
 
#define SPEKTRUM_BIND_WAIT   60000
 
#define SPEKTRUM_SYS_TYPE   0
 
#define SPEKTRUM_SYS_22_1024_2   0x01
 Allowed system field valaues. More...
 
#define SPEKTRUM_SYS_11_2048_2   0x12
 
#define SPEKTRUM_SYS_22_2048_X   0xa2
 
#define SPEKTRUM_SYS_11_2048_X   0xb2
 
#define _UART_RX_PORT(i)   i ## _PORT_RX
 
#define UART_RX_PORT(i)   _UART_RX_PORT(i)
 
#define _UART_RX(i)   i ## _RX
 
#define UART_RX(i)   _UART_RX(i)
 
#define SPEKTRUM_PRIMARY_BIND_CONF_PORT   UART_RX_PORT(SPEKTRUM_PRIMARY_UART_UPPER)
 By default, the same pin is used for pulse train and uart rx, but they can be different if needed. More...
 
#define SPEKTRUM_PRIMARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_PRIMARY_UART_UPPER)
 
#define SPEKTRUM_SECONDARY_BIND_CONF_PORT   UART_RX_PORT(SPEKTRUM_SECONDARY_UART_UPPER)
 
#define SPEKTRUM_SECONDARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_SECONDARY_UART_UPPER)
 

Functions

static void spektrum_bind (void)
 This function puts the satellite in binding mode. More...
 
static void spektrum_init_sat (struct spektrum_sat_t *sat)
 Initialize a spektrum sattelite. More...
 
void spektrum_try_bind (void)
 
void radio_control_impl_init (void)
 Main Radio initialization. More...
 
static void spektrum_parse_channel (struct spektrum_sat_t *sat, uint16_t chan)
 
static void spektrum_parser (struct spektrum_sat_t *sat)
 
static void spektrum_uart_check (struct uart_periph *dev, struct spektrum_sat_t *sat)
 Check bytes on the UART. More...
 
void spektrum_event (void(*frame_handler)(void))
 Checks if there is one valid satellite and sets the radio_control structure. More...
 

Variables

const int8_t spektrum_signs [] = RADIO_CONTROL_SPEKTRUM_SIGNS
 
static struct spektrum_t spektrum
 

Detailed Description

Spektrum sattelite receiver implementation.

For the protocol specification see: http://www.spektrumrc.com/ProdInfo/Files/Remote%20Receiver%20Interfacing%20Rev%20A.pdf

Definition in file spektrum.c.

Macro Definition Documentation

#define _UART_RX (   i)    i ## _RX

Definition at line 332 of file spektrum.c.

#define _UART_RX_PORT (   i)    i ## _PORT_RX

Definition at line 330 of file spektrum.c.

#define RC_SET_POLARITY   gpio_clear

Definition at line 65 of file spektrum.c.

Referenced by radio_control_impl_init().

#define SPEKTRUM_BIND_WAIT   60000

Definition at line 72 of file spektrum.c.

Referenced by spektrum_bind().

#define SPEKTRUM_MASTER_RECEIVER_PULSES   5

Definition at line 59 of file spektrum.c.

Referenced by spektrum_bind().

#define SPEKTRUM_PRIMARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_PRIMARY_UART_UPPER)

Definition at line 343 of file spektrum.c.

Referenced by spektrum_bind().

#define SPEKTRUM_PRIMARY_BIND_CONF_PORT   UART_RX_PORT(SPEKTRUM_PRIMARY_UART_UPPER)

By default, the same pin is used for pulse train and uart rx, but they can be different if needed.

Definition at line 340 of file spektrum.c.

Referenced by spektrum_bind().

#define SPEKTRUM_SECONDARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_SECONDARY_UART_UPPER)

Definition at line 349 of file spektrum.c.

Referenced by spektrum_bind().

#define SPEKTRUM_SECONDARY_BIND_CONF_PORT   UART_RX_PORT(SPEKTRUM_SECONDARY_UART_UPPER)

Definition at line 346 of file spektrum.c.

Referenced by spektrum_bind().

#define SPEKTRUM_SLAVE_RECEIVER_PULSES   6

Definition at line 60 of file spektrum.c.

Referenced by spektrum_bind().

#define SPEKTRUM_SYS_11_2048_2   0x12

Definition at line 99 of file spektrum.c.

Referenced by spektrum_parser().

#define SPEKTRUM_SYS_11_2048_X   0xb2

Definition at line 101 of file spektrum.c.

Referenced by spektrum_parser().

#define SPEKTRUM_SYS_22_1024_2   0x01

Allowed system field valaues.

from datasheet, possible values for the frame format encoded in the system field of the internal remote frame (second byte). Only the first one is encoding values on 10bits, other ones on 11bits.

Definition at line 98 of file spektrum.c.

Referenced by spektrum_parse_channel(), and spektrum_parser().

#define SPEKTRUM_SYS_22_2048_X   0xa2

Definition at line 100 of file spektrum.c.

Referenced by spektrum_parser().

#define SPEKTRUM_SYS_TYPE   0

Definition at line 79 of file spektrum.c.

#define UART_RX (   i)    _UART_RX(i)

Definition at line 333 of file spektrum.c.

#define UART_RX_PORT (   i)    _UART_RX_PORT(i)

Definition at line 331 of file spektrum.c.

Function Documentation

void radio_control_impl_init ( void  )

Main Radio initialization.

Definition at line 164 of file spektrum.c.

References gpio_setup_output(), RADIO_CONTROL_NB_CHANNEL, RC_POLARITY_GPIO_PIN, RC_POLARITY_GPIO_PORT, RC_SET_POLARITY, spektrum_t::satellites, spektrum_t::signs, and spektrum_init_sat().

+ Here is the call graph for this function:

static void UNUSED spektrum_bind ( void  )
static

This function puts the satellite in binding mode.

The requirement of this are that this needs to be done while powering up.

Definition at line 355 of file spektrum.c.

References gpio_set(), gpio_setup_input(), gpio_setup_output(), gpio_toggle(), SPEKTRUM_BIND_WAIT, SPEKTRUM_MASTER_RECEIVER_PULSES, SPEKTRUM_PRIMARY_BIND_CONF_PIN, SPEKTRUM_PRIMARY_BIND_CONF_PORT, SPEKTRUM_SECONDARY_BIND_CONF_PIN, SPEKTRUM_SECONDARY_BIND_CONF_PORT, SPEKTRUM_SLAVE_RECEIVER_PULSES, and sys_time_usleep().

Referenced by spektrum_try_bind().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void spektrum_event ( void(*)(void)  frame_handler)
static void spektrum_init_sat ( struct spektrum_sat_t sat)
inlinestatic

Initialize a spektrum sattelite.

Definition at line 106 of file spektrum.c.

References get_sys_time_msec(), spektrum_sat_t::idx, SPEKTRUM_MAX_CHANNELS, spektrum_sat_t::timer, spektrum_sat_t::valid, and spektrum_sat_t::values.

Referenced by radio_control_impl_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void spektrum_parse_channel ( struct spektrum_sat_t sat,
uint16_t  chan 
)
inlinestatic

Definition at line 185 of file spektrum.c.

References MAX_PPRZ, RADIO_THROTTLE, SPEKTRUM_SYS_22_1024_2, spektrum_t::tx_type, spektrum_sat_t::valid, spektrum_t::valid, and spektrum_sat_t::values.

Referenced by spektrum_parser().

+ Here is the caller graph for this function:

static void spektrum_parser ( struct spektrum_sat_t sat)
inlinestatic

Definition at line 231 of file spektrum.c.

References spektrum_sat_t::buf, spektrum_sat_t::lost_frame_cnt, SPEKTRUM_CHANNELS_PER_FRAME, spektrum_parse_channel(), SPEKTRUM_SYS_11_2048_2, SPEKTRUM_SYS_11_2048_X, SPEKTRUM_SYS_22_1024_2, SPEKTRUM_SYS_22_2048_X, and spektrum_t::tx_type.

Referenced by spektrum_uart_check().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void spektrum_try_bind ( void  )

Definition at line 126 of file spektrum.c.

References gpio_get(), gpio_setup_input_pulldown(), gpio_setup_input_pullup(), spektrum_bind(), SPEKTRUM_BIND_PIN, SPEKTRUM_BIND_PIN_PORT, and sys_time_usleep().

+ Here is the call graph for this function:

static void spektrum_uart_check ( struct uart_periph dev,
struct spektrum_sat_t sat 
)
static

Check bytes on the UART.

Definition at line 257 of file spektrum.c.

References spektrum_sat_t::buf, get_sys_time_msec(), spektrum_sat_t::idx, SPEKTRUM_FRAME_LEN, SPEKTRUM_MIN_FRAME_SPACE, spektrum_parser(), spektrum_sat_t::timer, uart_char_available(), and uart_getch().

Referenced by spektrum_event().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

struct spektrum_t spektrum
static
Initial value:
= {
.valid = false,
.tx_type = SPEKTRUM_SYS_TYPE,
}
#define SPEKTRUM_SYS_TYPE
Definition: spektrum.c:79

Definition at line 86 of file spektrum.c.

const int8_t spektrum_signs[] = RADIO_CONTROL_SPEKTRUM_SIGNS

Definition at line 83 of file spektrum.c.