Jump to content

Moberg

Members
  • Content Count

    4
  • Joined

  • Last visited

Everything posted by Moberg

  1. Two modules, an input Generator and a Controller. The Generator sends a signal to increase a value in the Controller. The controller contains a loop where it checks if this value is > 0 and in that case do some stuf and reset it to zero.; How should I connect these two modules? Sending an event seemed most intuitional, but it doesnt look like the standard way to do this. I also read about semaphore but I'm not sure how to connect them. (I also want a monitor module to be able to print the value at some points (probably when it is reset))
  2. It is almost always stupid to try to read from your own output signal (right?)(I just got an infinite loop because it didn't update). I had code along these lines: sc_out<bool> access1; sc_out<bool> access2; for(; { while(!(condition1 || condition2)) { wait(sensor_ev); } if(condition1) { access1 = true; } if(condition2) { access2 = true; } if(access1 or access2) { wait(5, SC_SEC); access1 = false; access2 = false; } } The last if could be changed to cond1 or 2 instead of access1 or 2 to remedy this. Any way to make the compiler or the simulator warn me on this kind of code? i.e. whenever an sc_out is being read? Maybe there are cases when I want to read an output?
  3. Moberg

    Use event to communicate between modules

    Thanks this looks like the right stuff. I will try it in a while! Should I use sig.write(true) or is it equal to normal assignment, i.e. sig = true:
  4. Moberg

    Use event to communicate between modules

    I'm not sure what to do, really ^^' I'm not familiar with sc_buffer nor default_event(). I have this code right now. But in this way I can't react to two ones (1) coming in serie, because there has been no change on the input. Testbench: int sc_main(int argc, char **argv) { sc_time sim_time(atof(argv[1]), SC_SEC); char *infile = argv[2]; sc_signal<bool> sig; // create modules Generator generator("Generator", infile); Controller controller("Controller"); // connect channels to ports generator(sig); controller(sig); } (stimuli) Generator: SC_MODULE(Generator) { sc_out<bool> sensor; [...] } Generator::Generator(sc_module_name name, char *datafile) : sc_module(name) { in = new ifstream(datafile); // open input file (it is a file of ones and zeroes, a 1 indicating the sensor getting a new registration) SC_THREAD(generate_thread); } void Generator::generate_thread() { for (; { bool sens; wait(1,SC_SEC); // generate new inputs every second *in >> sens; // read from file sensor = sens; } } (DUT) Controller: SC_MODULE(Controller) { // input ports sc_in<bool> sensor; [...] //internal variables int value; //method void increase(); // thread void controller(); SC_CTOR(Lights) : value(0) { SC_THREAD(controller); sensitive << sensor; SC_METHOD(increase); sensitive << sensor; dont_initialize(); } } void Controller::controller() { while(true) { while(value == 0) wait(); //this could/should wait for an event trigger fired by increase() instead. if(value > 0) { value = 0; wait(20, SC_SEC); } Some_Other_Stuff(); } } void Controller::increase(){ //if(sensor == 1) ++value; } As you see, instead of this signal I would like to trigger the method increase from another module. But I am not sure how to do this. I could let Generator send pulses. But it doesn't feel right. All help is muchly appreciated.
×