SC_MODULE(fir) { sc_in; reset; sc_in<bool> input_valid; sc_in<int> sample; sc_out<bool> output_data_ready; sc_out<int> result; sc_in_clk CLK; sc_int<9> coefs[16]; SC_CTOR(fir) { SC_CTHREAD(entry, CLK.pos()); reset_signal_is(reset,true); #include "fir_const.h" } void entry(); };在 fir.cpp中, 會定義這個Black Box的動作,底下是16個tap的Fir. hw 的架構大概如此, 底下是5個tap 的FIR
Pic Ref: http://commons.wikimedia.org/wiki/File:Fir_filter_df1.png
這邊會用wait()去模擬HW的Delay.
void fir::entry() { sc_int<8> sample_tmp; sc_int<17> pro; sc_int<19> acc; sc_int<8> shift[16]; // reset watching /* this would be an unrolled loop */ for (int i=0; i<=15; i++) shift[i] = 0; result.write(0); output_data_ready.write(false); wait(); // main functionality while(1) { output_data_ready.write(false); do { wait(); } while ( !(input_valid == true) ); sample_tmp = sample.read(); acc = sample_tmp*coefs[0]; for(int i=14; i>=0; i--) { /* this would be an unrolled loop */ pro = shift[i]*coefs[i+1]; acc += pro; }; for(int i=14; i>=0; i--) { /* this would be an unrolled loop */ shift[i+1] = shift[i]; }; shift[0] = sample_tmp; // write output values result.write((int)acc); output_data_ready.write(true); wait(); }; }
執行結果.

If using SystemC version 2.2.0, and make errors out with the following:
回覆刪除../../../../src/sysc/utils/sc_utils_ids.cpp: In function int 'sc_core::initialize()':
../../../../src/sysc/utils/sc_utils_ids.cpp:110: error: 'getenv' is not a member of std
../../../../src/sysc/utils/sc_utils_ids.cpp:111: error: 'strcmp' was not declared in this scope
Then change the includes in the file systemc-2.2.0/src/sysc/utils/sc_utils_ids.cpp to look like the following:
#include
#include
#include "sysc/utils/sc_report.h"
using namespace std;
and re-run make. Hopefully this will be addressed in the next release of SystemC:
# make
When make has completed, continue with:
# make install
# make check (optional)
Add export SYSTEMC=/path/to/systemc-x.x.x to ~/.bashrc