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 7

Go to most recent revision | 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
uint cpu_if::read(uint addr) {
83
 
84
    uint data;
85
 
86
    //--
87
    // Wait for bus to be free, lock it, start transaction
88
 
89
    bus_lock.lock();
90
    bus_addr = addr;
91
    bus_write = false;
92
    bus_start.notify();
93
 
94
    //--
95
    // Wait for transaction to complete
96
 
97
    while (bus_done.trywait()) {
98
        wait(10, SC_NS);
99
    };
100
 
101
    //--
102
    // Get the data, free the bus
103
 
104
    data = bus_data;
105
    cout << hex << "READ ADDR 0x" << addr << ": 0x" << data << dec << endl;
106
    bus_lock.unlock();
107
 
108
    return data;
109
};
110
 
111
void cpu_if::write(uint addr, uint data) {
112
 
113
    //--
114
    // Wait for bus to be free, lock it, start transaction
115
 
116
    bus_lock.lock();
117
    bus_addr = addr;
118
    bus_data = data;
119
    bus_write = true;
120
    bus_start.notify();
121
 
122
    //--
123
    // Wait for transaction to complete
124
 
125
    while (bus_done.trywait()) {
126
        wait(10, SC_NS);
127
    };
128
 
129
    //--
130
    // Free the bus
131
 
132
    cout << hex << "WRITE ADDR 0x" << addr << ": 0x" << data << dec << endl;
133
    bus_lock.unlock();
134
};
135
 
136
void cpu_if::writebits(uint addr, uint hbit, uint lbit, uint value) {
137
 
138
    uint data;
139
    uint mask;
140
 
141
    mask = ~((0xffffffff << lbit) & (0xffffffff >> (31-lbit)));
142
 
143
    data = mask & read(addr);
144
    data = data | ((value << lbit) & ~mask);
145
 
146
    write(addr, data);
147
};
148
 
149
void cpu_if::transactor() {
150
 
151
 
152
    while (true) {
153
 
154
        // Wait for a transaction
155
        wait(bus_start);
156
 
157
        if (!bus_write) {
158
 
159
            //---
160
            // Read access
161
 
162
            // Start of access
163
            wb_adr_i = bus_addr;
164
            wb_dat_i = 0;
165
 
166
            wb_cyc_i = 1;
167
            wb_stb_i = 1;
168
            wb_we_i = 0;
169
 
170
            // Wait for ack
171
            while (wb_ack_o != 1) {
172
                wait();
173
            }
174
 
175
            // Capture data
176
            bus_data = wb_dat_o;
177
 
178
            wb_adr_i = 0;
179
            wb_dat_i = 0;
180
 
181
            wb_cyc_i = 0;
182
            wb_stb_i = 0;
183
 
184
        }
185
        else {
186
 
187
            //---
188
            // Write access
189
 
190
            // Start of access
191
            wb_adr_i = bus_addr;
192
            wb_dat_i = bus_data;
193
 
194
            wb_cyc_i = 1;
195
            wb_stb_i = 1;
196
            wb_we_i = 1;
197
 
198
            // Wait for ack
199
            while (wb_ack_o != 1) {
200
                wait();
201
            }
202
 
203
            // End cycle
204
            wb_adr_i = 0;
205
            wb_dat_i = 0;
206
 
207
            wb_cyc_i = 0;
208
            wb_stb_i = 0;
209
            wb_we_i = 0;
210
 
211
        }
212
 
213
        bus_done.post();
214
    }
215
};
216
 
217
void cpu_if::monitor() {
218
 
219
    uint data;
220
 
221
    wait();
222
 
223
    while (true) {
224
 
225
        if (wb_int_o) {
226
 
227
            //---
228
            // Read interrupt register when interrupt signal is asserted
229
 
230
            data = read(cpu_if::CPUREG_INT_PENDING);
231
 
232
            cout << "READ INTERRUPTS: 0x" << hex << data << dec << endl;
233
 
234
            //---
235
            // Notify scoreboard
236
 
237
            if ((data >> cpu_if::INT_CRC_ERROR) & 0x1) {
238
                sb->notify_status(sb_id, scoreboard::CRC_ERROR);
239
            }
240
 
241
            if ((data >> cpu_if::INT_FRAGMENT_ERROR) & 0x1) {
242
               sb->notify_status(sb_id, scoreboard::FRAGMENT_ERROR);
243
            }
244
 
245
            if ((data >> cpu_if::INT_LOCAL_FAULT) & 0x1) {
246
 
247
                data = read(cpu_if::CPUREG_INT_STATUS);
248
 
249
                if ((data >> cpu_if::INT_LOCAL_FAULT) & 0x1) {
250
                    sb->notify_status(sb_id, scoreboard::LOCAL_FAULT);
251
                }
252
            }
253
 
254
            if ((data >> cpu_if::INT_REMOTE_FAULT) & 0x1) {
255
 
256
                data = read(cpu_if::CPUREG_INT_STATUS);
257
 
258
                if ((data >> cpu_if::INT_REMOTE_FAULT) & 0x1) {
259
                    sb->notify_status(sb_id, scoreboard::REMOTE_FAULT);
260
                }
261
            }
262
 
263
            if ((data >> cpu_if::INT_RXD_FIFO_OVFLOW) & 0x1) {
264
                sb->notify_status(sb_id, scoreboard::RXD_FIFO_OVFLOW);
265
            }
266
 
267
            if ((data >> cpu_if::INT_RXD_FIFO_UDFLOW) & 0x1) {
268
                sb->notify_status(sb_id, scoreboard::RXD_FIFO_UDFLOW);
269
            }
270
 
271
            if ((data >> cpu_if::INT_TXD_FIFO_OVFLOW) & 0x1) {
272
                sb->notify_status(sb_id, scoreboard::TXD_FIFO_OVFLOW);
273
            }
274
 
275
            if ((data >> cpu_if::INT_TXD_FIFO_UDFLOW) & 0x1) {
276
                sb->notify_status(sb_id, scoreboard::TXD_FIFO_UDFLOW);
277
            }
278
 
279
            if ((data >> cpu_if::INT_PAUSE_FRAME) & 0x1) {
280
                sb->notify_status(sb_id, scoreboard::RX_GOOD_PAUSE_FRAME);
281
            }
282
 
283
        }
284
 
285
        wait();
286
    }
287
};

powered by: WebSVN 2.1.0

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