]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - pwm_min_dump.vhd
Wave_table initialization data format modified.
[fpga/pwm.git] / pwm_min_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_min_dump is
9   generic (
10     IRF_ADR_W  : integer := 5;
11     BASE       : integer := 0;
12     PWMMIN_OFF : integer := 6;
13     P_BASE     : integer := 16;
14     PWM_OFF    : integer := 1;
15     PWM_W      : integer := 10);
16   port (
17     -- Primary slave intefrace
18     ACK_O     : out std_logic;
19     CLK_I     : in  std_logic;
20     RST_I     : in  std_logic;
21     STB_I     : in  std_logic;
22     -- PWM interface
23     PWM_DAT_O : out std_logic_vector (PWM_W-1 downto 0);
24     PWM_STB_O : out std_logic := '0';
25     -- Shared dual-port memory
26     IRF_ACK_I : in  std_logic;
27     IRF_ADR_O : out std_logic_vector (IRF_ADR_W-1 downto 0);
28     IRF_DAT_I : in  std_logic_vector (15 downto 0);
29     IRF_STB_O : out std_logic);
30 end entity pwm_min_dump;
31
32 --------------------------------------------------------------------------------
33
34 architecture behavioral of pwm_min_dump is
35
36   type state_t is (ready, dump, done);
37   subtype irf_adr_t is std_logic_vector (IRF_ADR_W-1 downto 0);
38
39   constant PWMMIN_ADR : irf_adr_t := conv_std_logic_vector(BASE+PWMMIN_OFF, IRF_ADR_W);
40   constant PWM_ADR    : irf_adr_t := conv_std_logic_vector(P_BASE + PWM_OFF, IRF_ADR_W);
41   
42   signal state : state_t := ready;
43
44   signal ack     : std_logic := '0';
45   --signal pwm_min : std_logic_vector (PWM_DAT_O'RANGE);
46   signal pwm_min : std_logic_vector (PWM_DAT_O'range);
47   signal pwm_stb : std_logic := '0';
48   signal irf_adr : irf_adr_t := PWMMIN_ADR;
49   signal irf_we  : std_logic := '0';
50   
51 --------------------------------------------------------------------------------
52
53 begin
54
55   ACK_O <= STB_I and ack;
56
57   PWM_DAT_O <= IRF_DAT_I(pwm_min'RANGE) - pwm_min;
58   PWM_STB_O <= pwm_stb;
59   
60   IRF_ADR_O <= irf_adr;
61   IRF_STB_O <= STB_I;
62
63   
64   FSM : process (CLK_I, RST_I) is
65   begin
66     if RST_I = '1' then
67       state   <= ready;
68       ack     <= '0';
69       irf_adr <= PWMMIN_ADR;
70       pwm_stb <= '0';
71       
72     elsif rising_edge(CLK_I) then
73       case state is
74         when ready =>
75           if STB_I = '1' then
76             state   <= dump;
77             irf_adr <= PWM_ADR;
78           end if;
79           
80         when dump =>
81           state   <= done;
82           ack     <= '1';
83           pwm_stb <= '1';
84           pwm_min <= IRF_DAT_I(pwm_min'RANGE);
85
86         when done =>
87           pwm_stb <= '0';
88           if STB_I = '0' then
89             state   <= ready;
90             ack     <= '0';
91             irf_adr <= PWMMIN_ADR;
92           end if;
93       end case;
94     end if;
95   end process;
96   
97 end architecture behavioral;
98