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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [cli/] [util/] [util_mem.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 "util_mem.h"
4
 
5
 
6
/*-----------------------------------------------------------*/
7
 
8
/* Display values from last command.
9
 * Memory modify remembered values are different from display memory.
10
 */
11
static ulong    dp_last_addr, dp_last_size;
12
static ulong    dp_last_length = 0x40;
13
// static ulong mm_last_addr, mm_last_size;
14
 
15
static  ulong   base_address = 0;
16
 
17
/* Memory Display
18
 *
19
 * Syntax:
20
 *      md{.b, .w, .l, .q} {addr} {len}
21
 */
22
#define DISP_LINE_LEN   16
23
static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, const char * argv[])
24
{
25
        ulong   addr, length;
26
#if defined(CONFIG_HAS_DATAFLASH)
27
        ulong   nbytes, linebytes;
28
#endif
29
        int     size;
30
        int rc = 0;
31
 
32
        /* We use the last specified parameters, unless new ones are
33
         * entered.
34
         */
35
        addr = dp_last_addr;
36
        size = dp_last_size;
37
        length = dp_last_length;
38
 
39
        if (argc < 2)
40
                return CMD_RET_USAGE;
41
 
42
        if ((flag & CMD_FLAG_REPEAT) == 0) {
43
                /* New command specified.  Check for a size specification.
44
                 * Defaults to long if no or incorrect specification.
45
                 */
46
                if ((size = cmd_get_data_size(argv[0], 4)) < 0)
47
                        return 1;
48
 
49
                /* Address is specified since argc > 1
50
                */
51
                addr = simple_strtoul(argv[1], NULL, 16);
52
                addr += base_address;
53
 
54
                /* If another parameter, it is the length to display.
55
                 * Length is the number of objects, not number of bytes.
56
                 */
57
                if (argc > 2)
58
                        length = simple_strtoul(argv[2], NULL, 16);
59
        }
60
 
61
#if defined(CONFIG_HAS_DATAFLASH)
62
        /* Print the lines.
63
         *
64
         * We buffer all read data, so we can make sure data is read only
65
         * once, and all accesses are with the specified bus width.
66
         */
67
        nbytes = length * size;
68
        do {
69
                char    linebuf[DISP_LINE_LEN];
70
                void* p;
71
                linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
72
 
73
                rc = read_dataflash(addr, (linebytes/size)*size, linebuf);
74
                p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr;
75
                print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size);
76
 
77
                nbytes -= linebytes;
78
                addr += linebytes;
79
                if (ctrlc()) {
80
                        rc = 1;
81
                        break;
82
                }
83
        } while (nbytes > 0);
84
#else
85
 
86
# if defined(CONFIG_BLACKFIN)
87
        /* See if we're trying to display L1 inst */
88
        if (addr_bfin_on_chip_mem(addr)) {
89
                char linebuf[DISP_LINE_LEN];
90
                ulong linebytes, nbytes = length * size;
91
                do {
92
                        linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
93
                        memcpy(linebuf, (void *)addr, linebytes);
94
                        print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size);
95
 
96
                        nbytes -= linebytes;
97
                        addr += linebytes;
98
                        if (ctrlc()) {
99
                                rc = 1;
100
                                break;
101
                        }
102
                } while (nbytes > 0);
103
        } else
104
# endif
105
 
106
        {
107
                ulong bytes = size * length;
108
                const void *buf = map_sysmem(addr, bytes);
109
 
110
                /* Print the lines. */
111
                print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
112
                addr += bytes;
113
                unmap_sysmem(buf);
114
        }
115
#endif
116
 
117
        dp_last_addr = addr;
118
        dp_last_length = length;
119
        dp_last_size = size;
120
        return (rc);
121
}
122
 
123
 
124
/*-----------------------------------------------------------*/
125
static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, const char * argv[])
126
{
127
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
128
        u64 writeval;
129
#else
130
        ulong writeval;
131
#endif
132
        ulong   addr, count;
133
        int     size;
134
        void *buf, *start;
135
        ulong bytes;
136
 
137
        if ((argc < 3) || (argc > 4))
138
                return CMD_RET_USAGE;
139
 
140
        /* Check for size specification.
141
        */
142
        if ((size = cmd_get_data_size(argv[0], 4)) < 1)
143
                return 1;
144
 
145
        /* Address is specified since argc > 1
146
        */
147
        addr = simple_strtoul(argv[1], NULL, 16);
148
        addr += base_address;
149
 
150
        /* Get the value to write.
151
        */
152
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
153
        writeval = simple_strtoull(argv[2], NULL, 16);
154
#else
155
        writeval = simple_strtoul(argv[2], NULL, 16);
156
#endif
157
 
158
        /* Count ? */
159
        if (argc == 4) {
160
                count = simple_strtoul(argv[3], NULL, 16);
161
        } else {
162
                count = 1;
163
        }
164
 
165
        bytes = size * count;
166
        start = map_sysmem(addr, bytes);
167
        buf = start;
168
        while (count-- > 0) {
169
                if (size == 4)
170
                        *((u32 *)buf) = (u32)writeval;
171
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
172
                else if (size == 8)
173
                        *((u64 *)buf) = (u64)writeval;
174
#endif
175
                else if (size == 2)
176
                        *((u16 *)buf) = (u16)writeval;
177
                else
178
                        *((u8 *)buf) = (u8)writeval;
179
                buf += size;
180
        }
181
        unmap_sysmem(start);
182
        return 0;
183
}
184
 
185
 
186
/*-----------------------------------------------------------*/
187
char func_mw( const unsigned char argc, const char *argv[] )
188
{
189
  return do_mem_mw(0, 0, argc, argv);
190
}
191
 
192
 
193
/*-----------------------------------------------------------*/
194
char func_md( const unsigned char argc, const char *argv[] )
195
{
196
  return do_mem_md(0, 0, argc, argv);
197
}
198
 
199
 
200
 
201
 
202
 
203
 

powered by: WebSVN 2.1.0

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