Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
spektrum_arch.c File Reference
#include <stdint.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/timer.h>
#include <libopencm3/stm32/usart.h>
#include <libopencm3/cm3/nvic.h>
#include "subsystems/radio_control.h"
#include "subsystems/radio_control/spektrum_arch.h"
#include "mcu_periph/uart.h"
#include "mcu_periph/gpio.h"
#include "mcu_periph/sys_time.h"
#include "mcu_arch.h"
#include <BOARD_CONFIG>
+ Include dependency graph for spektrum_arch.c:

Go to the source code of this file.

Data Structures

struct  SpektrumStateStruct
 

Macros

#define SPEKTRUM_CHANNELS_PER_FRAME   7
 
#define MAX_SPEKTRUM_FRAMES   2
 
#define MAX_SPEKTRUM_CHANNELS   16
 
#define ONE_MHZ   1000000
 
#define MASTER_RECEIVER_PULSES   5
 
#define SLAVE_RECEIVER_PULSES   6
 
#define TIM_TICS_FOR_100us   100
 
#define MIN_FRAME_SPACE   70
 
#define MAX_BYTE_SPACE   3
 
#define NVIC_TIM6_IRQ_PRIO   2
 
#define NVIC_TIM6_DAC_IRQ_PRIO   2
 
#define NVIC_PRIMARY_UART_PRIO   2
 
#define __PrimaryUart(dev, _x)   dev##_x
 
#define _PrimaryUart(dev, _x)   __PrimaryUart(dev, _x)
 
#define PrimaryUart(_x)   _PrimaryUart(RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT, _x)
 
#define __SecondaryUart(dev, _x)   dev##_x
 
#define _SecondaryUart(dev, _x)   __SecondaryUart(dev, _x)
 
#define SecondaryUart(_x)   _SecondaryUart(RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT, _x)
 
#define RC_SET_POLARITY   gpio_clear
 Set polarity using RC_POLARITY_GPIO. More...
 
#define SPEKTRUM_PRIMARY_BIND_CONF_PORT   PrimaryUart(_BANK)
 
#define SPEKTRUM_PRIMARY_BIND_CONF_PIN   PrimaryUart(_PIN)
 
#define SPEKTRUM_SECONDARY_BIND_CONF_PORT   SecondaryUart(_BANK)
 
#define SPEKTRUM_SECONDARY_BIND_CONF_PIN   SecondaryUart(_PIN)
 

Typedefs

typedef struct SpektrumStateStruct SpektrumStateType
 

Functions

void SpektrumUartInit (void)
 
void SpektrumTimerInit (void)
 
void tim6_irq_handler (void)
 
void radio_control_impl_init (void)
 
static void SpektrumParser (uint8_t _c, SpektrumStateType *spektrum_state, bool_t secondary_receiver)
 
void RadioControlEventImp (void(*frame_handler)(void))
 
 timer_clear_flag (TIM6, TIM_SR_UIF)
 
 if (PrimarySpektrumState.SpektrumTimer)--PrimarySpektrumState.SpektrumTimer
 
void PrimaryUart() _ISR (void)
 
void radio_control_spektrum_try_bind (void)
 

Variables

SpektrumStateType PrimarySpektrumState = {1,0,0,0,0,0,0,0,0,{0}}
 
int16_t SpektrumBuf [SPEKTRUM_CHANNELS_PER_FRAME *MAX_SPEKTRUM_FRAMES]
 
int8_t SpektrumSigns [] = RADIO_CONTROL_SPEKTRUM_SIGNS
 
static uint8_t EncodingType = 0
 
static uint8_t ExpectedFrames = 0
 

Macro Definition Documentation

#define __PrimaryUart (   dev,
  _x 
)    dev##_x

Definition at line 76 of file spektrum_arch.c.

#define __SecondaryUart (   dev,
  _x 
)    dev##_x

Definition at line 80 of file spektrum_arch.c.

#define _PrimaryUart (   dev,
  _x 
)    __PrimaryUart(dev, _x)

Definition at line 77 of file spektrum_arch.c.

#define _SecondaryUart (   dev,
  _x 
)    __SecondaryUart(dev, _x)

Definition at line 81 of file spektrum_arch.c.

#define MASTER_RECEIVER_PULSES   5

Definition at line 47 of file spektrum_arch.c.

Referenced by radio_control_spektrum_try_bind().

#define MAX_BYTE_SPACE   3

Definition at line 52 of file spektrum_arch.c.

Referenced by SpektrumParser().

#define MAX_SPEKTRUM_CHANNELS   16

Definition at line 42 of file spektrum_arch.c.

#define MAX_SPEKTRUM_FRAMES   2

