]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - mcc_master.vhd
Wave_table initialization data format modified.
[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 := '0';
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) := (others => '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) := (others => '0');
26     MCC_MUX_EN   : out std_logic := '0';
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 := '0';
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 := ready;
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) := (others => '0');
46   signal mcc_stb_inner  : std_logic_vector (MCC_W-1 downto 0) := (others => '0');
47   signal mux_code_inner : std_logic_vector (MUX_W-1 downto 0);
48   signal mcc_exec       : std_logic := '0';
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 rising_edge(CLK_I) then
71       if RST_I = '1' then
72         mcc_ack_inner <= (others => '0');
73         mcc_stb_inner <= (others => '0');
74
75       else
76         if mcc_exec = '0' then
77           mcc_ack_inner <= (others => '0');
78           mcc_stb_inner <= (others => '0');
79           
80         else
81           mcc_ack_inner (0) <= mcc_exec;
82           
83           for i in 0 to MCC_W-1 loop
84             if mcc_mask (i) = '1' then
85               mcc_ack_inner (i+1) <= MCC_ACK_I (i);
86               mcc_stb_inner (i)   <= mcc_ack_inner (i);
87             else
88               mcc_ack_inner (i+1) <= mcc_ack_inner (i);
89               mcc_stb_inner (i)   <= '0';
90             end if;
91           end loop;
92         end if;
93       end if;
94     end if;
95   end process;
96
97   
98   LATCHES : process (RST_I, CLK_I) is
99   begin
100     if RST_I = '1' then
101       MCC_STB_O    <= (others => '0');
102       MCC_MUX_CODE <= (others => '0');
103
104     elsif rising_edge(CLK_I) then
105       MCC_STB_O    <= mcc_stb_inner;
106       MCC_MUX_CODE <= mux_code_inner;
107     end if;
108   end process;
109
110   
111   FSM : process (CLK_I, RST_I) is
112   begin
113     if RST_I = '1' then
114       state      <= ready;
115       ACK_O      <= '0';
116       mcc_exec   <= '0';
117       MCC_MUX_EN <= '0';
118       IRF_STB_O  <= '0';
119       
120     elsif rising_edge(CLK_I) then
121       case state is
122         when ready =>
123           if STB_I = '1' then
124             state     <= read_mask;
125             IRF_STB_O <= '1';
126           end if;
127
128         when read_mask =>
129           if IRF_ACK_I = '1' then
130             state      <= do_mcc;
131             mcc_mask   <= IRF_DAT_I (mcc_mask'RANGE);
132             MCC_MUX_EN <= '1';
133             mcc_exec   <= '1';
134           end if;
135
136         when do_mcc =>
137           if mcc_ack_inner (MCC_W) = '1' then
138             state      <= done;
139             ACK_O      <= '1';
140             IRF_STB_O  <= '0';
141             MCC_MUX_EN <= '0';
142             mcc_exec   <= '0';
143           end if;
144
145         when done =>
146           if STB_I = '0' then
147             state <= ready;
148             ACK_O <= '0';
149           end if;
150       end case;      
151     end if;
152   end process;
153   
154 end architecture behavioral;
155