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
ppm.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef RC_PPM_H
23 #define RC_PPM_H
24 
25 #include "std.h"
26 
30 #include "subsystems/radio_control/ppm_arch.h"
31 /* must be implemented by arch dependant code */
32 extern void ppm_arch_init(void);
33 
38 #include "generated/radio.h"
39 
44 #define RADIO_CONTROL_NB_CHANNEL RADIO_CTL_NB
45 
49 #define PPM_PULSE_TYPE_POSITIVE 0
50 #define PPM_PULSE_TYPE_NEGATIVE 1
51 
53 extern volatile bool_t ppm_frame_available;
54 
59 #define RadioControlEvent(_received_frame_handler) { \
60  if (ppm_frame_available) { \
61  radio_control.frame_cpt++; \
62  radio_control.time_since_last_frame = 0; \
63  if (radio_control.radio_ok_cpt > 0) { \
64  radio_control.radio_ok_cpt--; \
65  } else { \
66  radio_control.status = RC_OK; \
67  NormalizePpmIIR(ppm_pulses,radio_control); \
68  _received_frame_handler(); \
69  } \
70  ppm_frame_available = FALSE; \
71  } \
72 }
73 
77 extern uint8_t ppm_cur_pulse;
79 extern bool_t ppm_data_valid;
80 
87 #ifndef RssiValid
88 #define RssiValid() TRUE
89 #endif
90 
97 #define DecodePpmFrame(_ppm_time) { \
98  uint32_t length = _ppm_time - ppm_last_pulse_time; \
99  ppm_last_pulse_time = _ppm_time; \
100  \
101  if (ppm_cur_pulse == PPM_NB_CHANNEL) { \
102  if (length > RC_PPM_TICKS_OF_USEC(PPM_SYNC_MIN_LEN) && \
103  length < RC_PPM_TICKS_OF_USEC(PPM_SYNC_MAX_LEN)) { \
104  if (ppm_data_valid && RssiValid()) { \
105  ppm_frame_available = TRUE; \
106  ppm_data_valid = FALSE; \
107  } \
108  ppm_cur_pulse = 0; \
109  } \
110  else { \
111  ppm_data_valid = FALSE; \
112  } \
113  } \
114  else { \
115  if (length > RC_PPM_TICKS_OF_USEC(PPM_DATA_MIN_LEN) && \
116  length < RC_PPM_TICKS_OF_USEC(PPM_DATA_MAX_LEN)) { \
117  ppm_pulses[ppm_cur_pulse] = length; \
118  ppm_cur_pulse++; \
119  if (ppm_cur_pulse == PPM_NB_CHANNEL) { \
120  ppm_data_valid = TRUE; \
121  } \
122  } \
123  else { \
124  ppm_cur_pulse = PPM_NB_CHANNEL; \
125  ppm_data_valid = FALSE; \
126  } \
127  } \
128 }
129 
130 #endif /* RC_PPM_H */
unsigned short uint16_t
Definition: types.h:16
void ppm_arch_init(void)
Architecture dependant code.
Definition: ppm_arch.c:29
uint8_t ppm_cur_pulse
State machine for decoding ppm frames.
Definition: ppm_arch.c:25
#define RADIO_CONTROL_NB_CHANNEL
Generated code holding the description of a given transmitter.
Definition: ppm.h:44
uint32_t ppm_last_pulse_time
Definition: ppm_arch.c:26
bool_t ppm_data_valid
Definition: ppm_arch.c:27
unsigned long uint32_t
Definition: types.h:18
uint16_t ppm_pulses[RADIO_CONTROL_NB_CHANNEL]
Definition: ppm.c:25
unsigned char uint8_t
Definition: types.h:14
volatile bool_t ppm_frame_available
Definition: ppm.c:26