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 26

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 26 gedra
-- $Log: not supported by cvs2svn $
49
-- Revision 1.1  2004/06/13 18:07:47  gedra
50
-- Frame decoder and sample extractor
51
--                        
52 18 gedra
--
53
 
54
library ieee;
55
use ieee.std_logic_1164.all;
56
use ieee.std_logic_arith.all;
57
 
58
entity rx_decode is
59
  generic (DATA_WIDTH: integer range 16 to 32;
60
           ADDR_WIDTH: integer range 8 to 64);
61
  port (
62
    wb_clk_i: in std_logic;
63
    conf_rxen: in std_logic;
64
    conf_sample: in std_logic;
65
    conf_valid: in std_logic;
66
    conf_mode: in std_logic_vector(3 downto 0);
67
    conf_blken: in std_logic;
68
    conf_valen: in std_logic;
69
    conf_useren: in std_logic;
70
    conf_staten: in std_logic;
71
    conf_paren: in std_logic;
72
    lock: in std_logic;
73
    rx_data: in std_logic;
74
    rx_data_en: in std_logic;
75
    rx_block_start: in std_logic;
76
    rx_frame_start: in std_logic;
77
    rx_channel_a: in std_logic;
78
    wr_en: out std_logic;
79
    wr_addr: out std_logic_vector(ADDR_WIDTH - 2 downto 0);
80 26 gedra
    wr_data: out std_logic_vector(DATA_WIDTH -1 downto 0);
81 18 gedra
    stat_paritya: out std_logic;
82
    stat_parityb: out std_logic;
83
    stat_lsbf: out std_logic;
84
    stat_hsbf: out std_logic);
85
end rx_decode;
86
 
87
architecture rtl of rx_decode is
88
 
89
  signal adr_cnt : integer range 0 to 2**(ADDR_WIDTH - 1) - 1;
90
  type samp_states is (IDLE, CHA_SYNC, GET_SAMP, PAR_CHK);
91
  signal sampst : samp_states;
92
  signal bit_cnt, par_cnt : integer range 0 to 31;
93
  signal samp_start : integer range 0 to 15;
94
  signal tmp_data : std_logic_vector(DATA_WIDTH - 6 downto 0);
95
  signal tmp_stat : std_logic_vector(4 downto 0);
96
  signal valid, next_is_a, blk_start : std_logic;
97
 
98
begin
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 26 gedra
          wr_addr <= CONV_STD_LOGIC_VECTOR(adr_cnt, ADDR_WIDTH - 1);
132 18 gedra
          wr_en <= '0';
133
          bit_cnt <= 0;
134
          valid <= '0';
135
          par_cnt <= 0;
136
          stat_paritya <= '0';
137
          stat_parityb <= '0';
138
          stat_lsbf <= '0';
139
          stat_hsbf <= '0';
140
          tmp_data(DATA_WIDTH - 6 downto 0) <= (others => '0');
141
          if rx_block_start = '1' and conf_blken = '1' then
142
            blk_start <= '1';
143
          end if;
144
          if rx_frame_start = '1' and rx_channel_a = next_is_a then
145
            next_is_a <= not next_is_a;
146
            sampst <= GET_SAMP;
147
          end if;
148
        when GET_SAMP =>
149
          tmp_stat(0) <= blk_start;
150
          if rx_data_en = '1' then
151 26 gedra
            bit_cnt <= bit_cnt + 1;
152 18 gedra
            -- audio part
153
            if bit_cnt >= samp_start and bit_cnt <= 23 then
154
              tmp_data(bit_cnt - samp_start) <= rx_data;
155
            end if;
156
            -- status bits
157
            case bit_cnt is
158
              when 24 =>                -- validity bit
159
                valid <= rx_data;
160
                if conf_valen = '1' then
161
                  tmp_stat(1) <= rx_data;
162
                else
163
                  tmp_stat(1) <= '0';
164
                end if;
165
              when 25 =>                -- user data
166
                if conf_useren = '1' then
167
                  tmp_stat(2) <= rx_data;
168
                else
169
                  tmp_stat(2) <= '0';
170
                end if;
171
              when 26 =>                -- channel status
172
                if conf_staten = '1' then
173
                  tmp_stat(3) <= rx_data;
174
                else
175
                  tmp_stat(3) <= '0';
176
                end if;
177
              when 27 =>                -- parity bit
178
                if conf_paren = '1' then
179
                  tmp_stat(4) <= rx_data;
180
                else
181
                  tmp_stat(4) <= '0';
182
                end if;
183
              when others =>
184
                null;
185
            end case;
186
            -- parity: count number of 1's
187 26 gedra
            if rx_data = '1' then
188
              par_cnt <= par_cnt + 1;
189
            end if;
190 18 gedra
          end if;
191 26 gedra
          if bit_cnt = 28 then
192 18 gedra
            sampst <= PAR_CHK;
193
          end if;
194
        when PAR_CHK =>
195
          blk_start <= '0';
196
          if (valid = '0' and conf_valen = '1') or conf_valen = '0' then
197
            wr_en <= '1';
198
          end if;
199
          -- parity check
200
          if par_cnt mod 2 /= 0 then
201
            if rx_channel_a = '1' then
202
              stat_paritya <= '1';
203
            else
204
              stat_parityb <= '1';
205
            end if;
206
          end if;
207
          -- address counter
208
          if adr_cnt < 2**(ADDR_WIDTH - 1) - 1 then
209
            adr_cnt <= adr_cnt + 1;
210
          else
211
            adr_cnt <= 0;
212
            stat_hsbf <= '1';           -- signal high buffer full
213
          end if;
214
          if adr_cnt = 2**(ADDR_WIDTH - 2) - 1 then
215
            stat_lsbf <= '1';           -- signal low buffer full
216
          end if;
217
          sampst <= CHA_SYNC;
218
        when others =>
219
          sampst <= IDLE;
220
      end case;
221
    end if;
222
  end process SAEX;
223
 
224
-- determine sample resolution from mode bits in 32bit mode
225
  M32: if DATA_WIDTH = 32 generate
226
    samp_start <= 8 when conf_mode = "0000" else
227
                  7 when conf_mode = "0001" else
228
                  6 when conf_mode = "0010" else
229
                  5 when conf_mode = "0011" else
230
                  4 when conf_mode = "0100" else
231
                  3 when conf_mode = "0101" else
232
                  2 when conf_mode = "0110" else
233
                  1 when conf_mode = "0111" else
234
 
235
                  8;
236
  end generate M32;
237
-- in 16bit mode onyl 16bit of audio is supported 
238
  M16: if DATA_WIDTH = 16 generate
239
    samp_start <= 8;
240
  end generate M16;
241
 
242
 
243
end rtl;

powered by: WebSVN 2.1.0

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