Reputation: 23
I am trying to use a switch case statement in systemc and I want the case to be a port of data type int. The code I have created is as follows:
#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_ */
the error is on the line;
case next == 1:
The error message I get is:
call to non-constexpr function ‘sc_core::sc_in::operator const data_type&() const [with T = int; sc_core::sc_in::data_type = int]
How do I declare the case so that it will be a port and with which data type because I want to have four cases 1 to 4 so that it goes four times?
Upvotes: 2
Views: 1232
Reputation: 168796
The correct syntax is:
switch(next) {
case 1:
// your code goes here
break;
case 2:
// your code for next==2 goes here
break;
// etc.
}
Also, unless you have a while
or for
loop in traffic::traffic_light()
, you want to use SC_METHOD
, not SC_THREAD
:
SC_METHOD(traffic_light)
Upvotes: 2