RC C library: Use same buffer as the protocols do not decode in parallel.

This commit is contained in:
Lorenz Meier
2017-05-01 17:32:08 +02:00
parent 118b9aad19
commit 71731d17a9
7 changed files with 53 additions and 12 deletions

View File

@@ -35,10 +35,11 @@ px4_add_module(
COMPILE_FLAGS
-Wno-unused-result
SRCS
st24.c
sumd.c
sbus.c
dsm.c
st24.cpp
sumd.cpp
sbus.cpp
dsm.cpp
common_rc.cpp
DEPENDS
platforms__common
)

4
src/lib/rc/common_rc.cpp Normal file
View File

@@ -0,0 +1,4 @@
#include "common_rc.h"
__EXPORT rc_decode_buf_t rc_decode_buf;

33
src/lib/rc/common_rc.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include <stdint.h>
#include "dsm.h"
#include "sbus.h"
#include "st24.h"
#include "sumd.h"
#include "dsm.h"
#pragma pack(push, 1)
typedef uint8_t dsm_frame_t[DSM_BUFFER_SIZE]; /**< DSM dsm frame receive buffer */
typedef uint8_t dsm_buf_t[DSM_FRAME_SIZE * 2]; // Define working buffer
typedef struct dsm_decode_t {
dsm_frame_t frame;
dsm_buf_t buf;
} dsm_decode_t;
typedef uint8_t sbus_frame_t[SBUS_FRAME_SIZE + (SBUS_FRAME_SIZE / 2)];
typedef struct rc_decode_buf_ {
union {
dsm_decode_t dsm;
sbus_frame_t sbus_frame;
ReceiverFcPacket _strxpacket;
ReceiverFcPacketHoTT _hottrxpacket;
};
} rc_decode_buf_t;
#pragma pack(pop)
extern rc_decode_buf_t rc_decode_buf;

View File

@@ -32,7 +32,7 @@
****************************************************************************/
/**
* @file dsm.c
* @file dsm.cpp
*
* Serial protocol decoder for the Spektrum DSM* family of protocols.
*
@@ -49,6 +49,7 @@
#include <string.h>
#include "dsm.h"
#include "common_rc.h"
#include <drivers/drv_hrt.h>
#if defined (__PX4_LINUX) || defined (__PX4_DARWIN) || defined(__PX4_QURT)
@@ -68,8 +69,9 @@ static enum DSM_DECODE_STATE {
static int dsm_fd = -1; /**< File handle to the DSM UART */
static hrt_abstime dsm_last_rx_time; /**< Timestamp when we last received data */
static hrt_abstime dsm_last_frame_time; /**< Timestamp for start of last valid dsm frame */
static uint8_t dsm_frame[DSM_BUFFER_SIZE]; /**< DSM dsm frame receive buffer */
static uint8_t dsm_buf[DSM_FRAME_SIZE * 2];
static dsm_frame_t &dsm_frame = rc_decode_buf.dsm.frame; /**< DSM_BUFFER_SIZE DSM dsm frame receive buffer */
static dsm_buf_t &dsm_buf = rc_decode_buf.dsm.buf; /**< DSM_BUFFER_SIZE DSM dsm frame receive buffer */
static uint16_t dsm_chan_buf[DSM_MAX_CHANNEL_COUNT];
static unsigned dsm_partial_frame_count; /**< Count of bytes received for current dsm frame */
static unsigned dsm_channel_shift = 0; /**< Channel resolution, 0=unknown, 1=10 bit, 2=11 bit */

View File

@@ -49,6 +49,7 @@
#endif
#include "sbus.h"
#include "common_rc.h"
#include <drivers/drv_hrt.h>
#define SBUS_DEBUG_LEVEL 0 /* Set debug output level */
@@ -116,7 +117,7 @@ static enum SBUS2_DECODE_STATE {
SBUS2_DECODE_STATE_SBUS2_DATA2 = 0x34
} sbus_decode_state = SBUS2_DECODE_STATE_DESYNC;
static uint8_t sbus_frame[SBUS_FRAME_SIZE + (SBUS_FRAME_SIZE / 2)];
static sbus_frame_t &sbus_frame = rc_decode_buf.sbus_frame;
static unsigned partial_frame_count;
static unsigned sbus1_frame_delay = (1000U * 1000U) / SBUS1_DEFAULT_RATE_HZ;

View File

@@ -42,6 +42,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "st24.h"
#include "common_rc.h"
enum ST24_DECODE_STATE {
ST24_DECODE_STATE_UNSYNCED = 0,
@@ -74,7 +75,7 @@ const char *decode_states[] = {"UNSYNCED",
static enum ST24_DECODE_STATE _decode_state = ST24_DECODE_STATE_UNSYNCED;
static uint8_t _rxlen;
static ReceiverFcPacket _rxpacket;
static ReceiverFcPacket &_rxpacket = rc_decode_buf._strxpacket;
uint8_t st24_common_crc8(uint8_t *ptr, uint8_t len)
{

View File

@@ -42,7 +42,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "sumd.h"
#include "common_rc.h"
enum SUMD_DECODE_STATE {
SUMD_DECODE_STATE_UNSYNCED = 0,
@@ -88,8 +88,7 @@ bool _debug = false;
static enum SUMD_DECODE_STATE _decode_state = SUMD_DECODE_STATE_UNSYNCED;
static uint8_t _rxlen;
static ReceiverFcPacketHoTT _rxpacket;
static ReceiverFcPacketHoTT &_rxpacket = rc_decode_buf._hottrxpacket;
uint16_t sumd_crc16(uint16_t crc, uint8_t value)
{