RecoSim  1.0
 All Classes Files Functions Variables Enumerations
TB_Stream_OUT.h
Go to the documentation of this file.
1 
11 #include "user_parameters.h"
12 #ifndef TB_STREAM_OUT_TESTBENCH_FILE_H
13 #define TB_STREAM_OUT_TESTBENCH_FILE_H
14 
15 /*****************************************************************************/
16 /************************** BEGIN USER SPACE ********************************/
17 
18 /*******************/
19 /* Input TestBench */
20 template<int Ni>
21 void TB_Stream_OUT(Testbench_in_interface<Ni> &tb_interface) {
22 
23  /* Default Behavior */
24 
25  // Verify data 'on-the-fly'
26  int nb_transactions_received = 0;
27  int nb_diff = 0;
28  int last_transaction_count[Ni];
29  for(int i = 0; i < Ni; i++) last_transaction_count[i] = 0;
30 
31  while(nb_transactions_received != NB_TRANSACTIONS_TO_SEND * Ni) {
32 
33  /* Time out right before end of simulation */
34  sc_time timeout(Reconfiguration_manager::getMaximumSimulationTime() - sc_time_stamp() - sc_time(1, SC_US));
35  wait(timeout, tb_interface.TB_IF_transaction_received_event());
36 
37 
38 
39  if(sc_time_stamp() == Reconfiguration_manager::getMaximumSimulationTime() - sc_time(1, SC_US)) {
40  /* Reached end of simulation due to timeout, something is wrong with the testbench */
41  cout << "CRITICAL WARNING: End of simulation reached but testbench thread is still waiting for transactions..." << endl;
42  cout << "Testbench name: " << tb_interface.TB_IF_name();
43  cout << "Consider revising:" << endl;
44  cout << " - Testbench to wait for less transactions" << endl;
45  cout << " - Module algorithms to send data more often" << endl;
46  return;
47  }
48  else {
49  /* Event(s) received */
50  for(int i = 0; i < Ni; i++) {
51  if(tb_interface.TB_IF_get_nb_transactions_received_per_socket(i) != last_transaction_count[i]) {
52  // Data received on this socket
53  // Check data
54  int *data_ptr = tb_interface.TB_IF_get_data_in_ptr(i);
55  for(int j = 0; j < 16; j++) {
56  if(data_ptr[j] != ((last_transaction_count[i] << 16) | j)) {
57  nb_diff++;
58  cout << "Socket " << i << ", Transaction " << last_transaction_count[i] << ", Data " << j << " -> " << hex << data_ptr[j] << " (expected " << ((last_transaction_count[i] << 16) | j) << ")" << endl;
59  }
60  }
61 
62  // Update transaction count
63  last_transaction_count[i]++;
64 
65  break;
66  }
67  }
68 
69  nb_transactions_received++;
70  }
71 
72 
73  }
74 
75  if(nb_diff == 0) {
76  Simulation_controller::get_logfile() << endl << "==================================================" << endl;
77  Simulation_controller::get_logfile() << " CONGRATULATIONS: Simulation ended successfully " << endl;
78  Simulation_controller::get_logfile() << "==================================================" << endl << endl;
79 
80  // Communicate with the simulation controller
81  tb_interface.TB_IF_notify_simulation_controller(true);
82  } else {
83  Simulation_controller::get_logfile() << endl << "==================================================" << endl;
84  Simulation_controller::get_logfile() << " Simulation failed with " << dec << nb_diff << " errors " << endl;
85  Simulation_controller::get_logfile() << "==================================================" << endl << endl;
86 
87  exit(RECOSIM_TESTBENCH_CHECK_FAILED);
88  }
89 }
90 
91 /************************** END USER SPACE ********************************/
92 /***************************************************************************/
93 
94 #endif
virtual const sc_event & TB_IF_transaction_received_event(void) const =0
Get the event launched when a transaction has been received.
Definition: testbench_in_interface.h:31
virtual void TB_IF_notify_simulation_controller(bool success)=0
Notifies simulation controller about success/failure of the simulation (e.g. data corruption)...
virtual const int TB_IF_get_nb_transactions_received_per_socket(int socketID) const =0
Get the number of transactions processed per socket.
virtual int * TB_IF_get_data_in_ptr(int socketID) const =0
Get incoming data pointer.
virtual const char * TB_IF_name(void) const =0
Get testbench full name.