jtag/drivers/cmsis-dap-usb: fix cmsis_dap_serial
[openocd.git] / src / jtag / aice / aice_usb.h
blobadb027eaa1a486681554c2a25ff1c7b62bbae740
1 /***************************************************************************
2 * Copyright (C) 2013 by Andes Technology *
3 * Hsiangkai Wang <hkwang@andestech.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
19 ***************************************************************************/
20 #ifndef __AICE_USB_H__
21 #define __AICE_USB_H__
23 #include "aice_port.h"
25 /* AICE USB timeout value */
26 #define AICE_USB_TIMEOUT 5000
28 /* AICE USB buffer size */
29 #define AICE_IN_BUFFER_SIZE 2048
30 #define AICE_OUT_BUFFER_SIZE 2048
31 #define AICE_IN_PACKETS_BUFFER_SIZE 2048
32 #define AICE_OUT_PACKETS_BUFFER_SIZE 2048
33 #define AICE_IN_BATCH_COMMAND_SIZE 512
34 #define AICE_OUT_BATCH_COMMAND_SIZE 512
35 #define AICE_IN_PACK_COMMAND_SIZE 2048
36 #define AICE_OUT_PACK_COMMAND_SIZE 2048
38 /* Constants for AICE command READ_CTRL */
39 #define AICE_READ_CTRL_GET_ICE_STATE 0x00
40 #define AICE_READ_CTRL_GET_HARDWARE_VERSION 0x01
41 #define AICE_READ_CTRL_GET_FPGA_VERSION 0x02
42 #define AICE_READ_CTRL_GET_FIRMWARE_VERSION 0x03
43 #define AICE_READ_CTRL_GET_JTAG_PIN_STATUS 0x04
44 #define AICE_READ_CTRL_BATCH_BUF_INFO 0x22
45 #define AICE_READ_CTRL_BATCH_STATUS 0x23
46 #define AICE_READ_CTRL_BATCH_BUF0_STATE 0x31
47 #define AICE_READ_CTRL_BATCH_BUF4_STATE 0x39
48 #define AICE_READ_CTRL_BATCH_BUF5_STATE 0x3b
50 /* Constants for AICE command WRITE_CTRL */
51 #define AICE_WRITE_CTRL_TCK_CONTROL 0x00
52 #define AICE_WRITE_CTRL_JTAG_PIN_CONTROL 0x01
53 #define AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS 0x02
54 #define AICE_WRITE_CTRL_RESERVED 0x03
55 #define AICE_WRITE_CTRL_JTAG_PIN_STATUS 0x04
56 #define AICE_WRITE_CTRL_CUSTOM_DELAY 0x0d
57 #define AICE_WRITE_CTRL_BATCH_CTRL 0x20
58 #define AICE_WRITE_CTRL_BATCH_ITERATION 0x21
59 #define AICE_WRITE_CTRL_BATCH_DIM_SIZE 0x22
60 #define AICE_WRITE_CTRL_BATCH_CMD_BUF0_CTRL 0x30
61 #define AICE_WRITE_CTRL_BATCH_DATA_BUF0_CTRL 0x38
62 #define AICE_WRITE_CTRL_BATCH_DATA_BUF1_CTRL 0x3a
64 #define AICE_BATCH_COMMAND_BUFFER_0 0x0
65 #define AICE_BATCH_COMMAND_BUFFER_1 0x1
66 #define AICE_BATCH_COMMAND_BUFFER_2 0x2
67 #define AICE_BATCH_COMMAND_BUFFER_3 0x3
68 #define AICE_BATCH_DATA_BUFFER_0 0x4
69 #define AICE_BATCH_DATA_BUFFER_1 0x5
70 #define AICE_BATCH_DATA_BUFFER_2 0x6
71 #define AICE_BATCH_DATA_BUFFER_3 0x7
73 /* Constants for AICE command WRITE_CTRL:TCK_CONTROL */
74 #define AICE_TCK_CONTROL_TCK3048 0x08
76 /* Constants for AICE command WRITE_CTRL:JTAG_PIN_CONTROL */
77 #define AICE_JTAG_PIN_CONTROL_SRST 0x01
78 #define AICE_JTAG_PIN_CONTROL_TRST 0x02
79 #define AICE_JTAG_PIN_CONTROL_STOP 0x04
80 #define AICE_JTAG_PIN_CONTROL_RESTART 0x08
82 /* Constants for AICE command WRITE_CTRL:TCK_CONTROL */
83 #define AICE_TCK_CONTROL_TCK_SCAN 0x10
85 /* Custom SRST/DBGI/TRST */
86 #define AICE_CUSTOM_DELAY_SET_SRST 0x01
87 #define AICE_CUSTOM_DELAY_CLEAN_SRST 0x02
88 #define AICE_CUSTOM_DELAY_SET_DBGI 0x04
89 #define AICE_CUSTOM_DELAY_CLEAN_DBGI 0x08
90 #define AICE_CUSTOM_DELAY_SET_TRST 0x10
91 #define AICE_CUSTOM_DELAY_CLEAN_TRST 0x20
93 struct aice_usb_handler_s {
94 unsigned int usb_read_ep;
95 unsigned int usb_write_ep;
96 struct jtag_libusb_device_handle *usb_handle;
99 struct cache_info {
100 uint32_t set;
101 uint32_t way;
102 uint32_t line_size;
104 uint32_t log2_set;
105 uint32_t log2_line_size;
108 struct aice_nds32_info {
109 uint32_t edm_version;
110 uint32_t r0_backup;
111 uint32_t r1_backup;
112 uint32_t host_dtr_backup;
113 uint32_t target_dtr_backup;
114 uint32_t edmsw_backup;
115 uint32_t edm_ctl_backup;
116 bool debug_under_dex_on;
117 bool dex_use_psw_on;
118 bool host_dtr_valid;
119 bool target_dtr_valid;
120 enum nds_memory_access access_channel;
121 enum nds_memory_select memory_select;
122 enum aice_target_state_s core_state;
123 bool cache_init;
124 struct cache_info icache;
125 struct cache_info dcache;
128 extern struct aice_port_api_s aice_usb_api;
130 int aice_read_ctrl(uint32_t address, uint32_t *data);
131 int aice_write_ctrl(uint32_t address, uint32_t data);
133 #endif