fixed warning
[fw/openocd] / src / target / target.c
index c2fce59d61c986a1e03855eae112adc44f721020..b2220c0bbe8c0c341fefc5f43caa452c569cf12f 100644 (file)
@@ -290,7 +290,7 @@ int target_process_reset(struct command_context_s *cmd_ctx, enum target_reset_mo
         *
         * For the "reset halt/init" case we must only set up the registers here.
         */
-       if ((retval = target_examine(cmd_ctx)) != ERROR_OK)
+       if ((retval = target_examine()) != ERROR_OK)
                return retval;
 
        keep_alive(); /* we might be running on a very slow JTAG clk */
@@ -303,60 +303,38 @@ int target_process_reset(struct command_context_s *cmd_ctx, enum target_reset_mo
                 */
                target_free_all_working_areas_restore(target, 0);
                target->reset_halt=((reset_mode==RESET_HALT)||(reset_mode==RESET_INIT));
-               target->type->assert_reset(target);
+               if ((retval = target->type->assert_reset(target))!=ERROR_OK)
+                       return retval;
                target = target->next;
        }
-       if ((retval = jtag_execute_queue()) != ERROR_OK)
-       {
-               LOG_WARNING("JTAG communication failed asserting reset.");
-               retval = ERROR_OK;
-       }
 
-       /* request target halt if necessary, and schedule further action */
        target = targets;
        while (target)
        {
-               if (reset_mode!=RESET_RUN)
-               {
-                       if ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0)
-                               target_halt(target);
-               }
+               if ((retval = target->type->deassert_reset(target))!=ERROR_OK)
+                       return retval;
                target = target->next;
        }
 
-       if ((retval = jtag_execute_queue()) != ERROR_OK)
-       {
-               LOG_WARNING("JTAG communication failed while reset was asserted. Consider using srst_only for reset_config.");
-               retval = ERROR_OK;
-       }
-
        target = targets;
        while (target)
        {
-               target->type->deassert_reset(target);
-               /* We can fail to bring the target into the halted state  */
-               target_poll(target);
-               if (target->reset_halt&&((target->state != TARGET_HALTED)))
+               /* We can fail to bring the target into the halted state, try after reset has been deasserted  */
+               if (target->reset_halt)
                {
-                       LOG_WARNING("Failed to reset target into halted mode - issuing halt");
-                       target->type->halt(target);
+                       /* wait up to 1 second for halt. */
+                       target_wait_state(target, TARGET_HALTED, 1000);
+                       if (target->state != TARGET_HALTED)
+                       {
+                               LOG_WARNING("Failed to reset target into halted mode - issuing halt");
+                               if ((retval = target->type->halt(target))!=ERROR_OK)
+                                       return retval;
+                       }
                }
 
                target = target->next;
        }
 
-       if ((retval = jtag_execute_queue()) != ERROR_OK)
-       {
-               LOG_WARNING("JTAG communication failed while deasserting reset.");
-               retval = ERROR_OK;
-       }
-
-       if (jtag_reset_config & RESET_SRST_PULLS_TRST)
-       {
-               /* If TRST was asserted we need to set up registers again */
-               if ((retval = target_examine(cmd_ctx)) != ERROR_OK)
-                       return retval;
-       }
 
        LOG_DEBUG("Waiting for halted stated as appropriate");
 
@@ -393,7 +371,7 @@ static int default_mmu(struct target_s *target, int *enabled)
        return ERROR_OK;
 }
 
-static int default_examine(struct command_context_s *cmd_ctx, struct target_s *target)
+static int default_examine(struct target_s *target)
 {
        target->type->examined = 1;
        return ERROR_OK;
@@ -405,13 +383,13 @@ static int default_examine(struct command_context_s *cmd_ctx, struct target_s *t
  *
  * XScale
  */
-int target_examine(struct command_context_s *cmd_ctx)
+int target_examine(void)
 {
        int retval = ERROR_OK;
        target_t *target = targets;
        while (target)
        {
-               if ((retval = target->type->examine(cmd_ctx, target))!=ERROR_OK)
+               if ((retval = target->type->examine(target))!=ERROR_OK)
                        return retval;
                target = target->next;
        }
@@ -688,15 +666,15 @@ static int target_call_timer_callbacks_check_time(int checktime)
        return ERROR_OK;
 }
 
-int target_call_timer_callbacks()
+int target_call_timer_callbacks(void)
 {
        return target_call_timer_callbacks_check_time(1);
 }
 
 /* invoke periodic callbacks immediately */
-int target_call_timer_callbacks_now()
+int target_call_timer_callbacks_now(void)
 {
-       return target_call_timer_callbacks(0);
+       return target_call_timer_callbacks();
 }
 
 int target_alloc_working_area(struct target_s *target, u32 size, working_area_t **area)
@@ -1222,7 +1200,7 @@ int target_register_user_commands(struct command_context_s *cmd_ctx)
        register_command(cmd_ctx,  NULL, "halt", handle_halt_command, COMMAND_EXEC, "halt target");
        register_command(cmd_ctx,  NULL, "resume", handle_resume_command, COMMAND_EXEC, "resume target [addr]");
        register_command(cmd_ctx,  NULL, "step", handle_step_command, COMMAND_EXEC, "step one instruction from current PC or [addr]");
-       register_command(cmd_ctx,  NULL, "reset", handle_reset_command, COMMAND_EXEC, "reset target [run|halt|init]");
+       register_command(cmd_ctx,  NULL, "reset", handle_reset_command, COMMAND_EXEC, "reset target [run|halt|init] - default is run");
        register_command(cmd_ctx,  NULL, "soft_reset_halt", handle_soft_reset_halt_command, COMMAND_EXEC, "halt the target and do a soft reset");
 
        register_command(cmd_ctx,  NULL, "mdw", handle_md_command, COMMAND_EXEC, "display memory words <addr> [count]");
@@ -1664,7 +1642,7 @@ int target_wait_state(target_t *target, enum target_state state, int ms)
                if (once)
                {
                        once=0;
-                       LOG_USER("waiting for target %s...", target_state_strings[state]);
+                       LOG_DEBUG("waiting for target %s...", target_state_strings[state]);
                }
 
                gettimeofday(&now, NULL);
@@ -1723,9 +1701,7 @@ int handle_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
        }
 
        /* reset *all* targets */
-       target_process_reset(cmd_ctx, reset_mode);
-
-       return ERROR_OK;
+       return target_process_reset(cmd_ctx, reset_mode);
 }
 
 int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@@ -2529,7 +2505,7 @@ int handle_profile_command(struct command_context_s *cmd_ctx, char *cmd, char **
                        samples[numSamples++]=t;
                        retval = target_resume(target, 1, 0, 0, 0); /* current pc, addr = 0, do not handle breakpoints, not debugging */
                        target_poll(target);
-                       usleep(10*1000); // sleep 10ms, i.e. <100 samples/second.
+                       alive_sleep(10); // sleep 10ms, i.e. <100 samples/second.
                } else if (target->state == TARGET_RUNNING)
                {
                        // We want to quickly sample the PC.