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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [cli/] [cli/] [sys_cmd.c] - Rev 22

Go to most recent revision | Compare with Previous | Blame | View Log

/*-----------------------------------------------------------*/
 
#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;
}
 
 
/*-----------------------------------------------------------*/
//  command table
#include "sys_cmd_table.h"
 
 
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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