flash/nor/at91samd: Use 32-bit register writes for ST-Link compat
[fw/openocd] / src / target / arm_jtag.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /***************************************************************************
4  *   Copyright (C) 2005 by Dominic Rath                                    *
5  *   Dominic.Rath@gmx.de                                                   *
6  *                                                                         *
7  *   Copyright (C) 2007-2010 Ã˜yvind Harboe                                 *
8  *   oyvind.harboe@zylin.com                                               *
9  ***************************************************************************/
10
11 #ifndef OPENOCD_TARGET_ARM_JTAG_H
12 #define OPENOCD_TARGET_ARM_JTAG_H
13
14 #include <jtag/jtag.h>
15 #include <helper/bits.h>
16
17 struct arm_jtag {
18         struct jtag_tap *tap;
19
20         uint32_t scann_size;
21         uint32_t scann_instr;
22         uint32_t cur_scan_chain;
23
24         uint32_t intest_instr;
25 };
26
27 int arm_jtag_set_instr_inner(struct jtag_tap *tap, uint32_t new_instr,
28                 void *no_verify_capture,
29                 tap_state_t end_state);
30
31 static inline int arm_jtag_set_instr(struct jtag_tap *tap,
32                 uint32_t new_instr, void *no_verify_capture, tap_state_t end_state)
33 {
34         /* inline most common code path */
35         if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != (new_instr & (BIT(tap->ir_length) - 1)))
36                 return arm_jtag_set_instr_inner(tap, new_instr, no_verify_capture, end_state);
37
38         return ERROR_OK;
39
40 }
41
42 int arm_jtag_scann_inner(struct arm_jtag *jtag_info, uint32_t new_scan_chain, tap_state_t end_state);
43 static inline int arm_jtag_scann(struct arm_jtag *jtag_info, uint32_t new_scan_chain, tap_state_t end_state)
44 {
45         /* inline most common code path */
46         int retval = ERROR_OK;
47         if (jtag_info->cur_scan_chain != new_scan_chain)
48                 return arm_jtag_scann_inner(jtag_info, new_scan_chain, end_state);
49
50         return retval;
51 }
52
53 int arm_jtag_setup_connection(struct arm_jtag *jtag_info);
54 int arm_jtag_close_connection(struct arm_jtag *jtag_info);
55
56 /* use this as a static so we can inline it in -O3 and refer to it via a pointer  */
57 static inline void arm7flip32(jtag_callback_data_t arg)
58 {
59         uint8_t *in = (uint8_t *)arg;
60         *((uint32_t *)arg) = flip_u32(le_to_h_u32(in), 32);
61 }
62
63 static inline void arm_le_to_h_u32(jtag_callback_data_t arg)
64 {
65         uint8_t *in = (uint8_t *)arg;
66         *((uint32_t *)arg) = le_to_h_u32(in);
67 }
68
69 #endif /* OPENOCD_TARGET_ARM_JTAG_H */