Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ppm.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2010 The Paparazzi Team
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #ifndef RC_PPM_H
25 #define RC_PPM_H
26 
27 #include "std.h"
28 
32 #include "subsystems/radio_control/ppm_arch.h"
33 /* must be implemented by arch dependant code */
34 extern void ppm_arch_init(void);
35 
40 #include "generated/radio.h"
41 
46 #define RADIO_CONTROL_NB_CHANNEL RADIO_CTL_NB
47 
51 #define PPM_PULSE_TYPE_POSITIVE 0
52 #define PPM_PULSE_TYPE_NEGATIVE 1
53 
55 extern volatile bool_t ppm_frame_available;
56 
61 #define RadioControlEvent(_received_frame_handler) { \
62  if (ppm_frame_available) { \
63  radio_control.frame_cpt++; \
64  radio_control.time_since_last_frame = 0; \
65  if (radio_control.radio_ok_cpt > 0) { \
66  radio_control.radio_ok_cpt--; \
67  } else { \
68  radio_control.status = RC_OK; \
69  NormalizePpmIIR(ppm_pulses,radio_control); \
70  _received_frame_handler(); \
71  } \
72  ppm_frame_available = FALSE; \
73  } \
74 }
75 
79 extern uint8_t ppm_cur_pulse;
81 extern bool_t ppm_data_valid;
82 
89 #define DecodePpmFrame(_ppm_time) { \
90  uint32_t length = _ppm_time - ppm_last_pulse_time; \
91  ppm_last_pulse_time = _ppm_time; \
92  \
93  if (ppm_cur_pulse == PPM_NB_CHANNEL) { \
94  if (length > RC_PPM_TICKS_OF_USEC(PPM_SYNC_MIN_LEN) && \
95  length < RC_PPM_TICKS_OF_USEC(PPM_SYNC_MAX_LEN)) { \
96  if (ppm_data_valid) { \
97  ppm_frame_available = TRUE; \
98  ppm_data_valid = FALSE; \
99  } \
100  ppm_cur_pulse = 0; \
101  } \
102  else { \
103  ppm_data_valid = FALSE; \
104  } \
105  } \
106  else { \
107  if (length > RC_PPM_TICKS_OF_USEC(PPM_DATA_MIN_LEN) && \
108  length < RC_PPM_TICKS_OF_USEC(PPM_DATA_MAX_LEN)) { \
109  ppm_pulses[ppm_cur_pulse] = length; \
110  ppm_cur_pulse++; \
111  if (ppm_cur_pulse == PPM_NB_CHANNEL) { \
112  ppm_data_valid = TRUE; \
113  } \
114  } \
115  else { \
116  ppm_cur_pulse = PPM_NB_CHANNEL; \
117  ppm_data_valid = FALSE; \
118  } \
119  } \
120 }
121 
122 #endif /* RC_PPM_H */
unsigned short uint16_t
Definition: types.h:16
void ppm_arch_init(void)
Architecture dependant code.
Definition: ppm_arch.c:31
uint8_t ppm_cur_pulse
State machine for decoding ppm frames.
Definition: ppm_arch.c:27
#define RADIO_CONTROL_NB_CHANNEL
Generated code holding the description of a given transmitter.
Definition: ppm.h:46
uint32_t ppm_last_pulse_time
Definition: ppm_arch.c:28
bool_t ppm_data_valid
Definition: ppm_arch.c:29
unsigned long uint32_t
Definition: types.h:18
uint16_t ppm_pulses[RADIO_CONTROL_NB_CHANNEL]
Definition: ppm.c:27
unsigned char uint8_t
Definition: types.h:14
volatile bool_t ppm_frame_available
Definition: ppm.c:28