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

Subversion Repositories aor3000

[/] [aor3000/] [trunk/] [sim/] [div-test/] [main.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * This file is subject to the terms and conditions of the BSD License. See
3
 * the file "LICENSE" in the main directory of this archive for more details.
4
 *
5
 * Copyright (C) 2014 Aleksander Osman
6
 */
7
 
8
#include <cstdio>
9
#include <cstdlib>
10
 
11
#include <sys/mman.h>
12
#include <sys/types.h>
13
#include <sys/stat.h>
14
#include <fcntl.h>
15
#include <unistd.h>
16
 
17
#include "Vmain.h"
18
#include "verilated.h"
19
#include "verilated_vcd_c.h"
20
 
21
//------------------------------------------------------------------------------
22
 
23
typedef unsigned int        uint32;
24
typedef unsigned char       uint8;
25
typedef unsigned long long  uint64;
26
 
27
//------------------------------------------------------------------------------
28
 
29
 
30
int main(int argc, char **argv) {
31
 
32
    //--------------------------------------------------------------------------
33
 
34
    Verilated::commandArgs(argc, argv);
35
 
36
    Verilated::traceEverOn(true);
37
    VerilatedVcdC* tracer = new VerilatedVcdC;
38
 
39
    Vmain *top = new Vmain();
40
    top->trace (tracer, 99);
41
    //tracer->rolloverMB(1000000);
42
    tracer->open("main.vcd");
43
 
44
    //reset
45
    top->clk = 0; top->rst_n = 1; top->eval();
46
    top->clk = 1; top->rst_n = 1; top->eval();
47
    top->clk = 1; top->rst_n = 0; top->eval();
48
    top->clk = 0; top->rst_n = 0; top->eval();
49
    top->clk = 0; top->rst_n = 1; top->eval();
50
 
51
    //--------------------------------------------------------------------------
52
 
53
    bool dump_enabled = true;
54
 
55
    int cycle = 0;
56
 
57
    int pnom[]  = { 0,1,2,3, 0,1,2,3, 0,1,2,3, 0,1,2,3, 0,1,-2,-1, 0,1,-2,-1,  0, 1,-2,-1,  0, 1,-2,-1 };
58
    int pden[]  = { 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3, 0,0, 0, 0, 1,1, 1, 1, -2,-2,-2,-2, -1,-1,-1,-1 };
59
 
60
    int nom[]   = { 0,1,2,3, 0,1,2,3, 0,1,2,3, 0,1,2,3,  0,1,4|2,4|3, 0,1,4|2,4|3, 0,  1,  4|2,4|3, 0,  1,  4|2,4|3 };
61
    int denom[] = { 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3,  0,0,0,  0,   1,1,1,  1,   4|2,4|2,4|2,4|2, 4|2,4|2,4|2,4|2 };
62
 
63
    int index = 0;
64
    bool running = false;
65
 
66
    while(!Verilated::gotFinish()) {
67
 
68
        top->start = 0;
69
        top->dividend = 0;
70
        top->divisor = 0;
71
 
72
        if(running == false) {
73
            top->start = 1;
74
            top->dividend = nom[index];
75
            top->divisor  = denom[index];
76
            running = true;
77
        }
78
 
79
        if(top->ready) {
80
            printf("%02d / %02d = q: %02d r: %02d\n", pnom[index], pden[index], top->quotient, top->remainder);
81
            running = false;
82
            index++;
83
 
84
            if(index == 32) {
85
                printf("END\n");
86
                break;
87
            }
88
        }
89
 
90
        top->clk = 0;
91
        top->eval();
92
 
93
        cycle++;
94
        if(dump_enabled) tracer->dump(cycle);
95
 
96
        top->clk = 1;
97
        top->eval();
98
 
99
        cycle++;
100
        if(dump_enabled) tracer->dump(cycle);
101
 
102
        tracer->flush();
103
        //usleep(1);
104
    }
105
    delete top;
106
    return 0;
107
}
108
 
109
/*
110
    input               clk,
111
    input               rst_n,
112
 
113
    input               start,
114
    input       [2:0]  dividend,
115
    input       [2:0]  divisor,
116
 
117
    output              ready,
118
    output      [1:0]  quotient,
119
    output      [1:0]  remainder
120
*/

powered by: WebSVN 2.1.0

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