1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
29 #include "binarybuffer.h"
36 #define _ARM_JTAG_SCAN_N_CHECK_
39 int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, in_handler_t handler)
46 if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr)
52 field.num_bits = tap->ir_length;
54 buf_set_u32(field.out_value, 0, field.num_bits, new_instr);
55 field.out_mask = NULL;
56 field.in_value = NULL;
57 field.in_check_value = NULL;
58 field.in_check_mask = NULL;
59 field.in_handler = handler;
60 field.in_handler_priv = NULL;
61 jtag_add_ir_scan(1, &field, -1);
67 int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain)
69 int retval = ERROR_OK;
70 if(jtag_info->cur_scan_chain != new_scan_chain)
75 values[0]=new_scan_chain;
76 num_bits[0]=jtag_info->scann_size;
78 if((retval = arm_jtag_set_instr(jtag_info, jtag_info->scann_instr, NULL)) != ERROR_OK)
83 jtag_add_dr_out(jtag_info->tap,
89 jtag_info->cur_scan_chain = new_scan_chain;
95 int arm_jtag_reset_callback(enum jtag_event event, void *priv)
97 arm_jtag_t *jtag_info = priv;
99 if (event == JTAG_TRST_ASSERTED)
101 jtag_info->cur_scan_chain = 0;
107 int arm_jtag_setup_connection(arm_jtag_t *jtag_info)
109 jtag_info->scann_instr = 0x2;
110 jtag_info->cur_scan_chain = 0;
111 jtag_info->intest_instr = 0xc;
113 return jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);
116 /* read JTAG buffer into host-endian u32, flipping bit-order */
117 int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
120 *dest = flip_u32(le_to_h_u32(in_buf), 32);
124 /* read JTAG buffer into little-endian u32, flipping bit-order */
125 int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
127 h_u32_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
131 /* read JTAG buffer into little-endian u16, flipping bit-order */
132 int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
134 h_u16_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
138 /* read JTAG buffer into big-endian u32, flipping bit-order */
139 int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
141 h_u32_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
145 /* read JTAG buffer into big-endian u16, flipping bit-order */
146 int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
148 h_u16_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
152 /* read JTAG buffer into u8, flipping bit-order */
153 int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
156 *dest = flip_u32(le_to_h_u32(in_buf), 32) & 0xff;
160 /* not-flipping variants */
161 /* read JTAG buffer into host-endian u32 */
162 int arm_jtag_buf_to_u32(u8 *in_buf, void *priv, struct scan_field_s *field)
165 *dest = le_to_h_u32(in_buf);
169 /* read JTAG buffer into little-endian u32 */
170 int arm_jtag_buf_to_le32(u8 *in_buf, void *priv, struct scan_field_s *field)
172 h_u32_to_le(((u8*)priv), le_to_h_u32(in_buf));
176 /* read JTAG buffer into little-endian u16 */
177 int arm_jtag_buf_to_le16(u8 *in_buf, void *priv, struct scan_field_s *field)
179 h_u16_to_le(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
183 /* read JTAG buffer into big-endian u32 */
184 int arm_jtag_buf_to_be32(u8 *in_buf, void *priv, struct scan_field_s *field)
186 h_u32_to_be(((u8*)priv), le_to_h_u32(in_buf));
190 /* read JTAG buffer into big-endian u16 */
191 int arm_jtag_buf_to_be16(u8 *in_buf, void *priv, struct scan_field_s *field)
193 h_u16_to_be(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
197 /* read JTAG buffer into u8 */
198 int arm_jtag_buf_to_8(u8 *in_buf, void *priv, struct scan_field_s *field)
201 *dest = le_to_h_u32(in_buf) & 0xff;