Ejemplo n.º 1
0
        void act() {
            // get aware of what capacity the memory features
            memsize = memory->size();
            cout << "CPU: size request served, capacity is " << memsize << " data units." << endl;

            // make room for local computations
            const unsigned char opbufsize = 10;  // set this > 2!
            char *operate_buf = new char[opbufsize];
            // initialize operate_buf with some readable (ascii) data
            for (char *x = operate_buf; x < operate_buf + opbufsize; x++) {
                *x = 48 + (random() % 43); // some in the ascii alphanum domain (circa)
            }

            // A unit operation -- store operate_buf[0] into memory at some random address
            // choose a random address (within memory space) to operate, warn, then write
            address_t operaddr = random() % memsize;
            cout << "CPU: will write " << operate_buf[0] << " into memory's " << operaddr << " cell." << endl;
            // write and read ops might cause errors...
            try {
                memory->write(operate_buf[0], operaddr);
            } catch (std::runtime_error &e) {
                cout << "CPU: an error occurred: " << e.what() << endl;
                return;
            }
            char tmpbuf;
            try {
                memory->read(tmpbuf, operaddr);
            } catch (std::runtime_error &e) {
                cout << "CPU: an error occurred: " << e.what() << endl;
                return;
            }
            cout << "CPU: memory location " << operaddr << " now holding '" << tmpbuf << "'." << endl;

            // A block operation -- store a bunch of data units into memory at some
            // random address, then, fetch some of them back
            operaddr = random() % (memsize - opbufsize);
            // advicing data, and writing to memory
            cout << "CPU: will write: "; for (unsigned char i = 0; i < opbufsize; i++) cout << operate_buf[i]; cout << endl;
            try {
                memory->writeblock(operate_buf, opbufsize, operaddr);
            } catch (std::runtime_error &e) {
                cout << "CPU: an error occurred: " << e.what() << endl;
                return;
            }
            // reading back some piece of it
            cout << "CPU: getting back " << opbufsize/2 << " units of data...";
            char *newbuf = new char[opbufsize/2];
            try {
                memory->readblock(newbuf, opbufsize/2, operaddr);
            } catch (std::runtime_error &e) {
                cout << "CPU: an error occurred: " << e.what() << endl;
                return;
            }

            cout << "CPU: got back ";
            for (unsigned char i = 0; i < opbufsize/2; i++) cout << newbuf[i];
            cout << endl;

            delete[] operate_buf;   // free the temporary buffer
        }
Ejemplo n.º 2
0
Archivo: main.cpp Proyecto: Yonka/sc
    void send_byte()
    {
        out_port->write(x);
        send.notify(5, SC_NS);
        wait();
//		cout << "send " << x << '\n';
    }
Ejemplo n.º 3
0
    void main()
    {
        const char *str =
            "Visit www.systemc.org and see what SystemC can do for you today!\n";

        while (*str)
            out->write(*str++);
    }
Ejemplo n.º 4
0
        void act() {
            while (true) {
                cout << "MemAdaptor: waiting for requests..." << endl;
                // wait for a request to come
                while (req.read() != true) wait();
                // request now accepted
                address_t memaddr = addr.read(); // read recipient address
                // SIZE request?
                if (memsize.read() == true) {
                    // SIZE request!
                    cout << "MemAdaptor: SIZE request income, processing...";
                    addr.write(memory->size());
                    cout << " done." << endl;
                    goto act_oper_ok;
                }
                // READ request?
                if (r_w.read() == true) {
                    // READ request!
                    cout << "MemAdaptor: READ request income, processing...";
                    char val;
                    try {
                        memory->read(val, memaddr);
                    } catch (std::runtime_error &e) {
                        // an error occurred, reporting on the bus
                        goto act_oper_err;
                    }
                    data.write(val);
                    cout << " done." << endl;
                    goto act_oper_ok;
                }
                // in any other case..
                // WRITE request!
                cout << "MemAdaptor: WRITE request income, processing...";
                try { memory->write(data.read(), memaddr); } catch (std::runtime_error &e) {
                    // an error occurred, reporting on the bus
                    goto act_oper_err;
                }
                cout << " done." << endl;
                goto act_oper_ok;
act_oper_err:       // an error happened operating the service
                err.write(true);
                while (req.read() != false) wait();
                err.write(false);
                continue;

act_oper_ok:        // service went ok
                ack.write(true);    // request served
                // wait for peer assertion
                while (req.read() != false) wait();
                ack.write(false);   // terminate the operation
            }
        }
Ejemplo n.º 5
0
Archivo: main.cpp Proyecto: Yonka/sc
 void printer()
 {
     while (write_buf.nb_read(tmp_byte))
     {          
         if (port_is_ready)
         {
             out_port->write(tmp_byte);
             cout << this->basename() << " send " << tmp_byte << " at " <<sc_time_stamp() << "\n";
             port_is_ready = false;
         }
     }
     cout << '\n';
 }
Ejemplo n.º 6
0
    void msgin_monitor() {
        while (true) {
            message_t msg;
            msgin->read(msg);
            if (msg.cmd == RD && msg.addr == DMEM) {
                wait(1 + random() % 10, SC_NS);
                message_t daval(DataValid, NOADDR, msg.tag);
                msgout->write(daval);
            }
            else if (msg.cmd == DataValid) {}
            
            else
                throw std::invalid_argument("in memory.cpp: Invalid messages from SSA: " + msg.toString());

        }
    }
Ejemplo n.º 7
0
    void main()
    {
      const char *str =
	"Visit www.accellera.org and see what SystemC can do for you today!\n";
      const char *p = str;
      int total = 100000;

      while (true)
      {
	int i = 1 + int(19.0 * rand() / RAND_MAX);  //  1 <= i <= 19

	while (--i >= 0)
	{
          out->write(*p++);
	  if (!*p) p = str;
	  -- total;
	}

	if (total <= 0)
	  break;

	wait(1000, SC_NS);
      }
    }