简体   繁体   English

如何正确地将sc_lv转换为sc_uint?

[英]How to properly convert sc_lv to sc_uint?

For a project, I am trying to convert a value that I receive from an sc_lv<8> type input port to an sc_uint<8> type signal. 对于一个项目,我试图将从sc_lv<8>类型的输入端口接收到的值转换为sc_uint<8>类型的信号。 By the way, the input port is connected to an sc_signal_rv<8> channel. 顺便说一下,输入端口连接到sc_signal_rv<8>通道。

I tried casting the input data using this line : 我尝试使用此行转换输入数据:

sc_in< sc_lv<8> > data_in;

// Other declarations

sc_signal< sc_uint<8> > tx_data;

// Other declarations
// Assume that all else is properly declared

sc_uint<8> temp;
temp = (sc_uint<8>)data_in->read(); // Casting
tx_data.write(temp);

But I get this warning during simulation : 但是我在模拟过程中收到此警告:

Warning: (W211) sc_logic value 'Z' cannot be converted to bool

I though of doing a case-by-case affect, but I'm not entirely sure. 尽管我会逐案处理,但我不确定。

Any ideas? 有任何想法吗?

That's a warning, it notices you about 4-value to 2-value converting, it would lose information. 这是一个警告,它会通知您有关从4值到2值的转换,它将丢失信息。 So warning is good to make you awaring that 因此警告可以使您警惕

Agree with enchanter. 同意附魔。 But, it is a good practice to have your program compile without any warning, in other words that warning is a question and you should answer by modifying your code with an explicit cast: 但是,在没有任何警告的情况下编译程序是一个好习惯,换句话说,警告是一个问题,您应该通过使用显式强制转换来修改代码来回答:

sc_uint<8> temp = static_cast< sc_uint<8> >( data_in->read() );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM