]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - mcc_exec.vhd
Wave_table initialization data format modified.
[fpga/pwm.git] / mcc_exec.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 --------------------------------------------------------------------------------
7
8 entity mcc_exec is
9   generic (
10     AXIS_CNT   : integer := 1;
11     AXIS_CNT_W : integer := 1);
12   port (
13     -- Clock & reset
14     CLK_I     : in  std_logic;
15     RST_I     : in  std_logic;
16     -- MCC execution
17     MCC_AXIS_O    : out std_logic_vector (AXIS_CNT_W-1 downto 0);
18     MCC_DONE_O    : out std_logic;
19     MCC_EN_I      : in  std_logic;
20     MCC_EXEC_I    : in  std_logic;
21     MCC_ERR_O     : out std_logic;
22     -- MCC master interface
23     MCC_ACK_I : in  std_logic;
24     MCC_STB_O : out std_logic);
25 end entity mcc_exec;
26
27 --------------------------------------------------------------------------------
28
29 architecture behavioral of mcc_exec is
30
31   type state_t is (ready, do);
32
33   signal state : state_t := ready;
34   
35   signal mcc_axis : std_logic_vector (MCC_AXIS_O'range);
36   signal mcc_done : std_logic := '0';
37   signal mcc_stb  : std_logic := '0';
38   
39 --------------------------------------------------------------------------------
40
41 begin
42
43   assert (AXIS_CNT <= 2**AXIS_CNT_W)
44     report "Insufficient count of bits in MCC_AXIS_O to express axis number."
45     severity error;
46
47   
48   MCC_AXIS_O <= mcc_axis;
49   MCC_DONE_O <= mcc_done;
50   MCC_ERR_O  <= '1' when (MCC_EXEC_I = '1' and state = do) else '0';
51
52   MCC_STB_O  <= mcc_stb;
53
54   
55   FSM : process (CLK_I) is
56   begin
57     if rising_edge(CLK_I) then
58       if RST_I = '1' then
59         state    <= ready;
60         mcc_done <= '0';
61         mcc_stb  <= '0';
62
63       else
64         
65         case state is
66           when ready =>
67             mcc_stb  <= '0';
68             mcc_done <= '0';
69             
70             if MCC_EXEC_I = '1' and MCC_EN_I = '1' then
71               state    <= do;
72               mcc_stb  <= '1';
73               mcc_axis <= conv_std_logic_vector(0,AXIS_CNT_W);
74             end if;
75
76           when do =>
77             mcc_stb <= '1';
78
79             if MCC_ACK_I = '1' then
80               mcc_stb <= '0';
81
82               if mcc_axis = (AXIS_CNT-1) then
83                 state    <= ready;
84                 mcc_done <= '1';
85               else
86                 mcc_axis <= mcc_axis + 1;
87               end if;
88             end if;
89             
90         end case;
91       end if;
92     end if;
93   end process;
94   
95 end architecture behavioral;