]> git.sur5r.net Git - openocd/blob - src/target/arm_jtag.c
- added missing AT91RM9200 files
[openocd] / src / target / arm_jtag.c
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "arm_jtag.h"
25
26 #include "binarybuffer.h"
27 #include "log.h"
28 #include "jtag.h"
29
30 #include <stdlib.h>
31
32 int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr)
33 {
34         jtag_device_t *device = jtag_get_device(jtag_info->chain_pos);
35         
36         if (buf_get_u32(device->cur_instr, 0, device->ir_length) != new_instr)
37         {
38                 scan_field_t field;
39         
40                 field.device = jtag_info->chain_pos;
41                 field.num_bits = device->ir_length;
42                 field.out_value = calloc(CEIL(field.num_bits, 8), 1);
43                 buf_set_u32(field.out_value, 0, field.num_bits, new_instr);
44                 field.out_mask = NULL;
45                 field.in_value = NULL;
46                 field.in_check_value = NULL;
47                 field.in_check_mask = NULL;
48                 field.in_handler = NULL;
49                 field.in_handler_priv = NULL;
50                 
51                 jtag_add_ir_scan(1, &field, -1);
52                 
53                 free(field.out_value);
54         }
55         
56         return ERROR_OK;
57 }
58
59 int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain)
60 {
61         if(jtag_info->cur_scan_chain != new_scan_chain)
62         {
63                 scan_field_t field;
64                 
65                 field.device = jtag_info->chain_pos;
66                 field.num_bits = jtag_info->scann_size;
67                 field.out_value = calloc(CEIL(field.num_bits, 8), 1);
68                 buf_set_u32(field.out_value, 0, field.num_bits, new_scan_chain);
69                 field.out_mask = NULL;
70                 //field.in_value = &scan_n_capture;
71                 field.in_value = NULL;
72                 field.in_check_value = NULL;
73                 field.in_check_mask = NULL;
74                 field.in_handler = NULL;
75                 field.in_handler_priv = NULL;
76                 
77                 arm_jtag_set_instr(jtag_info, jtag_info->scann_instr);
78                 jtag_add_dr_scan(1, &field, -1);
79                 
80                 jtag_info->cur_scan_chain = new_scan_chain;
81                 
82                 free(field.out_value);
83         }
84         
85         return ERROR_OK;
86 }
87
88 int arm_jtag_reset_callback(enum jtag_event event, void *priv)
89 {
90         arm_jtag_t *jtag_info = priv;
91         
92         if (event == JTAG_TRST_ASSERTED)
93         {
94                 jtag_info->cur_scan_chain = 0;
95         }
96         
97         return ERROR_OK;
98 }
99
100 int arm_jtag_setup_connection(arm_jtag_t *jtag_info)
101 {
102         jtag_info->scann_instr = 0x2;
103         jtag_info->cur_scan_chain = 0;
104         jtag_info->intest_instr = 0xc;
105
106         jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);
107         
108         return ERROR_OK;
109 }
110
111 /* read JTAG buffer into host-endian u32, flipping bit-order */
112 int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv)
113 {
114         u32 *dest = priv;
115         *dest = flip_u32(le_to_h_u32(in_buf), 32);
116         return ERROR_OK;
117 }
118
119 /* read JTAG buffer into little-endian u32, flipping bit-order */
120 int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv)
121 {
122         h_u32_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
123         return ERROR_OK;
124 }
125
126 /* read JTAG buffer into little-endian u16, flipping bit-order */
127 int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv)
128 {
129         h_u16_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
130         return ERROR_OK;
131 }
132
133 /* read JTAG buffer into big-endian u32, flipping bit-order */
134 int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv)
135 {
136         h_u32_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
137         return ERROR_OK;
138 }
139
140 /* read JTAG buffer into big-endian u16, flipping bit-order */
141 int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv)
142 {
143         h_u16_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
144         return ERROR_OK;
145 }
146
147 /* read JTAG buffer into u8, flipping bit-order */
148 int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv)
149 {
150         u8 *dest = priv;
151         *dest = flip_u32(le_to_h_u32(in_buf), 32) & 0xff;
152         return ERROR_OK;
153 }
154
155 /* not-flipping variants */
156 /* read JTAG buffer into host-endian u32 */
157 int arm_jtag_buf_to_u32(u8 *in_buf, void *priv)
158 {
159         u32 *dest = priv;
160         *dest = le_to_h_u32(in_buf);
161         return ERROR_OK;
162 }
163
164 /* read JTAG buffer into little-endian u32 */
165 int arm_jtag_buf_to_le32(u8 *in_buf, void *priv)
166 {
167         h_u32_to_le(((u8*)priv), le_to_h_u32(in_buf));
168         return ERROR_OK;
169 }
170
171 /* read JTAG buffer into little-endian u16 */
172 int arm_jtag_buf_to_le16(u8 *in_buf, void *priv)
173 {
174         h_u16_to_le(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
175         return ERROR_OK;
176 }
177
178 /* read JTAG buffer into big-endian u32 */
179 int arm_jtag_buf_to_be32(u8 *in_buf, void *priv)
180 {
181         h_u32_to_be(((u8*)priv), le_to_h_u32(in_buf));
182         return ERROR_OK;
183 }
184
185 /* read JTAG buffer into big-endian u16 */
186 int arm_jtag_buf_to_be16(u8 *in_buf, void *priv)
187 {
188         h_u16_to_be(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
189         return ERROR_OK;
190 }
191
192 /* read JTAG buffer into u8 */
193 int arm_jtag_buf_to_8(u8 *in_buf, void *priv)
194 {
195         u8 *dest = priv;
196         *dest = le_to_h_u32(in_buf) & 0xff;
197         return ERROR_OK;
198 }