Paparazzi UAS  v5.8.2_stable-0-g6260b7c
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_t ppm_frame_available;
33 
34 /*
35  * State machine for decoding ppm frames
36  */
39 static bool_t 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 {
70  ppm_cur_pulse = RADIO_CTL_NB;
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  }
93  }
94 }
95 
104 {
105  uint32_t length = ppm_time - ppm_last_pulse_time;
106  ppm_last_pulse_time = ppm_time;
107 
108  if (ppm_cur_pulse == RADIO_CTL_NB) {
109  if (length > RC_PPM_TICKS_OF_USEC(PPM_SYNC_MIN_LEN) &&
110  length < RC_PPM_TICKS_OF_USEC(PPM_SYNC_MAX_LEN)) {
111  if (ppm_data_valid && RssiValid()) {
114  }
115  ppm_cur_pulse = 0;
116  } else {
118  }
119  } else {
120  if (length > RC_PPM_TICKS_OF_USEC(PPM_DATA_MIN_LEN) &&
121  length < RC_PPM_TICKS_OF_USEC(PPM_DATA_MAX_LEN)) {
122  ppm_pulses[ppm_cur_pulse] = length;
123  ppm_cur_pulse++;
124  if (ppm_cur_pulse == RADIO_CTL_NB) {
126  }
127  } else {
128  ppm_cur_pulse = RADIO_CTL_NB;
130  }
131  }
132 }
unsigned short uint16_t
Definition: types.h:16
void radio_control_impl_init(void)
Definition: ppm.c:66
Generic transmission transport header.
Definition: transport.h:89
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t radio_ok_cpt
Definition: radio_control.h:55
void ppm_arch_init(void)
Architecture dependant code.
Definition: ppm_arch.c:32
uint8_t status
Definition: radio_control.h:53
uint16_t ppm_pulses[RADIO_CTL_NB]
Definition: ppm.c:31
#define RssiValid()
RssiValid test macro.
Definition: ppm.c:48
static bool_t ppm_data_valid
Definition: ppm.c:39
value send_ppm(value unit)
Definition: ppm_arch.c:85
#define RC_PPM_TICKS_OF_USEC(_v)
On tiny (and booz) the ppm counter is running at the same speed as the systic counter.
Definition: ppm_arch.h:43
#define FALSE
Definition: std.h:5
#define TRUE
Definition: std.h:4
void radio_control_impl_event(void(*_received_frame_handler)(void))
RC event function with handler callback.
Definition: ppm.c:80
volatile bool_t ppm_frame_available
Definition: ppm.c:32
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
#define USEC_OF_RC_PPM_TICKS(_v)
Definition: ppm_arch.h:45
#define RC_OK
Definition: radio_control.h:48
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
unsigned char uint8_t
Definition: types.h:14
static uint32_t ppm_last_pulse_time
Definition: ppm.c:38
uint8_t time_since_last_frame
Definition: radio_control.h:54
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:57
uint8_t frame_rate
Definition: radio_control.h:56
void ppm_decode_frame(uint32_t ppm_time)
Decode a PPM frame.
Definition: ppm.c:103