Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "systemc.h"
- SC_MODULE(PROC_2) {
- sc_port<sc_fifo_in_if<int>> mux;
- SC_CTOR(PROC_2) {
- SC_THREAD(say_hello);
- }
- void say_hello() {
- while (true) {
- if (mux->read() == 1) {
- cout << "Tryb -> " << " GRAMOFON ->" << " " << " Procesor2 " << endl;
- }
- }
- }
- };
- SC_MODULE(MODUL_SPRZETOWY)
- {
- sc_in<sc_int<16>>in;
- void work(){
- if (in.read() == 1)
- {
- cout << "Tryb -> " << " KASETA -> " << " Modul sprzetowy " << endl;
- }
- }
- SC_CTOR(MODUL_SPRZETOWY)
- {
- SC_METHOD(work);
- sensitive << in;
- }
- };
- SC_MODULE(PROC_1) {
- sc_out<sc_int<16>>out;
- sc_port<sc_fifo_out_if<int>> mux;
- sc_event a1;
- sc_event a4;
- sc_event a5;
- sc_event a6;
- sc_event a7;
- sc_event a8;
- SC_CTOR(PROC_1){
- SC_THREAD(say_hello);
- SC_THREAD(task1);
- SC_THREAD(task4);
- SC_THREAD(task5);
- SC_THREAD(task6);
- SC_THREAD(task7);
- SC_THREAD(task8);
- }
- void task1()
- {
- while (true) {
- wait(a1);
- cout << "Tryb -> " << " RADIO -> " << " Procesor1 " << endl;
- }
- }
- void task4()
- {
- while (true) {
- wait(a4);
- cout << "Tryb -> " << " PLAYTA -> " << " Procesor1 " << endl;
- }
- }
- void task5()
- {
- while (true) {
- wait(a5);
- cout << "Tryb -> " << " DVD -> " << " Procesor1 " << endl;
- }
- }
- void task6()
- {
- while (true) {
- wait(a6);
- cout << "Tryb -> " << " AUX -> " << " Procesor1 " << endl;
- }
- }
- void task7()
- {
- while (true) {
- wait(a7);
- cout << "Tryb -> " << "RADIO -> FM -> " << " Procesor1 " << endl;
- }
- }
- void task8()
- {
- while (true) {
- wait(a8);
- cout << "Tryb -> " << "RADIO -> AM -> " << " Procesor1 " << endl;
- }
- }
- void say_hello() {
- int sw[8] = { 0 };
- while (true) {
- wait(10, SC_NS);
- cout << "Za pomoca klawiatury wybierz Tryb: " << endl;
- int a;
- cin >> a;
- system("cls");
- //1 tryb on; 0 tryb OFF
- switch (a) {
- case 1: if (sw[0] != 1) { sw[0] = 1; }
- else { sw[0] = 0; } break;
- case 2: if (sw[1] != 1) { sw[1] = 1; }
- else { sw[1] = 0; }break;
- case 3: if (sw[2] != 1) { sw[2] = 1; }
- else { sw[2] = 0; }break;
- case 4:if (sw[3] != 1) { sw[3] = 1; }
- else { sw[3] = 0; }break;
- case 5:if (sw[4] != 1) { sw[4] = 1; }
- else { sw[4] = 0; }break;
- case 6:if (sw[5] != 1) { sw[5] = 1; }
- else { sw[5] = 0; }break;
- case 7:if (sw[6] != 1) { sw[6] = 1; }
- else { sw[6] = 0; }break;
- case 8:if (sw[7] != 1) { sw[7] = 1; }
- else { sw[7] = 0; }break;
- }
- int state = 0;
- int currwork = 0;
- for (int j = 0; j < 8; j++)
- {
- state += sw[j];
- if (sw[j] == 1)
- {
- currwork = j + 1;
- }
- }
- if (state > 1)
- {
- if (sw[6] == 1)
- {
- a7.notify();
- }
- else if (sw[7] == 1)
- {
- a8.notify();
- }
- else cout << "ERROR" << endl;
- }
- else
- {
- if (state == 0)
- {
- cout << " BRAK TRYBU " << endl;
- out.write(0);
- }
- else
- {
- if (currwork != 2 && currwork != 3) {
- out.write(0);
- switch (currwork)
- {
- case(1):a1.notify(); break;
- case(4):a4.notify(); break;
- case(5):a5.notify(); break;
- case(6):a6.notify(); break;
- }
- }
- else
- {
- if (currwork == 3)
- {
- out.write(1);
- }
- else
- {
- out.write(0);
- mux->write(1);
- }
- }
- }
- }
- }
- }
- };
- int sc_main(int argc, char* argv[]) {
- PROC_2 proc_2("PROC_2");
- PROC_1 proc_1("PROC_1");
- MODUL_SPRZETOWY modul_sprzetowy("MODUL_SPRZETOWY");
- sc_signal<sc_int<16>> sygnal;
- sc_signal<sc_int<16>> out;
- sc_fifo<int> mux;
- proc_1.out(sygnal);
- modul_sprzetowy.in(sygnal);
- proc_1.mux(mux);
- proc_2.mux(mux);
- sc_start();
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement