Jump to content

AdrianAlter

Members
  • Content Count

    1
  • Joined

  • Last visited

  1. Hey everyone! I'm a total beginner with SystemC as i'm just starting to learn about it; i'm doing a simple program that takes two inputs and either sums or multiplies them depending on the signal i'm asserting. This is the code: #include <systemc.h> SC_MODULE( operation ){ sc_in<bool> clock; sc_in<bool> enable; sc_in<bool> reset; sc_in<bool> mult; sc_in<sc_uint<8>> in1; sc_in<sc_uint<8>> in2; sc_out<sc_uint<8>> out; sc_uint<8> val; void func(){ cout << "in1: " << in1.read() << endl; if(reset.read() == 1){ out = 0; out.write(val); cout << "@" << sc_time_stamp() << " ||RESET asserted. VAL: " << out.read() << endl; }else if(enable.read() == 1){ val = val + in1.read() + in2.read(); out.write(val); cout << "@" << sc_time_stamp() << " || I summed the numbers. VAL: " << out.read() << endl; }else if(mult.read() == 1){ val = val * in2.read(); out.write(val); cout << "@" << sc_time_stamp() << " || I multiplied the numbers. VAL: " << out.read() << endl; }else{ cout << "@" << sc_time_stamp() << " || doing nothing atm" << endl; } } SC_CTOR( operation ){ cout << "@" << sc_time_stamp() << " || executing new " << endl; SC_METHOD(func); sensitive << reset; sensitive << clock.pos(); } }; #include <systemc.h> #include <and.cpp> int sc_main(int argc, char* argv[]){ sc_signal<bool> clock; sc_signal<bool> reset; sc_signal<bool> enable; sc_signal<bool> mult; sc_signal<sc_uint<8>> result; sc_signal<sc_uint<8>> num1; sc_signal<sc_uint<8>> num2; int i = 0; clock = 1; operation operation("TEST"); operation.clock(clock); operation.reset(reset); operation.enable(enable); operation.mult(mult); operation.out(result); operation.in1(num1); operation.in2(num2); enable = 1; reset = 0; mult = 0; num1 = 1; num2 = 2; clock = 0; sc_start(10, SC_MS); clock = 1; sc_start(10, SC_MS); return 0; } And the output: SystemC 2.3.3-Accellera --- Jun 5 2019 18:17:04 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED @0 s || executing new in1: 1 @0 s || I summed the numbers. VAL: 0 in1: 1 @10 ms || I summed the numbers. VAL: 3 The problem is that at first cycle, VAL is 0, and should be 3, and at second cycle it should be 6. What am I doing wrong? Thanks, Adrian
×
×
  • Create New...