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 38

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

powered by: WebSVN 2.1.0

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