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

Subversion Repositories tosnet

[/] [tosnet/] [trunk/] [gateware/] [TosNet_rev3_2/] [tpl_rx.vhd] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 sonicwave
----------------------------------------------------------------------------------
2
-- Company:             University of Southern Denmark
3
-- Engineer:            Simon Falsig
4
-- 
5
-- Create Date:         19/3/2009 
6
-- Design Name:         TosNet
7
-- Module Name:         tpl_rx - Behavioral 
8
-- File Name:           tpl_rx.vhd
9
-- Project Name:        TosNet
10
-- Target Devices:      Spartan3/6
11
-- Tool versions:       Xilinx ISE 12.2
12
-- Description:         The receive part of the TosNet physical layer.
13
--
14
-- Revision: 
15
-- Revision 3.2 -       Initial release
16
--
17
-- Copyright 2010
18
--
19
-- This module is free software: you can redistribute it and/or modify
20
-- it under the terms of the GNU Lesser General Public License as published by
21
-- the Free Software Foundation, either version 3 of the License, or
22
-- (at your option) any later version.
23
--
24
-- This module is distributed in the hope that it will be useful,
25
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
26
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
-- GNU Lesser General Public License for more details.
28
--
29
-- You should have received a copy of the GNU Lesser General Public License
30
-- along with this module.  If not, see <http://www.gnu.org/licenses/>.
31
----------------------------------------------------------------------------------
32
library IEEE;
33
use IEEE.STD_LOGIC_1164.ALL;
34
use IEEE.STD_LOGIC_ARITH.ALL;
35
use IEEE.STD_LOGIC_UNSIGNED.ALL;
36
 
37
entity tpl_rx is
38
        Port (  data                            : out   STD_LOGIC_VECTOR(7 downto 0);
39
                        valid                           : out   STD_LOGIC;
40
                        error                           : out   STD_LOGIC;
41
                        clk_data                        : out   STD_LOGIC;
42
                        clk_50M                         : in    STD_LOGIC;
43
                        reset                           : in    STD_LOGIC;
44
                        sig_in                          : in    STD_LOGIC);
45
end tpl_rx;
46
 
47
architecture Behavioral of tpl_rx is
48
 
49
        type STATES is (IDLE, QUIET, REC_START, REC_SEED, REC_DATA, REC_ERROR);
50
 
51
        signal state                                    : STATES := IDLE;
52
        signal next_state                               : STATES := IDLE;
53
 
54
        signal sig_in_sync                              : STD_LOGIC := '0';
55
        signal last_sig_in_sync                 : STD_LOGIC := '0';
56
 
57
        signal in_buffer                                : STD_LOGIC_VECTOR(9 downto 0) := "0000000000";
58
        signal data_buffer                              : STD_LOGIC_VECTOR(7 downto 0) := "00000000";
59
        signal bit_counter                              : STD_LOGIC_VECTOR(3 downto 0) := "0000";
60
        signal last_bit_counter                 : STD_LOGIC_VECTOR(3 downto 0) := "0000";
61
 
62
        signal clk_data_int                             : STD_LOGIC := '0';
63
        signal valid_int                                : STD_LOGIC := '0';
64
        signal bit_counter_synced               : STD_LOGIC := '0';
65
 
66
        signal lfsr_rec_out                             : STD_LOGIC_VECTOR(7 downto 0);
67
        signal lfsr_rec_seed                    : STD_LOGIC_VECTOR(7 downto 0);
68
        signal lfsr_rec_reset                   : STD_LOGIC;
69
        signal lfsr_rec_clk                             : STD_LOGIC;
70
        signal lfsr_rec_clk_en                  : STD_LOGIC;
71
 
72
        signal dec_clk                                  : STD_LOGIC;
73
        signal dec_clk_en                               : STD_LOGIC;
74
        signal dec_in                                   : STD_LOGIC_VECTOR(9 downto 0);
75
        signal dec_out                                  : STD_LOGIC_VECTOR(7 downto 0);
76
        signal dec_kout                                 : STD_LOGIC;
77
        signal dec_code_err                             : STD_LOGIC;
78
 
79
        component lfsr is
80
                generic (
81
                        lfsr_length             : STD_LOGIC_VECTOR(7 downto 0);
82
                        lfsr_out_length         : STD_LOGIC_VECTOR(7 downto 0);
83
                        lfsr_allow_zero         : STD_LOGIC);
84
                port (
85
                        lfsr_out                        : out   STD_LOGIC_VECTOR((conv_integer(lfsr_out_length) - 1) downto 0);
86
                        lfsr_seed                       : in    STD_LOGIC_VECTOR((conv_integer(lfsr_length) - 1) downto 0);
87
                        lfsr_reset                      : in    STD_LOGIC;
88
                        lfsr_clk                        : in    STD_LOGIC;
89
                        lfsr_clk_en                     : in    STD_LOGIC);
90
        end component;
91
 
92
        component dec_8b10b is
93
                port (
94
                        clk                                     : in    STD_LOGIC;
95
                        ce                                      : in    STD_LOGIC;
96
                        din                                     : in    STD_LOGIC_VECTOR(9 downto 0);
97
                        dout                            : out   STD_LOGIC_VECTOR(7 downto 0);
98
                        kout                            : out   STD_LOGIC;
99
                        code_err                        : out   STD_LOGIC);
100
        end component;
101
 
102
begin
103
 
104
        clk_data <= clk_data_int;
105
        valid <= valid_int and not dec_kout;
106
 
107
        lfsr_rec_clk <= clk_50M;
108
 
109
        lfsr_rec : lfsr
110
        Generic map (   lfsr_length => "00001000",
111
                                        lfsr_out_length => "00001000",
112
                                        lfsr_allow_zero => '0')
