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

Subversion Repositories de1_olpcl2294_system

[/] [de1_olpcl2294_system/] [trunk/] [sw/] [ecos/] [shell/] [dbg_sh.c] - Blame information for rev 7

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

Line No. Rev Author Line
1 7 qaztronic
//
2
//
3
//
4
 
5
#include <stdio.h>
6
#include "LPC22xx.h"
7
 
8
#include <cyg/error/codes.h>
9
#include <cyg/io/io.h>
10
#include <cyg/io/ttyio.h>
11
 
12
// #include <redboot.h>
13
#include "lib_dbg_sh.h"
14
#include "parse.h"
15
 
16
 
17
CYG_HAL_TABLE_BEGIN( __RedBoot_CMD_TAB__, RedBoot_commands );
18
CYG_HAL_TABLE_END( __RedBoot_CMD_TAB_END__, RedBoot_commands );
19
extern struct cmd __RedBoot_CMD_TAB__[], __RedBoot_CMD_TAB_END__;
20
 
21
 
22
//--------------------------------------------------------------------------
23
//  
24
//
25
 
26
#include "memtest.h"
27
 
28
extern datum memTestDataBus(volatile datum *address);
29
extern datum *memTestAddressBus(volatile datum *baseAddress, unsigned long nBytes);
30
extern datum *memTestDevice(volatile datum *baseAddress, unsigned long nBytes);
31
 
32
static void do_memtest (int argc, char *argv[]);
33
RedBoot_cmd ("memtest", "Test Memory", "-b <location> -l <length>", do_memtest);
34
 
35
 
36
static void
37
do_memtest (int argc, char *argv[])
38
{
39
    struct option_info opts[2];
40
    unsigned long location, length, result;
41
    bool location_set, length_set;
42
 
43
    init_opts (&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
44
               &location, &location_set, "location");
45
    init_opts (&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
46
               &length, &length_set, "length");
47
    if (!scan_opts (argc, argv, 1, opts, 2, 0, 0, "")) {
48
        return;
49
    }
50
    if (!location_set) {
51
        printf ("memtest: what location?\n");
52
        return;
53
    }
54
 
55
    if (!length_set) {
56
        printf ("memtest: what length?\n");
57
        return;
58
    }
59
 
60
    result = memTestDataBus( (volatile datum *)location );
61
 
62
    if( result == 0 ) {
63
      printf( "memTestDataBus: passes\n" );
64
    } else {
65
      printf( "memTestDataBus: failed with %x\n", result );
66
      return;
67
    }
68
 
69
    result = memTestAddressBus( (volatile datum *)location, length );
70
 
71
    if( result == NULL ) {
72
      printf( "memTestAddressBus: passes\n" );
73
    } else {
74
      printf( "memTestAddressBus: failed at address %x\n", result );
75
      return;
76
    }
77
 
78
    result = memTestDevice( (volatile datum *)location, length );
79
 
80
    if( result == NULL ) {
81
      printf( "memTestDevice: passes\n" );
82
    } else {
83
      printf( "memTestDevice: failed at address %x\n", result );
84
      return;
85
    }
86
 
87
    printf( "memtest: done\n" );
88
 
89
    return;
90
}
91
 
92
 
93
//--------------------------------------------------------------------------
94
//
95
//
96
RedBoot_cmd("iopeek",
97
            "Read I/O location",
98
            "[-b <location>] [-1|2|4]",
99
            do_iopeek
100
    );
101
RedBoot_cmd("iopoke",
102
            "Write I/O location",
103
            "[-b <location>] [-1|2|4] -v <value>",
104
            do_iopoke
105
    );
106
 
107
void
108
do_iopoke(int argc, char *argv[])
109
{
110
    struct option_info opts[5];
111
    unsigned long base;
112
    bool base_set, value_set;
113
    bool set_32bit = false;
114
    bool set_16bit = false;
115
    bool set_8bit = false;
116
    cyg_uint32 value;
117
    int size = 1;
118
 
119
    init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
120
              &base, &base_set, "base address");
121
    init_opts(&opts[1], 'v', true, OPTION_ARG_TYPE_NUM,
122
              &value, &value_set, "valuex");
123
    init_opts(&opts[2], '4', false, OPTION_ARG_TYPE_FLG,
124
              &set_32bit, 0, "output 32 bit units");
125
    init_opts(&opts[3], '2', false, OPTION_ARG_TYPE_FLG,
126
              &set_16bit, 0, "output 16 bit units");
127
    init_opts(&opts[4], '1', false, OPTION_ARG_TYPE_FLG,
128
              &set_8bit, 0, "output 8 bit units");
129
    if (!scan_opts(argc, argv, 1, opts, 5, 0, 0, "")) {
130
        return;
131
    }
132
    if (!base_set) {
133
        printf("iopoke what <location>?\n");
134
        return;
135
    }
136
    if (!value_set) {
137
        printf("iopoke what <value>?\n");
138
        return;
139
    }
140
    if (set_32bit) {
141
        size = 4;
142
    } else if (set_16bit) {
143
        size = 2;
144
    } else if (set_8bit) {
145
        size = 1;
146
    }
147
 
148
    switch (size) {
149
    case 4:
150
        HAL_WRITE_UINT32 ( base, value );
151
        break;
152
    case 2:
153
        HAL_WRITE_UINT16 ( base, value );
154
        break;
155
    case 1:
156
        HAL_WRITE_UINT8 ( base, value );
157
        break;
158
    }
159
}
160
 
161
void
162
do_iopeek(int argc, char *argv[])
163
{
164
    struct option_info opts[4];
165
    unsigned long base;
166
    bool base_set;
167
    bool set_32bit = false;
168
    bool set_16bit = false;
169
    bool set_8bit = false;
170
    int size = 1, value;
171
 
172
    init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
173
              &base, &base_set, "base address");
174
    init_opts(&opts[1], '4', false, OPTION_ARG_TYPE_FLG,
175
              &set_32bit, 0, "output 32 bit units");
176
    init_opts(&opts[2], '2', false, OPTION_ARG_TYPE_FLG,
177
              &set_16bit, 0, "output 16 bit units");
178
    init_opts(&opts[3], '1', false, OPTION_ARG_TYPE_FLG,
179
              &set_8bit, 0, "output 8 bit units");
180
    if (!scan_opts(argc, argv, 1, opts, 4, 0, 0, "")) {
181
        return;
182
    }
183
    if (!base_set) {
184
        printf("iopeek what <location>?\n");
185
        return;
186
    }
187
    if (set_32bit) {
188
      size = 4;
189
    } else if (set_16bit) {
190
        size = 2;
191
    } else if (set_8bit) {
192
        size = 1;
193
    }
194
 
195
    switch (size) {
196
    case 4:
197
        HAL_READ_UINT32 ( base, value );
198
        printf("0x%04lx = 0x%08x\n", base, value );
199
        break;
200
    case 2:
201
        HAL_READ_UINT16 ( base, value );
202
        printf("0x%04lx = 0x%04x\n", base, value );
203
        break;
204
    case 1:
205
        HAL_READ_UINT8 ( base, value );
206
        printf("0x%04lx = 0x%02x\n", base, value );
207
        break;
208
    }
209
}
210
 
211
 
212
//--------------------------------------------------------------------------
213
//
214
//
215
RedBoot_cmd("help",
216
            "Help about help?",
217
            "[<topic>]",
218
            do_help
219
    );
220
 
221
void
222
show_help(struct cmd *cmd, struct cmd *cmd_end, char *which, char *pre)
223
{
224
    bool show;
225
    int len = 0;
226
 
227
    if (which) {
228
        len = strlen(which);
229
    }
230
    while (cmd != cmd_end) {
231
        show = true;
232
        if (which && (strncasecmp(which, cmd->str, len) != 0)) {
233
            show = false;
234
        }
235
        if (show) {
236
            printf("%s\n  %s %s %s\n", cmd->help, pre, cmd->str, cmd->usage);
237
            if ((cmd->sub_cmds != (struct cmd *)0) && (which != (char *)0)) {
238
                show_help(cmd->sub_cmds, cmd->sub_cmds_end, 0, cmd->str);
239
            }
240
        }
241
        cmd++;
242
    }
243
}
244
 
245
void
246
do_help(int argc, char *argv[])
247
{
248
    struct cmd *cmd;
249
    char *which = (char *)0;
250
 
251
    if (!scan_opts(argc, argv, 1, 0, 0, (void *)&which, OPTION_ARG_TYPE_STR, "<topic>")) {
252
        printf("Invalid argument\n");
253
        return;
254
    }
255
    cmd = __RedBoot_CMD_TAB__;
256
    show_help(cmd, &__RedBoot_CMD_TAB_END__, which, "");
257
    return;
258
}
259
 
260
 
261
void dbg_sh(void)
262
{
263
  char buffer[256];
264
 
265
  char *command;
266
  struct cmd *cmd;
267
 
268
  int argc;
269
  char *argv[16];
270
 
271
  while(1)
272
  {
273
    printf( "dbg_sh> " );
274
 
275
    gets( buffer );
276
    command = buffer;
277
 
278
    if( strlen(command) > 0 )
279
    {
280
      if ((cmd = parse(&command, &argc, &argv[0])) != (struct cmd *)0)
281
      {
282
          (cmd->fun)(argc, argv);
283
      } else
284
      {
285
          printf("** Error: Illegal command: \"%s\"\n", argv[0]);
286
      }
287
    }
288
  }
289
}
290
 
291
 

powered by: WebSVN 2.1.0

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