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

Subversion Repositories aes3rx

[/] [aes3rx/] [trunk/] [rtl/] [vhdl/] [aes3rx.vhd] - Blame information for rev 9

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

Line No. Rev Author Line
1 8 nohous
----------------------------------------------------------------------------------
2
-- Company:  Czech Television
3
-- Engineer: Petr Nohavica
4
-- 
5
-- Create Date:    09:02:45 05/09/2009 
6
-- Module Name:    aes3rx - Behavioral 
7
-- Project Name:   AES3 minimalistic receiver
8
-- Target Devices: Spartan 3
9 9 nohous
-- Tool versions:  ISE 10.1
10
----------------------------------------------------------------------------------
11 8 nohous
 
12
library IEEE;
13
use IEEE.STD_LOGIC_1164.ALL;
14
use IEEE.STD_LOGIC_ARITH.ALL;
15
use IEEE.STD_LOGIC_UNSIGNED.ALL;
16
 
17 9 nohous
Library UNISIM;
18
use UNISIM.vcomponents.all;
19
 
20 8 nohous
entity aes3rx is
21
   generic (
22 9 nohous
      reg_width : integer := 4
23 8 nohous
   );
24
   port (
25 9 nohous
      clk_in: in  std_logic; -- master clock
26
      aes3  : in  std_logic; -- input 
27
      reset : in  std_logic; -- synchronous reset
28 8 nohous
 
29
      sdata : out std_logic := '0'; -- output serial data
30
      sclk  : out std_logic := '0'; -- output serial data clock
31 9 nohous
      bsync : out std_logic := '0'; -- block start (high when Z subframe is being transmitted)
32
      lrck  : out std_logic := '0'; -- frame sync (high for channel A, low for B)
33 8 nohous
      active: out std_logic := '0'  -- receiver has valid data on its outputs
34
   );
35
end aes3rx;
36
 
37
architecture Behavioral of aes3rx is
38 9 nohous
   constant X_PREAMBLE     : std_logic_vector(7 downto 0) := "01000111"; -- X preamble bit sequence
39
   constant Y_PREAMBLE     : std_logic_vector(7 downto 0) := "00100111"; -- Y preamble bit sequence
40
   constant Z_PREAMBLE     : std_logic_vector(7 downto 0) := "00010111"; -- Z preamble bit sequence
41 8 nohous
 
42 9 nohous
   signal aes3_sync        : std_logic_vector(3 downto 0) := (others => '0'); -- input shift reg for double sampling, change detection and input delaying
43
   signal change           : std_logic := '0'; -- signal signifying a change on the input
44
   signal aes3_clk         : std_logic := '0'; -- recovered clock signal (actually a stream of pulses on supposed clock edges for implementation on single edge driven FFs)
45
   signal decoder_shift    : std_logic_vector(7 downto 0) := (others => '0'); -- decoder shift reg for preamble detection and logical state decoding
46
   signal align_counter    : std_logic := '0'; -- 1 bit counter reset on preamble detection, provides correct bit alignement for decoder
47
   signal clk_counter      : std_logic_vector(reg_width - 1 downto 0) := (others => '0'); -- counter for aes3 clock regeneration
48
   signal sync_timer       : std_logic_vector(5 downto 0) := (others => '0'); -- timer counting input changes
49
   signal reg_clk_period   : std_logic_vector(reg_width - 1 downto 0) := (others => '1'); -- copied from reg_shortest on update counter overflow, serves as reference for aes3 clock regeneration
50
   signal sync_lost        : std_logic := '1';
51
   signal preamble_detected: std_logic := '0';
52 8 nohous
 
53 9 nohous
   signal sdata_int        : std_logic := '0'; -- internal sdata signal
54
   signal bsync_int        : std_logic := '0'; -- internal bsync signal
55
   signal lrck_int         : std_logic := '0'; -- internal lrck signal
56
 
57
   signal clk : std_logic := '0';
58
 
59 8 nohous
begin
60
 
61 9 nohous
   clk <= clk_in;
62
 
63 8 nohous
   ------------------------------------------
64
   -- input_shift_reg_proc
65
   -- Carries out input double sampling in 
66
   -- order to avoid metastable states on FFs
67
   -- and creation of delayed signals for
68
   -- change detector (1 clk period) and 
69
   -- decoder (2 clk periods)
70
   ------------------------------------------
71
   input_shift_reg_proc: process (clk)
72
   begin
73
      if clk'event and clk = '1' then
74
         if reset = '1' then
75
            aes3_sync <= (others => '0');
76
         else
77
            aes3_sync <= aes3 & aes3_sync(3 downto 1); -- synthetizes  shift reg
78
         end if;
79
      end if;
80
   end process;
81
 
82
   ------------------------------------------
83
   -- change_detect_proc
84
   -- Detects edge on sampled input in the 
85
   -- way of comparsion of delayed input 
86
   -- and current state on XOR gate
87
   ------------------------------------------   
88
   change_detect_proc: process (clk)
89
   begin
90
      if clk'event and clk = '1' then
91
         if reset = '1' then
92
            change <= '0';
