Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 #include "modules/core/abi.h"
31 
32 #if RADIO_CONTROL_NB_CHANNEL < RADIO_CTL_NB
33 #error "RADIO_CONTROL_NB_CHANNEL mustn't be lower than number of channels in radio file."
34 #endif
35 
36 uint16_t ppm_pulses[RADIO_CTL_NB];
37 volatile bool ppm_frame_available;
38 
39 /*
40  * State machine for decoding ppm frames
41  */
44 static bool ppm_data_valid;
45 
52 #ifndef RssiValid
53 #define RssiValid() TRUE
54 #endif
55 
56 
57 #if PERIODIC_TELEMETRY
59 
60 static void send_ppm(struct transport_tx *trans, struct link_device *dev)
61 {
62  uint16_t ppm_pulses_usec[RADIO_CTL_NB];
63  for (int i = 0; i < RADIO_CTL_NB; i++) {
64  ppm_pulses_usec[i] = USEC_OF_RC_PPM_TICKS(ppm_pulses[i]);
65  }
66  pprz_msg_send_PPM(trans, dev, AC_ID,
67  &radio_control.frame_rate, RADIO_CTL_NB, ppm_pulses_usec);
68 }
69 #endif
70 
71 void ppm_init(void)
72 {
73  ppm_frame_available = false;
75  ppm_cur_pulse = RADIO_CTL_NB;
76  ppm_data_valid = false;
77  radio_control.nb_channel = RADIO_CTL_NB;
78 
79  ppm_arch_init();
80 
81 #if PERIODIC_TELEMETRY
83 #endif
84 }
85 
86 void ppm_event(void)
87 {
88  if (ppm_frame_available) {
91  if (radio_control.radio_ok_cpt > 0) {
93  } else {
95  NormalizePpmIIR(ppm_pulses, radio_control);
96  AbiSendMsgRADIO_CONTROL(RADIO_CONTROL_PPM_ID, &radio_control);
97  }
98  ppm_frame_available = false;
99  }
100 }
101 
106 {
107  uint32_t length = ppm_time - ppm_last_pulse_time;
108  ppm_last_pulse_time = ppm_time;
109 
110  ppm_decode_frame_width(length);
111 }
112 
121 {
122  if (ppm_cur_pulse == RADIO_CTL_NB) {
123  if (ppm_width > RC_PPM_TICKS_OF_USEC(PPM_SYNC_MIN_LEN) &&
124  ppm_width < RC_PPM_TICKS_OF_USEC(PPM_SYNC_MAX_LEN)) {
125  if (ppm_data_valid && RssiValid()) {
126  ppm_frame_available = true;
127  ppm_data_valid = false;
128  }
129  ppm_cur_pulse = 0;
130  } else {
131  ppm_data_valid = false;
132  }
133  } else {
134  if (ppm_width > RC_PPM_TICKS_OF_USEC(PPM_DATA_MIN_LEN) &&
135  ppm_width < RC_PPM_TICKS_OF_USEC(PPM_DATA_MAX_LEN)) {
136  ppm_pulses[ppm_cur_pulse] = ppm_width;
137  ppm_cur_pulse++;
138  if (ppm_cur_pulse == RADIO_CTL_NB) {
139  ppm_data_valid = true;
140  }
141  } else {
142  ppm_cur_pulse = RADIO_CTL_NB;
143  ppm_data_valid = false;
144  }
145  }
146 }
Main include for ABI (AirBorneInterface).
#define RADIO_CONTROL_PPM_ID
void ppm_arch_init(void)
Architecture dependant code.
Definition: ppm_arch.c:90
#define USEC_OF_RC_PPM_TICKS(_v)
Definition: ppm_arch.h:46
#define RC_PPM_TICKS_OF_USEC(_v)
Definition: ppm_arch.h:44
static uint32_t ppm_last_pulse_time
Definition: ppm.c:43
static bool ppm_data_valid
Definition: ppm.c:44
static void send_ppm(struct transport_tx *trans, struct link_device *dev)
Definition: ppm.c:60
void ppm_decode_frame_width(uint32_t ppm_width)
Decode a PPM frame from last width.
Definition: ppm.c:120
void ppm_init(void)
RC init function.
Definition: ppm.c:71
uint16_t ppm_pulses[RADIO_CTL_NB]
Definition: ppm.c:36
void ppm_decode_frame(uint32_t ppm_time)
Decode a PPM frame from global timer value.
Definition: ppm.c:105
void ppm_event(void)
RC event function.
Definition: ppm.c:86
volatile bool ppm_frame_available
Definition: ppm.c:37
static uint8_t ppm_cur_pulse
Definition: ppm.c:42
#define RssiValid()
RssiValid test macro.
Definition: ppm.c:53
struct RadioControl radio_control
Definition: radio_control.c:33
Generic interface for radio control modules.
uint8_t time_since_last_frame
Definition: radio_control.h:62
uint8_t status
Definition: radio_control.h:61
uint8_t radio_ok_cpt
Definition: radio_control.h:63
uint8_t frame_rate
Definition: radio_control.h:64
uint8_t frame_cpt
Definition: radio_control.h:65
#define RC_OK
Definition: radio_control.h:49
uint8_t nb_channel
Definition: radio_control.h:66
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98