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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [VHDL/] [queue/] [queue.vhdl] - Blame information for rev 24

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

Line No. Rev Author Line
1 2 lcdsgmtr
-- Copyright 2015, Jürgen Defurne
2
--
3
-- This file is part of the Experimental Unstable CPU System.
4
--
5
-- The Experimental Unstable CPU System Is free software: you can redistribute
6
-- it and/or modify it under the terms of the GNU Lesser General Public License
7
-- as published by the Free Software Foundation, either version 3 of the
8
-- License, or (at your option) any later version.
9
--
10
-- The Experimental Unstable CPU System is distributed in the hope that it will
11
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
13
-- General Public License for more details.
14
--
15
-- You should have received a copy of the GNU Lesser General Public License
16
-- along with Experimental Unstable CPU System. If not, see
17
-- http://www.gnu.org/licenses/lgpl.txt.
18
 
19
 
20
LIBRARY ieee;
21
USE ieee.std_logic_1164.ALL;
22
USE ieee.numeric_std.ALL;
23
 
24
ENTITY queue IS
25
 
26
  PORT (
27
    data_in  : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);
28
    data_out : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
29
    clock    : IN  STD_LOGIC;
30
    wr       : IN  STD_LOGIC;
31
    sh       : IN  STD_LOGIC;
32
    reset    : IN  STD_LOGIC);
33
 
34
END queue;
35
 
36
ARCHITECTURE Behavioral OF queue IS
37
 
38
  -- Datapath declarations
39
 
40
  TYPE queue_t IS ARRAY (0 TO 3) OF STD_LOGIC_VECTOR(7 DOWNTO 0);
41
 
42
  SIGNAL queue : queue_t;
43
 
44
  -- Control path declarations
45
 
46
  SUBTYPE cntr_t IS INTEGER RANGE 0 TO 4;
47
 
48
  SIGNAL i      : cntr_t := 0;
49
  SIGNAL i_next : cntr_t := 0;
50
 
51
BEGIN  -- Behavioral
52
 
53
  -- Datapath
54
 
55
  -- Control path
56
  -- purpose: Control the queue
57
  -- type   : sequential
58
  -- inputs : clock, reset, wr
59
  -- outputs: 
60
  control : PROCESS (clock, reset)
61
  BEGIN  -- PROCESS control
62
    IF rising_edge(clock) THEN          -- rising clock edge
63
      IF reset = '1' THEN               -- synchronous reset (active high)
64
        i <= 0;
65
      ELSE
66
        i <= i_next;
67
      END IF;
68
    END IF;
69
  END PROCESS control;
70
 
71
  -- purpose: Implement the queue
72
  -- type   : sequential
73
  -- inputs : clock, reset, wr, sh
74
  -- outputs: out
75
  data: PROCESS (clock, reset)
76
  BEGIN  -- PROCESS data
77
    IF rising_edge(clock) THEN  -- rising clock edge
78
      CASE i IS
79
        WHEN 0 =>
80
          IF wr = '1' AND sh = '0' THEN
81
            queue(3) <= queue(3);
82
            queue(2) <= queue(2);
83
            queue(1) <= queue(1);
84
            queue(0) <= data_in;
85
            i_next   <= 1;
86
          ELSIF wr = '0' AND sh = '1' THEN
87
            queue(3) <= data_in;
88
            queue(2) <= queue(3);
89
            queue(1) <= queue(2);
90
            queue(0) <= queue(1);
91
            i_next   <= 0;
92
          ELSIF wr = '1' AND sh = '1' THEN
93
            queue(3) <= data_in;
94
            queue(2) <= queue(3);
95
            queue(1) <= queue(2);
96
            queue(0) <= queue(1);
97
            i_next   <= 0;
98
          ELSE
99
            queue(3) <= queue(3);
100
            queue(2) <= queue(2);
101
            queue(1) <= queue(1);
102
            queue(0) <= queue(0);
103
            i_next   <= 0;
104
          END IF;
105
        WHEN 1 =>
106
          IF wr = '1' AND sh = '0' THEN
107
            queue(3) <= queue(3);
108
            queue(2) <= queue(2);
