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 36

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 28 qaztronic
 
41 22 qaztronic
  for(i = 0; cli_commands[i].func != NULL; i++);
42 28 qaztronic
 
43 22 qaztronic
  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 28 qaztronic
 
62 22 qaztronic
  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 28 qaztronic
static char func_comment( const unsigned char argc, const char *argv[] )
86
{
87
  PRINTF_MACRO( "# > ");
88
  return EXIT_SUCCESS;
89
}
90
 
91
 
92
/*-----------------------------------------------------------*/
93 22 qaztronic
static char func_peek( const unsigned char argc, const char *argv[] )
94
{
95
  volatile unsigned int *address = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
96
 
97
  PRINTF_MACRO( "peek: %s => 0x%08x \r\n", argv[1], *address  );
98
 
99
  return EXIT_SUCCESS;
100
}
101
 
102
 
103
/*-----------------------------------------------------------*/
104
static char func_poke( const unsigned char argc, const char *argv[] )
105
{
106
  volatile unsigned int *address  = (volatile unsigned int *)( strtoul( argv[1], (char **)NULL, 16 ) );
107
  unsigned int value              = strtoul( argv[2], (char **)NULL, 16 );
108
 
109
  *((volatile unsigned int *)address) = value;
110
 
111
  PRINTF_MACRO( "poke: %s <= %s \r\n", argv[1], argv[2]  );
112
 
113
  return EXIT_SUCCESS;
114
}
115
 
116
 
117
/*-----------------------------------------------------------*/
118
#include "memtest.h"
119
 
120
static char func_memtest( const unsigned char argc, const char *argv[] )
121
{
122
  datum *address        = (datum *)( strtoul( argv[1], (char **)NULL, 16 ) );
123
  unsigned long nBytes  = strtoul( argv[2], (char **)NULL, 16 );
124
 
125
  if( argc != 3 || address == NULL || nBytes == 0 )
126
  {
127
    PRINTF_MACRO( "memtest:  bad args \r\n" );
128
    return( EXIT_FAILURE );
129
  }
130
 
131
  PRINTF_MACRO( "running memTestDataBus() ...   " );
132
 
133
  if( memTestDataBus( address ) )
134
    PRINTF_MACRO( "FAILED!!!\r\n" );
135
  else
136
    PRINTF_MACRO( "PASSED\r\n" );
137
 
138
 
139
  PRINTF_MACRO( "running memTestAddressBus() ...   " );
140
 
141
  if( memTestAddressBus( address, nBytes ) )
142
    PRINTF_MACRO( "FAILED!!!\r\n" );
143
  else
144
    PRINTF_MACRO( "PASSED\r\n" );
145
 
146
 
147
  PRINTF_MACRO( "running memTestDevice() ...   " );
148
 
149
  if( memTestDevice( address, nBytes ) )
150
    PRINTF_MACRO( "FAILED!!!\r\n" );
151
  else
152
    PRINTF_MACRO( "PASSED\r\n" );
153
 
154
    return EXIT_SUCCESS;
155
}
156
 
157
 
158
/*-----------------------------------------------------------*/
159
//  command table
160
#include "sys_cmd_table.h"
161
 
162
 

powered by: WebSVN 2.1.0

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