Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.75 KB | None | 0 0
  1. #include "systemc.h"
  2.  
  3. SC_MODULE(PROC_2) {
  4.     sc_port<sc_fifo_in_if<int>> mux;
  5.  
  6.     SC_CTOR(PROC_2) {
  7.         SC_THREAD(say_hello);
  8.  
  9.  
  10.     }
  11.     void say_hello() {
  12.         while (true) {
  13.             if (mux->read() == 1) {
  14.                 cout << "Tryb -> " << " GRAMOFON ->" << "   " << " Procesor2  " << endl;
  15.             }
  16.              
  17.         }
  18.     }
  19. };
  20.  
  21. SC_MODULE(MODUL_SPRZETOWY)
  22. {
  23.     sc_in<sc_int<16>>in;
  24.     void work(){
  25.  
  26.         if (in.read() == 1)
  27.         {
  28.             cout << "Tryb -> " << " KASETA -> " << " Modul sprzetowy   " << endl;
  29.         }
  30.        
  31.     }
  32.     SC_CTOR(MODUL_SPRZETOWY)
  33.     {
  34.         SC_METHOD(work);
  35.         sensitive << in;
  36.     }
  37. };
  38.  
  39.  
  40. SC_MODULE(PROC_1) {
  41.  
  42.     sc_out<sc_int<16>>out;
  43.     sc_port<sc_fifo_out_if<int>> mux;
  44.     sc_event a1;
  45.     sc_event a4;
  46.     sc_event a5;
  47.     sc_event a6;
  48.     sc_event a7;
  49.     sc_event a8;
  50.    
  51.  
  52.     SC_CTOR(PROC_1){
  53.         SC_THREAD(say_hello);
  54.         SC_THREAD(task1);
  55.         SC_THREAD(task4);
  56.         SC_THREAD(task5);
  57.         SC_THREAD(task6);
  58.         SC_THREAD(task7);
  59.         SC_THREAD(task8);
  60.  
  61.     }
  62.     void task1()
  63.     {
  64.         while (true) {
  65.             wait(a1);
  66.             cout << "Tryb -> " << " RADIO -> " << " Procesor1  " << endl;
  67.         }
  68.     }
  69.     void task4()
  70.     {
  71.         while (true) {
  72.             wait(a4);
  73.             cout << "Tryb -> " << " PLAYTA -> " << " Procesor1  " << endl;
  74.         }
  75.     }
  76.     void task5()
  77.     {
  78.         while (true) {
  79.             wait(a5);
  80.             cout << "Tryb -> " << " DVD -> " << " Procesor1  " << endl;
  81.         }
  82.     }
  83.     void task6()
  84.     {
  85.         while (true) {
  86.             wait(a6);
  87.             cout << "Tryb -> " << " AUX  -> " << " Procesor1  " << endl;
  88.         }
  89.     }
  90.  
  91.     void task7()
  92.     {
  93.         while (true) {
  94.             wait(a7);
  95.             cout << "Tryb -> " << "RADIO -> FM  -> " << " Procesor1  " << endl;
  96.         }
  97.     }
  98.  
  99.     void task8()
  100.     {
  101.         while (true) {
  102.             wait(a8);
  103.             cout << "Tryb -> " << "RADIO -> AM  -> " << " Procesor1  " << endl;
  104.         }
  105.     }
  106.  
  107.     void say_hello() {
  108.          
  109.         int sw[8] = { 0 };
  110.         while (true) {
  111.              
  112.             wait(10, SC_NS);
  113.             cout << "Za pomoca klawiatury wybierz Tryb: " << endl;
  114.             int a;
  115.             cin >> a;
  116.             system("cls");
  117.  
  118.             //1 tryb on; 0 tryb OFF
  119.             switch (a) {
  120.             case 1: if (sw[0] != 1) { sw[0] = 1; }
  121.                   else { sw[0] = 0; }   break;
  122.             case 2: if (sw[1] != 1) { sw[1] = 1; }
  123.                   else { sw[1] = 0; }break;
  124.             case 3: if (sw[2] != 1) { sw[2] = 1; }
  125.                   else { sw[2] = 0; }break;
  126.             case 4:if (sw[3] != 1) { sw[3] = 1; }
  127.                   else { sw[3] = 0; }break;
  128.             case 5:if (sw[4] != 1) { sw[4] = 1; }
  129.                   else { sw[4] = 0; }break;
  130.             case 6:if (sw[5] != 1) { sw[5] = 1; }
  131.                   else { sw[5] = 0; }break;
  132.             case 7:if (sw[6] != 1) { sw[6] = 1; }
  133.                   else { sw[6] = 0; }break;
  134.             case 8:if (sw[7] != 1) { sw[7] = 1; }
  135.                   else { sw[7] = 0; }break;
  136.             }
  137.  
  138.             int state = 0;
  139.             int currwork = 0;
  140.             for (int j = 0; j < 8; j++)
  141.             {
  142.                 state += sw[j];
  143.                 if (sw[j] == 1)
  144.                 {
  145.                     currwork = j + 1;
  146.                 }
  147.             }
  148.  
  149.             if (state > 1)
  150.             {
  151.                 if (sw[6] == 1)
  152.                 {
  153.                     a7.notify();
  154.                 }
  155.                 else if (sw[7] == 1)
  156.                 {
  157.                     a8.notify();
  158.                 }
  159.                 else cout << "ERROR" << endl;
  160.             }
  161.             else
  162.             {
  163.                 if (state == 0)
  164.                 {
  165.                     cout << " BRAK TRYBU " << endl;
  166.                     out.write(0);
  167.                 }
  168.                 else
  169.                 {
  170.                     if (currwork != 2 && currwork != 3) {
  171.  
  172.                         out.write(0);
  173.                         switch (currwork)
  174.                         {
  175.                         case(1):a1.notify(); break;
  176.                         case(4):a4.notify(); break;
  177.                         case(5):a5.notify(); break;
  178.                         case(6):a6.notify(); break;
  179.                         }
  180.                     }
  181.                     else
  182.                     {
  183.                         if (currwork == 3)
  184.                         {
  185.                             out.write(1);
  186.                         }
  187.                         else
  188.                         {
  189.                             out.write(0);
  190.                             mux->write(1);
  191.                         }
  192.                     }
  193.                 }
  194.             }
  195.         }
  196.     }
  197. };
  198.  
  199. int sc_main(int argc, char* argv[]) {
  200.  
  201.  
  202.     PROC_2 proc_2("PROC_2");
  203.     PROC_1 proc_1("PROC_1");
  204.     MODUL_SPRZETOWY modul_sprzetowy("MODUL_SPRZETOWY");
  205.  
  206.     sc_signal<sc_int<16>> sygnal;
  207.     sc_signal<sc_int<16>> out;
  208.     sc_fifo<int> mux;
  209.  
  210.     proc_1.out(sygnal);
  211.     modul_sprzetowy.in(sygnal);
  212.     proc_1.mux(mux);
  213.     proc_2.mux(mux);
  214.  
  215.     sc_start();
  216.     return(0);
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement