OpenCores
URL https://opencores.org/ocsvn/spdif_interface/spdif_interface/trunk

Subversion Repositories spdif_interface

[/] [spdif_interface/] [trunk/] [rtl/] [vhdl/] [rx_cap_reg.vhd] - Blame information for rev 62

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 gedra
----------------------------------------------------------------------
2
----                                                              ----
3
---- WISHBONE SPDIF IP Core                                       ----
4
----                                                              ----
5
---- This file is part of the SPDIF project                       ----
6
---- http://www.opencores.org/cores/spdif_interface/              ----
7
----                                                              ----
8
---- Description                                                  ----
9
---- SPDIF receiver channel status capture module                 ----
10
----                                                              ----
11
----                                                              ----
12
---- To Do:                                                       ----
13
---- -                                                            ----
14
----                                                              ----
15
---- Author(s):                                                   ----
16
---- - Geir Drange, gedra@opencores.org                           ----
17
----                                                              ----
18
----------------------------------------------------------------------
19
----                                                              ----
20
---- Copyright (C) 2004 Authors and OPENCORES.ORG                 ----
21
----                                                              ----
22
---- This source file may be used and distributed without         ----
23
---- restriction provided that this copyright statement is not    ----
24
---- removed from the file and that any derivative work contains  ----
25
---- the original copyright notice and the associated disclaimer. ----
26
----                                                              ----
27
---- This source file is free software; you can redistribute it   ----
28
---- and/or modify it under the terms of the GNU Lesser General   ----
29
---- Public License as published by the Free Software Foundation; ----
30
---- either version 2.1 of the License, or (at your option) any   ----
31
---- later version.                                               ----
32
----                                                              ----
33
---- This source is distributed in the hope that it will be       ----
34
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
35
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
36
---- PURPOSE. See the GNU Lesser General Public License for more  ----
37
---- details.                                                     ----
38
----                                                              ----
39
---- You should have received a copy of the GNU Lesser General    ----
40
---- Public License along with this source; if not, download it   ----
41
---- from http://www.opencores.org/lgpl.shtml                     ----
42
----                                                              ----
43
----------------------------------------------------------------------
44
--
45
-- CVS Revision History
46
--
47
-- $Log: not supported by cvs2svn $
48 62 gedra
-- Revision 1.4  2004/07/19 16:58:37  gedra
49
-- Fixed bug.
50
--
51 58 gedra
-- Revision 1.3  2004/06/27 16:16:55  gedra
52
-- Signal renaming and bug fix.
53
--
54 38 gedra
-- Revision 1.2  2004/06/26 14:14:47  gedra
55
-- Converted to numeric_std and fixed a few bugs.
56
--
57 37 gedra
-- Revision 1.1  2004/06/05 17:16:46  gedra
58
-- Channel status/user data capture register
59 9 gedra
--
60 37 gedra
--
61 9 gedra
 
62 37 gedra
library ieee;
63
use ieee.std_logic_1164.all;
64
use ieee.numeric_std.all;
65 9 gedra
use work.rx_package.all;
66
 
67
entity rx_cap_reg is
68
  port (
69
    clk: in std_logic;                  -- clock
70
    rst: in std_logic; -- reset
71
    cap_ctrl_wr: in std_logic; -- control register write        
72
    cap_ctrl_rd: in std_logic; -- control register read
73
    cap_data_rd: in std_logic;          -- data register read
74
    cap_din: in std_logic_vector(31 downto 0); -- write data
75 38 gedra
    rx_block_start: in std_logic; -- start of block signal
76 9 gedra
    ch_data: in std_logic;  -- channel status/user data
77
    ud_a_en: in std_logic;            -- user data ch. A enable
78
    ud_b_en: in std_logic;              -- user data ch. B enable
79
    cs_a_en: in std_logic;              -- channel status ch. A enable
80
    cs_b_en: in std_logic;              -- channel status ch. B enable
81
    cap_dout: out std_logic_vector(31 downto 0); -- read data
82
    cap_evt: out std_logic);             -- capture event (interrupt)
83
end rx_cap_reg;
84
 
85
architecture rtl of rx_cap_reg is
86
 
87
  signal cap_ctrl_bits, cap_ctrl_dout: std_logic_vector(31 downto 0);
