Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
sbus_common.c File Reference

Futaba SBUS decoder. More...

#include "modules/radio_control/radio_control.h"
#include "modules/radio_control/sbus_common.h"
#include "mcu_periph/sys_time.h"
#include <BOARD_CONFIG>
#include <string.h>
#include <stdbool.h>
+ Include dependency graph for sbus_common.c:

Go to the source code of this file.

Macros

#define SBUS_START_BYTE   0x0f
 
#define SBUS_END_BYTE_0   0x00
 
#define SBUS_END_BYTE_1   0x04
 
#define SBUS_END_BYTE_2   0x14
 
#define SBUS_END_BYTE_3   0x24
 
#define SBUS_END_BYTE_4   0x34
 
#define SBUS_END_BYTE_5   0x08
 
#define SBUS_BIT_PER_CHANNEL   11
 
#define SBUS_BIT_PER_BYTE   8
 
#define SBUS_FLAGS_BYTE   22
 
#define SBUS_FRAME_LOST_BIT   2
 
#define SBUS_RC_FAILSAFE_BIT   3
 
#define SBUS_RC_LOST_BIT   5
 
#define SBUS_STATUS_UNINIT   0
 
#define SBUS_STATUS_GOT_START   1
 
#define SBUS_TIMEOUT_MS   4
 Time before timeout when receiving a full SBUS frame. More...
 
#define RC_SET_POLARITY   gpio_set
 Set polarity using RC_POLARITY_GPIO. More...
 

Functions

void sbus_common_init (struct Sbus *sbus_p, struct uart_periph *dev, gpio_port_t gpio_polarity_port, uint16_t gpio_polarity_pin)
 Init function. More...
 
static void decode_sbus_buffer (const uint8_t *src, uint16_t *dst, bool *is_frame_available, bool *is_rc_failsafe, bool *is_rc_lost, uint16_t *dstppm)
 Decode the raw buffer. More...
 
void sbus_common_decode_event (struct Sbus *sbus_p, struct uart_periph *dev)
 Decoding event function. More...
 

Detailed Description

Futaba SBUS decoder.

Definition in file sbus_common.c.

Macro Definition Documentation

◆ RC_SET_POLARITY

#define RC_SET_POLARITY   gpio_set

Set polarity using RC_POLARITY_GPIO.

SBUS signal has a reversed polarity compared to normal UART this allows to using hardware UART peripheral by changing the input signal polarity. Setting this gpio ouput high inverts the signal, output low sets it to normal polarity.

Definition at line 71 of file sbus_common.c.

◆ SBUS_BIT_PER_BYTE

#define SBUS_BIT_PER_BYTE   8

Definition at line 48 of file sbus_common.c.

◆ SBUS_BIT_PER_CHANNEL

#define SBUS_BIT_PER_CHANNEL   11

Definition at line 47 of file sbus_common.c.

◆ SBUS_END_BYTE_0

#define SBUS_END_BYTE_0   0x00

Definition at line 41 of file sbus_common.c.

◆ SBUS_END_BYTE_1

#define SBUS_END_BYTE_1   0x04

Definition at line 42 of file sbus_common.c.

◆ SBUS_END_BYTE_2

#define SBUS_END_BYTE_2   0x14

Definition at line 43 of file sbus_common.c.

◆ SBUS_END_BYTE_3

#define SBUS_END_BYTE_3   0x24

Definition at line 44 of file sbus_common.c.

◆ SBUS_END_BYTE_4

#define SBUS_END_BYTE_4   0x34

Definition at line 45 of file sbus_common.c.

◆ SBUS_END_BYTE_5

#define SBUS_END_BYTE_5   0x08

Definition at line 46 of file sbus_common.c.

◆ SBUS_FLAGS_BYTE

#define SBUS_FLAGS_BYTE   22

Definition at line 49 of file sbus_common.c.

◆ SBUS_FRAME_LOST_BIT

#define SBUS_FRAME_LOST_BIT   2

Definition at line 50 of file sbus_common.c.

◆ SBUS_RC_FAILSAFE_BIT

#define SBUS_RC_FAILSAFE_BIT   3

Definition at line 51 of file sbus_common.c.

◆ SBUS_RC_LOST_BIT

#define SBUS_RC_LOST_BIT   5

Definition at line 52 of file sbus_common.c.

◆ SBUS_START_BYTE

#define SBUS_START_BYTE   0x0f

Definition at line 40 of file sbus_common.c.

◆ SBUS_STATUS_GOT_START

#define SBUS_STATUS_GOT_START   1

Definition at line 55 of file sbus_common.c.

◆ SBUS_STATUS_UNINIT

#define SBUS_STATUS_UNINIT   0

Definition at line 54 of file sbus_common.c.

◆ SBUS_TIMEOUT_MS

#define SBUS_TIMEOUT_MS   4

Time before timeout when receiving a full SBUS frame.

Definition at line 61 of file sbus_common.c.

Function Documentation

◆ decode_sbus_buffer()

static void decode_sbus_buffer ( const uint8_t src,
uint16_t dst,
bool *  is_frame_available,
bool *  is_rc_failsafe,
bool *  is_rc_lost,
uint16_t dstppm 
)
static

Decode the raw buffer.

Definition at line 99 of file sbus_common.c.

References SBUS_FLAGS_BYTE, SBUS_FRAME_LOST_BIT, SBUS_NB_CHANNEL, SBUS_RC_FAILSAFE_BIT, SBUS_RC_LOST_BIT, and USEC_OF_RC_PPM_TICKS.

Referenced by sbus_common_decode_event().

+ Here is the caller graph for this function:

◆ sbus_common_decode_event()

void sbus_common_decode_event ( struct Sbus sbus_p,
struct uart_periph dev 
)

◆ sbus_common_init()

void sbus_common_init ( struct Sbus sbus_p,
struct uart_periph dev,
gpio_port_t  gpio_polarity_port,
uint16_t  gpio_polarity_pin 
)

Init function.

Definition at line 74 of file sbus_common.c.

References B100000, dev, Sbus::frame_available, gpio_setup_output(), Sbus::rc_failsafe, Sbus::rc_lost, RC_SET_POLARITY, SBUS_STATUS_UNINIT, Sbus::start_time, Sbus::status, uart_periph_invert_data_logic(), uart_periph_set_baudrate(), uart_periph_set_bits_stop_parity(), UBITS_8, UPARITY_EVEN, and USTOP_2.

Referenced by sbus_dual_init(), and sbus_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: