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

Subversion Repositories spdif_interface

[/] [spdif_interface/] [trunk/] [rtl/] [vhdl/] [rx_decode.vhd] - Blame information for rev 18

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

Line No. Rev Author Line
1 18 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
---- Sample decoder. Extract sample words and write to sample     ----
10
---- buffer.                                                      ----
11
----                                                              ----
12
----                                                              ----
13
---- To Do:                                                       ----
14
---- -                                                            ----
15
----                                                              ----
16
---- Author(s):                                                   ----
17
---- - Geir Drange, gedra@opencores.org                           ----
18
----                                                              ----
19
----------------------------------------------------------------------
20
----                                                              ----
21
---- Copyright (C) 2004 Authors and OPENCORES.ORG                 ----
22
----                                                              ----
23
---- This source file may be used and distributed without         ----
24
---- restriction provided that this copyright statement is not    ----
25
---- removed from the file and that any derivative work contains  ----
26
---- the original copyright notice and the associated disclaimer. ----
27
----                                                              ----
28
---- This source file is free software; you can redistribute it   ----
29
---- and/or modify it under the terms of the GNU Lesser General   ----
30
---- Public License as published by the Free Software Foundation; ----
31
---- either version 2.1 of the License, or (at your option) any   ----
32
---- later version.                                               ----
33
----                                                              ----
34
---- This source is distributed in the hope that it will be       ----
35
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
36
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
37
---- PURPOSE. See the GNU Lesser General Public License for more  ----
38
---- details.                                                     ----
39
----                                                              ----
40
---- You should have received a copy of the GNU Lesser General    ----
41
---- Public License along with this source; if not, download it   ----
42
---- from http://www.opencores.org/lgpl.shtml                     ----
43
----                                                              ----
44
----------------------------------------------------------------------
45
--
46
-- CVS Revision History
47
--
48
-- $Log: not supported by cvs2svn $                        
49
--
50
 
51
library ieee;
52
use ieee.std_logic_1164.all;
53
use ieee.std_logic_arith.all;
54
 
55
entity rx_decode is
56
  generic (DATA_WIDTH: integer range 16 to 32;
57
           ADDR_WIDTH: integer range 8 to 64);
58
  port (
59
    wb_clk_i: in std_logic;
60
    conf_rxen: in std_logic;
61
    conf_sample: in std_logic;
62
    conf_valid: in std_logic;
63
    conf_mode: in std_logic_vector(3 downto 0);
64
    conf_blken: in std_logic;
65
    conf_valen: in std_logic;
66
    conf_useren: in std_logic;
67
    conf_staten: in std_logic;
68
    conf_paren: in std_logic;
69
    lock: in std_logic;
70
    rx_data: in std_logic;
71
    rx_data_en: in std_logic;
72
    rx_block_start: in std_logic;
73
    rx_frame_start: in std_logic;
74
    rx_channel_a: in std_logic;
75
    wr_en: out std_logic;
76
    wr_addr: out std_logic_vector(ADDR_WIDTH - 2 downto 0);
77
    wr_data: out std_logic_vector(DATA_WIDTH downto 0);
78
    stat_paritya: out std_logic;
79
    stat_parityb: out std_logic;
80
    stat_lsbf: out std_logic;
81
    stat_hsbf: out std_logic);
82
end rx_decode;
83
 
84
architecture rtl of rx_decode is
85
 
86
  signal adr_cnt : integer range 0 to 2**(ADDR_WIDTH - 1) - 1;
87
  type samp_states is (IDLE, CHA_SYNC, GET_SAMP, PAR_CHK);
88
  signal sampst : samp_states;
89
  signal bit_cnt, par_cnt : integer range 0 to 31;
90
  signal samp_start : integer range 0 to 15;
91
  signal tmp_data : std_logic_vector(DATA_WIDTH - 6 downto 0);
92
  signal tmp_stat : std_logic_vector(4 downto 0);
93
  signal valid, next_is_a, blk_start : std_logic;
94
 
95
begin
96
 
97
-- sample buffer address
98
  wr_addr <= CONV_STD_LOGIC_VECTOR(adr_cnt, ADDR_WIDTH - 1);
99
 
100
-- output data
101
  OD32: if DATA_WIDTH = 32 generate
102
    wr_data(31 downto 27) <= tmp_stat;
103
    wr_data(26 downto 0) <= tmp_data(26 downto 0);
104
  end generate OD32;
105
  OD16: if DATA_WIDTH = 16 generate
106
    wr_data(15 downto 0) <= tmp_data(15 downto 0);
107
  end generate OD16;
108
 
109
-- State machine extracting audio samples
110
  SAEX: process (wb_clk_i, conf_rxen)
111
  begin  -- process SAEX
112
    if conf_rxen = '0' then
113
      adr_cnt <= 0;
