1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
87
88
89
90
91
92
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
120
121
122
123
124
125
126
127
128
129
130
133
137
138
139
140
141
142
143
144
145
146
147
148
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
187
188
189
190
191
192
193
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
267
282
283
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
308
309
310
311
312
313
314
315
316
317
318
319
325
326
327
328
329
330
331
332
333
334
335
336
337
342
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
459
464
465
466
467
468
469
470
471
472
473
474
475
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
620
621
622
623
626
627
628
629
635
636
637
638
639
640
641
642
643
648
649
650
653
660
665
666
667
668
669
670
673
674
675
676
677
678
679
680
681
682
683
684
685
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
732
733
734
735
736
741
742
743
744
745
746
747
748
749
750
751
752
753
758
759
762
763
764
765
766
767
768
769
770
771
772
776
777
778
779
780
783
787
790
793
796
799
802
805
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
850
851
855
856
859
860
861
862
863
864
865
866
867
868
869
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
903
904
910
911
917
918
919
920
921
922
923
924
925
926
932
933
937
938
939
940
941
942
947
948
952
953
954
955
956
957
958
959
977
978
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
/* ... */
/* ... */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if IS_CYGWIN == 1
#include "windows.h"
#undef LOG_ERROR/* ... */
#endif
#include <jtag/interface.h>
#include <jtag/commands.h>
#include <helper/time_support.h>
#include <helper/replacements.h>
#include "ublast_access.h"
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
10 includes
#define MAX_PACKET_SIZE 64
/* ... */
#define BUF_LEN 4096
#define CMD_COPY_TDO_BUFFER 0x5F
enum gpio_steer {
FIXED_0 = 0,
FIXED_1,
SRST,
TRST,
...};
struct ublast_info {
enum gpio_steer pin6;
enum gpio_steer pin8;
int tms;
int tdi;
bool trst_asserted;
bool srst_asserted;
uint8_t buf[BUF_LEN];
int bufidx;
char *lowlevel_name;
struct ublast_lowlevel *drv;
uint16_t ublast_vid, ublast_pid;
uint16_t ublast_vid_uninit, ublast_pid_uninit;
int flags;
char *firmware_path;
...};
/* ... */
static struct ublast_info info = {
.ublast_vid = 0x09fb,
.ublast_pid = 0x6001,
.lowlevel_name = NULL,
.srst_asserted = false,
.trst_asserted = false,
.pin6 = FIXED_1,
.pin8 = FIXED_1,
...};
/* ... */
struct drvs_map {
char *name;
struct ublast_lowlevel *(*drv_register)(void);
...};
static struct drvs_map lowlevel_drivers_map[] = {
#if BUILD_USB_BLASTER
{ .name = "ftdi", .drv_register = ublast_register_ftdi },
#endif
#if BUILD_USB_BLASTER_2
{ .name = "ublast2", .drv_register = ublast2_register_libusb },
#endif
{ NULL, NULL },
...};
/* ... */
static char *hexdump(uint8_t *buf, unsigned int size)
{
unsigned int i;
char *str = calloc(size * 2 + 1, 1);
for (i = 0; i < size; i++)
sprintf(str + 2*i, "%02x", buf[i]);
return str;
}{ ... }
static int ublast_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
{
int ret = info.drv->read(info.drv, buf, size, bytes_read);
char *str = hexdump(buf, *bytes_read);
LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %" PRIu32, size, str,
*bytes_read);
free(str);
return ret;
}{ ... }
static int ublast_buf_write(uint8_t *buf, int size, uint32_t *bytes_written)
{
int ret = info.drv->write(info.drv, buf, size, bytes_written);
char *str = hexdump(buf, *bytes_written);
LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %" PRIu32, size, str,
*bytes_written);
free(str);
return ret;
}{ ... }
static int nb_buf_remaining(void)
{
return BUF_LEN - info.bufidx;
}{ ... }
static void ublast_flush_buffer(void)
{
uint32_t retlen;
int nb = info.bufidx, ret = ERROR_OK;
while (ret == ERROR_OK && nb > 0) {
ret = ublast_buf_write(info.buf, nb, &retlen);
nb -= retlen;
}while (ret == ERROR_OK && nb > 0) { ... }
info.bufidx = 0;
}{ ... }
/* ... */
/* ... */
#define TCK (1 << 0)
#define TMS (1 << 1)
#define NCE (1 << 2)
#define NCS (1 << 3)
#define TDI (1 << 4)
#define LED (1 << 5)
#define READ (1 << 6)
#define SHMODE (1 << 7)
#define READ_TDO (1 << 0)
9 defines
/* ... */
static void ublast_queue_byte(uint8_t abyte)
{
if (nb_buf_remaining() < 1)
ublast_flush_buffer();
info.buf[info.bufidx++] = abyte;
if (nb_buf_remaining() == 0)
ublast_flush_buffer();
LOG_DEBUG_IO("(byte=0x%02x)", abyte);
}{ ... }
/* ... */
static bool ublast_compute_pin(enum gpio_steer steer)
{
switch (steer) {
case FIXED_0:
return 0;case FIXED_0:
case FIXED_1:
return 1;case FIXED_1:
case SRST:
return !info.srst_asserted;case SRST:
case TRST:
return !info.trst_asserted;case TRST:
default:
return 1;default
}switch (steer) { ... }
}{ ... }
/* ... */
static uint8_t ublast_build_out(enum scan_type type)
{
uint8_t abyte = 0;
abyte |= info.tms ? TMS : 0;
abyte |= ublast_compute_pin(info.pin6) ? NCE : 0;
abyte |= ublast_compute_pin(info.pin8) ? NCS : 0;
abyte |= info.tdi ? TDI : 0;
abyte |= LED;
if (type == SCAN_IN || type == SCAN_IO)
abyte |= READ;
return abyte;
}{ ... }
/* ... */
static void ublast_reset(int trst, int srst)
{
uint8_t out_value;
info.trst_asserted = trst;
info.srst_asserted = srst;
out_value = ublast_build_out(SCAN_OUT);
ublast_queue_byte(out_value);
ublast_flush_buffer();
}{ ... }
/* ... */
static void ublast_clock_tms(int tms)
{
uint8_t out;
LOG_DEBUG_IO("(tms=%d)", !!tms);
info.tms = !!tms;
info.tdi = 0;
out = ublast_build_out(SCAN_OUT);
ublast_queue_byte(out);
ublast_queue_byte(out | TCK);
}{ ... }
/* ... */
static void ublast_idle_clock(void)
{
uint8_t out = ublast_build_out(SCAN_OUT);
LOG_DEBUG_IO(".");
ublast_queue_byte(out);
}{ ... }
/* ... */
static void ublast_clock_tdi(int tdi, enum scan_type type)
{
uint8_t out;
LOG_DEBUG_IO("(tdi=%d)", !!tdi);
info.tdi = !!tdi;
out = ublast_build_out(SCAN_OUT);
ublast_queue_byte(out);
out = ublast_build_out(type);
ublast_queue_byte(out | TCK);
}{ ... }
/* ... */
static void ublast_clock_tdi_flip_tms(int tdi, enum scan_type type)
{
uint8_t out;
LOG_DEBUG_IO("(tdi=%d)", !!tdi);
info.tdi = !!tdi;
info.tms = !info.tms;
out = ublast_build_out(SCAN_OUT);
ublast_queue_byte(out);
out = ublast_build_out(type);
ublast_queue_byte(out | TCK);
out = ublast_build_out(SCAN_OUT);
ublast_queue_byte(out);
}{ ... }
/* ... */
static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes)
{
if (info.bufidx + nb_bytes > BUF_LEN) {
LOG_ERROR("buggy code, should never queue more that %d bytes",
info.bufidx + nb_bytes);
exit(-1);
}if (info.bufidx + nb_bytes > BUF_LEN) { ... }
LOG_DEBUG_IO("(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes,
bytes ? bytes[0] : 0);
if (bytes)
memcpy(&info.buf[info.bufidx], bytes, nb_bytes);
else
memset(&info.buf[info.bufidx], 0, nb_bytes);
info.bufidx += nb_bytes;
if (nb_buf_remaining() == 0)
ublast_flush_buffer();
}{ ... }
/* ... */
static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip)
{
int i;
LOG_DEBUG_IO("(bits=%02x..., nb_bits=%d)", bits[0], nb_bits);
for (i = skip; i < nb_bits; i++)
ublast_clock_tms((bits[i / 8] >> (i % 8)) & 0x01);
ublast_idle_clock();
}{ ... }
/* ... */
static void ublast_tms(struct tms_command *cmd)
{
LOG_DEBUG_IO("(num_bits=%d)", cmd->num_bits);
ublast_tms_seq(cmd->bits, cmd->num_bits, 0);
}{ ... }
/* ... */
static void ublast_path_move(struct pathmove_command *cmd)
{
LOG_DEBUG_IO("(num_states=%u, last_state=%d)",
cmd->num_states, cmd->path[cmd->num_states - 1]);
for (unsigned int i = 0; i < cmd->num_states; i++) {
if (tap_state_transition(tap_get_state(), false) == cmd->path[i])
ublast_clock_tms(0);
if (tap_state_transition(tap_get_state(), true) == cmd->path[i])
ublast_clock_tms(1);
tap_set_state(cmd->path[i]);
}for (unsigned int i = 0; i < cmd->num_states; i++) { ... }
ublast_idle_clock();
}{ ... }
/* ... */
static void ublast_state_move(tap_state_t state, int skip)
{
uint8_t tms_scan;
int tms_len;
LOG_DEBUG_IO("(from %s to %s)", tap_state_name(tap_get_state()),
tap_state_name(state));
if (tap_get_state() == state)
return;
tms_scan = tap_get_tms_path(tap_get_state(), state);
tms_len = tap_get_tms_path_len(tap_get_state(), state);
ublast_tms_seq(&tms_scan, tms_len, skip);
tap_set_state(state);
}{ ... }
/* ... */
static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes)
{
uint32_t retlen;
int ret = ERROR_OK;
LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8);
ublast_flush_buffer();
while (ret == ERROR_OK && nb_bytes > 0) {
ret = ublast_buf_read(buf, nb_bytes, &retlen);
nb_bytes -= retlen;
}while (ret == ERROR_OK && nb_bytes > 0) { ... }
return ret;
}{ ... }
/* ... */
static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits)
{
int nb1 = nb_bits;
int i, ret = ERROR_OK;
uint32_t retlen;
uint8_t tmp[8];
LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits);
/* ... */
ublast_flush_buffer();
ret = ublast_buf_read(tmp, nb1, &retlen);
for (i = 0; ret == ERROR_OK && i < nb1; i++)
if (tmp[i] & READ_TDO)
*buf |= (1 << i);
else
*buf &= ~(1 << i);
return ret;
}{ ... }
/* ... */
static void ublast_queue_tdi(uint8_t *bits, int nb_bits, enum scan_type scan)
{
int nb8 = nb_bits / 8;
int nb1 = nb_bits % 8;
int nbfree_in_packet, i, trans = 0, read_tdos;
uint8_t *tdos = calloc(1, nb_bits / 8 + 1);
static uint8_t byte0[BUF_LEN];
/* ... */
if (nb8 > 0 && nb1 == 0) {
nb8--;
nb1 = 8;
}if (nb8 > 0 && nb1 == 0) { ... }
read_tdos = (scan == SCAN_IN || scan == SCAN_IO);
for (i = 0; i < nb8; i += trans) {
/* ... */
nbfree_in_packet = (MAX_PACKET_SIZE - (info.bufidx%MAX_PACKET_SIZE));
trans = MIN(nbfree_in_packet - 1, nb8 - i);
/* ... */
if (read_tdos)
ublast_queue_byte(SHMODE | READ | trans);
else
ublast_queue_byte(SHMODE | trans);
if (bits)
ublast_queue_bytes(&bits[i], trans);
else
ublast_queue_bytes(byte0, trans);
if (read_tdos) {
if (info.flags & COPY_TDO_BUFFER)
ublast_queue_byte(CMD_COPY_TDO_BUFFER);
ublast_read_byteshifted_tdos(&tdos[i], trans);
}if (read_tdos) { ... }
}for (i = 0; i < nb8; i += trans) { ... }
/* ... */
for (i = 0; i < nb1; i++) {
int tdi = bits ? bits[nb8 + i / 8] & (1 << i) : 0;
if (bits && i == nb1 - 1)
ublast_clock_tdi_flip_tms(tdi, scan);
else
ublast_clock_tdi(tdi, scan);
}for (i = 0; i < nb1; i++) { ... }
if (nb1 && read_tdos) {
if (info.flags & COPY_TDO_BUFFER)
ublast_queue_byte(CMD_COPY_TDO_BUFFER);
ublast_read_bitbang_tdos(&tdos[nb8], nb1);
}if (nb1 && read_tdos) { ... }
if (bits)
memcpy(bits, tdos, DIV_ROUND_UP(nb_bits, 8));
free(tdos);
/* ... */
ublast_idle_clock();
}{ ... }
static void ublast_runtest(unsigned int num_cycles, tap_state_t state)
{
LOG_DEBUG_IO("%s(cycles=%u, end_state=%d)", __func__, num_cycles, state);
ublast_state_move(TAP_IDLE, 0);
ublast_queue_tdi(NULL, num_cycles, SCAN_OUT);
ublast_state_move(state, 0);
}{ ... }
static void ublast_stableclocks(unsigned int num_cycles)
{
LOG_DEBUG_IO("%s(cycles=%u)", __func__, num_cycles);
ublast_queue_tdi(NULL, num_cycles, SCAN_OUT);
}{ ... }
/* ... */
static int ublast_scan(struct scan_command *cmd)
{
int scan_bits;
uint8_t *buf = NULL;
enum scan_type type;
int ret = ERROR_OK;
static const char * const type2str[] = { "", "SCAN_IN", "SCAN_OUT", "SCAN_IO" };
char *log_buf = NULL;
type = jtag_scan_type(cmd);
scan_bits = jtag_build_buffer(cmd, &buf);
if (cmd->ir_scan)
ublast_state_move(TAP_IRSHIFT, 0);
else
ublast_state_move(TAP_DRSHIFT, 0);
log_buf = hexdump(buf, DIV_ROUND_UP(scan_bits, 8));
LOG_DEBUG_IO("%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__,
cmd->ir_scan ? "IRSCAN" : "DRSCAN",
type2str[type],
scan_bits, log_buf, cmd->end_state);
free(log_buf);
ublast_queue_tdi(buf, scan_bits, type);
ret = jtag_read_buffer(buf, cmd);
free(buf);
/* ... */
ublast_state_move(cmd->end_state, 1);
return ret;
}{ ... }
static void ublast_usleep(int us)
{
LOG_DEBUG_IO("%s(us=%d)", __func__, us);
jtag_sleep(us);
}{ ... }
static void ublast_initial_wipeout(void)
{
static uint8_t tms_reset = 0xff;
uint8_t out_value;
uint32_t retlen;
int i;
out_value = ublast_build_out(SCAN_OUT);
for (i = 0; i < BUF_LEN; i++)
info.buf[i] = out_value | ((i % 2) ? TCK : 0);
/* ... */
ublast_buf_write(info.buf, BUF_LEN, &retlen);
/* ... */
ublast_tms_seq(&tms_reset, 5, 0);
tap_set_state(TAP_RESET);
}{ ... }
static int ublast_execute_queue(struct jtag_command *cmd_queue)
{
struct jtag_command *cmd;
static int first_call = 1;
int ret = ERROR_OK;
if (first_call) {
first_call--;
ublast_initial_wipeout();
}if (first_call) { ... }
for (cmd = cmd_queue; ret == ERROR_OK && cmd;
cmd = cmd->next) {
switch (cmd->type) {
case JTAG_RESET:
ublast_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
break;case JTAG_RESET:
case JTAG_RUNTEST:
ublast_runtest(cmd->cmd.runtest->num_cycles,
cmd->cmd.runtest->end_state);
break;case JTAG_RUNTEST:
case JTAG_STABLECLOCKS:
ublast_stableclocks(cmd->cmd.stableclocks->num_cycles);
break;case JTAG_STABLECLOCKS:
case JTAG_TLR_RESET:
ublast_state_move(cmd->cmd.statemove->end_state, 0);
break;case JTAG_TLR_RESET:
case JTAG_PATHMOVE:
ublast_path_move(cmd->cmd.pathmove);
break;case JTAG_PATHMOVE:
case JTAG_TMS:
ublast_tms(cmd->cmd.tms);
break;case JTAG_TMS:
case JTAG_SLEEP:
ublast_usleep(cmd->cmd.sleep->us);
break;case JTAG_SLEEP:
case JTAG_SCAN:
ret = ublast_scan(cmd->cmd.scan);
break;case JTAG_SCAN:
default:
LOG_ERROR("BUG: unknown JTAG command type 0x%X",
cmd->type);
ret = ERROR_FAIL;
break;default
}switch (cmd->type) { ... }
}for (cmd = cmd_queue; ret == ERROR_OK && cmd; cmd = cmd->next) { ... }
ublast_flush_buffer();
return ret;
}{ ... }
/* ... */
static int ublast_init(void)
{
int ret, i;
for (i = 0; lowlevel_drivers_map[i].name; i++) {
if (info.lowlevel_name) {
if (!strcmp(lowlevel_drivers_map[i].name, info.lowlevel_name)) {
info.drv = lowlevel_drivers_map[i].drv_register();
if (!info.drv) {
LOG_ERROR("Error registering lowlevel driver \"%s\"",
info.lowlevel_name);
return ERROR_JTAG_DEVICE_ERROR;
}if (!info.drv) { ... }
break;
}if (!strcmp(lowlevel_drivers_map[i].name, info.lowlevel_name)) { ... }
}if (info.lowlevel_name) { ... } else {
info.drv = lowlevel_drivers_map[i].drv_register();
if (info.drv) {
info.lowlevel_name = strdup(lowlevel_drivers_map[i].name);
LOG_INFO("No lowlevel driver configured, using %s", info.lowlevel_name);
break;
}if (info.drv) { ... }
}else { ... }
}for (i = 0; lowlevel_drivers_map[i].name; i++) { ... }
if (!info.drv) {
LOG_ERROR("No lowlevel driver available");
return ERROR_JTAG_DEVICE_ERROR;
}if (!info.drv) { ... }
/* ... */
info.drv->ublast_vid = info.ublast_vid;
info.drv->ublast_pid = info.ublast_pid;
info.drv->ublast_vid_uninit = info.ublast_vid_uninit;
info.drv->ublast_pid_uninit = info.ublast_pid_uninit;
info.drv->firmware_path = info.firmware_path;
info.flags |= info.drv->flags;
ret = info.drv->open(info.drv);
/* ... */
tap_set_state(TAP_RESET);
return ret;
}{ ... }
/* ... */
static int ublast_quit(void)
{
uint8_t byte0 = 0;
uint32_t retlen;
ublast_buf_write(&byte0, 1, &retlen);
return info.drv->close(info.drv);
}{ ... }
COMMAND_HANDLER(ublast_handle_vid_pid_command)
{
if (CMD_ARGC > 4) {
LOG_WARNING("ignoring extra IDs in ublast_vid_pid "
"(maximum is 2 pairs)");
CMD_ARGC = 4;
}if (CMD_ARGC > 4) { ... }
if (CMD_ARGC >= 2) {
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], info.ublast_vid);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], info.ublast_pid);
}if (CMD_ARGC >= 2) { ... } else {
LOG_WARNING("incomplete ublast_vid_pid configuration");
}else { ... }
if (CMD_ARGC == 4) {
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[2], info.ublast_vid_uninit);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[3], info.ublast_pid_uninit);
}if (CMD_ARGC == 4) { ... } else {
LOG_WARNING("incomplete ublast_vid_pid configuration");
}else { ... }
return ERROR_OK;
}{ ... }
COMMAND_HANDLER(ublast_handle_pin_command)
{
uint8_t out_value;
const char * const pin_name = CMD_ARGV[0];
enum gpio_steer *steer = NULL;
static const char * const pin_val_str[] = {
[FIXED_0] = "0",
[FIXED_1] = "1",
[SRST] = "SRST driven",
[TRST] = "TRST driven",
...};
if (CMD_ARGC > 2) {
LOG_ERROR("%s takes exactly one or two arguments", CMD_NAME);
return ERROR_COMMAND_SYNTAX_ERROR;
}if (CMD_ARGC > 2) { ... }
if (!strcmp(pin_name, "pin6"))
steer = &info.pin6;
if (!strcmp(pin_name, "pin8"))
steer = &info.pin8;
if (!steer) {
LOG_ERROR("%s: pin name must be \"pin6\" or \"pin8\"",
CMD_NAME);
return ERROR_COMMAND_SYNTAX_ERROR;
}if (!steer) { ... }
if (CMD_ARGC == 1) {
LOG_INFO("%s: %s is set as %s\n", CMD_NAME, pin_name,
pin_val_str[*steer]);
}if (CMD_ARGC == 1) { ... }
if (CMD_ARGC == 2) {
const char * const pin_value = CMD_ARGV[1];
char val = pin_value[0];
if (strlen(pin_value) > 1)
val = '?';
switch (tolower((unsigned char)val)) {
case '0':
*steer = FIXED_0;
break;case '0':
case '1':
*steer = FIXED_1;
break;case '1':
case 't':
*steer = TRST;
break;case 't':
case 's':
*steer = SRST;
break;case 's':
default:
LOG_ERROR("%s: pin value must be 0, 1, s (SRST) or t (TRST)",
pin_value);
return ERROR_COMMAND_SYNTAX_ERROR;default
}switch (tolower((unsigned char)val)) { ... }
if (info.drv) {
out_value = ublast_build_out(SCAN_OUT);
ublast_queue_byte(out_value);
ublast_flush_buffer();
}if (info.drv) { ... }
}if (CMD_ARGC == 2) { ... }
return ERROR_OK;
}{ ... }
COMMAND_HANDLER(ublast_handle_lowlevel_drv_command)
{
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
info.lowlevel_name = strdup(CMD_ARGV[0]);
return ERROR_OK;
}{ ... }
COMMAND_HANDLER(ublast_firmware_command)
{
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
info.firmware_path = strdup(CMD_ARGV[0]);
return ERROR_OK;
}{ ... }
static const struct command_registration ublast_subcommand_handlers[] = {
{
.name = "vid_pid",
.handler = ublast_handle_vid_pid_command,
.mode = COMMAND_CONFIG,
.help = "the vendor ID and product ID of the USB-Blaster and "
"vendor ID and product ID of the uninitialized device "
"for USB-Blaster II",
.usage = "vid pid vid_uninit pid_uninit",
...},
{
.name = "lowlevel_driver",
.handler = ublast_handle_lowlevel_drv_command,
.mode = COMMAND_CONFIG,
.help = "set the lowlevel access for the USB Blaster (ftdi, ublast2)",
.usage = "(ftdi|ublast2)",
...},
{
.name = "pin",
.handler = ublast_handle_pin_command,
.mode = COMMAND_ANY,
.help = "show or set pin state for the unused GPIO pins",
.usage = "(pin6|pin8) (0|1|s|t)",
...},
{
.name = "firmware",
.handler = &ublast_firmware_command,
.mode = COMMAND_CONFIG,
.help = "configure the USB-Blaster II firmware location",
.usage = "path/to/blaster_xxxx.hex",
...},
COMMAND_REGISTRATION_DONE
...};
static const struct command_registration ublast_command_handlers[] = {
{
.name = "usb_blaster",
.mode = COMMAND_ANY,
.help = "perform usb_blaster management",
.chain = ublast_subcommand_handlers,
.usage = "",
...},
COMMAND_REGISTRATION_DONE
...};
static struct jtag_interface usb_blaster_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = ublast_execute_queue,
...};
struct adapter_driver usb_blaster_adapter_driver = {
.name = "usb_blaster",
.transports = jtag_only,
.commands = ublast_command_handlers,
.init = ublast_init,
.quit = ublast_quit,
.jtag_ops = &usb_blaster_interface,
...};