SVF player courtesy of Simon Qian <simonqian@SimonQian.com>
[openocd.git] / src / jtag / zy1000.c
index 315b785525ca7dff9737eea60292ae88b66330e5..2c56191326a5af2ece954f385b6702fb0d24d552 100644 (file)
 
 #include <stdlib.h>
 
+#define ZYLIN_VERSION "1.48"
+#define ZYLIN_DATE __DATE__
+#define ZYLIN_TIME __TIME__
+#define ZYLIN_OPENOCD "$Revision: 1241 $"
+#define ZYLIN_OPENOCD_VERSION "Zylin JTAG ZY1000 " ZYLIN_VERSION " " ZYLIN_DATE " " ZYLIN_TIME
+const char *zylin_config_dir="/config/settings";
 
 extern int jtag_error;
 
@@ -77,7 +83,7 @@ static int zy1000_speed_div(int speed, int *khz)
        return ERROR_OK;
 }
 
-static bool readPowerDropout()
+static bool readPowerDropout(void)
 {
        cyg_uint32 state;
        // sample and clear power dropout
@@ -89,7 +95,7 @@ static bool readPowerDropout()
 }
 
 
-static bool readSRST()
+static bool readSRST(void)
 {
        cyg_uint32 state;
        // sample and clear SRST sensing
@@ -146,7 +152,7 @@ int zy1000_read(void)
        return -1;
 }
 
-extern bool readSRST();
+extern bool readSRST(void);
 
 void zy1000_reset(int trst, int srst)
 {
@@ -223,7 +229,7 @@ int zy1000_speed(int speed)
        {
                if(speed > 8190 || speed < 2)
                {
-                       LOG_ERROR("valid ZY1000 jtag_speed=[8190,2]. Divisor is 64MHz / even values between 8190-2, i.e. min 7814Hz, max 32MHz");
+                       LOG_USER("valid ZY1000 jtag_speed=[8190,2]. Divisor is 64MHz / even values between 8190-2, i.e. min 7814Hz, max 32MHz");
                        return ERROR_INVALID_ARGUMENTS;
                }
 
@@ -234,86 +240,141 @@ int zy1000_speed(int speed)
        return ERROR_OK;
 }
 
-int zy1000_register_commands(struct command_context_s *cmd_ctx)
+static bool savePower;
+
+
+static void setPower(bool power)
 {
-       return ERROR_OK;
+       savePower = power;
+       if (power)
+       {
+               HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x14, 0x8);
+       } else
+       {
+               HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x8);
+       }
 }
 
-
-int zy1000_init(void)
+int handle_power_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x30); // Turn on LED1 & LED2
+       if (argc > 1)
+       {
+               return ERROR_INVALID_ARGUMENTS;
+       }
 
-        /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
-       zy1000_reset(0, 0);
-       zy1000_speed(jtag_speed);
+       if (argc == 1)
+       {
+               if (strcmp(args[0], "on") == 0)
+               {
+                       setPower(1);
+               }
+               else if (strcmp(args[0], "off") == 0)
+               {
+                       setPower(0);
+               } else
+               {
+                       command_print(cmd_ctx, "arg is \"on\" or \"off\"");
+                       return ERROR_INVALID_ARGUMENTS;
+               }
+       }
 
-       bitbang_interface = &zy1000_bitbang;
+       command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off");
 
        return ERROR_OK;
 }
 
-int zy1000_quit(void)
+
+/* Give TELNET a way to find out what version this is */
+int handle_zy1000_version_command(struct command_context_s *cmd_ctx, char *cmd,
+               char **args, int argc)
 {
+       if (argc > 1)
+       {
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       }
+       if (argc == 0)
+       {
+               command_print(cmd_ctx, ZYLIN_OPENOCD_VERSION);
+       }
+       else if (strcmp("openocd", args[0]) == 0)
+       {
+               int revision;
+               revision = atol(ZYLIN_OPENOCD+strlen("XRevision: "));
+               command_print(cmd_ctx, "%d", revision);
+       }
+       else if (strcmp("zy1000", args[0]) == 0)
+       {
+               command_print(cmd_ctx, "%s", ZYLIN_VERSION);
+       }
+       else if (strcmp("date", args[0]) == 0)
+       {
+               command_print(cmd_ctx, "%s", ZYLIN_DATE);
+       }
+       else
+       {
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       }
 
        return ERROR_OK;
 }
 
 