109
            queue(1) <= data_in;
110
            queue(0) <= queue(0);
111
            i_next   <= 2;
112
          ELSIF wr = '0' AND sh = '1' THEN
113
            queue(3) <= data_in;
114
            queue(2) <= queue(3);
115
            queue(1) <= queue(2);
116
            queue(0) <= queue(1);
117
            i_next   <= 0;
118
          ELSIF wr = '1' AND sh = '1' THEN
119
            queue(3) <= queue(3);
120
            queue(2) <= queue(2);
121
            queue(1) <= queue(1);
122
            queue(0) <= data_in;
123
            i_next   <= 1;
124
          ELSE
125
            queue(3) <= queue(3);
126
            queue(2) <= queue(2);
127
            queue(1) <= queue(1);
128
            queue(0) <= queue(0);
129
            i_next   <= 1;
130
          END IF;
131
        WHEN 2 =>
132
          IF wr = '1' AND sh = '0' THEN
133
            queue(3) <= queue(3);
134
            queue(2) <= data_in;
135
            queue(1) <= queue(1);
136
            queue(0) <= queue(0);
137
            i_next   <= 3;
138
          ELSIF wr = '0' AND sh = '1' THEN
139
            queue(3) <= data_in;
140
            queue(2) <= queue(3);
141
            queue(1) <= queue(2);
142
            queue(0) <= queue(1);
143
            i_next   <= 1;
144
          ELSIF wr = '1' AND sh = '1' THEN
145
            queue(3) <= data_in;
146
            queue(2) <= queue(3);
147
            queue(1) <= data_in;
148
            queue(0) <= queue(1);
149
            i_next   <= 2;
150
          ELSE
151
            queue(3) <= queue(3);
152
            queue(2) <= queue(2);
153
            queue(1) <= queue(1);
154
            queue(0) <= queue(0);
155
            i_next   <= 2;
156
          END IF;
157
        WHEN 3 =>
158
          IF wr = '1' AND sh = '0' THEN
159
            queue(3) <= data_in;
160
            queue(2) <= queue(2);
161
            queue(1) <= queue(1);
162
            queue(0) <= queue(0);
163
            i_next   <= 4;
164
          ELSIF wr = '0' AND sh = '1' THEN
165
            queue(3) <= data_in;
166
            queue(2) <= queue(3);
167
            queue(1) <= queue(2);
168
            queue(0) <= queue(1);
169
            i_next   <= 2;
170
          ELSIF wr = '1' AND sh = '1' THEN
171
            queue(3) <= data_in;
172
            queue(2) <= data_in;
173
            queue(1) <= queue(2);
174
            queue(0) <= queue(1);
175
            i_next   <= 3;
176
          ELSE
177
            queue(3) <= queue(3);
178
            queue(2) <= queue(2);
179
            queue(1) <= queue(1);
180
            queue(0) <= queue(0);
181
            i_next   <= 3;
182
          END IF;
183
        WHEN 4 =>
184
          IF wr = '1' AND sh = '0' THEN
185
            queue(3) <= data_in;
186
            queue(2) <= queue(3);
187
            queue(1) <= queue(2);
188
            queue(0) <= queue(1);
189
            i_next   <= 4;
190
          ELSIF wr = '0' AND sh = '1' THEN
191
            queue(3) <= data_in;
192
            queue(2) <= queue(3);
193
            queue(1) <= queue(2);
194
            queue(0) <= queue(1);
195
            i_next   <= 3;
196
          ELSIF wr = '1' AND sh = '1' THEN
197
            queue(3) <= data_in;
198
            queue(2) <= queue(3);
199
            queue(1) <= queue(2);
200
            queue(0) <= queue(1);
201
            i_next   <= 4;
202
          ELSE
203
            queue(3) <= queue(3);
204
            queue(2) <= queue(2);
205
            queue(1) <= queue(1);
206
            queue(0) <= queue(0);
207
            i_next   <= 4;
208
          END IF;
209
      END CASE;
210
    END IF;
211
  END PROCESS data;
212
 
213
  data_out <= queue(0);
214
 
215
END Behavioral;

powered by: WebSVN 2.1.0

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