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 17

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

powered by: WebSVN 2.1.0

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