]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - sequencer.vhd
PWM_dump added to the MCC a its test bench.
[fpga/pwm.git] / sequencer.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 sequencer is
9   generic (
10     IRF_ADR_W : integer := 5;
11     P_BASE    : integer := 16;
12     P_SIZE    : integer := 4);
13   port (
14     -- Primary slave interface
15     ACK_O        : out std_logic;
16     CLK_I        : in  std_logic;
17     RST_I        : in  std_logic;
18     STB_I        : in  std_logic;
19     -- Dual-port memory interface
20     IRF_ADR_O    : out std_logic_vector (IRF_ADR_W-1 downto 0);
21     -- Slave interface
22     SL_ACK_I     : in  std_logic;
23     SL_IRF_ADR_I : in  std_logic_vector (IRF_ADR_W-1 downto 0);
24     SL_STB_O     : out std_logic;
25     SL_MUX_CODE  : out std_logic_vector (1 downto 0));
26 end entity sequencer;
27
28 --------------------------------------------------------------------------------
29
30 architecture behavioral of sequencer is
31
32   type state_t is (ready, phase1, phase2, phase3, done);
33   subtype irf_adr_t is std_logic_vector (IRF_ADR_W-1 downto 0);
34
35   constant P1_MASK: irf_adr_t := conv_std_logic_vector(P_BASE+0*P_SIZE, IRF_ADR_W);
36   constant P2_MASK: irf_adr_t := conv_std_logic_vector(P_BASE+1*P_SIZE, IRF_ADR_W);
37   constant P3_MASK: irf_adr_t := conv_std_logic_vector(P_BASE+2*P_SIZE, IRF_ADR_W);
38
39   signal state     : state_t;
40
41   signal INNER_ACK : std_logic;
42
43 --------------------------------------------------------------------------------
44
45 begin
46
47   ACK_O <= STB_I and INNER_ACK;
48
49   IRF_ADR_O <= SL_IRF_ADR_I when conv_integer(SL_IRF_ADR_I) < P_BASE else
50                SL_IRF_ADR_I or P1_MASK when state = phase1 else
51                SL_IRF_ADR_I or P2_MASK when state = phase2 else
52                SL_IRF_ADR_I or P3_MASK when state = phase3 else
53                (others => '-');
54
55   SL_MUX_CODE <= "00" when state = phase1 else
56                  "01" when state = phase2 else
57                  "10" when state = phase3 else
58                  "--";
59
60
61   FSM : process (CLK_I, RST_I) is
62   begin
63     if RST_I = '1' then
64       state     <= ready;
65       INNER_ACK <= '0';
66       SL_STB_O  <= '0';
67
68     elsif rising_edge(CLK_I) then
69       case state is
70         when ready =>
71           if STB_I = '1' then
72             state    <= phase1;
73             SL_STB_O <= '1';
74           end if;
75
76         when phase1 =>
77           if SL_ACK_I = '1' then
78             state    <= phase2;
79             SL_STB_O <= '0';
80           end if;
81           
82         when phase2 =>
83           SL_STB_O <= '1';
84           if SL_ACK_I = '1' then
85             state    <= phase3;
86             SL_STB_O <= '0';
87           end if;
88
89         when phase3 =>
90           SL_STB_O <= '1';
91           if SL_ACK_I = '1' then
92             state     <= done;
93             INNER_ACK <= '1';
94             SL_STB_O  <= '0';
95           end if;
96
97         when done =>
98           if STB_I = '0' then
99             state     <= ready;
100             INNER_ACK <= '0';
101           end if;
102       end case;
103     end if;
104   end process;
105
106 end architecture behavioral;
107