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 24

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

Line No. Rev Author Line
1 24 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27 22 qaztronic
 
28
#include <stdio.h>
29
#include <stdlib.h>
30
#include <string.h>
31
#include "sys_cmd.h"
32
 
33
 
34
/*-----------------------------------------------------------*/
35
static unsigned int cli_no_of_commands;
36
 
37
void cli_init( void )
38
{
39
  int i;
40
 
41
  for(i = 0; cli_commands[i].func != NULL; i++);
42
 
43
  cli_no_of_commands = i;
44
}
45
 
46
 
47
/*-----------------------------------------------------------*/
48
static int cmd_cmp( const void *e1, const void *e2 )
49
{
50
  struct cli_cmd_tab_t *p_cmd_1 = (struct cli_cmd_tab_t *)e1;
51
  struct cli_cmd_tab_t *p_cmd_2 = (struct cli_cmd_tab_t *)e2;
52
 
53
  return strncmp( p_cmd_1->cmd, p_cmd_2->cmd, MAX_CMD_LENGTH );
54
}
55
 
56
 
57
/*-----------------------------------------------------------*/
58
cli_cmd_tab_t *cli_find_command( cli_cmd_tab_t *cmd_to_check )
59
{
60
  struct cli_cmd_tab_t *cli_cmd;
61
 
62
  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 );
63
 
64
  return(cli_cmd);
65
}
66
 
67
 
68
/*-----------------------------------------------------------*/
69
static char func_help( const unsigned char argc, const char *argv[] )
70
{
71
  unsigned int i;
72
 
73
  PRINTF_MACRO( "Usage: cmd <arg1> <arg2> <arg3> ...\r\n" );
74
  PRINTF_MACRO( "\r\n" );
75
  PRINTF_MACRO( "Commands:\r\n" );
76
 
77
  for( i = 0; i < cli_no_of_commands; i++ )
78
    puts( cli_commands[i].help_string );
79
 
80
  return EXIT_SUCCESS;
81
}
82
 
83
 
84
/*-----------------------------------------------------------*/
85
static char func_peek( const unsigned char argc, const char *argv[] )
86
{
87
  volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
88
 
89
  PRINTF_MACRO( "peek: %s => 0x%08x \r\n", argv[1], *address  );
90
 
91
  return EXIT_SUCCESS;
92
}
93
 
94
 
95
/*-----------------------------------------------------------*/
96
static char func_poke( const unsigned char argc, const char *argv[] )
97
{
98
  volatile unsigned int *address  = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
99
  unsigned int value              = strtoul( argv[2], (char **)NULL, 16 );
100
 
101
  *((volatile unsigned int *)address) = value;
102
 
103
  PRINTF_MACRO( "poke: %s <= %s \r\n", argv[1], argv[2]  );
104
 
105
  return EXIT_SUCCESS;
106
}
107
 
108
 
109
/*-----------------------------------------------------------*/
110
#include "memtest.h"
111
 
112
static char func_memtest( const unsigned char argc, const char *argv[] )
113
{
114
  datum *address        = (datum *)( strtoul( argv[1], (char **)NULL, 16 ) );
115
  unsigned long nBytes  = strtoul( argv[2], (char **)NULL, 16 );
116
 
117
  if( argc != 3 || address == NULL || nBytes == 0 )
118
  {
119
    PRINTF_MACRO( "memtest:  bad args \r\n" );
120
    return( EXIT_FAILURE );
121
  }
122
 
123
  PRINTF_MACRO( "running memTestDataBus() ...   " );
124
 
125
  if( memTestDataBus( address ) )
126
    PRINTF_MACRO( "FAILED!!!\r\n" );
127
  else
128
    PRINTF_MACRO( "PASSED\r\n" );
129
 
130
 
131
  PRINTF_MACRO( "running memTestAddressBus() ...   " );
132
 
133
  if( memTestAddressBus( address, nBytes ) )
134
    PRINTF_MACRO( "FAILED!!!\r\n" );
135
  else
136
    PRINTF_MACRO( "PASSED\r\n" );
137
 
138
 
139
  PRINTF_MACRO( "running memTestDevice() ...   " );
140
 
141
  if( memTestDevice( address, nBytes ) )
142
    PRINTF_MACRO( "FAILED!!!\r\n" );
143
  else
144
    PRINTF_MACRO( "PASSED\r\n" );
145
 
146
    return EXIT_SUCCESS;
147
}
148
 
149
 
150
/*-----------------------------------------------------------*/
151
//  command table
152
#include "sys_cmd_table.h"
153
 
154
 

powered by: WebSVN 2.1.0

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