Jump to content

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....)

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

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

 

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...