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 58

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

powered by: WebSVN 2.1.0

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