Finish JTAG header file modularization; command factoring follows.
[openocd.git] / src / jtag / zy1000.c
index e74478a683feb1372991ff2e286b2988e06e6dbc..2cdd2fdc23bdfe3b069db02b03b7789233a974e1 100644 (file)
 #include "config.h"
 #endif
 
-
-#include "log.h"
-#include "jtag.h"
+#include "embeddedice.h"
+#include "minidriver.h"
+#include "interface.h"
 #include "bitbang.h"
-#include "../target/embeddedice.h"
-
 
 #include <cyg/hal/hal_io.h>             // low level i/o
 #include <cyg/hal/hal_diag.h>
 
-#include <stdlib.h>
 
-#define ZYLIN_VERSION "1.48"
+#define ZYLIN_VERSION "1.52"
 #define ZYLIN_DATE __DATE__
 #define ZYLIN_TIME __TIME__
-#define ZYLIN_OPENOCD "$Revision: 1241 $"
+#define ZYLIN_OPENOCD "$Revision$"
 #define ZYLIN_OPENOCD_VERSION "Zylin JTAG ZY1000 " ZYLIN_VERSION " " ZYLIN_DATE " " ZYLIN_TIME
 const char *zylin_config_dir="/config/settings";
 
-extern int jtag_error;
-
 /* low level command set
  */
 int zy1000_read(void);
@@ -83,7 +78,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
@@ -95,7 +90,7 @@ static bool readPowerDropout()
 }
 
 
-static bool readSRST()
+static bool readSRST(void)
 {
        cyg_uint32 state;
        // sample and clear SRST sensing
@@ -152,7 +147,7 @@ int zy1000_read(void)
        return -1;
 }
 
-extern bool readSRST();
+extern bool readSRST(void);
 
 void zy1000_reset(int trst, int srst)
 {
@@ -285,43 +280,49 @@ int handle_power_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
 
 
 /* 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)
+static int jim_zy1000_version(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
-       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)
+       if ((argc < 1) || (argc > 2))
+               return JIM_ERR;
+       char buff[128];
+       const char *version_str=NULL;
+
+       if (argc == 1)
        {
-               command_print(cmd_ctx, "%s", ZYLIN_DATE);
-       }
-       else
+               version_str=ZYLIN_OPENOCD_VERSION;
+       } else
        {
-               return ERROR_COMMAND_SYNTAX_ERROR;
+               const char *str = Jim_GetString(argv[1], NULL);
+               if (strcmp("openocd", str) == 0)
+               {
+                       int revision;
+                       revision = atol(ZYLIN_OPENOCD+strlen("XRevision: "));
+                       sprintf(buff, "%d", revision);
+                       version_str=buff;
+               }
+               else if (strcmp("zy1000", str) == 0)
+               {
+                       version_str=ZYLIN_VERSION;
+               }
+               else if (strcmp("date", str) == 0)
+               {
+                       version_str=ZYLIN_DATE;
+               }
+               else
+               {
+                       return JIM_ERR;
+               }
        }
 
-       return ERROR_OK;
+       Jim_SetResult(interp, Jim_NewStringObj(interp, version_str, -1));
+
+       return JIM_OK;
 }
 
 
 static int
 zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp,
-                                   int argc,
+                                                                  int argc,
                Jim_Obj * const *argv)
 {
        if (argc != 1)
@@ -342,8 +343,9 @@ 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, "zy1000_version", jim_zy1000_version, NULL, NULL);
+
 
        Jim_CreateCommand(interp, "powerstatus", zylinjtag_Jim_Command_powerstatus, NULL, NULL);
 
@@ -355,7 +357,7 @@ int zy1000_register_commands(struct command_context_s *cmd_ctx)
 
 int zy1000_init(void)
 {
-       LOG_ERROR("%s\n", ZYLIN_OPENOCD_VERSION);
+       LOG_USER("%s", ZYLIN_OPENOCD_VERSION);
 
        ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x30); // Turn on LED1 & LED2
 
@@ -379,7 +381,6 @@ int zy1000_quit(void)
 
 
 
-
 int interface_jtag_execute_queue(void)
 {
        cyg_uint32 empty;
@@ -404,7 +405,7 @@ int interface_jtag_execute_queue(void)
 
 
 
-static cyg_uint32 getShiftValue()
+static cyg_uint32 getShiftValue(void)
 {
        cyg_uint32 value;
        waitIdle();
@@ -413,7 +414,7 @@ static cyg_uint32 getShiftValue()
        return value;
 }
 #if 0
-static cyg_uint32 getShiftValueFlip()
+static cyg_uint32 getShiftValueFlip(void)
 {
        cyg_uint32 value;
        waitIdle();
@@ -424,9 +425,9 @@ static cyg_uint32 getShiftValueFlip()
 #endif
 
 #if 0
-static void shiftValueInnerFlip(const enum tap_state state, const enum tap_state endState, int repeat, cyg_uint32 value)
+static void shiftValueInnerFlip(const tap_state_t state, const tap_state_t endState, int repeat, cyg_uint32 value)
 {
-       VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", jtag_state_name(state), jtag_state_name(endState), repeat, value));
+       VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", tap_state_name(state), tap_state_name(endState), repeat, value));
        cyg_uint32 a,b;
        a=state;
        b=endState;
@@ -438,12 +439,12 @@ 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);
 }
 
-static __inline void scanFields(int num_fields, scan_field_t *fields, enum tap_state shiftState, int pause)
+static __inline void scanFields(int num_fields, scan_field_t *fields, tap_state_t shiftState, tap_state_t end_state)
 {
        int i;
        int j;
@@ -463,31 +464,13 @@ static __inline void scanFields(int num_fields, scan_field_t *fields, enum tap_s
                if (fields[i].in_value!=NULL)
                {
                        inBuffer=fields[i].in_value;
-               } else if (fields[i].in_handler!=NULL)
-               {
-                       if (in_buff_size*8<num_bits)
-                       {
-                               // we need more space
-                               if (in_buff!=NULL)
-                                       free(in_buff);
-                               in_buff=NULL;
-                               in_buff_size=(num_bits+7)/8;
-                               in_buff=malloc(in_buff_size);
-                               if (in_buff==NULL)
-                               {
-                                       LOG_ERROR("Out of memory");
-                                       jtag_error=ERROR_JTAG_QUEUE_FAILED;
-                                       return;
-                               }
-                       }
-                       inBuffer=in_buff;
                }
 
                // here we shuffle N bits out/in
                j=0;
                while (j<num_bits)
                {
-                       enum tap_state pause_state;
+                       tap_state_t pause_state;
                        int l;
                        k=num_bits-j;
                        pause_state=(shiftState==TAP_DRSHIFT)?TAP_DRSHIFT:TAP_IRSHIFT;
@@ -495,10 +478,10 @@ static __inline void scanFields(int num_fields, scan_field_t *fields, enum tap_s
                        {
                                k=32;
                                /* we have more to shift out */
-                       } else if (pause&&(i == num_fields-1))
+                       } else if (i == num_fields-1)
                        {
                                /* this was the last to shift out this time */
-                               pause_state=(shiftState==TAP_DRSHIFT)?TAP_DRPAUSE:TAP_IRPAUSE;
+                               pause_state=end_state;
                        }
 
                        // we have (num_bits+7)/8 bytes of bits to toggle out.
