1 |
6 |
root |
library ieee;
|
2 |
|
|
use ieee.std_logic_1164.all;
|
3 |
|
|
use ieee.std_logic_unsigned.all;
|
4 |
|
|
use ieee.std_logic_arith.all;
|
5 |
|
|
entity ebu_2_i2s is
|
6 |
|
|
port(spdif_in : in std_logic; -- entree spdif
|
7 |
|
|
nreset : in std_logic; -- remise a 0
|
8 |
|
|
clock,ref_clock : in std_logic; -- a speed clock
|
9 |
|
|
sync_start : out std_ulogic; -- apres detection de preambule B
|
10 |
|
|
preambule_l : out std_ulogic; -- -decoded data
|
11 |
|
|
preambule_r : out std_ulogic; -- -decoded data
|
12 |
|
|
v_ctrl : out std_ulogic; -- -decoded data
|
13 |
|
|
pll_v_setting : OUT std_logic_vector(8 downto 0); -- PLL parameter V
|
14 |
|
|
pll_r_setting : OUT std_logic_vector(6 downto 0); -- PLL parameter R
|
15 |
|
|
pll_s_setting : OUT std_logic_vector(2 downto 0); -- PLL parameter S
|
16 |
|
|
pll_npd : OUT std_logic;
|
17 |
|
|
copie_d : out std_ulogic;
|
18 |
|
|
lr ,scl,serial_out : out std_ulogic; -- -decoded data
|
19 |
|
|
data_v ,fin : out std_ulogic;
|
20 |
|
|
begin_block : out std_ulogic -- -decoded data
|
21 |
|
|
-- sclk : out std_logic_vector(6 downto 0) -- -decoded data
|
22 |
|
|
-- bit_en,demi_bit_en : out std_logic -- -decoded data
|
23 |
|
|
);
|
24 |
|
|
end entity;
|
25 |
|
|
architecture archi of ebu_2_i2s is
|
26 |
|
|
|
27 |
|
|
constant v_24_576mhz : std_logic_vector(8 downto 0) := "101111000";
|
28 |
|
|
constant r_24_576mhz : std_logic_vector(6 downto 0) := "0010111";
|
29 |
|
|
constant s_24_576mhz : std_logic_vector(2 downto 0) := "100";
|
30 |
|
|
|
31 |
|
|
signal var1,var2,var3,var4,var5,var6,var7,vara,varb,varc,vard,vare,varf,varg : std_ulogic;
|
32 |
|
|
signal sortie : std_ulogic;
|
33 |
|
|
signal high : std_ulogic := '1';
|
34 |
|
|
signal n_spdif_in : std_ulogic;
|
35 |
|
|
signal remise_0,n_remise_0 : std_ulogic ;
|
36 |
|
|
signal s : std_ulogic_vector ( 7 downto 0):= "11111111";
|
37 |
|
|
signal enable : std_ulogic;
|
38 |
|
|
signal level_0,n_level_0 : std_ulogic;
|
39 |
|
|
signal preambule_m,preambule_w : std_ulogic;
|
40 |
|
|
type etat is (value,preamb_b,preamb_w,preamb_m);
|
41 |
|
|
signal status : etat := preamb_b;
|
42 |
|
|
signal entier : integer range 0 to 56 := 0;
|
43 |
|
|
signal register_dat : std_ulogic_vector ( 55 downto 0);
|
44 |
|
|
signal donnee : std_ulogic_vector ( 31 downto 0);
|
45 |
|
|
signal dat : std_ulogic_vector ( 27 downto 0);
|
46 |
|
|
signal end_frame : std_ulogic;
|
47 |
|
|
signal data_valid : std_ulogic;
|
48 |
|
|
signal pair : std_ulogic;
|
49 |
|
|
signal sub_frame : integer range 0 to 384;
|
50 |
|
|
signal echantillon1,echantillon0 : std_ulogic;
|
51 |
|
|
signal i2s_cl,word_sel : std_ulogic:='1';
|
52 |
|
|
signal left_right : std_ulogic:='0';
|
53 |
|
|
signal valid_word : std_ulogic:='0';
|
54 |
|
|
signal copie : std_ulogic:='0';
|
55 |
|
|
signal charge,block_wsel : std_ulogic:='0';
|
56 |
|
|
signal data_i : integer range 0 to 4;
|
57 |
|
|
component dff port ( d,clk,clrn : in std_ulogic;
|
58 |
|
|
q : out std_ulogic);
|
59 |
|
|
end component;
|
60 |
|
|
begin
|
61 |
|
|
|
62 |
|
|
pll_v_setting <= v_24_576mhz; -- to programm th pll
|
63 |
|
|
pll_r_setting <= r_24_576mhz; -- to programm th pll
|
64 |
|
|
pll_s_setting <= s_24_576mhz; -- to programm th pll
|
65 |
|
|
pll_npd<='1';
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
n_spdif_in <= not spdif_in;
|
69 |
|
|
n_remise_0 <= not remise_0;
|
70 |
|
|
n_level_0 <= not level_0;
|
71 |
|
|
|
72 |
|
|
echantillon1 <= var1 and var2 and not var3 ;
|
73 |
|
|
echantillon0 <= vara and varb and not varc ;
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
-- les dff pour les echantillonnages
|
78 |
|
|
--------------------------------------------------------------
|
79 |
|
|
dff1 : dff port map ( d => spdif_in,
|
80 |
|
|
clk => clock,
|
81 |
|
|
clrn => n_remise_0,
|
82 |
|
|
q => var1
|
83 |
|
|
);
|
84 |
|
|
|
85 |
|
|
dff2 : dff port map ( d => var1,
|
86 |
|
|
clk => clock,
|
87 |
|
|
clrn => n_remise_0,
|
88 |
|
|
q => var2
|
89 |
|
|
);
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
dff3 : dff port map ( d => var2,
|
93 |
|
|
clk => clock,
|
94 |
|
|
clrn => n_remise_0,
|
95 |
|
|
q => var3
|
96 |
|
|
);
|
97 |
|
|
|
98 |
|
|
dff4 : dff port map ( d => var3,
|
99 |
|
|
clk => clock,
|
100 |
|
|
clrn => n_remise_0,
|
101 |
|
|
q => var4
|
102 |
|
|
);
|
103 |
|
|
dff5 : dff port map ( d => var4,
|
104 |
|
|
clk => clock,
|
105 |
|
|
clrn => n_remise_0,
|
106 |
|
|
q => var5
|
107 |
|
|
);
|
108 |
|
|
|
109 |
|
|
dff6 : dff port map ( d => var5,
|
110 |
|
|
clk => clock,
|
111 |
|
|
clrn => n_remise_0,
|
112 |
|
|
q => var6
|
113 |
|
|
);
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
dff7 : dff port map ( d => var6,
|
117 |
|
|
clk => clock,
|
118 |
|
|
clrn => n_remise_0,
|
119 |
|
|
q => var7
|
120 |
|
|
);
|
121 |
|
|
|
122 |
|
|
dff8 : dff port map ( d => var7,
|
123 |
|
|
clk => clock,
|
124 |
|
|
clrn => n_remise_0,
|
125 |
|
|
q => remise_0
|
126 |
|
|
);
|
127 |
|
|
|
128 |
|
|
--------------------------------------------------------------
|
129 |
|
|
dffa : dff port map ( d => n_spdif_in,
|
130 |
|
|
clk => clock,
|
131 |
|
|
clrn => n_level_0,
|
132 |
|
|
q => vara
|
133 |
|
|
);
|
134 |
|
|
|
135 |
|
|
dffb : dff port map ( d => vara,
|
136 |
|
|
clk => clock,
|
137 |
|
|
clrn => n_level_0,
|
138 |
|
|
q => varb
|
139 |
|
|
);
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
dffc : dff port map ( d => varb,
|
143 |
|
|
clk => clock,
|
144 |
|
|
clrn => n_level_0,
|
145 |
|
|
q => varc
|
146 |
|
|
);
|
147 |
|
|
dffd : dff port map ( d => varc,
|
148 |
|
|
clk => clock,
|
149 |
|
|
clrn => n_level_0,
|
150 |
|
|
q => vard
|
151 |
|
|
);
|
152 |
|
|
dffe : dff port map ( d => vard,
|
153 |
|
|
clk => clock,
|
154 |
|
|
clrn => n_level_0,
|
155 |
|
|
q => vare
|
156 |
|
|
);
|
157 |
|
|
|
158 |
|
|
dfff : dff port map ( d => vare,
|
159 |
|
|
clk => clock,
|
160 |
|
|
clrn => n_level_0,
|
161 |
|
|
q => varf
|
162 |
|
|
);
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
dffg : dff port map ( d => varf,
|
166 |
|
|
clk => clock,
|
167 |
|
|
clrn => n_level_0,
|
168 |
|
|
q => varg
|
169 |
|
|
);
|
170 |
|
|
dffh : dff port map ( d => varg,
|
171 |
|
|
clk => clock,
|
172 |
|
|
clrn => n_level_0,
|
173 |
|
|
q => level_0
|
174 |
|
|
);
|
175 |
|
|
----------------------------------------------------------------------------+
|
176 |
|
|
-- here I charge a register of 8 bits ,each bit correpsond to the value +
|
177 |
|
|
-- of a haf period in spdif this one is sampled in the middle approximatlly +
|
178 |
|
|
----------------------------------------------------------------------------------------------------------------+
|
179 |
|
|
charge_preambule : process (nreset,clock,var1,var2,var3,vara,varb,varc) -- detection du preambule --+
|
180 |
|
|
begin --+
|
181 |
|
|
if nreset = '0' then s <= (others => '0'); --+
|
182 |
|
|
elsif clock 'event and clock ='1' then if ( echantillon1 = '1' ) then s <= s( 6 downto 0) & '1'; --+
|
183 |
|
|
elsif ( echantillon0 = '1') then s <= s( 6 downto 0) & '0';--+
|
184 |
|
|
end if; --+
|
185 |
|
|
end if; --+
|
186 |
|
|
end process; --+
|
187 |
|
|
--+
|
188 |
|
|
----------------------------------------------------------------------------------------------------------------+
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
-- after detection of each preambule we put a signal to a high level
|
192 |
|
|
-- for approximatly a half period of spdif
|
193 |
|
|
|
194 |
|
|
--------------------------------------------------------------------------------------------------------------------
|
195 |
|
|
|
196 |
|
|
preambule_i : process (nreset,clock,s)
|
197 |
|
|
begin
|
198 |
|
|
if nreset = '0' then enable <= '0' ;preambule_w <= '0'; preambule_m <= '0';
|
199 |
|
|
elsif clock 'event and clock ='0'
|
200 |
|
|
then case s is
|
201 |
|
|
when "11101000" => enable <= '1' ;
|
202 |
|
|
when "00010111" => enable <= '1' ;
|
203 |
|
|
when "11100010" => preambule_m <= '1';
|
204 |
|
|
when "00011101" => preambule_m <= '1';
|
205 |
|
|
when "11100100" => preambule_w <= '1';
|
206 |
|
|
when "00011011" => preambule_w <= '1';
|
207 |
|
|
when others => enable <= '0' ;preambule_w <= '0';
|
208 |
|
|
preambule_m <= '0';
|
209 |
|
|
end case;
|
210 |
|
|
|
211 |
|
|
end if;
|
212 |
|
|
end process;
|
213 |
|
|
|
214 |
|
|
---------------------------------------------------------------------------------------------------------------
|
215 |
|
|
-- the state machine contains four states three for preambules and one for value
|
216 |
|
|
-- so here we can more serious in respect of synchronism
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
state_machine :process(nreset,clock,pair,preambule_w,preambule_m,enable)
|
221 |
|
|
begin
|
222 |
|
|
if nreset ='0' then status <= preamb_b;
|
223 |
|
|
elsif clock 'event and clock = '1' then case status is
|
224 |
|
|
when preamb_b => if enable = '1' then status <= value; end if ;
|
225 |
|
|
when preamb_w => if preambule_w = '1' then status <= value ; end if;
|
226 |
|
|
when preamb_m => if preambule_m ='1' then status <= value; end if;
|
227 |
|
|
when value => if end_frame = '0' then if data_valid ='1' then if pair = '1' then status <= preamb_m;
|
228 |
|
|
else status <= preamb_w; end if;
|
229 |
|
|
end if;
|
230 |
|
|
else if data_valid ='1' then status <= preamb_b;end if;
|
231 |
|
|
end if;
|
232 |
|
|
|
233 |
|
|
end case;
|
234 |
|
|
end if;
|
235 |
|
|
end process;
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
-- the process here is to determine when finishing on the status value then deteminte o wich
|
239 |
|
|
-- we must go
|
240 |
|
|
-- / preamb_w
|
241 |
|
|
-- value < --- or preamb_b
|
242 |
|
|
-- \ preamb_m
|
243 |
|
|
--------------------------------------------------
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
pros :process(nreset,clock,status,echantillon1,echantillon0,entier)
|
247 |
|
|
|
248 |
|
|
begin
|
249 |
|
|
if nreset = '0' or status = preamb_b or status = preamb_w or status = preamb_m then entier <= 0;
|
250 |
|
|
elsif clock 'event and clock ='1' then if status = value then if ( echantillon1 ='1' ) then register_dat <= register_dat( 54 downto 0) & '1';
|
251 |
|
|
if entier = 56 then entier <= 0; else entier <= entier +1;end if;
|
252 |
|
|
|
253 |
|
|
elsif ( echantillon0 ='1') then register_dat <= register_dat( 54 downto 0) & '0';
|
254 |
|
|
if entier = 56 then entier <= 0; else entier <= entier +1;end if;
|
255 |
|
|
|
256 |
|
|
end if;
|
257 |
|
|
end if;
|
258 |
|
|
end if;
|
259 |
|
|
if clock 'event and clock ='1' then if entier = 56 and status = value then data_valid <= '1';
|
260 |
|
|
else data_valid <= '0';end if;
|
261 |
|
|
end if;
|
262 |
|
|
|
263 |
|
|
end process;
|
264 |
|
|
|
265 |
|
|
--------------------------------------------------------------------------------------
|
266 |
|
|
--end of block one block is 192 frames so 384 sub_frames
|
267 |
|
|
--------------------------------------------------------------------------------------
|
268 |
|
|
|
269 |
|
|
end_block :process (data_valid,nreset,entier) -- counts the numbers of sub-frames
|
270 |
|
|
-- variable sub_frame : integer range 0 to 384;
|
271 |
|
|
begin
|
272 |
|
|
if nreset='0' or status = preamb_b then sub_frame<=0;
|
273 |
|
|
elsif data_valid 'event and data_valid='1' then pair <= not pair;
|
274 |
|
|
if sub_frame=384 then sub_frame<=0;
|
275 |
|
|
else sub_frame <=sub_frame +1;end if;
|
276 |
|
|
end if;
|
277 |
|
|
|
278 |
|
|
if (sub_frame =383 and entier = 56 ) then end_frame<='1';
|
279 |
|
|
else end_frame<='0'; end if;
|
280 |
|
|
end process;
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
-------------------------------------------------------------------------------+
|
284 |
|
|
-- Second entity in the same block code +
|
285 |
|
|
-- why ? for the reason that i will use the status variable to generate signals+
|
286 |
|
|
-- the things that is not possible with two entity +
|
287 |
|
|
-- +
|
288 |
|
|
---------------------------------------------------------------------------------------------------------+
|
289 |
|
|
i2s_clock : process(clock,echantillon1,echantillon0) --+
|
290 |
|
|
-- variable a_bit : integer range 0 to 31; --+
|
291 |
|
|
begin --+
|
292 |
|
|
if nreset ='0' then i2s_cl <= '1'; --+
|
293 |
|
|
elsif clock 'event and clock ='1' then if echantillon1= '1' then i2s_cl <= not i2s_cl;--+
|
294 |
|
|
elsif echantillon0 ='1' then i2s_cl <= not i2s_cl;--+
|
295 |
|
|
end if; --+
|
296 |
|
|
--+
|
297 |
|
|
end if; --+
|
298 |
|
|
end process; --+
|
299 |
|
|
---------------------------------------------------------------------------------------------------------+
|
300 |
|
|
-- this process generates an i2s clock in this case we have 3.072Mhz
|
301 |
|
|
|
302 |
|
|
---------------------------------------------------------------------------------------------------------+
|
303 |
|
|
w_valid : process(status,nreset,entier)
|
304 |
|
|
begin
|
305 |
|
|
if nreset ='0' then valid_word <= '0';
|
306 |
|
|
elsif clock 'event and clock = '1' then if status= value and entier = 55 then valid_word <= '1';end if;
|
307 |
|
|
end if;
|
308 |
|
|
end process;
|
309 |
|
|
|
310 |
|
|
--------------------------------------------------------
|
311 |
|
|
-- only needed signal for the state machine
|
312 |
|
|
-----------------------------------------------
|
313 |
|
|
number_bits : process(nreset,i2s_cl,status)
|
314 |
|
|
|
315 |
|
|
begin
|
316 |
|
|
if nreset ='0' or status = value then data_i <= 0;
|
317 |
|
|
elsif i2s_cl 'event and i2s_cl = '1' then if (status= preamb_b or status = preamb_m or status = preamb_w)
|
318 |
|
|
then if data_i = 4 then data_i <= 0 ; else data_i <= data_i +1; end if;
|
319 |
|
|
end if; end if;
|
320 |
|
|
end process;
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
-------------------------------------------------------
|
325 |
|
|
-- only needed signal for the state machine
|
326 |
|
|
-----------------------------------------------
|
327 |
|
|
decal_dat : process(nreset,i2s_cl,status)
|
328 |
|
|
begin
|
329 |
|
|
if nreset ='0' then charge <= '0';
|
330 |
|
|
elsif i2s_cl 'event and i2s_cl = '1' then case status is
|
331 |
|
|
when value => charge <= '0';block_wsel<='0';
|
332 |
|
|
when preamb_b => if data_i = 3 then charge <= '1' ; end if;
|
333 |
|
|
if data_i = 4 then block_wsel <= '1' ; end if;
|
334 |
|
|
when preamb_w => if data_i = 3 then charge <= '1' ; end if;
|
335 |
|
|
if data_i = 4 then block_wsel <= '1' ; end if;
|
336 |
|
|
when preamb_m => if data_i = 3 then charge <= '1' ; end if;
|
337 |
|
|
if data_i = 4 then block_wsel <= '1' ; end if;
|
338 |
|
|
end case;
|
339 |
|
|
end if;
|
340 |
|
|
end process;
|
341 |
|
|
-------------------------------------------------------
|
342 |
|
|
-- in each sub-frames a send 32 bit so we complete these bits with
|
343 |
|
|
-- zeros and the first zero in only for the reason that I implemented
|
344 |
|
|
-- a left justified protocol
|
345 |
|
|
-- so to change the i2s format change this process only
|
346 |
|
|
-----------------------------------------------------------
|
347 |
|
|
datas : process (nreset,i2s_cl,charge) --les datas a sortir
|
348 |
|
|
begin
|
349 |
|
|
if nreset = '0' then donnee <= (others => '0' );
|
350 |
|
|
elsif i2s_cl 'event and i2s_cl='0' then if charge ='1' and valid_word= '1' then
|
351 |
|
|
|
352 |
|
|
donnee(31 downto 0) <= "0000000" & dat(27 downto 4) & '0';
|
353 |
|
|
if block_wsel ='0' then word_sel <= not word_sel; end if;
|
354 |
|
|
else donnee(31 downto 0) <= '0' & donnee(31 downto 1) ;
|
355 |
|
|
end if;
|
356 |
|
|
end if;
|
357 |
|
|
end process;
|
358 |
|
|
------------------------------------------+
|
359 |
|
|
-- the registerd dat contains only the values sampled so need to know
|
360 |
|
|
-- the values corresponding : a xor function can do this
|
361 |
|
|
--------------------------------------------------+
|
362 |
|
|
msb_first : process(nreset,charge)
|
363 |
|
|
--variable I : integer range 0 to 27;
|
364 |
|
|
begin
|
365 |
|
|
if nreset = '0' then dat <=( others => '0');
|
366 |
|
|
elsif charge 'event and charge = '1' then for I in 0 to 27 loop
|
367 |
|
|
dat(I) <= register_dat(2*I) xor register_dat (2*I +1);
|
368 |
|
|
end loop;
|
369 |
|
|
end if;
|
370 |
|
|
end process;
|
371 |
|
|
|
372 |
|
|
--------------------------------------------------+
|
373 |
|
|
v_ctrl <= '1' when status = preamb_b else '0';
|
374 |
|
|
sync_start <= echantillon0;
|
375 |
|
|
lr <= word_sel;
|
376 |
|
|
preambule_l<= preambule_m;
|
377 |
|
|
preambule_r <= valid_word;
|
378 |
|
|
--sclk <= CONV_STD_LOGIC_VECTOR(entier,7);
|
379 |
|
|
data_v <= donnee(0) when status = value else '0' when status = value else '0';
|
380 |
|
|
begin_block <= end_frame;
|
381 |
|
|
fin <= i2s_cl;
|
382 |
|
|
copie_d <= block_wsel;
|
383 |
|
|
serial_out <= donnee(0);
|
384 |
|
|
end architecture;
|