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

Subversion Repositories core1990_interlaken

[/] [core1990_interlaken/] [trunk/] [gateware/] [sources/] [interlaken/] [receiver/] [decoder.vhd] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 N.Boukadid
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
 
5
entity Decoder is
6
    port(
7
        Clk             : in std_logic;                     -- Clock input
8
        Reset               : in std_logic;                                      -- Reset decoder
9
        Data_In         : in std_logic_vector(66 downto 0); -- Data input
10
        Decoder_En      : in std_logic;                     -- Enables the decoder
11
        Data_Valid_In   : in std_logic;
12
        Data_Valid_Out  : out std_logic;
13
        Data_Out        : out std_logic_vector(66 downto 0);-- Decoded 64-bit output
14
        Data_Control    : out std_logic;                    --  Indicates whether the word is data or control
15
 
16
        Sync_Locked  : out std_logic;
17
        Sync_Error       : out std_logic;
18
        Bitslip      : out std_logic
19
    );
20
end entity Decoder;
21
 
22
architecture Decoding of Decoder is
23
    type state_type is (IDLE, SYNC, LOCKED);
24
        signal pres_state, next_state : state_type;
25
 
26
        signal Data_T1, Data_T2, Data_T3 : std_logic_vector(66 downto 0);
27
        --shared variable Sync_ChangeCounter : integer range 0 to 65; -- Counts common bit changes
28
 
29
        signal Data_Valid_P1, Data_Valid_P2, Data_Valid_P3 : std_logic;
30
        signal Data_P1, Data_P2, Data_P3 : std_logic_vector(66 downto 0);
31
        signal Sync_Transition_Location : integer := 0;
32
        signal Sync_Search : std_logic;
33
        signal Sync_Counter, Word_Counter : integer range 0 to 65;
34
        signal Sync_Error_Counter : integer range 0 to 17;
35
        signal Trans_result : integer range 0 to 65;
36
begin
37
 
38
    input : process (Clk, Reset) is --Input registers/pipelining
39
    begin
40
        if (Reset = '1') then
41
            Data_P1 <= (others => '1');
42
            Data_P2 <= (others => '1');
43
            Data_P3 <= (others => '1');
44
        elsif (rising_edge(clk)) then
45
            Data_P3 <= Data_P2;
46
            Data_P2 <= Data_P1;
47
 
48
            Data_Valid_P3 <= Data_Valid_P2;
49
            Data_Valid_P2 <= Data_Valid_P1;
50
 
51
            if (Data_Valid_In = '1') then
52
                Data_P1(66 downto 64) <= Data_In(66 downto 64);
53
                Data_P1(63 downto 0) <= Data_In(63 downto 0);
54
                Data_Valid_P1 <= '1';
55
            else
56
                Data_P1 <= Data_P1;
57
                Data_Valid_P1 <= '0';
58
            end if;
59
        end if;
60
    end process input;
61
 
62
    transitions : process (Clk, Reset) is -- Detect transitions to locate the preamble
63
        begin
64
        if (Reset = '1') then
65
                        Data_T1 <= (others => '1');
66
                        Data_T2 <= (others => '1');
67
        elsif (rising_edge(clk)) then
68
 
69
            for i in 66 downto 1  loop      -- Indicates bit transitions of incoming data
70
                Data_T1(i) <= (Data_P1(i) xor Data_P1(i-1));
71
            end loop;
72
            Data_T1(0) <= '0';              -- Last bit must be zero
73
 
74
            Data_T2 <= Data_T1 and Data_T2; -- Loop and compare to new data, only the transitions always occuring will be left
75
 
76
            if Data_T1 = (Data_T1'range => '0') or Data_T2 = (Data_T2'range => '0') then
77
                Data_T2 <= (others => '1');
78
            end if;
79
 
80
        end if;
81
    end process transitions;
82
 
83
    synchronize : process (Clk, Reset, Sync_Search, Data_T2) is --Locate the preamble according to the detected transitions
84
        variable Sync_TransitionCounter: integer range 0 to 65 := 0; -- Counts common bit transitions
85
    begin
86
        if (Reset = '1') then
87
            Sync_TransitionCounter := 0;
88
        elsif (rising_edge(clk)) then
89
            Sync_TransitionCounter := 0;
90
            if (Sync_Search = '1') then
91
                Sync_TransitionCounter := 0;
92
 
93
                for j in 66 downto 0  loop  -- Count transitions that occur
94
                    if(Data_T2(j) = '1') then
95
                        Sync_TransitionCounter := Sync_TransitionCounter + 1;
96
                        Sync_Transition_Location <= j;
97
                    else
98
                        Sync_TransitionCounter := Sync_TransitionCounter;
99
                    end if;
100
                end loop;
101
 
102
            end if;
103
            Trans_result <= Sync_TransitionCounter;
104
 
105
        end if;
106
    end process synchronize;
107
 
108
        state_register : process (clk) is
109
    begin
110
        if (rising_edge(clk)) then
111
            pres_state <= next_state;
