2013-07-17 6 views
1

4 개의 NAND 게이트 바인딩에서 systemc에 xor 게이트를 만듭니다. 모듈이 N 비트의 벡터를 받길 원합니다. 여기서 N은 매개 변수로 전달됩니다. 나는 &이 아닌 비트 연산 (낸드 게이트의 경우)을 수행 할 수 있어야합니다.수신 된 매개 변수를 사용하여 systemc의 벡터 길이를 설정합니다.

가장 좋은 방법은 sc_bv_base 유형을 사용하고있을 수 있습니다,하지만 난 생성자에서 초기화하는 방법을 모르겠어요.

이 문제를 해결하는 데 도움이 되었으면합니다.

답변

2

모듈을 매개 변수화하는 방법은 모듈에 대한 새로운 C++ 템플릿을 만드는 것입니다. 'sc_module 구조체 my_xor'i.s.o.을 사용하는 본 예에서 는 입력 벡터의 폭은 그 모듈이

#ifndef MY_XOR_H_ 
#define MY_XOR_H_ 

#include <systemc.h>  

template<int depth> 
struct my_xor: sc_module { 
    sc_in<bool > clk; 
    sc_in<sc_uint<depth> > din; 
    sc_out<bool > dout; 

    void p1() {               
     dout.write(xor_reduce(din.read())); 
    } 

    SC_CTOR(my_xor) { 
     SC_METHOD(p1); 
     sensitive << clk.pos(); 
    } 

}; 
#endif /* MY_XOR_H_ */ 

참고 인스턴스화의 레벨로 설정 될 수있다 'SC_MODULE'매크로. (IEEE Std 1666-2011의 40, 5.2.5 SC_MODULE 참조).

다음과 같은 테스트 벤치와이를 테스트 할 수 있습니다 : 나는 '구조체'가 아닌 클래스를 사용하고

//------------------------------------------------------------------ 
// Simple Testbench for xor file 
//------------------------------------------------------------------ 

#include <systemc.h> 
#include "my_xor.h" 

int sc_main(int argc, char* argv[]) { 

    const int WIDTH = 8; 

    sc_signal<sc_uint<WIDTH> > din; 
    sc_signal<bool> dout; 

    sc_clock clk("clk", 10, SC_NS, 0.5); // Create a clock signal 

    my_xor<WIDTH> DUT("my_xor");   // Instantiate Device Under Test 

    DUT.din(din);       // Connect ports 
    DUT.dout(dout); 
    DUT.clk(clk); 

    sc_trace_file *fp;     // Create VCD file 
    fp = sc_create_vcd_trace_file("wave");  // open(fp), create wave.vcd file 
    fp->set_time_unit(100, SC_PS);  // set tracing resolution to ns 
    sc_trace(fp, clk, "clk");    // Add signals to trace file 
    sc_trace(fp, din, "din"); 
    sc_trace(fp, dout, "dout"); 

    sc_start(31, SC_NS);    // Run simulation 
    din = 0x00; 
    sc_start(31, SC_NS);    // Run simulation 
    din = 0x01; 
    sc_start(31, SC_NS);    // Run simulation 
    din = 0xFF; 
    sc_start(31, SC_NS);    // Run simulation 

    sc_close_vcd_trace_file(fp);  // close(fp) 

    return 0; 
} 

참고. '수업'도 가능합니다.

class my_xor: public sc_module{ 
public: 

이 코드의 XOR은 'xor_reduce'입니다. IEEE Std 1666-2011에서 자세한 내용을 확인할 수 있습니다. 197 (7.2.8 감속 연산자)를 참조하십시오. 그러나 나는 이것이 당신이 갖고 싶어하는 해결책이 아니라고 생각합니다.