2010年3月21日 星期日

Eclipse + SystemC + Cygwin

SystemC Download http://www.systemc.org/downloads/standards/ Cygwin http://www.cygwin.com/ Eclipse CDT http://www.eclipse.org/cdt/ 解壓縮後,在資料夾內有個configure檔. 我是沒有預設路徑,所以直接做configure的動作. 如果你要預設路徑在某個folder下. 就打 ./configure --prefix="xx/xx" % ./configure 會產生個 lib -cygwin的資料夾. 進入lib -cygwin % cp libsystemc.a 到 cygwin/bin 底下. 再來就開啟Eclipse CDT. Creat new project,就好. Path中還要帶入include 的 SysyemC Header 進入Examples folder -> sysc -> fir, 先用這個當作sample PS: Fir 為濾波器的響應會在有限的取樣時間內衰減,對於有限的輸入,其輸出響應必為有限,因此可視為是輸入值的加權平均,故又可稱為移動平均(Moving Average)濾波器,簡稱MA 濾波器. fir.h 中 , 會定義 Interface => In/Out Port length 內部的Register 跟 Trigger的方式( posedge clk)/(cthread) 用在approximation time
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();
};
}

執行結果.

1 則留言:

  1. 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

    回覆刪除