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 37

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 37 gedra
-- Revision 1.1  2004/06/05 17:16:46  gedra
49
-- Channel status/user data capture register
50 9 gedra
--
51 37 gedra
--
52 9 gedra
 
53 37 gedra
library ieee;
54
use ieee.std_logic_1164.all;
55
use ieee.numeric_std.all;
56 9 gedra
use work.rx_package.all;
57
 
58
entity rx_cap_reg is
59
  port (
60
    clk: in std_logic;                  -- clock
61
    rst: in std_logic; -- reset
62
    cap_ctrl_wr: in std_logic; -- control register write        
63
    cap_ctrl_rd: in std_logic; -- control register read
64
    cap_data_rd: in std_logic;          -- data register read
65
    cap_din: in std_logic_vector(31 downto 0); -- write data
66
    frame_rst: in std_logic; -- start of frame signal
67
    ch_data: in std_logic;  -- channel status/user data
68
    ud_a_en: in std_logic;            -- user data ch. A enable
69
    ud_b_en: in std_logic;              -- user data ch. B enable
70
    cs_a_en: in std_logic;              -- channel status ch. A enable
71
    cs_b_en: in std_logic;              -- channel status ch. B enable
72
    cap_dout: out std_logic_vector(31 downto 0); -- read data
73
    cap_evt: out std_logic);             -- capture event (interrupt)
74
end rx_cap_reg;
75
 
76
architecture rtl of rx_cap_reg is
77
 
78
  signal cap_ctrl_bits, cap_ctrl_dout: std_logic_vector(31 downto 0);
79
  signal cap_reg, cap_new : std_logic_vector(31 downto 0);
80
  signal bitlen, cap_len : integer range 0 to 63;
81
  signal bitpos, cur_pos : integer range 0 to 255;
82
  signal chid, cdata, compared : std_logic;
83
  signal d_enable : std_logic_vector(3 downto 0);
84
 
85
begin
86
 
87
-- Data bus or'ing
88
  cap_dout <= cap_reg when cap_data_rd = '1' else cap_ctrl_dout;
89
 
90
-- Capture control register
91
  CREG: gen_control_reg
92
    generic map (
93
      DATA_WIDTH => 32,
94
      ACTIVE_BIT_MASK => "11111111111111110000000000000000")
95
    port map (
96
      clk => clk,
97
      rst => rst,
98
      ctrl_wr => cap_ctrl_wr,
99
      ctrl_rd => cap_ctrl_rd,
100
      ctrl_din => cap_din,
101
      ctrl_dout => cap_ctrl_dout,
102
      ctrl_bits => cap_ctrl_bits);
103
 
104 37 gedra
  bitlen <= to_integer(unsigned(cap_ctrl_bits(5 downto 0)));
105 9 gedra
  chid <= cap_ctrl_bits(6);
106
  cdata <= cap_ctrl_bits(7);
107 37 gedra
  bitpos <= to_integer(unsigned(cap_ctrl_bits(15 downto 8)));
108 9 gedra
 
109
-- capture data register
110
  CDAT: process (clk, rst)
111
    begin
112
      if rst = '1' then
113
        cap_reg <= (others => '0');
114
        cap_new <= (others => '0');
115
        cur_pos <= 0;
116
        cap_len <= 0;
117
        cap_evt <= '0';
118
      else
119
        if rising_edge(clk) then
120
          if bitlen > 0 then    -- bitlen = 0 disables the capture function
121
            -- bit counter, 0 to 191
122
            if frame_rst = '1' then
123
              cur_pos <= 0;
124
              cap_len <= 0;
125
              cap_new <= (others => '0');
126
              compared <= '0';
127
            elsif cs_b_en = '1' then -- ch. status #2 comes last, count then
128
              cur_pos <= cur_pos + 1;
129
            end if;
130
            -- capture bits
131
            if cur_pos >= bitpos and cap_len < bitlen then
132
              case d_enable is
133
                when "0001" =>          -- user data channel A
134
                  if cdata = '0' and chid = '0' then
135
                    cap_new(0) <= ch_data;
136
                    cap_new(31 downto 1) <= cap_new(30 downto 0);
137
                    cap_len <= cap_len + 1;
138
                  end if;
139
                when "0010" =>          -- user data channel B
140
                  if cdata = '0' and chid = '1' then
141
                    cap_new(0) <= ch_data;
142
                    cap_new(31 downto 1) <= cap_new(30 downto 0);
143
                    cap_len <= cap_len + 1;
144
                  end if;
145
                when "0100" =>          -- channel status ch. A
146
                  if cdata = '1' and chid = '0' then
147
                    cap_new(0) <= ch_data;
148
                    cap_new(31 downto 1) <= cap_new(30 downto 0);
149
                    cap_len <= cap_len + 1;
150
                  end if;
151
                when "1000" =>          -- channel status ch. B
152
                  if cdata = '1' and chid = '1' then
153
                    cap_new(0) <= ch_data;
154
                    cap_new(31 downto 1) <= cap_new(30 downto 0);
155
                    cap_len <= cap_len + 1;
156
                  end if;
157
                when others => null;
158
              end case;
159
            end if;
160
            -- if all bits captured, check with previous data
161
            if cap_len = bitlen and compared = '0' then
162
              compared <= '1';
163
              -- event generated if captured bits differ
164 37 gedra
              if cap_reg /= cap_new then
165 9 gedra
                cap_evt <= '1';
166
              end if;
167
              cap_reg <= cap_new;
168
            else
169
              cap_evt <= '0';
170
            end if;
171
          end if;
172
        end if;
173
      end if;
174
    end process CDAT;
175
 
176
    d_enable(0) <= ud_a_en;
177
    d_enable(1) <= ud_b_en;
178
    d_enable(2) <= cs_a_en;
179
    d_enable(3) <= cs_b_en;
180
 
181
end rtl;

powered by: WebSVN 2.1.0

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