Files
bs_explorer/app/src/main.c
François Dausseur a8e7599b96 added ftdi on linux
2025-02-12 12:37:38 +01:00

108 lines
2.4 KiB
C

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "jtag_core.h"
#include "args.h"
#define PROBES_MAX_NUM 16
#define PROBE_NAME_SIZE 64
struct probe {
int drv;
int probe;
int probe_id;
char name[PROBE_NAME_SIZE];
};
void jprint(jtag_core *jc, const char *msg) {
printf(msg);
}
int list_probes(jtag_core *jc, struct probe probes[], int show) {
int i = 0;
int j = 0;
int n = 0;
char probe_name[PROBE_NAME_SIZE] = {0};
int n_probe_drv = 0;
int n_probes = 0;
/* Drivers and probes */
n_probe_drv = jtagcore_get_number_of_probes_drv(jc);
if (n_probe_drv > 0) {
if (0 != show) printf("Found a debug probe driver:\n");
} else {
if (0 != show) printf("No probes driver found\n");
return n;
}
for (i=0;i<n_probe_drv;i++) {
if (0 != show) printf(" JTAG probe driver %d\n", i);
n_probes = jtagcore_get_number_of_probes(jc, i);
if (n_probes > 0) {
if (0 != show) printf("Found a debug probe:\n");
} else {
if (0 != show) printf("No probe found.\n");
continue;
}
for (j=0;j<n_probes;j++) {
jtagcore_get_probe_name(jc, PROBE_ID(i,j), probe_name);
if (n < PROBES_MAX_NUM) {
probes[n].drv = i;
probes[n].probe = j;
probes[n].probe_id = PROBE_ID(i,j);
strncpy(probes[n].name, probe_name, PROBE_NAME_SIZE);
}
n++;
if (0 != show) {
printf(" JTAG probe %d: ", n+1);
printf("%s.\n", probe_name);
}
}
}
return n;
}
int main(int argc, char *argv[]) {
int success;
int n_probes;
jtag_core *jc = NULL;
struct args a = {0};
struct probe probes[PROBES_MAX_NUM] = {0};
success = parse_args(&a, argc, argv);
if (EXIT_FAILURE == success) exit(EXIT_FAILURE);
/* initialize the JTAG library */
jc = jtagcore_init();
/* Log printing callback */
if (jtagcore_set_logs_callback(jc, jprint) < 0) goto err;
jtagcore_set_logs_level(jc, MSG_DEBUG);
/* List the probes (and display if asked) */
n_probes = list_probes(jc, probes, a.list);
goto end;
err:
printf("Error while executing a command.\n");
end:
jtagcore_deinit(jc);
printf("Finished.");
return 0;
}