📄 testtool.c
字号:
sprintf( PrintBuffer, "Invalid base address (default is BASEADDRESS=h%08lx)", def_base );
STTST_TagCurrentLine(pars_p, PrintBuffer);
}
}
if (!IsBad)
{
/* get range */
IsBad = STTST_GetInteger(pars_p, (S32)def_range, (S32 *)&SearchRange);
if ( IsBad || SearchRange <= 0 )
{
sprintf( PrintBuffer, "Invalid range (default is RANGE=h%08lx)", def_range );
STTST_TagCurrentLine(pars_p, PrintBuffer);
}
}
if (!IsBad)
{
/* get nb of occurences to found */
IsBad = STTST_GetInteger(pars_p, (S32)1, (S32 *)&SearchOccurNb);
if ( IsBad || SearchOccurNb <= 0 )
{
STTST_TagCurrentLine(pars_p, "Invalid number max. of occurences (default is 1)");
}
}
if (!IsBad)
{
/* trace what must be searched */
pt = (char *)SearchBase;
if ( not_a_string )
{
sprintf( PrintBuffer, "Search h%02x", SearchString[0] ) ;
cpt = 1;
while ( cpt < SearchLen )
{
if ( SearchLen >= 2 )
{
sprintf( PrintBuffer, "%s%02x", PrintBuffer, SearchString[cpt] );
}
cpt++;
}
sprintf( PrintBuffer, "%s on %d bytes from h%08lx to h%08lx ...\n",
PrintBuffer, SearchLen, SearchBase, (SearchBase+SearchRange) );
}
else
{
sprintf( PrintBuffer, "Search [%s] on %d bytes from h%08lx to h%08lx ...\n",
SearchString, SearchLen, SearchBase, (SearchBase+SearchRange) );
}
STTBX_Print((PrintBuffer));
/* search in memory */
IsBad = do_find( SearchString, &SearchBase, SearchRange, SearchOccurNb,
SearchLen, result_sym_p);
/* if success then SearchBase is updated to the match address */
} /* end not IsBad */
return(IsBad);
}
/* ========================================================================
testtool command : finds string in range of memory
=========================================================================== */
static BOOL FindNextString(STTST_Parse_t *pars_p, char *result_sym_p)
{
BOOL IsBad;
UNUSED_PARAMETER(pars_p);
IsBad = do_find( SearchString, &SearchBase, SearchRange, 1,
SearchLen, result_sym_p);
/* if success then SearchBase is updated to the match address */
return(IsBad);
}
/* ========================================================================
testtool command : writes specific memory contents
=========================================================================== */
static BOOL FillMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
BOOL IsBad;
long base;
long length;
long value;
long def_base;
long def_range;
long def_value;
volatile long* address;
/* get default values from symbol variables */
STTST_EvaluateInteger("BASEADDRESS", (S32 *)&def_base, 10);
STTST_EvaluateInteger("RANGE", (S32 *)&def_range, 10);
STTST_EvaluateInteger("DATAVALUE", (S32 *)&def_value, 10);
IsBad = STTST_GetInteger(pars_p, (S32)def_base, (S32 *)&base);
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid base address");
}
else
{
IsBad = (STTST_GetInteger(pars_p, (S32)def_range, (S32 *)&length) || (length <= 0));
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid length");
}
else
{
IsBad = STTST_GetInteger(pars_p, (S32)def_value, (S32 *)&value);
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid data value");
}
else
{
/* do a word oriented global fill operation*/
address = (volatile long*) base;
while (((long)address < (base + length)))
{
*address = value;
address++;
}
}
}
}
return(IsBad || STTST_AssignInteger(result_sym_p, (S32)base, FALSE));
}
/* ========================================================================
testtool command : copies memory contents to new address range
=========================================================================== */
static BOOL CopyMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
BOOL IsBad;
long base;
long length;
long newbase;
long def_base;
long def_range;
long def_newbase;
/* get default values from symbol variables */
STTST_EvaluateInteger("BASEADDRESS", (S32 *)&def_base, 10);
STTST_EvaluateInteger("RANGE", (S32 *)&def_range, 10);
STTST_EvaluateInteger("ADDRESSVALUE", (S32 *)&def_newbase, 10);
IsBad = STTST_GetInteger(pars_p, (S32)def_base, (S32 *)&base);
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid base address");
}
#ifdef FORCE_32BITS_ALIGN
else if ((base & 0x03) != 0)
{
STTST_TagCurrentLine(pars_p, "address must be 32 bits aligned");
IsBad = TRUE;
}
#endif
if (!IsBad)
{
IsBad = (STTST_GetInteger(pars_p, (S32)def_range, (S32 *)&length) || (length <= 0));
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid length");
}
else
{
IsBad = (STTST_GetInteger(pars_p, (S32)def_newbase, (S32 *)&newbase) ||
(newbase == base));
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid new base address");
}
#ifdef FORCE_32BITS_ALIGN
else if ((newbase & 0x03) != 0)
{
STTST_TagCurrentLine(pars_p, "address must be 32 bits aligned");
IsBad = TRUE;
}
#endif
}
}
if (!IsBad)
{
/* do a memory copy operation using routine that works in overlapped case*/
memmove((void *)newbase, (void *)base, (int) length);
}
return(IsBad || STTST_AssignInteger(result_sym_p, (S32)base, FALSE));
}
/* ========================================================================
testtool command : peek an 8 bit value
=========================================================================== */
#ifdef NO_STAPIGAT
static BOOL PeekByteMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
STTST_TagCurrentLine(pars_p, "NO_STAPIGAT defined");
return(TRUE || STTST_AssignInteger(result_sym_p, 0, FALSE));
}
#else
static BOOL PeekByteMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
BOOL IsBad;
long base;
long def_base;
char value = 0;
/* get default value from symbol variables */
STTST_EvaluateInteger("BASEADDRESS", (S32 *)&def_base, 10);
IsBad = STTST_GetInteger(pars_p, (S32)def_base, (S32 *)&base);
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "expected base address");
IsBad = TRUE;
}
if (!IsBad)
{
#ifdef FORCE_32BITS_ALIGN
if ((base & 0x03) != 0)
{
STTST_TagCurrentLine(pars_p, "address must be 32 bits aligned");
IsBad = TRUE;
}
else
{
value = (char)(*((volatile long*)base));
}
#else
#ifdef ST_OSLINUX
value = (char)STAPIGAT_Phys_BRead((U8*)base);
#else
value = (char)(*((volatile U8*)base));
#endif
#endif
STTBX_Print(("read 0x%x (hex) = %d (dec) \n",(U8) value, (char) value ));
}
return(IsBad || STTST_AssignInteger(result_sym_p, (S32)value, FALSE));
}
#endif
/* ========================================================================
testtool command : poke an 8 bit value
=========================================================================== */
#ifdef NO_STAPIGAT
static BOOL PokeByteMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
STTST_TagCurrentLine(pars_p, "NO_STAPIGAT defined");
return(TRUE || STTST_AssignInteger(result_sym_p, 0, FALSE));
}
#else
static BOOL PokeByteMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
BOOL IsBad;
long base;
long value;
long def_base;
long def_value;
/* get default values from symbol variables */
STTST_EvaluateInteger("BASEADDRESS", (S32 *)&def_base, 10);
STTST_EvaluateInteger("DATAVALUE", (S32 *)&def_value, 10);
IsBad = STTST_GetInteger(pars_p, (S32)def_base, (S32 *)&base);
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid base address");
}
#ifdef FORCE_32BITS_ALIGN
else if ((base & 0x03) != 0)
{
STTST_TagCurrentLine(pars_p, "Address must be 32 bits aligned");
IsBad = TRUE;
}
#endif
if (!IsBad)
{
IsBad = STTST_GetInteger(pars_p, (S32)def_value, (S32 *)&value);
if( (value < 0) || (value > 255) )
{
IsBad = TRUE;
}
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid data value");
}
else
{
#ifdef FORCE_32BITS_ALIGN
*((volatile long *) base) = (long)value;
#else
#ifdef ST_OSLINUX
STAPIGAT_Phys_BWrite((U8*)base, (U8)value);
#else
*((volatile U8*) base) = (U8)value;
#endif
#endif
}
}
return(IsBad || STTST_AssignInteger(result_sym_p, (S32)value, FALSE));
}
#endif
/* ========================================================================
testtool command : peek an 16 bit value
=========================================================================== */
#ifdef NO_STAPIGAT
static BOOL PeekShortMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
STTST_TagCurrentLine(pars_p, "NO_STAPIGAT defined");
return(TRUE || STTST_AssignInteger(result_sym_p, 0, FALSE));
}
#else
static BOOL PeekShortMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
BOOL IsBad;
long base;
long def_base;
short value = 0;
/* get default value from symbol variables */
STTST_EvaluateInteger("BASEADDRESS", (S32 *)&def_base, 10);
IsBad = STTST_GetInteger(pars_p, (S32)def_base, (S32 *)&base);
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "expected base address");
}
else
{
#ifdef FORCE_32BITS_ALIGN
if ((base & 0x03) != 0)
{
STTST_TagCurrentLine(pars_p, "address must be 32 bits aligned");
IsBad = TRUE;
}
else
{
value = (short)(*((volatile long*)base));
}
#else
#ifdef ST_OSLINUX
value = (short)STAPIGAT_Phys_SRead((U16*)base);
#else
value = (short)(*((volatile U16*)base));
#endif
#endif
STTBX_Print(("read 0x%x (hex) = %d (dec) \n",(U16) value, (short) value ));
}
return(IsBad || STTST_AssignInteger(result_sym_p, (S32)value, FALSE));
}
#endif
/* ========================================================================
testtool command : poke an 16 bit value
=========================================================================== */
#ifdef NO_STAPIGAT
static BOOL PokeShortMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
STTST_TagCurrentLine(pars_p, "NO_STAPIGAT defined");
return(TRUE || STTST_AssignInteger(result_sym_p, 0, FALSE));
}
#else
static BOOL PokeShortMemory(STTST_Parse_t *pars_p, char *result_sym_p)
{
BOOL IsBad;
long base;
long value;
long def_base;
long def_value;
/* get default values from symbol variables */
STTST_EvaluateInteger("BASEADDRESS", (S32 *)&def_base, 10);
STTST_EvaluateInteger("DATAVALUE", (S32 *)&def_value, 10);
IsBad = STTST_GetInteger(pars_p, (S32)def_base, (S32 *)&base);
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid base address");
}
#ifdef FORCE_32BITS_ALIGN
else if ((base & 0x03) != 0)
{
STTST_TagCurrentLine(pars_p, "Address must be 32 bits aligned");
IsBad = TRUE;
}
#endif
if (!IsBad)
{
IsBad = STTST_GetInteger(pars_p, (S32)def_value, (S32 *)&value);
if( (value < 0) || (value > 65535) )
{
IsBad = TRUE;
}
if (IsBad)
{
STTST_TagCurrentLine(pars_p, "Invalid data value");
}
else
{
#ifdef FORCE_32BITS_ALIGN
*((volatile long *) base) = (long)value;
#else
#ifdef ST_OSLINUX
STAPIGAT_Phys_SWrite((U16*)base, (U16)value);
#else
*((volatile U16*) base) = (U16)value;
#endif
#endif
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -