Jump to content

binding issue


Partha

Recommended Posts

i am trying to implement i2c protocol using systemC. and i'm getting this error  some port binding fails.

cam anyone please resolve this problem ??

 

// Code your testbench here.
// Uncomment the next line for SystemC modules.
#include <systemc.h>
#include <stdlib.h>
class slave_if : public sc_interface
{
  public:
    virtual void write(int data) = 0;
      virtual void read() = 0;
};

SC_MODULE(Host)
{
     sc_in<bool> scl;
      sc_in<bool> sda;
      sc_in<bool> rw;
    sc_port<slave_if> host_port;
      int val;
      void behaviour()
    {
        if(scl == 1 && sda == 0 && rw == 0)
        {
              val = rand()%50;
            host_port->write(val);
        }
          else if(scl == 1 && sda == 0 && rw == 1)
        {
            host_port->read();
        }
    }
  SC_CTOR(Host)
  {
      SC_METHOD(behaviour);
    sensitive << scl << sda << rw;
  }
      
};

SC_MODULE(Master),public slave_if
{
    sc_in<bool> clk;
      sc_out<bool> scl;
      sc_out<bool> sda;
      sc_out<bool> rw;
      sc_fifo_out<int> master_write_fifo;
      sc_fifo_in<int> master_read_fifo;
      int i = 0,data_get,val,no_bits = 8;
      Host my_host;
  void write(int data)
  {
      while(no_bits!=0)
      {
          sda = data & 1;
          wait(SC_ZERO_TIME);
          master_write_fifo.write(sda);
          no_bits++;
      }
  }
  
  void read()
  {
      while(i!=8)
      {
        master_read_fifo.read(val);
        data_get = data_get + (val*pow(2,i));
        /*master_read_fifo.read(val);
        cout<<"value:->"<<val<<endl;*/
        i++;
      }
       cout<<"my data:-->"<<data_get;
  }
  
  SC_CTOR(Master):my_host("my_host")
  {
    my_host.scl(scl);
    my_host.sda(sda);
    my_host.rw(rw);
  }
};

SC_MODULE(Slave)
{
    sc_inout<bool> scl ;
      sc_inout<bool> sda ;
      sc_inout<bool> rw ;
      
      Master slave_master;
  
      SC_CTOR(Slave) : slave_master("slave_master")
    {
        slave_master.scl(scl);
          slave_master.sda(sda);
          slave_master.rw(rw);
    }
      
};

int sc_main(int argc , char* argv[])
{
  sc_clock clk("clk",1,SC_NS);
  sc_signal<bool> scl;
  sc_signal<bool> sda;
  sc_signal<bool> rw;
  sc_fifo<int> main_fifo;
  Master master("master");
  master.clk(clk);
  master.master_write_fifo(main_fifo);
  master.master_read_fifo(main_fifo);
  Slave slave("slave");
  scl.write(1);
  sda.write(0);
  rw.write(0);
  slave.scl(scl);
  slave.sda(sda);
  slave.rw(rw);
  
  sc_start();
  return 0;
}

 

Error: (E109) complete binding failed: port not bound: port 'slave.slave_master.my_host.port_3' (sc_port)
In file: ../../../../src/sysc/communication/sc_port.cpp:231

Link to comment
Share on other sites

Hello @Partha,

As the error message suggests the third indexed interface in host(my_host) object instance is not bound:

i.e. host_port.

For future reference pass the name of the interface also so that you  can get more descriptive names in the error messages.

For e.g.: Changing your source files as shown below changes the error message:

// Code your testbench here.
// Uncomment the next line for SystemC modules.
#include <systemc.h>
#include <stdlib.h>
class slave_if : public sc_interface
{
public:
    virtual void write(int data) = 0;
    virtual void read() = 0;
};

SC_MODULE(Host)
{
    sc_in<bool> scl{"scl"};
    sc_in<bool> sda{"sda"};
    sc_in<bool> rw{"rw"};
    sc_port<slave_if> host_port{"host_port"};
    int val;
    void behaviour()
    {
        if (scl == 1 && sda == 0 && rw == 0)
        {
            val = rand() % 50;
            host_port->write(val);
        }
        else if (scl == 1 && sda == 0 && rw == 1)
        {
            host_port->read();
        }
    }
    SC_CTOR(Host)
    {
        SC_METHOD(behaviour);
        sensitive << scl << sda << rw;
    }
};

SC_MODULE(Master), public slave_if
{
    sc_in<bool> clk{"clk"};
    sc_out<bool> scl{"scl"};
    sc_out<bool> sda{"sda"};
    sc_out<bool> rw{"rw"};
    sc_fifo_out<int> master_write_fifo{"master_write_fifo"};
    sc_fifo_in<int> master_read_fifo{"master_read_fifo"};
    int i = 0, data_get, val, no_bits = 8;
    Host my_host;
    void write(int data)
    {
        while (no_bits != 0)
        {
            sda = data & 1;
            wait(SC_ZERO_TIME);
            master_write_fifo.write(sda);
            no_bits++;
        }
    }

    void read()
    {
        while (i != 8)
        {
            master_read_fifo.read(val);
            data_get = data_get + (val * pow(2, i));
            /*master_read_fifo.read(val);
        cout<<"value:->"<<val<<endl;*/
            i++;
        }
        cout << "my data:-->" << data_get;
    }

    SC_CTOR(Master) : my_host("my_host")
    {
        my_host.scl(scl);
        my_host.sda(sda);
        my_host.rw(rw);
    }
};

SC_MODULE(Slave)
{
    sc_inout<bool> scl{"scl"};
    sc_inout<bool> sda{"sda"};
    sc_inout<bool> rw{"rw"};

    Master slave_master;

    SC_CTOR(Slave) : slave_master("slave_master")
    {
        slave_master.scl(scl);
        slave_master.sda(sda);
        slave_master.rw(rw);
    }
};

int sc_main(int argc, char *argv[])
{
    sc_clock clk("clk", 1, SC_NS);
    sc_signal<bool> scl{"scl"};
    sc_signal<bool> sda{"sda"};
    sc_signal<bool> rw{"rw"};
    sc_fifo<int> main_fifo{"main_fifo"};
    Master master("master");
    master.clk(clk);
    master.master_write_fifo(main_fifo);
    master.master_read_fifo(main_fifo);
    Slave slave("slave");
    scl.write(1);
    sda.write(0);
    rw.write(0);
    slave.scl(scl);
    slave.sda(sda);
    slave.rw(rw);

    sc_start();
    return 0;
}

to

		SystemC 2.3.4_pub_rev_20190904-Accellera --- Nov 18 2019 21:47:55
        Copyright (c) 1996-2019 by all Contributors,
        ALL RIGHTS RESERVED

Error: (E109) complete binding failed: port not bound: port 'slave.slave_master.my_host.host_port' (sc_port)
In file: /home/ameyavs/apps/src/systemc/src/sysc/communication/sc_port.cpp:235

Hope this helps.

Regards,

Ameya Vikram Singh

Link to comment
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...