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
/
- from Rev 10 to Rev 11
- ↔ Reverse comparison
Rev 10 → Rev 11
/qaz_libs/trunk/cli/memtest.c
0,0 → 1,221
/********************************************************************** |
* |
* 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() */ |
/qaz_libs/trunk/cli/sys_cmd.c
0,0 → 1,99
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include "sys_cmd.h" |
|
|
/*-----------------------------------------------------------*/ |
static char func_help( const unsigned char argc, const char *argv[] ) |
{ |
unsigned int i; |
|
iprintf( "Usage: cmd <arg1> <arg2> <arg3> ...\r\n" ); |
iprintf( "\r\n" ); |
iprintf( "Commands:\r\n" ); |
|
for( i = 0; i < 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 ) ); |
|
iprintf( "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; |
|
iprintf( "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 ) |
{ |
iprintf( "memtest: bad args \r\n" ); |
return( EXIT_FAILURE ); |
} |
|
iprintf( "running memTestDataBus() ... " ); |
|
if( memTestDataBus( address ) ) |
iprintf( "FAILED!!!\r\n" ); |
else |
iprintf( "PASSED\r\n" ); |
|
|
iprintf( "running memTestAddressBus() ... " ); |
|
if( memTestAddressBus( address, nBytes ) ) |
iprintf( "FAILED!!!\r\n" ); |
else |
iprintf( "PASSED\r\n" ); |
|
|
iprintf( "running memTestDevice() ... " ); |
|
if( memTestDevice( address, nBytes ) ) |
iprintf( "FAILED!!!\r\n" ); |
else |
iprintf( "PASSED\r\n" ); |
|
return EXIT_SUCCESS; |
} |
|
|
/*-----------------------------------------------------------*/ |
struct cli_cmd_tab_t cli_commands[NO_OF_COMMANDS] = |
{ |
{ "help", func_help, "\t help\t\t print this help message\r" }, |
{ "memtest", func_memtest, "\t memtest\t memtest 0x<base_address> 0x<size>\r" }, |
{ "peek", func_peek, "\t peek\t\t peek <address>\r" }, |
{ "poke", func_poke, "\t poke\t\t poke <address> <value> \r" }, |
{ "ssp0", func_ssp0, "\t ssp0\t\t ssp0 <command> \r" }, |
}; |
|
|
/qaz_libs/trunk/cli/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 */ |
/qaz_libs/trunk/cli/sys_cli.c
0,0 → 1,244
/*-----------------------------------------------------------*/ |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <unistd.h> |
|
#include "sys_cmd.h" |
#include "sys_drivers.h" |
#include "sys_error.h" |
|
#define ASCII_ESC '\x1b' |
|
|
/*-----------------------------------------------------------*/ |
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 ); |
} |
|
|
/*-----------------------------------------------------------*/ |
static void send_csi( char c ) |
{ |
putchar( ASCII_ESC ); |
putchar( '[' ); |
putchar( c ); |
} |
|
|
/*-----------------------------------------------------------*/ |
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; |
static char prev_char; |
static unsigned int csi; |
|
unsigned int i; |
|
if( out_buffer != NULL ) |
{ |
out_ptr = out_buffer; |
begin_ptr = out_buffer; |
end_ptr = out_buffer + INPUT_LINE_LENGTH; |
|
prev_char = 0; |
csi = 0; |
} |
|
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': |
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; |
|
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; |
|
default: |
*out_ptr = in_buffer[i]; |
out_ptr++; |
break; |
} |
|
prev_char = in_buffer[i]; |
} |
|
return( out_ptr ); |
} |
|
|
/*-----------------------------------------------------------*/ |
void sys_cli_task( void *pvParameters ) |
{ |
char last_return_value = EXIT_SUCCESS; |
char in_buffer[16]; |
char out_buffer[INPUT_LINE_LENGTH]; |
char *cli_ptr; |
struct cli_cmd_tab_t cmd_to_check = { "", NULL }; |
unsigned char cli_argc; |
char *cli_argv[MAX_CLI_ARGC]; |
struct cli_cmd_tab_t *cli_cmd; |
unsigned int bytes_read; |
|
iprintf( "\r\n" ); |
|
for( ;; ) |
{ |
iprintf( "%d > ", last_return_value ); |
iprintf( "# " ); |
|
cli_argc = 0; |
last_return_value = EXIT_SUCCESS; |
|
bytes_read = (unsigned int)read( FD_UART_2, (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( FD_UART_2, (void *)in_buffer, sizeof(in_buffer) ); |
cli_ptr = cli_edit_buffer( in_buffer, NULL, bytes_read ); |
} |
|
if( out_buffer[0] == '\0' ) |
{ |
iprintf( "\r\n 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 = (struct cli_cmd_tab_t *) bsearch( &cmd_to_check, cli_commands, NO_OF_COMMANDS, sizeof(struct cli_cmd_tab_t), cmd_cmp ); |
|
if ( cli_cmd == NULL ) |
{ |
iprintf( "\r\nCommand 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" ); |
} |
} |
|
last_return_value = cli_cmd->func( cli_argc, (const char **)cli_argv ); |
break; |
} |
|
} |
} |
|
/qaz_libs/trunk/cli/sys_cmd.h
0,0 → 1,29
/*-----------------------------------------------------------*/ |
|
|
#ifndef _QAZ_SYS_CMD_H_ |
#define _QAZ_SYS_CMD_H_ |
|
#define INPUT_LINE_LENGTH 40 |
#define MAX_CMD_LENGTH 11 |
#define MAX_CLI_ARGC 6 |
#define NO_OF_COMMANDS 5 |
|
|
typedef char (*cli_cmd_func)( const unsigned char argc, const char * argv[] ); |
|
struct cli_cmd_tab_t |
{ |
char cmd[MAX_CMD_LENGTH]; |
cli_cmd_func func; |
const char *help_string; |
}; |
|
extern struct cli_cmd_tab_t cli_commands[NO_OF_COMMANDS]; |
|
|
/*-----------------------------------------------------------*/ |
extern char func_ssp0( const unsigned char argc, const char *argv[] ); |
|
|
#endif // _QAZ_SYS_CMD_H_ |
/qaz_libs/trunk/cli/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) {}; |
} |
|
/qaz_libs/trunk/cli/sys_error.h
0,0 → 1,12
/*-----------------------------------------------------------*/ |
|
typedef enum |
{ |
FATAL_ERROR_CLI = 0, |
FATAL_ERROR_FD_SSP0_0, |
} sys_error_fatal_type; |
|
|
/*-----------------------------------------------------------*/ |
void sys_error_fatal( unsigned int error ); |
|