Firmware
hx_stream.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012 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 
41 #ifndef _SYSTEMLIB_HX_STREAM_H
42 #define _SYSTEMLIB_HX_STREAM_H
43 
44 #include <sys/types.h>
45 
46 #include <perf/perf_counter.h>
47 
48 struct hx_stream;
49 typedef struct hx_stream *hx_stream_t;
50 
51 #define HX_STREAM_MAX_FRAME 64
52 
53 typedef void (* hx_stream_rx_callback)(void *arg, const void *data, size_t length);
54 
55 __BEGIN_DECLS
56 
68 __EXPORT extern hx_stream_t hx_stream_init(int fd,
69  hx_stream_rx_callback callback,
70  void *arg);
71 
77 __EXPORT extern void hx_stream_free(hx_stream_t stream);
78 
89 __EXPORT extern void hx_stream_set_counters(hx_stream_t stream,
90  perf_counter_t tx_frames,
91  perf_counter_t rx_frames,
92  perf_counter_t rx_errors);
93 
101 __EXPORT extern void hx_stream_reset(hx_stream_t stream);
102 
116 __EXPORT extern int hx_stream_start(hx_stream_t stream,
117  const void *data,
118  size_t count);
119 
130 __EXPORT extern int hx_stream_send_next(hx_stream_t stream);
131 
147 __EXPORT extern int hx_stream_send(hx_stream_t stream,
148  const void *data,
149  size_t count);
150 
157 __EXPORT extern void hx_stream_rx(hx_stream_t stream,
158  uint8_t c);
159 
160 __END_DECLS
161 
162 #endif
__EXPORT void hx_stream_rx(hx_stream_t stream, uint8_t c)
Handle a byte from the stream.
Definition: hx_stream.c:299
__EXPORT void hx_stream_set_counters(hx_stream_t stream, perf_counter_t tx_frames, perf_counter_t rx_frames, perf_counter_t rx_errors)
Set performance counters for the stream.
Definition: hx_stream.c:172
__EXPORT void hx_stream_free(hx_stream_t stream)
Free a hx_stream object.
Definition: hx_stream.c:161
__EXPORT int hx_stream_send_next(hx_stream_t stream)
Get the next byte to send for a stream.
Definition: hx_stream.c:210
Header common to all counters.
Definition: perf_counter.cpp:65
__EXPORT int hx_stream_start(hx_stream_t stream, const void *data, size_t count)
Prepare to send a frame.
Definition: hx_stream.c:194
Definition: I2C.hpp:51
__EXPORT int hx_stream_send(hx_stream_t stream, const void *data, size_t count)
Send a frame.
Definition: hx_stream.c:270
__BEGIN_DECLS __EXPORT hx_stream_t hx_stream_init(int fd, hx_stream_rx_callback callback, void *arg)
Allocate a new hx_stream object.
Definition: hx_stream.c:142
Definition: hx_stream.c:55
__EXPORT void hx_stream_reset(hx_stream_t stream)
Reset a stream.
Definition: hx_stream.c:183
Performance measuring tools.