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

Subversion Repositories spdif_interface

[/] [spdif_interface/] [trunk/] [bench/] [vhdl/] [spdif_source.vhd] - Blame information for rev 73

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 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
---- Generates a SPDIF signal with given sampling rate.           ----
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.3  2004/07/11 16:20:16  gedra
49
-- Improved test bench.
50
--
51 40 gedra
-- Revision 1.2  2004/06/06 15:45:24  gedra
52
-- Cleaned up lint warnings.
53
--
54 13 gedra
-- Revision 1.1  2004/06/03 17:45:18  gedra
55
-- SPDIF signal generator.
56 4 gedra
--
57 13 gedra
--
58 4 gedra
 
59 40 gedra
library ieee;
60
use ieee.std_logic_1164.all;
61 4 gedra
 
62 72 gedra
entity spdif_source is
63
   generic (FREQ : natural);            -- Sampling frequency in Hz
64
   port (                               -- Bitrate is 64x sampling frequency
65
      reset : in  std_logic;
66
      spdif : out std_logic);           -- Output bi-phase encoded signal
67 4 gedra
end spdif_source;
68
 
69 72 gedra
architecture behav of spdif_source is
70 4 gedra
 
71 72 gedra
   constant X_Preamble : std_logic_vector(7 downto 0) := "11100010";
72
   constant Y_Preamble : std_logic_vector(7 downto 0) := "11100100";
73
   constant Z_Preamble : std_logic_vector(7 downto 0) := "11101000";
74
   signal clk, ispdif  : std_logic;
75
   signal fcnt         : natural range 0 to 191;  -- frame counter
76
   signal bcnt         : natural range 0 to 63;   -- subframe bit counter
77
   signal pcnt         : natural range 0 to 63;   -- parity counter
78
   signal toggle       : integer range 0 to 1;
79
   -- Channel A: sinewave with frequency=Freq/12
80
   type sine16 is array (0 to 15) of std_logic_vector(15 downto 0);
81
   signal channel_a : sine16 := ((x"8000"), (x"b0fb"), (x"da82"), (x"f641"),
82
                                 (x"ffff"), (x"f641"), (x"da82"), (x"b0fb"),
83
                                 (x"8000"), (x"4f04"), (x"257d"), (x"09be"),
84
                                 (x"0000"), (x"09be"), (x"257d"), (x"4f04"));
85
   -- channel B: sinewave with frequency=Freq/24
86
   type sine8 is array (0 to 7) of std_logic_vector(15 downto 0);
87
   signal channel_b : sine8 := ((x"8000"), (x"da82"), (x"ffff"), (x"da82"),
88
                                (x"8000"), (x"257d"), (x"0000"), (x"257d"));
89
   signal channel_status : std_logic_vector(0 to 191);
90 4 gedra
 
91 40 gedra
begin
92 4 gedra
 
93 72 gedra
   spdif          <= ispdif;
94
   channel_status <= (others => '0');
95
 
96 4 gedra
-- Generate SPDIF signal 
97 72 gedra
   SGEN : process (clk, reset)
98
   begin
99
      if reset = '1' then
100
         fcnt   <= 184;  -- start just before block to shorten simulation
101
         bcnt   <= 0;
102
         toggle <= 0;
103
         ispdif <= '0';
104
         pcnt   <= 0;
105
      elsif rising_edge(clk) then
106
         if toggle = 1 then
107
            -- frame counter: 0 to 191
108
            if fcnt < 191 then
109
               if bcnt = 63 then
110
                  fcnt <= fcnt + 1;
111
               end if;
112
            else
113
               fcnt <= 0;
114
            end if;
115
            -- subframe bit counter: 0 to 63
116
            if bcnt < 63 then
117
               bcnt <= bcnt + 1;
118
            else
119
               bcnt <= 0;
120
            end if;
121
         end if;
122
         if toggle = 0 then
123
            toggle <= 1;
124
         else
125
            toggle <= 0;
126
         end if;
127
         -- subframe generation
128
         if fcnt = 0 and bcnt < 4 then
129
            ispdif <= Z_Preamble(7 - 2* bcnt - toggle);
130
         elsif fcnt > 0 and bcnt < 4 then
131
            ispdif <= X_Preamble(7 - 2 * bcnt - toggle);
132
         elsif bcnt > 31 and bcnt < 36 then
133
            ispdif <= Y_Preamble(71 - 2 * bcnt - toggle);
134
         end if;
135
         -- aux data, and 4 LSB are zero
136
         if (bcnt > 3 and bcnt < 12) or (bcnt > 35 and bcnt < 44) then
137
            if toggle = 0 then
138
               ispdif <= not ispdif;
139
            end if;
140
         end if;
141
         -- chanmel A data
142
         if (bcnt > 11) and (bcnt < 28) then
143
            if channel_a(fcnt mod 16)(bcnt - 12) = '0' then
144
               if toggle = 0 then
145
                  ispdif <= not ispdif;
146
               end if;
147
            else
148
               ispdif <= not ispdif;
149
               if toggle = 0 then
150
                  pcnt <= pcnt + 1;
151
               end if;
152
            end if;
153
         end if;
154
         -- channel B data
155
         if (bcnt > 43) and (bcnt < 60) then
156
            if channel_b(fcnt mod 8)(bcnt - 44) = '0' then
157
               if toggle = 0 then
158
                  ispdif <= not ispdif;
159
               end if;
160
            else
161
               ispdif <= not ispdif;
162
               if toggle = 0 then
163
                  pcnt <= pcnt + 1;
164
               end if;
165
            end if;
166
         end if;
167
         -- validity bit always 0
168
         if bcnt = 28 or bcnt = 60 then
169
            if toggle = 0 then
170
               ispdif <= not ispdif;
171
            end if;
172
         end if;
173
         -- user data always 0
174
         if bcnt = 29 or bcnt = 61 then
175
            if toggle = 0 then
176
               ispdif <= not ispdif;
177
            end if;
178
         end if;
179
         -- channel status bit
180
         if bcnt = 30 or bcnt = 62 then
181
            if channel_status(fcnt) = '0' then
182
               if toggle = 0 then
183
                  ispdif <= not ispdif;
184
               end if;
185
            else
186
               ispdif <= not ispdif;
187
               if toggle = 0 then
188
                  pcnt <= pcnt + 1;
189
               end if;
190
            end if;
191
         end if;
192
         -- parity bit, even parity
193
         if bcnt = 0 or bcnt = 32 then
194
            pcnt <= 0;
195
         end if;
196
         if bcnt = 31 or bcnt = 63 then
197
            if (pcnt mod 2) = 1 then
198
               ispdif <= not ispdif;
199
            else
200
               if toggle = 0 then
201
                  ispdif <= not ispdif;
202
               end if;
203
            end if;
204
         end if;
205 4 gedra
      end if;
206 72 gedra
   end process SGEN;
207
 
208 4 gedra
-- Clock process, generate a clock based on the desired sampling frequency    
209 72 gedra
   CLKG : process
210
      variable t1 : time := 1.0e12/real(FREQ*256) * 1 ps;
211
   begin
212
      clk <= '0';
213
      wait for t1;
214
      clk <= '1';
215
      wait for t1;
216
   end process CLKG;
217
 
218 4 gedra
end behav;

powered by: WebSVN 2.1.0

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