From b66e82da87cb63ef163aa4cb81e305d9daabeb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sun, 16 Feb 2025 19:43:48 +0100 Subject: [PATCH] init and deinit --- bs/init.c | 41 +++++++++++++++++++++-------------- bs/init.h | 3 ++- bs/main.c | 2 ++ modules/jtag_core/jtag_core.c | 23 -------------------- 4 files changed, 29 insertions(+), 40 deletions(-) diff --git a/bs/init.c b/bs/init.c index 35d87bd..0103535 100644 --- a/bs/init.c +++ b/bs/init.c @@ -31,25 +31,26 @@ void jprint(jtag_core *jc, const char *msg) printf(msg); } -jtag_core * bsexp_init(void) +jtag_core *bsexp_init(void) { jtag_core *jc = NULL; - script_ctx * sctx; + script_ctx *sctx; /* initialize the JTAG library */ jc = jtagcore_init(); - if (NULL == jc) goto end; + if (NULL == jc) + goto end; - jc->envvar = (void*)initEnv(NULL, NULL); + jc->envvar = (void *)initEnv(NULL, NULL); - jtagcore_setEnvVar( jc, "VERSION", "v"LIB_JTAG_CORE_VERSION); + jtagcore_setEnvVar(jc, "VERSION", "v" LIB_JTAG_CORE_VERSION); sctx = jtagcore_initScript(jc); - execute_ram_script(sctx, config_script, config_script_len ); + execute_ram_script(sctx, config_script, config_script_len); - execute_file_script( sctx, "config.script" ); + execute_file_script(sctx, "config.script"); /* Log printing callback */ if (jtagcore_set_logs_callback(jc, jprint) < 0) @@ -58,19 +59,27 @@ jtag_core * bsexp_init(void) } 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)) - { - jtagcore_set_logs_file( jc, jtagcore_getEnvVar( jc, "LOG_MESSAGES_FILE_OUTPUT", NULL) ); - } - - deinit_script(sctx); + if (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; -} \ No newline at end of file +} + +void bsexp_deinit(jtag_core *jc) +{ + if (NULL == jc) return; + + envvar_entry *env = jc->envvar; + deinitEnv(env); + jtagcore_deinit(jc); +} diff --git a/bs/init.h b/bs/init.h index 87ee0a5..4cc629e 100644 --- a/bs/init.h +++ b/bs/init.h @@ -1,7 +1,7 @@ #ifndef _BS_INIT_H #define _BS_INIT_H -#include "jtag_core/jtag_core.h" +#include "config/bs_defines.h" typedef int (*command_call)(jtag_core *jc, int argc, char *argv[]); @@ -13,5 +13,6 @@ typedef struct { extern Command commands[]; jtag_core *bsexp_init(void); +void bsexp_deinit(jtag_core *jc); #endif \ No newline at end of file diff --git a/bs/main.c b/bs/main.c index 53de3f9..0812d4d 100644 --- a/bs/main.c +++ b/bs/main.c @@ -115,4 +115,6 @@ int main() { err: return error; +end: + bsexp_deinit(jc); } \ No newline at end of file diff --git a/modules/jtag_core/jtag_core.c b/modules/jtag_core/jtag_core.c index e2f26c9..7f9fc42 100644 --- a/modules/jtag_core/jtag_core.c +++ b/modules/jtag_core/jtag_core.c @@ -47,29 +47,6 @@ jtag_core * jtagcore_init() if ( jc ) { memset( jc, 0, sizeof(jtag_core) ); -/* - jc->envvar = (void*)initEnv(NULL, NULL); - - jtagcore_setEnvVar( jc, "LIBVERSION", "v"jtag_core_VERSION); - - sctx = jtagcore_initScript(jc); - - jtagcore_execScriptRam( sctx, config_script, config_script_len ); - - jtagcore_execScriptFile( sctx, "config.script" ); - - if(jtagcore_getEnvVar( jc, "LOG_MESSAGES_FILTER_LEVEL", NULL)) - { - jtagcore_set_logs_level( jc, jtagcore_getEnvVarValue( jc, "LOG_MESSAGES_FILTER_LEVEL") ); - } - - if(jtagcore_getEnvVar( jc, "LOG_MESSAGES_FILE_OUTPUT", NULL)) - { - jtagcore_set_logs_file( jc, jtagcore_getEnvVar( jc, "LOG_MESSAGES_FILE_OUTPUT", NULL) ); - } - - jtagcore_deinitScript(sctx); -*/ } return jc;