Definition at line 41 of file spektrum_arch.c.

#define MIN_FRAME_SPACE   70

Definition at line 51 of file spektrum_arch.c.

Referenced by SpektrumParser().

#define NVIC_PRIMARY_UART_PRIO   2

Definition at line 66 of file spektrum_arch.c.

Referenced by SpektrumUartInit().

#define NVIC_TIM6_DAC_IRQ_PRIO   2

Definition at line 59 of file spektrum_arch.c.

Referenced by SpektrumTimerInit().

#define NVIC_TIM6_IRQ_PRIO   2

Definition at line 55 of file spektrum_arch.c.

Referenced by SpektrumTimerInit().

#define ONE_MHZ   1000000

Definition at line 44 of file spektrum_arch.c.

Referenced by SpektrumTimerInit().

#define PrimaryUart (   _x)    _PrimaryUart(RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT, _x)

Definition at line 78 of file spektrum_arch.c.

Referenced by _ISR(), and SpektrumUartInit().

#define RC_SET_POLARITY   gpio_clear

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. So for spektrum this is set to normal polarity.

Definition at line 150 of file spektrum_arch.c.

Referenced by radio_control_impl_init().

#define SecondaryUart (   _x)    _SecondaryUart(RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT, _x)

Definition at line 82 of file spektrum_arch.c.

Referenced by SpektrumUartInit().

#define SLAVE_RECEIVER_PULSES   6

Definition at line 48 of file spektrum_arch.c.

Referenced by radio_control_spektrum_try_bind().

#define SPEKTRUM_CHANNELS_PER_FRAME   7

Definition at line 40 of file spektrum_arch.c.

Referenced by RadioControlEventImp(), and SpektrumParser().

#define SPEKTRUM_PRIMARY_BIND_CONF_PIN   PrimaryUart(_PIN)

Definition at line 670 of file spektrum_arch.c.

Referenced by radio_control_spektrum_try_bind().

#define SPEKTRUM_PRIMARY_BIND_CONF_PORT   PrimaryUart(_BANK)

Definition at line 667 of file spektrum_arch.c.

Referenced by radio_control_spektrum_try_bind().

#define SPEKTRUM_SECONDARY_BIND_CONF_PIN   SecondaryUart(_PIN)

Definition at line 676 of file spektrum_arch.c.

Referenced by radio_control_spektrum_try_bind().

#define SPEKTRUM_SECONDARY_BIND_CONF_PORT   SecondaryUart(_BANK)

Definition at line 673 of file spektrum_arch.c.

Referenced by radio_control_spektrum_try_bind().

#define TIM_TICS_FOR_100us   100

Definition at line 50 of file spektrum_arch.c.

Referenced by SpektrumTimerInit().

Typedef Documentation

Definition at line 97 of file spektrum_arch.c.

Function Documentation

void PrimaryUart() _ISR ( void  )

Definition at line 618 of file spektrum_arch.c.

References FALSE, PrimaryUart, and SpektrumParser().

+ Here is the call graph for this function:

void radio_control_impl_init ( void  )
static void SpektrumParser ( uint8_t  _c,
SpektrumStateType spektrum_state,
bool_t  secondary_receiver 
)
inlinestatic
void SpektrumTimerInit ( void  )

Definition at line 498 of file spektrum_arch.c.

References NVIC_TIM6_DAC_IRQ, NVIC_TIM6_DAC_IRQ_PRIO, NVIC_TIM6_IRQ_PRIO, ONE_MHZ, TIM_TICS_FOR_100us, timer_clear_flag(), and timer_get_frequency().

Referenced by radio_control_impl_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SpektrumUartInit ( void  )

Definition at line 555 of file spektrum_arch.c.

References FALSE, gpio_enable_clock(), gpio_setup_pin_af(), NVIC_PRIMARY_UART_PRIO, PrimaryUart, and SecondaryUart.

Referenced by radio_control_impl_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tim6_irq_handler ( void  )
timer_clear_flag ( TIM6  ,
TIM_SR_UIF   
)

Referenced by clear_timer_flag(), and SpektrumTimerInit().

+ Here is the caller graph for this function:

Variable Documentation

uint8_t EncodingType = 0
static

Definition at line 132 of file spektrum_arch.c.

uint8_t ExpectedFrames = 0
static

Definition at line 133 of file spektrum_arch.c.

Referenced by RadioControlEventImp(), and SpektrumParser().

SpektrumStateType PrimarySpektrumState = {1,0,0,0,0,0,0,0,0,{0}}

Definition at line 99 of file spektrum_arch.c.

Definition at line 110 of file spektrum_arch.c.

Definition at line 129 of file spektrum_arch.c.