Jump to content
Elvis

How to connect sc_signals/ports with simple data types ?

Recommended Posts

 

Hi,  I came across the ConnectPorts between TDF and Discrete domain models.....  In this case for the discrete domain is intended a System-C model, therefore, we go from classes to classes. The question I have is:  How to connect in an efficient way a sc_signal<double> with a variable of type double?   

 

sc_signal<double>  myscd;

double myvar;

having the above defined, what is a good way to do (a made up code):

 

assign myscd = myvar;

 

and

 

assign myvar = myscd;

 

I usually have to use the .read()  and .write() methods but how can I achieve a permanent assignment?  assuming that all that I want to do is manipulate simple variables.  The same would apply to other data types (int, logic etc....)

Share this post


Link to post
Share on other sites

Signals constitute the communication channels between your models. However, in almost all cases, you should avoid to read/write them directly. Signals are meant to be bound to ports, which constitute the interface of your modules. The read() and write() member functions of the ports are the primary functions to reading a value from the port or writing a value into it, respectively. As you can see from the class definitions of the ports in the SystemC LRM and SystemC AMS LRM, the ports do provide depending on their input/output direction overloads, which allow them to be used in most cases like a regular variable for reading and writing:

sc_core::sc_in<int> de_in;
sc_core::sc_out<int> de_out;
sca_tdf::sca_in<double> tdf_in;
sca_tdf::sca_out<double> tdf_out;

...
  
void my_proc() {
  int ivar;
  double dvar;
  
  ivar = de_in;
  de_out = ivar;
  
  dvar = tdf_in;
  tdf_out = dvar;
}

Though, using the read() and write() member functions of the ports is the recommended practice as this makes it explicit that you are accessing a port instead of a variable. As this questions touches very basic concepts of SystemC (AMS), I recommend you to read a good introductory text on SystemC and SystemC AMS.

Share this post


Link to post
Share on other sites

Thanks for the code template.  

"As this question touches very basic concepts of SystemC (AMS), I recommend you to read a good introductory text on SystemC and SystemC AMS.".  

Your point is well taken here. Sometimes, is hard to spot the solution to your problem by just going through the LRM. It comes down to having acquired a certain level of experience :).

Thanks again,

Elvis

 

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

×