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

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [tbench/] [systemc/] [sc_pkt_if.cpp] - Blame information for rev 29

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 antanguay
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "sc_pkt_if.cpp"                                   ////
4
////                                                              ////
5
////  This file is part of the "10GE MAC" project                 ////
6
////  http://www.opencores.org/cores/xge_mac/                     ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - A. Tanguay (antanguay@opencores.org)                  ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
#include <stdio.h>
39
#include <iostream>
40
#include <sys/times.h>
41
#include <sys/stat.h>
42
 
43
#include "systemc.h"
44
 
45
#include "sc_pkt_if.h"
46
 
47
sc_fifo<packet_t*> * pkt_if::get_tx_fifo_ptr() {
48
    return &tx_fifo;
49
}
50
 
51
sc_fifo<packet_t*> * pkt_if::get_rx_fifo_ptr() {
52
    return &rx_fifo;
53
}
54
 
55
void pkt_if::init(void) {
56
    disable_rx = false;
57 29 antanguay
    flush_rx = false;
58 2 antanguay
    allow_rx_sop_err = false;
59
}
60
 
61
void pkt_if::connect_scoreboard(scoreboard *sbptr, scoreboard::sbSourceId sid) {
62
    sb = sbptr;
63
    sb_id = sid;
64
}
65
 
66
void pkt_if::transmit() {
67
 
68
    packet_t* pkt;
69
 
70
    while (true) {
71
 
72
        wait();
73
 
74
        if (tx_fifo.nb_read(pkt)) {
75
 
76
            pack(pkt);
77
 
78
            //cout << "Transmit PKT_IF packet:\n" << * pkt << endl;
79
 
80
            pkt_tx_val = 1;
81
 
82
            for (int i = 0; i < pkt->length; i += 8) {
83
 
84 15 antanguay
                pkt_tx_data = pkt->data[i] << 56 |
85
                    pkt->data[i+1] << 48 |
86
                    pkt->data[i+2] << 40 |
87
                    pkt->data[i+3] << 32 |
88
                    pkt->data[i+4] << 24 |
89
                    pkt->data[i+5] << 16 |
90
                    pkt->data[i+6] << 8 |
91
                    pkt->data[i+7];
92 2 antanguay
 
93
                if (i == 0) {
94
                    pkt_tx_sop = 1;
95
                }
96
                else {
97
                    pkt_tx_sop = 0;
98
                }
99
 
100
                if (i + 8 >= pkt->length) {
101 6 antanguay
                    pkt_tx_eop = 1;
102
                    pkt_tx_mod = pkt->length % 8;
103 2 antanguay
                }
104
                else {
105
                    pkt_tx_eop = 0;
106
                }
107
 
108
                wait();
109
            }
110
 
111
            pkt_tx_val = 0;
112
 
113
 
114
            //---
115
            // Pass packet to scoreboard
116
 
117
            sb->notify_packet_tx(sb_id, pkt);
118
 
119
            //---
120 29 antanguay
            // Wait for room in the FIFO before processing next packet
121 2 antanguay
 
122 29 antanguay
            while (pkt_tx_full) {
123 2 antanguay
                wait();
124
            }
125
        }
126
    }
127
};
128
 
129
 
130
void pkt_if::receive() {
131
 
132
    packet_t* pkt;
133
 
134
    sc_uint<64> data;
135
 
136 29 antanguay
    bool flush;
137
 
138 2 antanguay
    wait();
139
 
140
    while (true) {
141
 
142
        if (pkt_rx_avail && !disable_rx) {
143
 
144
            pkt = new(packet_t);
145
            pkt->length = 0;
146 29 antanguay
            pkt->err_flags = 0;
147
            flush = false;
148 2 antanguay
 
149
            // If reading already selected just keep going,
150
            // if not we must enable ren
151
            if (!pkt_rx_ren) {
152
                pkt_rx_ren = 1;
153
                wait();
154
            };
155
 
156
            while (true) {
157
 
158
                wait();
159
 
160
                if (!pkt_rx_val) {
161
                    continue;
162
                }
163
 
164
                // Check SOP
165
 
166
                if (pkt->length != 0 && pkt_rx_sop) {
167
                    if (allow_rx_sop_err) {
168
                        cout << "INFO: SOP errors allowed" << endl;
169
                        pkt->length = 0;
170
                        pkt->err_flags = 0;
171
                    }
172
                    else {
173
                        pkt->err_flags |= PKT_FLAG_ERR_SOP;
174
                    }
175
                }
176
 
177
                // Check error line
178
 
179
                if (pkt_rx_err) {
180
                    pkt->err_flags |= PKT_FLAG_ERR_SIG;
181
                }
182
 
183
                // Capture data
184
 
185
                data = pkt_rx_data;
186
 
187
                for (int lane = 0; lane < 8; lane++) {
188
 
189 15 antanguay
                    pkt->data[pkt->length++] = (data >> (8 * (7-lane))) & 0xff;
190 2 antanguay
 
191 29 antanguay
                    if (pkt->length >= 17000) {
192 2 antanguay
                        cout << "ERROR: Packet too long" << endl;
193
                        sc_stop();
194
                    }
195
 
196 6 antanguay
                    if (pkt_rx_eop && (pkt_rx_mod == ((lane+1) % 8))) {
197 2 antanguay
                        break;
198
                    }
199
                }
200
 
201
                // Stop on EOP
202 15 antanguay
 
203 2 antanguay
                if (pkt_rx_eop) {
204
                    break;
205
                }
206
            }
207
 
208 29 antanguay
            if (flush_rx && pkt->err_flags) {
209
                flush = true;
210
            }
211
 
212 2 antanguay
            //---
213
            // Store packet
214
 
215
            unpack(pkt);
216
            //rx_fifo.write(pkt);
217
 
218
            //cout << "Receive PKT_IF packet:\n" << * pkt << endl;
219
 
220
            //---
221
            // Pass packet to scoreboard
222
 
223 29 antanguay
            if (!flush) {
224
                sb->notify_packet_rx(sb_id, pkt);
225
            }
226 2 antanguay
 
227
        }
228
        else {
229
            pkt_rx_ren = 0;
230 15 antanguay
            wait();
231 2 antanguay
        }
232
    }
233
};

powered by: WebSVN 2.1.0

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