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.
 
 
 
 
 
 

879 lines
19 KiB

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