Jump to content
Aaron Yang

How to connect array of ports?

Recommended Posts

Hey I am kinda new to system C, I met this error when connecting ports declared as array: 

sc_main.cpp: In function 'int sc_main(int, char**)':
sc_main.cpp:16:21: error: expression cannot be used as a function
     tb0.in(sample_in);

This is sc_main.cpp

#include <systemc.h>
#include "fir.h"
#include "tb.h"

int sc_main (int, char *[]){
    sc_clock clock("clock", 10, SC_NS);
    sc_signal<bool> reset;
    sc_signal<sc_fixed<16,2>> sample_in[2];
    sc_signal<sc_fixed<16,2>> sample_out[4];
    
    tb tb0("tb0_name");
    tb0.rstn(reset);
    tb0.clk(clock);
    tb0.in(sample_in);
    tb0.out(sample_out);
  
    fir1("fir1_name", true);
    fir1.din(sample_in);
    fir1.dout(sample_out);

This is the tb.h file

#include <systemc.h>
SC_MODULE(tb)
{
    sc_in<bool>         clk;
    sc_out<bool>        rstn;
    sc_out<sc_fixed<16,2>>  in[2];
    sc_in<sc_fixed<16,2>>   out[4];

This is the fir.h

#include <systemc.h>

SC_MODULE(fir) {
    sc_in<bool>                             rst_n;
    sc_in<bool>                             clk;
    sc_in<sc_fixed<16,2>>      				din[2];
    sc_out<sc_fixed<16,2>>   				dout[4];

What should I do in this case?

Share this post


Link to post
Share on other sites
19 minutes ago, Aaron Yang said:

What should I do in this case?

Usually you should use sc_vector instead of array. The problem with array is that names of signals and ports in array will be initialized to meaningless values (port_0 ... port_1 ).

If you still want to use arrays, then bind with a loop.

Here is example, both for array and sc_vector.

 

#include <systemc.h>

static const int N_PORTS = 4;

struct dut : sc_module {

    sc_in<int>             in_array[N_PORTS];
    sc_vector<sc_in<int>>  in_vector{"in_vector", N_PORTS};

    SC_CTOR(dut) {}

};

struct test : sc_module {

    dut d0{"d0"};
    sc_signal<int>             sig_array[N_PORTS];
    sc_vector<sc_signal<int>>  sig_vector{"sig_vector", N_PORTS};

    SC_CTOR(test) {

        for (size_t i = 0; i < N_PORTS; ++i) {
            d0.in_array[i](sig_array[i]);
        }

        d0.in_vector(sig_vector);
    }

};

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...