Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
27
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
36uint16_t ppm_pulses[RADIO_CTL_NB];
37volatile bool ppm_frame_available;
38
39/*
40 * State machine for decoding ppm frames
41 */
44static bool ppm_data_valid;
45
52#ifndef RssiValid
53#define RssiValid() TRUE
54#endif
55
56
57#if PERIODIC_TELEMETRY
59
60static 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
71void 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
80
81#if PERIODIC_TELEMETRY
83#endif
84}
85
86void ppm_event(void)
87{
89 radio_control.frame_cpt++;
90 radio_control.time_since_last_frame = 0;
91 if (radio_control.radio_ok_cpt > 0) {
92 radio_control.radio_ok_cpt--;
93 } else {
94 radio_control.status = RC_OK;
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
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;
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
uint32_t ppm_last_pulse_time
Definition ppm_arch.c:36
bool ppm_data_valid
Definition ppm_arch.c:37
void ppm_arch_init(void)
Architecture dependant code.
Definition ppm_arch.c:90
uint8_t ppm_cur_pulse
Definition ppm_arch.c:35
#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 struct uart_periph * dev
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
#define RssiValid()
RssiValid test macro.
Definition ppm.c:53
struct RadioControl radio_control
Generic interface for radio control modules.
#define RC_OK
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_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.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.