88
  signal cap_reg, cap_new : std_logic_vector(31 downto 0);
89
  signal bitlen, cap_len : integer range 0 to 63;
90
  signal bitpos, cur_pos : integer range 0 to 255;
91
  signal chid, cdata, compared : std_logic;
92
  signal d_enable : std_logic_vector(3 downto 0);
93
 
94
begin
95
 
96
-- Data bus or'ing
97
  cap_dout <= cap_reg when cap_data_rd = '1' else cap_ctrl_dout;
98
 
99
-- Capture control register
100
  CREG: gen_control_reg
101
    generic map (
102
      DATA_WIDTH => 32,
103
      ACTIVE_BIT_MASK => "11111111111111110000000000000000")
104
    port map (
105
      clk => clk,
106
      rst => rst,
107
      ctrl_wr => cap_ctrl_wr,
108
      ctrl_rd => cap_ctrl_rd,
109
      ctrl_din => cap_din,
110
      ctrl_dout => cap_ctrl_dout,
111
      ctrl_bits => cap_ctrl_bits);
112
 
113
  chid <= cap_ctrl_bits(6);
114
  cdata <= cap_ctrl_bits(7);
115
 
116
-- capture data register
117
  CDAT: process (clk, rst)
118
    begin
119
      if rst = '1' then
120
        cap_reg <= (others => '0');
121
        cap_new <= (others => '0');
122
        cur_pos <= 0;
123
        cap_len <= 0;
124
        cap_evt <= '0';
125 62 gedra
        compared <= '0';
126
        bitpos <= 0;
127
        bitlen <= 0;
128 9 gedra
      else
129
        if rising_edge(clk) then
130 58 gedra
          bitlen <= to_integer(unsigned(cap_ctrl_bits(5 downto 0)));
131
          bitpos <= to_integer(unsigned(cap_ctrl_bits(15 downto 8)));
132 9 gedra
          if bitlen > 0 then    -- bitlen = 0 disables the capture function
133
            -- bit counter, 0 to 191
134 38 gedra
            if rx_block_start = '1' then
135 9 gedra
              cur_pos <= 0;
136
              cap_len <= 0;
137
              cap_new <= (others => '0');
138
              compared <= '0';
139
            elsif cs_b_en = '1' then -- ch. status #2 comes last, count then
140
              cur_pos <= cur_pos + 1;
141
            end if;
142
            -- capture bits
143
            if cur_pos >= bitpos and cap_len < bitlen then
144
              case d_enable is
145
                when "0001" =>          -- user data channel A
146
                  if cdata = '0' and chid = '0' then
147 58 gedra
                    cap_new(cap_len) <= ch_data;
148 9 gedra
                    cap_len <= cap_len + 1;
149
                  end if;
150
                when "0010" =>          -- user data channel B
151
                  if cdata = '0' and chid = '1' then
152 58 gedra
                    cap_new(cap_len) <= ch_data;
153 9 gedra
                    cap_len <= cap_len + 1;
154
                  end if;
155
                when "0100" =>          -- channel status ch. A
156
                  if cdata = '1' and chid = '0' then
157 58 gedra
                    cap_new(cap_len) <= ch_data;
158 9 gedra
                    cap_len <= cap_len + 1;
159
                  end if;
160
                when "1000" =>          -- channel status ch. B
161
                  if cdata = '1' and chid = '1' then
162 58 gedra
                    cap_new(cap_len) <= ch_data;
163 9 gedra
                    cap_len <= cap_len + 1;
164
                  end if;
165
                when others => null;
166
              end case;
167
            end if;
168
            -- if all bits captured, check with previous data
169
            if cap_len = bitlen and compared = '0' then
170
              compared <= '1';
171
              -- event generated if captured bits differ
172 37 gedra
              if cap_reg /= cap_new then
173 9 gedra
                cap_evt <= '1';
174
              end if;
175
              cap_reg <= cap_new;
176
            else
177
              cap_evt <= '0';
178
            end if;
179
          end if;
180
        end if;
181
      end if;
182
    end process CDAT;
183
 
184
    d_enable(0) <= ud_a_en;
185
    d_enable(1) <= ud_b_en;
186
    d_enable(2) <= cs_a_en;
187
    d_enable(3) <= cs_b_en;
188
 
189
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.