OpenOCD
libjaylink-internal.h
Go to the documentation of this file.
1 /*
2  * This file is part of the libjaylink project.
3  *
4  * Copyright (C) 2014-2016 Marc Schink <jaylink-dev@marcschink.de>
5  *
6  * This program 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 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBJAYLINK_LIBJAYLINK_INTERNAL_H
21 #define LIBJAYLINK_LIBJAYLINK_INTERNAL_H
22 
23 #include <stddef.h>
24 #include <stdint.h>
25 #include <stdbool.h>
26 #include <stdarg.h>
27 #include <sys/types.h>
28 #ifdef _WIN32
29 #include <ws2tcpip.h>
30 #else
31 #include <sys/socket.h>
32 #include <arpa/inet.h>
33 #endif
34 
35 #ifdef HAVE_CONFIG_H
36 #include "config.h"
37 #endif
38 
39 #ifdef HAVE_LIBUSB
40 #include <libusb.h>
41 #endif
42 
43 #include "libjaylink.h"
44 
52 #if defined(_WIN32) || defined(__MSYS__) || defined(__CYGWIN__)
53 #define JAYLINK_PRIV
54 #else
55 #define JAYLINK_PRIV __attribute__ ((visibility ("hidden")))
56 #endif
57 
59 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
60 
62 #ifdef HAVE_LIBUSB
63 
64  struct libusb_context *usb_ctx;
65 #endif
66 
71  struct list *devs;
82 };
83 
88  size_t ref_count;
97  uint32_t serial_number;
100 #ifdef HAVE_LIBUSB
101 
102  struct libusb_device *usb_dev;
105 #endif
106 
114  char ipv4_address[INET_ADDRSTRLEN];
148  struct jaylink_hardware_version hw_version;
151 };
152 
162  uint8_t *buffer;
164  size_t buffer_size;
166  size_t read_length;
170  size_t read_pos;
175  size_t write_length;
182  size_t write_pos;
183 #ifdef HAVE_LIBUSB
184 
185  struct libusb_device_handle *usb_devh;
187  uint8_t interface_number;
189  uint8_t endpoint_in;
191  uint8_t endpoint_out;
192 #endif
193 
199  int sock;
200 };
201 
202 struct list {
203  void *data;
204  struct list *next;
205 };
206 
207 typedef bool (*list_compare_callback)(const void *data, const void *user_data);
208 
209 /*--- buffer.c --------------------------------------------------------------*/
210 
211 JAYLINK_PRIV void buffer_set_u16(uint8_t *buffer, uint16_t value,
212  size_t offset);
213 JAYLINK_PRIV uint16_t buffer_get_u16(const uint8_t *buffer, size_t offset);
214 JAYLINK_PRIV void buffer_set_u32(uint8_t *buffer, uint32_t value,
215  size_t offset);
216 JAYLINK_PRIV uint32_t buffer_get_u32(const uint8_t *buffer, size_t offset);
217 
218 /*--- device.c --------------------------------------------------------------*/
219 
221  struct jaylink_context *ctx);
222 
223 /*--- discovery_tcp.c -------------------------------------------------------*/
224 
226 
227 /*--- discovery_usb.c -------------------------------------------------------*/
228 
230 
231 /*--- list.c ----------------------------------------------------------------*/
232 
233 JAYLINK_PRIV struct list *list_prepend(struct list *list, void *data);
234 JAYLINK_PRIV struct list *list_remove(struct list *list, const void *data);
235 JAYLINK_PRIV struct list *list_find_custom(struct list *list,
236  list_compare_callback callback, const void *user_data);
237 JAYLINK_PRIV size_t list_length(struct list *list);
238 JAYLINK_PRIV void list_free(struct list *list);
239 
240 /*--- log.c -----------------------------------------------------------------*/
241 
242 JAYLINK_PRIV int log_vprintf(const struct jaylink_context *ctx,
243  enum jaylink_log_level level, const char *format, va_list args,
244  void *user_data);
245 JAYLINK_PRIV void log_err(const struct jaylink_context *ctx,
246  const char *format, ...);
247 JAYLINK_PRIV void log_warn(const struct jaylink_context *ctx,
248  const char *format, ...);
249 JAYLINK_PRIV void log_info(const struct jaylink_context *ctx,
250  const char *format, ...);
251 JAYLINK_PRIV void log_dbg(const struct jaylink_context *ctx,
252  const char *format, ...);
253 JAYLINK_PRIV void log_dbgio(const struct jaylink_context *ctx,
254  const char *format, ...);
255 
256 /*--- socket.c --------------------------------------------------------------*/
257 
258 JAYLINK_PRIV bool socket_close(int sock);
259 JAYLINK_PRIV bool socket_bind(int sock, const struct sockaddr *address,
260  size_t length);
261 JAYLINK_PRIV bool socket_send(int sock, const void *buffer, size_t *length,
262  int flags);
263 JAYLINK_PRIV bool socket_recv(int sock, void *buffer, size_t *length,
264  int flags);
265 JAYLINK_PRIV bool socket_sendto(int sock, const void *buffer, size_t *length,
266  int flags, const struct sockaddr *address,
267  size_t address_length);
268 JAYLINK_PRIV bool socket_recvfrom(int sock, void *buffer, size_t *length,
269  int flags, struct sockaddr *address, size_t *address_length);
270 JAYLINK_PRIV bool socket_set_option(int sock, int level, int option,
271  const void *value, size_t length);
272 
273 /*--- transport.c -----------------------------------------------------------*/
274 
278  size_t write_length, size_t read_length, bool has_command);
280  size_t length, bool has_command);
282  size_t length);
284  const uint8_t *buffer, size_t length);
286  uint8_t *buffer, size_t length);
287 
288 /*--- transport_usb.c -------------------------------------------------------*/
289 
293  struct jaylink_device_handle *devh, size_t write_length,
294  size_t read_length, bool has_command);
296  size_t length, bool has_command);
298  size_t length);
300  const uint8_t *buffer, size_t length);
302  uint8_t *buffer, size_t length);
303 
304 /*--- transport_tcp.c -------------------------------------------------------*/
305 
309  struct jaylink_device_handle *devh, size_t write_length,
310  size_t read_length, bool has_command);
312  size_t length, bool has_command);
314  size_t length);
316  const uint8_t *buffer, size_t length);
318  uint8_t *buffer, size_t length);
319 
320 #endif /* LIBJAYLINK_LIBJAYLINK_INTERNAL_H */
#define bool
Definition: types.h:58
uint32_t offset
Definition: arm_cti.c:179
static const char * product_name(const struct flash_bank *bank)
Definition: xcf.c:97
struct list * next