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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [sim/] [verilator/] [soc/] [pit/] [main_plugin.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
#include <cstdio>
2
#include <cstdlib>
3
 
4
#include <dlfcn.h>
5
 
6
#include <sys/mman.h>
7
#include <sys/types.h>
8
#include <sys/stat.h>
9
#include <fcntl.h>
10
#include <unistd.h>
11
 
12
#include "Vpit.h"
13
#include "verilated.h"
14
#include "verilated_vcd_c.h"
15
 
16
#include "shared_mem.h"
17
 
18
//------------------------------------------------------------------------------
19
//------------------------------------------------------------------------------
20
//------------------------------------------------------------------------------
21
 
22
volatile shared_mem_t *shared_ptr = NULL;
23
 
24
//------------------------------------------------------------------------------
25
//------------------------------------------------------------------------------
26
//------------------------------------------------------------------------------
27
 
28
//------------------------------------------------------------------------------
29
 
30
int main(int argc, char **argv) {
31
 
32
    //map shared memory
33
    int fd = open("./../../../sim_pc/shared_mem.dat", O_RDWR, S_IRUSR | S_IWUSR);
34
 
35
    if(fd == -1) {
36
        perror("open() failed for shared_mem.dat");
37
        return -1;
38
    }
39
 
40
    shared_ptr = (shared_mem_t *)mmap(NULL, sizeof(shared_mem_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
41
 
42
    if(shared_ptr == MAP_FAILED) {
43
        perror("mmap() failed");
44
        close(fd);
45
        return -2;
46
    }
47
 
48
    Verilated::commandArgs(argc, argv);
49
 
50
    Verilated::traceEverOn(true);
51
    VerilatedVcdC* tracer = new VerilatedVcdC;
52
 
53
    Vpit *top = new Vpit();
54
    top->trace (tracer, 99);
55
    //tracer->rolloverMB(1000000);
56
    tracer->open("pit.vcd");
57
 
58
    //reset
59
    top->clk = 0; top->rst_n = 1; top->eval();
60
    top->clk = 1; top->rst_n = 1; top->eval();
61
    top->clk = 1; top->rst_n = 0; top->eval();
62
    top->clk = 0; top->rst_n = 0; top->eval();
63
    top->clk = 0; top->rst_n = 1; top->eval();
64
 
65
    bool dump = false;
66
    uint64 cycle = 0;
67
    bool read_cycle = false;
68
 
69
    int CYCLES_IN_SYSCLOCK = 2;
70
 
71
    /*
72
    0.[7:0]: cycles in sysclock 1193181 Hz
73
    */
74
    top->mgmt_address = 0;
75
    top->mgmt_write   = 1;
76
    top->mgmt_writedata = CYCLES_IN_SYSCLOCK;
77
 
78
    top->clk = 0;
79
    top->eval();
80
    cycle++; if(dump) tracer->dump(cycle);
81
 
82
    top->clk = 1;
83
    top->eval();
84
    cycle++; if(dump) tracer->dump(cycle);
85
 
86
    tracer->flush();
87
    top->mgmt_write = 0;
88
 
89
    printf("pit main_plugin.cpp\n");
90
 
91
    int sleep_counter = 0;
92
 
93
    while(!Verilated::gotFinish()) {
94
 
95
        /*
96
        uint32 combined.io_address;
97
        uint32 combined.io_data;
98
        uint32 combined.io_byteenable;
99
        uint32 combined.io_is_write;
100
        step_t combined.io_step;
101
 
102
        //io slave 040h-043h
103
        input       [1:0]   io_address,
104
        input               io_read,
105
        output reg  [7:0]   io_readdata,
106
        input               io_write,
107
        input       [7:0]   io_writedata,
108
 
109
        //speaker port 61h
110
        input               speaker_61h_read,
111
        output      [7:0]   speaker_61h_readdata,
112
        input               speaker_61h_write,
113
        input       [7:0]   speaker_61h_writedata,
114
        */
115
 
116
        top->io_read      = 0;
117
        top->io_write     = 0;
118
 
119
        top->speaker_61h_read = 0;
120
        top->speaker_61h_write= 0;
121
 
122
        if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write && shared_ptr->combined.io_address == 0x0040) {
123
            if(shared_ptr->combined.io_byteenable != 1 && shared_ptr->combined.io_byteenable != 2 && shared_ptr->combined.io_byteenable != 4 && shared_ptr->combined.io_byteenable != 8) {
124
                printf("Vpit: combined.io_byteenable invalid: %x\n", shared_ptr->combined.io_byteenable);
125
                exit(-1);
126
            }
127
 
128
            top->io_address    = (shared_ptr->combined.io_byteenable == 1)?     0 :
129
                                 (shared_ptr->combined.io_byteenable == 2)?     1 :
130
                                 (shared_ptr->combined.io_byteenable == 4)?     2 :
131
                                                                                3;
132
            top->io_writedata  = (shared_ptr->combined.io_byteenable == 1)?     shared_ptr->combined.io_data & 0xFF :
133
                                 (shared_ptr->combined.io_byteenable == 2)?     (shared_ptr->combined.io_data >> 8) & 0xFF :
134
                                 (shared_ptr->combined.io_byteenable == 4)?     (shared_ptr->combined.io_data >> 16) & 0xFF :
135
                                                                                (shared_ptr->combined.io_data >> 24) & 0xFF;
136
            top->io_read  = 0;
137
            top->io_write = 1;
138
 
139
            shared_ptr->combined.io_step = STEP_ACK;
140
        }
141
 
142
        if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write && shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 0x2) {
143
            top->speaker_61h_writedata = (shared_ptr->combined.io_data >> 8) & 0xFF;
144
 
145
            top->speaker_61h_read = 0;
146
            top->speaker_61h_write= 1;
147
 
148
            shared_ptr->combined.io_step = STEP_ACK;
149
        }
150
 
151
        if(read_cycle == false) {
152
            if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 && shared_ptr->combined.io_address == 0x0040) {
153
                if(shared_ptr->combined.io_byteenable != 1 && shared_ptr->combined.io_byteenable != 2 && shared_ptr->combined.io_byteenable != 4 && shared_ptr->combined.io_byteenable != 8) {
154
                    printf("Vpit: combined.io_byteenable invalid: %x\n", shared_ptr->combined.io_byteenable);
155
                    exit(-1);
156
                }
157
 
158
                top->io_address = (shared_ptr->combined.io_byteenable == 1)?     0 :
159
                                  (shared_ptr->combined.io_byteenable == 2)?     1 :
160
                                  (shared_ptr->combined.io_byteenable == 4)?     2 :
161
                                                                                 3;
162
                top->io_writedata  = 0;
163
 
164
                top->io_read  = 1;
165
                top->io_write = 0;
166
 
167
                read_cycle = true;
168
            }
169
 
170
            if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 && shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 0x2) {
171
                top->speaker_61h_writedata = 0;
172
 
173
                top->speaker_61h_read = 1;
174
                top->speaker_61h_write= 0;
175
 
176
                read_cycle = true;
177
            }
178
        }
179
        else {
180
            if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 && shared_ptr->combined.io_address == 0x0040) {
181
                uint32 val = top->io_readdata;
182
 
183
                if(shared_ptr->combined.io_byteenable & 1) val <<= 0;
184
                if(shared_ptr->combined.io_byteenable & 2) val <<= 8;
185
                if(shared_ptr->combined.io_byteenable & 4) val <<= 16;
186
                if(shared_ptr->combined.io_byteenable & 8) val <<= 24;
187
 
188
                shared_ptr->combined.io_data = val;
189
 
190
                read_cycle = false;
191
                shared_ptr->combined.io_step = STEP_ACK;
192
            }
193
 
194
            if(shared_ptr->combined.io_step == STEP_REQ && shared_ptr->combined.io_is_write == 0 && shared_ptr->combined.io_address == 0x0060 && shared_ptr->combined.io_byteenable == 0x2) {
195
                uint32 val = top->speaker_61h_readdata << 8;
196
 
197
                shared_ptr->combined.io_data = val;
198
 
199
                read_cycle = false;
200
                shared_ptr->combined.io_step = STEP_ACK;
201
            }
202
        }
