2

我正在尝试在 systemc 中使用 switch case 语句,并且我希望 case 是数据类型 int 的端口。我创建的代码如下:

#ifndef TRAFFIC_H_
#define TRAFFIC_H_
#include<systemc.h>

SC_MODULE(traffic){
sc_in<int>next; //R,G,A;
sc_out<bool>t_R1,t_G1,t_A1;
sc_out<bool>t_R2,t_G2,t_A2;
sc_out<bool>t_R3,t_G3,t_A3;
sc_out<bool>t_R4,t_G4,t_A4;


void traffic_light();

    SC_CTOR(traffic){
        SC_THREAD(traffic_light);
        sensitive<<next;

    }
};
void traffic :: traffic_light(){

    switch(next){

    case  next == 1:

        t_R1 == 0; t_G1 == 1; t_A1 == 0;
        t_R2 == 1; t_G2 == 0; t_A2 == 0;
        t_R3 == 1; t_G3 == 0; t_A3 == 0;
        t_R4 == 1; t_G4 == 0; t_A4 == 0;
        wait(5, SC_NS);
        t_R2==1;t_G2==0;t_A2 == 1;
        break;


    }
}



#endif /* TRAFFIC_H_ */

错误就行了;

case  next == 1:

我得到的错误信息是:

调用非 constexpr 函数 'sc_core::sc_in::operator const data_type&() const [with T = int; sc_core::sc_in::data_type = int]

我如何声明案例,使其成为一个端口以及使用哪种数据类型,因为我想要四个案例 1 到 4,以便它进行四次?

4

1 回答 1

2

正确的语法是:

switch(next) {
case 1:
    // your code goes here
    break;
case 2:
    // your code for next==2 goes here
    break;
// etc.
}

此外,除非你有一个whileorfor循环,否则traffic::traffic_light()你想使用SC_METHOD,而不是SC_THREAD

SC_METHOD(traffic_light)
于 2015-08-05T19:29:21.620 回答