@@ -530,27 +513,16 @@ static __inline void scanFields(int num_fields, scan_field_t *fields, enum tap_s
                        }
                        j+=k;
                }
-
-               if (fields[i].in_handler!=NULL)
-               {
-                       // invoke callback
-                       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 */
-                               jtag_error=r;
-                       }
-               }
        }
 }
 
-int interface_jtag_add_end_state(enum tap_state state)
+int interface_jtag_add_end_state(tap_state_t state)
 {
        return ERROR_OK;
 }
 
 
-int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
+int interface_jtag_add_ir_scan(int num_fields, const scan_field_t *fields, tap_state_t state)
 {
 
        int j;
@@ -559,7 +531,14 @@ int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_st
        for(tap = jtag_NextEnabledTap(NULL); tap!= NULL; tap=nextTap)
        {
                nextTap=jtag_NextEnabledTap(tap);
-               int pause=(nextTap==NULL);
+               tap_state_t end_state;
+               if (nextTap==NULL)
+               {
+                       end_state = cmd_queue_end_state;
+               } else
+               {
+                       end_state = TAP_IRSHIFT;
+               }
 
                int found = 0;
 
@@ -572,16 +551,7 @@ int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_st
                        {
                                found = 1;
 
-                               if ((jtag_verify_capture_ir)&&(fields[j].in_handler==NULL))
-                               {
-                                       jtag_set_check_value(fields+j, tap->expected, tap->expected_mask, NULL);
-                               } else if (jtag_verify_capture_ir)
-                               {
-                                       fields[j].in_check_value = tap->expected;
-                                       fields[j].in_check_mask = tap->expected_mask;
-                               }
-
-                               scanFields(1, fields+j, TAP_IRSHIFT, pause);
+                               scanFields(1, fields+j, TAP_IRSHIFT, end_state);
                                /* update device information */
                                buf_cpy(fields[j].out_value, tap->cur_instr, scan_size);
 
@@ -599,13 +569,12 @@ int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_st
                        memset(&tmp, 0, sizeof(tmp));
                        tmp.out_value = ones;
                        tmp.num_bits = scan_size;
-                       scanFields(1, &tmp, TAP_IRSHIFT, pause);
+                       scanFields(1, &tmp, TAP_IRSHIFT, end_state);
                        /* update device information */
                        buf_cpy(tmp.out_value, tap->cur_instr, scan_size);
                        tap->bypass = 1;
                }
        }
-       gotoEndState();
 
        return ERROR_OK;
 }
@@ -614,17 +583,16 @@ int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_st
 
 
 
