w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
sn_humanio_emu_rbus.vhd
Go to the documentation of this file.
1-- $Id: sn_humanio_emu_rbus.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2017-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: sn_humanio_emu_rbus - syn
7-- Description: sn_humanio rbus emulator
8--
9-- Dependencies: -
10--
11-- Test bench: -
12--
13-- Target Devices: generic
14-- Tool versions: viv 2017.1-2019,1; ghdl 0.34-0.35
15--
16-- Revision History:
17-- Date Rev Version Comment
18-- 2017-06-11 912 1.0 Initial version (derived from sn_humanio_rbus
19------------------------------------------------------------------------------
20--
21-- rbus registers:
22--
23-- Addr Bits Name r/w/f Function
24-- 000 stat r/-/- Status register
25-- 15 emu r/-/- emulation (always 1)
26-- 14:12 hdig r/-/- display size as (2**DCWIDTH)-1
27-- 11:08 hled r/-/- led size as LWIDTH-1
28-- 7:04 hbtn r/-/- button size as BWIDTH-1
29-- 3:00 hswi r/-/- switch size as SWIDTH-1
30--
31-- 001 cntl r/w/- Control register
32-- 4 dsp1_en r/-/- always 0
33-- 3 dsp0_en r/-/- always 0
34-- 2 dp_en r/-/- always 0
35-- 1 led_en r/-/- always 0
36-- 0 swi_en r/-/- always 1: SWI will be driven by rbus
37--
38-- 010 x:00 btn -/-/f w: will pulse BTN
39-- 011 x:00 swi r/w/- SWI status
40-- 100 x:00 led r/-/- LED status
41-- 101 x:00 dp r/-/- DSP_DP status
42-- 110 15:00 dsp0 r/-/- DSP_DAT lsb status
43-- 111 15:00 dsp1 r/-/- DSP_DAT msb status
44--
45
46library ieee;
47use ieee.std_logic_1164.all;
48use ieee.numeric_std.all;
49
50use work.slvtypes.all;
51use work.rblib.all;
52
53-- ----------------------------------------------------------------------------
54
55entity sn_humanio_emu_rbus is -- sn_humanio rbus emulator
56 generic (
57 SWIDTH : positive := 8; -- SWI port width
58 BWIDTH : positive := 4; -- BTN port width
59 LWIDTH : positive := 8; -- LED port width
60 DCWIDTH : positive := 2; -- digit counter width (2 or 3)
61 RB_ADDR : slv16 := x"fef0");
62 port (
63 CLK : in slbit; -- clock
64 RESET : in slbit := '0'; -- reset
65 RB_MREQ : in rb_mreq_type; -- rbus: request
66 RB_SRES : out rb_sres_type; -- rbus: response
67 SWI : out slv(SWIDTH-1 downto 0); -- switch settings
68 BTN : out slv(BWIDTH-1 downto 0); -- button settings
69 LED : in slv(LWIDTH-1 downto 0); -- led data
70 DSP_DAT : in slv(4*(2**DCWIDTH)-1 downto 0); -- display data
71 DSP_DP : in slv((2**DCWIDTH)-1 downto 0) -- display decimal points
72 );
74
75architecture syn of sn_humanio_emu_rbus is
76
77 type regs_type is record
78 rbsel : slbit; -- rbus select
79 swi : slv(SWIDTH-1 downto 0); -- rbus swi
80 btn : slv(BWIDTH-1 downto 0); -- rbus btn
81 led : slv(LWIDTH-1 downto 0); -- hio led
82 dsp_dat : slv(4*(2**DCWIDTH)-1 downto 0); -- hio dsp_dat
83 dsp_dp : slv((2**DCWIDTH)-1 downto 0); -- hio dsp_dp
84 end record regs_type;
85
86 constant swizero : slv(SWIDTH-1 downto 0) := (others=>'0');
87 constant btnzero : slv(BWIDTH-1 downto 0) := (others=>'0');
88 constant ledzero : slv(LWIDTH-1 downto 0) := (others=>'0');
89 constant dpzero : slv((2**DCWIDTH)-1 downto 0) := (others=>'0');
90 constant datzero : slv(4*(2**DCWIDTH)-1 downto 0) := (others=>'0');
91
92 constant regs_init : regs_type := (
93 '0', -- rbsel
94 swizero, -- swi
95 btnzero, -- btn
96 ledzero, -- led
97 datzero, -- dsp_dat
98 dpzero -- dsp_dp
99 );
100
101 signal R_REGS : regs_type := regs_init; -- state registers
102 signal N_REGS : regs_type := regs_init; -- next value state regs
103
104 constant stat_rbf_emu: integer := 15;
105 subtype stat_rbf_hdig is integer range 14 downto 12;
106 subtype stat_rbf_hled is integer range 11 downto 8;
107 subtype stat_rbf_hbtn is integer range 7 downto 4;
108 subtype stat_rbf_hswi is integer range 3 downto 0;
109
110 constant cntl_rbf_dsp1_en: integer := 4;
111 constant cntl_rbf_dsp0_en: integer := 3;
112 constant cntl_rbf_dp_en: integer := 2;
113 constant cntl_rbf_led_en: integer := 1;
114 constant cntl_rbf_swi_en: integer := 0;
115
116 constant rbaddr_stat: slv3 := "000"; -- 0 r/-/-
117 constant rbaddr_cntl: slv3 := "001"; -- 0 r/w/-
118 constant rbaddr_btn: slv3 := "010"; -- 1 -/-/f
119 constant rbaddr_swi: slv3 := "011"; -- 1 r/w/-
120 constant rbaddr_led: slv3 := "100"; -- 2 r/-/-
121 constant rbaddr_dp: slv3 := "101"; -- 3 r/-/-
122 constant rbaddr_dsp0: slv3 := "110"; -- 4 r/-/-
123 constant rbaddr_dsp1: slv3 := "111"; -- 5 r/-/-
124
125 subtype dspdat_msb is integer range 4*(2**DCWIDTH)-1 downto 4*(2**DCWIDTH)-16;
126 subtype dspdat_lsb is integer range 15 downto 0;
127
128begin
129
130 assert SWIDTH<=16
131 report "assert (SWIDTH<=16)"
132 severity failure;
133 assert BWIDTH<=8
134 report "assert (BWIDTH<=8)"
135 severity failure;
136 assert LWIDTH<=16
137 report "assert (LWIDTH<=16)"
138 severity failure;
139
140 assert DCWIDTH=2 or DCWIDTH=3
141 report "assert(DCWIDTH=2 or DCWIDTH=3): unsupported DCWIDTH"
142 severity FAILURE;
143
144 proc_regs: process (CLK)
145 begin
146
147 if rising_edge(CLK) then
148 if RESET = '1' then
149 R_REGS <= regs_init;
150 else
151 R_REGS <= N_REGS;
152 end if;
153 end if;
154
155 end process proc_regs;
156
157 proc_next: process (R_REGS, RB_MREQ, LED, DSP_DAT, DSP_DP)
158
159 variable r : regs_type := regs_init;
160 variable n : regs_type := regs_init;
161
162 variable irb_ack : slbit := '0';
163 variable irb_busy : slbit := '0';
164 variable irb_err : slbit := '0';
165 variable irb_dout : slv16 := (others=>'0');
166 variable irbena : slbit := '0';
167
168 begin
169
170 r := R_REGS;
171 n := R_REGS;
172
173 irb_ack := '0';
174 irb_busy := '0';
175 irb_err := '0';
176 irb_dout := (others=>'0');
177
178 irbena := RB_MREQ.re or RB_MREQ.we;
179
180 -- input registers
181 n.led := LED;
182 n.dsp_dat := DSP_DAT;
183 n.dsp_dp := DSP_DP;
184 -- clear btn register --> cause single cycle pulses
185 n.btn := (others=>'0');
186
187 -- rbus address decoder
188 n.rbsel := '0';
189 if RB_MREQ.aval='1' and RB_MREQ.addr(15 downto 3)=RB_ADDR(15 downto 3) then
190 n.rbsel := '1';
191 end if;
192
193 -- rbus transactions
194 if r.rbsel = '1' then
195 irb_ack := irbena; -- ack all accesses
196
197 case RB_MREQ.addr(2 downto 0) is
198
199 when rbaddr_stat =>
200 irb_dout(stat_rbf_emu) := '1';
201 irb_dout(stat_rbf_hdig) := slv(to_unsigned((2**DCWIDTH)-1,3));
202 irb_dout(stat_rbf_hled) := slv(to_unsigned(LWIDTH-1,4));
203 irb_dout(stat_rbf_hbtn) := slv(to_unsigned(BWIDTH-1,4));
204 irb_dout(stat_rbf_hswi) := slv(to_unsigned(SWIDTH-1,4));
205 if RB_MREQ.we = '1' then
206 irb_ack := '0';
207 end if;
208
209 when rbaddr_cntl =>
210 irb_dout(cntl_rbf_dsp1_en) := '0';
211 irb_dout(cntl_rbf_dsp0_en) := '0';
212 irb_dout(cntl_rbf_dp_en) := '0';
213 irb_dout(cntl_rbf_led_en) := '0';
214 irb_dout(cntl_rbf_swi_en) := '1';
215
216 when rbaddr_btn =>
217 irb_dout(r.btn'range) := r.btn;
218 if RB_MREQ.we = '1' then
219 n.btn := RB_MREQ.din(n.btn'range);
220 end if;
221
222 when rbaddr_swi =>
223 irb_dout(r.swi'range) := r.swi;
224 if RB_MREQ.we = '1' then
225 n.swi := RB_MREQ.din(n.swi'range);
226 end if;
227
228 when rbaddr_led =>
229 irb_dout(r.led'range) := r.led;
230
231 when rbaddr_dp =>
232 irb_dout(r.dsp_dp'range) := r.dsp_dp;
233
234 when rbaddr_dsp0 =>
235 irb_dout := r.dsp_dat(dspdat_lsb);
236
237 when rbaddr_dsp1 =>
238 irb_dout := r.dsp_dat(dspdat_msb);
239
240 when others => null;
241 end case;
242
243 end if;
244
245 N_REGS <= n;
246
247 BTN <= R_REGS.btn;
248 SWI <= R_REGS.swi;
249
250 RB_SRES <= rb_sres_init;
251 RB_SRES.ack <= irb_ack;
252 RB_SRES.busy <= irb_busy;
253 RB_SRES.err <= irb_err;
254 RB_SRES.dout <= irb_dout;
255
256 end process proc_next;
257
258end syn;
Definition: rblib.vhd:32
std_logic_vector( 2 downto 0) slv3
Definition: slvtypes.vhd:35
std_logic_vector( 15 downto 0) slv16
Definition: slvtypes.vhd:48
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector slv
Definition: slvtypes.vhd:31
integer range 14 downto 12 stat_rbf_hdig
integer range 4*( 2** DCWIDTH)- 1 downto 4*( 2** DCWIDTH)- 16 dspdat_msb
slv( LWIDTH- 1 downto 0) :=( others => '0') ledzero
slv( 4*( 2** DCWIDTH)- 1 downto 0) :=( others => '0') datzero
integer range 7 downto 4 stat_rbf_hbtn
regs_type := regs_init N_REGS
regs_type :=( '0', swizero, btnzero, ledzero, datzero, dpzero) regs_init
slv( BWIDTH- 1 downto 0) :=( others => '0') btnzero
slv(( 2** DCWIDTH)- 1 downto 0) :=( others => '0') dpzero
integer range 11 downto 8 stat_rbf_hled
regs_type := regs_init R_REGS
slv( SWIDTH- 1 downto 0) :=( others => '0') swizero
integer range 15 downto 0 dspdat_lsb
integer range 3 downto 0 stat_rbf_hswi
in DSP_DP slv(( 2** DCWIDTH)- 1 downto 0)
RB_ADDR slv16 := x"fef0"
in DSP_DAT slv( 4*( 2** DCWIDTH)- 1 downto 0)
out SWI slv( SWIDTH- 1 downto 0)
out BTN slv( BWIDTH- 1 downto 0)
in RB_MREQ rb_mreq_type
out RB_SRES rb_sres_type
in LED slv( LWIDTH- 1 downto 0)