|
51 | 51 | #include "usb.h"
|
52 | 52 | #endif
|
53 | 53 |
|
| 54 | +typedef struct scan_command { |
| 55 | + bool (*scan)(void); |
| 56 | + const char *name; |
| 57 | +} scan_command_s; |
| 58 | + |
54 | 59 | static bool cmd_version(target_s *target, int argc, const char **argv);
|
55 | 60 | static bool cmd_help(target_s *target, int argc, const char **argv);
|
56 | 61 |
|
@@ -379,44 +384,44 @@ bool cmd_auto_scan(target_s *target, int argc, const char **argv)
|
379 | 384 | if (connect_assert_nrst)
|
380 | 385 | platform_nrst_set_val(true); /* will be deasserted after attach */
|
381 | 386 |
|
382 |
| - bool scan_result = false; |
383 |
| - TRY (EXCEPTION_ALL) { |
384 |
| -#if CONFIG_BMDA == 1 |
385 |
| - scan_result = bmda_jtag_scan(); |
386 |
| -#else |
387 |
| - scan_result = jtag_scan(); |
388 |
| -#endif |
389 |
| - if (!scan_result) { |
390 |
| - gdb_out("JTAG scan found no devices, trying SWD!\n"); |
391 |
| - |
| 387 | + static const scan_command_s scan_commands[] = |
392 | 388 | #if CONFIG_BMDA == 1
|
393 |
| - scan_result = bmda_swd_scan(); |
394 |
| -#else |
395 |
| - scan_result = adiv5_swd_scan(); |
396 |
| -#endif |
397 |
| - if (!scan_result) { |
398 |
| - gdb_out("SWD scan found no devices.\n"); |
| 389 | + /* clang-format off */ |
| 390 | + { |
| 391 | + {bmda_jtag_scan, "JTAG"}, |
| 392 | + {bmda_swd_scan, "SWD"}, |
399 | 393 | #if defined(CONFIG_RVSWD) && defined(PLATFORM_HAS_RVSWD)
|
400 |
| -#if CONFIG_BMDA == 1 |
401 |
| - scan_result = bmda_rvswd_scan(); |
402 |
| -#else |
403 |
| - scan_result = false; |
| 394 | + {bmda_rvswd_scan, "RVSWD"}, |
404 | 395 | #endif
|
405 |
| - if (!scan_result) |
406 |
| - gdb_out("RVSWD scan found no devices.\n"); |
| 396 | + }; |
| 397 | +#else |
| 398 | + { |
| 399 | + {jtag_scan, "JTAG"}, |
| 400 | + {adiv5_swd_scan, "SWD"}, |
| 401 | + }; |
| 402 | + /* clang-format on */ |
407 | 403 | #endif
|
408 |
| - } |
| 404 | + |
| 405 | + bool scan_result = false; |
| 406 | + for (size_t i = 0; i < ARRAY_LENGTH(scan_commands); i++) { |
| 407 | + TRY (EXCEPTION_ALL) { |
| 408 | + scan_result = scan_commands[i].scan(); |
409 | 409 | }
|
410 |
| - } |
411 |
| - CATCH () { |
412 |
| - case EXCEPTION_TIMEOUT: |
413 |
| - gdb_outf("Timeout during scan. Is target stuck in WFI?\n"); |
414 |
| - break; |
415 |
| - case EXCEPTION_ERROR: |
416 |
| - gdb_outf("Exception: %s\n", exception_frame.msg); |
417 |
| - break; |
418 |
| - default: |
419 |
| - break; |
| 410 | + CATCH () { |
| 411 | + case EXCEPTION_TIMEOUT: |
| 412 | + gdb_outf("Timeout during %s scan. Is target stuck in WFI?\n", scan_commands[i].name); |
| 413 | + break; |
| 414 | + case EXCEPTION_ERROR: |
| 415 | + gdb_outf("%s exception: %s\n", scan_commands[i].name, exception_frame.msg); |
| 416 | + break; |
| 417 | + default: |
| 418 | + break; |
| 419 | + } |
| 420 | + |
| 421 | + if (scan_result) |
| 422 | + break; |
| 423 | + |
| 424 | + gdb_outf("%s scan found no devices.\n", scan_commands[i].name); |
420 | 425 | }
|
421 | 426 |
|
422 | 427 | if (!scan_result) {
|
|
0 commit comments