diff --git a/src/jtag/core.c b/src/jtag/core.c index 97caeb18a..69553ebaf 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -35,8 +35,6 @@ #include "interface.h" #include #include -#include -#include #ifdef HAVE_STRINGS_H #include @@ -2009,19 +2007,7 @@ int adapter_resets(int trst, int srst) /* adapters without trst signal will eventually use tlr sequence */ jtag_add_reset(trst, srst); return ERROR_OK; - } else if (transport_is_swd()) { - if (trst == TRST_ASSERT) { - LOG_ERROR("transport swd has no trst signal"); - return ERROR_FAIL; - } - - if (srst == SRST_ASSERT && !(jtag_reset_config & RESET_HAS_SRST)) { - LOG_ERROR("adapter has no srst signal"); - return ERROR_FAIL; - } - adapter_system_reset(srst); - return ERROR_OK; - } else if (transport_is_hla()) { + } else if (transport_is_swd() || transport_is_hla()) { if (trst == TRST_ASSERT) { LOG_ERROR("transport %s has no trst signal", get_current_transport()->name); @@ -2032,7 +2018,8 @@ int adapter_resets(int trst, int srst) LOG_ERROR("adapter has no srst signal"); return ERROR_FAIL; } - return hl_interface_reset(srst); + adapter_system_reset(srst); + return ERROR_OK; } if (trst == TRST_DEASSERT && srst == SRST_DEASSERT) @@ -2044,33 +2031,37 @@ int adapter_resets(int trst, int srst) return ERROR_FAIL; } -void adapter_assert_reset(void) +int adapter_assert_reset(void) { if (transport_is_jtag()) { if (jtag_reset_config & RESET_SRST_PULLS_TRST) jtag_add_reset(1, 1); else jtag_add_reset(0, 1); - } else if (transport_is_swd()) - adapter_system_reset(1); + return ERROR_OK; + } else if (transport_is_swd() || transport_is_hla()) + return adapter_system_reset(1); else if (get_current_transport() != NULL) LOG_ERROR("reset is not supported on %s", get_current_transport()->name); else LOG_ERROR("transport is not selected"); + return ERROR_FAIL; } -void adapter_deassert_reset(void) +int adapter_deassert_reset(void) { - if (transport_is_jtag()) + if (transport_is_jtag()) { jtag_add_reset(0, 0); - else if (transport_is_swd()) - adapter_system_reset(0); + return ERROR_OK; + } else if (transport_is_swd() || transport_is_hla()) + return adapter_system_reset(0); else if (get_current_transport() != NULL) LOG_ERROR("reset is not supported on %s", get_current_transport()->name); else LOG_ERROR("transport is not selected"); + return ERROR_FAIL; } int adapter_config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol, diff --git a/src/jtag/hla/hla_interface.c b/src/jtag/hla/hla_interface.c index b50cb9c0f..5056741e1 100644 --- a/src/jtag/hla/hla_interface.c +++ b/src/jtag/hla/hla_interface.c @@ -127,6 +127,11 @@ static int hl_interface_quit(void) return ERROR_OK; } +static int hl_interface_reset(int req_trst, int req_srst) +{ + return hl_if.layout->api->assert_srst(hl_if.handle, req_srst ? 0 : 1); +} + static int hl_interface_execute_queue(void) { LOG_DEBUG("hl_interface_execute_queue: ignored"); @@ -136,33 +141,17 @@ static int hl_interface_execute_queue(void) int hl_interface_init_reset(void) { - /* incase the adapter has not already handled asserting srst + /* in case the adapter has not already handled asserting srst * we will attempt it again */ if (hl_if.param.connect_under_reset) { - jtag_add_reset(0, 1); - hl_if.layout->api->assert_srst(hl_if.handle, 0); + adapter_assert_reset(); } else { - jtag_add_reset(0, 0); + adapter_deassert_reset(); } return ERROR_OK; } -/* FIXME: hla abuses of jtag_add_reset() to track srst status and for timings */ -int hl_interface_reset(int srst) -{ - int result; - - if (srst == 1) { - jtag_add_reset(0, 1); - result = hl_if.layout->api->assert_srst(hl_if.handle, 0); - } else { - result = hl_if.layout->api->assert_srst(hl_if.handle, 1); - jtag_add_reset(0, 0); - } - return result; -} - static int hl_interface_khz(int khz, int *jtag_speed) { if (hl_if.layout->api->speed == NULL) @@ -371,6 +360,7 @@ struct jtag_interface hl_interface = { .transports = hl_transports, .init = hl_interface_init, .quit = hl_interface_quit, + .reset = hl_interface_reset, .execute_queue = hl_interface_execute_queue, .speed = &hl_interface_speed, .khz = &hl_interface_khz, diff --git a/src/jtag/hla/hla_interface.h b/src/jtag/hla/hla_interface.h index 84b0098b6..262025e98 100644 --- a/src/jtag/hla/hla_interface.h +++ b/src/jtag/hla/hla_interface.h @@ -67,13 +67,4 @@ int hl_interface_init_target(struct target *t); int hl_interface_init_reset(void); int hl_interface_override_target(const char **targetname); -#if BUILD_HLADAPTER == 1 -int hl_interface_reset(int srst); -#else -static inline int hl_interface_reset(int srst) -{ - return ERROR_OK; -} -#endif - #endif /* OPENOCD_JTAG_HLA_HLA_INTERFACE_H */ diff --git a/src/jtag/interface.h b/src/jtag/interface.h index 6e4237afc..c5579f5e0 100644 --- a/src/jtag/interface.h +++ b/src/jtag/interface.h @@ -341,8 +341,8 @@ struct jtag_interface { extern const char * const jtag_only[]; int adapter_resets(int assert_trst, int assert_srst); -void adapter_assert_reset(void); -void adapter_deassert_reset(void); +int adapter_assert_reset(void); +int adapter_deassert_reset(void); int adapter_config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol, uint32_t port_size, unsigned int *trace_freq, unsigned int traceclkin_freq, uint16_t *prescaler); diff --git a/src/target/hla_target.c b/src/target/hla_target.c index 60ed7d64d..f0dc57276 100644 --- a/src/target/hla_target.c +++ b/src/target/hla_target.c @@ -25,6 +25,7 @@ #include "config.h" #endif +#include "jtag/interface.h" #include "jtag/jtag.h" #include "jtag/hla/hla_transport.h" #include "jtag/hla/hla_interface.h" @@ -499,7 +500,7 @@ static int adapter_poll(struct target *target) return ERROR_OK; } -static int adapter_assert_reset(struct target *target) +static int hl_assert_reset(struct target *target) { int res = ERROR_OK; struct hl_interface_s *adapter = target_to_adapter(target); @@ -514,8 +515,7 @@ static int adapter_assert_reset(struct target *target) if ((jtag_reset_config & RESET_HAS_SRST) && (jtag_reset_config & RESET_SRST_NO_GATING)) { - jtag_add_reset(0, 1); - res = adapter->layout->api->assert_srst(adapter->handle, 0); + res = adapter_assert_reset(); srst_asserted = true; } @@ -529,8 +529,7 @@ static int adapter_assert_reset(struct target *target) if (jtag_reset_config & RESET_HAS_SRST) { if (!srst_asserted) { - jtag_add_reset(0, 1); - res = adapter->layout->api->assert_srst(adapter->handle, 0); + res = adapter_assert_reset(); } if (res == ERROR_COMMAND_NOTFOUND) LOG_ERROR("Hardware srst not supported, falling back to software reset"); @@ -563,21 +562,14 @@ static int adapter_assert_reset(struct target *target) return ERROR_OK; } -static int adapter_deassert_reset(struct target *target) +static int hl_deassert_reset(struct target *target) { - struct hl_interface_s *adapter = target_to_adapter(target); - enum reset_types jtag_reset_config = jtag_get_reset_config(); LOG_DEBUG("%s", __func__); if (jtag_reset_config & RESET_HAS_SRST) - adapter->layout->api->assert_srst(adapter->handle, 1); - - /* virtual deassert reset, we need it for the internal - * jtag state machine - */ - jtag_add_reset(0, 0); + adapter_deassert_reset(); target->savedDCRDR = 0; /* clear both DCC busy bits on initial resume */ @@ -819,8 +811,8 @@ struct target_type hla_target = { .arch_state = armv7m_arch_state, .target_request_data = hl_target_request_data, - .assert_reset = adapter_assert_reset, - .deassert_reset = adapter_deassert_reset, + .assert_reset = hl_assert_reset, + .deassert_reset = hl_deassert_reset, .halt = adapter_halt, .resume = adapter_resume, diff --git a/src/target/stm8.c b/src/target/stm8.c index 144c797de..54a4bce26 100644 --- a/src/target/stm8.c +++ b/src/target/stm8.c @@ -25,6 +25,7 @@ #include "target.h" #include "target_type.h" #include "hello.h" +#include "jtag/interface.h" #include "jtag/jtag.h" #include "jtag/hla/hla_transport.h" #include "jtag/hla/hla_interface.h" @@ -930,9 +931,7 @@ static int stm8_reset_assert(struct target *target) enum reset_types jtag_reset_config = jtag_get_reset_config(); if (jtag_reset_config & RESET_HAS_SRST) { - jtag_add_reset(0, 1); - res = adapter->layout->api->assert_srst(adapter->handle, 0); - + res = adapter_assert_reset(); if (res == ERROR_OK) /* hardware srst supported */ use_srst_fallback = false; @@ -966,21 +965,14 @@ static int stm8_reset_assert(struct target *target) static int stm8_reset_deassert(struct target *target) { int res; - struct hl_interface_s *adapter = target_to_adapter(target); - enum reset_types jtag_reset_config = jtag_get_reset_config(); if (jtag_reset_config & RESET_HAS_SRST) { - res = adapter->layout->api->assert_srst(adapter->handle, 1); + res = adapter_deassert_reset(); if ((res != ERROR_OK) && (res != ERROR_COMMAND_NOTFOUND)) return res; } - /* virtual deassert reset, we need it for the internal - * jtag state machine - */ - jtag_add_reset(0, 0); - /* The cpu should now be stalled. If halt was requested let poll detect the stall */ if (target->reset_halt)