-
-/* loads a file and returns a pointer to it in memory. The file contains
- * a 0 byte(sentinel) after len bytes - the length of the file. */
-int loadFile(const char *fileName, void **data, int *len)
+static int
+zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp,
+                                   int argc,
+               Jim_Obj * const *argv)
 {
-       FILE * pFile;
-       pFile = fopen (fileName,"rb");
-       if (pFile==NULL)
+       if (argc != 1)
        {
-               LOG_ERROR("Can't open %s\n", fileName);
-               return ERROR_JTAG_DEVICE_ERROR;
+               Jim_WrongNumArgs(interp, 1, argv, "powerstatus");
+               return JIM_ERR;
        }
-    if (fseek (pFile, 0, SEEK_END)!=0)
-    {
-               LOG_ERROR("Can't open %s\n", fileName);
-               fclose(pFile);
-               return ERROR_JTAG_DEVICE_ERROR;
-    }
-    *len=ftell (pFile);
-    if (*len==-1)
-    {
-               LOG_ERROR("Can't open %s\n", fileName);
-               fclose(pFile);
-               return ERROR_JTAG_DEVICE_ERROR;
-    }
 
-    if (fseek (pFile, 0, SEEK_SET)!=0)
-    {
-               LOG_ERROR("Can't open %s\n", fileName);
-               fclose(pFile);
-               return ERROR_JTAG_DEVICE_ERROR;
-    }
-    *data=malloc(*len+1);
-    if (*data==NULL)
-    {
-               LOG_ERROR("Can't open %s\n", fileName);
-               fclose(pFile);
-               return ERROR_JTAG_DEVICE_ERROR;
-    }
+       cyg_uint32 status;
+       ZY1000_PEEK(ZY1000_JTAG_BASE+0x10, status);
 
-    if (fread(*data, 1, *len, pFile)!=*len)
-    {
-               fclose(pFile);
-       free(*data);
-               LOG_ERROR("Can't open %s\n", fileName);
-               return ERROR_JTAG_DEVICE_ERROR;
-    }
-    fclose (pFile);
-    *(((char *)(*data))+*len)=0; /* sentinel */
+       Jim_SetResult(interp, Jim_NewIntObj(interp, (status&0x80)!=0));
 
-    return ERROR_OK;
+       return JIM_OK;
+}
 
+int zy1000_register_commands(struct command_context_s *cmd_ctx)
+{
+       register_command(cmd_ctx, NULL, "power", handle_power_command, COMMAND_ANY,
+                       "power <on/off> - turn power switch to target on/off. No arguments - print status.");
+       register_command(cmd_ctx, NULL, "zy1000_version", handle_zy1000_version_command,
+                       COMMAND_EXEC, "show zy1000 version numbers");
 
+       Jim_CreateCommand(interp, "powerstatus", zylinjtag_Jim_Command_powerstatus, NULL, NULL);
 
+       return ERROR_OK;
+}
+
+
+
+
+int zy1000_init(void)
+{
+       LOG_USER("%s", ZYLIN_OPENOCD_VERSION);
+
+       ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x30); // Turn on LED1 & LED2
+
+       setPower(true); // on by default
+
+
+        /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
+       zy1000_reset(0, 0);
+       zy1000_speed(jtag_speed);
+
+       bitbang_interface = &zy1000_bitbang;
+
+       return ERROR_OK;
+}
+
+int zy1000_quit(void)
+{
+
+       return ERROR_OK;
 }
 
 
@@ -343,7 +404,7 @@ int interface_jtag_execute_queue(void)
 
 
 
-static cyg_uint32 getShiftValue()
+static cyg_uint32 getShiftValue(void)
 {
        cyg_uint32 value;
        waitIdle();
@@ -352,7 +413,7 @@ static cyg_uint32 getShiftValue()
        return value;
 }
 #if 0
