iT邦幫忙

0

[SystemC] Hello SystemC! 寫一個簡單的 SystemC 程式

  • 分享至 

  • xImage
  •  

系列文章 : simulation / emulation 學習筆記

這裡來記錄一下,要怎麼運行一個 SystemC 的 hello world。

想要運行 SystemC 的程式的話,就必須先編譯 SystemC 的 library 才行。然後在編譯自己的 SystemC 程式的時候,需要把 library 也 link 進去。

這邊我一樣把繁瑣的 script 整合進 Makefile 裡面。

運行 SystemC 的 Hello World

git clone git@github.com:TommyWu-fdgkhdkgh/SystemC_example.git
cd SystemC_example/hello

# clone SystemC library 的 source code
# 並 checkout 到 2.3.4
make systemc/clone

# 編譯 SystemC library
# 並將 library 安裝到 systemc-install
make systemc/build

# 編譯 hello_world 範例
make hello/build

# 運行 hello_world 範例
make hello/run


        SystemC 2.3.4-Accellera --- Apr 23 2026 14:04:26
        Copyright (c) 1996-2022 by all Contributors,
        ALL RIGHTS RESERVED
Hello, World!

運行之後,假如一切都成功的話,我們可以看到

  • SystemC 的 copy write
  • 以及我們熟悉的 hello world!!

hello world 程式碼

SC_MODULE(HelloWorld) {

宣告一個 SystemC 的 module,有點像是 verilog 所使用的 module。
以 C++ 來說,就像是宣告一個叫做 HelloWorld 的 class。


SC_CTOR(HelloWorld) {
        SC_METHOD(say_hello);
    }

void say_hello() { std::cout << "Hello, World!" << std::endl; }

SC_CTOR 以 C++ 來說,就像是建構子一樣。
這邊的建構子會把 say_hello 當作是一個 SC_METHOD

SC_METHOD 對於 SystemC 來說,就像是組合邏輯 ( combinational logic )。就如同 Verilog 中的 combinational logic,代表這裡的行為會在單個 cycle 內,毫無延遲的完成。


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

就是一般 C++ 的 main function,程式的入口點。


HelloWorld hello("hello");

以 SystemC 來說,就是建立一個 HelloWorld 的 module。
以 C++ 來說,是建立一個 class HelloWorld 的 instance。


sc_start();

開始進行模擬。
想要模擬特定的時間的話,也可以像是 sc_start(10, SC_NS),這樣就會模擬 10 ns。


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言