1 |
2 |
dimamali |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : HPI MEMORY
|
3 |
|
|
-- Project : LEON3MINI
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- $Id: $
|
6 |
|
|
-------------------------------------------------------------------------------
|
7 |
|
|
-- Author : Thomas Ameseder
|
8 |
|
|
-- Company : Gleichmann Electronics
|
9 |
|
|
-- Created : 2005-08-19
|
10 |
|
|
-- Standard : VHDL'87
|
11 |
|
|
-------------------------------------------------------------------------------
|
12 |
|
|
-- Description:
|
13 |
|
|
--
|
14 |
|
|
-- This module is for testing the AHB2HPI(2) core. It is a memory that
|
15 |
|
|
-- can be connected to the HPI interface. Also features HPI timing
|
16 |
|
|
-- checks.
|
17 |
|
|
-------------------------------------------------------------------------------
|
18 |
|
|
-- Copyright (c) 2005
|
19 |
|
|
-------------------------------------------------------------------------------
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
library ieee;
|
23 |
|
|
use ieee.std_logic_1164.all;
|
24 |
|
|
library grlib;
|
25 |
|
|
use grlib.stdlib.all;
|
26 |
|
|
|
27 |
|
|
entity hpi_ram is
|
28 |
|
|
generic (abits : integer := 9; dbits : integer := 16);
|
29 |
|
|
port (
|
30 |
|
|
clk : in std_ulogic;
|
31 |
|
|
address : in std_logic_vector(1 downto 0);
|
32 |
|
|
datain : in std_logic_vector(dbits-1 downto 0);
|
33 |
|
|
dataout : out std_logic_vector(dbits-1 downto 0);
|
34 |
|
|
writen : in std_ulogic;
|
35 |
|
|
readn : in std_ulogic;
|
36 |
|
|
csn : in std_ulogic
|
37 |
|
|
);
|
38 |
|
|
end;
|
39 |
|
|
|
40 |
|
|
architecture behavioral of hpi_ram is
|
41 |
|
|
|
42 |
|
|
constant Tcyc : time := 40000 ps; -- cycle time
|
43 |
|
|
|
44 |
|
|
type mem is array(0 to (2**abits -1))
|
45 |
|
|
of std_logic_vector((dbits -1) downto 0);
|
46 |
|
|
signal memarr : mem;
|
47 |
|
|
|
48 |
|
|
signal
|
49 |
|
|
data_reg, -- "00"
|
50 |
|
|
mailbox_reg, -- "01"
|
51 |
|
|
address_reg, -- "10"
|
52 |
|
|
status_reg -- "11"
|
53 |
|
|
: std_logic_vector(dbits-1 downto 0);
|
54 |
|
|
|
55 |
|
|
begin
|
56 |
|
|
|
57 |
|
|
write : process(clk)
|
58 |
|
|
begin
|
59 |
|
|
if rising_edge(clk) then
|
60 |
|
|
if csn = '0' then
|
61 |
|
|
if writen = '0' then
|
62 |
|
|
case address(1 downto 0) is
|
63 |
|
|
when "00" => memarr(conv_integer(address_reg(abits-1 downto 1))) <= datain;
|
64 |
|
|
when "01" => mailbox_reg <= datain;
|
65 |
|
|
when "10" => address_reg <= datain;
|
66 |
|
|
when "11" => status_reg <= datain;
|
67 |
|
|
when others => null;
|
68 |
|
|
end case;
|
69 |
|
|
end if;
|
70 |
|
|
end if;
|
71 |
|
|
end if;
|
72 |
|
|
end process;
|
73 |
|
|
|
74 |
|
|
read : process(address, address_reg, csn, mailbox_reg, memarr, readn,
|
75 |
|
|
status_reg)
|
76 |
|
|
constant Tacc : time := Tcyc; -- data access time
|
77 |
|
|
begin
|
78 |
|
|
if (readn = '0' and csn = '0') then
|
79 |
|
|
case address(1 downto 0) is
|
80 |
|
|
when "00" => dataout <= memarr(conv_integer(address_reg(abits-1 downto 1))) after Tacc;
|
81 |
|
|
when "01" => dataout <= mailbox_reg after Tacc;
|
82 |
|
|
when "10" => dataout <= address_reg after Tacc;
|
83 |
|
|
when "11" => dataout <= status_reg after Tacc;
|
84 |
|
|
when others => null;
|
85 |
|
|
end case;
|
86 |
|
|
else
|
87 |
|
|
-- the rest of the time, invalid data shall be driven
|
88 |
|
|
-- (note: makes an 'X' when being resolved on a high-impedance bus)
|
89 |
|
|
dataout <= (others => 'Z');
|
90 |
|
|
end if;
|
91 |
|
|
end process;
|
92 |
|
|
|
93 |
|
|
-- pragma translate_off
|
94 |
|
|
|
95 |
|
|
---------------------------------------------------------------------------------------
|
96 |
|
|
-- HPI TIMING CHECKS
|
97 |
|
|
---------------------------------------------------------------------------------------
|
98 |
|
|
|
99 |
|
|
cycle_timing_check : process(datain, readn, writen)
|
100 |
|
|
constant Tcycmin : time := 6 * Tcyc; -- minimum write/read cycle time
|
101 |
|
|
constant Tpulsemin : time := 2 * Tcyc; -- minimum write/read pulse time
|
102 |
|
|
constant Twdatasu : time := 6 ns; -- write data setup time
|
103 |
|
|
constant Twdatahold : time := 2 ns; -- write data hold time
|
104 |
|
|
|
105 |
|
|
variable wrlastev, rdlastev : time := 0 ps;
|
106 |
|
|
variable wrlowlastev, rdlowlastev : time := 0 ps;
|
107 |
|
|
variable wdatalastev : time := 0 ps; -- write data last event
|
108 |
|
|
variable wrhighlastev : time := 0 ps;
|
109 |
|
|
begin
|
110 |
|
|
|
111 |
|
|
-- write data hold check
|
112 |
|
|
if datain'event then
|
113 |
|
|
assert (now = 0 ps) or (now - wrhighlastev >= Twdatahold)
|
114 |
|
|
report "Write data hold violation!" severity error;
|
115 |
|
|
wdatalastev := now;
|
116 |
|
|
end if;
|
117 |
|
|
|
118 |
|
|
-- exclusive read or write check
|
119 |
|
|
assert writen = '1' or readn = '1'
|
120 |
|
|
report "Both read and write are signals are low!" severity error;
|
121 |
|
|
|
122 |
|
|
-- write cycle time and write pulse width checks
|
123 |
|
|
if writen'event then
|
124 |
|
|
if writen = '0' then
|
125 |
|
|
assert (now = 0 ps) or (now - wrlowlastev >= Tcycmin)
|
126 |
|
|
report "Write cycle time violation!" severity error;
|
127 |
|
|
wrlowlastev := now;
|
128 |
|
|
wrlastev := now;
|
129 |
|
|
elsif writen = '1' then
|
130 |
|
|
assert (now = 0 ps) or (now - wrlastev >= Tpulsemin)
|
131 |
|
|
report "Write pulse width violation!" severity error;
|
132 |
|
|
assert (now = 0 ps) or (now - wdatalastev >= Twdatasu)
|
133 |
|
|
report "Write data setup violation!" severity error;
|
134 |
|
|
wrhighlastev := now;
|
135 |
|
|
wrlastev := now;
|
136 |
|
|
end if;
|
137 |
|
|
end if;
|
138 |
|
|
|
139 |
|
|
-- read cycle time and read pulse width checks
|
140 |
|
|
if readn'event then
|
141 |
|
|
if readn = '0' then
|
142 |
|
|
assert (now = 0 ps) or (now - rdlowlastev >= Tcycmin)
|
143 |
|
|
report "Read cycle time violation!" severity error;
|
144 |
|
|
rdlowlastev := now;
|
145 |
|
|
rdlastev := now;
|
146 |
|
|
elsif readn = '1' then
|
147 |
|
|
assert (now = 0 ps) or (now - rdlastev >= Tpulsemin)
|
148 |
|
|
report "Read pulse width violation!" severity error;
|
149 |
|
|
rdlastev := now;
|
150 |
|
|
end if;
|
151 |
|
|
end if;
|
152 |
|
|
|
153 |
|
|
end process cycle_timing_check;
|
154 |
|
|
|
155 |
|
|
-- pragma translate_on
|
156 |
|
|
|
157 |
|
|
end architecture;
|
158 |
|
|
|