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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [redboot/] [current/] [src/] [iomem.c] - Blame information for rev 856

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      iomem.c
4
//
5
//      RedBoot I/O memory peek and poke
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2004 Free Software Foundation, Inc.                        
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    icampbell
43
// Contributors: icampbell
44
// Date:         2004-11-09
45
// Purpose:      
46
// Description:  
47
//              
48
// This code is part of RedBoot (tm).
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <redboot.h>
55
#include <cyg/hal/hal_io.h>
56
 
57
RedBoot_cmd("iopeek",
58
            "Read I/O location",
59
            "[-b <location>] [-1|2|4]",
60
            do_iopeek
61
    );
62
RedBoot_cmd("iopoke",
63
            "Write I/O location",
64
            "[-b <location>] [-1|2|4] -v <value>",
65
            do_iopoke
66
    );
67
 
68
void
69
do_iopoke(int argc, char *argv[])
70
{
71
    struct option_info opts[5];
72
    unsigned long base;
73
    bool base_set, value_set;
74
    bool set_32bit = false;
75
    bool set_16bit = false;
76
    bool set_8bit = false;
77
    cyg_uint32 value;
78
    int size = 1;
79
 
80
    init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
81
              &base, &base_set, "base address");
82
    init_opts(&opts[1], 'v', true, OPTION_ARG_TYPE_NUM,
83
              &value, &value_set, "valuex");
84
    init_opts(&opts[2], '4', false, OPTION_ARG_TYPE_FLG,
85
              &set_32bit, 0, "output 32 bit units");
86
    init_opts(&opts[3], '2', false, OPTION_ARG_TYPE_FLG,
87
              &set_16bit, 0, "output 16 bit units");
88
    init_opts(&opts[4], '1', false, OPTION_ARG_TYPE_FLG,
89
              &set_8bit, 0, "output 8 bit units");
90
    if (!scan_opts(argc, argv, 1, opts, 5, 0, 0, "")) {
91
        return;
92
    }
93
    if (!base_set) {
94
        diag_printf("iopoke what <location>?\n");
95
        return;
96
    }
97
    if (!value_set) {
98
        diag_printf("iopoke what <value>?\n");
99
        return;
100
    }
101
    if (set_32bit) {
102
        size = 4;
103
    } else if (set_16bit) {
104
        size = 2;
105
    } else if (set_8bit) {
106
        size = 1;
107
    }
108
 
109
    switch (size) {
110
    case 4:
111
        HAL_WRITE_UINT32 ( base, value );
112
        break;
113
    case 2:
114
        HAL_WRITE_UINT16 ( base, value );
115
        break;
116
    case 1:
117
        HAL_WRITE_UINT8 ( base, value );
118
        break;
119
    }
120
}
121
 
122
void
123
do_iopeek(int argc, char *argv[])
124
{
125
    struct option_info opts[4];
126
    unsigned long base;
127
    bool base_set;
128
    bool set_32bit = false;
129
    bool set_16bit = false;
130
    bool set_8bit = false;
131
    int size = 1, value;
132
 
133
    init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
134
              &base, &base_set, "base address");
135
    init_opts(&opts[1], '4', false, OPTION_ARG_TYPE_FLG,
136
              &set_32bit, 0, "output 32 bit units");
137
    init_opts(&opts[2], '2', false, OPTION_ARG_TYPE_FLG,
138
              &set_16bit, 0, "output 16 bit units");
139
    init_opts(&opts[3], '1', false, OPTION_ARG_TYPE_FLG,
140
              &set_8bit, 0, "output 8 bit units");
141
    if (!scan_opts(argc, argv, 1, opts, 4, 0, 0, "")) {
142
        return;
143
    }
144
    if (!base_set) {
145
        diag_printf("iopeek what <location>?\n");
146
        return;
147
    }
148
    if (set_32bit) {
149
      size = 4;
150
    } else if (set_16bit) {
151
        size = 2;
152
    } else if (set_8bit) {
153
        size = 1;
154
    }
155
 
156
    switch (size) {
157
    case 4:
158
        HAL_READ_UINT32 ( base, value );
159
        diag_printf("0x%04lx = 0x%08x\n", base, value );
160
        break;
161
    case 2:
162
        HAL_READ_UINT16 ( base, value );
163
        diag_printf("0x%04lx = 0x%04x\n", base, value );
164
        break;
165
    case 1:
166
        HAL_READ_UINT8 ( base, value );
167
        diag_printf("0x%04lx = 0x%02x\n", base, value );
168
        break;
169
    }
170
}

powered by: WebSVN 2.1.0

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