Add jtag_queue_command() by Michael Bruck <mbruck@digenius.de> [8/8]
[openocd.git] / src / svf / svf.c
1 /***************************************************************************
2 * Copyright (C) 2009 by Simon Qian *
3 * SimonQian@SimonQian.com *
4 * *
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. *
9 * *
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. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21
22 /* The specification for SVF is available here:
23 * http://www.asset-intertech.com/support/svf.pdf
24 * Below, this document is refered to as the "SVF spec".
25 *
26 * The specification for XSVF is available here:
27 * http://www.xilinx.com/support/documentation/application_notes/xapp503.pdf
28 * Below, this document is refered to as the "XSVF spec".
29 */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include "svf.h"
36 #include "jtag.h"
37 #include "time_support.h"
38
39
40 // SVF command
41 typedef enum
42 {
43 ENDDR,
44 ENDIR,
45 FREQUENCY,
46 HDR,
47 HIR,
48 PIO,
49 PIOMAP,
50 RUNTEST,
51 SDR,
52 SIR,
53 STATE,
54 TDR,
55 TIR,
56 TRST,
57 }svf_command_t;
58
59 const char *svf_command_name[14] =
60 {
61 "ENDDR",
62 "ENDIR",
63 "FREQUENCY",
64 "HDR",
65 "HIR",
66 "PIO",
67 "PIOMAP",
68 "RUNTEST",
69 "SDR",
70 "SIR",
71 "STATE",
72 "TDR",
73 "TIR",
74 "TRST"
75 };
76
77 typedef enum
78 {
79 TRST_ON,
80 TRST_OFF,
81 TRST_Z,
82 TRST_ABSENT
83 }trst_mode_t;
84
85 const char *svf_trst_mode_name[4] =
86 {
87 "ON",
88 "OFF",
89 "Z",
90 "ABSENT"
91 };
92
93 char *svf_tap_state_name[TAP_NUM_STATES];
94
95 #define XXR_TDI (1 << 0)
96 #define XXR_TDO (1 << 1)
97 #define XXR_MASK (1 << 2)
98 #define XXR_SMASK (1 << 3)
99 typedef struct
100 {
101 int len;
102 int data_mask;
103 u8 *tdi;
104 u8 *tdo;
105 u8 *mask;
106 u8 *smask;
107 }svf_xxr_para_t;
108
109 typedef struct
110 {
111 float frequency;
112 tap_state_t ir_end_state;
113 tap_state_t dr_end_state;
114 tap_state_t runtest_run_state;
115 tap_state_t runtest_end_state;
116 trst_mode_t trst_mode;
117
118 svf_xxr_para_t hir_para;
119 svf_xxr_para_t hdr_para;
120 svf_xxr_para_t tir_para;
121 svf_xxr_para_t tdr_para;
122 svf_xxr_para_t sir_para;
123 svf_xxr_para_t sdr_para;
124 }svf_para_t;
125
126 svf_para_t svf_para;
127 const svf_para_t svf_para_init =
128 {
129 // frequency, ir_end_state, dr_end_state, runtest_run_state, runtest_end_state, trst_mode
130 0, TAP_IDLE, TAP_IDLE, TAP_IDLE, TAP_IDLE, TRST_Z,
131 // hir_para
132 // {len, data_mask, tdi, tdo, mask, smask},
133 {0, 0, NULL, NULL, NULL, NULL},
134 // hdr_para
135 // {len, data_mask, tdi, tdo, mask, smask},
136 {0, 0, NULL, NULL, NULL, NULL},
137 // tir_para
138 // {len, data_mask, tdi, tdo, mask, smask},
139 {0, 0, NULL, NULL, NULL, NULL},
140 // tdr_para
141 // {len, data_mask, tdi, tdo, mask, smask},
142 {0, 0, NULL, NULL, NULL, NULL},
143 // sir_para
144 // {len, data_mask, tdi, tdo, mask, smask},
145 {0, 0, NULL, NULL, NULL, NULL},
146 // sdr_para
147 // {len, data_mask, tdi, tdo, mask, smask},
148 {0, 0, NULL, NULL, NULL, NULL},
149 };
150
151 typedef struct
152 {
153 int line_num; // used to record line number of the check operation
154 // so more information could be printed
155 int enabled; // check is enabled or not
156 int buffer_offset; // buffer_offset to buffers
157 int bit_len; // bit length to check
158 }svf_check_tdo_para_t;
159
160 #define SVF_CHECK_TDO_PARA_SIZE 1024
161 static svf_check_tdo_para_t *svf_check_tdo_para = NULL;
162 static int svf_check_tdo_para_index = 0;
163
164 #define dimof(a) (sizeof(a) / sizeof((a)[0]))
165
166 static int svf_read_command_from_file(int fd);
167 static int svf_check_tdo(void);
168 static int svf_add_check_para(u8 enabled, int buffer_offset, int bit_len);
169 static int svf_run_command(struct command_context_s *cmd_ctx, char *cmd_str);
170 static int handle_svf_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
171
172 static int svf_fd = 0;
173 static char *svf_command_buffer = NULL;
174 static int svf_command_buffer_size = 0;
175 static int svf_line_number = 1;
176
177 static jtag_tap_t *tap = NULL;
178 static tap_state_t last_state = TAP_RESET;
179
180 #define SVF_MAX_BUFFER_SIZE_TO_COMMIT (4 * 1024)
181 static u8 *svf_tdi_buffer = NULL, *svf_tdo_buffer = NULL, *svf_mask_buffer = NULL;
182 static int svf_buffer_index = 0, svf_buffer_size = 0;
183 static int svf_quiet = 0;
184
185
186 int svf_register_commands(struct command_context_s *cmd_ctx)
187 {
188 register_command(cmd_ctx, NULL, "svf", handle_svf_command,
189 COMMAND_EXEC, "run svf <file>");
190
191 return ERROR_OK;
192 }
193
194 void svf_free_xxd_para(svf_xxr_para_t *para)
195 {
196 if (NULL != para)
197 {
198 if (para->tdi != NULL)
199 {
200 free(para->tdi);
201 para->tdi = NULL;
202 }
203 if (para->tdo != NULL)
204 {
205 free(para->tdo);
206 para->tdo = NULL;
207 }
208 if (para->mask != NULL)
209 {
210 free(para->mask);
211 para->mask = NULL;
212 }
213 if (para->smask != NULL)
214 {
215 free(para->smask);
216 para->smask = NULL;
217 }
218 }
219 }
220
221 static int handle_svf_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
222 {
223 #define SVF_NUM_OF_OPTIONS 1
224 int command_num = 0, i;
225 int ret = ERROR_OK;
226 long long time_ago;
227
228 if ((argc < 1) || (argc > (1 + SVF_NUM_OF_OPTIONS)))
229 {
230 command_print(cmd_ctx, "usage: svf <file> [quiet]");
231 return ERROR_FAIL;
232 }
233
234 // parse variant
235 svf_quiet = 0;
236 for (i = 1; i < argc; i++)
237 {
238 if (!strcmp(args[i], "quiet"))
239 {
240 svf_quiet = 1;
241 }
242 else
243 {
244 LOG_ERROR("unknown variant for svf: %s", args[i]);
245
246 // no need to free anything now
247 return ERROR_FAIL;
248 }
249 }
250
251 if ((svf_fd = open(args[0], O_RDONLY)) < 0)
252 {
253 command_print(cmd_ctx, "file \"%s\" not found", args[0]);
254
255 // no need to free anything now
256 return ERROR_FAIL;
257 }
258
259 LOG_USER("svf processing file: \"%s\"", args[0]);
260
261 // get time
262 time_ago = timeval_ms();
263
264 // init
265 svf_line_number = 1;
266 svf_command_buffer_size = 0;
267
268 svf_check_tdo_para_index = 0;
269 svf_check_tdo_para = malloc(sizeof(svf_check_tdo_para_t) * SVF_CHECK_TDO_PARA_SIZE);
270 if (NULL == svf_check_tdo_para)
271 {
272 LOG_ERROR("not enough memory");
273 ret = ERROR_FAIL;
274 goto free_all;
275 }
276
277 svf_buffer_index = 0;
278 // double the buffer size
279 // in case current command cannot be commited, and next command is a bit scan command
280 // here is 32K bits for this big scan command, it should be enough
281 // buffer will be reallocated if buffer size is not enough
282 svf_tdi_buffer = (u8 *)malloc(2 * SVF_MAX_BUFFER_SIZE_TO_COMMIT);
283 if (NULL == svf_tdi_buffer)
284 {
285 LOG_ERROR("not enough memory");
286 ret = ERROR_FAIL;
287 goto free_all;
288 }
289 svf_tdo_buffer = (u8 *)malloc(2 * SVF_MAX_BUFFER_SIZE_TO_COMMIT);
290 if (NULL == svf_tdo_buffer)
291 {
292 LOG_ERROR("not enough memory");
293 ret = ERROR_FAIL;
294 goto free_all;
295 }
296 svf_mask_buffer = (u8 *)malloc(2 * SVF_MAX_BUFFER_SIZE_TO_COMMIT);
297 if (NULL == svf_mask_buffer)
298 {
299 LOG_ERROR("not enough memory");
300 ret = ERROR_FAIL;
301 goto free_all;
302 }
303 svf_buffer_size = 2 * SVF_MAX_BUFFER_SIZE_TO_COMMIT;
304
305 memcpy(&svf_para, &svf_para_init, sizeof(svf_para));
306 for (i = 0; i < (int)dimof(svf_tap_state_name); i++)
307 {
308 svf_tap_state_name[i] = (char *)tap_state_name(i);
309 }
310 // TAP_RESET
311 jtag_add_tlr();
312
313 while ( ERROR_OK == svf_read_command_from_file(svf_fd) )
314 {
315 if (ERROR_OK != svf_run_command(cmd_ctx, svf_command_buffer))
316 {
317 LOG_ERROR("fail to run command at line %d", svf_line_number);
318 ret = ERROR_FAIL;
319 break;
320 }
321 command_num++;
322 }
323 if (ERROR_OK != jtag_execute_queue())
324 {
325 ret = ERROR_FAIL;
326 }
327 else if (ERROR_OK != svf_check_tdo())
328 {
329 ret = ERROR_FAIL;
330 }
331
332 // print time
333 command_print(cmd_ctx, "%d ms used", timeval_ms() - time_ago);
334
335 free_all:
336
337 close(svf_fd);
338 svf_fd = 0;
339
340 // free buffers
341 if (svf_command_buffer)
342 {
343 free(svf_command_buffer);
344 svf_command_buffer = NULL;
345 svf_command_buffer_size = 0;
346 }
347 if (svf_check_tdo_para)
348 {
349 free(svf_check_tdo_para);
350 svf_check_tdo_para = NULL;
351 svf_check_tdo_para_index = 0;
352 }
353 if (svf_tdi_buffer)
354 {
355 free(svf_tdi_buffer);
356 svf_tdi_buffer = NULL;
357 }
358 if (svf_tdo_buffer)
359 {
360 free(svf_tdo_buffer);
361 svf_tdo_buffer = NULL;
362 }
363 if (svf_mask_buffer)
364 {
365 free(svf_mask_buffer);
366 svf_mask_buffer = NULL;
367 }
368 svf_buffer_index = 0;
369 svf_buffer_size = 0;
370
371 svf_free_xxd_para(&svf_para.hdr_para);
372 svf_free_xxd_para(&svf_para.hir_para);
373 svf_free_xxd_para(&svf_para.tdr_para);
374 svf_free_xxd_para(&svf_para.tir_para);
375 svf_free_xxd_para(&svf_para.sdr_para);
376 svf_free_xxd_para(&svf_para.sir_para);
377
378 if (ERROR_OK == ret)
379 {
380 command_print(cmd_ctx, "svf file programmed successfully for %d commands", command_num);
381 }
382 else
383 {
384 command_print(cmd_ctx, "svf file programmed failed");
385 }
386
387 return ret;
388 }
389
390 #define SVFP_CMD_INC_CNT 1024
391 static int svf_read_command_from_file(int fd)
392 {
393 char ch, *tmp_buffer = NULL;
394 int cmd_pos = 0, cmd_ok = 0, slash = 0, comment = 0;
395
396 while (!cmd_ok && (read(fd, &ch, 1) > 0) )
397 {
398 switch(ch)
399 {
400 case '!':
401 slash = 0;
402 comment = 1;
403 break;
404 case '/':
405 if (++slash == 2)
406 {
407 comment = 1;
408 }
409 break;
410 case ';':
411 slash = 0;
412 if (!comment)
413 {
414 cmd_ok = 1;
415 }
416 break;
417 case '\n':
418 svf_line_number++;
419 case '\r':
420 slash = 0;
421 comment = 0;
422 break;
423 default:
424 if (!comment)
425 {
426 if (cmd_pos >= svf_command_buffer_size - 1)
427 {
428 tmp_buffer = (char*)malloc(svf_command_buffer_size + SVFP_CMD_INC_CNT); // 1 more byte for '\0'
429 if (NULL == tmp_buffer)
430 {
431 LOG_ERROR("not enough memory");
432 return ERROR_FAIL;
433 }
434 if (svf_command_buffer_size > 0)
435 {
436 memcpy(tmp_buffer, svf_command_buffer, svf_command_buffer_size);
437 }
438 if (svf_command_buffer != NULL)
439 {
440 free(svf_command_buffer);
441 }
442 svf_command_buffer = tmp_buffer;
443 svf_command_buffer_size += SVFP_CMD_INC_CNT;
444 tmp_buffer = NULL;
445 }
446 svf_command_buffer[cmd_pos++] = (char)toupper(ch);
447 }
448 break;
449 }
450 }
451
452 if (cmd_ok)
453 {
454 svf_command_buffer[cmd_pos] = '\0';
455 return ERROR_OK;
456 }
457 else
458 {
459 return ERROR_FAIL;
460 }
461 }
462
463 static int svf_parse_cmd_string(char *str, int len, char **argus, int *num_of_argu)
464 {
465 int pos = 0, num = 0, space_found = 1;
466
467 while (pos < len)
468 {
469 switch(str[pos])
470 {
471 case '\n':
472 case '\r':
473 case '!':
474 case '/':
475 LOG_ERROR("fail to parse svf command");
476 return ERROR_FAIL;
477 break;
478 case ' ':
479 space_found = 1;
480 str[pos] = '\0';
481 break;
482 default:
483 if (space_found)
484 {
485 argus[num++] = &str[pos];
486 space_found = 0;
487 }
488 break;
489 }
490 pos++;
491 }
492
493 *num_of_argu = num;
494
495 return ERROR_OK;
496 }
497
498 static int svf_tap_state_is_stable(tap_state_t state)
499 {
500 return ((TAP_RESET == state) || (TAP_IDLE == state) || (TAP_DRPAUSE == state) || (TAP_IRPAUSE == state));
501 }
502
503 static int svf_tap_state_is_valid(tap_state_t state)
504 {
505 return state >= 0 && state < TAP_NUM_STATES;
506 }
507
508 static int svf_find_string_in_array(char *str, char **strs, int num_of_element)
509 {
510 int i;
511
512 for (i = 0; i < num_of_element; i++)
513 {
514 if (!strcmp(str, strs[i]))
515 {
516 return i;
517 }
518 }
519 return 0xFF;
520 }
521
522 static int svf_adjust_array_length(u8 **arr, int orig_bit_len, int new_bit_len)
523 {
524 int new_byte_len = (new_bit_len + 7) >> 3;
525
526 if ((NULL == *arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3)))
527 {
528 if (*arr != NULL)
529 {
530 free(*arr);
531 *arr = NULL;
532 }
533 *arr = (u8*)malloc(new_byte_len);
534 if (NULL == *arr)
535 {
536 LOG_ERROR("not enough memory");
537 return ERROR_FAIL;
538 }
539 memset(*arr, 0, new_byte_len);
540 }
541 return ERROR_OK;
542 }
543
544 static int svf_copy_hexstring_to_binary(char *str, u8 **bin, int orig_bit_len, int bit_len)
545 {
546 int i, str_len = strlen(str), str_byte_len = (bit_len + 3) >> 2, loop_cnt;
547 u8 ch, need_write = 1;
548
549 if (ERROR_OK != svf_adjust_array_length(bin, orig_bit_len, bit_len))
550 {
551 LOG_ERROR("fail to adjust length of array");
552 return ERROR_FAIL;
553 }
554
555 if (str_byte_len > str_len)
556 {
557 loop_cnt = str_byte_len;
558 }
559 else
560 {
561 loop_cnt = str_len;
562 }
563
564 for (i = 0; i < loop_cnt; i++)
565 {
566 if (i < str_len)
567 {
568 ch = str[str_len - i - 1];
569 if ((ch >= '0') && (ch <= '9'))
570 {
571 ch = ch - '0';
572 }
573 else if ((ch >= 'A') && (ch <= 'F'))
574 {
575 ch = ch - 'A' + 10;
576 }
577 else
578 {
579 LOG_ERROR("invalid hex string");
580 return ERROR_FAIL;
581 }
582 }
583 else
584 {
585 ch = 0;
586 }
587
588 // check valid
589 if (i >= str_byte_len)
590 {
591 // all data written, other data should be all '0's and needn't to be written
592 need_write = 0;
593 if (ch != 0)
594 {
595 LOG_ERROR("value execede length");
596 return ERROR_FAIL;
597 }
598 }
599 else if (i == (str_byte_len - 1))
600 {
601 // last data byte, written if valid
602 if ((ch & ~((1 << (bit_len - 4 * i)) - 1)) != 0)
603 {
604 LOG_ERROR("value execede length");
605 return ERROR_FAIL;
606 }
607 }
608
609 if (need_write)
610 {
611 // write bin
612 if (i % 2)
613 {
614 // MSB
615 (*bin)[i / 2] |= ch << 4;
616 }
617 else
618 {
619 // LSB
620 (*bin)[i / 2] = 0;
621 (*bin)[i / 2] |= ch;
622 }
623 }
624 }
625
626 return ERROR_OK;
627 }
628
629 static int svf_check_tdo(void)
630 {
631 int i, j, byte_len, index;
632
633 for (i = 0; i < svf_check_tdo_para_index; i++)
634 {
635 if (svf_check_tdo_para[i].enabled)
636 {
637 byte_len = (svf_check_tdo_para[i].bit_len + 7) >> 3;
638 index = svf_check_tdo_para[i].buffer_offset;
639 for (j = 0; j < byte_len; j++)
640 {
641 if ((svf_tdi_buffer[index + j] & svf_mask_buffer[index + j]) != svf_tdo_buffer[index + j])
642 {
643 unsigned bitmask = (1 << svf_check_tdo_para[i].bit_len) - 1;
644 unsigned received, expected, tapmask;
645 memcpy(&received, svf_tdi_buffer + index, sizeof(unsigned));
646 memcpy(&expected, svf_tdo_buffer + index, sizeof(unsigned));
647 memcpy(&tapmask, svf_mask_buffer + index, sizeof(unsigned));
648 LOG_ERROR("tdo check error at line %d, "
649 "read = 0x%X, want = 0x%X, mask = 0x%X",
650 svf_check_tdo_para[i].line_num,
651 received & bitmask,
652 expected & bitmask,
653 tapmask & bitmask);
654 return ERROR_FAIL;
655 }
656 }
657 }
658 }
659 svf_check_tdo_para_index = 0;
660
661 return ERROR_OK;
662 }
663
664 static int svf_add_check_para(u8 enabled, int buffer_offset, int bit_len)
665 {
666 if (svf_check_tdo_para_index >= SVF_CHECK_TDO_PARA_SIZE)
667 {
668 LOG_ERROR("toooooo many operation undone");
669 return ERROR_FAIL;
670 }
671
672 svf_check_tdo_para[svf_check_tdo_para_index].line_num = svf_line_number;
673 svf_check_tdo_para[svf_check_tdo_para_index].bit_len = bit_len;
674 svf_check_tdo_para[svf_check_tdo_para_index].enabled = enabled;
675 svf_check_tdo_para[svf_check_tdo_para_index].buffer_offset = buffer_offset;
676 svf_check_tdo_para_index++;
677
678 return ERROR_OK;
679 }
680
681 static int svf_execute_tap(void)
682 {
683 if (ERROR_OK != jtag_execute_queue())
684 {
685 return ERROR_FAIL;
686 }
687 else if (ERROR_OK != svf_check_tdo())
688 {
689 return ERROR_FAIL;
690 }
691
692 svf_buffer_index = 0;
693
694 return ERROR_OK;
695 }
696
697 // not good to use this
698 extern void* cmd_queue_alloc(size_t size);
699 extern void jtag_queue_command(jtag_command_t * cmd);
700
701 static int svf_run_command(struct command_context_s *cmd_ctx, char *cmd_str)
702 {
703 char *argus[256], command;
704 int num_of_argu = 0, i;
705
706 // tmp variable
707 int i_tmp;
708
709 // for RUNTEST
710 int run_count;
711 float min_time, max_time;
712 // for XXR
713 svf_xxr_para_t *xxr_para_tmp;
714 u8 **pbuffer_tmp;
715 scan_field_t field;
716 // for STATE
717 tap_state_t *path = NULL, state;
718
719 if (!svf_quiet)
720 {
721 LOG_USER("%s", svf_command_buffer);
722 }
723
724 if (ERROR_OK != svf_parse_cmd_string(cmd_str, strlen(cmd_str), argus, &num_of_argu))
725 {
726 return ERROR_FAIL;
727 }
728
729 command = svf_find_string_in_array(argus[0], (char **)svf_command_name, dimof(svf_command_name));
730 switch(command)
731 {
732 case ENDDR:
733 case ENDIR:
734 if (num_of_argu != 2)
735 {
736 LOG_ERROR("invalid parameter of %s", argus[0]);
737 return ERROR_FAIL;
738 }
739 i_tmp = svf_find_string_in_array(argus[1], (char **)svf_tap_state_name, dimof(svf_tap_state_name));
740 if (svf_tap_state_is_stable(i_tmp))
741 {
742 if (command == ENDIR)
743 {
744 svf_para.ir_end_state = i_tmp;
745 LOG_DEBUG("\tir_end_state = %s", svf_tap_state_name[svf_para.ir_end_state]);
746 }
747 else
748 {
749 svf_para.dr_end_state = i_tmp;
750 LOG_DEBUG("\tdr_end_state = %s", svf_tap_state_name[svf_para.dr_end_state]);
751 }
752 }
753 else
754 {
755 LOG_ERROR("%s is not valid state", argus[1]);
756 return ERROR_FAIL;
757 }
758 break;
759 case FREQUENCY:
760 if ((num_of_argu != 1) && (num_of_argu != 3))
761 {
762 LOG_ERROR("invalid parameter of %s", argus[0]);
763 return ERROR_FAIL;
764 }
765 if (1 == num_of_argu)
766 {
767 // TODO: set jtag speed to full speed
768 svf_para.frequency = 0;
769 }
770 else
771 {
772 if (strcmp(argus[2], "HZ"))
773 {
774 LOG_ERROR("HZ not found in FREQUENCY command");
775 return ERROR_FAIL;
776 }
777 if (ERROR_OK != svf_execute_tap())
778 {
779 return ERROR_FAIL;
780 }
781 svf_para.frequency = atof(argus[1]);
782 // TODO: set jtag speed to
783 if (svf_para.frequency > 0)
784 {
785 command_run_linef(cmd_ctx, "jtag_khz %d", (int)svf_para.frequency / 1000);
786 LOG_DEBUG("\tfrequency = %f", svf_para.frequency);
787 }
788 }
789 break;
790 case HDR:
791 xxr_para_tmp = &svf_para.hdr_para;
792 goto XXR_common;
793 case HIR:
794 xxr_para_tmp = &svf_para.hir_para;
795 goto XXR_common;
796 case TDR:
797 xxr_para_tmp = &svf_para.tdr_para;
798 goto XXR_common;
799 case TIR:
800 xxr_para_tmp = &svf_para.tir_para;
801 goto XXR_common;
802 case SDR:
803 xxr_para_tmp = &svf_para.sdr_para;
804 goto XXR_common;
805 case SIR:
806 xxr_para_tmp = &svf_para.sir_para;
807 goto XXR_common;
808 XXR_common:
809 // XXR length [TDI (tdi)] [TDO (tdo)][MASK (mask)] [SMASK (smask)]
810 if ((num_of_argu > 10) || (num_of_argu % 2))
811 {
812 LOG_ERROR("invalid parameter of %s", argus[0]);
813 return ERROR_FAIL;
814 }
815 i_tmp = xxr_para_tmp->len;
816 xxr_para_tmp->len = atoi(argus[1]);
817 LOG_DEBUG("\tlength = %d", xxr_para_tmp->len);
818 xxr_para_tmp->data_mask = 0;
819 for (i = 2; i < num_of_argu; i += 2)
820 {
821 if ((strlen(argus[i + 1]) < 3) || (argus[i + 1][0] != '(') || (argus[i + 1][strlen(argus[i + 1]) - 1] != ')'))
822 {
823 LOG_ERROR("data section error");
824 return ERROR_FAIL;
825 }
826 argus[i + 1][strlen(argus[i + 1]) - 1] = '\0';
827 // TDI, TDO, MASK, SMASK
828 if (!strcmp(argus[i], "TDI"))
829 {
830 // TDI
831 pbuffer_tmp = &xxr_para_tmp->tdi;
832 xxr_para_tmp->data_mask |= XXR_TDI;
833 }
834 else if (!strcmp(argus[i], "TDO"))
835 {
836 // TDO
837 pbuffer_tmp = &xxr_para_tmp->tdo;
838 xxr_para_tmp->data_mask |= XXR_TDO;
839 }
840 else if (!strcmp(argus[i], "MASK"))
841 {
842 // MASK
843 pbuffer_tmp = &xxr_para_tmp->mask;
844 xxr_para_tmp->data_mask |= XXR_MASK;
845 }
846 else if (!strcmp(argus[i], "SMASK"))
847 {
848 // SMASK
849 pbuffer_tmp = &xxr_para_tmp->smask;
850 xxr_para_tmp->data_mask |= XXR_SMASK;
851 }
852 else
853 {
854 LOG_ERROR("unknow parameter: %s", argus[i]);
855 return ERROR_FAIL;
856 }
857 if (ERROR_OK != svf_copy_hexstring_to_binary(&argus[i + 1][1], pbuffer_tmp, i_tmp, xxr_para_tmp->len))
858 {
859 LOG_ERROR("fail to parse hex value");
860 return ERROR_FAIL;
861 }
862 LOG_DEBUG("\t%s = 0x%X", argus[i], (**(int**)pbuffer_tmp) & ((1 << (xxr_para_tmp->len)) - 1));
863 }
864 // If a command changes the length of the last scan of the same type and the MASK parameter is absent,
865 // the mask pattern used is all cares
866 if (!(xxr_para_tmp->data_mask & XXR_MASK) && (i_tmp != xxr_para_tmp->len))
867 {
868 // MASK not defined and length changed
869 if (ERROR_OK != svf_adjust_array_length(&xxr_para_tmp->mask, i_tmp, xxr_para_tmp->len))
870 {
871 LOG_ERROR("fail to adjust length of array");
872 return ERROR_FAIL;
873 }
874 buf_set_ones(xxr_para_tmp->mask, xxr_para_tmp->len);
875 }
876 // do scan if necessary
877 if (SDR == command)
878 {
879 // check buffer size first, reallocate if necessary
880 i = svf_para.hdr_para.len + svf_para.sdr_para.len + svf_para.tdr_para.len;
881 if ((svf_buffer_size - svf_buffer_index) < ((i + 7) >> 3))
882 {
883 #if 1
884 // simply print error message
885 LOG_ERROR("buffer is not enough, report to author");
886 return ERROR_FAIL;
887 #else
888 u8 *buffer_tmp;
889
890 // reallocate buffer
891 buffer_tmp = (u8 *)malloc(svf_buffer_index + ((i + 7) >> 3));
892 if (NULL == buffer_tmp)
893 {
894 LOG_ERROR("not enough memory");
895 return ERROR_FAIL;
896 }
897 memcpy(buffer_tmp, svf_tdi_buffer, svf_buffer_index);
898 // svf_tdi_buffer isn't NULL here
899 free(svf_tdi_buffer);
900 svf_tdi_buffer = buffer_tmp;
901
902 buffer_tmp = (u8 *)malloc(svf_buffer_index + ((i + 7) >> 3));
903 if (NULL == buffer_tmp)
904 {
905 LOG_ERROR("not enough memory");
906 return ERROR_FAIL;
907 }
908 memcpy(buffer_tmp, svf_tdo_buffer, svf_buffer_index);
909 // svf_tdo_buffer isn't NULL here
910 free(svf_tdo_buffer);
911 svf_tdo_buffer = buffer_tmp;
912
913 buffer_tmp = (u8 *)malloc(svf_buffer_index + ((i + 7) >> 3));
914 if (NULL == buffer_tmp)
915 {
916 LOG_ERROR("not enough memory");
917 return ERROR_FAIL;
918 }
919 memcpy(buffer_tmp, svf_mask_buffer, svf_buffer_index);
920 // svf_mask_buffer isn't NULL here
921 free(svf_mask_buffer);
922 svf_mask_buffer = buffer_tmp;
923
924 buffer_tmp = NULL;
925 svf_buffer_size = svf_buffer_index + ((i + 7) >> 3);
926 #endif
927 }
928
929 // assemble dr data
930 i = 0;
931 buf_set_buf(svf_para.hdr_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.hdr_para.len);
932 i += svf_para.hdr_para.len;
933 buf_set_buf(svf_para.sdr_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.sdr_para.len);
934 i += svf_para.sdr_para.len;
935 buf_set_buf(svf_para.tdr_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.tdr_para.len);
936 i += svf_para.tdr_para.len;
937
938 // add check data
939 if (svf_para.sdr_para.data_mask & XXR_TDO)
940 {
941 // assemble dr mask data
942 i = 0;
943 buf_set_buf(svf_para.hdr_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.hdr_para.len);
944 i += svf_para.hdr_para.len;
945 buf_set_buf(svf_para.sdr_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.sdr_para.len);
946 i += svf_para.sdr_para.len;
947 buf_set_buf(svf_para.tdr_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.tdr_para.len);
948 i += svf_para.tdr_para.len;
949 // assemble dr check data
950 i = 0;
951 buf_set_buf(svf_para.hdr_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.hdr_para.len);
952 i += svf_para.hdr_para.len;
953 buf_set_buf(svf_para.sdr_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.sdr_para.len);
954 i += svf_para.sdr_para.len;
955 buf_set_buf(svf_para.tdr_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.tdr_para.len);
956 i += svf_para.tdr_para.len;
957
958 svf_add_check_para(1, svf_buffer_index, i);
959 }
960 else
961 {
962 svf_add_check_para(0, svf_buffer_index, i);
963 }
964 field.tap = tap;
965 field.num_bits = i;
966 field.out_value = &svf_tdi_buffer[svf_buffer_index];
967
968 field.in_value = &svf_tdi_buffer[svf_buffer_index];
969
970
971
972
973 jtag_add_plain_dr_scan(1, &field, svf_para.dr_end_state);
974
975 svf_buffer_index += (i + 7) >> 3;
976 last_state = svf_para.dr_end_state;
977 }
978 else if (SIR == command)
979 {
980 // check buffer size first, reallocate if necessary
981 i = svf_para.hir_para.len + svf_para.sir_para.len + svf_para.tir_para.len;
982 if ((svf_buffer_size - svf_buffer_index) < ((i + 7) >> 3))
983 {
984 #if 1
985 // simply print error message
986 LOG_ERROR("buffer is not enough, report to author");
987 return ERROR_FAIL;
988 #else
989 u8 *buffer_tmp;
990
991 // reallocate buffer
992 buffer_tmp = (u8 *)malloc(svf_buffer_index + ((i + 7) >> 3));
993 if (NULL == buffer_tmp)
994 {
995 LOG_ERROR("not enough memory");
996 return ERROR_FAIL;
997 }
998 memcpy(buffer_tmp, svf_tdi_buffer, svf_buffer_index);
999 // svf_tdi_buffer isn't NULL here
1000 free(svf_tdi_buffer);
1001 svf_tdi_buffer = buffer_tmp;
1002
1003 buffer_tmp = (u8 *)malloc(svf_buffer_index + ((i + 7) >> 3));
1004 if (NULL == buffer_tmp)
1005 {
1006 LOG_ERROR("not enough memory");
1007 return ERROR_FAIL;
1008 }
1009 memcpy(buffer_tmp, svf_tdo_buffer, svf_buffer_index);
1010 // svf_tdo_buffer isn't NULL here
1011 free(svf_tdo_buffer);
1012 svf_tdo_buffer = buffer_tmp;
1013
1014 buffer_tmp = (u8 *)malloc(svf_buffer_index + ((i + 7) >> 3));
1015 if (NULL == buffer_tmp)
1016 {
1017 LOG_ERROR("not enough memory");
1018 return ERROR_FAIL;
1019 }
1020 memcpy(buffer_tmp, svf_mask_buffer, svf_buffer_index);
1021 // svf_mask_buffer isn't NULL here
1022 free(svf_mask_buffer);
1023 svf_mask_buffer = buffer_tmp;
1024
1025 buffer_tmp = NULL;
1026 svf_buffer_size = svf_buffer_index + ((i + 7) >> 3);
1027 #endif
1028 }
1029
1030 // assemble ir data
1031 i = 0;
1032 buf_set_buf(svf_para.hir_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.hir_para.len);
1033 i += svf_para.hir_para.len;
1034 buf_set_buf(svf_para.sir_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.sir_para.len);
1035 i += svf_para.sir_para.len;
1036 buf_set_buf(svf_para.tir_para.tdi, 0, &svf_tdi_buffer[svf_buffer_index], i, svf_para.tir_para.len);
1037 i += svf_para.tir_para.len;
1038
1039 // add check data
1040 if (svf_para.sir_para.data_mask & XXR_TDO)
1041 {
1042 // assemble dr mask data
1043 i = 0;
1044 buf_set_buf(svf_para.hir_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.hir_para.len);
1045 i += svf_para.hir_para.len;
1046 buf_set_buf(svf_para.sir_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.sir_para.len);
1047 i += svf_para.sir_para.len;
1048 buf_set_buf(svf_para.tir_para.mask, 0, &svf_mask_buffer[svf_buffer_index], i, svf_para.tir_para.len);
1049 i += svf_para.tir_para.len;
1050 // assemble dr check data
1051 i = 0;
1052 buf_set_buf(svf_para.hir_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.hir_para.len);
1053 i += svf_para.hir_para.len;
1054 buf_set_buf(svf_para.sir_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.sir_para.len);
1055 i += svf_para.sir_para.len;
1056 buf_set_buf(svf_para.tir_para.tdo, 0, &svf_tdo_buffer[svf_buffer_index], i, svf_para.tir_para.len);
1057 i += svf_para.tir_para.len;
1058
1059 svf_add_check_para(1, svf_buffer_index, i);
1060 }
1061 else
1062 {
1063 svf_add_check_para(0, svf_buffer_index, i);
1064 }
1065 field.tap = tap;
1066 field.num_bits = i;
1067 field.out_value = &svf_tdi_buffer[svf_buffer_index];
1068
1069 field.in_value = &svf_tdi_buffer[svf_buffer_index];
1070
1071
1072
1073
1074 jtag_add_plain_ir_scan(1, &field, svf_para.ir_end_state);
1075
1076 svf_buffer_index += (i + 7) >> 3;
1077 last_state = svf_para.ir_end_state;
1078 }
1079 break;
1080 case PIO:
1081 case PIOMAP:
1082 LOG_ERROR("PIO and PIOMAP are not supported");
1083 return ERROR_FAIL;
1084 break;
1085 case RUNTEST:
1086 // RUNTEST [run_state] run_count run_clk [min_time SEC [MAXIMUM max_time SEC]] [ENDSTATE end_state]
1087 // RUNTEST [run_state] min_time SEC [MAXIMUM max_time SEC] [ENDSTATE end_state]
1088 if ((num_of_argu < 3) && (num_of_argu > 11))
1089 {
1090 LOG_ERROR("invalid parameter of %s", argus[0]);
1091 return ERROR_FAIL;
1092 }
1093 // init
1094 run_count = 0;
1095 min_time = 0;
1096 max_time = 0;
1097 i = 1;
1098 // run_state
1099 i_tmp = svf_find_string_in_array(argus[i], (char **)svf_tap_state_name, dimof(svf_tap_state_name));
1100 if (svf_tap_state_is_valid(i_tmp))
1101 {
1102 if (svf_tap_state_is_stable(i_tmp))
1103 {
1104 svf_para.runtest_run_state = i_tmp;
1105
1106 // When a run_state is specified, the new run_state becomes the default end_state
1107 svf_para.runtest_end_state = i_tmp;
1108 LOG_DEBUG("\trun_state = %s", svf_tap_state_name[svf_para.runtest_run_state]);
1109 i++;
1110 }
1111 else
1112 {
1113 LOG_ERROR("%s is not valid state", svf_tap_state_name[i_tmp]);
1114 return ERROR_FAIL;
1115 }
1116 }
1117 // run_count run_clk
1118 if (((i + 2) <= num_of_argu) && strcmp(argus[i + 1], "SEC"))
1119 {
1120 if (!strcmp(argus[i + 1], "TCK"))
1121 {
1122 // clock source is TCK
1123 run_count = atoi(argus[i]);
1124 LOG_DEBUG("\trun_count@TCK = %d", run_count);
1125 }
1126 else
1127 {
1128 LOG_ERROR("%s not supported for clock", argus[i + 1]);
1129 return ERROR_FAIL;
1130 }
1131 i += 2;
1132 }
1133 // min_time SEC
1134 if (((i + 2) <= num_of_argu) && !strcmp(argus[i + 1], "SEC"))
1135 {
1136 min_time = atof(argus[i]);
1137 LOG_DEBUG("\tmin_time = %fs", min_time);
1138 i += 2;
1139 }
1140 // MAXIMUM max_time SEC
1141 if (((i + 3) <= num_of_argu) && !strcmp(argus[i], "MAXIMUM") && !strcmp(argus[i + 2], "SEC"))
1142 {
1143 max_time = atof(argus[i + 1]);
1144 LOG_DEBUG("\tmax_time = %fs", max_time);
1145 i += 3;
1146 }
1147 // ENDSTATE end_state
1148 if (((i + 2) <= num_of_argu) && !strcmp(argus[i], "ENDSTATE"))
1149 {
1150 i_tmp = svf_find_string_in_array(argus[i + 1], (char **)svf_tap_state_name, dimof(svf_tap_state_name));
1151 if (svf_tap_state_is_stable(i_tmp))
1152 {
1153 svf_para.runtest_end_state = i_tmp;
1154 LOG_DEBUG("\tend_state = %s", svf_tap_state_name[svf_para.runtest_end_state]);
1155 }
1156 else
1157 {
1158 LOG_ERROR("%s is not valid state", svf_tap_state_name[i_tmp]);
1159 return ERROR_FAIL;
1160 }
1161 i += 2;
1162 }
1163 // calculate run_count
1164 if ((0 == run_count) && (min_time > 0))
1165 {
1166 run_count = min_time * svf_para.frequency;
1167 }
1168 // all parameter should be parsed
1169 if (i == num_of_argu)
1170 {
1171 if (run_count > 0)
1172 {
1173 // run_state and end_state is checked to be stable state
1174 // TODO: do runtest
1175 #if 1
1176 // enter into run_state if necessary
1177 if (last_state != svf_para.runtest_run_state)
1178 {
1179 jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
1180
1181 jtag_queue_command(cmd);
1182
1183 cmd->type = JTAG_STATEMOVE;
1184 cmd->cmd.statemove = cmd_queue_alloc(sizeof(statemove_command_t));
1185 cmd->cmd.statemove->end_state = svf_para.runtest_run_state;
1186
1187 cmd_queue_end_state = cmd_queue_cur_state = cmd->cmd.statemove->end_state;
1188 }
1189
1190 // call jtag_add_clocks
1191 jtag_add_clocks(run_count);
1192
1193 if (svf_para.runtest_end_state != svf_para.runtest_run_state)
1194 {
1195 // move to end_state
1196 jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
1197
1198 jtag_queue_command(cmd);
1199 cmd->type = JTAG_STATEMOVE;
1200 cmd->cmd.statemove = cmd_queue_alloc(sizeof(statemove_command_t));
1201 cmd->cmd.statemove->end_state = svf_para.runtest_end_state;
1202
1203 cmd_queue_end_state = cmd_queue_cur_state = cmd->cmd.statemove->end_state;
1204 }
1205 last_state = svf_para.runtest_end_state;
1206 #else
1207 if (svf_para.runtest_run_state != TAP_IDLE)
1208 {
1209 // RUNTEST can only executed in TAP_IDLE
1210 LOG_ERROR("cannot runtest in %s state", svf_tap_state_name[svf_para.runtest_run_state]);
1211 return ERROR_FAIL;
1212 }
1213
1214 jtag_add_runtest(run_count, svf_para.runtest_end_state);
1215 #endif
1216 }
1217 }
1218 else
1219 {
1220 LOG_ERROR("fail to parse parameter of RUNTEST, %d out of %d is parsed", i, num_of_argu);
1221 return ERROR_FAIL;
1222 }
1223 break;
1224 case STATE:
1225 // STATE [pathstate1 [pathstate2 ...[pathstaten]]] stable_state
1226 if (num_of_argu < 2)
1227 {
1228 LOG_ERROR("invalid parameter of %s", argus[0]);
1229 return ERROR_FAIL;
1230 }
1231 if (num_of_argu > 2)
1232 {
1233 // STATE pathstate1 ... stable_state
1234 path = (tap_state_t *)malloc((num_of_argu - 1) * sizeof(tap_state_t));
1235 if (NULL == path)
1236 {
1237 LOG_ERROR("not enough memory");
1238 return ERROR_FAIL;
1239 }
1240 num_of_argu--; // num of path
1241 i_tmp = 1; // path is from patameter 1
1242 for (i = 0; i < num_of_argu; i++)
1243 {
1244 path[i] = svf_find_string_in_array(argus[i_tmp++], (char **)svf_tap_state_name, dimof(svf_tap_state_name));
1245 if (!svf_tap_state_is_valid(path[i]))
1246 {
1247 LOG_ERROR("%s is not valid state", svf_tap_state_name[path[i]]);
1248 return ERROR_FAIL;
1249 }
1250 if (TAP_RESET == path[i])
1251 {
1252 if (i > 0)
1253 {
1254 jtag_add_pathmove(i, path);
1255 }
1256 jtag_add_tlr();
1257 num_of_argu -= i + 1;
1258 i = -1;
1259 }
1260 }
1261 if (num_of_argu > 0)
1262 {
1263 // execute last path if necessary
1264 if (svf_tap_state_is_stable(path[num_of_argu - 1]))
1265 {
1266 // last state MUST be stable state
1267 // TODO: call path_move
1268 jtag_add_pathmove(num_of_argu, path);
1269 last_state = path[num_of_argu - 1];
1270 LOG_DEBUG("\tmove to %s by path_move", svf_tap_state_name[path[num_of_argu - 1]]);
1271 }
1272 else
1273 {
1274 LOG_ERROR("%s is not valid state", svf_tap_state_name[path[num_of_argu - 1]]);
1275 return ERROR_FAIL;
1276 }
1277 }
1278 // no need to keep this memory, in jtag_add_pathmove, path will be duplicated
1279 if (NULL != path)
1280 {
1281 free(path);
1282 path = NULL;
1283 }
1284 }
1285 else
1286 {
1287 // STATE stable_state
1288 state = svf_find_string_in_array(argus[1], (char **)svf_tap_state_name, dimof(svf_tap_state_name));
1289 if (svf_tap_state_is_stable(state))
1290 {
1291 // TODO: move to state
1292 jtag_command_t * cmd = cmd_queue_alloc(sizeof(jtag_command_t));
1293
1294 jtag_queue_command(cmd);
1295
1296 cmd->type = JTAG_STATEMOVE;
1297 cmd->cmd.statemove = cmd_queue_alloc(sizeof(statemove_command_t));
1298 cmd->cmd.statemove->end_state = state;
1299
1300 cmd_queue_end_state = cmd_queue_cur_state = cmd->cmd.statemove->end_state;
1301 last_state = state;
1302
1303 LOG_DEBUG("\tmove to %s by state_move", svf_tap_state_name[state]);
1304 }
1305 else
1306 {
1307 LOG_ERROR("%s is not valid state", svf_tap_state_name[state]);
1308 return ERROR_FAIL;
1309 }
1310 }
1311 break;
1312 case TRST:
1313 // TRST trst_mode
1314 if (num_of_argu != 2)
1315 {
1316 LOG_ERROR("invalid parameter of %s", argus[0]);
1317 return ERROR_FAIL;
1318 }
1319 if (svf_para.trst_mode != TRST_ABSENT)
1320 {
1321 if (ERROR_OK != svf_execute_tap())
1322 {
1323 return ERROR_FAIL;
1324 }
1325 i_tmp = svf_find_string_in_array(argus[1], (char **)svf_trst_mode_name, dimof(svf_trst_mode_name));
1326 switch (i_tmp)
1327 {
1328 case TRST_ON:
1329 last_state = TAP_RESET;
1330 jtag_add_reset(1, 0);
1331 break;
1332 case TRST_Z:
1333 case TRST_OFF:
1334 jtag_add_reset(0, 0);
1335 break;
1336 case TRST_ABSENT:
1337 break;
1338 default:
1339 LOG_ERROR("unknown TRST mode: %s", argus[1]);
1340 return ERROR_FAIL;
1341 }
1342 svf_para.trst_mode = i_tmp;
1343 LOG_DEBUG("\ttrst_mode = %s", svf_trst_mode_name[svf_para.trst_mode]);
1344 }
1345 else
1346 {
1347 LOG_ERROR("can not accpet TRST command if trst_mode is ABSENT");
1348 return ERROR_FAIL;
1349 }
1350 break;
1351 default:
1352 LOG_ERROR("invalid svf command: %s", argus[0]);
1353 return ERROR_FAIL;
1354 break;
1355 }
1356
1357 if (debug_level >= LOG_LVL_DEBUG)
1358 {
1359 // for convenient debugging, execute tap if possible
1360 if ((svf_buffer_index > 0) && \
1361 (((command != STATE) && (command != RUNTEST)) || \
1362 ((command == STATE) && (num_of_argu == 2))))
1363 {
1364 if (ERROR_OK != svf_execute_tap())
1365 {
1366 return ERROR_FAIL;
1367 }
1368
1369 // output debug info
1370 if ((SIR == command) || (SDR == command))
1371 {
1372 int read_value;
1373 memcpy(&read_value, svf_tdi_buffer, sizeof(int));
1374 // in debug mode, data is from index 0
1375 int read_mask = (1 << (svf_check_tdo_para[0].bit_len)) - 1;
1376 LOG_DEBUG("\tTDO read = 0x%X", read_value & read_mask);
1377 }
1378 }
1379 }
1380 else
1381 {
1382 // for fast executing, execute tap if necessary
1383 // half of the buffer is for the next command
1384 if (((svf_buffer_index >= SVF_MAX_BUFFER_SIZE_TO_COMMIT) || (svf_check_tdo_para_index >= SVF_CHECK_TDO_PARA_SIZE / 2)) && \
1385 (((command != STATE) && (command != RUNTEST)) || \
1386 ((command == STATE) && (num_of_argu == 2))))
1387 {
1388 return svf_execute_tap();
1389 }
1390 }
1391
1392 return ERROR_OK;
1393 }