code refactoring
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "utils.h"
|
||||
#include "args.h"
|
||||
|
||||
// void global_help() {
|
||||
|
||||
13
bs/args.h
13
bs/args.h
@@ -1,19 +1,6 @@
|
||||
#ifndef _ARGS_H
|
||||
#define _ARGS_H
|
||||
|
||||
// #define MAX_LINE 1024
|
||||
// #define MAX_ARGS 16
|
||||
// #define MAX_COMMANDS 16
|
||||
// #define MAX_PATH 1024
|
||||
|
||||
// struct args {
|
||||
// int list;
|
||||
// int probe;
|
||||
// char bsdl[MAX_PATH];
|
||||
// int devid;
|
||||
// enum commands cmds[MAX_COMMANDS];
|
||||
// };
|
||||
|
||||
// int parse_args(struct args *a, int argc, char *argv[]);
|
||||
void parse_command(char *line, int *argc, char **argv);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "list_probes.h"
|
||||
#include "common.h"
|
||||
#include "../utils.h"
|
||||
|
||||
const char cmd_list_probes_help[] = "Bla bla.";
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "scan.h"
|
||||
#include "common.h"
|
||||
#include "../utils.h"
|
||||
|
||||
const char cmd_scan_help[] = "Bla bla.";
|
||||
|
||||
|
||||
21
bs/init.c
21
bs/init.c
@@ -20,15 +20,21 @@ Command commands[] = {
|
||||
*/
|
||||
|
||||
#include "jtag_core/jtag_core.h"
|
||||
#include "config/version.h"
|
||||
#include "script/env.h"
|
||||
#include "script/script.h"
|
||||
|
||||
#include "config/config_script.h"
|
||||
|
||||
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;
|
||||
|
||||
/* initialize the JTAG library */
|
||||
jc = jtagcore_init();
|
||||
@@ -37,13 +43,13 @@ jtag_core *bsexp_init(void)
|
||||
|
||||
jc->envvar = (void*)initEnv(NULL, NULL);
|
||||
|
||||
jtagcore_setEnvVar( jc, "VERSION", "v"jtag_core_VERSION);
|
||||
jtagcore_setEnvVar( jc, "VERSION", "v"LIB_JTAG_CORE_VERSION);
|
||||
|
||||
sctx = jtagcore_initScript(jc);
|
||||
|
||||
jtagcore_execScriptRam( sctx, config_script, config_script_len );
|
||||
execute_ram_script(sctx, config_script, config_script_len );
|
||||
|
||||
jtagcore_execScriptFile( sctx, "config.script" );
|
||||
execute_file_script( sctx, "config.script" );
|
||||
|
||||
/* Log printing callback */
|
||||
if (jtagcore_set_logs_callback(jc, jprint) < 0)
|
||||
@@ -56,6 +62,13 @@ jtag_core *bsexp_init(void)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _UTILS_H
|
||||
#define _UTILS_H
|
||||
#ifndef _BS_INIT_H
|
||||
#define _BS_INIT_H
|
||||
|
||||
#include "jtag_core/jtag_core.h"
|
||||
|
||||
|
||||
45
bs/main.c
45
bs/main.c
@@ -5,8 +5,9 @@
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
#include "jtag_core/jtag_core.h"
|
||||
#include "common.h"
|
||||
#include "config/bs_defines.h"
|
||||
#include "utils.h"
|
||||
#include "init.h"
|
||||
#include "args.h"
|
||||
|
||||
// int main(int argc, char *argv[]) {
|
||||
@@ -58,21 +59,21 @@
|
||||
// }
|
||||
|
||||
|
||||
int execute_command(jtag_core *jc, int argc, char **argv) {
|
||||
int error = 0;
|
||||
if (argv[0] == NULL) {
|
||||
return 0;
|
||||
}
|
||||
// int execute_command(jtag_core *jc, int argc, char **argv) {
|
||||
// int error = 0;
|
||||
// if (argv[0] == NULL) {
|
||||
// return 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");
|
||||
}
|
||||
// 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 main() {
|
||||
char *line = NULL;
|
||||
@@ -103,12 +104,12 @@ int main() {
|
||||
if (strcmp(cmd_argv[0], "exit") == 0) {
|
||||
break;
|
||||
}
|
||||
error = execute_command(jc, cmd_argc, cmd_argv);
|
||||
printf("\n");
|
||||
if (0 == error) {
|
||||
} else {
|
||||
printf("Command failed with code: %d", error);
|
||||
}
|
||||
// error = execute_command(jc, cmd_argc, cmd_argv);
|
||||
// printf("\n");
|
||||
// if (0 == error) {
|
||||
// } else {
|
||||
// printf("Command failed with code: %d", error);
|
||||
// }
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
16
bs/version.h
16
bs/version.h
@@ -1,16 +0,0 @@
|
||||
#define VDIG1 2
|
||||
#define VDIG2 6
|
||||
#define VDIG3 7
|
||||
#define VDIG4 1
|
||||
|
||||
#define STR_DATE "28 Oct 2024"
|
||||
|
||||
#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 ) )
|
||||
Reference in New Issue
Block a user