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

Subversion Repositories hdbn

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 allanh
-------------------------------------------------------------------------------
2
-- Title        : hdbne
3
-- Project      : hdbn
4
-------------------------------------------------------------------------------
5
-- File         : hdbne.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 decoder is hdb3d.
18
-------------------------------------------------------------------------------
19
-- Description  : HDB3 or HDB2 (B3ZS) encoder.
20
--                P and N outputs are full width by default.
21
--  Half width pulses can be created by using a double rate clock and
22
--  strobing ClkEnable and OutputEnable appropriately (high every second clock).
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
--  The outputs will require pulse shaping if used to drive the line.
27
--  These encodings are polarity insensitive, so the P and N outputs may be
28
--  used interchangeably (swapped).
29
--
30
-- Reference    : ITU-T G.703
31
--
32
-------------------------------------------------------------------------------
33
-- Copyright (c) notice
34
-- http://www.opensource.org/licenses/bsd-license.html
35
--
36
-------------------------------------------------------------------------------
37
--
38
-- CVS Revision History
39
--
40
-- $Log: not supported by cvs2svn $
41
--
42
------------------------------------------------------------------------------
43
 
44
library ieee;
45
use ieee.std_logic_1164.all;
46
 
47
 
48
entity hdbne is
49
    generic (
50
        EncoderType             : integer range 2 to 3 := 3;   -- 3: HDB3 2: HDB2/B3ZS
51
        PulseActiveState        : std_logic := '1'          -- active state of P and N outputs
52
    );
53
    port (
54
        Reset_i                 : in    std_logic := '0';   -- active high async reset
55
        Clk_i                   : in    std_logic;          -- rising edge clock
56
        ClkEnable_i             : in    std_logic := '1';   -- active high clock enable
57
        Data_i                  : in    std_logic;          -- active high data input
58
        OutputGate_i            : in    std_logic := '1';   -- '0' forces P and N to not PulseActiveState (synchronously, but ignoring ClkEnable)
59
        P_o                     : out   std_logic;          -- encoded +ve pulse output
60
        N_o                     : out   std_logic           -- encoded -ve pulse output
61
    );
62
end hdbne; -- End entity hdbne
63
 
64
 
65
architecture rtl of hdbne is
66
 
67
    signal  Q1                  : std_logic;    -- Q1 through Q5 form a shift
68
    signal  Q2                  : std_logic;    --   register for aligning
69
    signal  Q3                  : std_logic;    --   the data so we can insert
70
    signal  Q4                  : std_logic;    --   the violations
71
    signal  Q5                  : std_logic;
72
 
73
    signal  AMI                 : std_logic;    -- sense of pulse (P or N)
74
    signal  ViolationType       : std_logic;    -- sense of violation
75
    signal  ZeroCount           : integer range 0 to 3; -- counts 0s in input
76
    signal  ZeroString          : std_logic;    -- goes to '1' when 3 or 4 0s seen
77
    signal  ZeroStringDelayed   : std_logic;    -- above delayed by 1 clock
78
 
79
begin
80
 
81
-------------------------------------------------------------------------------
82
-- PROCESS    : RegisterInput
83
-- DESCRIPTION: DFF (Q1) to register input data (reduces fan-in, etc)
84
-------------------------------------------------------------------------------
85
    RegisterInput: process (Reset_i, Clk_i)
86
    begin
87
        if Reset_i = '1' then
88
            Q1 <= '0';
89
        elsif rising_edge(Clk_i) then
90
            if ClkEnable_i = '1' then
91
                Q1 <= to_X01(Data_i);
92
            end if;
93
        end if;
94
    end process RegisterInput;
95
 
96
 
97
-------------------------------------------------------------------------------
98
-- PROCESS    : CountZeros
99
-- DESCRIPTION: count number of contiguous zeros in input (mod 4 or mod 3)
100
-------------------------------------------------------------------------------
101
    CountZeros: process (Reset_i, Clk_i)
102
    begin
103
        if Reset_i = '1' then
104
            ZeroCount <= 0;
105
        elsif rising_edge(Clk_i) then
106
            if ClkEnable_i = '1' then
107
                if Q1 = '1' then
108
                    ZeroCount <= 0;                 -- have seen a 1, reset count
109
                elsif ZeroCount >= EncoderType then
110
                    ZeroCount <= 0;                 -- increment modulo 3 or 4
111
                else
112
                    ZeroCount <= ZeroCount + 1;     -- increment
113
                end if;
114
            end if;
115
        end if;
116
    end process CountZeros;
117
 
118
 
119
-------------------------------------------------------------------------------
120
-- PROCESS    : DecodeCount (combinatorial)
121
-- DESCRIPTION: decode ZeroCount to indicate when string of 3 or 4 zeros is present
122
--  Note: this process is not clocked
123
-------------------------------------------------------------------------------
124
    DecodeCount: process (Q1, ZeroCount)
125
    begin
126
        if ZeroCount = EncoderType and Q1 = '0' then
127
            ZeroString <= '1';
128
        else
129
            ZeroString <= '0';
130
        end if;
131
    end process DecodeCount;
132
 
133
 
134
-------------------------------------------------------------------------------
135
-- PROCESS    : RegisterZeroString
136
-- DESCRIPTION: DFF to register the ZeroString signal
137
-------------------------------------------------------------------------------
138
    RegisterZeroString: process (Reset_i, Clk_i)
139
    begin
140
        if Reset_i = '1' then
141
            ZeroStringDelayed <= '0';
142
        elsif rising_edge(Clk_i) then
143
            if ClkEnable_i = '1' then
144
                ZeroStringDelayed <= ZeroString;
145
            end if;
146
        end if;
147
    end process RegisterZeroString;
148
 
149
 
150
-------------------------------------------------------------------------------
151
-- PROCESS    : DelayData
152
-- DESCRIPTION: insert 1 if needed for violation, and delay data by 2 or 3 clocks
153
--  to line up with ZeroString detection.
154
-------------------------------------------------------------------------------
155
    DelayData: process (Reset_i, Clk_i)
156
    begin
157
        if Reset_i = '1' then
158
            Q2 <= '0';
159
            Q3 <= '0';
160
            Q4 <= '0';
161
        elsif rising_edge(Clk_i) then
162
            if ClkEnable_i = '1' then
163
                Q2 <= Q1 or ZeroString;  -- insert Violation bit
164
                Q3 <= Q2;
165
                if EncoderType = 3 then
166
                    -- HDB3, delay by 3 clocks
167
                    Q4 <= Q3;
168
                else
169
                    -- HDB2, delay by 2 clocks
170
                    Q4 <= Q2;   -- skip Q3
171
                end if;
172
            end if;
173
        end if;
174
    end process DelayData;
175
 
176
 
177
-------------------------------------------------------------------------------
178
-- PROCESS    : InsertBBit
179
-- DESCRIPTION: Delay Q4 by one clock, and insert B bit if needed.
180
-------------------------------------------------------------------------------
181
    InsertBBit: process (Reset_i, Clk_i)
182
    begin
183
        if Reset_i = '1' then
184
            Q5 <= '0';
185
        elsif rising_edge(Clk_i) then
186
            if ClkEnable_i = '1' then
187
                Q5 <= Q4 or (ZeroString and (not ViolationType));
188
            end if;
189
        end if;
190
    end process InsertBBit;
191
 
192
 
193
-------------------------------------------------------------------------------
194
-- PROCESS    : ToggleViolationType
195
-- DESCRIPTION: Toggle ViolationType whenever Q5 is 1
196
-------------------------------------------------------------------------------
197
    ToggleViolationType: process (Reset_i, Clk_i)
198
    begin
199
        if Reset_i = '1' then
200
            ViolationType <= '0';
201
        elsif rising_edge(Clk_i) then
202
            if ClkEnable_i = '1' then
203
                ViolationType <= ViolationType xor Q5;
204
            end if;
205
        end if;
206
    end process ToggleViolationType;
207
 
208
 
209
-------------------------------------------------------------------------------
210
-- PROCESS    : AMIFlipFlop
211
-- DESCRIPTION: toggle AMI to alternate P and N pulses.  Force a violation (no
212
-- toggle) occasionally.
213
-------------------------------------------------------------------------------
214
    AMIFlipFlop: process (Reset_i, Clk_i)
215
    begin
216
        if Reset_i = '1' then
217
            AMI <= '0';
218
        elsif rising_edge(Clk_i) then
219
            if ClkEnable_i = '1' then
220
                AMI <= AMI xor (Q5 and (ViolationType nand (ZeroString or ZeroStringDelayed)));
221
            end if;
222
        end if;
223
    end process AMIFlipFlop;
224
 
225
 
226
-------------------------------------------------------------------------------
227
-- PROCESS    : MakePandNPulses
228
-- DESCRIPTION: Gate Q5 with AMI to produce the P and N outputs
229
--  Note that OutputEnable overrides ClkEnable, to allow creation of
230
--  half width pulses.
231
-- The flip flops P and N will drive the outputs to the LIU, and these
232
-- flip flops should be in the IOBs in an FPGA.  Clk to output delay
233
-- should be matched for P and N to avoid pulse shape distortion at the LIU
234
-- output.
235
-------------------------------------------------------------------------------
236
    MakePandNPulses: process (Reset_i, Clk_i)
237
    begin
238
        if Reset_i = '1' then
239
            P_o <= not PulseActiveState;
240
            N_o <= not PulseActiveState;
241
        elsif rising_edge(Clk_i) then
242
            if ClkEnable_i = '1' or OutputGate_i /= '1' then
243
                if OutputGate_i /= '1' then
244
                    -- force output to '0'
245
                    P_o <= not PulseActiveState;
246
                    N_o <= not PulseActiveState;
247
                else
248
                    -- normal operation
249
                    if Q5 = '1' then
250
                        if AMI = '1' then
251
                            -- output '1' on P
252
                            P_o <= PulseActiveState;
253
                            N_o <= not PulseActiveState;
254
                        else
255
                            -- output '1' on N
256
                            P_o <= not PulseActiveState;
257
                            N_o <= PulseActiveState;
258
                        end if;
259
                    else
260
                        -- output '0'
261
                        P_o <= not PulseActiveState;
262
                        N_o <= not PulseActiveState;
263
                    end if;
264
                end if;
265
            end if;
266
        end if;
267
    end process MakePandNPulses;
268
 
269
 
270
end rtl; -- End architecture rtl;
271
-------------------------------------------------------------------------------
272
-- End of hdbne.vhd
273
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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