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 73

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

powered by: WebSVN 2.1.0

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