OpenCores
URL https://opencores.org/ocsvn/802154phycore/802154phycore/trunk

Subversion Repositories 802154phycore

[/] [802154phycore/] [trunk/] [rtl/] [sym_corr.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 entactogen
-- Copyright (c) 2010 Antonio de la Piedra
2
 
3
-- This program is free software: you can redistribute it and/or modify
4
-- it under the terms of the GNU General Public License as published by
5
-- the Free Software Foundation, either version 3 of the License, or
6
-- (at your option) any later version.
7
 
8
-- This program is distributed in the hope that it will be useful,
9
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
-- GNU General Public License for more details.
12
 
13
-- You should have received a copy of the GNU General Public License
14
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
-- A VHDL model of the IEEE 802.15.4 physical layer.
17
 
18
library IEEE;
19
use IEEE.STD_LOGIC_1164.ALL;
20
use IEEE.STD_LOGIC_UNSIGNED.ALL;
21
use IEEE.numeric_std.ALL;
22
 
23
entity sym_corr is
24
        generic (t_symbol: integer := 16);
25
        port( correlator_start :in std_logic;
26
                        correlator_clk: in std_logic;
27
                        correlator_rst: in std_logic;
28
                        correlator_input_q: in std_logic;
29
                        correlator_symbol: out std_logic_vector(3 downto 0));
30
 
31
end sym_corr;
32
 
33
architecture Behavioral of sym_corr is
34
        signal count_temp: integer range 0 to 17;
35
        signal chip_shr: std_logic_vector(15 downto 0);
36
 
37
        type sym_t is array (15 downto 0) of std_logic_vector(15 downto 0);
38
        type symbol_table is array (15 downto 0) of std_logic_vector(3 downto 0);
39
        type corr_value_t is array (15 downto 0) of integer;
40
        type max_fun_output is array (1 downto 0) of integer range 0 to 16;
41
 
42
 
43
   constant symbol_zero_q : std_logic_vector(15 downto 0) := "1101100111000010";
44
 
45
 
46
 
47
        constant symbol_table_q: symbol_table := ("1111",
48
                                                                                                                        "1110",
49
                                                                                                                        "1101",
50
                                                                                                                        "1100",
51
                                                                                                                        "1011",
52
                                                                                                                        "1010",
53
                                                                                                                        "1001",
54
                                                                                                                        "1000",
55
                                                                                                                        "0111",
56
                                                                                                                        "0110",
57
                                                                                                                        "0101",
58
                                                                                                                        "0100",
59
                                                                                                                        "0011",
60
                                                                                                                        "0010",
61
                                                                                                                        "0001",
62
                                                                                                                        "0000");
63
 
64
 
65
        function bit_to_integer(input_value: std_logic) return integer is
66
        begin
67
                if (input_value = '0' ) then
68
                        return 0;
69
                else
70
                        return 1;
71
                end if;
72
        end function bit_to_integer;
73
 
74
        function max_vector(vector: corr_value_t ) return max_fun_output is
75
                variable temp: integer range 0 to 8;
76
                variable pos: integer range 0 to 16;
77
                begin
78
                        temp := 0;
79
 
80
                        for i in vector'range loop
81
                                if vector(i) > temp then
82
                                        temp := vector(i);
83
                                        pos  := i;
84
                                end if;
85
                        end loop;
86
 
87
                        return max_fun_output'(temp, pos);
88
 
89
        end function max_vector;
90
 
91
begin
92
 
93
        corr_shr: process(correlator_start, correlator_clk, correlator_rst)
94
                variable chip_reg: std_logic_vector(15 downto 0);
95
        begin
96
 
97
                if (correlator_rst = '1') then
98
                        chip_reg := symbol_zero_q;
99
                elsif (rising_edge(correlator_clk) and correlator_start = '1') then
100
                        chip_reg := std_logic_vector(unsigned(chip_reg) rol 1);
101
                end if;
102
 
103
                chip_shr <= chip_reg;
104
        end process;
105
 
106
        corr_counter: process(correlator_start, correlator_clk)
107
                variable count: integer range 0 to t_symbol + 1:= 0;
108
        begin
109
                if (rising_edge(correlator_clk) and correlator_start = '1') then
110
                                count := count + 1;
111
                                if (count = t_symbol + 1) then
112
                                        count := 1;
113
                                end if;
114
                end if;
115
 
116
                count_temp <= count;
117
        end process;
118
 
119
        corr: process(correlator_start, correlator_clk, correlator_rst)
120
                        variable reg: std_logic_vector(15 downto 0) := (others => '0');
121
                        variable sym: sym_t;
122
                        variable corr_value: corr_value_t;
123
                        variable sym_pos: max_fun_output;
124
                begin
125
                        if (correlator_rst = '1') then
126
                                for i in 0 to 15 loop
127
                                        sym(i):= (others =>'0');
128
                                        corr_value(i) := 0;
129
                                end loop;
130
 
131
                                reg := (others => '0');
132
                        elsif (rising_edge(correlator_clk) and correlator_start = '1') then
133
 
134
                                        reg := reg(14 downto 0) & correlator_input_q;
135
 
136
                                        sym(0):= sym(0)(14 downto 0) & chip_shr(0);
137
                                        sym(1):= sym(1)(14 downto 0) & chip_shr(2);
138
                                        sym(2):= sym(2)(14 downto 0) & chip_shr(4);
139
                                        sym(3):= sym(3)(14 downto 0) & chip_shr(6);
140
                                        sym(4):= sym(4)(14 downto 0) & chip_shr(8);
141
                                        sym(5):= sym(5)(14 downto 0) & chip_shr(10);
142
                                        sym(6):= sym(6)(14 downto 0) & chip_shr(12);
143
                                        sym(7):= sym(7)(14 downto 0) & chip_shr(14);
144
                                        sym(8):= sym(8)(14 downto 0) & not chip_shr(0);
145
                                        sym(9):= sym(9)(14 downto 0) & not chip_shr(2);
146
                                        sym(10):= sym(10)(14 downto 0) & not chip_shr(4);
147
                                        sym(11):= sym(11)(14 downto 0) & not chip_shr(6);
148
                                        sym(12):= sym(12)(14 downto 0) & not chip_shr(8);
149
                                        sym(13):= sym(13)(14 downto 0) & not chip_shr(10);
150
                                        sym(14):= sym(14)(14 downto 0) & not chip_shr(12);
151
                                        sym(15):= sym(15)(14 downto 0) & not chip_shr(14);
152
 
153
                                        -- We've got a new symbol !
154
 
155
                                        if (count_temp = t_symbol) then
156
 
157
                                                for i in 0 to 15 loop
158
                                                        for j in 0 to 15 loop
159
                                                                corr_value(i) := corr_value(i) + bit_to_integer(reg(j) and sym(i)(j));
160
                                                        end loop;
161
                                                end loop;
162
 
163
                                                sym_pos := max_vector(corr_value);
164
 
165
                                                correlator_symbol <= symbol_table_q(sym_pos(0));
166
 
167
                                                for i in 0 to 15 loop
168
                                                        corr_value(i) := 0;
169
                                                end loop;
170
                                        end if;
171
 
172
                        end if;
173
        end process;
174
 
175
end Behavioral;
176
 

powered by: WebSVN 2.1.0

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