This patch (it includes Øyvind's previous patch) fixes my problems with
reset. By default it will do nothing so it should not affect anybody.

I added [optional] reset before running jtag_init_inner().

Is there a chance to commit this to svn tree?
--Michal


On Thu, 2009-09-24 at 00:28 +0200, Michael Schwingen wrote:
> David Brownell wrote:
> >> A board may stretch SRST, so you *have* to be able to wait a
> >> (user-defined) amount of time after SRESET assertion/deassertion before 
> >> talking to anything in the chain. This is also true if the SRESET 
> >> assertion is not caused by OpenOCD directly.
> >>     
> >
> > Understood.  This is part of why some JTAG adapters provide
> > inputs for SRST, not just outputs.  It'd be nice if the
> > FT2232 ones provided a "USB interrupt" to give hosts an
> > asynch (more or less) notification that it was asserted.
> >   
> This won't help if the FTDI library asserts SRST when calling the init
> function. At that point, the interrupts are probably not yet set up
> correctly.
> 
> If the library does assert SRST during init without being told to do
> that, then OpenOCD needs to know about that and at least apply the
> configured delays so that the chain is in working order.
> 
> cu
> Michael
> 
> _______________________________________________
> Openocd-development mailing list
> Openocd-development@lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/openocd-development
Index: src/jtag/zy1000/zy1000.c
===================================================================
--- src/jtag/zy1000/zy1000.c    (revision 2726)
+++ src/jtag/zy1000/zy1000.c    (working copy)
@@ -657,9 +657,6 @@
 
 
 
-extern int jtag_nsrst_delay;
-extern int jtag_ntrst_delay;
-
 int interface_jtag_add_reset(int req_trst, int req_srst)
 {
        zy1000_reset(req_trst, req_srst);
Index: src/jtag/core.c
===================================================================
--- src/jtag/core.c     (revision 2726)
+++ src/jtag/core.c     (working copy)
@@ -93,6 +93,9 @@
 /* how long the OpenOCD should wait before attempting JTAG communication after 
reset lines deasserted (in ms) */
 static int jtag_nsrst_delay = 0; /* default to no nSRST delay */
 static int jtag_ntrst_delay = 0; /* default to no nTRST delay */
+static int jtag_nsrst_assert_width = 0; /* width of assertion */
+static int jtag_ntrst_assert_width = 0; /* width of assertion */
+static bool jtag_reset_on_init = false; /* reset JTAG on init */
 
 typedef struct jtag_event_callback_s
 {
@@ -662,7 +665,11 @@
        if (jtag_srst != new_srst) {
                jtag_srst = new_srst;
                if (jtag_srst)
+               {
                        LOG_DEBUG("SRST line asserted");
+                       if (jtag_nsrst_assert_width)
+                               jtag_add_sleep(jtag_nsrst_assert_width * 1000);
+               }
                else {
                        LOG_DEBUG("SRST line released");
                        if (jtag_nsrst_delay)
@@ -694,6 +701,8 @@
                        LOG_DEBUG("TRST line asserted");
                        tap_set_state(TAP_RESET);
                        jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
+                       if (jtag_ntrst_assert_width)
+                               jtag_add_sleep(jtag_ntrst_assert_width * 1000);
                } else {
                        LOG_DEBUG("TRST line released");
                        if (jtag_ntrst_delay)
@@ -1296,6 +1305,10 @@
        int retval;
        if ((retval = jtag_interface_init(cmd_ctx)) != ERROR_OK)
                return retval;
+
+       if (jtag_reset_on_init)
+         return jtag_init_reset(cmd_ctx);
+
        if (jtag_init_inner(cmd_ctx) == ERROR_OK)
        {
                return ERROR_OK;
@@ -1462,3 +1475,30 @@
 {
        return jtag_ntrst_delay;
 }
+
+
+void jtag_set_nsrst_assert_width(unsigned delay)
+{
+       jtag_nsrst_assert_width = delay;
+}
+unsigned jtag_get_nsrst_assert_width(void)
+{
+       return jtag_nsrst_assert_width;
+}
+void jtag_set_ntrst_assert_width(unsigned delay)
+{
+       jtag_ntrst_assert_width = delay;
+}
+unsigned jtag_get_ntrst_assert_width(void)
+{
+       return jtag_ntrst_assert_width;
+}
+
+void jtag_set_reset_on_init(bool state)
+{
+       jtag_reset_on_init = state;
+}
+bool jtag_get_reset_on_init(void)
+{
+  return jtag_reset_on_init;
+}
Index: src/jtag/jtag.h
===================================================================
--- src/jtag/jtag.h     (revision 2726)
+++ src/jtag/jtag.h     (working copy)
@@ -289,6 +289,15 @@
 void jtag_set_ntrst_delay(unsigned delay);
 unsigned jtag_get_ntrst_delay(void);
 
+void jtag_set_nsrst_assert_width(unsigned delay);
+unsigned jtag_get_nsrst_assert_width(void);
+
+void jtag_set_ntrst_assert_width(unsigned delay);
+unsigned jtag_get_ntrst_assert_width(void);
+
+void jtag_set_reset_on_init(bool state);
+bool jtag_get_reset_on_init(void);
+     
 /// @returns The current state of TRST.
 int jtag_get_trst(void);
 /// @returns The current state of SRST.
Index: src/jtag/tcl.c
===================================================================
--- src/jtag/tcl.c      (revision 2726)
+++ src/jtag/tcl.c      (working copy)
@@ -61,6 +61,9 @@
 static int handle_reset_config_command(struct command_context_s *cmd_ctx, char 
*cmd, char **args, int argc);
 static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, 
char *cmd, char **args, int argc);
 static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, 
char *cmd, char **args, int argc);
+static int handle_jtag_nsrst_assert_width_command(struct command_context_s 
*cmd_ctx, char *cmd, char **args, int argc);
+static int handle_jtag_ntrst_assert_width_command(struct command_context_s 
*cmd_ctx, char *cmd, char **args, int argc);
+static int handle_jtag_reset_on_init_command(struct command_context_s 
*cmd_ctx, char *cmd, char **args, int argc);   
 
 static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char 
*cmd, char **args, int argc);
 
@@ -618,7 +621,12 @@
                COMMAND_ANY, "jtag_nsrst_delay <ms> - delay after deasserting 
srst in ms");
        register_command(cmd_ctx, NULL, "jtag_ntrst_delay", 
handle_jtag_ntrst_delay_command,
                COMMAND_ANY, "jtag_ntrst_delay <ms> - delay after deasserting 
trst in ms");
-
+       register_command(cmd_ctx, NULL, "jtag_nsrst_assert_width", 
handle_jtag_nsrst_assert_width_command,
+               COMMAND_ANY, "jtag_nsrst_assert_width <ms> - delay after 
deasserting srst in ms");
+       register_command(cmd_ctx, NULL, "jtag_ntrst_assert_width", 
handle_jtag_ntrst_assert_width_command,
+               COMMAND_ANY, "jtag_ntrst_assert_width <ms> - delay after 
deasserting trst in ms");
+       register_command(cmd_ctx, NULL, "jtag_reset_on_init", 
handle_jtag_reset_on_init_command,
+                        COMMAND_ANY, "jtag_reset_on_init true/false - reset 
JTAG chain before initializing.");
        register_command(cmd_ctx, NULL, "scan_chain", handle_scan_chain_command,
                COMMAND_EXEC, "print current scan chain configuration");
 
@@ -978,6 +986,61 @@
        return ERROR_OK;
 }
 
+static int handle_jtag_nsrst_assert_width_command(struct command_context_s 
*cmd_ctx,
+               char *cmd, char **args, int argc)
+{
+       if (argc > 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       if (argc == 1)
+       {
+               unsigned delay;
+               int retval = parse_uint(args[0], &delay);
+               if (ERROR_OK != retval)
+                       return retval;
+               jtag_set_nsrst_assert_width(delay);
+       }
+       command_print(cmd_ctx, "jtag_nsrst_assert_width: %u", 
jtag_get_nsrst_assert_width());
+       return ERROR_OK;
+}
+
+static int handle_jtag_ntrst_assert_width_command(struct command_context_s 
*cmd_ctx,
+               char *cmd, char **args, int argc)
+{
+       if (argc > 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       if (argc == 1)
+       {
+               unsigned delay;
+               int retval = parse_uint(args[0], &delay);
+               if (ERROR_OK != retval)
+                       return retval;
+               jtag_set_ntrst_assert_width(delay);
+       }
+       command_print(cmd_ctx, "jtag_ntrst_assert_width: %u", 
jtag_get_ntrst_assert_width());
+       return ERROR_OK;
+}
+
+static int handle_jtag_reset_on_init_command(struct command_context_s *cmd_ctx,
+               char *cmd, char **args, int argc)
+{
+       if (argc > 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       if (argc == 1)
+       {
+               bool state;
+               if (strcmp(args[0], "true") == 0)
+                 state = true;
+               else if (strcmp(args[0], "false") == 0)
+                 state = false;
+               else
+                 return ERROR_COMMAND_SYNTAX_ERROR;
+               jtag_set_reset_on_init(state);
+       }
+       command_print(cmd_ctx, "reset_on_init is  %s",
+                       jtag_get_reset_on_init() ? "true": "false");
+       return ERROR_OK;
+}
+
 static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char 
*cmd, char **args, int argc)
 {
        int retval = ERROR_OK;
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to