code refactoring
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config/bs_defines.h"
|
||||
#include "env.h"
|
||||
|
||||
/*
|
||||
@@ -547,6 +548,33 @@ envvar_entry * initEnv(envvar_entry * src, envvar_entry * dst)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int jtagcore_setEnvVar( jtag_core * jc, char * varname, char * varvalue )
|
||||
{
|
||||
if( setEnvVarDat( jc->envvar, varname, varvalue ) >= 0 )
|
||||
{
|
||||
return JTAG_CORE_NO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return JTAG_CORE_MEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
char * jtagcore_getEnvVar( jtag_core * jc, char * varname, char * varvalue)
|
||||
{
|
||||
return getEnvVarDat( jc->envvar, varname, varvalue, 512 );
|
||||
}
|
||||
|
||||
char * jtagcore_getEnvVarIndex( jtag_core * jc, int index, char * varvalue)
|
||||
{
|
||||
return getEnvVarDatIndex( jc->envvar, index, varvalue, 512 );
|
||||
}
|
||||
|
||||
int jtagcore_getEnvVarValue( jtag_core * jc, char * varname)
|
||||
{
|
||||
return getEnvVarValue( jc->envvar, varname);
|
||||
}
|
||||
|
||||
void deinitEnv(envvar_entry * env)
|
||||
{
|
||||
#ifndef STATIC_ENV_BUFFER
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#ifndef _ENV_H
|
||||
#define _ENV_H
|
||||
/*
|
||||
* JTAG Boundary Scanner
|
||||
* Copyright (c) 2008 - 2024 Viveris Technologies
|
||||
@@ -22,6 +24,9 @@
|
||||
* @brief Internal variables support header file.
|
||||
* @author Jean-François DEL NERO <Jean-Francois.DELNERO@viveris.fr>
|
||||
*/
|
||||
|
||||
#include "config/bs_defines.h"
|
||||
|
||||
#ifdef SCRIPT_64BITS_SUPPORT
|
||||
#define env_var_value uint64_t
|
||||
#define signed_env_var_value int64_t
|
||||
@@ -58,3 +63,12 @@ env_var_value getEnvVarValue( envvar_entry * env, char * varname );
|
||||
char * getEnvVarDatIndex( envvar_entry * env, int index, char * vardata, int maxsize );
|
||||
|
||||
void deinitEnv( envvar_entry * env );
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Internal variables functions
|
||||
int jtagcore_setEnvVar(jtag_core *jc, char *varname, char *varvalue);
|
||||
char *jtagcore_getEnvVar(jtag_core *jc, char *varname, char *varvalue);
|
||||
int jtagcore_getEnvVarValue(jtag_core *jc, char *varname);
|
||||
char *jtagcore_getEnvVarIndex(jtag_core *jc, int index, char *varvalue);
|
||||
|
||||
#endif
|
||||
@@ -31,11 +31,9 @@
|
||||
|
||||
#define MAX_PATH 256
|
||||
|
||||
#include "drivers/drv_loader.h"
|
||||
#include "jtag_core/jtag_core_internal.h"
|
||||
#include "script.h"
|
||||
#include "jtag_core/jtag_core.h"
|
||||
#include "jtag_core/version.h"
|
||||
#include "config/version.h"
|
||||
|
||||
#include "bsdl_parser/bsdl_loader.h"
|
||||
#include "os_interface/os_interface.h"
|
||||
@@ -61,7 +59,7 @@ typedef struct label_list_
|
||||
|
||||
extern cmd_list script_commands_list[];
|
||||
|
||||
static int dummy_script_printf(void * ctx, int MSGTYPE, char * string, ... )
|
||||
static int dummy_script_printf(script_ctx * ctx, int MSGTYPE, char * string, ... )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -2557,43 +2555,6 @@ script_ctx * jtagcore_initScript(jtag_core * jc)
|
||||
return init_script((void*)jc,0x00000000,(void*)jc->envvar);
|
||||
}
|
||||
|
||||
void jtagcore_setScriptOutputFunc( script_ctx * ctx, SCRIPT_PRINTF_FUNC ext_printf )
|
||||
{
|
||||
setOutputFunc_script(ctx, ext_printf);
|
||||
}
|
||||
|
||||
int jtagcore_execScriptLine( script_ctx * ctx, char * line )
|
||||
{
|
||||
if(!ctx)
|
||||
return JTAG_CORE_INTERNAL_ERROR;
|
||||
|
||||
return execute_line_script( ctx, line );
|
||||
}
|
||||
|
||||
int jtagcore_execScriptFile( script_ctx * ctx, char * script_path )
|
||||
{
|
||||
if(!ctx)
|
||||
return JTAG_CORE_INTERNAL_ERROR;
|
||||
|
||||
return execute_file_script( ctx, script_path );
|
||||
}
|
||||
|
||||
int jtagcore_execScriptRam( script_ctx * ctx, unsigned char * script_buffer, int buffersize )
|
||||
{
|
||||
if(!ctx)
|
||||
return JTAG_CORE_INTERNAL_ERROR;
|
||||
|
||||
return execute_ram_script( ctx, script_buffer, buffersize );
|
||||
}
|
||||
|
||||
script_ctx * jtagcore_deinitScript(script_ctx * ctx)
|
||||
{
|
||||
if(!ctx)
|
||||
return NULL;
|
||||
|
||||
return deinit_script(ctx);
|
||||
}
|
||||
|
||||
int jtagcore_savePinsStateScript( jtag_core * jc, int device, char * script_path )
|
||||
{
|
||||
FILE * f;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#ifndef _SCRIPT_H
|
||||
#define _SCRIPT_H
|
||||
/*
|
||||
* JTAG Boundary Scanner
|
||||
* Copyright (c) 2008 - 2024 Viveris Technologies
|
||||
@@ -23,64 +25,15 @@
|
||||
* @author Jean-François DEL NERO <Jean-Francois.DELNERO@viveris.fr>
|
||||
*/
|
||||
|
||||
#define _script_ctx_
|
||||
|
||||
#ifndef _script_printf_func_
|
||||
typedef int (* SCRIPT_PRINTF_FUNC)(void * ctx, int MSGTYPE, char * string, ... );
|
||||
#define _script_printf_func_
|
||||
#endif
|
||||
|
||||
#ifdef SCRIPT_64BITS_SUPPORT
|
||||
#define env_var_value uint64_t
|
||||
#define STRTOVALUE strtoull
|
||||
#define LONGHEXSTR "%llX"
|
||||
#else
|
||||
#define env_var_value uint32_t
|
||||
#define STRTOVALUE strtoul
|
||||
#define LONGHEXSTR "%.8X"
|
||||
#endif
|
||||
|
||||
#define MAX_LABEL_SIZE 64
|
||||
#define MAX_LABEL 256
|
||||
|
||||
typedef struct _script_label
|
||||
{
|
||||
char label_name[MAX_LABEL_SIZE];
|
||||
unsigned int offset;
|
||||
} script_label;
|
||||
|
||||
typedef struct _script_ctx
|
||||
{
|
||||
SCRIPT_PRINTF_FUNC script_printf;
|
||||
void * app_ctx;
|
||||
|
||||
void * env;
|
||||
|
||||
void * cmdlist;
|
||||
|
||||
FILE * script_file;
|
||||
char script_file_path[1024];
|
||||
|
||||
int cur_label_index;
|
||||
script_label labels[MAX_LABEL];
|
||||
|
||||
int cur_script_offset;
|
||||
|
||||
int dry_run;
|
||||
|
||||
int last_error_code;
|
||||
env_var_value last_data_value;
|
||||
int last_flags;
|
||||
|
||||
char pre_command[1024 + 32];
|
||||
|
||||
uint32_t rand_seed;
|
||||
|
||||
} script_ctx;
|
||||
#include "config/bs_defines.h"
|
||||
|
||||
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 );
|
||||
int execute_line_script( script_ctx * ctx, char * line );
|
||||
int execute_ram_script( script_ctx * ctx, unsigned char * script_buffer, int buffersize );
|
||||
void setOutputFunc_script( script_ctx * ctx, SCRIPT_PRINTF_FUNC ext_printf );
|
||||
script_ctx * deinit_script(script_ctx * ctx);
|
||||
int jtagcore_savePinsStateScript(jtag_core *jc, int device, char *script_path);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user