compiles and works

This commit is contained in:
François Dausseur
2025-02-18 11:36:18 +01:00
parent b66e82da87
commit 5dfe5b123e
17 changed files with 7087 additions and 2021 deletions

4
.vscode/launch.json vendored
View File

@@ -5,13 +5,13 @@
"version": "0.2.0",
"configurations": [
{
"name": "bs list",
"name": "bs",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/bs/bs",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",

View File

@@ -1,7 +1,7 @@
{
"files.associations": {
"*.cpt": "yaml",
"*.seq": "yaml",
"*.cpt": "yaml",
"os_interface.h": "c",
"bsdl_strings.h": "c",
"script.h": "c",
@@ -13,7 +13,9 @@
"dlfcn.h": "c",
"config_script.h": "c",
"bs_defines.h": "c",
"jtag_core.h": "c"
"jtag_core.h": "c",
"string.h": "c",
"readline.h": "c"
},
"C_Cpp.default.includePath": [
"libs/",

View File

@@ -4,11 +4,13 @@ project(BoundaryScanExplorer)
# script and jtag_core must be the last linked archive for the application to compile
set(BS_MODULES script jtag_core)
set(DIR_MODULES ${CMAKE_SOURCE_DIR}/modules)
set(DIR_LIBS ${CMAKE_SOURCE_DIR}/libs)
# We dive into submodules
file(GLOB MODULES_DIRS RELATIVE ${CMAKE_SOURCE_DIR}/modules ${CMAKE_SOURCE_DIR}/modules/*)
file(GLOB MODULES_DIRS RELATIVE ${DIR_MODULES} ${DIR_MODULES}/*)
foreach(module ${MODULES_DIRS})
set(module_path "${CMAKE_SOURCE_DIR}/modules/${module}")
set(module_path "${DIR_MODULES}/${module}")
# checks if it is a sub-directory and if it contains a cmake file
if(IS_DIRECTORY ${module_path} AND EXISTS "${module_path}/CMakeLists.txt")

View File

@@ -74,18 +74,18 @@
// return EXIT_SUCCESS;
// }
void parse_command(char *line, int *argc, char **argv) {
*argc = 0;
while (*line != '\0') {
while (*line == ' ' || *line == '\t' || *line == '\n') {
*line++ = '\0';
}
if (*argc >= MAX_ARGS) break;
(*argc)++;
*argv++ = line;
while (*line != '\0' && *line != ' ' && *line != '\t' && *line != '\n') {
line++;
}
}
*argv = '\0';
}
// void parse_command(char *line, int *argc, char **argv) {
// *argc = 0;
// while (*line != '\0') {
// while (*line == ' ' || *line == '\t' || *line == '\n') {
// *line++ = '\0';
// }
// if (*argc >= MAX_ARGS) break;
// (*argc)++;
// *argv++ = line;
// while (*line != '\0' && *line != ' ' && *line != '\t' && *line != '\n') {
// line++;
// }
// }
// *argv = '\0';
// }

View File

@@ -2,6 +2,6 @@
#define _ARGS_H
// int parse_args(struct args *a, int argc, char *argv[]);
void parse_command(char *line, int *argc, char **argv);
// void parse_command(char *line, int *argc, char **argv);
#endif

104
bs/init.c
View File

@@ -19,6 +19,10 @@ Command commands[] = {
{NULL, NULL}};
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "jtag_core/jtag_core.h"
#include "config/version.h"
#include "script/env.h"
@@ -31,55 +35,99 @@ void jprint(jtag_core *jc, const char *msg)
printf(msg);
}
jtag_core *bsexp_init(void)
int script_print(script_ctx *sctx, enum MSGTYPE typ, char *string, ...)
{
jtag_core *jc = NULL;
script_ctx *sctx;
int ret = 0;
char msg[64] = {0};
va_list args;
/* initialize the JTAG library */
jc = jtagcore_init();
switch (typ)
{
case MSG_DEBUG:
strcpy(msg, "DEBUG :");
break;
case MSG_INFO_1:
strcpy(msg, "INFO :");
break;
case MSG_WARNING:
strcpy(msg, "WARNING :");
break;
case MSG_ERROR:
strcpy(msg, "ERROR :");
break;
case MSG_INFO_0:
default:
strcpy(msg, "");
break;
}
if (NULL == jc)
va_start(args, string);
ret = printf(msg);
ret += vprintf(string, args);
va_end(args);
return ret;
}
void bsexp_init(jtag_core **jc, script_ctx **sctx)
{
// JTAG core initialization
*jc = jtagcore_init();
if (NULL == *jc)
goto end;
jc->envvar = (void *)initEnv(NULL, NULL);
// Environment initialization
(*jc)->envvar = (void *)initEnv(NULL, NULL);
if (NULL == (*jc)->envvar) {
jtagcore_deinit(*jc);
*jc = NULL;
goto end;
}
jtagcore_setEnvVar(*jc, "VERSION", "v" APP_VER_STR(APP_VER));
jtagcore_setEnvVar(jc, "VERSION", "v" LIB_JTAG_CORE_VERSION);
sctx = jtagcore_initScript(jc);
execute_ram_script(sctx, config_script, config_script_len);
execute_file_script(sctx, "config.script");
// Scripts initialization
*sctx = jtagcore_initScript(*jc);
if (NULL == *sctx) {
deinitEnv((*jc)->envvar);
jtagcore_deinit(*jc);
*jc = NULL;
goto end;
}
setOutputFunc_script(*sctx, script_print);
execute_ram_script(*sctx, config_script, config_script_len);
execute_file_script(*sctx, "config.script");
/* Log printing callback */
if (jtagcore_set_logs_callback(jc, jprint) < 0)
if (jtagcore_set_logs_callback(*jc, jprint) < 0)
{
printf("Impossible to define the logs callback!\n");
}
else
{
if (jtagcore_getEnvVar(jc, "LOG_MESSAGES_FILTER_LEVEL", NULL))
if (jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILTER_LEVEL", NULL))
{
jtagcore_set_logs_level(jc, jtagcore_getEnvVarValue(jc, "LOG_MESSAGES_FILTER_LEVEL"));
jtagcore_set_logs_level(*jc, jtagcore_getEnvVarValue(*jc, "LOG_MESSAGES_FILTER_LEVEL"));
}
if (jtagcore_getEnvVar(jc, "LOG_MESSAGES_FILE_OUTPUT", NULL))
if (jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILE_OUTPUT", NULL))
{
jtagcore_set_logs_file(jc, jtagcore_getEnvVar(jc, "LOG_MESSAGES_FILE_OUTPUT", NULL));
jtagcore_set_logs_file(*jc, jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILE_OUTPUT", NULL));
}
}
deinit_script(sctx);
end:
return jc;
return;
}
void bsexp_deinit(jtag_core *jc)
void bsexp_deinit(jtag_core *jc, script_ctx *sctx)
{
if (NULL == jc) return;
envvar_entry *env = NULL;
envvar_entry *env = jc->envvar;
deinitEnv(env);
jtagcore_deinit(jc);
if (NULL != jc)
{
deinit_script(sctx);
}
if (NULL != jc)
{
env = jc->envvar;
deinitEnv(env);
jtagcore_deinit(jc);
}
}

View File

@@ -12,7 +12,8 @@ typedef struct {
extern Command commands[];
jtag_core *bsexp_init(void);
void bsexp_deinit(jtag_core *jc);
int script_print(script_ctx *sctx, enum MSGTYPE typ, char *string, ...);
void bsexp_init(jtag_core **jc, script_ctx **sctx);
void bsexp_deinit(jtag_core *jc, script_ctx *sctx);
#endif

View File

@@ -2,6 +2,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <readline/readline.h>
#include <readline/history.h>
@@ -9,6 +10,7 @@
#include "utils.h"
#include "init.h"
#include "args.h"
#include "script/script.h"
// int main(int argc, char *argv[]) {
// int success = 0;
@@ -58,63 +60,70 @@
// return error;
// }
jtag_core *jc = NULL;
script_ctx *sctx = NULL;
// int execute_command(jtag_core *jc, int argc, char **argv) {
// int error = 0;
// if (argv[0] == NULL) {
// return 0;
// }
// Fonction de gestion du signal
void handle_sigint(int sig) {
bsexp_deinit(jc, sctx);
exit(0);
}
// for (int i = 0; commands[i].name != NULL; i++) {
// if (strcmp(argv[0], commands[i].name) == 0) {
// error = commands[i].cmd_call(jc, argc, argv);
// return error;
// }
// }
// error = -1;
// printf("Command not found\n");
// }
int execute_command(script_ctx *sctx, char *line)
{
int error = 0;
error = execute_line_script(sctx, line);
return error;
}
int main() {
int main()
{
char *line = NULL;
int error = 0;
int cmd_argc=0;
char *cmd_argv[MAX_ARGS] = {0};
jtag_core *jc = NULL;
int cmd_argc = 0;
jc = bsexp_init();
if (NULL == jc) {
bsexp_init(&jc, &sctx);
script_print(sctx, MSG_NONE, "\n");
if ((NULL == jc) || (NULL == sctx))
{
error = JTAG_CORE_MEM_ERROR;
printf("JTAG Core execution failed");
goto err;
printf("JTAG Core initialization failed!\n");
goto err_no_deinit;
}
while (1) {
signal(SIGINT, handle_sigint);
while (1)
{
line = readline("bs_explorer> ");
if (line == NULL) {
if (line == NULL)
{
break;
}
if (*line) {
if (*line)
{
add_history(line);
}
parse_command(line, &cmd_argc, cmd_argv);
if (cmd_argv[0] == NULL) {
continue;
}
if (strcmp(cmd_argv[0], "exit") == 0) {
if (strcmp(line, "exit") == 0) {
break;
}
// error = execute_command(jc, cmd_argc, cmd_argv);
// printf("\n");
// if (0 == error) {
// } else {
// printf("Command failed with code: %d", error);
// }
if (strcmp(line, "quit") == 0) {
break;
}
error = execute_command(sctx, line);
if (0 == error)
{
}
else
{
printf("Command failed with code: %d\n", error);
}
}
return 0;
err_no_deinit:
exit(error);
err:
return error;
printf("Failed with error (%d)", error);
end:
bsexp_deinit(jc);
bsexp_deinit(jc, sctx);
exit(error);
}

File diff suppressed because it is too large Load Diff

View File

@@ -62,7 +62,7 @@ typedef struct _script_label
typedef struct _script_ctx script_ctx;
typedef int (*SCRIPT_PRINTF_FUNC)(script_ctx * ctx, int MSGTYPE, char *string, ...);
typedef int (*SCRIPT_PRINTF_FUNC)(script_ctx * ctx, enum MSGTYPE typ, char *string, ...);
typedef struct _script_ctx
{

View File

@@ -1,21 +1,20 @@
#ifndef _VERSION_H
#define _VERSION_H
#define VDIG1 2
#define VDIG2 6
#define VDIG3 7
#define VDIG4 1
#define VDIG1 2
#define VDIG2 6
#define VDIG3 7
#define VDIG4 1
#define STR_DATE "28 Oct 2024"
#define STR_DATE "28 Oct 2024"
#define vxstr(s) vstr(s)
#define vstr(s) #s
#define vxstr(s) vstr(s)
#define vstr(s) #s
#define LIB_JTAG_CORE_VERSION vxstr(VDIG1) "." vxstr(VDIG2) "." vxstr(VDIG3) "." vxstr(VDIG4)
#define LIB_JTAG_CORE_VERSION_COMMA vxstr(VDIG1) "," vxstr(VDIG2) "," vxstr(VDIG3) "," vxstr(VDIG4)
#define APP_VER VDIG1.VDIG2.VDIG3.VDIG4
#define APP_VER_TXT( N ) JTAG Boundary Scanner v##N
#define APP_VER_STR( N ) vxstr( APP_VER_TXT( N ) )
#define APP_VER VDIG1.VDIG2.VDIG3.VDIG4
#define APP_VER_TXT_LONG( N ) JTAG Boundary Scanner v##N
#define APP_VER_TXT( N ) v##N
#define APP_VER_STR_LONG( N ) vxstr( APP_VER_TXT_LONG( N ) )
#define APP_VER_STR( N ) vxstr( APP_VER_TXT( N ) )
#endif

View File

@@ -5,6 +5,10 @@ file(GLOB_RECURSE JLINK_SOURCES "jlink_jtag/*.c")
file(GLOB_RECURSE FTDI_SOURCES "ftdi_jtag/*.c")
file(GLOB_RECURSE GPIO_SOURCES "linux_gpio_jtag/*.c")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories(${DIR_MODULES})
include_directories(${DIR_LIBS})
add_compile_definitions(FTD2XX_STATIC)
add_compile_definitions(FTDILIB)
add_library(drivers ${MAIN_SOURCES} ${FTDI_SOURCES} ${GPIO_SOURCES} ${JLINK_SOURCES})

View File

@@ -41,7 +41,7 @@
extern "C" {
#endif
#include "ftd2xx.h"
#include "libftd2xx/ftd2xx.h"
#ifdef __cplusplus
}

View File

@@ -18,10 +18,8 @@ add_custom_target(
DEPENDS prebuild_command_done
)
add_compile_definitions(FTD2XX_STATIC)
add_compile_definitions(FTDILIB)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories(${DIR_MODULES})
include_directories(${DIR_LIBS})
add_library(jtag_core ${ALL_SOURCES})
add_dependencies(jtag_core prebuild)

View File

@@ -2,6 +2,7 @@ set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB_RECURSE ALL_SOURCES "*.c")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories(${DIR_MODULES})
include_directories(${DIR_LIBS})
add_library(script ${ALL_SOURCES})

File diff suppressed because it is too large Load Diff

View File

@@ -27,6 +27,23 @@
#include "config/bs_defines.h"
typedef int (* CMD_FUNC)( script_ctx * ctx, char * line);
typedef struct cmd_list_
{
const char * command;
CMD_FUNC func;
const char ** help;
}cmd_list;
typedef struct label_list_
{
char * label;
unsigned int file_offset;
}label_list;
extern cmd_list script_commands_list[];
script_ctx *jtagcore_initScript(jtag_core *jc);
script_ctx * init_script(void * app_ctx, unsigned int flags, void * env);
int execute_file_script( script_ctx * ctx, char * filename );