]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - mcc_master.vhd
Added MCC_Master.
[fpga/pwm.git] / mcc_master.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
5
6 library std;
7 use std.textio.all;
8
9 --------------------------------------------------------------------------------
10
11 entity mcc_master is
12   generic (
13     MCC_W     : integer := 5;
14     MUX_W     : integer := 2;
15     IRF_ADR_W : integer := 5);
16   port (
17     -- Primary slave intefrace
18     ACK_O        : out std_logic;
19     CLK_I        : in  std_logic;
20     RST_I        : in  std_logic;
21     STB_I        : in  std_logic;
22     -- Motion Control Chain
23     MCC_STB_O    : out std_logic_vector (MCC_W-1 downto 0);
24     MCC_ACK_I    : in  std_logic_vector (MCC_W-1 downto 0);
25     MCC_MUX_CODE : out std_logic_vector (MUX_W-1 downto 0);
26     MCC_MUX_EN   : out std_logic;
27     -- Shared dual-port memory
28     IRF_ACK_I    : in  std_logic;
29     IRF_ADR_O    : out std_logic_vector (IRF_ADR_W-1 downto 0);
30     IRF_DAT_I    : in  std_logic_vector (15 downto 0);
31     IRF_DAT_O    : out std_logic_vector (15 downto 0);
32     IRF_STB_O    : out std_logic;
33     IRF_WE_O     : out std_logic);
34 end entity mcc_master;
35
36 --------------------------------------------------------------------------------
37
38 architecture behavioral of mcc_master is
39
40   type state_t is (ready, read_mask, do_mcc, done);
41
42   signal state : state_t;
43
44   signal mcc_mask       : std_logic_vector (MCC_W-1 downto 0);
45   signal mcc_ack_inner  : std_logic_vector (MCC_W downto 0);
46   signal mcc_stb_inner  : std_logic_vector (MCC_W-1 downto 0);
47   signal mux_code_inner : std_logic_vector (MUX_W-1 downto 0);
48   signal mcc_exec       : std_logic;
49   
50 --------------------------------------------------------------------------------
51
52 begin
53
54   IRF_ADR_O <= conv_std_logic_vector(0, IRF_ADR_W);
55   IRF_DAT_O <= (others => '-');
56   IRF_WE_O  <= '0';
57
58
59   priority_encoder_1: entity work.priority_encoder
60     generic map (
61       SEL_W  => MCC_W,
62       CODE_W => MUX_W)
63     port map (
64       sel  => mcc_stb_inner,
65       code => mux_code_inner);
66   
67
68   MCC_EXEC_LOGIC : process (RST_I, CLK_I) is
69   begin
70     if RST_I = '1' then
71       mcc_ack_inner <= (others => '0');
72       mcc_stb_inner <= (others => '0');
73
74     elsif rising_edge(CLK_I) then
75       mcc_ack_inner (0) <= mcc_exec;
76       
77       for i in 0 to MCC_W-1 loop
78         if mcc_mask (i) = '1' then
79           mcc_ack_inner (i+1) <= MCC_ACK_I (i);
80           mcc_stb_inner (i)   <= mcc_ack_inner (i);
81         else
82           mcc_ack_inner (i+1) <= mcc_ack_inner (i);
83           mcc_stb_inner (i)   <= '0';
84         end if;
85       end loop;
86     end if;
87   end process;
88
89   
90   LATCHES : process (RST_I, CLK_I) is
91   begin
92     if RST_I = '1' then
93       MCC_STB_O    <= (others => '0');
94       MCC_MUX_CODE <= (others => '0');
95
96     elsif rising_edge(CLK_I) then
97       MCC_STB_O    <= mcc_stb_inner;
98       MCC_MUX_CODE <= mux_code_inner;
99     end if;
100   end process;
101
102   
103   FSM : process (CLK_I, RST_I) is
104   begin
105     if RST_I = '1' then
106       state      <= ready;
107       ACK_O      <= '0';
108       mcc_exec   <= '0';
109       MCC_MUX_EN <= '0';
110       IRF_STB_O  <= '0';
111       
112     elsif rising_edge(CLK_I) then
113       case state is
114         when ready =>
115           if STB_I = '1' then
116             state     <= read_mask;
117             IRF_STB_O <= '1';
118           end if;
119
120         when read_mask =>
121           if IRF_ACK_I = '1' then
122             state      <= do_mcc;
123             mcc_mask   <= IRF_DAT_I (mcc_mask'RANGE);
124             MCC_MUX_EN <= '1';
125             mcc_exec   <= '1';
126           end if;
127
128         when do_mcc =>
129           if mcc_ack_inner (MCC_W) = '1' then
130             state      <= done;
131             ACK_O      <= '1';
132             IRF_STB_O  <= '0';
133             MCC_MUX_EN <= '0';
134             mcc_exec   <= '0';
135           end if;
136
137         when done =>
138           if STB_I = '0' then
139             state <= ready;
140             ACK_O <= '0';
141           end if;
142       end case;      
143     end if;
144   end process;
145   
146 end architecture behavioral;
147