Quantcast
Channel: SystemC Language Forum RSS Feed
Viewing all 595 articles
Browse latest View live

Dynamic module instance creation

$
0
0

Hello everyone, 

 

I have a folder with many modules. I want to create a configuration file specifying which of those modules to use in my simulation. In the sc_main.cpp, before the simulation starts I would like to open my configuration file, read which modules I would like to open and then create instances, connect their ports etc

 

The configuration file contains all the necessary information as number of ports, type of each port , name of the module, name of the file etc. 

I can easily create the signals I need but I don't know how I can create the module instance. 

 

example of configuration file 

....

ex_name_module 

porta ; input ; double

portb ; output ; double 

......

In the sc_main I will read the file. I will create 2 signals of type double. But then i should do something like 

ex_name_module EX_NAME_MODULE("EX_NAME_MODULE");

EX_NAME_MODULE.input(sig1);

EX_NAME_MODULE.output(sig2);

 

One idea that I tried but it didn't work, was to create a .cpp file for each module. This file has a function containing the instance creation of the respective module. The arguments of the function were the signals created in sc_main.

 

So any ideas of how I can create such an instance? Thank you in advance


What is the difference in default_event() and value_changed_event()

$
0
0

Hi Folks

 

What is the difference in default_event() and value_changed_event() for sc_signal channel.

I have an sc_in port in my module and a process run is sensitive on it

 

SC_THREAD(run)

sensitive<<irq;

 

When the run will be activated

- when there any any event on irq (read or write)

- when there is some value change event

 

When I use

 

SC_THREAD(run)

sensitive<<irq.value_changed_event();

or

 

SC_THREAD(run)

sensitive<<irq.default_event();

 

I get the following error

Error: (E112) get interface failed: port is not bound: port 'initiator.irq' (sc_in)
In file: ../../../../systemc-2.3.0/src/sysc/communication/sc_port.cpp:230
 

 

 

Regards

RahulJn

Error: (E115) sc_signal<T> cannot have more than one driver:

$
0
0

Hi every one,

 

I got this error in my simulator:

 

Error: (E115) sc_signal<T> cannot have more than one driver:
 signal `NoC.signal_213936' (sc_signal)
 first driver `NoC.Tile[00][00].Router.rxProcess' (sc_method_process)
 second driver `NoC.Tile[00][00].Router.txProcess' (sc_method_process)
In file: ../../../../src/sysc/communication/sc_signal.cpp:137
In process: NoC.Tile[00][00].Router.txProcess @ 0 s
 

 

I know the reason of the error that the same signal is connected to two outports at the same module but in diffrent process. the problem is: as you can see from the signal number I have many signal and I need your help to track this signal and fix the problem please?

 

thanks

 

Ammar

Building on Windows using gcc - compiler vs. environment #ifdefs

$
0
0

I've been using SystemC for years on Linux with gcc and Windows with Visual Studio.  I decided to try it out in Eclipse on windows with the Cygwin environment.

 

Several problems have popped up.  For example there are #ifdefs around defining data types supported by the compiler, such as __int64 in the Microsoft compiler versus long long elsewhere.  However these are defined based on the _WIN32 predefined macro.

 

That's not really correct, it should be defined based on the compiler type - in this case using _MSC_VER instead of _WIN32.

 

Example from sc_nbdefs.cpp

 

 

// Support for the long long type. This type is not in the standard
// but is usually supported by compilers.
#if !defined(_WIN32) || defined(__MINGW32__)
const uint64 UINT64_ZERO   = 0ULL;
const uint64 UINT64_ONE    = 1ULL;
const uint64 UINT64_32ONES = 0x00000000ffffffffULL;
#else
const uint64 UINT64_ZERO   = 0i64;
const uint64 UINT64_ONE    = 1i64;
const uint64 UINT64_32ONES = 0x00000000ffffffffi64;
#endif

What is a basic SystemC definition?

$
0
0

Hi,

Once I was asked about the question: What is the basic SystemC definition? It was said that it is the first thing too add to a general C language.

I remembered that I found it (It is prefixed by sc_) on SystemC User Manual. Now I forget the answer and cannot find it on the manual. Could you tell me that?

 

 

Thanks,

When the method to_default_time_units() returns 0?

$
0
0

Hi,

I see the below code snippet from an example. I wonder that when sc_time_stamp().to_default_time_units() returns 0.

 

 

 

     static bool first = true;

    if (first || sc_time_stamp().to_default_time_units() == 0)
    {
        first = false;
        clock.write(0);
    }

 

 

I have found its origin definition:

 

00161 // conversion functions
00162
00163 double
00164 sc_time::to_default_time_units() const
00165 {
00166 sc_time_params* time_params = sc_get_curr_simcontext()->m_time_params;
00167 return ( sc_dt::uint64_to_double( m_value ) /
00168 sc_dt::uint64_to_double( time_params->default_time_unit ) );
00169 }
00170

 

I think that if  sc_time_stamp().to_default_time_units() returns non-zero, it is equivalent to 1. It returns 0 when m_value is 0. My question is what does m_value is 0 mean?

 

 

 

Thanks,

Undefined process control interaction: attempt to disable a thread with timeout wait:

$
0
0

Hi Experts

 

With the below programe, I have following error

 

Error: (E559) Undefined process control interaction: attempt to disable a thread with timeout wait: t.func2
In file: ../../../../systemc-2.3.0/src/sysc/kernel/sc_process.cpp:345
In process: t.func1 @ 5 ns
I am not able to figure out why ?

Can you please help

 

#include "systemc.h"

class test : public sc_module {
    public :
    SC_HAS_PROCESS(test);
    test(sc_module_name name){
        SC_THREAD(func1);
         func1_p = sc_get_current_process_handle();
        SC_THREAD(func2);
         func2_p = sc_get_current_process_handle();
    }
    sc_process_handle func1_p,func2_p;

    void func1(){
        for(;;){
            wait(5,SC_NS);
            func2_p.disable();
            wait(5,SC_NS);
            func2_p.enable();
        }
    }

    void func2(){
        for(;;){
            wait(10,SC_NS);
            cout<<sc_time_stamp().value()<<endl;
        }
    }
};

int sc_main(int, char*[]){
    test t("t");
    sc_start(SC_ZERO_TIME);
    sc_start();
    /*cout<<sc_time_stamp().value()<<endl;
    if(sc_get_status() == SC_PAUSED){sc_start(10,SC_NS);}
    cout<<sc_time_stamp().value()<<endl;*/
    return 0;
}

Where is declared SC_OFF?

$
0
0

Hi,

 

After I define fixed point, the last line 

 

  d(SC_OFF);

 

of

 
#define SC_INCLUDE_FX 
#include <systemc.h>
#include "fir_data.h"
 
void fir_data::entry()
{
  int state;
  sc_int<8> sample_tmp;
  sc_ufixed<16,16> d;        
  d(SC_OFF);
 
 

is complained by compiler:

 

# fir_data.cpp:44: error: no match for call to '(sc_dt::sc_ufixed<16, 16, SC_TRN, SC_WRAP, 0>) (sc_dt::sc_switch)'
# C:\modeltech_10.1c\include\systemc/sc_fxnum.h:3372: note: candidates are: const sc_dt::sc_fxnum_subref sc_dt::sc_fxnum::operator()(int, int) const
# C:\modeltech_10.1c\include\systemc/sc_fxnum.h:3383: note:                 sc_dt::sc_fxnum_subref sc_dt::sc_fxnum::operator()(int, int)
# C:\modeltech_10.1c\include\systemc/sc_fxnum.h:3415: note:                 const sc_dt::sc_fxnum_subref sc_dt::sc_fxnum::operator()() const
# C:\modeltech_10.1c\include\systemc/sc_fxnum.h:3422: note:                 sc_dt::sc_fxnum_subref sc_dt::sc_fxnum::operator()()
# ** Error: (sccom-6142) Compilation failed.
# ** Error: C:/modeltech_10.1c/win32/sccom failed.
# Error in macro C:\Users\Jeff\modelsim_systemC\fir_clk\run0.do line 25

 

What is wrong with my code?

 

Thanks,


Why does not this kind of parameter initialization?

$
0
0

Hi,

 

When I try the following module, I find that the blue color initialization works while the red part is used, it does not work.

 

 

SC_MODULE(mytop)
{
sc_signal<bool> mysig;
sc_clock clk;
myclk mod;
 
SC_CTOR(mytop) : mysig("mysig"), mod("mod"), clk("ccllkk", 20, 0.5)
{
mod.outp(); 
mod.CLK(clk);
}
};
SC_MODULE_EXPORT(mytop);
 
 
..........
SC_MODULE(mytop)
{
                    sc_signal<bool> mysig;
line 7:          sc_clock clk("myclock", 20, 0.5);
                    myclk mod;
 
SC_CTOR(mytop) : mysig("mysig"), mod("mod")
{
mod.outp(); 
mod.CLK(clk);
}
};
SC_MODULE_EXPORT(mytop);

.........

When the above red cannot pas compilation, the error messages are:

 

# clk_g_head.cpp:7: error: expected identifier before string constant
# clk_g_head.cpp:7: error: expected ',' or '...' before string constant
# clk_g_head.cpp: In constructor 'mytop::mytop(sc_core::sc_module_name)':
# clk_g_head.cpp:13: error: no match for call to '(sc_core::sc_in<bool>) (<unresolved overloaded function type>)'
# C:\modeltech_10.1c\include\systemc/sc_signal_ports.h:640: note: candidates are: void sc_core::sc_in<bool>::operator()(const sc_core::sc_signal_in_if<bool>&)
# C:\modeltech_10.1c\include\systemc/sc_signal_ports.h:649: note:                 void sc_core::sc_in<bool>::operator()(sc_core::sc_port<sc_core::sc_signal_in_if<bool>, 1, SC_ONE_OR_MORE_BOUND>&)
# C:\modeltech_10.1c\include\systemc/sc_signal_ports.h:658: note:                 void sc_core::sc_in<bool>::operator()(sc_core::sc_port<sc_core::sc_signal_inout_if<bool>, 1, SC_ONE_OR_MORE_BOUND>&)
# ** Error: (sccom-6142) Compilation failed.
# ** Error: C:/modeltech_10.1c/win32/sccom failed.
# Error in macro C:\Users\Jeff\modelsim_systemC\clk_gen\run1.do line 25
# C:/modeltech_10.1c/win32/sccom failed.
#     while executing
# "sccom -g myclk.cpp clk_g_head.cpp"
# Model Technology ModelSim SE sccom 10.1c compiler 2012.07 Jul 27 2012
# Exported modules:
# mytop
# Model Technology ModelSim SE sccom 10.1c compiler 2012.07 Jul 27 2012
 
 
 
What is wrong? Please help me because I am new to both SystemC and C++ yet. Thanks again.

 

 

 

 

It can have two constructors in a SC_MODULE?

$
0
0

Hi,

 

A class can have several constructors. Can a module have two constructors? I try to do that, but it fails. I don't know whether it is allowed or the code

is wrong:

 

 

 

 

#include <systemc.h>
 
SC_MODULE(myclk) {
 
  sc_in<bool>  reset, sig; 
  sc_in<bool>  input_valid;        
  sc_in<bool>    CLK; 
 
  SC_CTOR(myclk)
     {      
         SC_METHOD(outp);
         sensitive << CLK.pos();
     }
    
  SC_CTOR(myclk, sig)
     {      
         input_valid = sig;
         SC_METHOD(outq);
         sensitive << CLK.pos();
     }  
     
     
     
  void outp();
  void outq(sc_signal<bool>, sc_signal<bool>);
};
 
 
The error message is:
 
 
# In file included from clk_g_head.cpp:2:
# myclk.h:18:21: error: macro "SC_CTOR" passed 2 arguments, but takes just 1
# In file included from clk_g_head.cpp:2:
# myclk.h:18: error: function definition does not declare parameters
# In file included from myclk.cpp:37:
# myclk.h:18:21: error: macro "SC_CTOR" passed 2 arguments, but takes just 1
# In file included from myclk.cpp:37:
# myclk.h:18: error: function definition does not declare parameters
# ** Error: (sccom-6142) Compilation failed.
# ** Error: C:/modeltech_10.1c/win32/sccom failed.
# Error in macro C:\Users\Jeff\modelsim_systemC\clk_gen\run1.do line 25
# C:/modeltech_10.1c/win32/sccom failed.
#     while executing
# "sccom -g myclk.cpp clk_g_head.cpp"
 
 
I do not find the answer after to look it on the manual.
 
Thanks,
 
 

Where is sc_link_mp defined?

$
0
0

Hi,

 

I try to run the following code from 

 

FUNCTIONAL SPECIFICATION
FOR
SYSTEMC 2 . 0

 

There are several key words are undefined. For example, "sc_link_mp" "sc_outmaster" etc. are not recognized by the compiler.

 

What is wrong with this? Those keywords are not supported now?

 

 

 

Thanks,

 

 

 

 

#include <systemc.h>
#include "key.h"
#include "ctrl.h"
#include "fun.h"
#include "disp.h"
 
int key::array1[MYMAX] = { 1,2,3,4,5 };
int key::array2[MYMAX] = {1,3,5,7,9 };
 
int sc_main(int argc, char* argv[])
{
sc_link_mp<int > cmd;
sc_link_mp<int > in1;
sc_link_mp<int > in2;
sc_link_mp<int > op1out;
sc_link_mp<int > op2out;
sc_link_mp<int > cmd_out;
sc_link_mp<int > result;
sc_link_mp<int > display;
key k1("key");
k1.cmd(cmd);
k1.op1(in1);
k1.op2(in2);
k1.clk(clock);
ctrl c1("ctrl");
c1.cmd_in(cmd);
c1.op1_in(in1);
c1.op2_in(in2);
c1.op1_out(op1out);
c1.op2_out(op2out);
c1.cmd_out(cmd_out);
c1.result(result);
c1.display(display);
fun f1("fun");
f1.op1(op1out);
f1.op2(op2out);
f1.cmd(cmd_out);
f1.result(result);
disp d1("display");
d1.din(display);
sc_start(50);
return (0);
};

Why is fixed point number not recognized by compiler?

$
0
0

Hi,

 

Sorry, I find the answer #define SC_INCLUDE_FX

How to achieve concurrency through SC_THREAD

$
0
0

Hi, everyone,

 

I am a starter of SystemC. I wrote a simple example with using SC_THREAD following the example in systemc source.

 

I have two classes which boot two threads, bootMAC and respondDrv. However, when I simulate this program, I observed that only bootMAC is running, respondDrv did not print anything. 
 
Are there anything I still need to add?
 

Thanks so much for you guys' help.

 

The code is follows.

 

class SYSCMAC : public sc_core::sc_module
{
public:
SC_HAS_PROCESS(SYSCMAC);
SYSCMAC(sc_module_name name) : sc_core::sc_module(name)
{
SC_THREAD(bootMAC);
}
 
void bootMAC()
{
while(true)
printf("in bootMAC\n");
}
};
 
class SYSCNETDEV : public sc_module
{
public:
   SC_HAS_PROCESS(SYSCNETDEV);
   SYSCNETDEV(sc_module_name name) : sc_core::sc_module(name)
   {
    SC_THREAD(respondDrv);
   }
 
   void respondDrv()
   {
    while(true)
    printf("in respondDrv\n");
   }
};
 
 
int sc_main(int argc, char **argv)
{
printf("hello world\n");
 
SYSCMAC *q = new SYSCMAC("mac");
SYSCNETDEV *sn = new SYSCNETDEV("qemu");
 
    sc_start();
 
    printf("start simulation now\n");
return 0;
}
 
 
 
 

Writting to fifo causes process to hang.

$
0
0

Hello systemc community,

I want to model a network on chip for my research and systemc proved to be my choice as it meets most of my requirements .In my attempt to try it ,I created two nodes that send simple data to each other using a simple generator and testnode modules as shown in the code below .

 

The generator generates numbers but the code hangs on the statements to write to the fifos .Can anyone help hint out what can be done to make this work?I am quite new to systemc so ,sorry if this is obvious.

 

Thanks.

Dan.

#include <systemc.h>
#include <iostream>

using namespace std;
SC_MODULE(Generator)
{

  sc_out<int> hanze;
  sc_event event1;
  int value;

  SC_HAS_PROCESS(Generator);
  Generator(sc_module_name name);

  void generateMethod();
  void eventTriggerThread();

};

Generator::Generator(sc_module_name name)
 :sc_module(name)
{
   value=0;
   SC_THREAD(eventTriggerThread);
   SC_METHOD(generateMethod);
   dont_initialize();
   sensitive << event1;
}

void Generator::eventTriggerThread()
{
  for(;;)
  {
    wait(1,SC_NS);
   event1.notify();
  }

}

void Generator::generateMethod()
{
   value++;
   hanze.write(value);
   cout<<name()<<"@ "<<sc_time_stamp() << " wrote "<<value << " to the terminal"<< endl;

}


SC_MODULE(testNode)

{
//GENERATOR PORTS
 sc_in <int> dataToSend;
 sc_port < sc_fifo_out_if <int> > out_port;
 sc_port < sc_fifo_in_if <int> > 	in_port;

  SC_HAS_PROCESS(testNode);
  testNode(sc_module_name name);

   void method1();
   void method2 ();
};


testNode::testNode(sc_module_name name)
 :sc_module(name)
{
    SC_THREAD(method1);
    dont_initialize();
    sensitive << dataToSend;

    SC_THREAD(method2);
    dont_initialize();
    sensitive << dataToSend;
}


void testNode::method1()
{

    for( ; ;)
    {
        wait();
    int availableData;
    availableData=dataToSend.read();

    out_port->write(availableData);
    std::cout << "At time "<< sc_time_stamp()  <<" Method1 Wrote a piece of data to the output port :"<<std::endl;
    wait(1, SC_NS);
   }
}
void testNode::method2 ()
{
     for( ; ;)
     {
         wait();
        int availableData;
        availableData=dataToSend.read();

       out_port->write(availableData);
        std::cout <<"At time "<< sc_time_stamp()  << " Method2 Wrote a piece of data to the output port :"<<std::endl;
        wait(1, SC_NS);
     }
}




int sc_main(int argc,char *argv[])
{

    sc_time sim_time( 10, SC_NS);

    //CREATE THE NODE
    testNode mNode1("node1");
    testNode mNode2("node2");

    //CREATE THE SIGNALS
    sc_signal<int> dataToSend1;
    sc_signal<int> dataToSend2;
    sc_fifo<int> connect1To2(1);
    sc_fifo<int> connect2To1(1);

    //CREATE THE GENERATOR
    Generator gen1("gen1");
    Generator gen2("gen2");

    //CONNECT THE GENERATOR
    gen1.hanze(dataToSend1);
    gen2.hanze(dataToSend2);

    //CONNECT THE SIGNALS
    mNode1.dataToSend(dataToSend1);
    mNode1.in_port(connect2To1);
    mNode1.out_port(connect1To2);

    mNode2.dataToSend(dataToSend2);
    mNode2.in_port(connect1To2);
    mNode2.out_port(connect2To1);
    //START THE SIMULATION
    sc_start(sim_time);

    return 1;
}

How to read a text file as input data?

$
0
0

Hi,

 

I want to simulate a FIR filter, which reads a text file content as input data. I have tried with open a text file and call a function (entry) as a parameter, but it fails compilation. Because I cannot paste the code on this window, I attach the text .h file in the attachment. Please tell me how to access a text file in a method. Or you can tell me what is the best way to read text data file into the SystemC simulator.

 

 

Thanks,

Attached Files


Why this forum cannot paste text to a post?

$
0
0

Hi,

 

I don't know what is wrong that I cannot paste text to a post. I have tried Google Chrom and Microsoft Explore.

 

Can you paste when writing a post?

 

I cannot upload image too. When I open the upload image box, it cannot even close the dialogue box.

Can you load image?

 

 

Thanks, 

Can it write a text file in a MC_CTHREAD?

$
0
0

Hi,

 

I write to a text file in a MC_CTHREAD. I find that it can write before an IO write method and wait(). Then, nothing is written to the file any more.

 

I do not know where this is written on the manual. Could you explain it to me?

 

I attach the text file in this post. In this file, the MC_CTHREAD function can write "shift[0000000000]" to the text file while it cannot write "shift[0]" to the text file. Is there some rule about this?

 

 

Thanks,

Difference of file write between MSVC and MINGW421?

$
0
0

Hi,

I have a code run well with Microsoft Visio Studio Express 10.0, but I would like to run with Modelsim which has MINGW4.2.1. I find that the file write operation fails. If I comment out the file operation part, it works.

 

What requirement for SystemC 2.3.1 work with Modelsim?

 

The code is attached below.

 

 

Thanks,

Attached Files

SystemC- 2.3.1 64-bit static library linking issue in windows

$
0
0

Hello,

 

    I am using systemC-2.3.1 which I think has started supporting native windows(x64) build. I have build the library of systemC using the msvc solution file in visual C++ express 2010. The library is generated under x64/Release directory and I didn't get any build error.

 

But while linking this library with my application it throws an error message as follow:

 

systemc.lib<sc_time.obj> : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'.

 

I am compiling my application with visual studio command prompt.

Am I missing here something ?

Process Synchronisation issue

$
0
0

Hello experts

 

I have a tricky synchronisation to achieve in one model. Here I have two thread processes, The IInd one is waiting for an event which is notified by Ist thread. Here after the event notification from Ist process, I wait for one delta cycle to allow IInd one to come out of wait and do some stuff before Ist one proceed. But what I am abserving that after the wait in Ist process, in next delta cycle both process becomes ready to run and scheduler may pick them in any order but I want IInd process  to run before Ist one. I may use another wait but is there any another way to achieve this ?

 

Here is one simple examle to show this issue

 

In the below example, I am getting the following output

P3

P6

I am expecting

P3

P6

 

#include "systemc.h"

SC_MODULE(event_trial){
    public:
    sc_event se;
    SC_CTOR(event_trial) {
 SC_THREAD(process1);
 SC_THREAD(process2);
    }

    void process1(){
 wait(SC_ZERO_TIME);
 se.notify(SC_ZERO_TIME);
 wait(SC_ZERO_TIME);
 cout<<"P3"<<endl;
    }

    void process2(){
 wait(se);
 cout<<"P6"<<endl;
    }
};

int sc_main(int , char**){
    event_trial et("et");
    sc_start();
    return 0;
}

 

Can anyone suggest a recommended way to achieve the desired output

 

Thanks

Rahul

 

Viewing all 595 articles
Browse latest View live