- only check normal resume, not debug resume
[openocd.git] / src / target / target.c
index da70f3ea524f140bc726ca21d6e7a9cb40a6acef..bd334da25700ff80e6420ee0501622fb8eb945a8 100644 (file)
@@ -49,7 +49,6 @@
 
 int cli_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv);
 
-
 int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 
@@ -225,9 +224,7 @@ int target_init_handler(struct target_s *target, enum target_event event, void *
        if (event == TARGET_EVENT_HALTED)
        {
                target_unregister_event_callback(target_init_handler, priv);
-
-               target_invoke_script(cmd_ctx, target, "reset");
-
+               target_invoke_script(cmd_ctx, target, "post_reset");
                jtag_execute_queue();
        }
        
@@ -267,16 +264,40 @@ int target_halt(struct target_s *target)
 
 int target_resume(struct target_s *target, int current, u32 address, int handle_breakpoints, int debug_execution)
 {
+       int retval;
+       int timeout_ms = 5000;
+       
        /* We can't poll until after examine */
        if (!target->type->examined)
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
        }
-       return target->type->resume(target, current, address, handle_breakpoints, debug_execution);
+       
+       if ((retval = target->type->resume(target, current, address, handle_breakpoints, debug_execution)) != ERROR_OK)
+               return retval;
+       
+       /* only check for resume event if normal resume */
+       if (!debug_execution)
+       {
+               /* wait for target to exit halted mode - not debug resume*/
+               target_poll(target);
+               
+               while (target->state != TARGET_RUNNING)
+               {
+                       usleep(10000);
+                       target_poll(target);
+                       if ((timeout_ms -= 10) <= 0)
+                       {
+                               LOG_ERROR("timeout waiting for target resume");
+                               return ERROR_TARGET_TIMEOUT;
+                       }
+               }
+       }
+       
+       return retval;
 }
 
-
 int target_process_reset(struct command_context_s *cmd_ctx)
 {
        int retval = ERROR_OK;
@@ -460,7 +481,6 @@ int target_process_reset(struct command_context_s *cmd_ctx)
                target = target->next;
        }
        target_unregister_event_callback(target_init_handler, cmd_ctx);
-                               
        
        jtag->speed(jtag_speed_post_reset);
        
@@ -783,7 +803,6 @@ int target_call_timer_callbacks_now()
        return target_call_timer_callbacks(0);
 }
 
-
 int target_alloc_working_area(struct target_s *target, u32 size, working_area_t **area)
 {
        working_area_t *c = target->working_areas;
@@ -1472,7 +1491,6 @@ int target_invoke_script(struct command_context_s *cmd_ctx, target_t *target, ch
        name, get_num_by_target(target));
 }
 
-
 int handle_target_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
        target_t *target = NULL;
@@ -1490,12 +1508,19 @@ int handle_target_script_command(struct command_context_s *cmd_ctx, char *cmd, c
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
        
+       const char *event=args[1];
+       if (strcmp("reset", event)==0)
+       {
+               /* synonymous */
+               event="post_reset";
+       }
+                       
        /* Define a tcl procedure which we'll invoke upon some event */
        command_run_linef(cmd_ctx, 
        "proc target_%s_%d {} {"
-       "openocd {script %s}" 
+       "openocd {script %s} ; return \"\"
        "}",
-       args[1],
+       event,
        get_num_by_target(target),
        args[2]);
        
@@ -1754,13 +1779,6 @@ int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd, char
        return wait_state(cmd_ctx, cmd, TARGET_HALTED, ms); 
 }
 
-static void target_process_events(struct command_context_s *cmd_ctx)
-{
-       target_t *target = get_current_target(cmd_ctx);
-       target_poll(target);
-       target_call_timer_callbacks_now();
-}
-
 static int wait_state(struct command_context_s *cmd_ctx, char *cmd, enum target_state state, int ms)
 {
        int retval;
@@ -1811,7 +1829,6 @@ int handle_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **arg
        return handle_wait_halt_command(cmd_ctx, cmd, args, argc);
 }
 
-               
 int handle_soft_reset_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
        target_t *target = get_current_target(cmd_ctx);
@@ -1879,6 +1896,8 @@ int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **a
        int retval;
        target_t *target = get_current_target(cmd_ctx);
        
+       target_invoke_script(cmd_ctx, target, "pre_resume");
+       
        if (argc == 0)
                retval = target_resume(target, 1, 0, 1, 0); /* current pc, addr = 0, handle breakpoints, not debugging */
        else if (argc == 1)
@@ -1887,8 +1906,6 @@ int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **a
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-
-       target_process_events(cmd_ctx);
        
        return retval;
 }
@@ -2003,8 +2020,7 @@ int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args,
        value = strtoul(args[1], NULL, 0);
        if (argc == 3)
                count = strtoul(args[2], NULL, 0);
-
-
+       
        switch (cmd[2])
        {
                case 'w':

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)