From 0f24549ce95e682f1e04b3358b13ea8b7f80c074 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 6 Sep 2019 11:00:19 +0200 Subject: [PATCH] hla: use the new system_reset API HLA uses its own internal driver's API to control the adapter's system reset, but at the same time it calls jtag_add_reset() to avoid breaking the internal logic of OpenOCD. This implicitly forces HLA to rely on jtag queue mechanism, even if HLA has no link with JTAG state machine. It requires HLA to implement an empty execute_queue() to comply with the JTAG queue. Modify the HLA framework and the HLA targets to use the new adapter API for system_reset and decouple HLA from JTAG queue. Rename the HLA static functions adapter_assert_reset() and adapter_deassert_reset() to avoid overlap with the global functions with same name. While there, fix a minor typo in a comment s/incase/in case/. Do not remove from HLA the JTAG specific API execute_queue(), even if not required anymore, because OpenOCD code still has calls to jtag_execute_queue() in case of non JTAG transport. Change-Id: I0e65e3e557bd665bd3d3aeaa84ea609b55a05e48 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4896 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/jtag/core.c | 37 ++++++++++++++---------------------- src/jtag/hla/hla_interface.c | 28 +++++++++------------------ src/jtag/hla/hla_interface.h | 9 --------- src/jtag/interface.h | 4 ++-- src/target/hla_target.c | 24 ++++++++--------------- src/target/stm8.c | 14 +++----------- 6 files changed, 36 insertions(+), 80 deletions(-) diff --git a/src/jtag/core.c b/src/jtag/core.c index 97caeb18aa..69553ebaff 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 b50cb9c0fd..5056741e15 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 84b0098b63..262025e981 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 6e4237afc5..c5579f5e06 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 60ed7d64df..f0dc572764 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 144c797def..54a4bce262 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) -- 2.30.2