]> git.sur5r.net Git - openocd/blob - src/jtag/zy1000/zy1000.c
206b362c6258502cc3c2ccf9c07ce3743ff2fa6b
[openocd] / src / jtag / zy1000 / zy1000.c
1 /***************************************************************************
2  *   Copyright (C) 2007-2008 by Ã˜yvind Harboe                              *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include "embeddedice.h"
24 #include "minidriver.h"
25 #include "interface.h"
26 #include "zy1000_version.h"
27
28 #include <cyg/hal/hal_io.h>             // low level i/o
29 #include <cyg/hal/hal_diag.h>
30
31 #include <time.h>
32
33 #define ZYLIN_VERSION GIT_ZY1000_VERSION
34 #define ZYLIN_DATE __DATE__
35 #define ZYLIN_TIME __TIME__
36 #define ZYLIN_OPENOCD GIT_OPENOCD_VERSION
37 #define ZYLIN_OPENOCD_VERSION "ZY1000 " ZYLIN_VERSION " " ZYLIN_DATE
38
39 /* low level command set
40  */
41 void zy1000_reset(int trst, int srst);
42
43
44 int zy1000_speed(int speed);
45 int zy1000_register_commands(struct command_context *cmd_ctx);
46 int zy1000_init(void);
47 int zy1000_quit(void);
48
49 /* interface commands */
50 int zy1000_handle_zy1000_port_command(struct command_context *cmd_ctx, char *cmd, char **args, int argc);
51
52 static int zy1000_khz(int khz, int *jtag_speed)
53 {
54         if (khz == 0)
55         {
56                 *jtag_speed = 0;
57         }
58         else
59         {
60                 *jtag_speed = 64000/khz;
61         }
62         return ERROR_OK;
63 }
64
65 static int zy1000_speed_div(int speed, int *khz)
66 {
67         if (speed == 0)
68         {
69                 *khz = 0;
70         }
71         else
72         {
73                 *khz = 64000/speed;
74         }
75
76         return ERROR_OK;
77 }
78
79 static bool readPowerDropout(void)
80 {
81         cyg_uint32 state;
82         // sample and clear power dropout
83         HAL_WRITE_UINT32(ZY1000_JTAG_BASE + 0x10, 0x80);
84         HAL_READ_UINT32(ZY1000_JTAG_BASE + 0x10, state);
85         bool powerDropout;
86         powerDropout = (state & 0x80) != 0;
87         return powerDropout;
88 }
89
90
91 static bool readSRST(void)
92 {
93         cyg_uint32 state;
94         // sample and clear SRST sensing
95         HAL_WRITE_UINT32(ZY1000_JTAG_BASE + 0x10, 0x00000040);
96         HAL_READ_UINT32(ZY1000_JTAG_BASE + 0x10, state);
97         bool srstAsserted;
98         srstAsserted = (state & 0x40) != 0;
99         return srstAsserted;
100 }
101
102 static int zy1000_srst_asserted(int *srst_asserted)
103 {
104         *srst_asserted = readSRST();
105         return ERROR_OK;
106 }
107
108 static int zy1000_power_dropout(int *dropout)
109 {
110         *dropout = readPowerDropout();
111         return ERROR_OK;
112 }
113
114
115 struct jtag_interface zy1000_interface =
116 {
117         .name = "ZY1000",
118         .execute_queue = NULL,
119         .speed = zy1000_speed,
120         .register_commands = zy1000_register_commands,
121         .init = zy1000_init,
122         .quit = zy1000_quit,
123         .khz = zy1000_khz,
124         .speed_div = zy1000_speed_div,
125         .power_dropout = zy1000_power_dropout,
126         .srst_asserted = zy1000_srst_asserted,
127 };
128
129 void zy1000_reset(int trst, int srst)
130 {
131         LOG_DEBUG("zy1000 trst=%d, srst=%d", trst, srst);
132         if (!srst)
133         {
134                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x00000001);
135         }
136         else
137         {
138                 /* Danger!!! if clk != 0 when in
139                  * idle in TAP_IDLE, reset halt on str912 will fail.
140                  */
141                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x00000001);
142         }
143
144         if (!trst)
145         {
146                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x00000002);
147         }
148         else
149         {
150                 /* assert reset */
151                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x00000002);
152         }
153
154         if (trst||(srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
155         {
156                 waitIdle();
157                 /* we're now in the RESET state until trst is deasserted */
158                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_RESET);
159         } else
160         {
161                 /* We'll get RCLK failure when we assert TRST, so clear any false positives here */
162                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x400);
163         }
164
165         /* wait for srst to float back up */
166         if (!srst)
167         {
168                 int i;
169                 for (i = 0; i < 1000; i++)
170                 {
171                         // We don't want to sense our own reset, so we clear here.
172                         // There is of course a timing hole where we could loose
173                         // a "real" reset.
174                         if (!readSRST())
175                                 break;
176
177                         /* wait 1ms */
178                         alive_sleep(1);
179                 }
180
181                 if (i == 1000)
182                 {
183                         LOG_USER("SRST didn't deassert after %dms", i);
184                 } else if (i > 1)
185                 {
186                         LOG_USER("SRST took %dms to deassert", i);
187                 }
188         }
189 }
190
191 int zy1000_speed(int speed)
192 {
193         if (speed == 0)
194         {
195                 /*0 means RCLK*/
196                 speed = 0;
197                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x100);
198                 LOG_DEBUG("jtag_speed using RCLK");
199         }
200         else
201         {
202                 if (speed > 8190 || speed < 2)
203                 {
204                         LOG_USER("valid ZY1000 jtag_speed=[8190,2]. Divisor is 64MHz / even values between 8190-2, i.e. min 7814Hz, max 32MHz");
205                         return ERROR_INVALID_ARGUMENTS;
206                 }
207
208                 LOG_USER("jtag_speed %d => JTAG clk=%f", speed, 64.0/(float)speed);
209                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x100);
210                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x1c, speed&~1);
211         }
212         return ERROR_OK;
213 }
214
215 static bool savePower;
216
217
218 static void setPower(bool power)
219 {
220         savePower = power;
221         if (power)
222         {
223                 HAL_WRITE_UINT32(ZY1000_JTAG_BASE + 0x14, 0x8);
224         } else
225         {
226                 HAL_WRITE_UINT32(ZY1000_JTAG_BASE + 0x10, 0x8);
227         }
228 }
229
230 int handle_power_command(struct command_context *cmd_ctx, char *cmd, char **args, int argc)
231 {
232         if (argc > 1)
233         {
234                 return ERROR_INVALID_ARGUMENTS;
235         }
236
237         if (argc == 1)
238         {
239                 bool enable;
240                 COMMAND_PARSE_ON_OFF(args[0], enable);
241                 setPower(enable);
242         }
243
244         command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off");
245
246         return ERROR_OK;
247 }
248
249
250 /* Give TELNET a way to find out what version this is */
251 static int jim_zy1000_version(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
252 {
253         if ((argc < 1) || (argc > 3))
254                 return JIM_ERR;
255         const char *version_str = NULL;
256
257         if (argc == 1)
258         {
259                 version_str = ZYLIN_OPENOCD_VERSION;
260         } else
261         {
262                 const char *str = Jim_GetString(argv[1], NULL);
263                 const char *str2 = NULL;
264                 if (argc > 2)
265                         str2 = Jim_GetString(argv[2], NULL);
266                 if (strcmp("openocd", str) == 0)
267                 {
268                         version_str = ZYLIN_OPENOCD;
269                 }
270                 else if (strcmp("zy1000", str) == 0)
271                 {
272                         version_str = ZYLIN_VERSION;
273                 }
274                 else if (strcmp("date", str) == 0)
275                 {
276                         version_str = ZYLIN_DATE;
277                 }
278                 else if (strcmp("time", str) == 0)
279                 {
280                         version_str = ZYLIN_TIME;
281                 }
282                 else if (strcmp("pcb", str) == 0)
283                 {
284 #ifdef CYGPKG_HAL_NIOS2
285                         version_str="c";
286 #else
287                         version_str="b";
288 #endif
289                 }
290 #ifdef CYGPKG_HAL_NIOS2
291                 else if (strcmp("fpga", str) == 0)
292                 {
293
294                         /* return a list of 32 bit integers to describe the expected
295                          * and actual FPGA
296                          */
297                         static char *fpga_id = "0x12345678 0x12345678 0x12345678 0x12345678";
298                         cyg_uint32 id, timestamp;
299                         HAL_READ_UINT32(SYSID_BASE, id);
300                         HAL_READ_UINT32(SYSID_BASE+4, timestamp);
301                         sprintf(fpga_id, "0x%08x 0x%08x 0x%08x 0x%08x", id, timestamp, SYSID_ID, SYSID_TIMESTAMP);
302                         version_str = fpga_id;
303                         if ((argc>2) && (strcmp("time", str2) == 0))
304                         {
305                             time_t last_mod = timestamp;
306                             char * t = ctime (&last_mod) ;
307                             t[strlen(t)-1] = 0;
308                             version_str = t;
309                         }
310                 }
311 #endif
312
313                 else
314                 {
315                         return JIM_ERR;
316                 }
317         }
318
319         Jim_SetResult(interp, Jim_NewStringObj(interp, version_str, -1));
320
321         return JIM_OK;
322 }
323
324
325 #ifdef CYGPKG_HAL_NIOS2
326 static int jim_zy1000_writefirmware(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
327 {
328         if (argc != 2)
329                 return JIM_ERR;
330
331         int length;
332         int stat;
333         const char *str = Jim_GetString(argv[1], &length);
334
335         /* BUG!!!! skip header! */
336         void *firmware_address=0x4000000;
337         int firmware_length=0x100000;
338
339         if (length>firmware_length)
340                 return JIM_ERR;
341
342         void *err_addr;
343
344     if ((stat = flash_erase((void *)firmware_address, firmware_length, (void **)&err_addr)) != 0)
345     {
346         return JIM_ERR;
347     }
348
349     if ((stat = flash_program(firmware_address, str, length, (void **)&err_addr)) != 0)
350         return JIM_ERR;
351
352     return JIM_OK;
353 }
354 #endif
355
356 static int
357 zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp,
358                                                                    int argc,
359                 Jim_Obj * const *argv)
360 {
361         if (argc != 1)
362         {
363                 Jim_WrongNumArgs(interp, 1, argv, "powerstatus");
364                 return JIM_ERR;
365         }
366
367         cyg_uint32 status;
368         ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, status);
369
370         Jim_SetResult(interp, Jim_NewIntObj(interp, (status&0x80) != 0));
371
372         return JIM_OK;
373 }
374
375 int zy1000_register_commands(struct command_context *cmd_ctx)
376 {
377         register_command(cmd_ctx, NULL, "power", handle_power_command, COMMAND_ANY,
378                         "power <on/off> - turn power switch to target on/off. No arguments - print status.");
379
380         Jim_CreateCommand(interp, "zy1000_version", jim_zy1000_version, NULL, NULL);
381
382
383         Jim_CreateCommand(interp, "powerstatus", zylinjtag_Jim_Command_powerstatus, NULL, NULL);
384
385 #ifdef CYGPKG_HAL_NIOS2
386         Jim_CreateCommand(interp, "updatezy1000firmware", jim_zy1000_writefirmware, NULL, NULL);
387 #endif
388
389
390         return ERROR_OK;
391 }
392
393
394
395
396 int zy1000_init(void)
397 {
398         LOG_USER("%s", ZYLIN_OPENOCD_VERSION);
399
400         ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x30); // Turn on LED1 & LED2
401
402         setPower(true); // on by default
403
404
405          /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
406         zy1000_reset(0, 0);
407         zy1000_speed(jtag_get_speed());
408
409         return ERROR_OK;
410 }
411
412 int zy1000_quit(void)
413 {
414
415         return ERROR_OK;
416 }
417
418
419
420 int interface_jtag_execute_queue(void)
421 {
422         cyg_uint32 empty;
423
424         waitIdle();
425         ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, empty);
426         /* clear JTAG error register */
427         ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x400);
428
429         if ((empty&0x400) != 0)
430         {
431                 LOG_WARNING("RCLK timeout");
432                 /* the error is informative only as we don't want to break the firmware if there
433                  * is a false positive.
434                  */
435 //              return ERROR_FAIL;
436         }
437         return ERROR_OK;
438 }
439
440
441
442
443
444 static cyg_uint32 getShiftValue(void)
445 {
446         cyg_uint32 value;
447         waitIdle();
448         ZY1000_PEEK(ZY1000_JTAG_BASE + 0xc, value);
449         VERBOSE(LOG_INFO("getShiftValue %08x", value));
450         return value;
451 }
452 #if 0
453 static cyg_uint32 getShiftValueFlip(void)
454 {
455         cyg_uint32 value;
456         waitIdle();
457         ZY1000_PEEK(ZY1000_JTAG_BASE + 0x18, value);
458         VERBOSE(LOG_INFO("getShiftValue %08x (flipped)", value));
459         return value;
460 }
461 #endif
462
463 #if 0
464 static void shiftValueInnerFlip(const tap_state_t state, const tap_state_t endState, int repeat, cyg_uint32 value)
465 {
466         VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", tap_state_name(state), tap_state_name(endState), repeat, value));
467         cyg_uint32 a,b;
468         a = state;
469         b = endState;
470         ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value);
471         ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 15) | (repeat << 8) | (a << 4) | b);
472         VERBOSE(getShiftValueFlip());
473 }
474 #endif
475
476 static void gotoEndState(tap_state_t end_state)
477 {
478         setCurrentState(end_state);
479 }
480
481 static __inline void scanFields(int num_fields, const struct scan_field *fields, tap_state_t shiftState, int pause)
482 {
483         int i;
484         int j;
485         int k;
486
487         for (i = 0; i < num_fields; i++)
488         {
489                 cyg_uint32 value;
490
491                 uint8_t *inBuffer = NULL;
492
493
494                 // figure out where to store the input data
495                 int num_bits = fields[i].num_bits;
496                 if (fields[i].in_value != NULL)
497                 {
498                         inBuffer = fields[i].in_value;
499                 }
500
501                 // here we shuffle N bits out/in
502                 j = 0;
503                 while (j < num_bits)
504                 {
505                         tap_state_t pause_state;
506                         int l;
507                         k = num_bits-j;
508                         pause_state = (shiftState == TAP_DRSHIFT)?TAP_DRSHIFT:TAP_IRSHIFT;
509                         if (k > 32)
510                         {
511                                 k = 32;
512                                 /* we have more to shift out */
513                         } else if (pause&&(i == num_fields-1))
514                         {
515                                 /* this was the last to shift out this time */
516                                 pause_state = (shiftState==TAP_DRSHIFT)?TAP_DRPAUSE:TAP_IRPAUSE;
517                         }
518
519                         // we have (num_bits + 7)/8 bytes of bits to toggle out.
520                         // bits are pushed out LSB to MSB
521                         value = 0;
522                         if (fields[i].out_value != NULL)
523                         {
524                                 for (l = 0; l < k; l += 8)
525                                 {
526                                         value|=fields[i].out_value[(j + l)/8]<<l;
527                                 }
528                         }
529                         /* mask away unused bits for easier debugging */
530                         if (k < 32)
531                         {
532                                 value&=~(((uint32_t)0xffffffff) << k);
533                         } else
534                         {
535                                 /* Shifting by >= 32 is not defined by the C standard
536                                  * and will in fact shift by &0x1f bits on nios */
537                         }
538
539                         shiftValueInner(shiftState, pause_state, k, value);
540
541                         if (inBuffer != NULL)
542                         {
543                                 // data in, LSB to MSB
544                                 value = getShiftValue();
545                                 // we're shifting in data to MSB, shift data to be aligned for returning the value
546                                 value >>= 32-k;
547
548                                 for (l = 0; l < k; l += 8)
549                                 {
550                                         inBuffer[(j + l)/8]=(value >> l)&0xff;
551                                 }
552                         }
553                         j += k;
554                 }
555         }
556 }
557
558 int interface_jtag_add_ir_scan(int num_fields, const struct scan_field *fields, tap_state_t state)
559 {
560
561         int j;
562         int scan_size = 0;
563         struct jtag_tap *tap, *nextTap;
564         for (tap = jtag_tap_next_enabled(NULL); tap!= NULL; tap = nextTap)
565         {
566                 nextTap = jtag_tap_next_enabled(tap);
567                 int pause = (nextTap==NULL);
568
569                 int found = 0;
570
571                 scan_size = tap->ir_length;
572
573                 /* search the list */
574                 for (j = 0; j < num_fields; j++)
575                 {
576                         if (tap == fields[j].tap)
577                         {
578                                 found = 1;
579
580                                 scanFields(1, fields + j, TAP_IRSHIFT, pause);
581                                 /* update device information */
582                                 buf_cpy(fields[j].out_value, tap->cur_instr, scan_size);
583
584                                 tap->bypass = 0;
585                                 break;
586                         }
587                 }
588
589                 if (!found)
590                 {
591                         /* if a device isn't listed, set it to BYPASS */
592                         uint8_t ones[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
593
594                         struct scan_field tmp;
595                         memset(&tmp, 0, sizeof(tmp));
596                         tmp.out_value = ones;
597                         tmp.num_bits = scan_size;
598                         scanFields(1, &tmp, TAP_IRSHIFT, pause);
599                         /* update device information */
600                         buf_cpy(tmp.out_value, tap->cur_instr, scan_size);
601                         tap->bypass = 1;
602                 }
603         }
604         gotoEndState(state);
605
606         return ERROR_OK;
607 }
608
609
610
611
612
613 int interface_jtag_add_plain_ir_scan(int num_fields, const struct scan_field *fields, tap_state_t state)
614 {
615         scanFields(num_fields, fields, TAP_IRSHIFT, 1);
616         gotoEndState(state);
617
618         return ERROR_OK;
619 }
620
621 int interface_jtag_add_dr_scan(int num_fields, const struct scan_field *fields, tap_state_t state)
622 {
623
624         int j;
625         struct jtag_tap *tap, *nextTap;
626         for (tap = jtag_tap_next_enabled(NULL); tap!= NULL; tap = nextTap)
627         {
628                 nextTap = jtag_tap_next_enabled(tap);
629                 int found = 0;
630                 int pause = (nextTap==NULL);
631
632                 for (j = 0; j < num_fields; j++)
633                 {
634                         if (tap == fields[j].tap)
635                         {
636                                 found = 1;
637
638                                 scanFields(1, fields+j, TAP_DRSHIFT, pause);
639                         }
640                 }
641                 if (!found)
642                 {
643                         struct scan_field tmp;
644                         /* program the scan field to 1 bit length, and ignore it's value */
645                         tmp.num_bits = 1;
646                         tmp.out_value = NULL;
647                         tmp.in_value = NULL;
648
649                         scanFields(1, &tmp, TAP_DRSHIFT, pause);
650                 }
651                 else
652                 {
653                 }
654         }
655         gotoEndState(state);
656         return ERROR_OK;
657 }
658
659 int interface_jtag_add_plain_dr_scan(int num_fields, const struct scan_field *fields, tap_state_t state)
660 {
661         scanFields(num_fields, fields, TAP_DRSHIFT, 1);
662         gotoEndState(state);
663         return ERROR_OK;
664 }
665
666
667 int interface_jtag_add_tlr()
668 {
669         setCurrentState(TAP_RESET);
670         return ERROR_OK;
671 }
672
673
674
675
676 int interface_jtag_add_reset(int req_trst, int req_srst)
677 {
678         zy1000_reset(req_trst, req_srst);
679         return ERROR_OK;
680 }
681
682 static int zy1000_jtag_add_clocks(int num_cycles, tap_state_t state, tap_state_t clockstate)
683 {
684         /* num_cycles can be 0 */
685         setCurrentState(clockstate);
686
687         /* execute num_cycles, 32 at the time. */
688         int i;
689         for (i = 0; i < num_cycles; i += 32)
690         {
691                 int num;
692                 num = 32;
693                 if (num_cycles-i < num)
694                 {
695                         num = num_cycles-i;
696                 }
697                 shiftValueInner(clockstate, clockstate, num, 0);
698         }
699
700 #if !TEST_MANUAL()
701         /* finish in end_state */
702         setCurrentState(state);
703 #else
704         tap_state_t t = TAP_IDLE;
705         /* test manual drive code on any target */
706         int tms;
707         uint8_t tms_scan = tap_get_tms_path(t, state);
708         int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
709
710         for (i = 0; i < tms_count; i++)
711         {
712                 tms = (tms_scan >> i) & 1;
713                 waitIdle();
714                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x28,  tms);
715         }
716         waitIdle();
717         ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, state);
718 #endif
719
720
721         return ERROR_OK;
722 }
723
724 int interface_jtag_add_runtest(int num_cycles, tap_state_t state)
725 {
726         return zy1000_jtag_add_clocks(num_cycles, state, TAP_IDLE);
727 }
728
729 int interface_jtag_add_clocks(int num_cycles)
730 {
731         return zy1000_jtag_add_clocks(num_cycles, cmd_queue_cur_state, cmd_queue_cur_state);
732 }
733
734 int interface_jtag_add_sleep(uint32_t us)
735 {
736         jtag_sleep(us);
737         return ERROR_OK;
738 }
739
740 int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
741 {
742         int state_count;
743         int tms = 0;
744
745         /*wait for the fifo to be empty*/
746         waitIdle();
747
748         state_count = 0;
749
750         tap_state_t cur_state = cmd_queue_cur_state;
751
752         while (num_states)
753         {
754                 if (tap_state_transition(cur_state, false) == path[state_count])
755                 {
756                         tms = 0;
757                 }
758                 else if (tap_state_transition(cur_state, true) == path[state_count])
759                 {
760                         tms = 1;
761                 }
762                 else
763                 {
764                         LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(cur_state), tap_state_name(path[state_count]));
765                         exit(-1);
766                 }
767
768                 waitIdle();
769                 ZY1000_POKE(ZY1000_JTAG_BASE + 0x28,  tms);
770
771                 cur_state = path[state_count];
772                 state_count++;
773                 num_states--;
774         }
775
776         waitIdle();
777         ZY1000_POKE(ZY1000_JTAG_BASE + 0x20,  cur_state);
778         return ERROR_OK;
779 }
780
781
782
783 void embeddedice_write_dcc(struct jtag_tap *tap, int reg_addr, uint8_t *buffer, int little, int count)
784 {
785 //      static int const reg_addr = 0x5;
786         tap_state_t end_state = jtag_get_end_state();
787         if (jtag_tap_next_enabled(jtag_tap_next_enabled(NULL)) == NULL)
788         {
789                 /* better performance via code duplication */
790                 if (little)
791                 {
792                         int i;
793                         for (i = 0; i < count; i++)
794                         {
795                                 shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, 1));
796                                 shiftValueInner(TAP_DRSHIFT, end_state, 6, reg_addr | (1 << 5));
797                                 buffer += 4;
798                         }
799                 } else
800                 {
801                         int i;
802                         for (i = 0; i < count; i++)
803                         {
804                                 shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, 0));
805                                 shiftValueInner(TAP_DRSHIFT, end_state, 6, reg_addr | (1 << 5));
806                                 buffer += 4;
807                         }
808                 }
809         }
810         else
811         {
812                 int i;
813                 for (i = 0; i < count; i++)
814                 {
815                         embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little));
816                         buffer += 4;
817                 }
818         }
819 }
820
821