[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openocd-development
Subject:    [PATCH]: 3ec6104b0b target: add API to temporarily mask target polling
From:       gerrit () openocd ! org
Date:       2022-05-31 8:07:39
Message-ID: 20220531080739.62C02F4 () openocd ! org
[Download RAW message or body]

This is an automated email from Gerrit.

"Antonio Borneo <borneo.antonio@gmail.com>" just uploaded a new patch set to Gerrit, \
which you can find at https://review.openocd.org/c/openocd/+/7009

-- gerrit

commit 3ec6104b0b5cde67e4707c6a2605144fb0ce5170
Author: Antonio Borneo <borneo.antonio@gmail.com>
Date:   Mon May 30 22:49:12 2022 +0200

    target: add API to temporarily mask target polling
    
    The same flag 'jtag_poll' is currently used as local data for the
    command 'poll' and to temporarily mask the target polling.
    This can cause unexpected behavior if the command 'poll' is
    executed while polling is temporarily masked.
    
    Add a new flag 'jtag_poll_en' to hold the temporarily mask
    condition and keep 'jtag_poll' for the 'poll' command only.
    
    While there, change the initial assignment of 'jtag_poll' using
    the proper boolean value.
    
    Change-Id: I18dcf7c65b07aefadf046caaa2fcd2d74fa6fbae
    Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>

diff --git a/src/flash/nor/psoc4.c b/src/flash/nor/psoc4.c
index 0a2702ab5d..7a4a4d1e16 100644
--- a/src/flash/nor/psoc4.c
+++ b/src/flash/nor/psoc4.c
@@ -662,8 +662,12 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t \
*buffer,  if (row_offset)
 		memset(row_buffer, bank->default_padded_value, row_offset);
 
-	bool save_poll = jtag_poll_get_enabled();
-	jtag_poll_set_enabled(false);
+	/*
+	 * We use breakpoint in target_run_algorithm().
+	 * Don't poll to avoid halted events
+	 * TODO: should mask/unmask this be moved in target_run_algorithm() ?
+	 */
+	bool save_poll_mask = jtag_poll_mask();
 
 	while (count) {
 		uint32_t chunk_size = psoc4_info->row_size - row_offset;
@@ -704,7 +708,7 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t \
*buffer,  }
 
 cleanup:
-	jtag_poll_set_enabled(save_poll);
+	jtag_poll_unmask(save_poll_mask);
 
 	free(sysrq_buffer);
 	return retval;
diff --git a/src/helper/command.c b/src/helper/command.c
index 1e769d7190..622e2d77fe 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -713,14 +713,12 @@ static int jim_capture(Jim_Interp *interp, int argc, Jim_Obj \
                *const *argv)
 	 * This is necessary in order to avoid accidentally getting a non-empty
 	 * string for tcl fn's.
 	 */
-	bool save_poll = jtag_poll_get_enabled();
-
-	jtag_poll_set_enabled(false);
+	bool save_poll_mask = jtag_poll_mask();
 
 	const char *str = Jim_GetString(argv[1], NULL);
 	int retcode = Jim_Eval_Named(interp, str, __THIS__FILE__, __LINE__);
 
-	jtag_poll_set_enabled(save_poll);
+	jtag_poll_unmask(save_poll_mask);
 
 	command_log_capture_finish(state);
 
diff --git a/src/jtag/core.c b/src/jtag/core.c
index bbc9877ee9..18d4ba685a 100644
--- a/src/jtag/core.c
+++ b/src/jtag/core.c
@@ -147,14 +147,19 @@ int jtag_error_clear(void)
 
 /************/
 
-static bool jtag_poll = 1;
+static bool jtag_poll = true;
+static bool jtag_poll_en = true;
 
 bool is_jtag_poll_safe(void)
 {
 	/* Polling can be disabled explicitly with set_enabled(false).
+	 * It can also be masked with mask().
 	 * It is also implicitly disabled while TRST is active and
 	 * while SRST is gating the JTAG clock.
 	 */
+	if (!jtag_poll_en)
+		return false;
+
 	if (!transport_is_jtag())
 		return jtag_poll;
 
@@ -173,6 +178,18 @@ void jtag_poll_set_enabled(bool value)
 	jtag_poll = value;
 }
 
+bool jtag_poll_mask(void)
+{
+	bool retval = jtag_poll_en;
+	jtag_poll_en = false;
+	return retval;
+}
+
+void jtag_poll_unmask(bool saved)
+{
+	jtag_poll_en = saved;
+}
+
 /************/
 
 struct jtag_tap *jtag_all_taps(void)
diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h
index 4ec2f1e311..8bc3525d61 100644
--- a/src/jtag/jtag.h
+++ b/src/jtag/jtag.h
@@ -598,6 +598,19 @@ bool jtag_poll_get_enabled(void);
  */
 void jtag_poll_set_enabled(bool value);
 
+/**
+ * Mask (disable) polling and return the current mask status that should be
+ * feed to jtag_poll_unmask() to restore it.
+ * Multiple nested calls to jtag_poll_mask() are allowed, each balanced with
+ * its call to jtag_poll_unmask().
+ */
+bool jtag_poll_mask(void);
+
+/**
+ * Restore saved mask for polling.
+ */
+void jtag_poll_unmask(bool saved);
+
 #include <jtag/minidriver.h>
 
 int jim_jtag_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
diff --git a/src/target/target.c b/src/target/target.c
index 76327b1c77..e616f5294d 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -659,10 +659,10 @@ int target_resume(struct target *target, int current, \
                target_addr_t address,
 	 * Disable polling during resume() to guarantee the execution of handlers
 	 * in the correct order.
 	 */
-	bool save_poll = jtag_poll_get_enabled();
-	jtag_poll_set_enabled(false);
+	bool save_poll_mask = jtag_poll_mask();
 	retval = target->type->resume(target, current, address, handle_breakpoints, \
                debug_execution);
-	jtag_poll_set_enabled(save_poll);
+	jtag_poll_unmask(save_poll_mask);
+
 	if (retval != ERROR_OK)
 		return retval;
 
@@ -690,14 +690,12 @@ static int target_process_reset(struct command_invocation *cmd, \
                enum target_rese
 	 * more predictable, i.e. dr/irscan & pathmove in events will
 	 * not have JTAG operations injected into the middle of a sequence.
 	 */
-	bool save_poll = jtag_poll_get_enabled();
-
-	jtag_poll_set_enabled(false);
+	bool save_poll_mask = jtag_poll_mask();
 
 	sprintf(buf, "ocd_process_reset %s", n->name);
 	retval = Jim_Eval(cmd->ctx->interp, buf);
 
-	jtag_poll_set_enabled(save_poll);
+	jtag_poll_unmask(save_poll_mask);
 
 	if (retval != JIM_OK) {
 		Jim_MakeErrorMessage(cmd->ctx->interp);

-- 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic