summaryrefslogtreecommitdiff
path: root/2004/n/fpga/src/registre/registre.vhd
blob: 23a00799347b5cb0571c225234f58c79e9ec6d5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
-- txserie.vhd
-- Eurobot 2004 : APB Team
-- Auteur : Pierre Prot
-- registre IO adressable sur bus ISA

-- MARCHE 

-- -------------------------------------------
-- Registre g�n�rique � brancher sur un bus
-- -------------------------------------------
-- 
-- * on peut �crire ou lire dans le registre depuis le bus :
--   . Positionner l'adresse
--   . Mettre 'rw' � 1=>read 0=>write
--   . Front montant sur 'ck'
--   Remarque : on ne peut pas �crire via le bus si 'load' est activ�
-- * on peut lire la valeur en permanence sur 'output'
-- * on peut �crire dans le registre en permanence gr�ce � 'load'. Cette
--   action est prioritaire sur l'�criture via le bus
--   . Mettre 'load' � 1
--   . Ecrire dans 'input' (actualisation imm�diate)
--   . Mettre 'load' � 0 pour latcher


library ieee;
use	ieee.std_logic_1164.all;
use     ieee.std_logic_arith.all;
use     ieee.std_logic_unsigned.all;

use	work.nono_const.all;

entity regIO is
    generic(adr : unsigned);
    port(
	bus_data: inout unsigned ((NB_BIT_DATA - 1) downto 0);
	bus_address: in unsigned ((NB_BIT_ADDRESS - 1) downto 0);
	input: 	in    unsigned(7 downto 0);
	output: out   unsigned(7 downto 0);
	rw:	in std_logic;
	load:	in std_logic;
	ck:	in std_logic;
	rst:	in std_logic
	);
end entity;


architecture rtl of regIO is
signal REG : unsigned((NB_BIT_DATA - 1) downto 0):=(others => '1');

begin
    p_w:process(ck,load,input,rst)
    begin
	if(ck='1') then
	    if(bus_address=adr) then
		if(rw='0') then
		    if(load='0') then
			REG<=bus_data;
		    end if;
		else -- RW=1 : la CM lit => on �crit sur le bus
		    bus_data<=REG;
		end if;
	    else
	    	bus_data<=(others => 'Z');
	    end if;
	else
	    bus_data<=(others => 'Z');
	end if;

-- chargement : prioritaire sur l'�criture via le bus
	if(load='1') then
	    REG<=input;
	end if;
	
-- reset : prioritaire sur tout
	if(rst'event and rst='1') then 
	    REG<=(others => '0');
	    bus_data<=(others => 'Z');
	end if;

    end process p_w;
    
--    p_load : process(load,input)
--    begin
--	if(load='1') then
--	    REG<=input;
--	end if;
--    end process p_load;

--   p_reset : process(rst)
--   begin
--	if(rst'event and rst='1') then 
--	    REG<=(others => '0');
--	    bus_data<=(others => 'Z');
--	end if;
--    end process p_reset;
	
    output<=REG;
end rtl;