OpenOCD
usbtojtagraw.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2009 - 2010 by Simon Qian <SimonQian@SimonQian.com> *
5  ***************************************************************************/
6 
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 
11 #include <string.h>
12 
13 #include "../versaloon_include.h"
14 #include "../versaloon.h"
15 #include "../versaloon_internal.h"
16 #include "usbtoxxx.h"
17 #include "usbtoxxx_internal.h"
18 
19 RESULT usbtojtagraw_init(uint8_t interface_index)
20 {
21  return usbtoxxx_init_command(USB_TO_JTAG_RAW, interface_index);
22 }
23 
24 RESULT usbtojtagraw_fini(uint8_t interface_index)
25 {
26  return usbtoxxx_fini_command(USB_TO_JTAG_RAW, interface_index);
27 }
28 
29 RESULT usbtojtagraw_config(uint8_t interface_index, uint32_t khz)
30 {
31  uint8_t cfg_buf[4];
32 
33 #if PARAM_CHECK
34  if (interface_index > 7) {
35  LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
36  return ERROR_FAIL;
37  }
38 #endif
39 
40  SET_LE_U32(&cfg_buf[0], khz);
41 
42  return usbtoxxx_conf_command(USB_TO_JTAG_RAW, interface_index, cfg_buf, 4);
43 }
44 
45 RESULT usbtojtagraw_execute(uint8_t interface_index, uint8_t *tdi,
46  uint8_t *tms, uint8_t *tdo, uint32_t bitlen)
47 {
48  uint16_t bytelen;
49 
50 #if PARAM_CHECK
51  if (interface_index > 7) {
52  LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
53  return ERROR_FAIL;
54  }
55 #endif
56 
57  if (bitlen > 8 * 0xFFFF)
58  return ERROR_FAIL;
59  bytelen = (uint16_t)((bitlen + 7) >> 3);
60 
61  SET_LE_U32(&versaloon_cmd_buf[0], bitlen);
62  memcpy(versaloon_cmd_buf + 4, tdi, bytelen);
63  memcpy(versaloon_cmd_buf + 4 + bytelen, tms, bytelen);
64 
65  return usbtoxxx_inout_command(USB_TO_JTAG_RAW, interface_index,
66  versaloon_cmd_buf, 4 + bytelen * 2, bytelen, tdo, 0, bytelen, 0);
67 }
#define ERROR_FAIL
Definition: log.h:161
RESULT usbtojtagraw_config(uint8_t interface_index, uint32_t khz)
Definition: usbtojtagraw.c:29
RESULT usbtojtagraw_execute(uint8_t interface_index, uint8_t *tdi, uint8_t *tms, uint8_t *tdo, uint32_t bitlen)
Definition: usbtojtagraw.c:45
RESULT usbtojtagraw_fini(uint8_t interface_index)
Definition: usbtojtagraw.c:24
RESULT usbtojtagraw_init(uint8_t interface_index)
Definition: usbtojtagraw.c:19
#define usbtoxxx_conf_command(type, port, cmdbuf, cmdlen)
#define usbtoxxx_inout_command(type, port, cmdbuf, cmdlen, retlen, wantbuf, wantpos, wantlen, c)
#define USB_TO_JTAG_RAW
#define usbtoxxx_init_command(type, port)
#define usbtoxxx_fini_command(type, port)
uint8_t * versaloon_cmd_buf
Definition: versaloon.c:22
#define RESULT
#define ERRMSG_INVALID_INTERFACE_NUM
#define LOG_BUG
#define SET_LE_U32(p, v)