PX4 Firmware
PX4 Autopilot Software http://px4.io
drv_input_capture.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2016 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file Input capture interface.
36  *
37  * Input capture interface utilizes the FMU_AUX_PINS to time stamp
38  * an edge.
39  */
40 
41 #pragma once
42 
43 #include <px4_platform_common/defines.h>
44 #include <stdint.h>
45 #include <sys/ioctl.h>
46 
47 #include "drv_hrt.h"
48 
50 
51 /**
52  * Path for the default capture input device.
53  *
54  *
55  */
56 #define INPUT_CAPTURE_BASE_DEVICE_PATH "/dev/capture"
57 #define INPUT_CAPTURE0_DEVICE_PATH "/dev/capture0"
58 
59 typedef void (*capture_callback_t)(void *context, uint32_t chan_index,
60  hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow);
61 
62 /**
63  * Maximum number of PWM input channels supported by the device.
64  */
65 #ifndef INPUT_CAPTURE_MAX_CHANNELS
66 #define INPUT_CAPTURE_MAX_CHANNELS 6
67 #endif
68 
69 typedef uint16_t capture_filter_t;
70 typedef uint16_t capture_t;
71 
72 typedef enum input_capture_edge {
73  Disabled = 0,
74  Rising = 1,
75  Falling = 2,
76  Both = 3
78 
79 typedef struct input_capture_element_t {
82  bool overrun;
84 
85 typedef struct input_capture_stats_t {
87  uint32_t overflows;
88  uint32_t last_edge;
90  uint16_t latnecy;
92 
93 /**
94  * input capture values for a channel
95  *
96  * This allows for Capture input driver values to be set without a
97  * param_get() dependency
98  */
99 typedef struct input_capture_config_t {
100  uint8_t channel;
104  void *context;
105 
107 
108 /*
109  * ioctl() definitions
110  *
111  * Note that ioctls and ORB updates should not be mixed, as the
112  * behaviour of the system in this case is not defined.
113  */
114 #define _INPUT_CAP_BASE 0x2d00
115 
116 /** Set Enable a channel arg is pointer to input_capture_config
117  * with all parameters set.
118  * edge controls the mode: Disable will free the capture channel.
119  * (When edge is Disabled call back and context are ignored)
120  * context may be null. If callback and context are null the
121  * callback will be disabled.
122  * */
123 
124 #define INPUT_CAP_SET _PX4_IOC(_INPUT_CAP_BASE, 0)
125 
126 /** Set the call back on a capture channel - arg is pointer to
127  * input_capture_config with channel call back and context set
128  * context may be null. If both ate null the call back will be
129  * disabled */
130 #define INPUT_CAP_SET_CALLBACK _PX4_IOC(_INPUT_CAP_BASE, 1)
131 
132 /** Get the call back on a capture channel - arg is pointer to
133  * input_capture_config with channel set.
134  */
135 #define INPUT_CAP_GET_CALLBACK _PX4_IOC(_INPUT_CAP_BASE, 2)
136 
137 /** Set Edge a channel arg is pointer to input_capture_config
138  * with channel and edge set */
139 #define INPUT_CAP_SET_EDGE _PX4_IOC(_INPUT_CAP_BASE, 3)
140 
141 /** Get Edge for a channel arg is pointer to input_capture_config
142  * with channel set */
143 #define INPUT_CAP_GET_EDGE _PX4_IOC(_INPUT_CAP_BASE, 4)
144 
145 /** Set Filter input filter channel arg is pointer to input_capture_config
146  * with channel and filter set */
147 #define INPUT_CAP_SET_FILTER _PX4_IOC(_INPUT_CAP_BASE, 5)
148 
149 /** Set Filter input filter channel arg is pointer to input_capture_config
150  * with channel set */
151 #define INPUT_CAP_GET_FILTER _PX4_IOC(_INPUT_CAP_BASE, 6)
152 
153 /** Get the number of capture in *(unsigned *)arg */
154 #define INPUT_CAP_GET_COUNT _PX4_IOC(_INPUT_CAP_BASE, 7)
155 
156 /** Set the number of capture in (unsigned)arg - allows change of
157  * split between servos and capture */
158 #define INPUT_CAP_SET_COUNT _PX4_IOC(_INPUT_CAP_BASE, 8)
159 
160 /** Get channel stats - arg is pointer to input_capture_config
161  * with channel set.
162  */
163 #define INPUT_CAP_GET_STATS _PX4_IOC(_INPUT_CAP_BASE, 9)
164 
165 /** Get channel stats - arg is pointer to input_capture_config
166  * with channel set.
167  */
168 #define INPUT_CAP_GET_CLR_STATS _PX4_IOC(_INPUT_CAP_BASE, 10)
169 
170 /*
171  *
172  *
173  * WARNING WARNING WARNING! DO NOT EXCEED 31 IN IOC INDICES HERE!
174  *
175  *
176  */
177 
179  capture_callback_t callback, void *context);
180 
181 __EXPORT int up_input_capture_get_filter(unsigned channel, capture_filter_t *filter);
182 __EXPORT int up_input_capture_set_filter(unsigned channel, capture_filter_t filter);
183 
186 __EXPORT int up_input_capture_get_callback(unsigned channel, capture_callback_t *callback, void **context);
187 __EXPORT int up_input_capture_set_callback(unsigned channel, capture_callback_t callback, void *context);
188 __EXPORT int up_input_capture_get_stats(unsigned channel, input_capture_stats_t *stats, bool clear);
__EXPORT int up_input_capture_set_callback(unsigned channel, capture_callback_t callback, void *context)
void(* capture_callback_t)(void *context, uint32_t chan_index, hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow)
#define __END_DECLS
Definition: visibility.h:59
uint16_t capture_t
struct input_capture_element_t input_capture_element_t
input_capture_edge edge
Definition: I2C.hpp:51
__EXPORT int up_input_capture_set_trigger(unsigned channel, input_capture_edge edge)
struct input_capture_config_t input_capture_config_t
input capture values for a channel
High-resolution timer with callouts and timekeeping.
__EXPORT int up_input_capture_get_trigger(unsigned channel, input_capture_edge *edge)
uint16_t capture_filter_t
__EXPORT int up_input_capture_get_callback(unsigned channel, capture_callback_t *callback, void **context)
__EXPORT int up_input_capture_get_filter(unsigned channel, capture_filter_t *filter)
#define __BEGIN_DECLS
Definition: visibility.h:58
__EXPORT int up_input_capture_set(unsigned channel, input_capture_edge edge, capture_filter_t filter, capture_callback_t callback, void *context)
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
input capture values for a channel
capture_callback_t callback
__EXPORT int up_input_capture_get_stats(unsigned channel, input_capture_stats_t *stats, bool clear)
__EXPORT int up_input_capture_set_filter(unsigned channel, capture_filter_t filter)
input_capture_edge edge
struct input_capture_stats_t input_capture_stats_t
input_capture_edge