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

Subversion Repositories hdbn

[/] [hdbn/] [trunk/] [rtl/] [vhdl/] [hdbnd.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 allanh
-------------------------------------------------------------------------------
2
-- Title        : hdbnd
3
-- Project      : hdbn
4
-------------------------------------------------------------------------------
5
-- File         : hdbnd.vhd
6
-- Author       : Allan Herriman <allanh@opencores.org>
7
-- Organization : Opencores
8
-- Created      : 9 Aug 1999
9
-- Platform     : ?
10
-- Simulators   : Any VHDL '87, '93 or '00 compliant simulator will work.
11
--                Tested with several versions of Modelsim and Simili.
12
-- Synthesizers : Any VHDL compliant synthesiser will work (tested with
13
--                Synplify Pro and Leonardo).
14
-- Targets      : Anything (contains no target dependent features except
15
--                combinatorial logic and D flip flops with async
16
--                reset or set).
17
-- Dependency   : None.  Complementary encoder is hdb3e.
18
-------------------------------------------------------------------------------
19
-- Description  : HDB3 or HDB2 (B3ZS) decoder.
20
--                Note: this module does not include clock recovery.
21
--                A separate CDR (Clock and Data Recovery) circuit must be
22
--                used.
23
--
24
--  HDB3 is typically used to encode data at 2.048, 8.448 and 34.368Mb/s
25
--  B3ZS is typically used to encode data at 44.736Mb/s
26
--  These encodings are polarity insensitive, so the P and N inputs may be
27
--  used interchangeably (swapped).
28
--
29
-- Reference    : ITU-T G.703
30
--
31
-------------------------------------------------------------------------------
32
-- Copyright (c) notice
33
-- http://www.opensource.org/licenses/bsd-license.html
34
--
35
-------------------------------------------------------------------------------
36
--
37
-- CVS Revision History
38
--
39
-- $Log: not supported by cvs2svn $
40
--
41
------------------------------------------------------------------------------
42
 
43
library ieee;
44
use ieee.std_logic_1164.all;
45
 
46
 
47
entity hdbnd is
48
    generic (
49
        EncoderType             : integer range 2 to 3 := 3;   -- 3: HDB3 2: HDB2/B3ZS
50
        PulseActiveState        : std_logic := '1'          -- active state of P and N inputs
51
    );
52
    port (
53
        Reset_i                 : in    std_logic := '0';   -- active high async reset
54
        Clk_i                   : in    std_logic;          -- rising edge clock
55
        ClkEnable_i             : in    std_logic := '1';   -- active high clock enable
56
        P_i                     : in    std_logic;          -- +ve pulse input
57
        N_i                     : in    std_logic;          -- -ve pulse input
58
        Data_o                  : out   std_logic;          -- active high data output
59
        CodeError_o             : out   std_logic           -- active high error indicator
60
    );
61
end hdbnd; -- End entity hdbnd
62
 
63
 
64
architecture rtl of hdbnd is
65
 
66
    signal  PinRaw                  : std_logic;    -- registered P input
67
    signal  NinRaw                  : std_logic;    -- registered N input
68
    signal  Pin                     : std_logic;    -- registered P input (with polarity corrected)
69
    signal  Nin                     : std_logic;    -- registered N input (with polarity corrected)
70
    signal  Violation               : std_logic;    -- pulse violation detected
71
    signal  LastPulsePolarity       : std_logic;    -- last pulse sense 1=P, 0=N
72
    signal  LastViolationPolarity   : std_logic;    -- last violation sense "
73
 
74
    -- shift register bits (to align data with violations, so we can delete them)
75
    signal  Q1                      : std_logic;
76
    signal  Q2                      : std_logic;
77
    signal  Q3                      : std_logic;
78
 
79
    -- signals used for calculating CodeError
80
    signal  ViolationError          : std_logic;    -- indicates bad violation
81
    signal  ZeroCount               : integer range 0 to 3; -- counts 0s in input
82
    signal  TooManyZeros            : std_logic;    -- indicates 4 consecutive zeros detected
83
    signal  PulseError              : std_logic;    -- indicates simultaneous P and N pulse
84
 
85
begin
86
 
87
-------------------------------------------------------------------------------
88
-- PROCESS    : RegisterInput
89
-- DESCRIPTION: DFF to register P and N inputs (reduces fan-in, etc)
90
--              Most applications of this core will be taking inputs from
91
--              off-chip, so these FF will be in the I/O blocks.
92
-- Metastability issues: None.
93
--  Either (1) the external CDR provides adequate
94
--  timing margin (which ensures no metastability issues)
95
--  or (2) it doesn't provide adequate timing margin (which could happen
96
--  if the input cable is unplugged) and any metastable states are irrelevant,
97
--  as the downstream decoding logic is free of lockup states,
98
--  and will recover within a few clocks once the
99
--  CDR is providing normal input again.
100
-------------------------------------------------------------------------------
101
    RegisterInput: process (Reset_i, Clk_i)
102
    begin
103
        if Reset_i = '1' then
104
            PinRaw <= '0';
105
            NinRaw <= '0';
106
        elsif rising_edge(Clk_i) then
107
            if ClkEnable_i = '1' then
108
                PinRaw <= to_X01(P_i);
109
                NinRaw <= to_X01(N_i);
110
            end if;
111
        end if;
112
    end process RegisterInput;
113
 
114
 
115
    --  Restore active low pulse inputs to active high for internal use.
116
    Pin <= PinRaw xor (not PulseActiveState);
117
    Nin <= NinRaw xor (not PulseActiveState);
118
 
119
 
