⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fifo_fir.cpp

📁 Kluwer.Academic.Pub.Systemc.From.The.Ground.Up-此全书的范例程式。
💻 CPP
字号:
//BEGIN fifo_fir.cpp//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//See fifo_fir.h for more information//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#include "fifo_fir.h"#include <fstream>#include <iomanip>#include <cmath>extern unsigned errors;using std::cout;using std::cerr;using std::fixed;using std::setw;using std::setfill;using std::setprecision;using std::endl;//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Constructor//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~fifo_fir::fifo_fir(sc_module_name _name, char* _cfg_filename) :  sc_module(_name),  m_cfg_filename(_cfg_filename),  m_taps(0),  m_tap(0),  orig_in(32),  data_in(32),  data_out(32){  SC_THREAD(stimulus_thread);  SC_THREAD(sc_fifo_ex_thread);  SC_THREAD(results_thread);  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // Read coefficients from configuration file and initialize pipe to zero  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ifstream cfg_file(m_cfg_filename);  if (!cfg_file) {    cerr << "ERROR: Problem opening " << m_cfg_filename << " for input." << endl;    errors++;    return;  }//endif  cfg_file >> m_taps;  if (m_taps < 1) {    cerr << "ERROR: Number of taps must be greater than zero!" << endl;    errors++;    return;  }//endif  // Allocate memory  m_pipe  = new double[m_taps];  m_coeff = new double[m_taps];  for (unsigned tap=0;tap!=m_taps;tap++) {    if (cfg_file.eof()) {      cerr << "ERROR: Too few coefficients when reading [" << tap << "]." << endl;      errors++;      return;    }//endif    cfg_file >> m_coeff[tap];    m_pipe[tap] = 0;  }//endfor}//end fifo_fir()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Processes//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~void fifo_fir::stimulus_thread(void) {  unsigned PTS=20;  for (unsigned t=0;t<PTS;t++) {    double data = 0.0;    if (t==10) data = 1.0; // impulse    orig_in.write(data);    data_in.write(data);  }//endfor  wait(SC_ZERO_TIME);}//end stimulus_thread()void fifo_fir::sc_fifo_ex_thread(void) {  for(;;) {    unsigned coeff = m_tap; // used to index coeffiecients    // read next piece of data    double data = data_in.read();    m_pipe[m_tap++] = data;    if (m_tap == m_taps) m_tap = 0; // wrap    double result = 0;    for (unsigned tap=0;tap!=m_taps;tap++,coeff++) {      if (coeff == m_taps) coeff = 0; // wrap      result += m_coeff[coeff] * m_pipe[tap];    }//endfor    data_out.write(result);  }//endforever}//end sc_fifo_ex_thread()void fifo_fir::results_thread(void) {  for(unsigned i=0;;i++) {    double data =  orig_in.read();    double result =  data_out.read();    cout << "DATA: "         << "["  << setw(2) << i << "]"          << "= " << setw(9) << fixed << setprecision(5) << data         << " "  << setw(9) << fixed << setprecision(5) << result         << endl;  }//endforever}//end results_thread()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//END $Id: fifo_fir.cpp,v 1.2 2004/02/02 12:36:18 dcblack Exp $

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -