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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [grlib/] [stdlib/] [stdio.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
------------------------------------------------------------------------------
2
--  This file is a part of the GRLIB VHDL IP LIBRARY
3
--  Copyright (C) 2003, Gaisler Research
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This program is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this program; if not, write to the Free Software
17
--  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
18
--------------------------------------------------------------------------------
19
-- Package:       StdIO
20
-- File:          stdio.vhd
21
-- Author:        Gaisler Research
22
-- Description:   Package for common I/O functions
23
--------------------------------------------------------------------------------
24
 
25
-- pragma translate_off
26
library  Std;
27
use      Std.Standard.all;
28
use      Std.TextIO.all;
29
 
30
library  IEEE;
31
use      IEEE.Std_Logic_1164.all;
32
-- pragma translate_on
33
 
34
package StdIO is
35
 
36
-- pragma translate_off
37
   procedure HRead(
38
      variable L:          inout Line;
39
      variable VALUE:      out   Std_ULogic_Vector;
40
      variable GOOD:       out   Boolean);
41
 
42
   procedure HRead(
43
      variable L:          inout Line;
44
      variable VALUE:      out   Std_ULogic_Vector);
45
 
46
   procedure HRead(
47
      variable L:          inout Line;
48
      variable VALUE:      out   Std_Logic_Vector;
49
      variable GOOD:       out   Boolean);
50
 
51
   procedure HRead(
52
      variable L:          inout Line;
53
      variable VALUE:      out   Std_Logic_Vector);
54
 
55
   procedure HWrite(
56
      variable L:          inout Line;
57
      constant VALUE:      in    Std_ULogic_Vector;
58
      constant JUSTIFIED:  in    SIDE  := RIGHT;
59
      constant FIELD:      in    WIDTH := 0);
60
 
61
   procedure HWrite(
62
      variable L:          inout Line;
63
      constant VALUE:      in    Std_Logic_Vector;
64
      constant JUSTIFIED:  in    SIDE  := RIGHT;
65
      constant FIELD:      in    WIDTH := 0);
66
 
67
   procedure Write(
68
      variable L:          inout Line;
69
      constant VALUE:      in    Std_ULogic;
70
      constant JUSTIFIED:  in    SIDE  := RIGHT;
71
      constant FIELD:      in    WIDTH := 0);
72
-- pragma translate_on
73
 
74
end package StdIO;
75
 
76
package body StdIO is
77
-- pragma translate_off
78
 
79
   function ToChar(N: Std_ULogic_Vector(0 to 3)) return Character is
80
   begin
81
     case N is
82
        when "0000"  => return('0');
83
        when "0001"  => return('1');
84
        when "0010"  => return('2');
85
        when "0011"  => return('3');
86
        when "0100"  => return('4');
87
        when "0101"  => return('5');
88
        when "0110"  => return('6');
89
        when "0111"  => return('7');
90
        when "1000"  => return('8');
91
        when "1001"  => return('9');
92
        when "1010"  => return('A');
93
        when "1011"  => return('B');
94
        when "1100"  => return('C');
95
        when "1101"  => return('D');
96
        when "1110"  => return('E');
97
        when "1111"  => return('F');
98
        when others  => return('X');
99
     end case;
100
   end ToChar;
101
 
102
   function FromChar(C: Character) return Std_ULogic_Vector is
103
      variable R:       Std_ULogic_Vector(0 to 3);
104
   begin
105
      case C is
106
         when '0'    => R := "0000";
107
         when '1'    => R := "0001";
108
         when '2'    => R := "0010";
109
         when '3'    => R := "0011";
110
         when '4'    => R := "0100";
111
         when '5'    => R := "0101";
112
         when '6'    => R := "0110";
113
         when '7'    => R := "0111";
114
         when '8'    => R := "1000";
115
         when '9'    => R := "1001";
116
 
117
         when 'A'    => R := "1010";
118
         when 'B'    => R := "1011";
119
         when 'C'    => R := "1100";
120
         when 'D'    => R := "1101";
121
         when 'E'    => R := "1110";
122
         when 'F'    => R := "1111";
123
 
124
         when 'a'    => R := "1010";
125
         when 'b'    => R := "1011";
126
         when 'c'    => R := "1100";
127
         when 'd'    => R := "1101";
128
         when 'e'    => R := "1110";
129
         when 'f'    => R := "1111";
130
         when others => R := "XXXX";
131
      end case;
132
   return R;
133
   end FromChar;
134
 
135
   procedure HRead(
136
      variable L:          inout Line;
137
      variable VALUE:      out   Std_ULogic_Vector;
138
      variable GOOD:       out   Boolean) is
139
 
140
      variable B:                Boolean;
141
      variable C:                Character;
142
      constant SL:               Integer := VALUE'Length;
143
      variable SV:               Std_ULogic_Vector(0 to SL-1);
144
      variable S:                String(1 to SL/4-1);
145
   begin
146
      if VALUE'Length mod 4 /= 0 then
147
         GOOD     := False;
148
         SV       := (others => 'X');
149
         VALUE    := SV;
150
         return;
151
      end if;
152
 
153
      loop
154
         Read(L, C, B);
155
         exit when ((C /= ' ') and (C /= CR) and (C /= HT)) or (not B);
156
      end loop;
157
 
158
      SV(0 to 3) := FromChar(C);
159
      if Is_X(SV(0 to 3)) or (not B) then
160
         GOOD     := False;
161
         SV       := (others => 'X');
162
         VALUE    := SV;
163
         return;
164
      end if;
165
 
166
      Read(L, S, B);
167
      if not B then
168
         GOOD     := False;
169
         SV       := (others => 'X');
170
         VALUE    := SV;
171
         return;
172
      end if;
173
 
174
      for i in 1 to SL/4-1 loop
175
         SV(4*i to 4*i+3) := FromChar(S(i));
176
         if Is_X(SV(4*i to 4*i+3)) then
177
            GOOD     := False;
178
            SV       := (others => 'X');
179
            VALUE    := SV;
180
            return;
181
         end if;
182
      end loop;
183
      GOOD        := True;
184
      VALUE       := SV;
185
   end HRead;
186
 
187
   procedure HRead(
188
      variable L:          inout Line;
189
      variable VALUE:      out   Std_ULogic_Vector) is
190
      variable GOOD:             Boolean;
191
   begin
192
      HRead(L, VALUE, GOOD);
193
      assert GOOD
194
         report "HREAD: access incorrect";
195
   end HRead;
196
 
197
   procedure HRead(
198
      variable L:          inout Line;
199
      variable VALUE:      out   Std_Logic_Vector;
200
      variable GOOD:       out   Boolean) is
201
      variable V:                Std_ULogic_Vector(0 to Value'Length-1);
202
   begin
203
      HRead(L, V, GOOD);
204
      VALUE := Std_Logic_Vector(V);
205
   end HRead;
206
 
207
   procedure HRead(
208
      variable L:          inout Line;
209
      variable VALUE:      out   Std_Logic_Vector) is
210
      variable GOOD:             Boolean;
211
      variable V:                Std_ULogic_Vector(0 to Value'Length-1);
212
   begin
213
      HRead(L, V, GOOD);
214
      VALUE := Std_Logic_Vector(V);
215
      assert GOOD
216
         report "HREAD: access incorrect";
217
   end HRead;
218
 
219
   procedure HWrite(
220
      variable L:          inout Line;
221
      constant VALUE:      in    Std_ULogic_Vector;
222
      constant JUSTIFIED:  in    SIDE     := RIGHT;
223
      constant FIELD:      in    WIDTH    := 0) is
224
 
225
      constant PL:               Integer  := 4-(VALUE'Length mod 4);
226
      constant PV:               Std_ULogic_Vector(1 to PL) := (others => '0');
227
      constant TL:               Integer  := PL + VALUE'Length;
228
      constant TV:               Std_ULogic_Vector(0 to TL-1) := PV & Value;
229
      variable S:                String(1 to TL/4);
230
   begin
231
      if PL /= 4 then
232
         for i in 0 to TL/4 -1 loop
233
            S(i+1) :=  ToChar(TV(4*i to 4*i+3));
234
         end loop;
235
         Write(L, S(1 to TL/4), JUSTIFIED, FIELD);
236
      else
237
         for i in 1 to TL/4 -1 loop
238
            S(i+1) :=  ToChar(TV(4*i to 4*i+3));
239
         end loop;
240
         Write(L, S(2 to TL/4), JUSTIFIED, FIELD);
241
      end if;
242
   end HWrite;
243
 
244
   procedure HWrite(
245
      variable L:          inout Line;
246
      constant VALUE:      in    Std_Logic_Vector;
247
      constant JUSTIFIED:  in    SIDE  := RIGHT;
248
      constant FIELD:      in    WIDTH := 0) is
249
   begin
250
      HWrite(L, Std_ULogic_Vector(VALUE), JUSTIFIED, FIELD);
251
   end HWrite;
252
 
253
   procedure Write(
254
      variable L:          inout Line;
255
      constant VALUE:      in    Std_ULogic;
256
      constant JUSTIFIED:  in    SIDE  := RIGHT;
257
      constant FIELD:      in    WIDTH := 0) is
258
 
259
   type     Char_Array  is array (Std_ULogic) of Character;
260
      constant ToChar:           Char_Array := "UX01ZWLH-";
261
   begin
262
      Write(L, ToChar(VALUE), JUSTIFIED, FIELD);
263
   end Write;
264
 
265
-- pragma translate_on
266
end package body StdIO;

powered by: WebSVN 2.1.0

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