120
-------------------------------------------------------------------------------
121
-- PROCESS    : DecodeViolation
122
-- DESCRIPTION: Work out whether there has been a pulse violation, and
123
--              remember the sense of the last input pulse.
124
-------------------------------------------------------------------------------
125
    DecodeViolation: process (Reset_i, Clk_i)
126
        variable tmp : std_logic_vector(1 downto 0);
127
    begin
128
        if Reset_i = '1' then
129
            LastPulsePolarity <= '0';
130
        elsif rising_edge(Clk_i) then
131
            if ClkEnable_i = '1' then
132
                tmp := Pin & Nin;
133
                case tmp is
134
                    when "00"   =>   LastPulsePolarity <= LastPulsePolarity; --hold
135
                    when "10"   =>   LastPulsePolarity <= '1';   -- set
136
                    when "01"   =>   LastPulsePolarity <= '0';   -- reset
137
                    when others =>   LastPulsePolarity <= '0';   -- don't care
138
                end case;
139
            end if;
140
        end if;
141
    end process DecodeViolation;
142
 
143
    Violation <= (Pin and LastPulsePolarity) or (Nin and (not LastPulsePolarity));
144
 
145
 
146
-------------------------------------------------------------------------------
147
-- PROCESS    : DelayData
148
-- DESCRIPTION: Delay the data input so that it lines up with the violation
149
-- signal, so we can remove the B bit (in process DecodeData).
150
-------------------------------------------------------------------------------
151
    DelayData: process (Reset_i, Clk_i)
152
    begin
153
        if Reset_i = '1' then
154
            Q1 <= '0';
155
            Q2 <= '0';
156
            Q3 <= '0';
157
        elsif rising_edge(Clk_i) then
158
            if ClkEnable_i = '1' then
159
                Q1 <=  (Pin or Nin) and (not Violation); -- delete V bit
160
                Q2 <= Q1;
161
                if EncoderType = 3 then
162
                    -- HDB3, delay by 3 clocks
163
                    Q3 <= Q2;
164
                else
165
                    -- HDB2, delay by 2 clocks
166
                    Q3 <= Q1;   -- skip Q2
167
                end if;
168
            end if;
169
        end if;
170
    end process DelayData;
171
 
172
 
173
-------------------------------------------------------------------------------
174
-- PROCESS    : DecodeData
175
-- DESCRIPTION: remove B bits from data, and register output
176
-------------------------------------------------------------------------------
177
    DecodeData: process (Reset_i, Clk_i)
178
    begin
179
        if Reset_i = '1' then
180
            Data_o <= '0';
181
        elsif rising_edge(Clk_i) then
182
            if ClkEnable_i = '1' then
183
                Data_o <= Q3 and (not Violation); -- delete B bit
184
            end if;
185
        end if;
186
    end process DecodeData;
187
 
188
 
189
-------------------------------------------------------------------------------
190
-- PROCESS    : CountZeros
191
-- DESCRIPTION: count number of contiguous zeros in input (mod 3 or 4)
192
-------------------------------------------------------------------------------
193
    CountZeros: process (Reset_i, Clk_i)
194
    begin
195
        if Reset_i = '1' then
196
            ZeroCount <= 0;
197
        elsif rising_edge(Clk_i) then
198
            if ClkEnable_i = '1' then
199
                if (Pin or Nin) = '1' then
200
                    ZeroCount <= 0;             -- have seen a 1, reset count
201
                elsif ZeroCount >= EncoderType then
202
                    ZeroCount <= EncoderType;   -- hold
203
                else
204
                    ZeroCount <= ZeroCount + 1; -- increment
205
                end if;
206
            end if;
207
        end if;
208
    end process CountZeros;
209
 
210
 
211
-------------------------------------------------------------------------------
212
-- PROCESS    : DecodeViolationError
213
-- DESCRIPTION: Remember the polarity of this violation, so that we can work
214
--              out whether the next violation is an error.
215
-------------------------------------------------------------------------------
216
    DecodeViolationError: process (Reset_i, Clk_i)
217
    begin
218
        if Reset_i = '1' then
219
            LastViolationPolarity <= '0';
220
        elsif rising_edge(Clk_i) then
221
            if ClkEnable_i = '1' then
222
                if Violation = '1' then
223
                    LastViolationPolarity <= LastPulsePolarity;
224
                else
225
                    LastViolationPolarity <= LastViolationPolarity; -- latch
226
                end if;
227
            end if;
228
        end if;
229
    end process DecodeViolationError;
230
 
231
 
232
-------------------------------------------------------------------------------
233
-- The follow logic checks for various error conditions.
234
-------------------------------------------------------------------------------
235
 
236
    ViolationError <= Violation and (not (Pin xor LastViolationPolarity));
237
 
238
    PulseError <= Pin and Nin;
239
 
240
    TooManyZeros <= (not (Pin or Nin)) when (ZeroCount = EncoderType) else '0';
241
 
242
 
243
-------------------------------------------------------------------------------
244
-- PROCESS    : RegisterCodeError
245
-- DESCRIPTION: combine all error signals and register the output
246
-------------------------------------------------------------------------------
247
    RegisterCodeError: process (Reset_i, Clk_i)
248
    begin
249
        if Reset_i = '1' then
250
            CodeError_o <= '0';
251
        elsif rising_edge(Clk_i) then
252
            if ClkEnable_i = '1' then
253
                CodeError_o <= ViolationError or PulseError or TooManyZeros;
254
            end if;
255
        end if;
256
    end process RegisterCodeError;
257
 
258
 
259
end rtl; -- End architecture rtl;
260
-------------------------------------------------------------------------------
261
-- End of hdbnd.vhd
262
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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