OpenCores
URL https://opencores.org/ocsvn/lxp32/lxp32/trunk

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [rtl/] [lxp32_ubuf.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
---------------------------------------------------------------------
2
-- Microbuffer
3
--
4
-- Part of the LXP32 CPU
5
--
6
-- Copyright (c) 2016 by Alex I. Kuznetsov
7
--
8
-- A small buffer with a FIFO-like interface, implemented
9
-- using registers.
10
---------------------------------------------------------------------
11
 
12
library ieee;
13
use ieee.std_logic_1164.all;
14
 
15
entity lxp32_ubuf is
16
        generic(
17
                DATA_WIDTH: integer
18
        );
19
        port(
20
                clk_i: in std_logic;
21
                rst_i: in std_logic;
22
 
23
                we_i: in std_logic;
24
                d_i: in std_logic_vector(DATA_WIDTH-1 downto 0);
25
                re_i: in std_logic;
26
                d_o: out std_logic_vector(DATA_WIDTH-1 downto 0);
27
 
28
                empty_o: out std_logic;
29
                full_o: out std_logic
30
        );
31
end entity;
32
 
33
architecture rtl of lxp32_ubuf is
34
 
35
signal we: std_logic;
36
signal re: std_logic;
37
 
38
signal empty: std_logic:='1';
39
signal full: std_logic:='0';
40
 
41
type regs_type is array (1 downto 0) of std_logic_vector(DATA_WIDTH-1 downto 0);
42
signal regs: regs_type;
43
signal regs_mux: regs_type;
44
 
45
begin
46
 
47
we<=we_i and not full;
48
re<=re_i and not empty;
49
 
50
process (clk_i) is
51
begin
52
        if rising_edge(clk_i) then
53
                if rst_i='1' then
54
                        empty<='1';
55
                        full<='0';
56
                        regs<=(others=>(others=>'-'));
57
                else
58
                        if re='0' then
59
                                regs(0)<=regs_mux(0);
60
                        else
61
                                regs(0)<=regs_mux(1);
62
                        end if;
63
 
64
                        regs(1)<=regs_mux(1);
65
 
66
                        if we='1' and re='0' then
67
                                empty<='0';
68
                                full<=not empty;
69
                        elsif we='0' and re='1' then
70
                                empty<=not full;
71
                                full<='0';
72
                        end if;
73
                end if;
74
        end if;
75
end process;
76
 
77
regs_mux(0)<=regs(0) when we='0' or empty='0' else d_i;
78
regs_mux(1)<=regs(1) when we='0' or empty='1' else d_i;
79
 
80
d_o<=regs(0);
81
empty_o<=empty;
82
full_o<=full;
83
 
84
end architecture;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.