Jump to content
Sign in to follow this  
ashwathgan

Advise on Multiple Driver problem

Recommended Posts

Hi all

 

 

I am trying to build a Statemachinefor different tasks that is given as input:

 

To be more specific, i have different states like Not_ready, ready, running which would do some operations and advance the time respectively

 

 

 

I have something like this:

 

class StateMachine: public sc_module

{

enum state {NotREAdy, ready,..}

 

 

sc_out<bool> out;

 

void perform

{

switch (state)

{

case Not_ready: ... Do something and update state value to "ready"

case Ready : Do something and update state value to "running"

case Rnning : do some calculation and wait for event

out.write(true); // send output to timer module

}

 

//I have a constructor lik this

StateMachine(sc-module_name name, ......): sc_module(name)

{..

 

 

sensitive < Event;

}

 

 

 

};

 

 

 

SC_MODULE(Timer)

{

sc_in<bool> timeIn;

 

void time()

{

Event.notify(20,SC_NS);

}

 

SC_CTOR(Timer)

{

senstivity << TimeIn;

SC_METHOD(time);

}

};

 

 

main()

{

 

// I am creating two instances of StateMAchine for TaskA and taskB

 

 

StateMachine *M1 = new StateMachine(TaskA, .....);

Statemachine*M2 = new Statemachine(Taskb,.......);

 

 

Now when I try to bind the ports, I get error of multple drivers from Statemachine (E115)

 

 

 

How to use vector of ports here with type bool from StateMachine and how to bind it with the port of Timer module??

 

 

 

 

Share this post


Link to post
Share on other sites

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

{

 

// Manager(Module Name, Task Name, Initial State, Load, Speed)

 

      Manager*M1 =  new Manager("Sys","A",State::NOT_READY,100,1);

      Manager*M2 = new Manager("Mys", "B", State::NOT_READY, 20,1);

     

 

      sc_signal<bool> timing;

 

 

      M1->calculateTime(timing);

     M2->calculateTime(timing);

     

 

      Timer T("timer");

      T.Timecal(timing);

 

 

 

      sc_start();

 

     

 

      system("PAUSE");

      return(0);

}

Share this post


Link to post
Share on other sites

Yes, you've connected the signal timing twice times. That's not allowed with the default options for sc_signal.

 

You can declare two signals, e.g.

 

sc_signal<bool> timing[2];

 

and then bind timing[0] to the first module, timing[1] to the second.

 

You then need a port sc_in<bool> TimingIn[2] on the timer, and to make the process sensitive to both TimingIn[0] and TimingIn[1].

 

regards

Alan

 

P.S. If this alls seems a bit tedious, you use the sc_vector class (look in the LRM); or, as I always say for this type of code - write it in VHDL instead :-)

Share this post


Link to post
Share on other sites

Thanks a lot Sir. It cleared many of my doubts:

 

I have one last doubt

 

Now I have my main lik as follows:

 

int sc_main(int argc, char* argv[])
{
 
Manager*M1 = new Manager("Sys", "A", State::NOT_READY, 100, 1);
Manager*M2 = new Manager("Mys", "B", State::NOT_READY, 20,1);
 
 
sc_signal<bool> timing[1];
 
 
M1->calculateTime(timing[0]);
M2->calculateTime(timing[1]);
 
 
// Im confused about how to connect here with the Timer module as my code crashes at this Timer binding
 
Timer T("timer");
for (int z = 0; z < 1; z++)
{
T.Timecal[z](timing[z]);
}
 
 
 
 
 
sc_start();
 
 
 
system("PAUSE");
return(0);
}
 
 
 
and also my "Timer "module with array of ports as follows:
 
 

SC_MODULE(Timer)
{
sc_in<bool> Timecal[1];
 
void time()
{
for (int i = 0; i < 1; i++)
{
if (Timecal.read())
{
 
ND1.notify(100, SC_NS);
}
}
 
}
 
SC_CTOR(Timer)
{
SC_METHOD(time);
for (int i = 0; i < 1; i++)
{
sensitive << Timecal;
}
 
}
};
 
 
 
But my output crashes:
 
The problem is with this:
 
T.Timecal[1](timing[1]);
 
How should I bind with the array of ports?
 
 
Im sorry for this stupid question
 

Share this post


Link to post
Share on other sites

You have to bind each port in turn i.e. bind port 0 to 0, 1 to 1 etc.

Your arrays need to be size 2, i.e. sc_signal<bool> timing[2],  sc_in<bool> Timecal[2] and so on.

 

The sc_vector class is intended to help with this issue (that is binding multiple elements of an array in one call)

 

regards

Alan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×