Jump to content
Eustaquio

Newbie problem: writing to a range of bits of sc_out ports declared as sc_lv<n>

Recommended Posts

I am working as a VHDL developer, and I am evaluating the use of SystemC, mainly focused on writing synthesizable code according some third vendor manuals.

 

I am currently writing SystemC versions of some basic VHDL modules we have, and I have some newbie doubts accesing a range of bits of types sc_lv<n>.

 

For example, I have this code that works:

SC_MODULE (blah)
{
....
sc_out <sc_lv<8> > dummy;
...
dummy.write((SC_LOGIC_0, dummy.read()(7,1)));    // Correct at compile and simulation
...

But I am not able to write to a single position or to a range of positions of dummy. Following instructions of different manuals, and trying desperate things, I have tried:

dummy[2].write(SC_LOGIC_1);            // error: request for member ‘write’ in  [...] (maybe you meant to use ‘->’ ?)
dummy[2]=SC_LOGIC_1;                   // error : lvalue required as left operand of assignment
dummy(5,2).write(0xA);                 // error: no match for call to ‘(sc_core::sc_out<sc_dt::sc_lv<8> >) (int, int)’
dummy.range(5,2).write(0xA);           // error: ‘class sc_core::sc_out<sc_dt::sc_lv<8> >’ has no member named ‘range’

How could I write on position 2 of dummy, or a nibble in positions 5 to 2 of dummy?

 

The only working solution I have found is too complicated, so I think it is an awful way:

 
dummy.write(((dummy.read()(7,3), SC_LOGIC_1),dummy.read()(1,0)));        // Working, but too complicated
dummy.write(((dummy.read()(7,6), 0xA),dummy.read()(1,0)));               // Working, but too complicated
 

 

 

Share this post


Link to post
Share on other sites

Probably the most readable thing would be to read into a temporary variable, manipulate it, then write back. E.g.

 

sc_lv<8> temp = dummy;

temp[2] = SC_LOGIC_1;

dummy.write(temp);

 

The main thing you need to think about is that in VHDL each element of a signal of type std_logic_vector is itself a signal (of type std_logic). In SystemC that's not true.  sc_signal <sc_lv<8> > s is a single signal s containing data of type sc_lv<8>. You can't do s[2], but you can do s.read()[2]. The [], concat(), and range() methods belong to the data type, not to the signal class,

 

regards

Alan

 

P.S. You can also run into issues with concat() and range() because they don't return  the data type you think they do (i.e. sc_lv<> in the example I gave), they return proxy classes, which you sometimes need to cast.

Share this post


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