113
        Port map (              lfsr_out => lfsr_rec_out,
114
                                        lfsr_seed => lfsr_rec_seed,
115
                                        lfsr_reset => lfsr_rec_reset,
116
                                        lfsr_clk => lfsr_rec_clk,
117
                                        lfsr_clk_en => lfsr_rec_clk_en);
118
 
119
        dec_clk <= clk_50M;
120
        data_buffer <= dec_out xor lfsr_rec_out;
121
 
122
        dec : dec_8b10b
123
        Port map (              clk => dec_clk,
124
                                        ce => dec_clk_en,
125
                                        din => dec_in,
126
                                        dout => dec_out,
127
                                        kout => dec_kout,
128
                                        code_err => dec_code_err);
129
 
130
        process(clk_50M)
131
                variable sig_in_counter : STD_LOGIC_VECTOR(1 downto 0) := "00";
132
        begin
133
                if(clk_50M = '1' and clk_50M'event) then
134
                        if(reset = '1') then
135
                                state <= IDLE;
136
                        else
137
                                state <= next_state;
138
                        end if;
139
 
140
                        sig_in_sync <= sig_in;
141
 
142
 
143
                        last_sig_in_sync <= sig_in_sync;
144
 
145
                        if(last_sig_in_sync = sig_in_sync) then
146
                                sig_in_counter := sig_in_counter + 1;
147
                        else
148
                                sig_in_counter := (others => '0');
149
                        end if;
150
 
151
                        if(sig_in_counter(1 downto 0) = "01") then                       --This should be the approximate middle of the bit cell
152
                                in_buffer <= sig_in_sync & in_buffer(9 downto 1);
153
                                bit_counter <= bit_counter + 1;
154
 
155
                                if(bit_counter = 0) then
156
                                        dec_in <= in_buffer;
157
                                        clk_data_int <= '1';
158
                                elsif(bit_counter = 5) then
159
                                        clk_data_int <= '0';
160
                                end if;
161
                        end if;
162
 
163
                        if(bit_counter = 10) then
164
                                bit_counter <= "0000";
165
                        end if;
166
 
167
                        if((bit_counter = 1) and (last_bit_counter = 0)) then
168
                                dec_clk_en <= '1';
169
                        else
170
                                dec_clk_en <= '0';
171
                        end if;
172
 
173
                        lfsr_rec_clk_en <= dec_clk_en;
174
                        last_bit_counter <= bit_counter;
175
 
176
                        case state is
177
                                when IDLE =>
178
                                        lfsr_rec_seed <= "00000000";
179
                                        data <= "00000000";
180
                                        valid_int <= '0';
181
                                        error <= '0';
182
                                when QUIET =>
183
                                        bit_counter_synced <= '0';
184
                                        lfsr_rec_seed <= "00000000";
185
                                        lfsr_rec_reset <= '1';
186
                                        data <= "00000000";
187
                                        valid_int <= '0';
188
                                        error <= '0';
189
                                when REC_START =>
190
                                        if(bit_counter_synced = '0') then
191
                                                bit_counter <= "0000";
192
                                                bit_counter_synced <= '1';
193
                                        end if;
194
                                        lfsr_rec_seed <= "00000000";
195
                                        lfsr_rec_reset <= '1';
196
                                        data <= "00000000";
197
                                        valid_int <= '0';
198
                                        error <= '0';
199
                                when REC_SEED =>
200
                                        lfsr_rec_reset <= '1';
201
                                        if(bit_counter = 9) then
202
                                                lfsr_rec_seed <= dec_out;
203
                                        end if;
204
                                        data <= "00000000";
205
                                        valid_int <= '0';
206
                                        error <= '0';
207
                                when REC_DATA =>
208
                                        lfsr_rec_reset <= '0';
209
                                        if(bit_counter = 2) then
210
                                                data <= data_buffer;
211
                                                valid_int <= '1';
212
                                                error <= '0';
213
                                        end if;
214
                                when REC_ERROR =>
215
                                        error <= '1';
216
                        end case;
217
 
218
                end if;
219
        end process;
220
 
221
        process(state, in_buffer, bit_counter, dec_kout, dec_code_err)
222
        begin
223
                case state is
224
                        when IDLE =>
225
                                next_state <= QUIET;
226
                        when QUIET =>
227
                                if(in_buffer = "0101111100" or in_buffer = "1010000011") then
228
                                        next_state <= REC_START;
229
                                else
230
                                        next_state <= QUIET;
231
                                end if;
232
                        when REC_START =>
233
                                if(bit_counter = 10) then
234
                                        next_state <= REC_SEED;
235
                                else
236
                                        next_state <= REC_START;
237
                                end if;
238
                        when REC_SEED =>
239
                                if(dec_code_err = '1') then     --Need to wait until this state to check the decoder error output, as otherwise we may pick up the result of decoding something unaligned, resulting in a whole lot of errors that really aren't there...
240
                                        next_state <= REC_ERROR;
241
                                elsif(bit_counter = 10) then
242
                                        next_state <= REC_DATA;
243
                                else
244
                                        next_state <= REC_SEED;
245
                                end if;
246
                        when REC_DATA =>
247
                                if(dec_code_err = '1') then
248
                                        next_state <= REC_ERROR;
249
                                elsif(bit_counter = 10 and dec_kout = '1') then
250
                                        next_state <= QUIET;
251
                                else
252
                                        next_state <= REC_DATA;
253
                                end if;
254
                        when REC_ERROR =>
255
                                next_state <= QUIET;
256
                end case;
257
        end process;
258
 
259
end Behavioral;
260
 

powered by: WebSVN 2.1.0

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