93
         else
94
            change <= '0';
95
            if aes3_sync(2) /= aes3_sync(1) then
96
               change <= '1';
97
            end if;
98
         end if;
99
      end if;
100 9 nohous
   end process;
101
 
102
   aes3_clk_feedback: process (clk)
103 8 nohous
   begin
104
      if clk'event and clk = '1' then
105
         if reset = '1' then
106 9 nohous
            reg_clk_period <= (others => '1');
107
            sync_timer <= (others => '0');
108
         else
109
            if preamble_detected = '1' then
110
               sync_timer <= (others => '0');
111
               sync_lost <= '0';
112
            elsif aes3_clk = '1' then
113
               if sync_timer = 63 then
114
                  if sync_lost = '1' then
115
                     reg_clk_period <= reg_clk_period - 1;
116
                  else
117
                     reg_clk_period <= (others => '1');
118
                     sync_lost <= '1';
119
                  end if;
120 8 nohous
               end if;
121 9 nohous
               sync_timer <= sync_timer + 1;
122 8 nohous
            end if;
123
         end if;
124
      end if;
125
   end process;
126 9 nohous
 
127
   aes3_clk_regen_proc: process (clk)
128 8 nohous
   begin
129
      if clk'event and clk = '1' then
130
         if reset = '1' then
131 9 nohous
            clk_counter <= (others => '0');
132
            aes3_clk <= '0';
133
         else
134
            clk_counter <= clk_counter - 1;
135
            aes3_clk <= '0';
136
            if change = '1' then
137
               clk_counter <= '0' & reg_clk_period(reg_width - 1 downto 1);
138
            elsif clk_counter = 0 then
139
               clk_counter <= reg_clk_period;
140
               aes3_clk <= '1';
141 8 nohous
            end if;
142
         end if;
143
      end if;
144
   end process;
145 9 nohous
 
146 8 nohous
   ------------------------------------------
147 9 nohous
   -- decoder_shift_reg_proc
148
   -- Eight bit shift register for preamble
149
   -- detection and decoder functionality.
150 8 nohous
   ------------------------------------------   
151
   decoder_shift_reg_proc: process (clk)
152
   begin
153
      if clk'event and clk = '1' then
154
         if reset = '1' then
155
            decoder_shift <= (others => '0');
156
         elsif aes3_clk = '1' then
157
            decoder_shift <= aes3_sync(0) & decoder_shift(7  downto 1);
158
         end if;
159
      end if;
160 9 nohous
   end process;
161
 
162
   ------------------------------------------
163
   -- decoder_proc
164
   -- Compares shift register with preamble
165
   -- bit sequences and when one is detected,
166
   -- accoridngly changes sync signals and
167
   -- resets bit alignment counter 
168
   -- (align_counter). Bits are decoded when
169 8 nohous
   -- align_counter is high.
170
   ------------------------------------------
171
   decoder_proc: process (clk)
172
   begin
173 9 nohous
      if clk'event and clk = '1' then
174
         if reset = '1' then
175
            lrck_int <= '0';
176 8 nohous
            bsync_int <= '0';
177 9 nohous
            align_counter <= '0';
178 8 nohous
         else
179
            if aes3_clk = '1' then
180
               align_counter <= not align_counter;
181 9 nohous
               preamble_detected <= '0';
182 8 nohous
               if decoder_shift = X_PREAMBLE or decoder_shift = not X_PREAMBLE then
183 9 nohous
                  preamble_detected <= '1';
184
                  align_counter <= '0';
185 8 nohous
                  bsync_int <= '0';
186 9 nohous
                  lrck_int <= '1';
187
               elsif decoder_shift = Y_PREAMBLE or decoder_shift = not Y_PREAMBLE then
188
                  preamble_detected <= '1';
189 8 nohous
                  align_counter <= '0';
190
                  bsync_int <= '0';
191 9 nohous
                  lrck_int <= '0';
192
               elsif decoder_shift = Z_PREAMBLE or decoder_shift = not Z_PREAMBLE then
193
                  preamble_detected <= '1';
194 8 nohous
                  align_counter <= '0';
195
                  bsync_int <= '1';
196 9 nohous
                  lrck_int <= '1';
197 8 nohous
               end if;
198
               if align_counter = '1' then
199 9 nohous
                  if decoder_shift(5) = decoder_shift(4) then
200 8 nohous
                     sdata_int <= '0';
201
                  else
202
                     sdata_int <= '1';
203 9 nohous
                  end if;
204 8 nohous
               end if;
205
            end if;
206
         end if;
207
      end if;
208
   end process;
209
 
210 9 nohous
   activity_eval_proc: process (clk)
211
   begin
212
      if clk'event and clk = '1' then
213
         active <= not sync_lost;
214
         sclk <= align_counter and not sync_lost;
215
         sdata <= sdata_int and not sync_lost;
216
         lrck <= lrck_int and not sync_lost;
217
         bsync <= bsync_int and not sync_lost;
218
      end if;
219
   end process;
220 8 nohous
end Behavioral;
221
 

powered by: WebSVN 2.1.0

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