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

Subversion Repositories parallel_scrambler

[/] [parallel_scrambler/] [trunk/] [src/] [par_scrambler.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sparkish
----------------------------------------------------------------------
2
----                                                              ----
3
---- Parallel Scrambler.                                              
4
----                                                              ----
5
---- This file is part of the Configurable Parallel Scrambler project 
6
---- http://opencores.org/project,parallel_scrambler              ----
7
----                                                              ----
8
---- Description                                                  ----
9
---- Parallel scrambler/descrambler module, user reconfigurable   ----
10
----                                                                      ----
11
----                                                              ----
12
---- License: LGPL                                                ----
13
---- -                                                            ----
14
----                                                              ----
15
---- Author(s):                                                   ----
16
---- - Howard Yin, sparkish@opencores.org                         ----
17
----                                                              ----
18
----------------------------------------------------------------------
19
 
20
library ieee;
21
use ieee.std_logic_1164.all;
22
 
23
entity par_scrambler is
24
        generic (
25
                Data_Width                      : integer       := 8;           -- Input/output data width
26
                Polynomial_Width        : integer       := 8            -- Polynomial width
27
                );
28
        port (
29
                rst                                     : in std_logic;                 -- Async reset
30
                clk                                     : in std_logic;                 -- System clock
31
                scram_rst                       : in std_logic;                 -- Scrambler reset, use for initialization.
32
                Polynomial                      : in std_logic_vector (Polynomial_Width downto 0);       -- Polynomial. Example: 1+x^4+x^6+x^7 represent as "11010001"
33
                data_in                         : in std_logic_vector (Data_Width-1 downto 0);           -- Data input
34
                scram_en                        : in std_logic;                                                                         -- Input valid
35
                data_out                        : out std_logic_vector (Data_Width-1 downto 0);          -- Data output
36
                out_valid                       : out std_logic                                                                         -- Output valid
37
                );
38
end par_scrambler;
39
 
40
architecture behavior of par_scrambler is
41
 
42
begin
43
 
44
    scram_p : process (clk,rst)
45
                variable c : std_logic  := '0';
46
                variable lfsr_q: std_logic_vector (Polynomial_Width-1 downto 0)  := (others => '1');
47
                variable lfsr_c: std_logic_vector (Data_Width-1 downto 0) := (others => '0');
48
        begin
49
                if (rst = '1') then
50
                        lfsr_q          := (others => '1');
51
                        out_valid       <= '0';
52
                        data_out        <= (others => '0');
53
                        c                       := '0';
54
                elsif (clk'EVENT and clk = '1') then
55
                        out_valid <= scram_en;
56
                        if (scram_rst = '1') then
57
                                lfsr_q := (others => '1');
58
                        elsif (scram_en = '1') then
59
                                for i in 0 to Data_Width-1 loop
60
                                        c       := lfsr_q (Polynomial_Width-1);
61
                                        xor_loop : for j in 1 to Polynomial_Width-2 loop
62
                                                if Polynomial(j) = '1' then
63
                                                        c       := c xor lfsr_q(j-1);
64
                                                end if;
65
                                        end loop xor_loop;
66
                                        lfsr_q  := lfsr_q (Polynomial_Width-2 downto 0) & c;
67
                                        lfsr_c  := c & lfsr_c(Data_Width-1 downto 1);
68
                                end loop;
69
                                data_out <= lfsr_c xor data_in;
70
                        end if;
71
        end if;
72
    end process;
73
 
74
end architecture behavior;

powered by: WebSVN 2.1.0

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