114
      next_is_a <= '1';
115
      wr_en <= '0';
116
      par_cnt <= 0;
117
      blk_start <= '0';
118
      stat_paritya <= '0';
119
      stat_parityb <= '0';
120
      stat_lsbf <= '0';
121
      stat_hsbf <= '0';
122
    elsif rising_edge(wb_clk_i) then
123
      --extract and store samples
124
      case sampst is
125
        when IDLE =>
126
          next_is_a <= '1';
127
          if lock = '1' and conf_sample = '1' then
128
            sampst <= CHA_SYNC;
129
          end if;
130
        when CHA_SYNC =>
131
          wr_en <= '0';
132
          bit_cnt <= 0;
133
          valid <= '0';
134
          par_cnt <= 0;
135
          stat_paritya <= '0';
136
          stat_parityb <= '0';
137
          stat_lsbf <= '0';
138
          stat_hsbf <= '0';
139
          tmp_data(DATA_WIDTH - 6 downto 0) <= (others => '0');
140
          if rx_block_start = '1' and conf_blken = '1' then
141
            blk_start <= '1';
142
          end if;
143
          if rx_frame_start = '1' and rx_channel_a = next_is_a then
144
            next_is_a <= not next_is_a;
145
            sampst <= GET_SAMP;
146
          end if;
147
        when GET_SAMP =>
148
          tmp_stat(0) <= blk_start;
149
          if rx_data_en = '1' then
150
            -- audio part
151
            if bit_cnt >= samp_start and bit_cnt <= 23 then
152
              tmp_data(bit_cnt - samp_start) <= rx_data;
153
            end if;
154
            -- status bits
155
            case bit_cnt is
156
              when 24 =>                -- validity bit
157
                valid <= rx_data;
158
                if conf_valen = '1' then
159
                  tmp_stat(1) <= rx_data;
160
                else
161
                  tmp_stat(1) <= '0';
162
                end if;
163
              when 25 =>                -- user data
164
                if conf_useren = '1' then
165
                  tmp_stat(2) <= rx_data;
166
                else
167
                  tmp_stat(2) <= '0';
168
                end if;
169
              when 26 =>                -- channel status
170
                if conf_staten = '1' then
171
                  tmp_stat(3) <= rx_data;
172
                else
173
                  tmp_stat(3) <= '0';
174
                end if;
175
              when 27 =>                -- parity bit
176
                if conf_paren = '1' then
177
                  tmp_stat(4) <= rx_data;
178
                else
179
                  tmp_stat(4) <= '0';
180
                end if;
181
              when others =>
182
                null;
183
            end case;
184
            -- parity: count number of 1's
185
            par_cnt <= par_cnt + 1;
186
          end if;
187
          bit_cnt <= bit_cnt + 1;
188
          if bit_cnt = 27 then
189
            sampst <= PAR_CHK;
190
          end if;
191
        when PAR_CHK =>
192
          blk_start <= '0';
193
          if (valid = '0' and conf_valen = '1') or conf_valen = '0' then
194
            wr_en <= '1';
195
          end if;
196
          -- parity check
197
          if par_cnt mod 2 /= 0 then
198
            if rx_channel_a = '1' then
199
              stat_paritya <= '1';
200
            else
201
              stat_parityb <= '1';
202
            end if;
203
          end if;
204
          -- address counter
205
          if adr_cnt < 2**(ADDR_WIDTH - 1) - 1 then
206
            adr_cnt <= adr_cnt + 1;
207
          else
208
            adr_cnt <= 0;
209
            stat_hsbf <= '1';           -- signal high buffer full
210
          end if;
211
          if adr_cnt = 2**(ADDR_WIDTH - 2) - 1 then
212
            stat_lsbf <= '1';           -- signal low buffer full
213
          end if;
214
          sampst <= CHA_SYNC;
215
        when others =>
216
          sampst <= IDLE;
217
      end case;
218
    end if;
219
  end process SAEX;
220
 
221
-- determine sample resolution from mode bits in 32bit mode
222
  M32: if DATA_WIDTH = 32 generate
223
    samp_start <= 8 when conf_mode = "0000" else
224
                  7 when conf_mode = "0001" else
225
                  6 when conf_mode = "0010" else
226
                  5 when conf_mode = "0011" else
227
                  4 when conf_mode = "0100" else
228
                  3 when conf_mode = "0101" else
229
                  2 when conf_mode = "0110" else
230
                  1 when conf_mode = "0111" else
231
 
232
                  8;
233
  end generate M32;
234
-- in 16bit mode onyl 16bit of audio is supported 
235
  M16: if DATA_WIDTH = 16 generate
236
    samp_start <= 8;
237
  end generate M16;
238
 
239
 
240
end rtl;

powered by: WebSVN 2.1.0

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