-int interface_jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
+int interface_jtag_add_plain_ir_scan(int num_fields, const scan_field_t *fields, tap_state_t state)
 {
-       scanFields(num_fields, fields, TAP_IRSHIFT, 1);
-       gotoEndState();
+       scanFields(num_fields, fields, TAP_IRSHIFT, cmd_queue_end_state);
 
        return ERROR_OK;
 }
 
 /*extern jtag_command_t **jtag_get_last_command_p(void);*/
 
-int interface_jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
+int interface_jtag_add_dr_scan(int num_fields, const scan_field_t *fields, tap_state_t state)
 {
 
        int j;
@@ -633,7 +601,14 @@ int interface_jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_st
        {
                nextTap=jtag_NextEnabledTap(tap);
                int found=0;
-               int pause=(nextTap==NULL);
+               tap_state_t end_state;
+               if (nextTap==NULL)
+               {
+                       end_state = cmd_queue_end_state;
+               } else
+               {
+                       end_state = TAP_DRSHIFT;
+               }
 
                for (j=0; j < num_fields; j++)
                {
@@ -641,7 +616,7 @@ int interface_jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_st
                        {
                                found = 1;
 
-                               scanFields(1, fields+j, TAP_DRSHIFT, pause);
+                               scanFields(1, fields+j, TAP_DRSHIFT, end_state);
                        }
                }
                if (!found)
@@ -650,27 +625,20 @@ int interface_jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_st
                        /* program the scan field to 1 bit length, and ignore it's value */
                        tmp.num_bits = 1;
                        tmp.out_value = NULL;
-                       tmp.out_mask = NULL;
                        tmp.in_value = NULL;
-                       tmp.in_check_value = NULL;
-                       tmp.in_check_mask = NULL;
-                       tmp.in_handler = NULL;
-                       tmp.in_handler_priv = NULL;
 
-                       scanFields(1, &tmp, TAP_DRSHIFT, pause);
+                       scanFields(1, &tmp, TAP_DRSHIFT, end_state);
                }
                else
                {
                }
        }
-       gotoEndState();
        return ERROR_OK;
 }
 
-int interface_jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
+int interface_jtag_add_plain_dr_scan(int num_fields, const scan_field_t *fields, tap_state_t state)
 {
-       scanFields(num_fields, fields, TAP_DRSHIFT, 1);
-       gotoEndState();
+       scanFields(num_fields, fields, TAP_DRSHIFT, cmd_queue_end_state);
        return ERROR_OK;
 }
 
@@ -693,10 +661,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, tap_state_t state, tap_state_t clockstate)
 {
        /* num_cycles can be 0 */
-       setCurrentState(TAP_IDLE);
+       setCurrentState(clockstate);
 
        /* execute num_cycles, 32 at the time. */
        int i;
@@ -708,19 +676,20 @@ 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()
        /* finish in end_state */
        setCurrentState(state);
 #else
-       enum tap_state t=TAP_IDLE;
+       tap_state_t t=TAP_IDLE;
        /* test manual drive code on any target */
        int tms;
-       u8 tms_scan = TAP_MOVE(t, state);
+       u8 tms_scan = tap_get_tms_path(t, state);
+       int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
 
-       for (i = 0; i < 7; i++)
+       for (i = 0; i < tms_count; i++)
        {
                tms = (tms_scan >> i) & 1;
                waitIdle();
@@ -734,13 +703,23 @@ int interface_jtag_add_runtest(int num_cycles, enum tap_state state)
        return ERROR_OK;
 }
 
+int interface_jtag_add_runtest(int num_cycles, tap_state_t 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);
        return ERROR_OK;
 }
 
-int interface_jtag_add_pathmove(int num_states, enum tap_state *path)
+int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
 {
        int state_count;
        int tms = 0;
@@ -750,21 +729,21 @@ int interface_jtag_add_pathmove(int num_states, enum tap_state *path)
 
        state_count = 0;
 
-       enum tap_state cur_state=cmd_queue_cur_state;
+       tap_state_t cur_state=cmd_queue_cur_state;
 
        while (num_states)
        {
-               if (tap_transitions[cur_state].low == path[state_count])
+               if (tap_state_transition(cur_state, false) == path[state_count])
                {
                        tms = 0;
                }
-               else if (tap_transitions[cur_state].high == path[state_count])
+               else if (tap_state_transition(cur_state, true) == path[state_count])
                {
                        tms = 1;
                }
                else
                {
-                       LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", jtag_state_name(cur_state), jtag_state_name(path[state_count]));
+                       LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(cur_state), tap_state_name(path[state_count]));
                        exit(-1);
                }
 
@@ -786,7 +765,7 @@ int interface_jtag_add_pathmove(int num_states, enum tap_state *path)
 void embeddedice_write_dcc(jtag_tap_t *tap, int reg_addr, u8 *buffer, int little, int count)
 {
 //     static int const reg_addr=0x5;
-       enum tap_state end_state=cmd_queue_end_state;
+       tap_state_t end_state=cmd_queue_end_state;
        if (jtag_NextEnabledTap(jtag_NextEnabledTap(NULL))==NULL)
        {
                /* better performance via code duplication */
@@ -843,3 +822,5 @@ int boolParam(char *var)
        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)