]> git.sur5r.net Git - openocd/blob - src/target/arm_jtag.c
rtos/linux.c: fix clang static analyzer warning
[openocd] / src / target / arm_jtag.c
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, see <http://www.gnu.org/licenses/>. *
20  ***************************************************************************/
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "arm_jtag.h"
27
28 #if 0
29 #define _ARM_JTAG_SCAN_N_CHECK_
30 #endif
31
32 int arm_jtag_set_instr_inner(struct jtag_tap *tap,
33                 uint32_t new_instr, void *no_verify_capture, tap_state_t end_state)
34 {
35         struct scan_field field;
36         uint8_t t[4];
37
38         field.num_bits = tap->ir_length;
39         field.out_value = t;
40         buf_set_u32(t, 0, field.num_bits, new_instr);
41         field.in_value = NULL;
42
43         if (no_verify_capture == NULL)
44                 jtag_add_ir_scan(tap, &field, end_state);
45         else {
46                 /* FIX!!!! this is a kludge!!! arm926ejs.c should reimplement this arm_jtag_set_instr to
47                  * have special verification code.
48                  */
49                 jtag_add_ir_scan_noverify(tap, &field, end_state);
50         }
51
52         return ERROR_OK;
53 }
54
55 int arm_jtag_scann_inner(struct arm_jtag *jtag_info, uint32_t new_scan_chain, tap_state_t end_state)
56 {
57         int retval = ERROR_OK;
58
59         uint8_t out_value[4];
60         buf_set_u32(out_value, 0, jtag_info->scann_size, new_scan_chain);
61         struct scan_field field = { .num_bits = jtag_info->scann_size, .out_value = out_value, };
62
63         retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->scann_instr, NULL, end_state);
64         if (retval != ERROR_OK)
65                 return retval;
66
67         jtag_add_dr_scan(jtag_info->tap,
68                         1,
69                         &field,
70                         end_state);
71
72         jtag_info->cur_scan_chain = new_scan_chain;
73
74         return retval;
75 }
76
77 static int arm_jtag_reset_callback(enum jtag_event event, void *priv)
78 {
79         struct arm_jtag *jtag_info = priv;
80
81         if (event == JTAG_TRST_ASSERTED)
82                 jtag_info->cur_scan_chain = 0;
83
84         return ERROR_OK;
85 }
86
87 int arm_jtag_setup_connection(struct arm_jtag *jtag_info)
88 {
89         jtag_info->scann_instr = 0x2;
90         jtag_info->cur_scan_chain = 0;
91         jtag_info->intest_instr = 0xc;
92
93         return jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);
94 }