]> rtime.felk.cvut.cz Git - fpga/virtex2/uart.git/blob - omsp_quadcount.vhd
Peripheral connected to the quadcount module and an incremental encoder. Interrupt...
[fpga/virtex2/uart.git] / omsp_quadcount.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 entity omsp_quadcount is
7   port (
8     mclk        : in  std_logic;
9     per_addr    : in  std_logic_vector (7  downto 0);
10     per_din     : in  std_logic_vector (15 downto 0);  -- unused
11     per_en      : in  std_logic;
12     per_wen     : in  std_logic_vector (1  downto 0);  -- unused
13     puc         : in  std_logic;                       -- unused
14     per_irq_acc : in  std_logic;                       -- unused
15     per_irq     : out std_logic;
16     per_dout    : out std_logic_vector (15 downto 0);
17     
18     qcount      : in  std_logic_vector (31 downto 0)
19   );
20 end omsp_quadcount;
21
22 --------------------------------------------------------------------------------
23
24 architecture behavioral of omsp_quadcount is
25
26   -- When reading whole 32-bit qcount input, first QCNTL has to be loaded, because
27   -- this event causes QCNTH to latch appropriate value of qcount. This procedure
28   -- ensures that correct value is readed.
29   constant QCNTL : std_logic_vector (15 downto 0) := X"0150";  -- qcount lower word logic address
30   constant QCNTH : std_logic_vector (15 downto 0) := X"0152";  -- qcount higher word logic address
31
32   signal qcntl_sel : boolean;
33   signal qcnth_sel : boolean;
34
35   signal qcnth_latch : std_logic_vector (15 downto 0) := (others => '0');
36
37   signal qcount_prev : std_logic_vector (31 downto 0) := (others => '0');
38
39 --------------------------------------------------------------------------------
40
41 begin
42
43   qcntl_sel <= (per_addr = QCNTL(8 downto 1)) and (per_en = '1');
44   qcnth_sel <= (per_addr = QCNTH(8 downto 1)) and (per_en = '1');
45
46   per_dout <= qcount (15 downto 0) when qcntl_sel else
47               qcnth_latch          when qcnth_sel else
48               (others => '0');
49
50
51   process (mclk)
52   begin
53     if (rising_edge(mclk) and qcntl_sel) then
54       qcnth_latch <= qcount (31 downto 16);
55     end if;
56   end process;
57
58   -- Generation of IRQ signal. (changes in lower 2 bits are suppresed)
59   process (mclk)
60   begin
61     if (rising_edge(mclk)) then
62       qcount_prev <= qcount;
63       
64       if (qcntl_sel) then
65         per_irq <= '0';
66       elsif (qcount_prev (31 downto 2) /= qcount (31 downto 2)) then
67         per_irq <= '1';
68       end if;
69     end if;
70   end process;
71
72 end behavioral;
73