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

Subversion Repositories simpcon

[/] [simpcon/] [trunk/] [vhdl/] [sc_pack.vhd] - Blame information for rev 29

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 martin
--
2
--
3
--  This file is a part of JOP, the Java Optimized Processor
4
--
5
--  Copyright (C) 2001-2008, Martin Schoeberl (martin@jopdesign.com)
6
--
7
--  This program is free software: you can redistribute it and/or modify
8
--  it under the terms of the GNU General Public License as published by
9
--  the Free Software Foundation, either version 3 of the License, or
10
--  (at your option) any later version.
11
--
12
--  This program is distributed in the hope that it will be useful,
13
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
--  GNU General Public License for more details.
16
--
17
--  You should have received a copy of the GNU General Public License
18
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
 
21
 
22
--
23
--      sc_pack.vhd
24
--
25
--      Package for SimpCon defines
26
--
27
--      Author: Martin Schoeberl (martin@jopdesign.com)
28
--      
29
--
30
--      2007-03-16  first version
31
--
32
--
33
 
34
library std;
35
use std.textio.all;
36
 
37
library ieee;
38
use ieee.std_logic_1164.all;
39
use ieee.numeric_std.all;
40
 
41
package sc_pack is
42
 
43
        -- two more bits than needed for the main memory
44
        --    one to distinguishe between memory and IO access
45
        --    one more to allow memory mirroring for size auto
46
        --        detection at boot time
47
        constant SC_ADDR_SIZE : integer := 23;
48
        constant RDY_CNT_SIZE : integer := 2;
49
 
50
        type sc_out_type is record
51
                address         : std_logic_vector(SC_ADDR_SIZE-1 downto 0);
52
                wr_data         : std_logic_vector(31 downto 0);
53
                rd                      : std_logic;
54
                wr                      : std_logic;
55
                atomic          : std_logic;
56
                nc                      : std_logic;
57
        end record;
58
 
59
        type sc_in_type is record
60
                rd_data         : std_logic_vector(31 downto 0);
61
                rdy_cnt         : unsigned(RDY_CNT_SIZE-1 downto 0);
62
        end record;
63
 
64
        type sc_out_array_type is array (integer range <>) of sc_out_type;
65
        type sc_in_array_type is array (integer range <>) of sc_in_type;
66
 
67
        constant TIMEOUT : integer := 50;
68
 
69
        procedure sc_write(
70
                signal clk : in std_logic;
71
                constant addr : in natural;
72
                constant data : in natural;
73
                signal sc_out : out sc_out_type;
74
                signal sc_in  : in sc_in_type);
75
 
76
        procedure sc_read(
77
                signal clk : in std_logic;
78
                constant addr : in natural;
79
                variable data : out natural;
80
                signal sc_out : out sc_out_type;
81
                signal sc_in  : in sc_in_type);
82
 
83
end sc_pack;
84
 
85
package body sc_pack is
86
 
87
        procedure sc_write(
88
                signal clk : in std_logic;
89
                constant addr : in natural;
90
                constant data : in natural;
91
                signal sc_out : out sc_out_type;
92
                signal sc_in  : in sc_in_type) is
93
 
94
                variable txt : line;
95
 
96
        begin
97
 
98
                write(txt, now, right, 8);
99
                write(txt, string'(" wrote "));
100
                write(txt, data);
101
                write(txt, string'(" to addr. "));
102
                write(txt, addr);
103
 
104
                sc_out.wr_data <= std_logic_vector(to_unsigned(data, sc_out.wr_data'length));
105
                sc_out.address <= std_logic_vector(to_unsigned(addr, sc_out.address'length));
106
                sc_out.wr <= '1';
107
                sc_out.rd <= '0';
108
 
109
                -- one cycle valid
110
                wait until rising_edge(clk);
111
                sc_out.wr_data <= (others => 'X');
112
                sc_out.address <= (others => 'X');
113
                sc_out.wr <= '0';
114
 
115
                for i in 1 to TIMEOUT loop
116
                        wait until rising_edge(clk);
117
                        exit when sc_in.rdy_cnt = "00";
118
                        if (i = TIMEOUT) then
119
                                write (txt, string'("No acknowledge recevied!"));
120
                        end if;
121
                end loop;
122
 
123
                writeline(output, txt);
124
 
125
        end;
126
 
127
        procedure sc_read(
128
                signal clk : in std_logic;
129
                constant addr : in natural;
130
                variable data : out natural;
131
                signal sc_out : out sc_out_type;
132
                signal sc_in  : in sc_in_type) is
133
 
134
                variable txt : line;
135
                variable in_data : natural;
136
 
137
        begin
138
 
139
                write(txt, now, right, 8);
140
                write(txt, string'(" read from addr. "));
141
                write(txt, addr);
142
                writeline(output, txt);
143
 
144
                sc_out.address <= std_logic_vector(to_unsigned(addr, sc_out.address'length));
145
                sc_out.wr_data <= (others => 'X');
146
                sc_out.wr <= '0';
147
                sc_out.rd <= '1';
148
 
149
                -- one cycle valid
150
                wait until rising_edge(clk);
151
                sc_out.address <= (others => 'X');
152
                sc_out.rd <= '0';
153
 
154
                -- wait for acknowledge
155
                for i in 1 to TIMEOUT loop
156
                        wait until rising_edge(clk);
157
                        exit when sc_in.rdy_cnt = "00";
158
                        if (i = TIMEOUT) then
159
                                write (txt, string'("No acknowledge recevied!"));
160
                        end if;
161
                end loop;
162
 
163
                in_data := to_integer(unsigned(sc_in.rd_data));
164
                data := in_data;
165
 
166
                write(txt, now, right, 8);
167
                write(txt, string'(" value: "));
168
                write(txt, in_data);
169
 
170
                writeline(output, txt);
171
 
172
        end;
173
 
174
end sc_pack;

powered by: WebSVN 2.1.0

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