203
 
204
        //----------------------------------------------------------------------
205
 
206
        if(top->irq) {
207
            shared_ptr->pit_irq_step = STEP_REQ;
208
        }
209
        else {
210
            shared_ptr->pit_irq_step = STEP_IDLE;
211
        }
212
 
213
        //----------------------------------------------------------------------
214
 
215
//if((cycle % 5000) == 0) printf("-- %d\n", cycle);
216
 
217
 
218
        //----------------------------------------------------------------------
219
 
220
        top->clk = 0;
221
        top->eval();
222
        cycle++; if(dump) tracer->dump(cycle);
223
 
224
        top->clk = 1;
225
        top->eval();
226
        cycle++; if(dump) tracer->dump(cycle);
227
 
228
        tracer->flush();
229
 
230
        sleep_counter++;
231
        if((sleep_counter % 20) == 0) usleep(1);
232
    }
233
    tracer->close();
234
    delete tracer;
235
    delete top;
236
 
237
    return 0;
238
}
239
 
240
 
241
 
242
//------------------------------------------------------------------------------
243
 
244
/*
245
    input               clk,
246
    input               rst_n,
247
 
248
    output              irq,
249
 
250
    //io slave 040h-043h
251
    input       [1:0]   io_address,
252
    input               io_read,
253
    output reg  [7:0]   io_readdata,
254
    input               io_write,
255
    input       [7:0]   io_writedata,
256
 
257
    //speaker port 61h
258
    input               speaker_61h_read,
259
    output      [7:0]   speaker_61h_readdata,
260
    input               speaker_61h_write,
261
    input       [7:0]   speaker_61h_writedata,
262
 
263
    //speaker output
264
    output reg          speaker_enable,
265
    output              speaker_out,
266
 
267
    //mgmt slave
268
    //0.[7:0]: cycles in sysclock 1193181 Hz
269
 
270
    input               mgmt_address,
271
    input               mgmt_write,
272
    input       [31:0]  mgmt_writedata
273
*/

powered by: WebSVN 2.1.0

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