본문 바로가기

SystemC Tutorial

Ch5. sc_export 사용하기

반응형

 

SystemC 2.1에서 부터 sc_export가 도입 되었다. sc_port와 뭔가 유사할 것 같은 느낌이 들지 않는가?

그렇다. sc_port는 sc_interface class를 매개로 하여 channel과 연결되고 이 channel은 또다른 sc_port와 연결 된다는 것을 배웠다. 즉 하나의 모듈에서 다른 모듈과 연결 되려면 반드시 channel을 통해야 한다. 하지만 sc_export를 사용하면 channel을 통할 필요 없이 직접 다른 모듈의 sc_port와 연결할 수 있다. 이것의 의미는 interface 구현 함수를 구현 하는channel을 module안으로 가져온다는 의미이다. 다시 말해 A라는 module과 B라는 모듈을 연결하기 위해 C라는 channel을 사용하는 경우 기존 sc_port를 이용할 때는

A[port]->C[channel]->B[port]

라는 형태로 구성 되는 반면 sc_export를 이용하면

A[port]->B[export[C]]

의 형태로 연결이 가능하다.

아래는 sc_export 사용 예제이다.

 

#include <systemc.h>

// Interface : 인터페이스 클래스. 가상 함수를 선언 해준다.
class my_if : virtual public sc_interface
{
public:
    virtual void display() = 0;
};

// Channel : 가상 함수를 실재 구현하는 채널 클래스
class my_channel : public my_if, public sc_channel
{
public:
    SC_CTOR(my_channel) { }
    virtual void display()
    {
        cout << sc_time_stamp() << " In my channel display() " << endl;
    }
};

// Module B: export channel my_interface through my_exp  : A module에서 sc_port를 통해서 바로 my_exp에 연결 할 수 있다.
SC_MODULE( B ) 
{
    sc_export<my_if> my_exp;

    SC_CTOR( B )
        : my_exp("my_exp"),   // explicit name
          my_c("my_channel")
    {                
         my_exp( my_c );     // bind sc_export->interface by name : my_if의 가상 함수가 구현된 채널을 연결해 준다.
    }
 private:
    my_channel my_c;            // channel
};

// Module A connected to the channels through B
SC_MODULE( A )
{
    sc_port<my_if> my_port;

    SC_CTOR(A) {
        SC_THREAD(run);
    }
    void run() {
        while (true) {
                wait(10, SC_NS);
                my_port->display();
        }
    }
};

int sc_main(int , char** ) {
  A my_A("A");
  B my_B("B");
  // port->export
  my_A.my_port( my_B.my_exp ); // port와 export의 직접 연결을 보여준다.
  sc_start(50, SC_NS);

  return 0;
}

 

execution result :

SystemC 2.3.0-ASI --- Jan  9 2014 21:05:00
        Copyright (c) 1996-2012 by all Contributors,
        ALL RIGHTS RESERVED

10 ns In my channel display()
20 ns In my channel display()
30 ns In my channel display()
40 ns In my channel display()


==========================================================

 

반응형