Click here to Skip to main content
15,916,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, we have the following code segment:

//Sensor Module 1
SC_MODULE(MODULE1) {
    sc_signal<int> s1;
    sc_port<sc_signal_out_if<int>> port 1;

    SC_CTOR(MODULE1) {
        SC_THREAD(Sensor_1);
        sensitive << s1;
    }
    void Sensor_1() {
        int s1val;
        while (true) {
            s1val = rand() % 6;
            std::cout << "Sensor 1 data produced: " << s1val << endl;
            s1.write(s1val);
            wait(10, SC_MS);
        }
    }
};

//Sensor Module 1
SC_MODULE(MODULE2) {
    sc_signal<int> s2;
    sc_port<sc_signal_out_if<int>> port 2;

    SC_CTOR(MODULE2) {
        SC_THREAD(Sensor_2);
        sensitive << s2;
    }
    void Sensor_2() {
        int s2val;
        while (true) {
            s2val = rand() % 6;
            std::cout << "Sensor 2 data produced: " << s2val << endl;
            s2.write(s2val);
            wait(10, SC_MS);
        }
    }
};

// Camera Module 
SC_MODULE(MODULE3) {
    sc_signal<int[4]> cam;
    sc_port<sc_signal_out_if<int[4]>> port3;
    
    
    SC_CTOR(MODULE3) {
       SC_THREAD(Camera);
       sensitive << cam; 
    }
    
    void Camera() {
        int array[4];
        while (true) {
            for (int i = 0; i < 4; i++) {
                array[i] = rand() % 10;
            }
            std::cout << "Camera data produced: " << endl;
            for (int i = 0; i < 4; i++) {
                std::cout << array[i] << " ";
            }
            std::cout << endl;

            cam.write(array);
            wait(20, SC_MS);
        }
    }
};


What we want to also add is that the sensors sample data every, say, 30 seconds and the camera sample data every, say, 40 seconds. How to implement the operations in systemC? Is there someone who could please help? We haven't had so much systemC before.

What I have tried:

Tried with searching the internet, but couldn't get the necessary information/inspiration.
Posted
Updated 27-Dec-22 0:26am
Comments
[no name] 26-Dec-22 10:47am    
I see a bunch of "wait" statements in there. Understanding why they are there and what they are waiting on would probably further your cause.

A wild guess, based on this Time In SystemC Part V[^]:
Change from (Sensor_1, Sensor_2)
Quote:
wait(10, SC_MS);
to
C++
wait(30, SC_SEC);


from (Camera)
Quote:
wait(20, SC_MS);
to
C++
wait(40, SC_SEC);
 
Share this answer
 
Comments
Member 15862460 27-Dec-22 8:00am    
Thanks, CPallini
CPallini 27-Dec-22 9:30am    
You are welcome.
You have two options:

1. Visit some Learn C tutorial and get started.
2. Hire some coder to do the job.

In the first case you need to learn the basics and understand the macros of your code. The code
SC_MODULE(MODULE1)
get resolved from the compiler into some other code. You need to understand what is going on and I think it is a bit weired.
So it isnt as easy as you may think.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900