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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [cli/] [cli/] [sys_cmd.c] - Blame information for rev 22

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

Line No. Rev Author Line
1 22 qaztronic
/*-----------------------------------------------------------*/
2
 
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
#include "sys_cmd.h"
7
 
8
 
9
/*-----------------------------------------------------------*/
10
static unsigned int cli_no_of_commands;
11
 
12
void cli_init( void )
13
{
14
  int i;
15
 
16
  for(i = 0; cli_commands[i].func != NULL; i++);
17
 
18
  cli_no_of_commands = i;
19
}
20
 
21
 
22
/*-----------------------------------------------------------*/
23
static int cmd_cmp( const void *e1, const void *e2 )
24
{
25
  struct cli_cmd_tab_t *p_cmd_1 = (struct cli_cmd_tab_t *)e1;
26
  struct cli_cmd_tab_t *p_cmd_2 = (struct cli_cmd_tab_t *)e2;
27
 
28
  return strncmp( p_cmd_1->cmd, p_cmd_2->cmd, MAX_CMD_LENGTH );
29
}
30
 
31
 
32
/*-----------------------------------------------------------*/
33
cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check )
34
{
35
  struct cli_cmd_tab_t *cli_cmd;
36
 
37
  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 );
38
 
39
  return(cli_cmd);
40
}
41
 
42
 
43
/*-----------------------------------------------------------*/
44
static char func_help( const unsigned char argc, const char *argv[] )
45
{
46
  unsigned int i;
47
 
48
  PRINTF_MACRO( "Usage: cmd <arg1> <arg2> <arg3> ...\r\n" );
49
  PRINTF_MACRO( "\r\n" );
50
  PRINTF_MACRO( "Commands:\r\n" );
51
 
52
  for( i = 0; i < cli_no_of_commands; i++ )
53
    puts( cli_commands[i].help_string );
54
 
55
  return EXIT_SUCCESS;
56
}
57
 
58
 
59
/*-----------------------------------------------------------*/
60
static char func_peek( const unsigned char argc, const char *argv[] )
61
{
62
  volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
63
 
64
  PRINTF_MACRO( "peek: %s => 0x%08x \r\n", argv[1], *address  );
65
 
66
  return EXIT_SUCCESS;
67
}
68
 
69
 
70
/*-----------------------------------------------------------*/
71
static char func_poke( const unsigned char argc, const char *argv[] )
72
{
73
  volatile unsigned int *address  = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
74
  unsigned int value              = strtoul( argv[2], (char **)NULL, 16 );
75
 
76
  *((volatile unsigned int *)address) = value;
77
 
78
  PRINTF_MACRO( "poke: %s <= %s \r\n", argv[1], argv[2]  );
79
 
80
  return EXIT_SUCCESS;
81
}
82
 
83
 
84
/*-----------------------------------------------------------*/
85
#include "memtest.h"
86
 
87
static char func_memtest( const unsigned char argc, const char *argv[] )
88
{
89
  datum *address        = (datum *)( strtoul( argv[1], (char **)NULL, 16 ) );
90
  unsigned long nBytes  = strtoul( argv[2], (char **)NULL, 16 );
91
 
92
  if( argc != 3 || address == NULL || nBytes == 0 )
93
  {
94
    PRINTF_MACRO( "memtest:  bad args \r\n" );
95
    return( EXIT_FAILURE );
96
  }
97
 
98
  PRINTF_MACRO( "running memTestDataBus() ...   " );
99
 
100
  if( memTestDataBus( address ) )
101
    PRINTF_MACRO( "FAILED!!!\r\n" );
102
  else
103
    PRINTF_MACRO( "PASSED\r\n" );
104
 
105
 
106
  PRINTF_MACRO( "running memTestAddressBus() ...   " );
107
 
108
  if( memTestAddressBus( address, nBytes ) )
109
    PRINTF_MACRO( "FAILED!!!\r\n" );
110
  else
111
    PRINTF_MACRO( "PASSED\r\n" );
112
 
113
 
114
  PRINTF_MACRO( "running memTestDevice() ...   " );
115
 
116
  if( memTestDevice( address, nBytes ) )
117
    PRINTF_MACRO( "FAILED!!!\r\n" );
118
  else
119
    PRINTF_MACRO( "PASSED\r\n" );
120
 
121
    return EXIT_SUCCESS;
122
}
123
 
124
 
125
/*-----------------------------------------------------------*/
126
//  command table
127
#include "sys_cmd_table.h"
128
 
129
 

powered by: WebSVN 2.1.0

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