]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - pwm_dump.vhd
Added irc_dump.
[fpga/pwm.git] / pwm_dump.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 pwm_dump is
9   generic (
10     IRF_ADR_W : integer := 5;
11     P_BASE    : integer := 16;
12     PWM_OFF   : integer := 1;
13     PWM_W     : integer := 10);
14   port (
15     -- Primary slave intefrace
16     ACK_O     : out std_logic;
17     CLK_I     : in  std_logic;
18     RST_I     : in  std_logic;
19     STB_I     : in  std_logic;
20     -- PWM interface
21     PWM_DAT_O : out std_logic_vector (PWM_W-1 downto 0);
22     PWM_STB_O : out std_logic;
23     -- Shared dual-port memory
24     IRF_ACK_I : in  std_logic;
25     IRF_ADR_O : out std_logic_vector (IRF_ADR_W-1 downto 0);
26     IRF_DAT_I : in  std_logic_vector (15 downto 0);
27     IRF_STB_O : out std_logic);
28 end entity pwm_dump;
29
30 --------------------------------------------------------------------------------
31
32 architecture behavioral of pwm_dump is
33
34   type state_t is (ready, done);
35   subtype irf_adr_t is std_logic_vector (IRF_ADR_W-1 downto 0);
36
37   constant PWM_ADR : irf_adr_t :=  conv_std_logic_vector(P_BASE + PWM_OFF, 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   PWM_DAT_O <= IRF_DAT_I (PWM_DAT_O'RANGE);
50   
51   IRF_ADR_O <= PWM_ADR;
52   IRF_STB_O <= STB_I;
53
54   
55   FSM : process (CLK_I, RST_I) is
56   begin
57     if RST_I = '1' then
58       state     <= ready;
59       INNER_ACK <= '0';
60       PWM_STB_O <= '0';
61       
62     elsif rising_edge(CLK_I) then
63       case state is
64         when ready =>
65           if STB_I = '1' then
66             state     <= done;
67             INNER_ACK <= '1';
68             PWM_STB_O <= '1';
69           end if;
70
71         when done =>
72           PWM_STB_O <= '0';
73           if STB_I = '0' then
74             state     <= ready;
75             INNER_ACK <= '0';
76           end if;
77       end case;
78     end if;
79   end process;
80   
81 end architecture behavioral;
82