added ftdi on linux

This commit is contained in:
François Dausseur
2025-02-12 12:37:38 +01:00
parent b6775ae680
commit a8e7599b96
13 changed files with 315 additions and 92 deletions

View File

@@ -1,8 +1,10 @@
file(GLOB_RECURSE ALL_SOURCES "src/*.c")
# Application configuration
add_executable(
bs
main.c
${ALL_SOURCES}
)
# linking configuration

View File

@@ -1,21 +0,0 @@
#include <stdio.h>
#include "jtag_core.h"
void jtcprint(jtag_core *jc, const char *msg) {
printf(msg);
}
int main(int argc, char **argv) {
jtag_core *jc;
jc = jtagcore_init();
if (jtagcore_set_logs_callback(jc, jtcprint) < 0) goto end;
end:
jtagcore_deinit(jc);
printf("Finished.");
return 0;
}

65
app/src/args.c Normal file
View File

@@ -0,0 +1,65 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include "args.h"
char * COMMAND_STRINGS[COMMANDS_NUMBER-1] = {
"scan"
};
void usage() {
printf("Usage: bs [[-l] [--list]] [[-n] [--nprobe] PROBE_NUM] [scan]\n");
}
int parse_args(struct args *a, int argc, char *argv[]) {
int opt = 0;
int i = 0;
int command = 0;
__uint8_t option_arg[32] = {0};
// Définir les options longues
static struct option long_options[] = {
{"list", no_argument, 0, 'l'},
{"nprobe", required_argument, 0, 'n'},
{0, 0, 0, 0}
};
// Utilisation de getopt_long pour parser les options
while ((opt = getopt_long(argc, argv, "ln:", long_options, NULL)) != -1) {
switch (opt) {
case 'l':
a->list = 1;
break;
case 'n':
snprintf(option_arg, sizeof(option_arg)-2, "%s");
a->probe = atoi(option_arg);
break;
default:
usage();
return EXIT_FAILURE;
}
}
// Positional arguments
if (optind < argc) {
/* Positional arguments */
while (optind < argc) {
for (i=0;i<COMMANDS_NUMBER-1;i++) {
if (0 == strcmp(COMMAND_STRINGS[i], argv[optind])) {
a->cmds[command] = (enum commands)i+1;
}
}
optind++;
}
}
// Si aucune option n'est fournie, afficher l'aide
if (optind == 1) {
usage();
}
return EXIT_SUCCESS;
}

20
app/src/args.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef _ARGS_H
#define _ARGS_H
#define MAX_COMMANDS 16
enum commands {
NO_COMMAND=0,
COMMAND_SCAN,
COMMANDS_NUMBER, /* The number of enums +1*/
};
struct args {
int list;
int probe;
enum commands cmds[MAX_COMMANDS];
};
int parse_args(struct args *a, int argc, char *argv[]);
#endif

108
app/src/main.c Normal file
View File

@@ -0,0 +1,108 @@
#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;
}