112
        end if;
113
    end process state_register;
114
 
115
    state_decoder : process (pres_state, Decoder_En, Sync_Counter, Sync_Error_Counter, Trans_result, Sync_Transition_Location) is
116
    begin
117
        case pres_state is
118
        when IDLE =>
119
            if (Decoder_En = '1' and Trans_result < 67) then
120
                next_state <= SYNC;
121
            else
122
                next_state <= IDLE;
123
            end if;
124
        when SYNC =>
125
            if(Sync_Counter >= 63 and Trans_result = 1 and Sync_Transition_Location = 65) then
126
                next_state <= Locked;
127
            elsif (Trans_result = 0) then
128
                next_state <= IDLE;
129
            else
130
                next_state <= SYNC;
131
            end if;
132
        when LOCKED =>
133
            if (Sync_Error_Counter > 14) then
134
                next_state <= IDLE;
135
            else
136
                next_state <= LOCKED;
137
            end if;
138
        when others =>
139
            next_state <= IDLE;
140
        end case;
141
    end process state_decoder;
142
 
143
    output : process (pres_state, clk) is
144
        variable Data_Temp : std_logic_vector(63 downto 0);
145
        variable Data_Lock : std_logic_vector(66 downto 0);
146
        variable Data_Header : std_logic_vector(2 downto 0);
147
        variable shift_timeout : integer range 0 to 63;
148
    begin
149
        if rising_edge(clk) then
150
            Bitslip <= '0';
151
            case pres_state is
152
            when IDLE =>
153
                Sync_Error <= '0';
154
                Sync_Locked <= '0';
155
                Sync_Search <= '1';
156
                Sync_Counter <= 0;
157
                Data_Control <= '0';
158
                Data_T3 <= (others => '0');
159
                Data_Lock := (others => '0');
160
                Data_Out <= (others => '0');
161
 
162
--                if (Decoder_En = '1' and Sync_TransitionCounter < 67) then
163
--                   Sync_Counter <= 1;
164
--                end if;
165
 
166
            when SYNC =>
167
             if (Data_Valid_In = '1') then
168
                Sync_Counter <= Sync_Counter + 1; --Count sync words passed
169
                if(Sync_Counter >= 63 and Trans_result = 1 and Sync_Transition_Location = 65) then
170
                    Data_Lock := Data_T2;   -- If decoder goes in lock, data including bit position will be saved
171
                    Sync_Counter <= 0 ;     -- Reset counter after changing state
172
                    Sync_Locked <= '1';
173
                    Sync_Search <= '0';
174
                    Data_Control <= '1';
175
                    Data_T3 <= Data_Lock and Data_T1;
176
                elsif (Trans_result = 0) then
177
                    Sync_Error <= '1';
178
                end if;
179
 
180
                if (Sync_Transition_Location /= 65) then
181
                    if(shift_timeout = 0) then
182
                        Bitslip <= '1';
183
                        shift_timeout := 63;
184
                    else
185
                        shift_timeout := shift_timeout - 1;
186
                        Bitslip <= '0';
187
                    end if;
188
                else
189
                    Bitslip <= '0';
190
                end if;
191
             end if;
192
            when LOCKED =>
193
                Sync_Locked <= '1';
194
                Sync_Error <= '0';
195
                Word_Counter <= Word_Counter + 1; -- Count data words passed
196
 
197
                Data_T3 <= Data_Lock and Data_T1;
198
 
199
                if(Data_T3(Sync_Transition_Location) = '0') then
200
                    Sync_Error_Counter <= Sync_Error_Counter + 1;
201
                    Sync_Error <= '1';
202
                    Data_out <= (others => '0');
203
                    Data_Header := "010";
204
                else
205
                    --Change to P2!!!
206
                    Data_Temp := Data_P3(63 downto 0);
207
                    Data_Header := Data_P3(66 downto 64);
208
                end if;
209
 
210
                Data_Valid_Out <= Data_Valid_P3;
211
 
212
                if (Data_Header(2) = '1') then -- Read inversion bit
213
                    Data_Out(63 downto 0) <= not(Data_Temp(63 downto 0));
214
                else
215
                    Data_Out(63 downto 0) <= Data_Temp(63 downto 0);
216
                end if;
217
                Data_Out(66 downto 64) <= Data_Header;
218
 
219
                if(Data_Header(1) = '1') then -- Read control word bit
220
                    Data_Control <= '1';
221
                else
222
                    Data_Control <= '0';
223
                end if;
224
 
225
                if (Sync_Error_Counter > 14) then -- Rest error counter after 16 errors
226
                    Sync_Locked <= '0';
227
                    Sync_Error_Counter <= 0;
228
                end if;
229
 
230
                if (Word_Counter > 63) then -- Reset word and error counters after 64 passed words
231
                    Word_Counter <= 1;
232
                    Sync_Error_Counter <= 0;
233
                end if;
234
            end case;
235
        end if;
236
    end process output;
237
 
238
end architecture Decoding;

powered by: WebSVN 2.1.0

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