aboutsummaryrefslogtreecommitdiff
path: root/src/jtag/aice/aice_usb.h
blob: 893ba38c5ce510c8dd726a1d102ae9fdaec8cc0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/***************************************************************************
 *   Copyright (C) 2013 by Andes Technology                                *
 *   Hsiangkai Wang <hkwang@andestech.com>                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/
#ifndef __AICE_USB_H__
#define __AICE_USB_H__

#include "aice_port.h"

/* AICE USB timeout value */
#define AICE_USB_TIMEOUT				5000

/* AICE USB buffer size */
#define AICE_IN_BUFFER_SIZE				2048
#define AICE_OUT_BUFFER_SIZE			2048
#define AICE_IN_PACKETS_BUFFER_SIZE		2048
#define AICE_OUT_PACKETS_BUFFER_SIZE	2048
#define AICE_IN_BATCH_COMMAND_SIZE		512
#define AICE_OUT_BATCH_COMMAND_SIZE		512
#define AICE_IN_PACK_COMMAND_SIZE		2048
#define AICE_OUT_PACK_COMMAND_SIZE		2048

/* Constants for AICE command READ_CTRL */
#define AICE_READ_CTRL_GET_ICE_STATE		0x00
#define AICE_READ_CTRL_GET_HARDWARE_VERSION	0x01
#define AICE_READ_CTRL_GET_FPGA_VERSION		0x02
#define AICE_READ_CTRL_GET_FIRMWARE_VERSION	0x03
#define AICE_READ_CTRL_GET_JTAG_PIN_STATUS	0x04
#define AICE_READ_CTRL_BATCH_BUF_INFO		0x22
#define AICE_READ_CTRL_BATCH_STATUS			0x23
#define AICE_READ_CTRL_BATCH_BUF0_STATE		0x31
#define AICE_READ_CTRL_BATCH_BUF4_STATE		0x39
#define AICE_READ_CTRL_BATCH_BUF5_STATE		0x3b

/* Constants for AICE command WRITE_CTRL */
#define AICE_WRITE_CTRL_TCK_CONTROL				0x00
#define AICE_WRITE_CTRL_JTAG_PIN_CONTROL		0x01
#define AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS	0x02
#define AICE_WRITE_CTRL_RESERVED				0x03
#define AICE_WRITE_CTRL_JTAG_PIN_STATUS			0x04
#define AICE_WRITE_CTRL_CUSTOM_DELAY			0x0d
#define AICE_WRITE_CTRL_BATCH_CTRL				0x20
#define AICE_WRITE_CTRL_BATCH_ITERATION			0x21
#define AICE_WRITE_CTRL_BATCH_DIM_SIZE			0x22
#define AICE_WRITE_CTRL_BATCH_CMD_BUF0_CTRL		0x30
#define AICE_WRITE_CTRL_BATCH_DATA_BUF0_CTRL	0x38
#define AICE_WRITE_CTRL_BATCH_DATA_BUF1_CTRL	0x3a

#define AICE_BATCH_COMMAND_BUFFER_0			0x0
#define AICE_BATCH_COMMAND_BUFFER_1			0x1
#define AICE_BATCH_COMMAND_BUFFER_2			0x2
#define AICE_BATCH_COMMAND_BUFFER_3			0x3
#define AICE_BATCH_DATA_BUFFER_0			0x4
#define AICE_BATCH_DATA_BUFFER_1			0x5
#define AICE_BATCH_DATA_BUFFER_2			0x6
#define AICE_BATCH_DATA_BUFFER_3			0x7

/* Constants for AICE command WRITE_CTRL:TCK_CONTROL */
#define AICE_TCK_CONTROL_TCK3048		0x08

/* Constants for AICE command WRITE_CTRL:JTAG_PIN_CONTROL */
#define AICE_JTAG_PIN_CONTROL_SRST		0x01
#define AICE_JTAG_PIN_CONTROL_TRST		0x02
#define AICE_JTAG_PIN_CONTROL_STOP		0x04
#define AICE_JTAG_PIN_CONTROL_RESTART	0x08

/* Constants for AICE command WRITE_CTRL:TCK_CONTROL */
#define AICE_TCK_CONTROL_TCK_SCAN		0x10

/* Custom SRST/DBGI/TRST */
#define AICE_CUSTOM_DELAY_SET_SRST		0x01
#define AICE_CUSTOM_DELAY_CLEAN_SRST	0x02
#define AICE_CUSTOM_DELAY_SET_DBGI		0x04
#define AICE_CUSTOM_DELAY_CLEAN_DBGI	0x08
#define AICE_CUSTOM_DELAY_SET_TRST		0x10
#define AICE_CUSTOM_DELAY_CLEAN_TRST	0x20

struct aice_usb_handler_s {
	unsigned int usb_read_ep;
	unsigned int usb_write_ep;
	struct jtag_libusb_device_handle *usb_handle;
};

struct cache_info {
	uint32_t set;
	uint32_t way;
	uint32_t line_size;

	uint32_t log2_set;
	uint32_t log2_line_size;
};

struct aice_nds32_info {
	uint32_t edm_version;
	uint32_t r0_backup;
	uint32_t r1_backup;
	uint32_t host_dtr_backup;
	uint32_t target_dtr_backup;
	uint32_t edmsw_backup;
	uint32_t edm_ctl_backup;
	bool debug_under_dex_on;
	bool dex_use_psw_on;
	bool host_dtr_valid;
	bool target_dtr_valid;
	enum nds_memory_access access_channel;
	enum nds_memory_select memory_select;
	enum aice_target_state_s core_state;
	bool cache_init;
	struct cache_info icache;
	struct cache_info dcache;
};

extern struct aice_port_api_s aice_usb_api;

int aice_read_ctrl(uint32_t address, uint32_t *data);
int aice_write_ctrl(uint32_t address, uint32_t data);

#endif