You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

846 lines
18 KiB

  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. #include "log.h"
  23. #include "jtag.h"
  24. #include "bitbang.h"
  25. #include "../target/embeddedice.h"
  26. #include <cyg/hal/hal_io.h> // low level i/o
  27. #include <cyg/hal/hal_diag.h>
  28. #include <stdlib.h>
  29. #define ZYLIN_VERSION "1.48"
  30. #define ZYLIN_DATE __DATE__
  31. #define ZYLIN_TIME __TIME__
  32. #define ZYLIN_OPENOCD "$Revision: 1241 $"
  33. #define ZYLIN_OPENOCD_VERSION "Zylin JTAG ZY1000 " ZYLIN_VERSION " " ZYLIN_DATE " " ZYLIN_TIME
  34. const char *zylin_config_dir="/config/settings";
  35. extern int jtag_error;
  36. /* low level command set
  37. */
  38. int zy1000_read(void);
  39. static void zy1000_write(int tck, int tms, int tdi);
  40. void zy1000_reset(int trst, int srst);
  41. int zy1000_speed(int speed);
  42. int zy1000_register_commands(struct command_context_s *cmd_ctx);
  43. int zy1000_init(void);
  44. int zy1000_quit(void);
  45. /* interface commands */
  46. int zy1000_handle_zy1000_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  47. static int zy1000_khz(int khz, int *jtag_speed)
  48. {
  49. if (khz==0)
  50. {
  51. *jtag_speed=0;
  52. }
  53. else
  54. {
  55. *jtag_speed=64000/khz;
  56. }
  57. return ERROR_OK;
  58. }
  59. static int zy1000_speed_div(int speed, int *khz)
  60. {
  61. if (speed==0)
  62. {
  63. *khz = 0;
  64. }
  65. else
  66. {
  67. *khz=64000/speed;
  68. }
  69. return ERROR_OK;
  70. }
  71. static bool readPowerDropout()
  72. {
  73. cyg_uint32 state;
  74. // sample and clear power dropout
  75. HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x80);
  76. HAL_READ_UINT32(ZY1000_JTAG_BASE+0x10, state);
  77. bool powerDropout;
  78. powerDropout = (state & 0x80) != 0;
  79. return powerDropout;
  80. }
  81. static bool readSRST()
  82. {
  83. cyg_uint32 state;
  84. // sample and clear SRST sensing
  85. HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x00000040);
  86. HAL_READ_UINT32(ZY1000_JTAG_BASE+0x10, state);
  87. bool srstAsserted;
  88. srstAsserted = (state & 0x40) != 0;
  89. return srstAsserted;
  90. }
  91. static int zy1000_srst_asserted(int *srst_asserted)
  92. {
  93. *srst_asserted=readSRST();
  94. return ERROR_OK;
  95. }
  96. static int zy1000_power_dropout(int *dropout)
  97. {
  98. *dropout=readPowerDropout();
  99. return ERROR_OK;
  100. }
  101. jtag_interface_t zy1000_interface =
  102. {
  103. .name = "ZY1000",
  104. .execute_queue = bitbang_execute_queue,
  105. .speed = zy1000_speed,
  106. .register_commands = zy1000_register_commands,
  107. .init = zy1000_init,
  108. .quit = zy1000_quit,
  109. .khz = zy1000_khz,
  110. .speed_div = zy1000_speed_div,
  111. .power_dropout = zy1000_power_dropout,
  112. .srst_asserted = zy1000_srst_asserted,
  113. };
  114. bitbang_interface_t zy1000_bitbang =
  115. {
  116. .read = zy1000_read,
  117. .write = zy1000_write,
  118. .reset = zy1000_reset
  119. };
  120. static void zy1000_write(int tck, int tms, int tdi)
  121. {
  122. }
  123. int zy1000_read(void)
  124. {
  125. return -1;
  126. }
  127. extern bool readSRST();
  128. void zy1000_reset(int trst, int srst)
  129. {
  130. LOG_DEBUG("zy1000 trst=%d, srst=%d", trst, srst);
  131. if(!srst)
  132. {
  133. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x00000001);
  134. }
  135. else
  136. {
  137. /* Danger!!! if clk!=0 when in
  138. * idle in TAP_IDLE, reset halt on str912 will fail.
  139. */
  140. ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x00000001);
  141. }
  142. if(!trst)
  143. {
  144. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x00000002);
  145. }
  146. else
  147. {
  148. /* assert reset */
  149. ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x00000002);
  150. }
  151. if (trst||(srst&&(jtag_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. /* wait for srst to float back up */
  162. if (!srst)
  163. {
  164. int i;
  165. for (i=0; i<1000; i++)
  166. {
  167. // We don't want to sense our own reset, so we clear here.
  168. // There is of course a timing hole where we could loose
  169. // a "real" reset.
  170. if (!readSRST())
  171. break;
  172. /* wait 1ms */
  173. alive_sleep(1);
  174. }
  175. if (i==1000)
  176. {
  177. LOG_USER("SRST didn't deassert after %dms", i);
  178. } else if (i>1)
  179. {
  180. LOG_USER("SRST took %dms to deassert", i);
  181. }
  182. }
  183. }
  184. int zy1000_speed(int speed)
  185. {
  186. if(speed == 0)
  187. {
  188. /*0 means RCLK*/
  189. speed = 0;
  190. ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x100);
  191. LOG_DEBUG("jtag_speed using RCLK");
  192. }
  193. else
  194. {
  195. if(speed > 8190 || speed < 2)
  196. {
  197. LOG_USER("valid ZY1000 jtag_speed=[8190,2]. Divisor is 64MHz / even values between 8190-2, i.e. min 7814Hz, max 32MHz");
  198. return ERROR_INVALID_ARGUMENTS;
  199. }
  200. LOG_USER("jtag_speed %d => JTAG clk=%f", speed, 64.0/(float)speed);
  201. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x100);
  202. ZY1000_POKE(ZY1000_JTAG_BASE+0x1c, speed&~1);
  203. }
  204. return ERROR_OK;
  205. }
  206. static bool savePower;
  207. static void setPower(bool power)
  208. {
  209. savePower = power;
  210. if (power)
  211. {
  212. HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x14, 0x8);
  213. } else
  214. {
  215. HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x8);
  216. }
  217. }
  218. int handle_power_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  219. {
  220. if (argc > 1)
  221. {
  222. return ERROR_INVALID_ARGUMENTS;
  223. }
  224. if (argc == 1)
  225. {
  226. if (strcmp(args[0], "on") == 0)
  227. {
  228. setPower(1);
  229. }
  230. else if (strcmp(args[0], "off") == 0)
  231. {
  232. setPower(0);
  233. } else
  234. {
  235. command_print(cmd_ctx, "arg is \"on\" or \"off\"");
  236. return ERROR_INVALID_ARGUMENTS;
  237. }
  238. }
  239. command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off");
  240. return ERROR_OK;
  241. }
  242. /* Give TELNET a way to find out what version this is */
  243. int handle_zy1000_version_command(struct command_context_s *cmd_ctx, char *cmd,
  244. char **args, int argc)
  245. {
  246. if (argc > 1)
  247. {
  248. return ERROR_COMMAND_SYNTAX_ERROR;
  249. }
  250. if (argc == 0)
  251. {
  252. command_print(cmd_ctx, ZYLIN_OPENOCD_VERSION);
  253. }
  254. else if (strcmp("openocd", args[0]) == 0)
  255. {
  256. int revision;
  257. revision = atol(ZYLIN_OPENOCD+strlen("XRevision: "));
  258. command_print(cmd_ctx, "%d", revision);
  259. }
  260. else if (strcmp("zy1000", args[0]) == 0)
  261. {
  262. command_print(cmd_ctx, "%s", ZYLIN_VERSION);
  263. }
  264. else if (strcmp("date", args[0]) == 0)
  265. {
  266. command_print(cmd_ctx, "%s", ZYLIN_DATE);
  267. }
  268. else
  269. {
  270. return ERROR_COMMAND_SYNTAX_ERROR;
  271. }
  272. return ERROR_OK;
  273. }
  274. static int
  275. zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp,
  276. int argc,
  277. Jim_Obj * const *argv)
  278. {
  279. if (argc != 1)
  280. {
  281. Jim_WrongNumArgs(interp, 1, argv, "powerstatus");
  282. return JIM_ERR;
  283. }
  284. cyg_uint32 status;
  285. ZY1000_PEEK(ZY1000_JTAG_BASE+0x10, status);
  286. Jim_SetResult(interp, Jim_NewIntObj(interp, (status&0x80)!=0));
  287. return JIM_OK;
  288. }
  289. int zy1000_register_commands(struct command_context_s *cmd_ctx)
  290. {
  291. register_command(cmd_ctx, NULL, "power", handle_power_command, COMMAND_ANY,
  292. "power <on/off> - turn power switch to target on/off. No arguments - print status.");
  293. register_command(cmd_ctx, NULL, "zy1000_version", handle_zy1000_version_command,
  294. COMMAND_EXEC, "show zy1000 version numbers");
  295. Jim_CreateCommand(interp, "powerstatus", zylinjtag_Jim_Command_powerstatus, NULL, NULL);
  296. return ERROR_OK;
  297. }
  298. int zy1000_init(void)
  299. {
  300. LOG_ERROR("%s\n", ZYLIN_OPENOCD_VERSION);
  301. ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x30); // Turn on LED1 & LED2
  302. setPower(true); // on by default
  303. /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
  304. zy1000_reset(0, 0);
  305. zy1000_speed(jtag_speed);
  306. bitbang_interface = &zy1000_bitbang;
  307. return ERROR_OK;
  308. }
  309. int zy1000_quit(void)
  310. {
  311. return ERROR_OK;
  312. }
  313. int interface_jtag_execute_queue(void)
  314. {
  315. cyg_uint32 empty;
  316. waitIdle();
  317. ZY1000_PEEK(ZY1000_JTAG_BASE+0x10, empty);
  318. /* clear JTAG error register */
  319. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x400);
  320. if ((empty&0x400)!=0)
  321. {
  322. LOG_WARNING("RCLK timeout");
  323. /* the error is informative only as we don't want to break the firmware if there
  324. * is a false positive.
  325. */
  326. // return ERROR_FAIL;
  327. }
  328. return ERROR_OK;
  329. }
  330. static cyg_uint32 getShiftValue()
  331. {
  332. cyg_uint32 value;
  333. waitIdle();
  334. ZY1000_PEEK(ZY1000_JTAG_BASE+0xc, value);
  335. VERBOSE(LOG_INFO("getShiftValue %08x", value));
  336. return value;
  337. }
  338. #if 0
  339. static cyg_uint32 getShiftValueFlip()
  340. {
  341. cyg_uint32 value;
  342. waitIdle();
  343. ZY1000_PEEK(ZY1000_JTAG_BASE+0x18, value);
  344. VERBOSE(LOG_INFO("getShiftValue %08x (flipped)", value));
  345. return value;
  346. }
  347. #endif
  348. #if 0
  349. static void shiftValueInnerFlip(const enum tap_state state, const enum tap_state endState, int repeat, cyg_uint32 value)
  350. {
  351. VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", jtag_state_name(state), jtag_state_name(endState), repeat, value));
  352. cyg_uint32 a,b;
  353. a=state;
  354. b=endState;
  355. ZY1000_POKE(ZY1000_JTAG_BASE+0xc, value);
  356. ZY1000_POKE(ZY1000_JTAG_BASE+0x8, (1<<15)|(repeat<<8)|(a<<4)|b);
  357. VERBOSE(getShiftValueFlip());
  358. }
  359. #endif
  360. extern int jtag_check_value(u8 *captured, void *priv);
  361. static void gotoEndState()
  362. {
  363. setCurrentState(cmd_queue_end_state);
  364. }
  365. static __inline void scanFields(int num_fields, scan_field_t *fields, enum tap_state shiftState, int pause)
  366. {
  367. int i;
  368. int j;
  369. int k;
  370. for (i = 0; i < num_fields; i++)
  371. {
  372. cyg_uint32 value;
  373. static u8 *in_buff=NULL; /* pointer to buffer for scanned data */
  374. static int in_buff_size=0;
  375. u8 *inBuffer=NULL;
  376. // figure out where to store the input data
  377. int num_bits=fields[i].num_bits;
  378. if (fields[i].in_value!=NULL)
  379. {
  380. inBuffer=fields[i].in_value;
  381. } else if (fields[i].in_handler!=NULL)
  382. {
  383. if (in_buff_size*8<num_bits)
  384. {
  385. // we need more space
  386. if (in_buff!=NULL)
  387. free(in_buff);
  388. in_buff=NULL;
  389. in_buff_size=(num_bits+7)/8;
  390. in_buff=malloc(in_buff_size);
  391. if (in_buff==NULL)
  392. {
  393. LOG_ERROR("Out of memory");
  394. jtag_error=ERROR_JTAG_QUEUE_FAILED;
  395. return;
  396. }
  397. }
  398. inBuffer=in_buff;
  399. }
  400. // here we shuffle N bits out/in
  401. j=0;
  402. while (j<num_bits)
  403. {
  404. enum tap_state pause_state;
  405. int l;
  406. k=num_bits-j;
  407. pause_state=(shiftState==TAP_DRSHIFT)?TAP_DRSHIFT:TAP_IRSHIFT;
  408. if (k>32)
  409. {
  410. k=32;
  411. /* we have more to shift out */
  412. } else if (pause&&(i == num_fields-1))
  413. {
  414. /* this was the last to shift out this time */
  415. pause_state=(shiftState==TAP_DRSHIFT)?TAP_DRPAUSE:TAP_IRPAUSE;
  416. }
  417. // we have (num_bits+7)/8 bytes of bits to toggle out.
  418. // bits are pushed out LSB to MSB
  419. value=0;
  420. if (fields[i].out_value!=NULL)
  421. {
  422. for (l=0; l<k; l+=8)
  423. {
  424. value|=fields[i].out_value[(j+l)/8]<<l;
  425. }
  426. }
  427. /* mask away unused bits for easier debugging */
  428. value&=~(((u32)0xffffffff)<<k);
  429. shiftValueInner(shiftState, pause_state, k, value);
  430. if (inBuffer!=NULL)
  431. {
  432. // data in, LSB to MSB
  433. value=getShiftValue();
  434. // we're shifting in data to MSB, shift data to be aligned for returning the value
  435. value >>= 32-k;
  436. for (l=0; l<k; l+=8)
  437. {
  438. inBuffer[(j+l)/8]=(value>>l)&0xff;
  439. }
  440. }
  441. j+=k;
  442. }
  443. if (fields[i].in_handler!=NULL)
  444. {
  445. // invoke callback
  446. int r=fields[i].in_handler(inBuffer, fields[i].in_handler_priv, fields+i);
  447. if (r!=ERROR_OK)
  448. {
  449. /* this will cause jtag_execute_queue() to return an error */
  450. jtag_error=r;
  451. }
  452. }
  453. }
  454. }
  455. int interface_jtag_add_end_state(enum tap_state state)
  456. {
  457. return ERROR_OK;
  458. }
  459. int interface_jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
  460. {
  461. int j;
  462. int scan_size = 0;
  463. jtag_tap_t *tap, *nextTap;
  464. for(tap = jtag_NextEnabledTap(NULL); tap!= NULL; tap=nextTap)
  465. {
  466. nextTap=jtag_NextEnabledTap(tap);
  467. int pause=(nextTap==NULL);
  468. int found = 0;
  469. scan_size = tap->ir_length;
  470. /* search the list */
  471. for (j=0; j < num_fields; j++)
  472. {
  473. if (tap == fields[j].tap)
  474. {
  475. found = 1;
  476. if ((jtag_verify_capture_ir)&&(fields[j].in_handler==NULL))
  477. {
  478. jtag_set_check_value(fields+j, tap->expected, tap->expected_mask, NULL);
  479. } else if (jtag_verify_capture_ir)
  480. {
  481. fields[j].in_check_value = tap->expected;
  482. fields[j].in_check_mask = tap->expected_mask;
  483. }
  484. scanFields(1, fields+j, TAP_IRSHIFT, pause);
  485. /* update device information */
  486. buf_cpy(fields[j].out_value, tap->cur_instr, scan_size);
  487. tap->bypass = 0;
  488. break;
  489. }
  490. }
  491. if (!found)
  492. {
  493. /* if a device isn't listed, set it to BYPASS */
  494. u8 ones[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  495. scan_field_t tmp;
  496. memset(&tmp, 0, sizeof(tmp));
  497. tmp.out_value = ones;
  498. tmp.num_bits = scan_size;
  499. scanFields(1, &tmp, TAP_IRSHIFT, pause);
  500. /* update device information */
  501. buf_cpy(tmp.out_value, tap->cur_instr, scan_size);
  502. tap->bypass = 1;
  503. }
  504. }
  505. gotoEndState();
  506. return ERROR_OK;
  507. }
  508. int interface_jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
  509. {
  510. scanFields(num_fields, fields, TAP_IRSHIFT, 1);
  511. gotoEndState();
  512. return ERROR_OK;
  513. }
  514. /*extern jtag_command_t **jtag_get_last_command_p(void);*/
  515. int interface_jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
  516. {
  517. int j;
  518. jtag_tap_t *tap, *nextTap;
  519. for(tap = jtag_NextEnabledTap(NULL); tap!= NULL; tap=nextTap)
  520. {
  521. nextTap=jtag_NextEnabledTap(tap);
  522. int found=0;
  523. int pause=(nextTap==NULL);
  524. for (j=0; j < num_fields; j++)
  525. {
  526. if (tap == fields[j].tap)
  527. {
  528. found = 1;
  529. scanFields(1, fields+j, TAP_DRSHIFT, pause);
  530. }
  531. }
  532. if (!found)
  533. {
  534. scan_field_t tmp;
  535. /* program the scan field to 1 bit length, and ignore it's value */
  536. tmp.num_bits = 1;
  537. tmp.out_value = NULL;
  538. tmp.out_mask = NULL;
  539. tmp.in_value = NULL;
  540. tmp.in_check_value = NULL;
  541. tmp.in_check_mask = NULL;
  542. tmp.in_handler = NULL;
  543. tmp.in_handler_priv = NULL;
  544. scanFields(1, &tmp, TAP_DRSHIFT, pause);
  545. }
  546. else
  547. {
  548. }
  549. }
  550. gotoEndState();
  551. return ERROR_OK;
  552. }
  553. int interface_jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
  554. {
  555. scanFields(num_fields, fields, TAP_DRSHIFT, 1);
  556. gotoEndState();
  557. return ERROR_OK;
  558. }
  559. int interface_jtag_add_tlr()
  560. {
  561. setCurrentState(TAP_RESET);
  562. return ERROR_OK;
  563. }
  564. extern int jtag_nsrst_delay;
  565. extern int jtag_ntrst_delay;
  566. int interface_jtag_add_reset(int req_trst, int req_srst)
  567. {
  568. zy1000_reset(req_trst, req_srst);
  569. return ERROR_OK;
  570. }
  571. int interface_jtag_add_runtest(int num_cycles, enum tap_state state)
  572. {
  573. /* num_cycles can be 0 */
  574. setCurrentState(TAP_IDLE);
  575. /* execute num_cycles, 32 at the time. */
  576. int i;
  577. for (i=0; i<num_cycles; i+=32)
  578. {
  579. int num;
  580. num=32;
  581. if (num_cycles-i<num)
  582. {
  583. num=num_cycles-i;
  584. }
  585. shiftValueInner(TAP_IDLE, TAP_IDLE, num, 0);
  586. }
  587. #if !TEST_MANUAL()
  588. /* finish in end_state */
  589. setCurrentState(state);
  590. #else
  591. enum tap_state t=TAP_IDLE;
  592. /* test manual drive code on any target */
  593. int tms;
  594. u8 tms_scan = TAP_MOVE(t, state);
  595. for (i = 0; i < 7; i++)
  596. {
  597. tms = (tms_scan >> i) & 1;
  598. waitIdle();
  599. ZY1000_POKE(ZY1000_JTAG_BASE+0x28, tms);
  600. }
  601. waitIdle();
  602. ZY1000_POKE(ZY1000_JTAG_BASE+0x20, state);
  603. #endif
  604. return ERROR_OK;
  605. }
  606. int interface_jtag_add_sleep(u32 us)
  607. {
  608. jtag_sleep(us);
  609. return ERROR_OK;
  610. }
  611. int interface_jtag_add_pathmove(int num_states, enum tap_state *path)
  612. {
  613. int state_count;
  614. int tms = 0;
  615. /*wait for the fifo to be empty*/
  616. waitIdle();
  617. state_count = 0;
  618. enum tap_state cur_state=cmd_queue_cur_state;
  619. while (num_states)
  620. {
  621. if (tap_transitions[cur_state].low == path[state_count])
  622. {
  623. tms = 0;
  624. }
  625. else if (tap_transitions[cur_state].high == path[state_count])
  626. {
  627. tms = 1;
  628. }
  629. else
  630. {
  631. LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", jtag_state_name(cur_state), jtag_state_name(path[state_count]));
  632. exit(-1);
  633. }
  634. waitIdle();
  635. ZY1000_POKE(ZY1000_JTAG_BASE+0x28, tms);
  636. cur_state = path[state_count];
  637. state_count++;
  638. num_states--;
  639. }
  640. waitIdle();
  641. ZY1000_POKE(ZY1000_JTAG_BASE+0x20, cur_state);
  642. return ERROR_OK;
  643. }
  644. void embeddedice_write_dcc(jtag_tap_t *tap, int reg_addr, u8 *buffer, int little, int count)
  645. {
  646. // static int const reg_addr=0x5;
  647. enum tap_state end_state=cmd_queue_end_state;
  648. if (jtag_NextEnabledTap(jtag_NextEnabledTap(NULL))==NULL)
  649. {
  650. /* better performance via code duplication */
  651. if (little)
  652. {
  653. int i;
  654. for (i = 0; i < count; i++)
  655. {
  656. shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, 1));
  657. shiftValueInner(TAP_DRSHIFT, end_state, 6, reg_addr|(1<<5));
  658. buffer+=4;
  659. }
  660. } else
  661. {
  662. int i;
  663. for (i = 0; i < count; i++)
  664. {
  665. shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, 0));
  666. shiftValueInner(TAP_DRSHIFT, end_state, 6, reg_addr|(1<<5));
  667. buffer+=4;
  668. }
  669. }
  670. }
  671. else
  672. {
  673. int i;
  674. for (i = 0; i < count; i++)
  675. {
  676. embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little));
  677. buffer += 4;
  678. }
  679. }
  680. }
  681. int loadFile(const char *fileName, void **data, int *len);
  682. /* boolean parameter stored on config */
  683. int boolParam(char *var)
  684. {
  685. bool result = false;
  686. char *name = alloc_printf("%s/%s", zylin_config_dir, var);
  687. if (name == NULL)
  688. return result;
  689. void *data;
  690. int len;
  691. if (loadFile(name, &data, &len) == ERROR_OK)
  692. {
  693. if (len > 1)
  694. len = 1;
  695. result = strncmp((char *) data, "1", len) == 0;
  696. free(data);
  697. }
  698. free(name);
  699. return result;
  700. }