错误:未在此范围内声明'sc_unit'(SystemC-2.3.0)

时间:2014-06-11 00:58:19

标签: c++ compilation systemc

// first_counter.cpp
SC_MODULE (first_counter) {
    sc_in_clk       clock;        // clock input of the design
    sc_in<bool>     reset;          // active high, synchronous reset input
    sc_in<bool>     enable;         // active high enable signal for counter
    sc_out<sc_unit<4>>      counter_out;    //4-bit vector output of the counter

    // local variables here 
    sc_unit<4> count;

    // code starts here
    // This is for synchronous reset
    void incr_count () {
            if (reset.read() == 1) {                // at every rising edge of clock, check reset is active, 
                    count = 0;                      // if zero, initialize count register
                    counter_out.write(count);
            } else if (enable.read() == 1) {        // if enable is active, increment the counter;
                    count = count + 1;
                    counter_out.write(count);
                    cout<<"@"<<sc_time_stamp() <<"::Incremented Counter" << counter_out.read()<<endl;
            }
    } // end of function incr_count;

    // constructor for the counter (postive edge triggered one) 
    // trigger the below block with respect to positive edge of the clock and also whenever reset changes states. 
    SC_CTOR(first_counter) {
            cout<<"Executing new"<<endl;
            SC_METHOD(incr_count);
                    sensitive << reset;
                    sensitive << clock.pos();
    }
}; // End of Module counter


//// first_counter_tb.cpp
#include "systemc.h"
#include "first_counter.cpp"

int sc_main (int argc, char* argv[]) {
    sc_signal<bool> clock;
    sc_signal<bool> reset;
    sc_signal<bool> enable;
    sc_signal<sc_unit<4>>   counter_out;
    int i=0;

    //connect the DUT
    first_counter counter("COUNTER");
            counter.clock(clock);
            counter.reset(reset);
            counter.enable(enable);
            counter.counter_out(counter_out);

    sc_start(1, SC_NS);

    // open VCD file
    sc_trace_file *wf=sc_create_vcd_trace_file("counter");
    sc_trace(wf, clock, "clock");
    sc_trace(wf, reset, "reset");
    sc_trace(wf, enable, "enable");
    sc_trace(wf, counter_out, "count");

    //initialize all variables
    reset = 0;
    enable = 0;
    for (i=0; i<5; i++) {
            clock = 0;
            sc_start(1, SC_NS);
            clock=1;
            sc_start(1, SC_NS);
    }
    reset = 1;      // assert the reset
    cout << "@" << sc_time_stamp() << "Asserting reset\n" << endl;
    for (i=0; i<10; i++) {
            clock = 0;
            sc_start(1, SC_NS);
            clock=1;
            sc_start(1, SC_NS);
    }
    reset = 0;      // De-assert the reset
    cout << "@" << sc_time_stamp() << "De-Asserting reset\n" << endl;
    for (i=0; i<5; i++) {
            clock = 0;
            sc_start(1, SC_NS);
            clock = 1;
            sc_start(1, SC_NS);
    }
    count << "@" << sc_time_stamp() << "Asserting Enable\n" << endl;
    enable =1;
    for (i=0; i<20; i++){
            clock =0;
            sc_start(1, SC_NS);
            clock =1;
            sc_start(1, SC_NS);
    }
    cout << "@" << sc_time_stamp() << "De-asserting Enable\n" << endl;
    enable = 0;     // De-assert enable

    cout << "@" << sc_time_stamp() << "Terminating simulation\n" << endl;
    sc_close_vcd_trace_file(wf);
    return 0;       //terminate simulation
}

当我编译这个时,我得到了以下错误..但我不知道如何解决这个问题.. root @ ubuntu:/mnt/lnx-arch/systemc-2.3.0/workspace/picoE/first_counter#make     g ++ -I。 -I / mnt / lnx-arch / systemc-2.3.0 / include -L。 -L / mnt / lnx-arch / systemc-2.3.0 / lib-linux64&gt; -Wl,-rpath = / mnt / lnx-arch / systemc-2.3.0 / lib-linux64 -o first_counter_tb first_counter_tb.cpp&gt; -lsystemc-2.3.0 -lm

In file included from first_counter_tb.cpp:3:0:
first_counter.cpp:12:9: error: ‘sc_unit’ was not declared in this scope
first_counter.cpp:12:21: error: ‘counter_out’ was not declared in this scope
first_counter.cpp:12:21: error: template argument 1 is invalid
first_counter.cpp:15:2: error: ‘sc_unit’ does not name a type
first_counter.cpp: In member function ‘void first_counter::incr_count()’:
first_counter.cpp:21:4: error: ‘count’ was not declared in this scope
first_counter.cpp:22:4: error: ‘counter_out’ was not declared in this scope
first_counter.cpp:24:4: error: ‘count’ was not declared in this scope
first_counter.cpp:25:4: error: ‘counter_out’ was not declared in this scope
first_counter_tb.cpp: In function ‘int sc_main(int, char**)’:
first_counter_tb.cpp:9:12: error: ‘sc_unit’ was not declared in this scope
first_counter_tb.cpp:9:24: error: ‘counter_out’ was not declared in this scope
first_counter_tb.cpp:9:24: error: template argument 1 is invalid
first_counter_tb.cpp:17:11: error: ‘struct first_counter’ has no member named ‘counter_out’
first_counter_tb.cpp:53:2: error: ‘count’ was not declared in this scope
make: *** [first_counter_tb] Error 1

1 个答案:

答案 0 :(得分:1)

这是错字。它应该是sc_uint而不是sc_unit