-static cyg_uint32 getShiftValueFlip()
+static cyg_uint32 getShiftValueFlip(void)
 {
        cyg_uint32 value;
        waitIdle();
@@ -365,7 +426,7 @@ static cyg_uint32 getShiftValueFlip()
 #if 0
 static void shiftValueInnerFlip(const enum tap_state state, const enum tap_state endState, int repeat, cyg_uint32 value)
 {
-       VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", tap_state_strings[state], tap_state_strings[endState], repeat, value));
+       VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", jtag_state_name(state), jtag_state_name(endState), repeat, value));
        cyg_uint32 a,b;
        a=state;
        b=endState;
@@ -377,7 +438,7 @@ static void shiftValueInnerFlip(const enum tap_state state, const enum tap_state
 
 extern int jtag_check_value(u8 *captured, void *priv);
 
-static void gotoEndState()
+static void gotoEndState(void)
 {
        setCurrentState(cmd_queue_end_state);
 }
@@ -476,7 +537,7 @@ static __inline void scanFields(int num_fields, scan_field_t *fields, enum tap_s
                        int r=fields[i].in_handler(inBuffer, fields[i].in_handler_priv, fields+i);
                        if (r!=ERROR_OK)
                        {
-                           /* this will cause jtag_execute_queue() to return an error */
+                               /* this will cause jtag_execute_queue() to return an error */
                                jtag_error=r;
                        }
                }
@@ -632,10 +693,10 @@ int interface_jtag_add_reset(int req_trst, int req_srst)
        return ERROR_OK;
 }
 
-int interface_jtag_add_runtest(int num_cycles, enum tap_state state)
+static int zy1000_jtag_add_clocks(int num_cycles, enum tap_state state, enum tap_state clockstate)
 {
        /* num_cycles can be 0 */
-       setCurrentState(TAP_IDLE);
+       setCurrentState(clockstate);
 
        /* execute num_cycles, 32 at the time. */
        int i;
@@ -647,7 +708,7 @@ int interface_jtag_add_runtest(int num_cycles, enum tap_state state)
                {
                        num=num_cycles-i;
                }
-               shiftValueInner(TAP_IDLE, TAP_IDLE, num, 0);
+               shiftValueInner(clockstate, clockstate, num, 0);
        }
 
 #if !TEST_MANUAL()
@@ -673,6 +734,16 @@ int interface_jtag_add_runtest(int num_cycles, enum tap_state state)
        return ERROR_OK;
 }
 
+int interface_jtag_add_runtest(int num_cycles, enum tap_state state)
+{
+       return zy1000_jtag_add_clocks(num_cycles, state, TAP_IDLE);
+}
+
+int interface_jtag_add_clocks(int num_cycles)
+{
+       return zy1000_jtag_add_clocks(num_cycles, cmd_queue_cur_state, cmd_queue_end_state);
+}
+
 int interface_jtag_add_sleep(u32 us)
 {
        jtag_sleep(us);
@@ -703,7 +774,7 @@ int interface_jtag_add_pathmove(int num_states, enum tap_state *path)
                }
                else
                {
-                       LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[path[state_count]]);
+                       LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", jtag_state_name(cur_state), jtag_state_name(path[state_count]));
                        exit(-1);
                }
 
@@ -760,3 +831,27 @@ void embeddedice_write_dcc(jtag_tap_t *tap, int reg_addr, u8 *buffer, int little
        }
 }
 
+int loadFile(const char *fileName, void **data, int *len);
+
+/* boolean parameter stored on config */
+int boolParam(char *var)
+{
+       bool result = false;
+       char *name = alloc_printf("%s/%s", zylin_config_dir, var);
+       if (name == NULL)
+               return result;
+
+       void *data;
+       int len;
+       if (loadFile(name, &data, &len) == ERROR_OK)
+       {
+               if (len > 1)
+                       len = 1;
+               result = strncmp((char *) data, "1", len) == 0;
+               free(data);
+       }
+       free(name);
+       return result;
+}
+
+

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)