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