Major Tools
Other Tools
General Info

Very basic eval() usage question

Added by Julius Baxter 11 months ago

I want to write some functions in the same C++ file as the main() function is in which will also call top->eval();

However it looks like top->eval() has no effect.


        #include <verilated.h>          // Defines common routines
        #include <iostream>             // Need std::cout
        #include "Vtop.h"               // From Verilating "top.v" 

        vluint64_t main_time = 0;       // Current simulation time
        // This is a 64-bit integer to reduce wrap over issues and
        // allow modulus.  You can also use a double, if you wish.

        double sc_time_stamp () {       // Called by $time in Verilog
            return main_time;           // converts to double, to match
                                        // what SystemC does

        // My example eval() calling function
        void myeval(Vtop *top) {

        int main(int argc, char** argv) {
            Verilated::commandArgs(argc, argv);   // Remember args
            Vtop *top;                      // Instantiation of module
            top = new Vtop;             // Create instance

            top->reset_l = 0;           // Set some inputs

            while (!Verilated::gotFinish()) {
                if (main_time > 10) {
                    top->reset_l = 1;   // Deassert reset
                if ((main_time % 10) == 1) {
                    top->clk = 1;       // Toggle clock
                if ((main_time % 10) == 6) {
                    top->clk = 0;
                myeval(top); // top->eval();            // Evaluate model    <----- replace eval with myeval() call. 
                cout << top->out << endl;       // Read a output
                main_time++;            // Time passes...

            top->final();               // Done simulating
            //    // (Though this example doesn't get here)
            delete top;

This behaves as if top->eval() is never called.

My actual app calls eval() in both main() and my own functions, and I also notice the evals which are not in main() do not called.

Why is that?

Thanks, Julius

Replies (2)

RE: Very basic eval() usage question - Added by Wilson Snyder 11 months ago

No idea, obviously makes no sense at first glance; try stepping through in the debugger. Let us know what it turns out to be.

RE: Very basic eval() usage question - Added by Julius Baxter 10 months ago

The code snippet I pasted above actually works fine. There was something in my actual app which didn't work, for some reason, it's slightly beyond me to debug why at the moment. So please close ignore this question. If I figure out what I was doing wrong, then I'll post an update.