jtag/drivers/ti_icdi: do not segfault when adapter can't be opened
[openocd.git] / src / target / arm_jtag.c
blob6f70e853a04bf9cedd20f1c0e5c215569e0f33ba
1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
7 * *
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. *
12 * *
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. *
17 * *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
22 ***************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #include "arm_jtag.h"
30 #if 0
31 #define _ARM_JTAG_SCAN_N_CHECK_
32 #endif
34 int arm_jtag_set_instr_inner(struct arm_jtag *jtag_info,
35 uint32_t new_instr, void *no_verify_capture, tap_state_t end_state)
37 struct jtag_tap *tap;
38 tap = jtag_info->tap;
39 struct scan_field field;
40 uint8_t t[4];
42 field.num_bits = tap->ir_length;
43 field.out_value = t;
44 buf_set_u32(t, 0, field.num_bits, new_instr);
45 field.in_value = NULL;
47 if (no_verify_capture == NULL)
48 jtag_add_ir_scan(tap, &field, end_state);
49 else {
50 /* FIX!!!! this is a kludge!!! arm926ejs.c should reimplement this arm_jtag_set_instr to
51 * have special verification code.
53 jtag_add_ir_scan_noverify(tap, &field, end_state);
56 return ERROR_OK;
59 int arm_jtag_scann_inner(struct arm_jtag *jtag_info, uint32_t new_scan_chain, tap_state_t end_state)
61 int retval = ERROR_OK;
63 uint8_t out_value[4];
64 buf_set_u32(out_value, 0, jtag_info->scann_size, new_scan_chain);
65 struct scan_field field = { .num_bits = jtag_info->scann_size, .out_value = out_value, };
67 retval = arm_jtag_set_instr(jtag_info, jtag_info->scann_instr, NULL, end_state);
68 if (retval != ERROR_OK)
69 return retval;
71 jtag_add_dr_scan(jtag_info->tap,
73 &field,
74 end_state);
76 jtag_info->cur_scan_chain = new_scan_chain;
78 return retval;
81 static int arm_jtag_reset_callback(enum jtag_event event, void *priv)
83 struct arm_jtag *jtag_info = priv;
85 if (event == JTAG_TRST_ASSERTED)
86 jtag_info->cur_scan_chain = 0;
88 return ERROR_OK;
91 int arm_jtag_setup_connection(struct arm_jtag *jtag_info)
93 jtag_info->scann_instr = 0x2;
94 jtag_info->cur_scan_chain = 0;
95 jtag_info->intest_instr = 0xc;
97 return jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);