30 cci::cci_param<std::string> p_read_file;
31 cci::cci_param<std::string> p_write_file;
32 cci::cci_param<unsigned int> p_baudrate;
35 FILE* r_file =
nullptr;
36 FILE* w_file =
nullptr;
42 sc_core::sc_event update_event;
50 : sc_core::sc_module(name)
51 , p_read_file(
"read_file",
"",
"read file path")
52 , p_write_file(
"write_file",
"",
"write file path")
53 , p_baudrate(
"baudrate", 0,
"number of bytes per second")
54 , socket(
"biflow_socket")
58 if (p_write_file.get_value().empty() && p_read_file.get_value().empty()) {
59 SCP_ERR(()) <<
"At least one of read_file or write_file must be specified.\n";
67 void start_of_simulation()
69 if (!p_read_file.get_value().empty()) {
70 r_file =
fopen(p_read_file.get_value().c_str(),
"r");
72 if (r_file ==
NULL)
SCP_ERR(()) <<
"Error opening the input file " << p_read_file.get_value() <<
".\n";
73 update_event.notify(sc_core::SC_ZERO_TIME);
76 if (!p_write_file.get_value().empty()) {
77 w_file =
fopen(p_write_file.get_value().c_str(),
"w");
79 if (w_file ==
NULL)
SCP_ERR(()) <<
"Error opening the output file " << p_write_file.get_value() <<
".\n";
84 void end_of_elaboration() {}
88 if (p_baudrate.get_value() == 0)
91 delay = (1.0 / p_baudrate.get_value());
93 while (
fread(&
c,
sizeof(
char), 1, r_file) == 1) {
95 sc_core::wait(delay, sc_core::SC_SEC);
102 void writefn(tlm::tlm_generic_payload& txn, sc_core::sc_time&
t)
104 uint8_t* data = txn.get_data_ptr();
105 for (
int i = 0;
i < txn.get_streaming_width();
i++) {
108 SCP_ERR(()) <<
"Error writing to the file.\n";
116 if (w_file !=
NULL) {
120 if (r_file !=
NULL) {
void register_b_transport(MODULE *mod, void(MODULE::*cb)(tlm::tlm_generic_payload &, sc_core::sc_time &))
Register b_transport to be called whenever data is received from the socket.
Definition biflow-socket.h:226