OpenOCD
discovery.c
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
#include <stdlib.h>
21
22
#ifdef HAVE_CONFIG_H
23
#include "config.h"
24
#endif
25
#include "
libjaylink.h
"
26
#include "
libjaylink-internal.h
"
27
34
static
void
clear_discovery_list
(
struct
jaylink_context
*ctx)
35
{
36
struct
list
*item;
37
struct
list
*tmp;
38
struct
jaylink_device
*dev;
39
40
item = ctx->
discovered_devs
;
41
42
while
(item) {
43
dev = (
struct
jaylink_device
*)item->
data
;
44
jaylink_unref_device
(dev);
45
46
tmp = item;
47
item = item->
next
;
48
free(tmp);
49
}
50
51
ctx->
discovered_devs
=
NULL
;
52
}
53
72
JAYLINK_API
int
jaylink_discovery_scan
(
struct
jaylink_context
*
ctx
,
73
uint32_t ifaces)
74
{
75
int
ret;
76
77
if
(!ctx)
78
return
JAYLINK_ERR_ARG
;
79
80
if
(!ifaces)
81
ifaces =
JAYLINK_HIF_USB
|
JAYLINK_HIF_TCP
;
82
83
clear_discovery_list
(ctx);
84
85
#ifdef HAVE_LIBUSB
86
if
(ifaces &
JAYLINK_HIF_USB
) {
87
ret =
discovery_usb_scan
(ctx);
88
89
if
(ret !=
JAYLINK_OK
) {
90
log_err
(ctx,
"USB device discovery failed."
);
91
return
ret;
92
}
93
}
94
#endif
95
96
if
(ifaces &
JAYLINK_HIF_TCP
) {
97
ret =
discovery_tcp_scan
(ctx);
98
99
if
(ret !=
JAYLINK_OK
) {
100
log_err
(ctx,
"TCP/IP device discovery failed."
);
101
return
ret;
102
}
103
}
104
105
return
JAYLINK_OK
;
106
}
clear_discovery_list
static void clear_discovery_list(struct jaylink_context *ctx)
Definition:
discovery.c:34
discovery_usb_scan
JAYLINK_PRIV int discovery_usb_scan(struct jaylink_context *ctx)
Definition:
discovery_usb.c:250
JAYLINK_OK
No error.
Definition:
libjaylink.h:46
jaylink_context::discovered_devs
struct list * discovered_devs
List of recently discovered devices.
Definition:
libjaylink-internal.h:73
log_err
JAYLINK_PRIV void log_err(const struct jaylink_context *ctx, const char *format,...)
Definition:
jtag/drivers/libjaylink/libjaylink/log.c:194
JAYLINK_HIF_USB
Universal Serial Bus (USB).
Definition:
libjaylink.h:104
JAYLINK_ERR_ARG
Invalid argument.
Definition:
libjaylink.h:50
jaylink_device
Opaque structure representing a device.
Definition:
libjaylink-internal.h:84
jaylink_context
Opaque structure representing a libjaylink context.
Definition:
libjaylink-internal.h:61
list::data
void * data
Definition:
libjaylink-internal.h:203
libjaylink-internal.h
Internal libjaylink header file.
jaylink_device::ctx
struct jaylink_context * ctx
libjaylink context.
Definition:
libjaylink-internal.h:86
JAYLINK_HIF_TCP
Transmission Control Protocol (TCP).
Definition:
libjaylink.h:106
discovery_tcp_scan
JAYLINK_PRIV int discovery_tcp_scan(struct jaylink_context *ctx)
Definition:
discovery_tcp.c:229
libjaylink.h
Public libjaylink header file to be used by applications.
list
Definition:
libjaylink-internal.h:202
jaylink_discovery_scan
JAYLINK_API int jaylink_discovery_scan(struct jaylink_context *ctx, uint32_t ifaces)
Scan for devices.
Definition:
discovery.c:72
JAYLINK_API
#define JAYLINK_API
Macro to mark public libjaylink API symbol.
Definition:
libjaylink.h:429
jaylink_unref_device
JAYLINK_API void jaylink_unref_device(struct jaylink_device *dev)
Decrement the reference count of a device.
Definition:
device.c:536
NULL
#define NULL
Definition:
usb.h:27
list::next
struct list * next
Definition:
libjaylink-internal.h:204
src
jtag
drivers
libjaylink
libjaylink
discovery.c
Generated by
1.8.13