OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /qaz_libs/trunk/cli
    from Rev 22 to Rev 18
    Reverse comparison

Rev 22 → Rev 18

/cli/sys_error.h File deleted
/cli/sys_cmd_table.h File deleted
/cli/memtest.c File deleted
/cli/sys_cmd.c File deleted
/cli/memtest.h File deleted
/cli/sys_cli.c File deleted
/cli/sys_cmd.h File deleted
/cli/sys_error.c File deleted
/util/util_bits.h File deleted
/util/uboot_lib.h File deleted
/util/types.h File deleted
/util/util_mem.c File deleted
/util/util_bits.c File deleted
/util/uboot_lib.c File deleted
/util/util_mem.h File deleted
/util/mapmem.h File deleted
/sys_cmd.c
0,0 → 1,136
/*-----------------------------------------------------------*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sys_cmd.h"
 
 
/*-----------------------------------------------------------*/
static unsigned int cli_no_of_commands;
 
void cli_init( void )
{
int i;
for(i = 0; cli_commands[i].func != NULL; i++);
cli_no_of_commands = i;
}
 
 
/*-----------------------------------------------------------*/
static int cmd_cmp( const void *e1, const void *e2 )
{
struct cli_cmd_tab_t *p_cmd_1 = (struct cli_cmd_tab_t *)e1;
struct cli_cmd_tab_t *p_cmd_2 = (struct cli_cmd_tab_t *)e2;
 
return strncmp( p_cmd_1->cmd, p_cmd_2->cmd, MAX_CMD_LENGTH );
}
 
 
/*-----------------------------------------------------------*/
cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check )
{
struct cli_cmd_tab_t *cli_cmd;
cli_cmd = (struct cli_cmd_tab_t *) bsearch( cmd_to_check, cli_commands, cli_no_of_commands, sizeof(struct cli_cmd_tab_t), cmd_cmp );
 
return(cli_cmd);
}
 
 
/*-----------------------------------------------------------*/
static char func_help( const unsigned char argc, const char *argv[] )
{
unsigned int i;
 
PRINTF_MACRO( "Usage: cmd <arg1> <arg2> <arg3> ...\r\n" );
PRINTF_MACRO( "\r\n" );
PRINTF_MACRO( "Commands:\r\n" );
 
for( i = 0; i < cli_no_of_commands; i++ )
puts( cli_commands[i].help_string );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
static char func_peek( const unsigned char argc, const char *argv[] )
{
volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
 
PRINTF_MACRO( "peek: %s => 0x%08x \r\n", argv[1], *address );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
static char func_poke( const unsigned char argc, const char *argv[] )
{
volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
unsigned int value = strtoul( argv[2], (char **)NULL, 16 );
 
*((volatile unsigned int *)address) = value;
 
PRINTF_MACRO( "poke: %s <= %s \r\n", argv[1], argv[2] );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
#include "memtest.h"
 
static char func_memtest( const unsigned char argc, const char *argv[] )
{
datum *address = (datum *)( strtoul( argv[1], (char **)NULL, 16 ) );
unsigned long nBytes = strtoul( argv[2], (char **)NULL, 16 );
 
if( argc != 3 || address == NULL || nBytes == 0 )
{
PRINTF_MACRO( "memtest: bad args \r\n" );
return( EXIT_FAILURE );
}
 
PRINTF_MACRO( "running memTestDataBus() ... " );
 
if( memTestDataBus( address ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
 
PRINTF_MACRO( "running memTestAddressBus() ... " );
 
if( memTestAddressBus( address, nBytes ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
 
PRINTF_MACRO( "running memTestDevice() ... " );
 
if( memTestDevice( address, nBytes ) )
PRINTF_MACRO( "FAILED!!!\r\n" );
else
PRINTF_MACRO( "PASSED\r\n" );
 
return EXIT_SUCCESS;
}
 
 
/*-----------------------------------------------------------*/
/* put in alphabetical order by command name */
struct cli_cmd_tab_t cli_commands[] =
{
{ "help", func_help, " help print this help message\r" },
{ "memtest", func_memtest, " memtest memtest 0x<base_address> 0x<size>\r" },
{ "peek", func_peek, " peek peek <address>\r" },
{ "poke", func_poke, " poke poke <address> <value> \r" },
{ "", NULL, NULL }
};
 
 
/sys_cli.c
0,0 → 1,251
/*-----------------------------------------------------------*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
#include "sys_cmd.h"
#include "sys_error.h"
 
 
 
/*-----------------------------------------------------------*/
#ifdef ANSI_ESCAPE_CODE
#define ASCII_ESC '\x1b'
 
static void send_csi( char c )
{
putchar( ASCII_ESC );
putchar( '[' );
putchar( c );
}
#else
static void send_csi( char c ) {};
#endif
 
 
/*-----------------------------------------------------------*/
static char *cli_edit_buffer( char *in_buffer, char *out_buffer, unsigned int line_length )
{
static char *out_ptr;
static char *begin_ptr;
static char *end_ptr;
 
#ifdef ANSI_ESCAPE_CODE
static char prev_char;
static unsigned int csi;
#endif
 
unsigned int i;
 
if( out_buffer != NULL )
{
out_ptr = out_buffer;
begin_ptr = out_buffer;
end_ptr = out_buffer + INPUT_LINE_LENGTH;
 
#ifdef ANSI_ESCAPE_CODE
prev_char = 0;
csi = 0;
#endif
}
 
for( i = 0 ; i < line_length ; i++ )
{
 
if( out_ptr >= end_ptr )
{
*end_ptr = '\0';
return( NULL );
}
 
if( out_ptr < begin_ptr )
sys_error_fatal( FATAL_ERROR_CLI );
 
switch( in_buffer[i] )
{
case '\0':
return( NULL );
break;
 
case '\n':
*out_ptr = '\0';
return( NULL );
break;
 
case '\r':
*out_ptr = '\0';
return( NULL );
break;
 
case '\b':
if( out_ptr != begin_ptr )
{
send_csi( 'P' );
out_ptr--;
} else
{
putchar( ' ' );
send_csi( '\a' );
}
break;
 
#ifdef ANSI_ESCAPE_CODE
case ASCII_ESC:
break;
 
case '[':
if( prev_char == ASCII_ESC )
{
csi = 1;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'A':
if( csi )
{
send_csi( 'B' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'B':
if( csi == 0 )
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'C':
if( csi )
{
send_csi( 'D' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
 
case 'D':
if( csi )
{
send_csi( 'C' );
send_csi( '\a' );
 
csi = 0;
} else
{
*out_ptr = in_buffer[i];
out_ptr++;
}
break;
#endif
 
default:
*out_ptr = in_buffer[i];
out_ptr++;
break;
}
 
#ifdef ANSI_ESCAPE_CODE
prev_char = in_buffer[i];
#endif
}
 
return( out_ptr );
}
 
 
/*-----------------------------------------------------------*/
void sys_cli_task( void )
{
char last_return_value = EXIT_SUCCESS;
char in_buffer[INPUT_LINE_LENGTH + 1];
char out_buffer[INPUT_LINE_LENGTH + 1];
char *cli_ptr;
struct cli_cmd_tab_t cmd_to_check = { "", NULL, NULL };
unsigned char cli_argc;
char *cli_argv[MAX_CLI_ARGC];
struct cli_cmd_tab_t *cli_cmd;
unsigned int bytes_read;
 
cli_init();
 
PRINTF_MACRO( "\r\n" );
 
for( ;; )
{
PRINTF_MACRO( "%d > ", last_return_value );
 
cli_argc = 0;
last_return_value = EXIT_SUCCESS;
 
bytes_read = (unsigned int)read( STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer) );
cli_ptr = cli_edit_buffer( in_buffer, out_buffer, bytes_read );
 
while( cli_ptr != NULL )
{
bytes_read = (unsigned int)read( STDIN_FILENO, (void *)in_buffer, sizeof(in_buffer) );
cli_ptr = cli_edit_buffer( in_buffer, NULL, bytes_read );
}
 
if( out_buffer[0] == '\0' )
{
PRINTF_MACRO( " NULL String! Command ignored\r\n" );
last_return_value = EXIT_FAILURE;
}
 
while( last_return_value != EXIT_FAILURE )
{
cli_ptr = strtok( out_buffer, " \t" );
 
strncpy( cmd_to_check.cmd, out_buffer, MAX_CMD_LENGTH );
cli_cmd = cli_find_command( &cmd_to_check );
 
if ( cli_cmd == NULL )
{
PRINTF_MACRO( "\r\n Command not found!\r\n" );
last_return_value = EXIT_FAILURE;
break;
}
 
if( cli_ptr == NULL )
{
cli_argv[cli_argc] = out_buffer;
cli_argc++;
} else
{
while( cli_ptr != NULL )
{
cli_argv[cli_argc] = cli_ptr;
cli_argc++;
 
cli_ptr = strtok( NULL, " \t" );
}
}
 
PRINTF_MACRO( "\r\n" );
 
last_return_value = cli_cmd->func( cli_argc, (const char **)cli_argv );
break;
}
 
}
}
 
/sys_cmd.h
0,0 → 1,35
/*-----------------------------------------------------------*/
 
 
#ifndef _QAZ_SYS_CMD_H_
#define _QAZ_SYS_CMD_H_
 
#define INPUT_LINE_LENGTH 40
#define MAX_CMD_LENGTH 20
#define MAX_CLI_ARGC 6
 
#include <xil_printf.h>
 
// #define ANSI_ESCAPE_CODE
 
#define PRINTF_MACRO xil_printf
// #define PRINTF_MACRO iprintf
 
typedef char (*cli_cmd_func)( const unsigned char argc, const char * argv[] );
 
typedef struct cli_cmd_tab_t
{
char cmd[MAX_CMD_LENGTH];
cli_cmd_func func;
const char *help_string;
} cli_cmd_tab_t;
 
extern struct cli_cmd_tab_t cli_commands[];
 
 
/*-----------------------------------------------------------*/
extern void sys_cli_task(void);
extern cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check );
extern void cli_init( void );
 
#endif // _QAZ_SYS_CMD_H_
/memtest.c
0,0 → 1,222
/**********************************************************************
*
* Filename: memtest.c
*
* Description: General-purpose memory testing functions.
*
* Notes: This software can be easily ported to systems with
* different data bus widths by redefining 'datum'.
*
*
* Copyright (c) 1998 by Michael Barr. This software is placed into
* the public domain and may be used for any purpose. However, this
* notice must not be changed or removed and no warranty is either
* expressed or implied by its publication or distribution.
**********************************************************************/
 
 
#include "memtest.h"
 
 
/**********************************************************************
*
* Function: memTestDataBus()
*
* Description: Test the data bus wiring in a memory region by
* performing a walking 1's test at a fixed address
* within that region. The address (and hence the
* memory region) is selected by the caller.
*
* Notes:
*
* Returns: 0 if the test succeeds.
* A non-zero result is the first pattern that failed.
*
**********************************************************************/
datum
memTestDataBus(volatile datum * address)
{
datum pattern;
 
 
/*
* Perform a walking 1's test at the given address.
*/
for (pattern = 1; pattern != 0; pattern <<= 1)
{
/*
* Write the test pattern.
*/
*address = pattern;
 
/*
* Read it back (immediately is okay for this test).
*/
if (*address != pattern)
{
return (pattern);
}
}
 
return (0);
 
} /* memTestDataBus() */
 
 
/**********************************************************************
*
* Function: memTestAddressBus()
*
* Description: Test the address bus wiring in a memory region by
* performing a walking 1's test on the relevant bits
* of the address and checking for aliasing. This test
* will find single-bit address failures such as stuck
* -high, stuck-low, and shorted pins. The base address
* and size of the region are selected by the caller.
*
* Notes: For best results, the selected base address should
* have enough LSB 0's to guarantee single address bit
* changes. For example, to test a 64-Kbyte region,
* select a base address on a 64-Kbyte boundary. Also,
* select the region size as a power-of-two--if at all
* possible.
*
* Returns: NULL if the test succeeds.
* A non-zero result is the first address at which an
* aliasing problem was uncovered. By examining the
* contents of memory, it may be possible to gather
* additional information about the problem.
*
**********************************************************************/
datum *
memTestAddressBus(volatile datum * baseAddress, unsigned long nBytes)
{
unsigned long addressMask = (nBytes/sizeof(datum) - 1);
unsigned long offset;
unsigned long testOffset;
 
datum pattern = (datum) 0xAAAAAAAA;
datum antipattern = (datum) 0x55555555;
 
 
/*
* Write the default pattern at each of the power-of-two offsets.
*/
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
baseAddress[offset] = pattern;
}
 
/*
* Check for address bits stuck high.
*/
testOffset = 0;
baseAddress[testOffset] = antipattern;
 
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
if (baseAddress[offset] != pattern)
{
return ((datum *) &baseAddress[offset]);
}
}
 
baseAddress[testOffset] = pattern;
 
/*
* Check for address bits stuck low or shorted.
*/
for (testOffset = 1; (testOffset & addressMask) != 0; testOffset <<= 1)
{
baseAddress[testOffset] = antipattern;
 
if (baseAddress[0] != pattern)
{
return ((datum *) &baseAddress[testOffset]);
}
 
for (offset = 1; (offset & addressMask) != 0; offset <<= 1)
{
if ((baseAddress[offset] != pattern) && (offset != testOffset))
{
return ((datum *) &baseAddress[testOffset]);
}
}
 
baseAddress[testOffset] = pattern;
}
 
return (NULL);
 
} /* memTestAddressBus() */
 
 
/**********************************************************************
*
* Function: memTestDevice()
*
* Description: Test the integrity of a physical memory device by
* performing an increment/decrement test over the
* entire region. In the process every storage bit
* in the device is tested as a zero and a one. The
* base address and the size of the region are
* selected by the caller.
*
* Notes:
*
* Returns: NULL if the test succeeds.
*
* A non-zero result is the first address at which an
* incorrect value was read back. By examining the
* contents of memory, it may be possible to gather
* additional information about the problem.
*
**********************************************************************/
datum *
memTestDevice(volatile datum * baseAddress, unsigned long nBytes)
{
unsigned long offset;
unsigned long nWords = nBytes / sizeof(datum);
 
datum pattern;
datum antipattern;
 
 
/*
* Fill memory with a known pattern.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
baseAddress[offset] = pattern;
}
 
/*
* Check each location and invert it for the second pass.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
if (baseAddress[offset] != pattern)
{
return ((datum *) &baseAddress[offset]);
}
 
antipattern = ~pattern;
baseAddress[offset] = antipattern;
}
 
/*
* Check each location for the inverted pattern and zero it.
*/
for (pattern = 1, offset = 0; offset < nWords; pattern++, offset++)
{
antipattern = ~pattern;
if (baseAddress[offset] != antipattern)
{
return ((datum *) &baseAddress[offset]);
}
}
 
return (NULL);
 
} /* memTestDevice() */
 
/memtest.h
0,0 → 1,41
/**********************************************************************
*
* Filename: memtest.h
*
* Description: Memory-testing module API.
*
* Notes: The memory tests can be easily ported to systems with
* different data bus widths by redefining 'datum' type.
*
*
* Copyright (c) 2000 by Michael Barr. This software is placed into
* the public domain and may be used for any purpose. However, this
* notice must not be changed or removed and no warranty is either
* expressed or implied by its publication or distribution.
**********************************************************************/
 
#ifndef _memtest_h
#define _memtest_h
 
 
/*
* Define NULL pointer value.
*/
#ifndef NULL
#define NULL (void *) 0
#endif
 
/*
* Set the data bus width.
*/
typedef unsigned long datum;
 
/*
* Function prototypes.
*/
datum memTestDataBus(volatile datum * address);
datum * memTestAddressBus(volatile datum * baseAddress, unsigned long nBytes);
datum * memTestDevice(volatile datum * baseAddress, unsigned long nBytes);
 
 
#endif /* _memtest_h */
/sys_error.c
0,0 → 1,9
/*-----------------------------------------------------------*/
 
void sys_error_fatal( unsigned int error )
{
// (*( (volatile unsigned int *) (0x8000003c) )) = error; // write to scratch pad reg in FPGA
while(1) {};
}
 
/sys_error.h
0,0 → 1,17
/*-----------------------------------------------------------*/
 
#ifndef _QAZ_SYS_ERROR_H_
#define _QAZ_SYS_ERROR_H_
 
typedef enum
{
FATAL_ERROR_CLI = 0,
FATAL_ERROR_FD_SSP0_0,
} sys_error_fatal_type;
 
 
/*-----------------------------------------------------------*/
void sys_error_fatal( unsigned int error );
 
#endif // _QAZ_SYS_ERROR_H_
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.