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

Subversion Repositories e1framer

[/] [e1framer/] [trunk/] [e1_defr.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 victor
 
2
library ieee;
3
use ieee.std_logic_1164.all;
4
USE ieee.std_logic_arith.all;
5
USE ieee.std_logic_unsigned.all;
6
 
7
 
8
entity e1_defr is
9
port(E1_in: in STD_LOGIC;--input serial stream
10
         E1_CLK_in: in STD_LOGIC;--clock for input stream
11
         reset: in STD_LOGIC; -- reset
12
         frame_start,byte_ready,sync_ok: out STD_LOGIC;
13
        -- fr1,fr2: out STD_LOGIC;
14
         data: out STD_LOGIC_VECTOR (0 to 7);
15
        -- erri: out integer range 0 to 3;
16
         zero_frame: out STD_LOGIC_VECTOR (0 to 7)--;
17
        -- output: out STD_LOGIC_VECTOR (1 downto 0)
18
        );
19
end e1_defr ;
20
 
21
architecture BEHAVIOR of e1_defr is
22
 
23
constant BITS_IN_FRAME: integer :=255;--!!!!!!!!!!!!!!!!!!255
24
 
25
 
26
SIGNAL frame1_det,frame2_det: STD_LOGIC ;
27
signal prl_in:STD_LOGIC_VECTOR (0 to 7);
28
signal state: STD_LOGIC_VECTOR (1 downto 0);
29
 
30
begin
31
data<=prl_in;
32
-------------------------------------------------------------------------------------------------------
33
-- frame1 and frame2  detection
34
-------------------------------------------------------------------------------------------------------
35
frame2_det<=prl_in(1);
36
with prl_in select
37
         frame1_det<='1' when "10011011",
38
                                 '0' when others;
39
------------------------------------------------------------------------------------------------------
40
-- lower bits come first!!!
41
-- serial to parallel converter
42
------------------------------------------------------------------------------------------------------
43
process (E1_CLK_in)
44
begin
45
if (FALLING_EDGE(E1_CLK_in)) then
46
prl_in(0 to 6)<=prl_in(1 to 7);
47
prl_in(7)<=E1_in;
48
end if;
49
end process;
50
 
51
--------------------------------------------------------------------------------------------------------
52
-- state machine using GRAY CODE (or trying to use GRAY CODE :-) )
53
-- 00 - waiting for the first frame syncronization sygnal
54
-- 01 - skipping other frame bits + 8 bits of next syncro signal and trying to detect second frame sync.
55
-- signal, if all OK go to the 011 state, else to the 000 state
56
-- 11 - skipping other frame bits + 8 bits of next syncro signal and trying to detect first frame sync.
57
-- signal, if all OK go to the 010 state, else to the 000 state
58
-- 10 - start normal data receiving. Syncronizanion complete.
59
--------------------------------------------------------------------------------------------------------
60
process (E1_CLK_in,reset)
61
variable cnt : integer range 0 to 255;
62
variable s_err: integer range 0 to 3;
63
variable frame_flag: std_logic;-- determines type of the frame
64
begin
65
if (reset='1') then
66
    state<="00";
67
elsif (RISING_EDGE(E1_CLK_in)) then
68
CASE state IS
69
        WHEN "00" =>
70
                sync_ok<='0';-- no syncronization
71
                frame_start<='0';
72
            state(0)<=frame1_det; -- waiting for the first frame alignment, if detected go to the next state
73
                cnt:=0;
74
                frame_flag:='0';
75
                s_err:=0;
76
        WHEN "01" =>
77
            if (cnt = BITS_IN_FRAME) then
78
                        state(0)<=frame2_det;
79
                        state(1)<=frame2_det;
80
                        cnt:=0;
81
                else
82
                        cnt:=cnt+1;
83
                end if;
84
        WHEN "11" =>
85
                if (cnt = BITS_IN_FRAME) then
86
                        state(0)<='0';
87
                        state(1)<=frame1_det;
88
                        cnt:=0;
89
                else
90
                        cnt:=cnt+1;
91
                end if;
92
        WHEN "10" =>
93
                sync_ok<='1';-- syncronization established
94
                if (cnt = BITS_IN_FRAME) then
95
                        if(frame_flag='0') then -- detecting wrong syncro signal ?????? according to g704
96
                                zero_frame<=prl_in;--store zero frame for future transmission
97
                                if(frame2_det='0') then
98
                                        s_err:=s_err+1;
99
                                else
100
                                        s_err:=0;
101
                                end if;
102
                        end if;
103
                        cnt:=0;
104
                        frame_start<='0';-- frame ended
105
                        frame_flag:=not(frame_flag);-- change type of zero time-slot
106
                else
107
--byte_ready placed there to avoid byte_ready generation then time-slot 0 received (cnt = BITS_IN_RFAME)                        
108
                        frame_start<='1';--frame begins
109
                        byte_ready<=CONV_STD_LOGIC_VECTOR(cnt,3)(0) and CONV_STD_LOGIC_VECTOR(cnt,3)(1) and CONV_STD_LOGIC_VECTOR(cnt,3)(2);
110
                        cnt:=cnt+1;
111
                end if;
112
-- if received 3 consecutive wrong frame alignment signals system detect "loss of frame alignment" situation
113
                state(1)<=not(CONV_STD_LOGIC_VECTOR(s_err,2)(0) and CONV_STD_LOGIC_VECTOR(s_err,2)(1));
114
        when others=> state<="00";
115
END CASE;
116
 
117
end if;
118
end process;
119
 
120
end BEHAVIOR;
121
 

powered by: WebSVN 2.1.0

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