-
Notifications
You must be signed in to change notification settings - Fork 9
/
f_vproc.vhd
275 lines (219 loc) · 9.15 KB
/
f_vproc.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
-- =============================================================
--
-- Copyright (c) 2021-2023 Simon Southwell. All rights reserved.
--
-- Date: 4th May 2021
--
-- This file is part of the VProc package.
--
-- VProc is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- VProc is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with VProc. If not, see <http://www.gnu.org/licenses/>.
--
-- =============================================================
-- altera vhdl_input_version vhdl_2008
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.vproc_pkg.all;
entity VProc is
generic (INT_WIDTH : integer := 3;
NODE_WIDTH : integer := 4;
BURST_ADDR_INCR : integer := 1;
DISABLE_DELTA : integer := 0
);
port (
Clk : in std_logic;
Addr : out std_logic_vector(31 downto 0) := 32x"0";
BE : out std_logic_vector( 3 downto 0) := 4x"F";
WE : out std_logic := '0';
RD : out std_logic := '0';
DataOut : out std_logic_vector(31 downto 0);
DataIn : in std_logic_vector(31 downto 0);
WRAck : in std_logic;
RDAck : in std_logic;
Interrupt : in std_logic_vector(INT_WIDTH-1 downto 0);
Update : out std_logic := '0';
UpdateResponse : in std_logic;
Burst : out std_logic_vector(11 downto 0);
BurstFirst : out std_logic;
BurstLast : out std_logic;
Node : in std_logic_vector(NODE_WIDTH-1 downto 0)
);
end;
architecture model of VProc is
constant WEbit : integer := 0;
constant RDbit : integer := 1;
constant BLKHIBIT : integer := 13;
constant BLKLOBIT : integer := 2;
constant BEFIRSTLOBIT : integer := 14;
constant BEFIRSTHIBIT : integer := 17;
constant BELASTLOBIT : integer := 18;
constant BELASTHIBIT : integer := 21;
constant DeltaCycle : integer := -1;
signal Initialised : integer := 0;
signal LBE : std_logic_vector(3 downto 0) := 4x"F";
begin
-- Initial
pINIT : process
begin
-- Don't remove delay! Needed to allow Node to be assigned
wait for 1 ns;
VInit(to_integer(unsigned(Node)));
Initialised <= 1;
wait;
end process;
-- Update process
pUPDATE : process
variable VPDataOut : integer;
variable VPAddr : integer;
variable VPRW : integer;
variable VPTicks : integer;
variable TickVal : integer := 1;
variable BlkCount : integer := 0;
variable AccIdx : integer := 0;
variable DataInSamp : integer;
variable IntSamp : integer;
variable IntSampLast : integer := 0;
variable RdAckSamp : std_logic;
variable WRAckSamp : std_logic;
begin
while true loop
-- Can't have a sensitivity list for the process and process delta cycles in VHDL,
-- so emulate the clock edge with a wait here.
wait until Clk'event and Clk = '1';
-- Cleanly sample the inputs
DataInSamp := to_integer(signed(DataIn));
IntSamp := to_integer(signed("0" & Interrupt));
RdAckSamp := RDAck;
WRAckSamp := WRAck;
VPTicks := DeltaCycle;
if Initialised = 1 then
if IntSamp > 0 then
-- If an interrupt active, call $vsched with interrupt value
VSched(to_integer(unsigned(Node)),
IntSamp,
DataInSamp,
VPDataOut,
VPAddr,
VPRW,
VPTicks);
-- If interrupt routine returns non-zero tick, then override
-- current tick value. Otherwise, leave at present value.
if VPTicks > 0 then
TickVal := VPTicks;
end if;
end if;
-- Call $virq when interrupt value changes, passing in
-- new value
if IntSamp /= IntSampLast then
VIrq(to_integer(unsigned(Node)), IntSamp);
IntSampLast := IntSamp;
end if;
-- If tick, write or a read has completed (or in last cycle)...
if (RD = '0' and WE = '0' and TickVal = 0) or
(RD = '1' and RdAckSamp = '1') or
(WE = '1' and WRAckSamp = '1') then
BurstFirst <= '0';
BurstLast <= '0';
-- Loop accessing new commands until VPTicks is not a delta cycle update
while VPTicks < 0 loop
-- Clear any interrupt (already dealt with)
IntSamp := 0;
-- Sample the data in port
DataInSamp := to_integer(signed(DataIn));
if BlkCount <= 1 then
-- If this is the last transfer in a burst, call $vaccess with
-- the last data input sample.
if BlkCount = 1 then
AccIdx := AccIdx + 1;
VAccess(to_integer(unsigned(Node)),
AccIdx,
DataInSamp,
VPDataOut);
end if;
-- Host process message scheduler called
VSched(to_integer(unsigned(Node)),
IntSamp,
DataInSamp,
VPDataOut,
VPAddr,
VPRW,
VPTicks);
Burst <= std_logic_vector(to_unsigned(VPRW, 32)(BLKHIBIT downto BLKLOBIT));
BE <= std_logic_vector(to_unsigned(VPRW, 32)(BEFIRSTHIBIT downto BEFIRSTLOBIT));
LBE <= std_logic_vector(to_unsigned(VPRW, 32)(BELASTHIBIT downto BELASTLOBIT));
WE <= to_unsigned(VPRW, 32)(WEbit);
RD <= to_unsigned(VPRW, 32)(RDbit);
Addr <= std_logic_vector(to_signed(VPAddr, 32));
BlkCount := to_integer(to_unsigned(VPRW, 32)(BLKHIBIT downto BLKLOBIT));
-- If new BlkCount is non-zero, setup burst transfer
if BlkCount /= 0 then
BurstFirst <= '1';
-- If a single word transfer, set the last flag
if BlkCount = 1 then
BurstLast <= '1';
end if;
-- On writes, override VPDataOut to get from burst access task $VAccess at index 0
if to_unsigned(VPRW, 32)(WEbit) = '1' then
AccIdx := 0;
VAccess(to_integer(unsigned(Node)),
AccIdx,
0,
VPDataOut);
else
AccIdx := -1;
end if;
end if;
-- Update DataOut port
DataOut <= std_logic_vector(to_signed(VPDataOut, 32));
-- If a block access is valid (BlkCount is non-zero), get the next data out/send back latest sample
else
AccIdx := AccIdx + 1;
VAccess(to_integer(unsigned(Node)),
AccIdx,
DataInSamp,
VPDataOut);
DataOut <= std_logic_vector(to_signed(VPDataOut, 32));
Addr <= std_logic_vector(unsigned(Addr) + BURST_ADDR_INCR);
BlkCount := BlkCount - 1;
if BlkCount = 1 then
BurstLast <= '1';
BE <= LBE;
else
BE <= x"F";
end if;
-- When bursting, reassert non-delta VPTicks value to break out of loop.
VPTicks := 0;
end if;
-- Update current tick value with returned number (if not zero)
if VPTicks > 0 then
TickVal := VPTicks - 1;
end if;
-- Flag to update externally and wait for response
Update <= not Update;
if DISABLE_DELTA = 0 then
wait on UpdateResponse;
end if;
end loop;
else
-- Count down to zero and stop
if TickVal > 0 then
TickVal := TickVal - 1;
else
TickVal := 0;
end if;
end if;
end if;
end loop;
end process;
end architecture;