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

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [tbench/] [systemc/] [sc_cpu_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_cpu_if.h"                                     ////
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_cpu_if.h"
46
 
47
void cpu_if::init() {
48
};
49
 
50
void cpu_if::connect_scoreboard(scoreboard *sbptr, scoreboard::sbSourceId sid) {
51
    sb = sbptr;
52
    sb_id = sid;
53
}
54
 
55
void cpu_if::set_param(cpu_if::paramId param, int value) {
56
 
57
    switch (param) {
58
 
59
      case TX_ENABLE:
60
          writebits(cpu_if::CPUREG_CONFIG0, 0, 0, value);
61
          break;
62
 
63
    }
64
 
65
};
66
 
67
void cpu_if::set_interrupt(cpu_if::intId intr) {
68
 
69
    writebits(cpu_if::CPUREG_INT_PENDING, intr, intr, 1);
70
};
71
 
72
void cpu_if::set_interrupt_mask(cpu_if::intId intr, bool value) {
73
 
74
    writebits(cpu_if::CPUREG_INT_MASK, intr, intr, value);
75
};
76
 
77
void cpu_if::enable_all_interrupts(void) {
78
 
79
    write(cpu_if::CPUREG_INT_MASK, 0xffffffff);
80
};
81
 
82 29 antanguay
void cpu_if::get_rmon_stats(rmonStats_t *rmon_stats) {
83
 
84
    rmon_stats->tx_octets_cnt = read(cpu_if::CPUREG_STATSTXOCTETS);
85
    rmon_stats->tx_pkt_cnt = read(cpu_if::CPUREG_STATSTXPKTS);
86
 
87
    rmon_stats->rx_octets_cnt = read(cpu_if::CPUREG_STATSRXOCTETS);
88
    rmon_stats->rx_pkt_cnt = read(cpu_if::CPUREG_STATSRXPKTS);
89
};
90
 
91 2 antanguay
uint cpu_if::read(uint addr) {
92
 
93
    uint data;
94
 
95
    //--
96
    // Wait for bus to be free, lock it, start transaction
97
 
98
    bus_lock.lock();
99
    bus_addr = addr;
100
    bus_write = false;
101 17 antanguay
    bus_start.post();
102 2 antanguay
 
103
    //--
104
    // Wait for transaction to complete
105
 
106 17 antanguay
    bus_done.wait();
107 2 antanguay
 
108
    //--
109
    // Get the data, free the bus
110
 
111
    data = bus_data;
112
    cout << hex << "READ ADDR 0x" << addr << ": 0x" << data << dec << endl;
113
    bus_lock.unlock();
114
 
115
    return data;
116
};
117
 
118
void cpu_if::write(uint addr, uint data) {
119
 
120
    //--
121
    // Wait for bus to be free, lock it, start transaction
122
 
123
    bus_lock.lock();
124
    bus_addr = addr;
125
    bus_data = data;
126
    bus_write = true;
127 17 antanguay
    bus_start.post();
128 2 antanguay
 
129
    //--
130
    // Wait for transaction to complete
131
 
132 17 antanguay
    bus_done.wait();
133 2 antanguay
 
134
    //--
135
    // Free the bus
136
 
137
    cout << hex << "WRITE ADDR 0x" << addr << ": 0x" << data << dec << endl;
138
    bus_lock.unlock();
139
};
140
 
141
void cpu_if::writebits(uint addr, uint hbit, uint lbit, uint value) {
142
 
143
    uint data;
144
    uint mask;
145
 
146
    mask = ~((0xffffffff << lbit) & (0xffffffff >> (31-lbit)));
147 17 antanguay
 
148 2 antanguay
    data = mask & read(addr);
149
    data = data | ((value << lbit) & ~mask);
150
 
151
    write(addr, data);
152
};
153
 
154
void cpu_if::transactor() {
155
 
156
 
157
    while (true) {
158
 
159
        // Wait for a transaction
160 17 antanguay
        while (bus_start.trywait()) {
161
            wait();
162
        }
163 2 antanguay
 
164
        if (!bus_write) {
165
 
166
            //---
167
            // Read access
168
 
169
            // Start of access
170
            wb_adr_i = bus_addr;
171
            wb_dat_i = 0;
172
 
173
            wb_cyc_i = 1;
174
            wb_stb_i = 1;
175
            wb_we_i = 0;
176
 
177
            // Wait for ack
178
            while (wb_ack_o != 1) {
179
                wait();
180
            }
181
 
182
            // Capture data
183
            bus_data = wb_dat_o;
184
 
185
            wb_adr_i = 0;
186
            wb_dat_i = 0;
187
 
188
            wb_cyc_i = 0;
189
            wb_stb_i = 0;
190
 
191
        }
192
        else {
193
 
194
            //---
195
            // Write access
196
 
197
            // Start of access
198
            wb_adr_i = bus_addr;
199
            wb_dat_i = bus_data;
200
 
201
            wb_cyc_i = 1;
202
            wb_stb_i = 1;
203
            wb_we_i = 1;
204
 
205
            // Wait for ack
206
            while (wb_ack_o != 1) {
207
                wait();
208
            }
209
 
210
            // End cycle
211
            wb_adr_i = 0;
212
            wb_dat_i = 0;
213
 
214
            wb_cyc_i = 0;
215
            wb_stb_i = 0;
216
            wb_we_i = 0;
217
 
218
        }
219
 
220
        bus_done.post();
221
    }
222
};
223
 
224
void cpu_if::monitor() {
225
 
226
    uint data;
227
 
228
    wait();
229
 
230
    while (true) {
231
 
232
        if (wb_int_o) {
233
 
234
            //---
235
            // Read interrupt register when interrupt signal is asserted
236
 
237
            data = read(cpu_if::CPUREG_INT_PENDING);
238 17 antanguay
 
239 2 antanguay
            cout << "READ INTERRUPTS: 0x" << hex << data << dec << endl;
240
 
241
            //---
242
            // Notify scoreboard
243
 
244
            if ((data >> cpu_if::INT_CRC_ERROR) & 0x1) {
245
                sb->notify_status(sb_id, scoreboard::CRC_ERROR);
246
            }
247
 
248
            if ((data >> cpu_if::INT_FRAGMENT_ERROR) & 0x1) {
249
               sb->notify_status(sb_id, scoreboard::FRAGMENT_ERROR);
250
            }
251
 
252 29 antanguay
            if ((data >> cpu_if::INT_LENGHT_ERROR) & 0x1) {
253
               sb->notify_status(sb_id, scoreboard::LENGHT_ERROR);
254
            }
255
 
256 2 antanguay
            if ((data >> cpu_if::INT_LOCAL_FAULT) & 0x1) {
257 17 antanguay
 
258 2 antanguay
                data = read(cpu_if::CPUREG_INT_STATUS);
259
 
260
                if ((data >> cpu_if::INT_LOCAL_FAULT) & 0x1) {
261
                    sb->notify_status(sb_id, scoreboard::LOCAL_FAULT);
262
                }
263
            }
264
 
265
            if ((data >> cpu_if::INT_REMOTE_FAULT) & 0x1) {
266
 
267
                data = read(cpu_if::CPUREG_INT_STATUS);
268
 
269
                if ((data >> cpu_if::INT_REMOTE_FAULT) & 0x1) {
270
                    sb->notify_status(sb_id, scoreboard::REMOTE_FAULT);
271
                }
272
            }
273
 
274
            if ((data >> cpu_if::INT_RXD_FIFO_OVFLOW) & 0x1) {
275
                sb->notify_status(sb_id, scoreboard::RXD_FIFO_OVFLOW);
276
            }
277
 
278
            if ((data >> cpu_if::INT_RXD_FIFO_UDFLOW) & 0x1) {
279
                sb->notify_status(sb_id, scoreboard::RXD_FIFO_UDFLOW);
280
            }
281
 
282
            if ((data >> cpu_if::INT_TXD_FIFO_OVFLOW) & 0x1) {
283
                sb->notify_status(sb_id, scoreboard::TXD_FIFO_OVFLOW);
284
            }
285
 
286
            if ((data >> cpu_if::INT_TXD_FIFO_UDFLOW) & 0x1) {
287
                sb->notify_status(sb_id, scoreboard::TXD_FIFO_UDFLOW);
288
            }
289
 
290
            if ((data >> cpu_if::INT_PAUSE_FRAME) & 0x1) {
291
                sb->notify_status(sb_id, scoreboard::RX_GOOD_PAUSE_FRAME);
292
            }
293
 
294
        }
295
 
296 17 antanguay
        wait();
297 2 antanguay
    }
298
};

powered by: WebSVN 2.1.0

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