Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ppm.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2014 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
30 
31 uint16_t ppm_pulses[RADIO_CTL_NB];
32 volatile bool ppm_frame_available;
33 
34 /*
35  * State machine for decoding ppm frames
36  */
39 static bool ppm_data_valid;
40 
47 #ifndef RssiValid
48 #define RssiValid() TRUE
49 #endif
50 
51 
52 #if PERIODIC_TELEMETRY
54 
55 static void send_ppm(struct transport_tx *trans, struct link_device *dev)
56 {
57  uint16_t ppm_pulses_usec[RADIO_CTL_NB];
58  for (int i = 0; i < RADIO_CTL_NB; i++) {
59  ppm_pulses_usec[i] = USEC_OF_RC_PPM_TICKS(ppm_pulses[i]);
60  }
61  pprz_msg_send_PPM(trans, dev, AC_ID,
62  &radio_control.frame_rate, RADIO_CTL_NB, ppm_pulses_usec);
63 }
64 #endif
65 
67 {
68  ppm_frame_available = false;
70  ppm_cur_pulse = RADIO_CTL_NB;
71  ppm_data_valid = false;
72 
73  ppm_arch_init();
74 
75 #if PERIODIC_TELEMETRY
77 #endif
78 }
79 
80 void radio_control_impl_event(void (* _received_frame_handler)(void))
81 {
82  if (ppm_frame_available) {
85  if (radio_control.radio_ok_cpt > 0) {
87  } else {
89  NormalizePpmIIR(ppm_pulses, radio_control);
90  _received_frame_handler();
91  }
92  ppm_frame_available = false;
93  }
94 }
95 
99 void ppm_decode_frame(uint32_t ppm_time)
100 {
101  uint32_t length = ppm_time - ppm_last_pulse_time;
102  ppm_last_pulse_time = ppm_time;
103 
104  ppm_decode_frame_width(length);
105 }
106 
115 {
116  if (ppm_cur_pulse == RADIO_CTL_NB) {
117  if (ppm_width > RC_PPM_TICKS_OF_USEC(PPM_SYNC_MIN_LEN) &&
118  ppm_width < RC_PPM_TICKS_OF_USEC(PPM_SYNC_MAX_LEN)) {
119  if (ppm_data_valid && RssiValid()) {
120  ppm_frame_available = true;
121  ppm_data_valid = false;
122  }
123  ppm_cur_pulse = 0;
124  } else {
125  ppm_data_valid = false;
126  }
127  } else {
128  if (ppm_width > RC_PPM_TICKS_OF_USEC(PPM_DATA_MIN_LEN) &&
129  ppm_width < RC_PPM_TICKS_OF_USEC(PPM_DATA_MAX_LEN)) {
130  ppm_pulses[ppm_cur_pulse] = ppm_width;
131  ppm_cur_pulse++;
132  if (ppm_cur_pulse == RADIO_CTL_NB) {
133  ppm_data_valid = true;
134  }
135  } else {
136  ppm_cur_pulse = RADIO_CTL_NB;
137  ppm_data_valid = false;
138  }
139  }
140 }
unsigned short uint16_t
Definition: types.h:16
void radio_control_impl_init(void)
Definition: ppm.c:66
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t radio_ok_cpt
Definition: radio_control.h:66
uint8_t status
Definition: radio_control.h:64
uint16_t ppm_pulses[RADIO_CTL_NB]
Definition: ppm.c:31
#define RssiValid()
RssiValid test macro.
Definition: ppm.c:48
static void send_ppm(struct transport_tx *trans, struct link_device *dev)
Definition: ppm.c:55
#define USEC_OF_RC_PPM_TICKS(_v)
Definition: ppm_arch.h:46
void radio_control_impl_event(void(*_received_frame_handler)(void))
RC event function with handler callback.
Definition: ppm.c:80
unsigned long uint32_t
Definition: types.h:18
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
struct RadioControl radio_control
Definition: radio_control.c:30
void ppm_arch_init(void)
Architecture dependant code.
Definition: ppm_arch.c:89
#define RC_OK
Definition: radio_control.h:56
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
#define RC_PPM_TICKS_OF_USEC(_v)
Definition: ppm_arch.h:44
void ppm_decode_frame_width(uint32_t ppm_width)
Decode a PPM frame from last width.
Definition: ppm.c:114
unsigned char uint8_t
Definition: types.h:14
static bool ppm_data_valid
Definition: ppm.c:39
static uint32_t ppm_last_pulse_time
Definition: ppm.c:38
uint8_t time_since_last_frame
Definition: radio_control.h:65
static uint8_t ppm_cur_pulse
Definition: ppm.c:37
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
uint8_t frame_cpt
Definition: radio_control.h:68
uint8_t frame_rate
Definition: radio_control.h:67
volatile bool ppm_frame_available
Definition: ppm.c:32
void ppm_decode_frame(uint32_t ppm_time)
Decode a PPM frame from global timer value.
Definition: ppm.c:99