Jump to content
HenkNep

Tri-State output port

Recommended Posts

Hi,

I have a simple tri-state output signal

sc_out<sc_logic> ctrlout;

If I write to it directly compilation fails:

ctrlout.write('Z'); // fails

The same applies to using a variable:

sc_logic local='Z'; // fails

The only one that works is:

sc_logic local;
local='Z';
ctrlout.write(local);


Do I really have to jump through so many hoops to assign a tri-state value to an output port?

I then found an example on the web which uses resolved types, even though I only have 1 driver the resolved type works:

sc_out_rv<1> out;
out.write('Z');


Am I correct in stating that even for a single driver I need to use the _rv types?

I also noticed that _resolved has the same issues, that is you cannot assign 'Z' directly.

Thanks for any advice.

Share this post


Link to post
Share on other sites

Conversion from char to sc_logic is not possible in all cases.  But fortunately, you can find the solution to your question is Section 7.9.2.8 of the IEEE Std. 1666-2011for SystemC (emphasis added):
 

7.9.2.8 sc_logic constant definitions

A constant of type sc_logic shall be defined for each of the four possible sc_logic_value_t states. These constants should be used by applications to assign values to, or compare values with, other sc_logic objects, particularly in those cases where an implicit conversion from a C++ char value would be ambiguous.

namespace sc_dt {
  const sc_logic SC_LOGIC_0( Log_0 );
  const sc_logic SC_LOGIC_1( Log_1 );
  const sc_logic SC_LOGIC_Z( Log_Z );
  const sc_logic SC_LOGIC_X( Log_X );
}

 

You can the use

ctrlout.write( sc_dt::SC_LOGIC_Z ); 

to write to the port/signal directly.

 

Greetings from Oldenburg,
  Philipp

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

×