More Related Content Similar to SystemC Tutorial Similar to SystemC Tutorial (20) SystemC Tutorial10. Hello World
$> ./main
!
SystemC 2.3.0-ASI --- Jul 13 2012 06:33:43
Copyright (c) 1996-2012 by all Contributors,
ALL RIGHTS RESERVED
!
Hello World!!!
\(^o^)/
できた∼
25. SC_MODULE( hoge ) {
!
sc_in<int> in;
sc_out<int> out;
!
int x;
!
void process();
!
};
SC_CTOR( hoge )
{
SC_THREAD( process );
sensitive << in ;
x = 10;
}
void hoge::process() {
out = 0;
while(1) {
wait();
out = in * x;
}
};
26. SC_MODULE( hoge ) {
モジュール宣言
!
sc_in<int> in;
sc_out<int> out;
int x;
!
void process();
};
#define SC_MODULE(name) struct name : sc_module
※classで書く場合(sc_moduleを継承する)
!
!
※実装はマクロ(struct)
class hoge : public sc_module {
...
};
※Verilog HDL/SystemVerilogでの意味
module hoge(...);
:
endmodule
SC_CTOR( hoge )
{
SC_THREAD( process );
sensitive << in ;
x = 10;
}
27. SC_MODULE( hoge ) {
モジュール宣言
!
sc_in<int> in;
sc_out<int> out;
!
int x;
初期化処理を記述する部分
!
void process();
!
};
SC_CTOR( hoge )
コンストラクタ宣言
{
SC_THREAD( process );
sensitive << in ;
x = 10;
}
28. SC_MODULE( hoge ) {
※実装はマクロ
!
sc_in<int> in;
sc_out<int> out;
!
int x;
!
void process();
!
};
#define SC_CTOR(name) implementation-defined;
name(sc_module_name)
※マクロを使わずで書く場合
SC_MODULE( hoge ) {
必ず必要
...
SC_HAS_PROCESS(hoge);
hoge( sc_module_name n) : sc_module_name(n) {
SC_THREAD( processs );
...
SC_CTOR( hoge )
コンストラクタ宣言
{
SC_THREAD( process );
sensitive << in ;
※SystemVerilogだと new関数
class hoge;
x = 10;
function new();
}
:
endfunction
29. 豆知識:初期化リスト
※サブモジュールのインスタンス時など
SC_MODULE( hoge ) {
!
sc_in<int> in;
sc_out<int> out;
!
int x;
!
void process();
!
SC_CTOR( hoge )
{
SC_THREAD( process );
sensitive << in ;
x = 10;
}
};
書かないといけない場合もあります
書いておくと良いことあるかも!
SC_CTOR( hoge ):
in(“in”), out(“out”)
{
http:/
/lsifrontend.blog100.fc2.com/blog-entry-432.html
30. SC_MODULE( hoge ) {
!
sc_in<int> in;
sc_out<int> out;
!
int x;
!
void process();
!
};
SC_CTOR( hoge )
{
SC_THREAD( process );
プロセスを定義
sensitive << in ;
x = 10;
}
31. SC_MODULE( hoge ) {
!
sc_in<int> in;
sc_out<int> out;
!
int x;
!
void process();
!
};
実際の機能(処理)
void hoge::process() {
out = 0;
while(1) {
wait();
out = in * x;
}
};
SC_CTOR( hoge )
機能(処理)が記述されている関数
{
SC_THREAD( process );
プロセスを定義
sensitive << in ;
x = 10;
}
32. SC_MODULE( hoge ) {
!
sc_in<int> in;
sc_out<int> out;
!
int x;
!
引数無しの関数
void process();
!
};
void hoge::process() {
out = 0;
while(1) {
wait();
sensitiveに登録されている
動作待ち
out = in * x;
}
};
SC_CTOR( hoge )
{
SC_THREAD( process );
プロセスを定義
sensitive << in ;
x = 10;
機能(処理)が動くきっかけを指定
}
(この例だと in の値が変化したら)
33. プロセス定義は3種類
SC_THREAD
SC_THREAD( process );
sensitive << in ;
void hoge::process() {
...
初期動作
...
wait(); / wait - in(value)
/
...
Simulation
...
wait(); / wait - in(value)
/
...
wait(); / wait - in(value)
/
...
}
再度呼び出しなし
・関数から抜けると再度呼び出されないため
while文や for文で無限ループを作る
35. プロセス定義は3種類
SC_CTHREAD
SC_CTHREAD( process, clock.pos() );
reset_signal_is(reset, true);
void hoge::process() {
...
初期動作
...
...
while(1) {
wait(); / wait - prosedge clock
/
...
wait(); / wait - posedge clock
/
...
}
reset_signal_isで
設定されていれば強制的に
}
・SC_THREADをクロックイベント用にしたもの
・関数から抜けると再度呼び出されないため
while文や for文で無限ループを作る
36. プロセス定義は3種類
SC_THREAD
SC_METHOD
SC_THREAD( process );
sensitive << in ;
SC_METHOD( process );
sensitive << a << b ;
void hoge::process() {
...
初期動作
...
wait(); / wait - in(value)
/
...
Simulation
...
wait(); / wait - in(value)
/
...
wait(); / wait - in(value)
/
...
}
再度呼び出しなし
void hoge::process() {
wait - a,b(value)
...
...
...
...
...
}
!
!
!
初期動作 Simulation
終了まで繰り返す
SC_CTHREAD
SC_CTHREAD( process, clock.pos() );
reset_signal_is(reset, true);
void hoge::process() {
...
初期動作
...
...
while(1) {
wait(); / wait - prosedge clock
/
...
wait(); / wait - posedge clock
/
...
}
reset_signal_isで
設定されていれば強制的に
}
初期動作は dont_initialize();で抑制可能
例)SC_THREAD( process );
sensitive << in ;
dont_initialize();
39. SC_MODULE( hoge ) {
!
sc_in<int> in;
入出力ポート(Interface)宣言
sc_out<int> out;
※SystemVerilogでの意味
!
int x;
!
void process();
!
};
module hoge(
input bit[31:0] in,
output bit[31:0] out
);
:
endmodule
SC_CTOR( hoge )
{
SC_THREAD( process );
sensitive << in ;
x = 10;
}
40. SC_MODULE( hoge ) {
!
sc_in<int> in;
sc_out<int> out;
!
int x;
!
void process();
!
};
SC_CTOR( hoge )
{
SC_THREAD( process );
sensitive << in ;
out.initialize(0);
っと書くことも可能
}
void hoge::process() {
out = 0;
while(1) {
wait();
out = in * x;
}
};
このように動いてます。
out.write(0);
while(1) {
wait();
out.write( in.read() * x);
}
42. チャネルはレジスタ(FF)
#include <systemc.h>
!
int sc_main(int argc, char *argv[]) {
int a;
sc_signal<int> b;
!
a = 10; b = 10;
std::cout << "a = " << a << ", b = " << b << std::endl;
!
sc_start(1, sc_core::SC_NS);
std::cout << "a = " << a << ", b = " << b << std::endl;
!
return 0;
}
実行結果
a = 10, b = 0
a = 10, b = 10
シミュレーション時刻の経過により値が更新される。
(代入はノンブロッキング代入)
44. SC_MODULE( hoge ) {
!
sc_in<int> in;
sc_out<int> out;
!
データ型
int x;
!
void process();
!
};
SC_CTOR( hoge )
{
SC_THREAD( process );
sensitive << in ;
x = 10;
}
45. SC_MODULE( hoge ) {
!
sc_in<int> in;
sc_out<int> out;
!
データ型
int x;
SystemCはC++なので、
!
void process();
C++のデータ型は全て使えます。
SC_CTOR( hoge )
!
{
};
}
SC_THREAD( process );
sensitive << in ;
x = 10;
50. sc_mainは必須
#include <systemc.h>
s_in = 0;
sc_start(10, SC_NS);
int sc_main(int argc, char *argv[]) { cout << "in = " << s_in
<< ", out = " << s_out << endl;
sc_signal<int> s_in, s_out;
hoge m_hoge(“m_hoge”);
s_in = 10;
m_hoge.in(s_in);
sc_start(10, SC_NS);
m_hoge.out(s_out);
cout << "in = " << s_in
<< ", out = " << s_out << endl;
return 0;
}
51. モジュールをインスタンス
#include <systemc.h>
s_in = 0;
sc_start(10, SC_NS);
cout << "in = " << s_in
<< ", out = " << s_out << endl;
int sc_main(int argc, char *argv[]) {
sc_signal<int> s_in, s_out;
hoge m_hoge(“m_hoge”);
m_hoge.in(s_in);
m_hoge.out(s_out);
※別の書き方
hoge *m_hoge;
m_hoge = new hoge(“m_hoge”);
m_hoge->in(s_in);
m_hoge->out(s_out);
}
s_in = 10;
sc_start(10, SC_NS);
cout << "in = " << s_in
<< ", out = " << s_out << endl;
return 0;
52. 信号を生成
#include <systemc.h>
s_in = 0;
sc_start(10, SC_NS);
cout << "in = " << s_in
<< ", out = " << s_out << endl;
int sc_main(int argc, char *argv[]) {
※sc_in/outの接続は sc_signal
sc_signal<int> s_in, s_out;
※sc_startでシミュレーション開始
hoge m_hoge(“m_hoge”);
m_hoge.in(s_in);
m_hoge.out(s_out);
}
s_in = 10;
sc_start(10, SC_NS);
cout << "in = " << s_in
<< ", out = " << s_out << endl;
return 0;
53. 変数の値を表示する
■cout
sc_signal - << operator
sc_intなど- a.to_string()関数が存在
s_in = 0;
■printf
sc_start(10, SC_NS);
sc_intなど- a.to_int()関数が存在
cout << "in = " << s_in
<< ", out = " << s_out << endl;
■sc_report
SystemC定義の表示形式関数
s_in = 10;
sc_start(10, SC_NS);
!
cout << "in = " << s_in
★ sc_time_stamp() で
<< ", out = " << s_out << endl;
時刻も表示!
return 0;
}
54. タイミング波形を取得
#include <systemc.h>
s_in = 0;
sc_start(10, SC_NS);
cout << "in = " << s_in
<< ", out = " << s_out << endl;
int sc_main(int argc, char *argv[]) {
sc_signal<int> s_in, s_out;
sc_trace_file *tf;
s_in = 10;
tf = sc_create_vcd_trace_file("waves"); sc_start(10, SC_NS);
sc_trace(tf, s_in, "in");
sc_trace(tf, s_out, "out");
hoge m_hoge(“m_hoge”);
m_hoge.in(s_in);
m_hoge.out(s_out);
cout << "in = " << s_in
<< ", out = " << s_out << endl;
sc_close_vcd_trace_file(tf);
return 0;
※閉じることを忘れずに
}