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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [sim/] [mMACEmulator.sv] - Blame information for rev 15

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 jefflieu
/*
2
Developed by Jeff Lieu (lieumychuong@gmail.com)
3
 
4
File            :
5
Description     :
6
 
7
Remarks         :
8
 
9
Revision        :
10
        Date    Author  Description
11
 
12
*/
13
`timescale 1ns/10ps
14
 
15
module mMACEmulator(
16
        input i_RxClk,
17
        input i_TxClk,
18
        input [07:00] i8_RxD,
19
        input i_RxDV,
20 11 jefflieu
        input i_RxER,
21 4 jefflieu
        output reg [07:00] o8_TxD,
22
        output reg o_TxEN,
23
        output reg o_TxER,
24
 
25 11 jefflieu
        input [1:0] i2_Speed,
26 4 jefflieu
        input i_Reset_L);
27
 
28
        reg r_Active;
29
        integer Octet;
30
        integer ExtCycles;
31
        integer ErrCycles;
32
        integer RxPktCnt;
33
        wire w_Active;
34
        wire w_Sop;
35
        wire w_Eop;
36
        reg [07:00] ReceivedPkt[0:10000];
37 6 jefflieu
        reg [07:00] r8_LstRxD;
38 4 jefflieu
        integer RxPtr;
39
        reg ReceiveEnable;
40
 
41
        assign w_Sop = ~r_Active & w_Active;
42
        assign w_Eop = r_Active & (~w_Active);
43
 
44
 
45
                initial
46
                        begin
47
                        RxPktCnt=0;
48
                        o_TxEN=0;
49
                        o_TxER=0;
50
                        o8_TxD=0;
51
                        ReceiveEnable <= 1'b0;
52
                        end
53
 
54
        assign w_Active=i_RxDV|i_RxER;
55
        always@(posedge i_RxClk)
56
                begin
57 6 jefflieu
                        r_Active <= w_Active;
58
                        r8_LstRxD       <= i8_RxD;
59 4 jefflieu
                end
60
 
61
 
62
 
63
 
64
        task automatic tsk_ReceivePkt;
65
                output [07:00] ov_ReceivedPkt[0:10000];
66
                output integer FrameSize;
67
                output integer ExtCycles;
68
                output integer ErrCycles;
69
 
70
                integer Octet;
71
        begin
72
                ExtCycles = 0;
73
                ErrCycles = 0;
74
                for(Octet=0;Octet<10000;Octet=Octet+1)
75
                        ov_ReceivedPkt[Octet]=0;
76
                Octet=0;
77 11 jefflieu
                $display("(%d)MAC       : Start Rx Task",$time);
78
                if(i2_Speed==2'b10)
79
                begin
80
                        while(w_Active!=1'b1||r_Active!=1'b0)
81
                                @(posedge i_RxClk);
82
                        while(w_Active!=1'b1||i8_RxD!=8'hD5||r8_LstRxD!=8'h55)
83
                                @(posedge i_RxClk);
84
 
85 4 jefflieu
                        @(posedge i_RxClk);
86 11 jefflieu
                        $display("MAC: Start Receiving");
87
                        while(r_Active!=1'b1||w_Active!=1'b0)
88
                        begin
89
                                if(i_RxDV==1'b1 && i_RxER==1'b0)
90
                                        begin
91
                                        ov_ReceivedPkt[Octet]=i8_RxD;
92
                                        Octet=Octet+1;
93
                                        end
94
                                else if(i_RxDV==1'b0 && i_RxER==1'b1)
95
                                        begin
96
                                                case(i8_RxD)
97
                                                8'h0F: begin
98
                                                                ExtCycles = ExtCycles+1;
99
                                                           end
100
                                                8'h1F: begin
101
                                                                $display("Error Propagation");
102
                                                                ExtCycles = ExtCycles+1;
103
                                                                ErrCycles = ErrCycles+1;
104
                                                                end
105
                                                default: $display("Unknown %x",i8_RxD);
106
                                                endcase
107
                                        end
108
                                else if(i_RxDV==1'b1 && i_RxER==1'b1)
109
                                        begin
110
                                                ErrCycles = ErrCycles+1;
111
                                        end
112
                                @(posedge i_RxClk);
113
                        end
114
                end
115
                else
116
                begin
117
                        while(w_Active!=1'b1||r_Active!=1'b0)
118
                                @(posedge i_RxClk);
119
                        while(w_Active!=1'b1||i8_RxD[3:0]!=4'hD||r8_LstRxD[3:0]!=4'h5)
120
                                @(posedge i_RxClk);
121 6 jefflieu
                        @(posedge i_RxClk);
122 11 jefflieu
                        $display("MAC: Start Receiving");
123
                        while(r_Active!=1'b1||w_Active!=1'b0)
124
                        begin
125
                                if(i_RxDV==1'b1 && i_RxER==1'b0)
126
                                        begin
127
                                        ov_ReceivedPkt[Octet][3:0]=i8_RxD[3:0];
128
                                        @(posedge i_RxClk);
129
                                        ov_ReceivedPkt[Octet][7:4]=i8_RxD[3:0];
130
                                        Octet=Octet+1;
131
                                        end
132
                                else if(i_RxDV==1'b1 && i_RxER==1'b1)
133
                                        begin
134
                                                ErrCycles = ErrCycles+1;
135
                                        end
136
                                @(posedge i_RxClk);
137
                        end
138 6 jefflieu
 
139 11 jefflieu
 
140 4 jefflieu
                end
141
                FrameSize=Octet;
142
                $display("MAC: Packet Received with %d bytes",FrameSize);
143
        end
144
        endtask
145
 
146
        task automatic tsk_TransmitPkt;
147
                ref reg [7:0] iv_TransmitPkt[0:10000];
148
                input integer PktSize;
149
                input integer PktIFG;
150
 
151
                integer Octet;
152 11 jefflieu
        begin
153
                if(i2_Speed==2'b10)
154
                begin
155
                        for(Octet=0;Octet<8;Octet++)
156 4 jefflieu
                                begin
157
                                @(posedge i_TxClk);#1;
158
                                o_TxEN = 1'b1;
159
                                o_TxER = 1'b0;
160 11 jefflieu
                                o8_TxD = (Octet==7)?8'hD5:8'h55;
161 4 jefflieu
                                end
162 11 jefflieu
                        for(Octet=0;Octet
163
                                        begin
164
                                        @(posedge i_TxClk);#1;
165
                                        o_TxEN = 1'b1;
166
                                        o_TxER = 1'b0;
167
                                        o8_TxD = iv_TransmitPkt[Octet];
168
                                        end
169
                                        @(posedge i_TxClk);#1;
170
                                        o_TxEN = 1'b0;
171
                                //Interframe Gap
172
                                for(Octet=0;Octet
173
                                        begin @(posedge i_TxClk);#1; end
174
                end else
175
                begin
176
                        for(Octet=0;Octet<8;Octet++)
177
                                begin
178 4 jefflieu
                                @(posedge i_TxClk);#1;
179 11 jefflieu
                                o_TxEN = 1'b1;
180
                                o_TxER = 1'b0;
181
                                o8_TxD = (Octet==7)?8'h5:8'h5;
182
                                @(posedge i_TxClk);#1;
183
                                o8_TxD = (Octet==7)?8'hD:8'h5;
184
                                end
185
                        for(Octet=0;Octet
186
                                        begin
187
                                        @(posedge i_TxClk);#1;
188
                                        o_TxEN = 1'b1;
189
                                        o_TxER = 1'b0;
190
                                        o8_TxD = iv_TransmitPkt[Octet][3:0];
191
                                        @(posedge i_TxClk);#1;
192
                                        o8_TxD = iv_TransmitPkt[Octet][7:4];
193
                                        end
194
                                @(posedge i_TxClk);#1;
195 4 jefflieu
                                o_TxEN = 1'b0;
196 11 jefflieu
                                //Interframe Gap
197
                                for(Octet=0;Octet
198
                                        begin @(posedge i_TxClk);#1; end
199
                end
200 4 jefflieu
        end
201
        endtask
202
 
203
 
204
endmodule

powered by: WebSVN 2.1.0

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