Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 01/13/2014 in all areas

  1. 1 point
    ips

    Lose data by sc_fifo

    Hi everyone, I'm met some problem. In box below you can see my code. struct Some_stuct { int data; float data_f; }; class payload_t { public: unsigned char *data; unsigned lenght; inline friend ostream& operator << ( ostream& os, payload_t const & v ) { os << "(" << v.data << "," << std::boolalpha << "," << v.lenght << ")"; return os; } }; SC_MODULE(tx) { sc_port<sc_fifo_out_if<payload_t> > out_port; void process() { Some_stuct data; payload_t out_data; while(true) { data.data = 5; data.data_f = 6; out_data.data = reinterpret_cast<unsigned char*>(&data); out_data.lenght = sizeof(Some_stuct); out_port->write(out_data); data.data++; data.data_f++; wait(1, SC_NS); } } SC_CTOR(tx) { SC_THREAD(process); } }; SC_MODULE(rx) { sc_port<sc_fifo_in_if<payload_t> > in_port; void process() { int realData = 0; payload_t in_data; while(true) { wait(in_port->data_written_event()); wait(171, SC_NS); in_data = in_port->read(); Some_stuct *val = reinterpret_cast<Some_stuct*>(in_data.data); cout << sc_time_stamp() << " " << val->data << " " << val->data_f << endl; } } SC_CTOR(rx) { SC_THREAD(process); } }; int sc_main(int argc, char* argv[]) { rx rx_i("rx"); tx tx_i("tx"); sc_fifo<payload_t> buf(8); tx_i.out_port(buf); rx_i.in_port(buf); sc_start(); getchar(); return 0; } I'm have two blocks: transmitter and receiver. When we call method write to fifo from transmitter, actually we will send address of our local data. And when i will read from buffer, I will receive address of transmitter local data. But if transmitter works more faster than receiver, my rx block will receive "New" data and sended data will loss. How to solve this problem? I should receive correct data
×
×
  • Create New...