SVF: fix checking bit pattern against length
[openocd/ztw.git] / src / svf / svf.c
blob9c597bf7d68e1711cfc2149be61a563bfe109557
1 /*
2 * Copyright (C) 2009 by Simon Qian
3 * SimonQian@SimonQian.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* The specification for SVF is available here:
22 * http://www.asset-intertech.com/support/svf.pdf
23 * Below, this document is refered to as the "SVF spec".
25 * The specification for XSVF is available here:
26 * http://www.xilinx.com/support/documentation/application_notes/xapp503.pdf
27 * Below, this document is refered to as the "XSVF spec".
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
34 #include "jtag.h"
35 #include "svf.h"
36 #include "time_support.h"
39 // SVF command
40 typedef enum
42 ENDDR,
43 ENDIR,
44 FREQUENCY,
45 HDR,
46 HIR,
47 PIO,
48 PIOMAP,
49 RUNTEST,
50 SDR,
51 SIR,
52 STATE,
53 TDR,
54 TIR,
55 TRST,
56 }svf_command_t;
58 static const char *svf_command_name[14] =
60 "ENDDR",
61 "ENDIR",
62 "FREQUENCY",
63 "HDR",
64 "HIR",
65 "PIO",
66 "PIOMAP",
67 "RUNTEST",
68 "SDR",
69 "SIR",
70 "STATE",
71 "TDR",
72 "TIR",
73 "TRST"
76 typedef enum
78 TRST_ON,
79 TRST_OFF,
80 TRST_Z,
81 TRST_ABSENT
82 }trst_mode_t;
84 static const char *svf_trst_mode_name[4] =
86 "ON",
87 "OFF",
88 "Z",
89 "ABSENT"
92 typedef struct
94 tap_state_t from;
95 tap_state_t to;
96 uint32_t num_of_moves;
97 tap_state_t paths[8];
98 }svf_statemove_t;
101 * These paths are from the SVF specification for the STATE command, to be
102 * used when the STATE command only includes the final state. The first
103 * element of the path is the "from" (current) state, and the last one is
104 * the "to" (target) state.
106 * All specified paths are the shortest ones in the JTAG spec, and are thus
107 * not (!!) exact matches for the paths used elsewhere in OpenOCD. Note
108 * that PAUSE-to-PAUSE transitions all go through UPDATE and then CAPTURE,
109 * which has specific effects on the various registers; they are not NOPs.
111 * Paths to RESET are disabled here. As elsewhere in OpenOCD, and in XSVF
112 * and many SVF implementations, we don't want to risk missing that state.
113 * To get to RESET, always we ignore the current state.
115 static const svf_statemove_t svf_statemoves[] =
117 // from to num_of_moves, paths[8]
118 // {TAP_RESET, TAP_RESET, 1, {TAP_RESET}},
119 {TAP_RESET, TAP_IDLE, 2, {TAP_RESET, TAP_IDLE}},
120 {TAP_RESET, TAP_DRPAUSE, 6, {TAP_RESET, TAP_IDLE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DREXIT1, TAP_DRPAUSE}},
121 {TAP_RESET, TAP_IRPAUSE, 7, {TAP_RESET, TAP_IDLE, TAP_DRSELECT, TAP_IRSELECT, TAP_IRCAPTURE, TAP_IREXIT1, TAP_IRPAUSE}},
123 // {TAP_IDLE, TAP_RESET, 4, {TAP_IDLE, TAP_DRSELECT, TAP_IRSELECT, TAP_RESET}},
124 {TAP_IDLE, TAP_IDLE, 1, {TAP_IDLE}},
125 {TAP_IDLE, TAP_DRPAUSE, 5, {TAP_IDLE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DREXIT1, TAP_DRPAUSE}},
126 {TAP_IDLE, TAP_IRPAUSE, 6, {TAP_IDLE, TAP_DRSELECT, TAP_IRSELECT, TAP_IRCAPTURE, TAP_IREXIT1, TAP_IRPAUSE}},
128 // {TAP_DRPAUSE, TAP_RESET, 6, {TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE, TAP_DRSELECT, TAP_IRSELECT, TAP_RESET}},
129 {TAP_DRPAUSE, TAP_IDLE, 4, {TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE, TAP_IDLE}},
130 {TAP_DRPAUSE, TAP_DRPAUSE, 7, {TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DREXIT1, TAP_DRPAUSE}},
131 {TAP_DRPAUSE, TAP_IRPAUSE, 8, {TAP_DRPAUSE, TAP_DREXIT2, TAP_DRUPDATE, TAP_DRSELECT, TAP_IRSELECT, TAP_IRCAPTURE, TAP_IREXIT1, TAP_IRPAUSE}},
133 // {TAP_IRPAUSE, TAP_RESET, 6, {TAP_IRPAUSE, TAP_IREXIT2, TAP_IRUPDATE, TAP_DRSELECT, TAP_IRSELECT, TAP_RESET}},
134 {TAP_IRPAUSE, TAP_IDLE, 4, {TAP_IRPAUSE, TAP_IREXIT2, TAP_IRUPDATE, TAP_IDLE}},
135 {TAP_IRPAUSE, TAP_DRPAUSE, 7, {TAP_IRPAUSE, TAP_IREXIT2, TAP_IRUPDATE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DREXIT1, TAP_DRPAUSE}},
136 {TAP_IRPAUSE, TAP_IRPAUSE, 8, {TAP_IRPAUSE, TAP_IREXIT2, TAP_IRUPDATE, TAP_DRSELECT, TAP_IRSELECT, TAP_IRCAPTURE, TAP_IREXIT1, TAP_IRPAUSE}}
140 #define XXR_TDI (1 << 0)
141 #define XXR_TDO (1 << 1)
142 #define XXR_MASK (1 << 2)
143 #define XXR_SMASK (1 << 3)
144 typedef struct
146 int len;
147 int data_mask;
148 uint8_t *tdi;
149 uint8_t *tdo;
150 uint8_t *mask;
151 uint8_t *smask;
152 }svf_xxr_para_t;
154 typedef struct
156 float frequency;
157 tap_state_t ir_end_state;
158 tap_state_t dr_end_state;
159 tap_state_t runtest_run_state;
160 tap_state_t runtest_end_state;
161 trst_mode_t trst_mode;
163 svf_xxr_para_t hir_para;
164 svf_xxr_para_t hdr_para;
165 svf_xxr_para_t tir_para;
166 svf_xxr_para_t tdr_para;
167 svf_xxr_para_t sir_para;
168 svf_xxr_para_t sdr_para;
169 }svf_para_t;
171 static svf_para_t svf_para;
172 static const svf_para_t svf_para_init =
174 // frequency, ir_end_state, dr_end_state, runtest_run_state, runtest_end_state, trst_mode
175 0, TAP_IDLE, TAP_IDLE, TAP_IDLE, TAP_IDLE, TRST_Z,
176 // hir_para
177 // {len, data_mask, tdi, tdo, mask, smask},
178 {0, 0, NULL, NULL, NULL, NULL},
179 // hdr_para
180 // {len, data_mask, tdi, tdo, mask, smask},
181 {0, 0, NULL, NULL, NULL, NULL},
182 // tir_para
183 // {len, data_mask, tdi, tdo, mask, smask},
184 {0, 0, NULL, NULL, NULL, NULL},
185 // tdr_para
186 // {len, data_mask, tdi, tdo, mask, smask},
187 {0, 0, NULL, NULL, NULL, NULL},
188 // sir_para
189 // {len, data_mask, tdi, tdo, mask, smask},
190 {0, 0, NULL, NULL, NULL, NULL},
191 // sdr_para
192 // {len, data_mask, tdi, tdo, mask, smask},
193 {0, 0, NULL, NULL, NULL, NULL},
196 typedef struct
198 int line_num; // used to record line number of the check operation
199 // so more information could be printed
200 int enabled; // check is enabled or not
201 int buffer_offset; // buffer_offset to buffers
202 int bit_len; // bit length to check
203 }svf_check_tdo_para_t;
205 #define SVF_CHECK_TDO_PARA_SIZE 1024
206 static svf_check_tdo_para_t *svf_check_tdo_para = NULL;
207 static int svf_check_tdo_para_index = 0;
209 static int svf_read_command_from_file(int fd);
210 static int svf_check_tdo(void);
211 static int svf_add_check_para(uint8_t enabled, int buffer_offset, int bit_len);
212 static int svf_run_command(struct command_context_s *cmd_ctx, char *cmd_str);
213 static int handle_svf_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
215 static int svf_fd = 0;
216 static char *svf_command_buffer = NULL;
217 static int svf_command_buffer_size = 0;
218 static int svf_line_number = 1;
220 static jtag_tap_t *tap = NULL;
222 #define SVF_MAX_BUFFER_SIZE_TO_COMMIT (4 * 1024)
223 static uint8_t *svf_tdi_buffer = NULL, *svf_tdo_buffer = NULL, *svf_mask_buffer = NULL;
224 static int svf_buffer_index = 0, svf_buffer_size = 0;
225 static int svf_quiet = 0;
228 int svf_register_commands(struct command_context_s *cmd_ctx)
230 register_command(cmd_ctx, NULL, "svf", handle_svf_command,
231 COMMAND_EXEC, "run svf <file>");
233 return ERROR_OK;
236 static void svf_free_xxd_para(svf_xxr_para_t *para)
238 if (NULL != para)
240 if (para->tdi != NULL)
242 free(para->tdi);
243 para->tdi = NULL;
245 if (para->tdo != NULL)
247 free(para->tdo);
248 para->tdo = NULL;
250 if (para->mask != NULL)
252 free(para->mask);
253 para->mask = NULL;
255 if (para->smask != NULL)
257 free(para->smask);
258 para->smask = NULL;
263 static unsigned svf_get_mask_u32(int bitlen)
265 uint32_t bitmask;
267 if (bitlen < 0)
269 bitmask = 0;
271 else if (bitlen >= 32)
273 bitmask = 0xFFFFFFFF;
275 else
277 bitmask = (1 << bitlen) - 1;
280 return bitmask;
283 int svf_add_statemove(tap_state_t state_to)
285 tap_state_t state_from = cmd_queue_cur_state;
286 uint8_t index;
288 /* when resetting, be paranoid and ignore current state */
289 if (state_to == TAP_RESET) {
290 jtag_add_tlr();
291 return ERROR_OK;
294 for (index = 0; index < DIM(svf_statemoves); index++)
296 if ((svf_statemoves[index].from == state_from)
297 && (svf_statemoves[index].to == state_to))
299 /* recorded path includes current state ... avoid extra TCKs! */
300 if (svf_statemoves[index].num_of_moves > 1)
301 jtag_add_pathmove(svf_statemoves[index].num_of_moves - 1,
302 svf_statemoves[index].paths + 1);
303 else
304 jtag_add_pathmove(svf_statemoves[index].num_of_moves,
305 svf_statemoves[index].paths);
306 return ERROR_OK;
309 LOG_ERROR("SVF: can not move to %s", tap_state_name(state_to));
310 return ERROR_FAIL;
313 static int handle_svf_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
315 #define SVF_NUM_OF_OPTIONS 1
316 int command_num = 0, i;
317 int ret = ERROR_OK;
318 long long time_ago;
320 if ((argc < 1) || (argc > (1 + SVF_NUM_OF_OPTIONS)))
322 command_print(cmd_ctx, "usage: svf <file> [quiet]");
323 return ERROR_FAIL;
326 // parse variant
327 svf_quiet = 0;
328 for (i = 1; i < argc; i++)
330 if (!strcmp(args[i], "quiet"))
332 svf_quiet = 1;
334 else
336 LOG_ERROR("unknown variant for svf: %s", args[i]);
338 // no need to free anything now
339 return ERROR_FAIL;
343 if ((svf_fd = open(args[0], O_RDONLY)) < 0)
345 command_print(cmd_ctx, "file \"%s\" not found", args[0]);
347 // no need to free anything now
348 return ERROR_FAIL;
351 LOG_USER("svf processing file: \"%s\"", args[0]);
353 // get time
354 time_ago = timeval_ms();
356 // init
357 svf_line_number = 1;
358 svf_command_buffer_size = 0;
360 svf_check_tdo_para_index = 0;
361 svf_check_tdo_para = malloc(sizeof(svf_check_tdo_para_t) * SVF_CHECK_TDO_PARA_SIZE);
362 if (NULL == svf_check_tdo_para)
364 LOG_ERROR("not enough memory");
365 ret = ERROR_FAIL;
366 goto free_all;
369 svf_buffer_index = 0;
370 // double the buffer size
371 // in case current command cannot be commited, and next command is a bit scan command
372 // here is 32K bits for this big scan command, it should be enough
373 // buffer will be reallocated if buffer size is not enough
374 svf_tdi_buffer = (uint8_t *)malloc(2 * SVF_MAX_BUFFER_SIZE_TO_COMMIT);
375 if (NULL == svf_tdi_buffer)
377 LOG_ERROR("not enough memory");
378 ret = ERROR_FAIL;
379 goto free_all;
381 svf_tdo_buffer = (uint8_t *)malloc(2 * SVF_MAX_BUFFER_SIZE_TO_COMMIT);
382 if (NULL == svf_tdo_buffer)
384 LOG_ERROR("not enough memory");
385 ret = ERROR_FAIL;
386 goto free_all;
388 svf_mask_buffer = (uint8_t *)malloc(2 * SVF_MAX_BUFFER_SIZE_TO_COMMIT);
389 if (NULL == svf_mask_buffer)
391 LOG_ERROR("not enough memory");
392 ret = ERROR_FAIL;
393 goto free_all;
395 svf_buffer_size = 2 * SVF_MAX_BUFFER_SIZE_TO_COMMIT;
397 memcpy(&svf_para, &svf_para_init, sizeof(svf_para));
399 // TAP_RESET
400 jtag_add_tlr();
402 while (ERROR_OK == svf_read_command_from_file(svf_fd))
404 if (ERROR_OK != svf_run_command(cmd_ctx, svf_command_buffer))
406 LOG_ERROR("fail to run command at line %d", svf_line_number);
407 ret = ERROR_FAIL;
408 break;
410 command_num++;
412 if (ERROR_OK != jtag_execute_queue())
414 ret = ERROR_FAIL;
416 else if (ERROR_OK != svf_check_tdo())
418 ret = ERROR_FAIL;
421 // print time
422 command_print(cmd_ctx, "%lld ms used", timeval_ms() - time_ago);
424 free_all:
426 close(svf_fd);
427 svf_fd = 0;
429 // free buffers
430 if (svf_command_buffer)
432 free(svf_command_buffer);
433 svf_command_buffer = NULL;
434 svf_command_buffer_size = 0;
436 if (svf_check_tdo_para)
438 free(svf_check_tdo_para);
439 svf_check_tdo_para = NULL;
440 svf_check_tdo_para_index = 0;
442 if (svf_tdi_buffer)
444 free(svf_tdi_buffer);
445 svf_tdi_buffer = NULL;
447 if (svf_tdo_buffer)
449 free(svf_tdo_buffer);
450 svf_tdo_buffer = NULL;
452 if (svf_mask_buffer)
454 free(svf_mask_buffer);
455 svf_mask_buffer = NULL;
457 svf_buffer_index = 0;
458 svf_buffer_size = 0;
460 svf_free_xxd_para(&svf_para.hdr_para);
461 svf_free_xxd_para(&svf_para.hir_para);
462 svf_free_xxd_para(&svf_para.tdr_para);
463 svf_free_xxd_para(&svf_para.tir_para);
464 svf_free_xxd_para(&svf_para.sdr_para);
465 svf_free_xxd_para(&svf_para.sir_para);
467 if (ERROR_OK == ret)
469 command_print(cmd_ctx, "svf file programmed successfully for %d commands", command_num);
471 else
473 command_print(cmd_ctx, "svf file programmed failed");
476 return ret;
479 #define SVFP_CMD_INC_CNT 1024
480 static int svf_read_command_from_file(int fd)
482 char ch, *tmp_buffer = NULL;
483 int cmd_pos = 0, cmd_ok = 0, slash = 0, comment = 0;
485 while (!cmd_ok && (read(fd, &ch, 1) > 0))
487 switch (ch)
489 case '!':
490 slash = 0;
491 comment = 1;
492 break;
493 case '/':
494 if (++slash == 2)
496 comment = 1;
498 break;
499 case ';':
500 slash = 0;
501 if (!comment)
503 cmd_ok = 1;
505 break;
506 case '\n':
507 svf_line_number++;
508 case '\r':
509 slash = 0;
510 comment = 0;
511 break;
512 default:
513 if (!comment)
515 if (cmd_pos >= svf_command_buffer_size - 1)
517 tmp_buffer = (char*)malloc(svf_command_buffer_size + SVFP_CMD_INC_CNT); // 1 more byte for '\0'
518 if (NULL == tmp_buffer)
520 LOG_ERROR("not enough memory");
521 return ERROR_FAIL;
523 if (svf_command_buffer_size > 0)
525 memcpy(tmp_buffer, svf_command_buffer, svf_command_buffer_size);
527 if (svf_command_buffer != NULL)
529 free(svf_command_buffer);
531 svf_command_buffer = tmp_buffer;
532 svf_command_buffer_size += SVFP_CMD_INC_CNT;
533 tmp_buffer = NULL;
535 svf_command_buffer[cmd_pos++] = (char)toupper(ch);
537 break;
541 if (cmd_ok)
543 svf_command_buffer[cmd_pos] = '\0';
544 return ERROR_OK;
546 else
548 return ERROR_FAIL;
552 static int svf_parse_cmd_string(char *str, int len, char **argus, int *num_of_argu)
554 int pos = 0, num = 0, space_found = 1;
556 while (pos < len)
558 switch (str[pos])
560 case '\n':
561 case '\r':
562 case '!':
563 case '/':
564 LOG_ERROR("fail to parse svf command");
565 return ERROR_FAIL;
566 break;
567 case ' ':
568 space_found = 1;
569 str[pos] = '\0';
570 break;
571 default:
572 if (space_found)
574 argus[num++] = &str[pos];
575 space_found = 0;
577 break;
579 pos++;
582 *num_of_argu = num;
584 return ERROR_OK;
587 bool svf_tap_state_is_stable(tap_state_t state)
589 return (TAP_RESET == state) || (TAP_IDLE == state)
590 || (TAP_DRPAUSE == state) || (TAP_IRPAUSE == state);
593 static int svf_find_string_in_array(char *str, char **strs, int num_of_element)
595 int i;
597 for (i = 0; i < num_of_element; i++)
599 if (!strcmp(str, strs[i]))
601 return i;
604 return 0xFF;
607 static int svf_adjust_array_length(uint8_t **arr, int orig_bit_len, int new_bit_len)
609 int new_byte_len = (new_bit_len + 7) >> 3;
611 if ((NULL == *arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3)))
613 if (*arr != NULL)
615 free(*arr);
616 *arr = NULL;
618 *arr = (uint8_t*)malloc(new_byte_len);
619 if (NULL == *arr)
621 LOG_ERROR("not enough memory");
622 return ERROR_FAIL;
624 memset(*arr, 0, new_byte_len);
626 return ERROR_OK;
629 static int svf_copy_hexstring_to_binary(char *str, uint8_t **bin, int orig_bit_len, int bit_len)
631 int i, str_len = strlen(str), str_hbyte_len = (bit_len + 3) >> 2;
632 uint8_t ch = 0;
634 if (ERROR_OK != svf_adjust_array_length(bin, orig_bit_len, bit_len))
636 LOG_ERROR("fail to adjust length of array");
637 return ERROR_FAIL;
640 for (i = 0; i < str_hbyte_len; i++)
642 ch = 0;
643 while (str_len > 0)
645 ch = str[--str_len];
647 if (!isblank(ch))
649 if ((ch >= '0') && (ch <= '9'))
651 ch = ch - '0';
652 break;
654 else if ((ch >= 'A') && (ch <= 'F'))
656 ch = ch - 'A' + 10;
657 break;
659 else
661 LOG_ERROR("invalid hex string");
662 return ERROR_FAIL;
666 ch = 0;
669 // write bin
670 if (i % 2)
672 // MSB
673 (*bin)[i / 2] |= ch << 4;
675 else
677 // LSB
678 (*bin)[i / 2] = 0;
679 (*bin)[i / 2] |= ch;
683 // consume optional leading '0' characters
684 while (str_len > 0 && str[str_len - 1] == '0')
685 str_len--;
687 // check valid
688 if (str_len > 0 || (ch & ~((2 << ((bit_len - 1) % 4)) - 1)) != 0)
690 LOG_ERROR("value execeeds length");
691 return ERROR_FAIL;
694 return ERROR_OK;
697 static int svf_check_tdo(void)
699 int i, len, index;
701 for (i = 0; i < svf_check_tdo_para_index; i++)
703 index = svf_check_tdo_para[i].buffer_offset;
704 len = svf_check_tdo_para[i].bit_len;
705 if ((svf_check_tdo_para[i].enabled)
706 && buf_cmp_mask(&svf_tdi_buffer[index], &svf_tdo_buffer[index], &svf_mask_buffer[index], len))
708 unsigned bitmask;
709 unsigned received, expected, tapmask;
710 bitmask = svf_get_mask_u32(svf_check_tdo_para[i].bit_len);
712 memcpy(&received, svf_tdi_buffer + index, sizeof(unsigned));
713 memcpy(&expected, svf_tdo_buffer + index, sizeof(unsigned));
714 memcpy(&tapmask, svf_mask_buffer + index, sizeof(unsigned));
715 LOG_ERROR("tdo check error at line %d",
716 svf_check_tdo_para[i].line_num);
717 LOG_ERROR("read = 0x%X, want = 0x%X, mask = 0x%X",
718 received & bitmask,
719 expected & bitmask,
720 tapmask & bitmask);
721 return ERROR_FAIL;
724 svf_check_tdo_para_index = 0;
726 return ERROR_OK;
729 static int svf_add_check_para(uint8_t enabled, int buffer_offset, int bit_len)
731 if (svf_check_tdo_para_index >= SVF_CHECK_TDO_PARA_SIZE)
733 LOG_ERROR("toooooo many operation undone");
734 return ERROR_FAIL;
737 svf_check_tdo_para[svf_check_tdo_para_index].line_num = svf_line_number;
738 svf_check_tdo_para[svf_check_tdo_para_index].bit_len = bit_len;
739 svf_check_tdo_para[svf_check_tdo_para_index].enabled = enabled;
740 svf_check_tdo_para[svf_check_tdo_para_index].buffer_offset = buffer_offset;
741 svf_check_tdo_para_index++;
743 return ERROR_OK;
746 static int svf_execute_tap(void)
748 if (ERROR_OK != jtag_execute_queue())
750 return ERROR_FAIL;
752 else if (ERROR_OK != svf_check_tdo())
754 return ERROR_FAIL;
757 svf_buffer_index = 0;
759 return ERROR_OK;
762 static int svf_run_command(struct command_context_s *cmd_ctx, char *cmd_str)
764 char *argus[256], command;
765 int num_of_argu = 0, i;
767 // tmp variable
768 int i_tmp;
770 // for RUNTEST
771 int run_count;
772 float min_time, max_time;
773 // for XXR
774 svf_xxr_para_t *xxr_para_tmp;
775 uint8_t **pbuffer_tmp;
776 scan_field_t field;
777 // for STATE
778 tap_state_t *path = NULL, state;
780 if (!svf_quiet)
782 LOG_USER("%s", svf_command_buffer);
785 if (ERROR_OK != svf_parse_cmd_string(cmd_str, strlen(cmd_str), argus, &num_of_argu))
787 return ERROR_FAIL;
790 /* NOTE: we're a bit loose here, because we ignore case in
791 * TAP state names (instead of insisting on uppercase).
794 command = svf_find_string_in_array(argus[0],
795 (char **)svf_command_name, DIM(svf_command_name));
796 switch (command)
798 case ENDDR:
799 case ENDIR:
800 if (num_of_argu != 2)
802 LOG_ERROR("invalid parameter of %s", argus[0]);
803 return ERROR_FAIL;
806 i_tmp = tap_state_by_name(argus[1]);
808 if (svf_tap_state_is_stable(i_tmp))
810 if (command == ENDIR)
812 svf_para.ir_end_state = i_tmp;
813 LOG_DEBUG("\tIR end_state = %s",
814 tap_state_name(i_tmp));
816 else
818 svf_para.dr_end_state = i_tmp;
819 LOG_DEBUG("\tDR end_state = %s",
820 tap_state_name(i_tmp));
823 else
825 LOG_ERROR("%s: %s is not a stable state",
826 argus[0], argus[1]);
827 return ERROR_FAIL;
829 break;
830 case FREQUENCY:
831 if ((num_of_argu != 1) && (num_of_argu != 3))
833 LOG_ERROR("invalid parameter of %s", argus[0]);
834 return ERROR_FAIL;
836 if (1 == num_of_argu)
838 // TODO: set jtag speed to full speed
839 svf_para.frequency = 0;
841 else
843 if (strcmp(argus[2], "HZ"))
845 LOG_ERROR("HZ not found in FREQUENCY command");
846 return ERROR_FAIL;
848 if (ERROR_OK != svf_execute_tap())
850 return ERROR_FAIL;
852 svf_para.frequency = atof(argus[1]);
853 // TODO: set jtag speed to
854 if (svf_para.frequency > 0)
856 command_run_linef(cmd_ctx, "jtag_khz %d", (int)svf_para.frequency / 1000);
857 LOG_DEBUG("\tfrequency = %f", svf_para.frequency);
860 break;
861 case HDR:
862 xxr_para_tmp = &svf_para.hdr_para;
863 goto XXR_common;
864 case HIR:
865 xxr_para_tmp = &svf_para.hir_para;
866 goto XXR_common;
867 case TDR:
868 xxr_para_tmp = &svf_para.tdr_para;
869 goto XXR_common;
870 case TIR:
871 xxr_para_tmp = &svf_para.tir_para;
872 goto XXR_common;
873 case SDR:
874 xxr_para_tmp = &svf_para.sdr_para;
875 goto XXR_common;
876 case SIR:
877 xxr_para_tmp = &svf_para.sir_para;
878 goto XXR_common;
879 XXR_common:
880 // XXR length [TDI (tdi)] [TDO (tdo)][MASK (mask)] [SMASK (smask)]
881 if ((num_of_argu > 10) || (num_of_argu % 2))
883 LOG_ERROR("invalid parameter of %s", argus[0]);
884 return ERROR_FAIL;
886 i_tmp = xxr_para_tmp->len;
887 xxr_para_tmp->len = atoi(argus[1]);
888 LOG_DEBUG("\tlength = %d", xxr_para_tmp->len);
889 xxr_para_tmp->data_mask = 0;
890 for (i = 2; i < num_of_argu; i += 2)
892 if ((strlen(argus[i + 1]) < 3) || (argus[i + 1][0] != '(') || (argus[i + 1][strlen(argus[i + 1]) - 1] != ')'))
894 LOG_ERROR("data section error");
895 return ERROR_FAIL;
897 argus[i + 1][strlen(argus[i + 1]) - 1] = '\0';
898 // TDI, TDO, MASK, SMASK
899 if (!strcmp(argus[i], "TDI"))
901 // TDI
902 pbuffer_tmp = &xxr_para_tmp->tdi;
903 xxr_para_tmp->data_mask |= XXR_TDI;
905 else if (!strcmp(argus[i], "TDO"))
907 // TDO
908 pbuffer_tmp = &xxr_para_tmp->tdo;
909 xxr_para_tmp->data_mask |= XXR_TDO;
911 else if (!strcmp(argus[i], "MASK"))
913 // MASK
914 pbuffer_tmp = &xxr_para_tmp->mask;
915 xxr_para_tmp->data_mask |= XXR_MASK;
917 else if (!strcmp(argus[i], "SMASK"))
919 // SMASK
920 pbuffer_tmp = &xxr_para_tmp->smask;
921 xxr_para_tmp->data_mask |= XXR_SMASK;
923 else
925 LOG_ERROR("unknow parameter: %s", argus[i]);
926 return ERROR_FAIL;
928 if (ERROR_OK != svf_copy_hexstring_to_binary(&argus[i + 1][1], pbuffer_tmp, i_tmp, xxr_para_tmp->len))
930 LOG_ERROR("fail to parse hex value");
931 return ERROR_FAIL;
933 LOG_DEBUG("\t%s = 0x%X", argus[i], (**(int**)pbuffer_tmp) & svf_get_mask_u32(xxr_para_tmp->len));
935 // If a command changes the length of the last scan of the same type and the MASK parameter is absent,
936 // the mask pattern used is all cares
937 if (!(xxr_para_tmp->data_mask & XXR_MASK) && (i_tmp != xxr_para_tmp->len))
939 // MASK not defined and length changed
940 if (ERROR_OK != svf_adjust_array_length(&xxr_para_tmp->mask, i_tmp, xxr_para_tmp->len))
942 LOG_ERROR("fail to adjust length of array");
943 return ERROR_FAIL;
945 buf_set_ones(xxr_para_tmp->mask, xxr_para_tmp->len);
947 // If TDO is absent, no comparison is needed, set the mask to 0
948 if (!(xxr_para_tmp->data_mask & XXR_TDO))
950 if (NULL == xxr_para_tmp->tdo)
952 if (ERROR_OK != svf_adjust_array_length(&xxr_para_tmp->tdo, i_tmp, xxr_para_tmp->len))
954 LOG_ERROR("fail to adjust length of array");
955 return ERROR_FAIL;
958 if (NULL == xxr_para_tmp->mask)
960 if (ERROR_OK != svf_adjust_array_length(&xxr_para_tmp->mask, i_tmp, xxr_para_tmp->len))
962 LOG_ERROR("fail to adjust length of array");
963 return ERROR_FAIL;
966 memset(xxr_para_tmp->mask, 0, (xxr_para_tmp->len + 7) >> 3);
968 // do scan if necessary
969 if (SDR == command)
971 // check buffer size first, reallocate if necessary
972 i = svf_para.hdr_para.len + svf_para.sdr_para.len + svf_para.tdr_para.len;
973 if ((svf_buffer_size - svf_buffer_index) < ((i + 7) >> 3))
975 #if 1
976 // simply print error message
977 LOG_ERROR("buffer is not enough, report to author");
978 return ERROR_FAIL;
979 #else
980 uint8_t *buffer_tmp;
982 // reallocate buffer
983 buffer_tmp = (uint8_t *)malloc(svf_buffer_index + ((i + 7) >> 3));
984 if (NULL == buffer_tmp)
986 LOG_ERROR("not enough memory");
987 return ERROR_FAIL;
989 memcpy(buffer_tmp, svf_tdi_buffer, svf_buffer_index);
990 // svf_tdi_buffer isn't NULL here
991 free(svf_tdi_buffer);
992 svf_tdi_buffer = buffer_tmp;
994 buffer_tmp = (uint8_t *)malloc(svf_buffer_index + ((i + 7) >> 3));
995 if (NULL == buffer_tmp)
997 LOG_ERROR("not enough memory");
998 return ERROR_FAIL;
1000 memcpy(buffer_tmp, svf_tdo_buffer, svf_buffer_index);
1001 // svf_tdo_buffer isn't NULL here
1002 free(svf_tdo_buffer);
1003 svf_tdo_buffer = buffer_tmp;
1005 buffer_tmp = (uint8_t *)malloc(svf_buffer_index + ((i + 7) >> 3));
1006 if (NULL == buffer_tmp)
1008 LOG_ERROR("not enough memory");
1009 return ERROR_FAIL;
1011 memcpy(buffer_tmp, svf_mask_buffer, svf_buffer_index);
1012 // svf_mask_buffer isn't NULL here
1013 free(svf_mask_buffer);
1014 svf_mask_buffer = buffer_tmp;
1016 buffer_tmp = NULL;
1017 svf_buffer_size = svf_buffer_index + ((i + 7) >> 3);
1018 #endif
1021 // assemble dr data
1022 i = 0;
1023 buf_set_buf(svf_para.hdr_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.hdr_para.len);
1024 i += svf_para.hdr_para.len;
1025 buf_set_buf(svf_para.sdr_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.sdr_para.len);
1026 i += svf_para.sdr_para.len;
1027 buf_set_buf(svf_para.tdr_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.tdr_para.len);
1028 i += svf_para.tdr_para.len;
1030 // add check data
1031 if (svf_para.sdr_para.data_mask & XXR_TDO)
1033 // assemble dr mask data
1034 i = 0;
1035 buf_set_buf(svf_para.hdr_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.hdr_para.len);
1036 i += svf_para.hdr_para.len;
1037 buf_set_buf(svf_para.sdr_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.sdr_para.len);
1038 i += svf_para.sdr_para.len;
1039 buf_set_buf(svf_para.tdr_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.tdr_para.len);
1040 i += svf_para.tdr_para.len;
1041 // assemble dr check data
1042 i = 0;
1043 buf_set_buf(svf_para.hdr_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.hdr_para.len);
1044 i += svf_para.hdr_para.len;
1045 buf_set_buf(svf_para.sdr_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.sdr_para.len);
1046 i += svf_para.sdr_para.len;
1047 buf_set_buf(svf_para.tdr_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.tdr_para.len);
1048 i += svf_para.tdr_para.len;
1050 svf_add_check_para(1, svf_buffer_index, i);
1052 else
1054 svf_add_check_para(0, svf_buffer_index, i);
1056 field.tap = tap;
1057 field.num_bits = i;
1058 field.out_value = &svf_tdi_buffer[svf_buffer_index];
1059 field.in_value = &svf_tdi_buffer[svf_buffer_index];
1060 /* NOTE: doesn't use SVF-specified state paths */
1061 jtag_add_plain_dr_scan(1, &field, svf_para.dr_end_state);
1063 svf_buffer_index += (i + 7) >> 3;
1065 else if (SIR == command)
1067 // check buffer size first, reallocate if necessary
1068 i = svf_para.hir_para.len + svf_para.sir_para.len + svf_para.tir_para.len;
1069 if ((svf_buffer_size - svf_buffer_index) < ((i + 7) >> 3))
1071 #if 1
1072 // simply print error message
1073 LOG_ERROR("buffer is not enough, report to author");
1074 return ERROR_FAIL;
1075 #else
1076 uint8_t *buffer_tmp;
1078 // reallocate buffer
1079 buffer_tmp = (uint8_t *)malloc(svf_buffer_index + ((i + 7) >> 3));
1080 if (NULL == buffer_tmp)
1082 LOG_ERROR("not enough memory");
1083 return ERROR_FAIL;
1085 memcpy(buffer_tmp, svf_tdi_buffer, svf_buffer_index);
1086 // svf_tdi_buffer isn't NULL here
1087 free(svf_tdi_buffer);
1088 svf_tdi_buffer = buffer_tmp;
1090 buffer_tmp = (uint8_t *)malloc(svf_buffer_index + ((i + 7) >> 3));
1091 if (NULL == buffer_tmp)
1093 LOG_ERROR("not enough memory");
1094 return ERROR_FAIL;
1096 memcpy(buffer_tmp, svf_tdo_buffer, svf_buffer_index);
1097 // svf_tdo_buffer isn't NULL here
1098 free(svf_tdo_buffer);
1099 svf_tdo_buffer = buffer_tmp;
1101 buffer_tmp = (uint8_t *)malloc(svf_buffer_index + ((i + 7) >> 3));
1102 if (NULL == buffer_tmp)
1104 LOG_ERROR("not enough memory");
1105 return ERROR_FAIL;
1107 memcpy(buffer_tmp, svf_mask_buffer, svf_buffer_index);
1108 // svf_mask_buffer isn't NULL here
1109 free(svf_mask_buffer);
1110 svf_mask_buffer = buffer_tmp;
1112 buffer_tmp = NULL;
1113 svf_buffer_size = svf_buffer_index + ((i + 7) >> 3);
1114 #endif
1117 // assemble ir data
1118 i = 0;
1119 buf_set_buf(svf_para.hir_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.hir_para.len);
1120 i += svf_para.hir_para.len;
1121 buf_set_buf(svf_para.sir_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.sir_para.len);
1122 i += svf_para.sir_para.len;
1123 buf_set_buf(svf_para.tir_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.tir_para.len);
1124 i += svf_para.tir_para.len;
1126 // add check data
1127 if (svf_para.sir_para.data_mask & XXR_TDO)
1129 // assemble dr mask data
1130 i = 0;
1131 buf_set_buf(svf_para.hir_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.hir_para.len);
1132 i += svf_para.hir_para.len;
1133 buf_set_buf(svf_para.sir_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.sir_para.len);
1134 i += svf_para.sir_para.len;
1135 buf_set_buf(svf_para.tir_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.tir_para.len);
1136 i += svf_para.tir_para.len;
1137 // assemble dr check data
1138 i = 0;
1139 buf_set_buf(svf_para.hir_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.hir_para.len);
1140 i += svf_para.hir_para.len;
1141 buf_set_buf(svf_para.sir_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.sir_para.len);
1142 i += svf_para.sir_para.len;
1143 buf_set_buf(svf_para.tir_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.tir_para.len);
1144 i += svf_para.tir_para.len;
1146 svf_add_check_para(1, svf_buffer_index, i);
1148 else
1150 svf_add_check_para(0, svf_buffer_index, i);
1152 field.tap = tap;
1153 field.num_bits = i;
1154 field.out_value = &svf_tdi_buffer[svf_buffer_index];
1155 field.in_value = &svf_tdi_buffer[svf_buffer_index];
1156 /* NOTE: doesn't use SVF-specified state paths */
1157 jtag_add_plain_ir_scan(1, &field, svf_para.ir_end_state);
1159 svf_buffer_index += (i + 7) >> 3;
1161 break;
1162 case PIO:
1163 case PIOMAP:
1164 LOG_ERROR("PIO and PIOMAP are not supported");
1165 return ERROR_FAIL;
1166 break;
1167 case RUNTEST:
1168 // RUNTEST [run_state] run_count run_clk [min_time SEC [MAXIMUM max_time SEC]] [ENDSTATE end_state]
1169 // RUNTEST [run_state] min_time SEC [MAXIMUM max_time SEC] [ENDSTATE end_state]
1170 if ((num_of_argu < 3) && (num_of_argu > 11))
1172 LOG_ERROR("invalid parameter of %s", argus[0]);
1173 return ERROR_FAIL;
1175 // init
1176 run_count = 0;
1177 min_time = 0;
1178 max_time = 0;
1179 i = 1;
1181 // run_state
1182 i_tmp = tap_state_by_name(argus[i]);
1183 if (i_tmp != TAP_INVALID)
1185 if (svf_tap_state_is_stable(i_tmp))
1187 svf_para.runtest_run_state = i_tmp;
1189 /* When a run_state is specified, the new
1190 * run_state becomes the default end_state.
1192 svf_para.runtest_end_state = i_tmp;
1193 LOG_DEBUG("\trun_state = %s",
1194 tap_state_name(i_tmp));
1195 i++;
1197 else
1199 LOG_ERROR("%s: %s is not a stable state",
1200 argus[0], tap_state_name(i_tmp));
1201 return ERROR_FAIL;
1205 // run_count run_clk
1206 if (((i + 2) <= num_of_argu) && strcmp(argus[i + 1], "SEC"))
1208 if (!strcmp(argus[i + 1], "TCK"))
1210 // clock source is TCK
1211 run_count = atoi(argus[i]);
1212 LOG_DEBUG("\trun_count@TCK = %d", run_count);
1214 else
1216 LOG_ERROR("%s not supported for clock", argus[i + 1]);
1217 return ERROR_FAIL;
1219 i += 2;
1221 // min_time SEC
1222 if (((i + 2) <= num_of_argu) && !strcmp(argus[i + 1], "SEC"))
1224 min_time = atof(argus[i]);
1225 LOG_DEBUG("\tmin_time = %fs", min_time);
1226 i += 2;
1228 // MAXIMUM max_time SEC
1229 if (((i + 3) <= num_of_argu) && !strcmp(argus[i], "MAXIMUM") && !strcmp(argus[i + 2], "SEC"))
1231 max_time = atof(argus[i + 1]);
1232 LOG_DEBUG("\tmax_time = %fs", max_time);
1233 i += 3;
1235 // ENDSTATE end_state
1236 if (((i + 2) <= num_of_argu) && !strcmp(argus[i], "ENDSTATE"))
1238 i_tmp = tap_state_by_name(argus[i + 1]);
1240 if (svf_tap_state_is_stable(i_tmp))
1242 svf_para.runtest_end_state = i_tmp;
1243 LOG_DEBUG("\tend_state = %s",
1244 tap_state_name(i_tmp));
1246 else
1248 LOG_ERROR("%s: %s is not a stable state",
1249 argus[0], tap_state_name(i_tmp));
1250 return ERROR_FAIL;
1252 i += 2;
1254 // calculate run_count
1255 if ((0 == run_count) && (min_time > 0))
1257 run_count = min_time * svf_para.frequency;
1259 // all parameter should be parsed
1260 if (i == num_of_argu)
1262 if (run_count > 0)
1264 // run_state and end_state is checked to be stable state
1265 // TODO: do runtest
1266 #if 1
1267 /* FIXME handle statemove failures */
1268 int retval;
1270 // enter into run_state if necessary
1271 if (cmd_queue_cur_state != svf_para.runtest_run_state)
1273 retval = svf_add_statemove(svf_para.runtest_run_state);
1276 // call jtag_add_clocks
1277 jtag_add_clocks(run_count);
1279 // move to end_state if necessary
1280 if (svf_para.runtest_end_state != svf_para.runtest_run_state)
1282 retval = svf_add_statemove(svf_para.runtest_end_state);
1284 #else
1285 if (svf_para.runtest_run_state != TAP_IDLE)
1287 LOG_ERROR("cannot runtest in %s state",
1288 tap_state_name(svf_para.runtest_run_state));
1289 return ERROR_FAIL;
1292 jtag_add_runtest(run_count, svf_para.runtest_end_state);
1293 #endif
1296 else
1298 LOG_ERROR("fail to parse parameter of RUNTEST, %d out of %d is parsed", i, num_of_argu);
1299 return ERROR_FAIL;
1301 break;
1302 case STATE:
1303 // STATE [pathstate1 [pathstate2 ...[pathstaten]]] stable_state
1304 if (num_of_argu < 2)
1306 LOG_ERROR("invalid parameter of %s", argus[0]);
1307 return ERROR_FAIL;
1309 if (num_of_argu > 2)
1311 // STATE pathstate1 ... stable_state
1312 path = (tap_state_t *)malloc((num_of_argu - 1) * sizeof(tap_state_t));
1313 if (NULL == path)
1315 LOG_ERROR("not enough memory");
1316 return ERROR_FAIL;
1318 num_of_argu--; // num of path
1319 i_tmp = 1; /* path is from parameter 1 */
1320 for (i = 0; i < num_of_argu; i++, i_tmp++)
1322 path[i] = tap_state_by_name(argus[i_tmp]);
1323 if (path[i] == TAP_INVALID)
1325 LOG_ERROR("%s: %s is not a valid state",
1326 argus[0], argus[i_tmp]);
1327 free(path);
1328 return ERROR_FAIL;
1330 /* OpenOCD refuses paths containing TAP_RESET */
1331 if (TAP_RESET == path[i])
1333 /* FIXME last state MUST be stable! */
1334 if (i > 0)
1336 jtag_add_pathmove(i, path);
1338 jtag_add_tlr();
1339 num_of_argu -= i + 1;
1340 i = -1;
1343 if (num_of_argu > 0)
1345 // execute last path if necessary
1346 if (svf_tap_state_is_stable(path[num_of_argu - 1]))
1348 // last state MUST be stable state
1349 jtag_add_pathmove(num_of_argu, path);
1350 LOG_DEBUG("\tmove to %s by path_move",
1351 tap_state_name(path[num_of_argu - 1]));
1353 else
1355 LOG_ERROR("%s: %s is not a stable state",
1356 argus[0],
1357 tap_state_name(path[num_of_argu - 1]));
1358 free(path);
1359 return ERROR_FAIL;
1362 // no need to keep this memory, in jtag_add_pathmove, path will be duplicated
1363 if (NULL != path)
1365 free(path);
1366 path = NULL;
1369 else
1371 // STATE stable_state
1372 state = tap_state_by_name(argus[1]);
1373 if (svf_tap_state_is_stable(state))
1375 LOG_DEBUG("\tmove to %s by svf_add_statemove",
1376 tap_state_name(state));
1377 /* FIXME handle statemove failures */
1378 svf_add_statemove(state);
1380 else
1382 LOG_ERROR("%s: %s is not a stable state",
1383 argus[0], tap_state_name(state));
1384 return ERROR_FAIL;
1387 break;
1388 case TRST:
1389 // TRST trst_mode
1390 if (num_of_argu != 2)
1392 LOG_ERROR("invalid parameter of %s", argus[0]);
1393 return ERROR_FAIL;
1395 if (svf_para.trst_mode != TRST_ABSENT)
1397 if (ERROR_OK != svf_execute_tap())
1399 return ERROR_FAIL;
1401 i_tmp = svf_find_string_in_array(argus[1],
1402 (char **)svf_trst_mode_name,
1403 DIM(svf_trst_mode_name));
1404 switch (i_tmp)
1406 case TRST_ON:
1407 jtag_add_reset(1, 0);
1408 break;
1409 case TRST_Z:
1410 case TRST_OFF:
1411 jtag_add_reset(0, 0);
1412 break;
1413 case TRST_ABSENT:
1414 break;
1415 default:
1416 LOG_ERROR("unknown TRST mode: %s", argus[1]);
1417 return ERROR_FAIL;
1419 svf_para.trst_mode = i_tmp;
1420 LOG_DEBUG("\ttrst_mode = %s", svf_trst_mode_name[svf_para.trst_mode]);
1422 else
1424 LOG_ERROR("can not accpet TRST command if trst_mode is ABSENT");
1425 return ERROR_FAIL;
1427 break;
1428 default:
1429 LOG_ERROR("invalid svf command: %s", argus[0]);
1430 return ERROR_FAIL;
1431 break;
1434 if (debug_level >= LOG_LVL_DEBUG)
1436 // for convenient debugging, execute tap if possible
1437 if ((svf_buffer_index > 0) && \
1438 (((command != STATE) && (command != RUNTEST)) || \
1439 ((command == STATE) && (num_of_argu == 2))))
1441 if (ERROR_OK != svf_execute_tap())
1443 return ERROR_FAIL;
1446 // output debug info
1447 if ((SIR == command) || (SDR == command))
1449 int read_value;
1450 memcpy(&read_value, svf_tdi_buffer, sizeof(int));
1451 // in debug mode, data is from index 0
1452 int read_mask = svf_get_mask_u32(svf_check_tdo_para[0].bit_len);
1453 LOG_DEBUG("\tTDO read = 0x%X", read_value & read_mask);
1457 else
1459 // for fast executing, execute tap if necessary
1460 // half of the buffer is for the next command
1461 if (((svf_buffer_index >= SVF_MAX_BUFFER_SIZE_TO_COMMIT) || (svf_check_tdo_para_index >= SVF_CHECK_TDO_PARA_SIZE / 2)) && \
1462 (((command != STATE) && (command != RUNTEST)) || \
1463 ((command == STATE) && (num_of_argu == 2))))
1465 return svf_execute_tap();
1469 return ERROR_OK;