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