]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - sequencer.vhd
Wave_table initialization data format modified.
[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 := '0';
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 := ready;
40
41   signal INNER_ACK : std_logic := '0';
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 rising_edge(CLK_I) then
64       if RST_I = '1' then
65         state     <= ready;
66         INNER_ACK <= '0';
67         SL_STB_O  <= '0';
68
69       else
70         case state is
71           when ready =>
72             if STB_I = '1' then
73               state    <= phase1;
74               SL_STB_O <= '1';
75             end if;
76
77           when phase1 =>
78             if SL_ACK_I = '1' then
79               state    <= phase2;
80               SL_STB_O <= '0';
81             end if;
82             
83           when phase2 =>
84             SL_STB_O <= '1';
85             if SL_ACK_I = '1' then
86               state    <= phase3;
87               SL_STB_O <= '0';
88             end if;
89
90           when phase3 =>
91             SL_STB_O <= '1';
92             if SL_ACK_I = '1' then
93               state     <= done;
94               INNER_ACK <= '1';
95               SL_STB_O  <= '0';
96             end if;
97
98           when done =>
99             if STB_I = '0' then
100               state     <= ready;
101               INNER_ACK <= '0';
102             end if;
103         end case;
104       end if;
105     end if;
106   end process;
107
108 end architecture behavioral;
109