Jump to content
ruwan2

How to read a text file as input data?

Recommended Posts

Hi,

 

I want to simulate a FIR filter, which reads a text file content as input data. I have tried with open a text file and call a function (entry) as a parameter, but it fails compilation. Because I cannot paste the code on this window, I attach the text .h file in the attachment. Please tell me how to access a text file in a method. Or you can tell me what is the best way to read text data file into the SystemC simulator.

 

 

Thanks,

stimulus.zip

Share this post


Link to post
Share on other sites

Hi,

I get a little progress. Before the read function, I want to implement a write text file (a log file) first.

I want to close the file when a counter reaches the maximum number in module A. When the counter reaches the maximum number, it issues an sc_evnt. This sc_event will notify a method B. Is it possible first?

 

Now, I do not know how to trigger the method B. I only have an example of the clock.pos() as event:

 

SC_METHOD(exitfile);

sensitive << clk. pos();

 

 

But, "sensitive << fileclose.pos();" does not work to substitute the second line. I have check the manual without finding how to notify a method example.

 

Thanks,

Share this post


Link to post
Share on other sites

Hi,

 

I want to simulate a FIR filter, which reads a text file content as input data. I have tried with open a text file and call a function (entry) as a parameter, but it fails compilation. Because I cannot paste the code on this window, I attach the text .h file in the attachment. Please tell me how to access a text file in a method. Or you can tell me what is the best way to read text data file into the SystemC simulator.

 

 

Thanks,

Hello,

Have you considered the option of piped reads and writes,

from stdin, stdout ? This works, and is very convenient for

quick, easy testing.

Share this post


Link to post
Share on other sites

There are several things wrong with the code you provided and perhaps indicate a serious lack of appropriate C++ background:

#include <iostream>
#include <fstream>
using namespace std;

SC_MODULE(stimulus) {

  sc_out<bool> reset;
  sc_out<bool> input_valid;   
  sc_out<int>  sample;  	    
  sc_in<bool>  CLK;

  sc_int<8>     send_value1;
  unsigned cycle;
  ofstream myfile;

  SC_CTOR(stimulus)
  {
      myfile.open ("example.txt");
      myfile << "Writing this to a file.\n";
      SC_METHOD(entry(ofstream));
      dont_initialize();
      sensitive << CLK.pos();
      send_value1 = 0;
      cycle       = 0;
      myfile.close();
  }  
  void entry(ofstream);
};
  1. You should check for success after opening a file
  2. If your process method requires an argument, you cannot use SC_METHOD to register it.
  3. It is unclear why you need ofstream as an argument to the entry() method.
  4. It is unclear what you are using the file for, and why you would write it inside the constructor.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...