1 |
8 |
barryw |
--Propery of Tecphos Inc. See WrimmLicense.txt for license details
|
2 |
|
|
--Latest version of all Wrimm project files available at http://opencores.org/project,wrimm
|
3 |
3 |
barryw |
--See WrimmManual.pdf for the Wishbone Datasheet and implementation details.
|
4 |
|
|
--See wrimm subversion project for version history
|
5 |
|
|
|
6 |
|
|
library ieee;
|
7 |
4 |
barryw |
use ieee.std_logic_1164.all;
|
8 |
6 |
barryw |
use ieee.numeric_std.all;
|
9 |
3 |
barryw |
|
10 |
6 |
barryw |
use work.WrimmPackage.all;
|
11 |
|
|
|
12 |
4 |
barryw |
entity Wrimm is
|
13 |
|
|
port (
|
14 |
|
|
WbClk : in std_logic;
|
15 |
|
|
WbRst : out std_logic;
|
16 |
3 |
barryw |
|
17 |
4 |
barryw |
WbMasterIn : in WbMasterOutArray; --Signals from Masters
|
18 |
|
|
WbMasterOut : out WbSlaveOutArray; --Signals to Masters
|
19 |
|
|
|
20 |
|
|
--WbSlaveIn : out WbMasterOutArray;
|
21 |
|
|
--WbSlaveOut : in WbSlaveOutArray;
|
22 |
|
|
|
23 |
|
|
StatusRegs : in StatusArrayType;
|
24 |
|
|
|
25 |
|
|
SettingRegs : out SettingArrayType;
|
26 |
|
|
SettingRsts : in SettingArrayBitType;
|
27 |
|
|
|
28 |
|
|
Triggers : out TriggerArrayType;
|
29 |
|
|
TriggerClr : in TriggerArrayType;
|
30 |
|
|
|
31 |
|
|
rstZ : in std_logic); --Asynchronous reset
|
32 |
|
|
end entity Wrimm;
|
33 |
|
|
|
34 |
|
|
architecture behavior of Wrimm is
|
35 |
|
|
signal wbStrobe : std_logic; --Internal Wishbone signals
|
36 |
|
|
signal validAddress : std_logic;
|
37 |
|
|
signal wbAddr : WbAddrType;
|
38 |
|
|
signal wbSData,wbMData : WbDataType;
|
39 |
|
|
signal wbWrEn,wbCyc : std_logic;
|
40 |
|
|
signal wbAck,wbRty,wbErr : std_logic;
|
41 |
|
|
--signal wbMDataTag : std_logic_vector(0 to 1);
|
42 |
|
|
--signal wbCycType : std_logic_vector(0 to 2);
|
43 |
|
|
|
44 |
|
|
signal iSettingRegs : SettingArrayType;
|
45 |
|
|
signal iTriggers : TriggerArrayType;
|
46 |
|
|
signal statusEnable : StatusArrayBitType;
|
47 |
|
|
signal settingEnable : SettingArrayBitType;
|
48 |
|
|
signal triggerEnable : TriggerArrayType;
|
49 |
|
|
signal grant : WbMasterGrantType;
|
50 |
|
|
|
51 |
3 |
barryw |
begin
|
52 |
4 |
barryw |
SettingRegs <= iSettingRegs;
|
53 |
|
|
Triggers <= iTriggers;
|
54 |
3 |
barryw |
|
55 |
|
|
--=============================================================================
|
56 |
|
|
-------------------------------------------------------------------------------
|
57 |
4 |
barryw |
-- Master Round Robin Arbitration
|
58 |
3 |
barryw |
-------------------------------------------------------------------------------
|
59 |
4 |
barryw |
procArb: process(WbClk,rstZ) is --Round robin arbitration (descending)
|
60 |
|
|
variable vGrant : WbMasterGrantType;
|
61 |
|
|
begin
|
62 |
|
|
if (rstZ='0') then
|
63 |
6 |
barryw |
vGrant := (Others=>'0');
|
64 |
|
|
vGrant(vGrant'left) := '1';
|
65 |
4 |
barryw |
elsif rising_edge(WbClk) then
|
66 |
|
|
loopGrant: for i in WbMasterType loop
|
67 |
|
|
if vGrant(i)='1' and WbMasterIn(i).Cyc='0' then --else maintain grant
|
68 |
|
|
loopNewGrantA: for j in i to WbMasterType'right loop --last master with cyc=1 will be selected
|
69 |
|
|
if WbMasterIn(j).Cyc='1' then
|
70 |
|
|
vGrant := (Others=>'0');
|
71 |
|
|
vGrant(j) := '1';
|
72 |
|
|
end if;
|
73 |
|
|
end loop loopNewGrantA;
|
74 |
|
|
if i/=WbMasterType'left then
|
75 |
|
|
loopNewGrantB: for j in WbMasterType'left to WbMasterType'pred(i) loop
|
76 |
|
|
if WbMasterIn(j).Cyc='1' then
|
77 |
|
|
vGrant := (Others=>'0');
|
78 |
|
|
vGrant(j) := '1';
|
79 |
|
|
end if;
|
80 |
|
|
end loop loopNewGrantB; --grant only moves after new requester
|
81 |
|
|
end if;
|
82 |
|
|
end if;
|
83 |
|
|
end loop loopGrant;
|
84 |
|
|
end if; --Clk
|
85 |
6 |
barryw |
grant <= vGrant;
|
86 |
4 |
barryw |
end process procArb;
|
87 |
3 |
barryw |
--=============================================================================
|
88 |
|
|
-------------------------------------------------------------------------------
|
89 |
4 |
barryw |
-- Master Multiplexers
|
90 |
3 |
barryw |
-------------------------------------------------------------------------------
|
91 |
4 |
barryw |
procWbMasterIn: process(grant,WbMasterIn) is
|
92 |
|
|
variable vSlaveOut : WbMasterOutType;
|
93 |
|
|
begin
|
94 |
|
|
loopGrantInMux: for i in WbMasterType loop
|
95 |
|
|
vSlaveOut := WbMasterIn(i);
|
96 |
|
|
exit when grant(i)='1';
|
97 |
|
|
end loop loopGrantInMux;
|
98 |
|
|
wbStrobe <= vSlaveOut.Strobe;
|
99 |
|
|
wbWrEn <= vSlaveOut.WrEn;
|
100 |
|
|
wbAddr <= vSlaveOut.Addr;
|
101 |
|
|
wbMData <= vSlaveOut.Data;
|
102 |
|
|
--wbMDataTag <= vSlaveOut.DataTag;
|
103 |
|
|
wbCyc <= vSlaveOut.Cyc;
|
104 |
|
|
--wbCycType <= vSlaveOut.CycType;
|
105 |
|
|
end process procWbMasterIn;
|
106 |
|
|
procWbMasterOut: process(grant,wbSData,wbAck,wbErr,wbRty) is
|
107 |
|
|
begin
|
108 |
|
|
loopGrantOutMux: for i in grant'range loop
|
109 |
|
|
WbMasterOut(i).Ack <= grant(i) and wbAck;
|
110 |
|
|
WbMasterOut(i).Err <= grant(i) and wbErr;
|
111 |
|
|
WbMasterOut(i).Rty <= grant(i) and wbRty;
|
112 |
|
|
WbMasterOut(i).Data <= wbSData; --Data out can always be active.
|
113 |
|
|
end loop loopGrantOutMux;
|
114 |
|
|
end process procWbMasterOut;
|
115 |
|
|
|
116 |
|
|
wbAck <= wbStrobe and validAddress;
|
117 |
|
|
wbErr <= wbStrobe and not(validAddress);
|
118 |
|
|
wbRty <= '0';
|
119 |
|
|
WbRst <= '0';
|
120 |
3 |
barryw |
--=============================================================================
|
121 |
|
|
-------------------------------------------------------------------------------
|
122 |
4 |
barryw |
-- Address Decode, Asynchronous
|
123 |
3 |
barryw |
-------------------------------------------------------------------------------
|
124 |
4 |
barryw |
procAddrDecode: process(wbAddr) is
|
125 |
|
|
variable vValidAddress : std_logic;
|
126 |
|
|
begin
|
127 |
|
|
vValidAddress := '0';
|
128 |
|
|
loopStatusEn: for f in StatusFieldType loop
|
129 |
|
|
if StatusParams(f).Address=wbAddr then
|
130 |
|
|
statusEnable(f) <= '1';
|
131 |
|
|
vValidAddress := '1';
|
132 |
|
|
else
|
133 |
|
|
statusEnable(f) <= '0';
|
134 |
|
|
end if;
|
135 |
|
|
end loop loopStatusEn;
|
136 |
|
|
loopSettingEn: for f in SettingFieldType loop
|
137 |
|
|
if SettingParams(f).Address=wbAddr then
|
138 |
|
|
settingEnable(f) <= '1';
|
139 |
|
|
vValidAddress := '1';
|
140 |
|
|
else
|
141 |
|
|
settingEnable(f) <= '0';
|
142 |
|
|
end if;
|
143 |
|
|
end loop loopSettingEn;
|
144 |
|
|
loopTriggerEn: for f in TriggerFieldType loop
|
145 |
|
|
if TriggerParams(f).Address=wbAddr then
|
146 |
|
|
triggerEnable(f) <= '1';
|
147 |
|
|
vValidAddress := '1';
|
148 |
|
|
else
|
149 |
|
|
triggerEnable(f) <= '0';
|
150 |
|
|
end if;
|
151 |
|
|
end loop loopTriggerEn;
|
152 |
|
|
validAddress <= vValidAddress;
|
153 |
|
|
end process procAddrDecode;
|
154 |
3 |
barryw |
--=============================================================================
|
155 |
|
|
-------------------------------------------------------------------------------
|
156 |
4 |
barryw |
-- Read
|
157 |
3 |
barryw |
-------------------------------------------------------------------------------
|
158 |
4 |
barryw |
procRegRead: process(StatusRegs,iSettingRegs,iTriggers,statusEnable,settingEnable,triggerEnable) is
|
159 |
|
|
variable vWbSData : WbDataType;
|
160 |
|
|
begin
|
161 |
|
|
vWbSData := (Others=>'0');
|
162 |
|
|
loopStatusRegs : for f in StatusFieldType loop
|
163 |
|
|
if statusEnable(f)='1' then
|
164 |
|
|
vWbSData(StatusParams(f).MSBLoc to (StatusParams(f).MSBLoc + StatusParams(f).BitWidth - 1)) := StatusRegs(f)((WbDataBits-StatusParams(f).BitWidth) to WbDataBits-1);
|
165 |
|
|
end if; --Address
|
166 |
|
|
end loop loopStatusRegs;
|
167 |
|
|
loopSettingRegs : for f in SettingFieldType loop
|
168 |
|
|
if settingEnable(f)='1' then
|
169 |
|
|
vWbSData(SettingParams(f).MSBLoc to (SettingParams(f).MSBLoc + SettingParams(f).BitWidth - 1)) := iSettingRegs(f)((WbDataBits-SettingParams(f).BitWidth) to WbDataBits-1);
|
170 |
|
|
end if; --Address
|
171 |
|
|
end loop loopSettingRegs;
|
172 |
|
|
loopTriggerRegs : for f in TriggerFieldType loop
|
173 |
|
|
if triggerEnable(f)='1' then
|
174 |
|
|
vWbSData(TriggerParams(f).BitLoc) := iTriggers(f);
|
175 |
|
|
end if; --Address
|
176 |
|
|
end loop loopTriggerRegs;
|
177 |
|
|
wbSData <= vWbSData;
|
178 |
|
|
end process procRegRead;
|
179 |
3 |
barryw |
--=============================================================================
|
180 |
|
|
-------------------------------------------------------------------------------
|
181 |
4 |
barryw |
-- Write, Reset, Clear
|
182 |
3 |
barryw |
-------------------------------------------------------------------------------
|
183 |
4 |
barryw |
procRegWrite: process(WbClk,rstZ) is
|
184 |
|
|
begin
|
185 |
|
|
if (rstZ='0') then
|
186 |
|
|
loopSettingRegDefault : for f in SettingFieldType loop
|
187 |
|
|
iSettingRegs(f) <= SettingParams(f).Default;
|
188 |
|
|
end loop loopSettingRegDefault;
|
189 |
|
|
loopTriggerRegDefault : for f in TriggerFieldType loop
|
190 |
|
|
iTriggers(f) <= '0';
|
191 |
|
|
end loop loopTriggerRegDefault;
|
192 |
|
|
elsif rising_edge(WbClk) then
|
193 |
|
|
loopSettingRegWr : for f in SettingFieldType loop
|
194 |
|
|
if settingEnable(f)='1' and wbStrobe='1' and wbWrEn='1' then
|
195 |
|
|
iSettingRegs(f)((WbDataBits-SettingParams(f).BitWidth) to WbDataBits-1) <= wbMData(SettingParams(f).MSBLoc to (SettingParams(f).MSBLoc + SettingParams(f).BitWidth-1));
|
196 |
|
|
end if;
|
197 |
|
|
end loop loopSettingRegWr;
|
198 |
|
|
loopSettingRegRst : for f in SettingFieldType loop
|
199 |
|
|
if SettingRsts(f)='1' then
|
200 |
|
|
iSettingRegs(f) <= SettingParams(f).Default;
|
201 |
|
|
end if;
|
202 |
|
|
end loop loopSettingRegRst;
|
203 |
|
|
loopTriggerRegWr : for f in TriggerFieldType loop
|
204 |
|
|
if triggerEnable(f)='1' and wbStrobe='1' and wbWrEn='1' then
|
205 |
|
|
iTriggers(f) <= wbMData(TriggerParams(f).BitLoc);
|
206 |
|
|
elsif TriggerClr(f)='1' then
|
207 |
|
|
iTriggers(f) <= '0';
|
208 |
|
|
end if; --Address or clear
|
209 |
|
|
end loop loopTriggerRegWr;
|
210 |
|
|
end if; --Clk
|
211 |
|
|
end process procRegWrite;
|
212 |
|
|
|
213 |
3 |
barryw |
end architecture behavior;
|