1 |
16 |
rudi |
--
|
2 |
|
|
-- Wishbone compliant cycle shared memory, priority based selection
|
3 |
|
|
-- author: Richard Herveille
|
4 |
|
|
--
|
5 |
|
|
-- rev.: 1.0 july 12th, 2001. Initial release
|
6 |
|
|
--
|
7 |
|
|
--
|
8 |
|
|
|
9 |
|
|
library ieee;
|
10 |
|
|
use ieee.std_logic_1164.all;
|
11 |
|
|
use ieee.std_logic_arith.all;
|
12 |
|
|
|
13 |
|
|
entity csm_pb is
|
14 |
|
|
generic(
|
15 |
|
|
DWIDTH : natural := 32; -- databus width
|
16 |
|
|
AWIDTH : natural := 8 -- addressbus width
|
17 |
|
|
);
|
18 |
|
|
port(
|
19 |
|
|
-- SYSCON signals
|
20 |
|
|
CLK_I : in std_logic; -- wishbone clock input
|
21 |
|
|
RST_I : in std_logic; -- synchronous active high reset
|
22 |
|
|
nRESET : in std_logic; -- asynchronous active low reset
|
23 |
|
|
|
24 |
|
|
-- wishbone slave0 connections
|
25 |
|
|
ADR0_I : in unsigned(AWIDTH -1 downto 0); -- address input
|
26 |
|
|
DAT0_I : in std_logic_vector(DWIDTH -1 downto 0); -- data input
|
27 |
|
|
DAT0_O : out std_logic_vector(DWIDTH -1 downto 0); -- data output
|
28 |
|
|
SEL0_I : in std_logic_vector( (DWIDTH/8) -1 downto 0); -- byte select input
|
29 |
|
|
WE0_I : in std_logic; -- write enable input
|
30 |
|
|
STB0_I : in std_logic; -- strobe input
|
31 |
|
|
CYC0_I : in std_logic; -- valid bus cycle input
|
32 |
|
|
ACK0_O : out std_logic; -- acknowledge output
|
33 |
|
|
ERR0_O : out std_logic; -- error output
|
34 |
|
|
|
35 |
|
|
-- wishbone slave1 connections
|
36 |
|
|
ADR1_I : in unsigned(AWIDTH -1 downto 0); -- address input
|
37 |
|
|
DAT1_I : in std_logic_vector(DWIDTH -1 downto 0); -- data input
|
38 |
|
|
DAT1_O : out std_logic_vector(DWIDTH -1 downto 0); -- data output
|
39 |
|
|
SEL1_I : in std_logic_vector( (DWIDTH/8) -1 downto 0); -- byte select input
|
40 |
|
|
WE1_I : in std_logic; -- write enable input
|
41 |
|
|
STB1_I : in std_logic; -- strobe input
|
42 |
|
|
CYC1_I : in std_logic; -- valid bus cycle input
|
43 |
|
|
ACK1_O : out std_logic; -- acknowledge output
|
44 |
|
|
ERR1_O : out std_logic -- error output
|
45 |
|
|
);
|
46 |
|
|
end entity csm_pb;
|
47 |
|
|
|
48 |
|
|
architecture structural of csm_pb is
|
49 |
|
|
-- function declarations
|
50 |
|
|
function "and"(L: std_logic_vector; R : std_logic) return std_logic_vector is
|
51 |
|
|
variable tmp : std_logic_vector(L'range);
|
52 |
|
|
begin
|
53 |
|
|
for n in L'range loop
|
54 |
|
|
tmp(n) := L(n) and R;
|
55 |
|
|
end loop;
|
56 |
|
|
return tmp;
|
57 |
|
|
end function "and";
|
58 |
|
|
|
59 |
|
|
function "and"(L: std_logic; R : std_logic_vector) return std_logic_vector is
|
60 |
|
|
begin
|
61 |
|
|
return (R and L);
|
62 |
|
|
end function "and";
|
63 |
|
|
|
64 |
|
|
-- define memory array
|
65 |
|
|
type mem_array is array(2**AWIDTH -1 downto 0) of std_logic_vector(DWIDTH -1 downto 0);
|
66 |
|
|
signal mem : mem_array;
|
67 |
|
|
|
68 |
|
|
-- multiplexor select signal
|
69 |
|
|
signal wb0_acc, dwb0_acc : std_logic;
|
70 |
|
|
signal wb1_acc, dwb1_acc : std_logic;
|
71 |
|
|
signal sel_wb0 : std_logic;
|
72 |
|
|
signal sel_wb1 : std_logic;
|
73 |
|
|
signal ack0_pipe, ack1_pipe : std_logic_vector(3 downto 0);
|
74 |
|
|
|
75 |
|
|
-- multiplexed memory busses / signals
|
76 |
|
|
signal mem_adr, mem_radr : unsigned(AWIDTH -1 downto 0);
|
77 |
|
|
signal mem_dati, mem_dato : std_logic_vector(DWIDTH -1 downto 0);
|
78 |
|
|
signal mem_we : std_logic;
|
79 |
|
|
|
80 |
|
|
-- acknowledge generation
|
81 |
|
|
signal wb0_ack, wb1_ack : std_logic;
|
82 |
|
|
|
83 |
|
|
-- error signal generation
|
84 |
|
|
signal err0, err1 : std_logic_vector( (DWIDTH/8) -1 downto 0);
|
85 |
|
|
|
86 |
|
|
begin
|
87 |
|
|
-- generate multiplexor select signal
|
88 |
|
|
wb0_acc <= CYC0_I and STB0_I;
|
89 |
|
|
wb1_acc <= CYC1_I and STB1_I and not sel_wb0;
|
90 |
|
|
|
91 |
|
|
process(CLK_I)
|
92 |
|
|
begin
|
93 |
|
|
if (CLK_I'event and CLK_I = '1') then
|
94 |
|
|
dwb0_acc <= wb0_acc and not wb0_ack;
|
95 |
|
|
dwb1_acc <= wb1_acc and not wb1_ack;
|
96 |
|
|
end if;
|
97 |
|
|
end process;
|
98 |
|
|
|
99 |
|
|
sel_wb0 <= wb0_acc and not dwb0_acc;
|
100 |
|
|
sel_wb1 <= wb1_acc and not dwb1_acc;
|
101 |
|
|
|
102 |
|
|
gen_ack_pipe: process(CLK_I, nRESET)
|
103 |
|
|
begin
|
104 |
|
|
if (nRESET = '0') then
|
105 |
|
|
ack0_pipe <= (others => '0');
|
106 |
|
|
ack1_pipe <= (others => '0');
|
107 |
|
|
elsif (CLK_I'event and CLK_I = '1') then
|
108 |
|
|
if (RST_I = '1') then
|
109 |
|
|
ack0_pipe <= (others => '0');
|
110 |
|
|
ack1_pipe <= (others => '0');
|
111 |
|
|
else
|
112 |
|
|
ack0_pipe <= (ack0_pipe(2 downto 0) & sel_wb0) and not wb0_ack;
|
113 |
|
|
ack1_pipe <= (ack1_pipe(2 downto 0) & sel_wb1) and not wb1_ack;
|
114 |
|
|
end if;
|
115 |
|
|
end if;
|
116 |
|
|
end process gen_ack_pipe;
|
117 |
|
|
|
118 |
|
|
-- multiplex memory bus
|
119 |
|
|
-- gen_muxs: process(CLK_I)
|
120 |
|
|
-- begin
|
121 |
|
|
-- if (CLK_I'event and CLK_I = '1') then
|
122 |
|
|
-- if (sel_wb0 = '1') then
|
123 |
|
|
-- mem_adr <= adr0_i;
|
124 |
|
|
-- mem_dati <= dat0_i;
|
125 |
|
|
-- mem_we <= we0_i and cyc0_i and stb0_i and not wb0_ack;
|
126 |
|
|
-- else
|
127 |
|
|
-- mem_adr <= adr1_i;
|
128 |
|
|
-- mem_dati <= dat1_i;
|
129 |
|
|
-- mem_we <= we1_i and cyc1_i and stb1_i and not wb1_ack;
|
130 |
|
|
-- end if;
|
131 |
|
|
-- end if;
|
132 |
|
|
-- end process gen_muxs;
|
133 |
|
|
|
134 |
|
|
mem_adr <= adr0_i when (sel_wb0 = '1') else adr1_i;
|
135 |
|
|
mem_dati <= dat0_i when (sel_wb0 = '1') else dat1_i;
|
136 |
|
|
mem_we <= (we0_i and cyc0_i and stb0_i) when (sel_wb0 = '1') else (we1_i and cyc1_i and stb1_i);
|
137 |
|
|
|
138 |
|
|
-- memory access
|
139 |
|
|
gen_mem: process(CLK_I)
|
140 |
|
|
begin
|
141 |
|
|
if (CLK_I'event and CLK_I = '1') then
|
142 |
|
|
-- write operation
|
143 |
|
|
if (mem_we = '1') then
|
144 |
|
|
mem(conv_integer(mem_adr)) <= mem_dati;
|
145 |
|
|
end if;
|
146 |
|
|
|
147 |
|
|
-- read operation
|
148 |
|
|
mem_radr <= mem_adr; -- FLEX RAMs require address to be registered with inclock for read operation.
|
149 |
|
|
mem_dato <= mem(conv_integer(mem_radr));
|
150 |
|
|
end if;
|
151 |
|
|
end process gen_mem;
|
152 |
|
|
|
153 |
|
|
-- assign DAT_O outputs
|
154 |
|
|
DAT1_O <= mem_dato;
|
155 |
|
|
DAT0_O <= mem_dato;
|
156 |
|
|
|
157 |
|
|
-- assign ACK_O outputs
|
158 |
|
|
-- gen_ack: process(CLK_I)
|
159 |
|
|
-- begin
|
160 |
|
|
-- if (CLK_I'event and CLK_I = '1') then
|
161 |
|
|
wb0_ack <= ( (sel_wb0 and WE0_I) or (ack0_pipe(1)) );-- and not wb0_ack;
|
162 |
|
|
wb1_ack <= ( (sel_wb1 and WE1_I) or (ack1_pipe(1)) );-- and not wb1_ack;
|
163 |
|
|
-- end if;
|
164 |
|
|
-- end process gen_ack;
|
165 |
|
|
-- ACK outputs
|
166 |
|
|
ACK0_O <= wb0_ack;
|
167 |
|
|
ACK1_O <= wb1_ack;
|
168 |
|
|
|
169 |
|
|
-- ERR outputs
|
170 |
|
|
err0 <= (others => '1');
|
171 |
|
|
ERR0_O <= '1' when ( (SEL0_I /= err0) and (CYC0_I = '1') and (STB0_I = '1') ) else '0';
|
172 |
|
|
|
173 |
|
|
err1 <= (others => '1');
|
174 |
|
|
ERR1_O <= '1' when ( (SEL1_I /= err1) and (CYC1_I = '1') and (STB1_I = '1') ) else '0';
|
175 |
|
|
end architecture;
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|