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 11 to Rev 17
    Reverse comparison

Rev 11 → Rev 17

/memtest.c
219,3 → 219,4
return (NULL);
 
} /* memTestDevice() */
 
/sys_cmd.c
1,3 → 1,5
/*-----------------------------------------------------------*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
5,15 → 7,49
 
 
/*-----------------------------------------------------------*/
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 = 1;
}
 
 
/*-----------------------------------------------------------*/
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;
 
iprintf( "Usage: cmd <arg1> <arg2> <arg3> ...\r\n" );
iprintf( "\r\n" );
iprintf( "Commands:\r\n" );
PRINTF_MACRO( "Usage: cmd <arg1> <arg2> <arg3> ...\r\n" );
PRINTF_MACRO( "\r\n" );
PRINTF_MACRO( "Commands:\r\n" );
 
for( i = 0; i < NO_OF_COMMANDS; i++ )
for( i = 0; i < cli_no_of_commands; i++ )
puts( cli_commands[i].help_string );
 
return EXIT_SUCCESS;
25,7 → 61,7
{
volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
 
iprintf( "peek: %s => 0x%08x \r\n", argv[1], *address );
PRINTF_MACRO( "peek: %s => 0x%08x \r\n", argv[1], *address );
 
return EXIT_SUCCESS;
}
39,7 → 75,7
 
*((volatile unsigned int *)address) = value;
 
iprintf( "poke: %s <= %s \r\n", argv[1], argv[2] );
PRINTF_MACRO( "poke: %s <= %s \r\n", argv[1], argv[2] );
 
return EXIT_SUCCESS;
}
55,32 → 91,32
 
if( argc != 3 || address == NULL || nBytes == 0 )
{
iprintf( "memtest: bad args \r\n" );
PRINTF_MACRO( "memtest: bad args \r\n" );
return( EXIT_FAILURE );
}
 
iprintf( "running memTestDataBus() ... " );
PRINTF_MACRO( "running memTestDataBus() ... " );
 
if( memTestDataBus( address ) )
iprintf( "FAILED!!!\r\n" );
PRINTF_MACRO( "FAILED!!!\r\n" );
else
iprintf( "PASSED\r\n" );
PRINTF_MACRO( "PASSED\r\n" );
 
 
iprintf( "running memTestAddressBus() ... " );
PRINTF_MACRO( "running memTestAddressBus() ... " );
 
if( memTestAddressBus( address, nBytes ) )
iprintf( "FAILED!!!\r\n" );
PRINTF_MACRO( "FAILED!!!\r\n" );
else
iprintf( "PASSED\r\n" );
PRINTF_MACRO( "PASSED\r\n" );
 
 
iprintf( "running memTestDevice() ... " );
PRINTF_MACRO( "running memTestDevice() ... " );
 
if( memTestDevice( address, nBytes ) )
iprintf( "FAILED!!!\r\n" );
PRINTF_MACRO( "FAILED!!!\r\n" );
else
iprintf( "PASSED\r\n" );
PRINTF_MACRO( "PASSED\r\n" );
 
return EXIT_SUCCESS;
}
87,13 → 123,14
 
 
/*-----------------------------------------------------------*/
struct cli_cmd_tab_t cli_commands[NO_OF_COMMANDS] =
/* put in alphabetical order by command name */
struct cli_cmd_tab_t cli_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" },
{ "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 }
};
 
 
/memtest.h
38,4 → 38,4
datum * memTestDevice(volatile datum * baseAddress, unsigned long nBytes);
 
 
#endif /* _memtest_h */
#endif /* _memtest_h */
/sys_cli.c
6,7 → 6,6
#include <unistd.h>
 
#include "sys_cmd.h"
#include "sys_drivers.h"
#include "sys_error.h"
 
#define ASCII_ESC '\x1b'
13,16 → 12,6
 
 
/*-----------------------------------------------------------*/
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 );
71,6 → 60,8
break;
 
case '\n':
*out_ptr = '\0';
return( NULL );
break;
 
case '\r':
169,40 → 160,41
 
 
/*-----------------------------------------------------------*/
void sys_cli_task( void *pvParameters )
void sys_cli_task( void )
{
char last_return_value = EXIT_SUCCESS;
char in_buffer[16];
char out_buffer[INPUT_LINE_LENGTH];
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 };
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;
iprintf( "\r\n" );
cli_init();
PRINTF_MACRO( "\r\n" );
 
for( ;; )
{
iprintf( "%d > ", last_return_value );
iprintf( "# " );
PRINTF_MACRO( "%d > ", last_return_value );
 
cli_argc = 0;
last_return_value = EXIT_SUCCESS;
 
bytes_read = (unsigned int)read( FD_UART_2, (void *)in_buffer, sizeof(in_buffer) );
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( FD_UART_2, (void *)in_buffer, sizeof(in_buffer) );
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' )
{
iprintf( "\r\n NULL String! Command ignored\r\n" );
PRINTF_MACRO( " NULL String! Command ignored\r\n" );
last_return_value = EXIT_FAILURE;
}
 
211,11 → 203,11
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 );
cli_cmd = cli_find_command( &cmd_to_check );
 
if ( cli_cmd == NULL )
{
iprintf( "\r\nCommand not found!\r\n" );
PRINTF_MACRO( "\r\n Command not found!\r\n" );
last_return_value = EXIT_FAILURE;
break;
}
235,6 → 227,8
}
}
 
PRINTF_MACRO( "\r\n" );
last_return_value = cli_cmd->func( cli_argc, (const char **)cli_argv );
break;
}
/sys_cmd.h
5,25 → 5,29
#define _QAZ_SYS_CMD_H_
 
#define INPUT_LINE_LENGTH 40
#define MAX_CMD_LENGTH 11
#define MAX_CMD_LENGTH 20
#define MAX_CLI_ARGC 6
#define NO_OF_COMMANDS 5
 
#include <xil_printf.h>
 
#define PRINTF_MACRO xil_printf
// #define PRINTF_MACRO iprintf
 
typedef char (*cli_cmd_func)( const unsigned char argc, const char * argv[] );
 
struct cli_cmd_tab_t
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[NO_OF_COMMANDS];
extern struct cli_cmd_tab_t cli_commands[];
 
 
/*-----------------------------------------------------------*/
extern char func_ssp0( const unsigned char argc, const char *argv[] );
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_
/sys_error.c
2,7 → 2,7
 
void sys_error_fatal( unsigned int error )
{
(*( (volatile unsigned int *) (0x8000003c) )) = error; // write to scratch pad reg in FPGA
// (*( (volatile unsigned int *) (0x8000003c) )) = error; // write to scratch pad reg in FPGA
while(1) {};
}
/sys_error.h
1,5 → 1,8
/*-----------------------------------------------------------*/
 
#ifndef _QAZ_SYS_ERROR_H_
#define _QAZ_SYS_ERROR_H_
 
typedef enum
{
FATAL_ERROR_CLI = 0,
10,3 → 13,5
/*-----------------------------------------------------------*/
void sys_error_fatal( unsigned int error );
 
#endif // _QAZ_SYS_ERROR_H_
 

powered by: WebSVN 2.1.0

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