OpenOCD
jtag/drivers/libjaylink/libjaylink/transport.c
Go to the documentation of this file.
1 /*
2  * This file is part of the libjaylink project.
3  *
4  * Copyright (C) 2014-2015 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 #include <stdint.h>
22 #include <stdbool.h>
23 #include <string.h>
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 #include "libjaylink.h"
29 #include "libjaylink-internal.h"
30 
50 {
51  int ret;
52 
53  switch (devh->dev->iface) {
54 #ifdef HAVE_LIBUSB
55  case JAYLINK_HIF_USB:
56  ret = transport_usb_open(devh);
57  break;
58 #endif
59  case JAYLINK_HIF_TCP:
60  ret = transport_tcp_open(devh);
61  break;
62  default:
63  log_err(devh->dev->ctx, "BUG: Invalid host interface: %u.",
64  devh->dev->iface);
65  return JAYLINK_ERR;
66  }
67 
68  return ret;
69 }
70 
83 {
84  int ret;
85 
86  switch (devh->dev->iface) {
87 #ifdef HAVE_LIBUSB
88  case JAYLINK_HIF_USB:
89  ret = transport_usb_close(devh);
90  break;
91 #endif
92  case JAYLINK_HIF_TCP:
93  ret = transport_tcp_close(devh);
94  break;
95  default:
96  log_err(devh->dev->ctx, "BUG: Invalid host interface: %u.",
97  devh->dev->iface);
98  return JAYLINK_ERR;
99  }
100 
101  return ret;
102 }
103 
120  size_t length, bool has_command)
121 {
122  int ret;
123 
124  switch (devh->dev->iface) {
125 #ifdef HAVE_LIBUSB
126  case JAYLINK_HIF_USB:
127  ret = transport_usb_start_write(devh, length, has_command);
128  break;
129 #endif
130  case JAYLINK_HIF_TCP:
131  ret = transport_tcp_start_write(devh, length, has_command);
132  break;
133  default:
134  log_err(devh->dev->ctx, "BUG: Invalid host interface: %u.",
135  devh->dev->iface);
136  return JAYLINK_ERR;
137  }
138 
139  return ret;
140 }
141 
156  size_t length)
157 {
158  int ret;
159 
160  switch (devh->dev->iface) {
161 #ifdef HAVE_LIBUSB
162  case JAYLINK_HIF_USB:
163  ret = transport_usb_start_read(devh, length);
164  break;
165 #endif
166  case JAYLINK_HIF_TCP:
167  ret = transport_tcp_start_read(devh, length);
168  break;
169  default:
170  log_err(devh->dev->ctx, "BUG: Invalid host interface: %u.",
171  devh->dev->iface);
172  return JAYLINK_ERR;
173  }
174 
175  return ret;
176 }
177 
199  size_t write_length, size_t read_length, bool has_command)
200 {
201  int ret;
202 
203  switch (devh->dev->iface) {
204 #ifdef HAVE_LIBUSB
205  case JAYLINK_HIF_USB:
206  ret = transport_usb_start_write_read(devh, write_length,
207  read_length, has_command);
208  break;
209 #endif
210  case JAYLINK_HIF_TCP:
211  ret = transport_tcp_start_write_read(devh, write_length,
212  read_length, has_command);
213  break;
214  default:
215  log_err(devh->dev->ctx, "BUG: Invalid host interface: %u.",
216  devh->dev->iface);
217  return JAYLINK_ERR;
218  }
219 
220  return ret;
221 }
222 
247  const uint8_t *buffer, size_t length)
248 {
249  int ret;
250 
251  switch (devh->dev->iface) {
252 #ifdef HAVE_LIBUSB
253  case JAYLINK_HIF_USB:
254  ret = transport_usb_write(devh, buffer, length);
255  break;
256 #endif
257  case JAYLINK_HIF_TCP:
258  ret = transport_tcp_write(devh, buffer, length);
259  break;
260  default:
261  log_err(devh->dev->ctx, "BUG: Invalid host interface: %u.",
262  devh->dev->iface);
263  return JAYLINK_ERR;
264  }
265 
266  return ret;
267 }
268 
289  uint8_t *buffer, size_t length)
290 {
291  int ret;
292 
293  switch (devh->dev->iface) {
294 #ifdef HAVE_LIBUSB
295  case JAYLINK_HIF_USB:
296  ret = transport_usb_read(devh, buffer, length);
297  break;
298 #endif
299  case JAYLINK_HIF_TCP:
300  ret = transport_tcp_read(devh, buffer, length);
301  break;
302  default:
303  log_err(devh->dev->ctx, "BUG: Invalid host interface: %u.",
304  devh->dev->iface);
305  return JAYLINK_ERR;
306  }
307 
308  return ret;
309 }