hla: use the new system_reset API 96/4896/7
authorAntonio Borneo <borneo.antonio@gmail.com>
Fri, 6 Sep 2019 09:00:19 +0000 (11:00 +0200)
committerTomas Vanek <vanekt@fbl.cz>
Tue, 14 Jan 2020 11:37:34 +0000 (11:37 +0000)
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 <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4896
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/jtag/core.c
src/jtag/hla/hla_interface.c
src/jtag/hla/hla_interface.h
src/jtag/interface.h
src/target/hla_target.c
src/target/stm8.c

index 97caeb18aaaf4e3c6896b431f774c2153bfe23fa..69553ebaff09a4615b6f0035f7bb0aa7b1829ae7 100644 (file)
@@ -35,8 +35,6 @@
 #include "interface.h"
 #include <transport/transport.h>
 #include <helper/jep106.h>
-#include <jtag/hla/hla_transport.h>
-#include <jtag/hla/hla_interface.h>
 
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
@@ -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,
index b50cb9c0fd31767b6efba334856c49c7fba97e29..5056741e15010b25459977d7bc63f959d661f5d5 100644 (file)
@@ -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,
index 84b0098b63619c81d13b18911c2d1d459160c73b..262025e9818b7e59e3bc46bd133f19d80cfd49bf 100644 (file)
@@ -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 */
index 6e4237afc50c3ce13e7d399332d387fdb91e2d0e..c5579f5e06b535c5ecd22228026ed2da121b4ad1 100644 (file)
@@ -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);
index 60ed7d64df1749014ff8d83b4466333d36181b6c..f0dc572764f34362a3e9f72351473a9f90255a0a 100644 (file)
@@ -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,
index 144c797def625e3ae50ab99d233007d7bdd64300..54a4bce262f4ee898963215ef772001e7ca35cb3 100644 (file)
@@ -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)

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)