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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [bench/] [cpp/] [helloworld.cpp] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    helloworld.cpp
4
//
5
// Project:     wbuart32, a full featured UART with simulator
6
//
7
// Purpose:     To demonstrate a useful Verilog file which could be used as a
8
//              toplevel program later, to demo the transmit UART.
9
//
10
// Creator:     Dan Gisselquist, Ph.D.
11
//              Gisselquist Technology, LLC
12
//
13
////////////////////////////////////////////////////////////////////////////////
14
//
15 26 dgisselq
// Copyright (C) 2015-2019, Gisselquist Technology, LLC
16 5 dgisselq
//
17
// This program is free software (firmware): you can redistribute it and/or
18
// modify it under the terms of  the GNU General Public License as published
19
// by the Free Software Foundation, either version 3 of the License, or (at
20
// your option) any later version.
21
//
22
// This program is distributed in the hope that it will be useful, but WITHOUT
23
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
24
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25
// for more details.
26
//
27
// You should have received a copy of the GNU General Public License along
28
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
29
// target there if the PDF file isn't present.)  If not, see
30
// <http://www.gnu.org/licenses/> for a copy.
31
//
32
// License:     GPL, v3, as defined and found on www.gnu.org,
33
//              http://www.gnu.org/licenses/gpl.html
34
//
35
//
36
////////////////////////////////////////////////////////////////////////////////
37
//
38
//
39 18 dgisselq
#include <verilatedos.h>
40 5 dgisselq
#include <stdio.h>
41
#include <fcntl.h>
42
#include <unistd.h>
43
#include <string.h>
44
#include <time.h>
45
#include <sys/types.h>
46
#include <signal.h>
47
#include "verilated.h"
48 6 dgisselq
#include "verilated_vcd_c.h"
49 5 dgisselq
#include "Vhelloworld.h"
50
#include "uartsim.h"
51
 
52
int     main(int argc, char **argv) {
53
        Verilated::commandArgs(argc, argv);
54
        Vhelloworld     tb;
55
        UARTSIM         *uart;
56
        int             port = 0;
57 6 dgisselq
        unsigned        setup = 868, clocks = 0, baudclocks;
58 5 dgisselq
 
59
        tb.i_setup = setup;
60
        uart = new UARTSIM(port);
61
        uart->setup(tb.i_setup);
62 6 dgisselq
        baudclocks = tb.i_setup & 0xfffffff;
63 5 dgisselq
 
64 6 dgisselq
#define VCDTRACE
65
#ifdef  VCDTRACE
66
        Verilated::traceEverOn(true);
67
        VerilatedVcdC* tfp = new VerilatedVcdC;
68
        tb.trace(tfp, 99);
69
        tfp->open("helloworld.vcd");
70
#define TRACE_POSEDGE   tfp->dump(10*clocks)
71
#define TRACE_NEGEDGE   tfp->dump(10*clocks+5)
72
#define TRACE_CLOSE     tfp->close()
73
#else
74
#define TRACE_POSEDGE
75
#define TRACE_NEGEDGE
76
#define TRACE_CLOSE
77
#endif
78 5 dgisselq
 
79 6 dgisselq
        clocks = 0;
80
        while(clocks < 16*32*baudclocks) {
81
 
82 5 dgisselq
                tb.i_clk = 1;
83
                tb.eval();
84 6 dgisselq
                TRACE_POSEDGE;
85 5 dgisselq
                tb.i_clk = 0;
86
                tb.eval();
87 6 dgisselq
                TRACE_NEGEDGE;
88 5 dgisselq
 
89
                (*uart)(tb.o_uart_tx);
90 6 dgisselq
                clocks++;
91 5 dgisselq
        }
92
 
93 6 dgisselq
        TRACE_CLOSE;
94 5 dgisselq
        printf("\n\nSimulation complete\n");
95
}

powered by: WebSVN 2.1.0

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