- CPU 是以 clock cycle 為單位,每一小段時間做一點事
start
SystemC 進入 sc_main 執行之後,會執行指定的程式,但並不會開始模擬。
這時候,需要有個開頭
sc_core::sc_start();
wait
執行的過程中,要讓系統知道這件事需要做多久。
所以要用 wait 在這邊等一下,才會讓時間前進!
wait(delay);
thread
在 SystemC 的 module 並不會知道我們要它做什麼,
這時候需要先用 SC_HAS_PROCESS 指定 SC_CURRENT_USER_MODULE,
再用 SC_THREAD 註冊要執行的 function 之後,才能讓 SystemC 系統知道這邊有事要做。
HELLO(sc_module_name name) : sc_module(name){ SC_HAS_PROCESS(HELLO);<-----------------------SC_THREAD(hello_thread);<-----------------------
}
實際程式碼
這次每一個 delay 過後都會輸出一個字元
//main.cpp #include <vector> #include "systemc.h" class HELLO : public sc_module{ public:HELLO(sc_module_name name) : sc_module(name){SC_HAS_PROCESS(HELLO);SC_THREAD(hello_thread);} private: std::vector<char> dataMemory{'H', 'e', 'l', 'l', 'o', ',', ' ', 'S', 'y', 's', 't', 'e', 'm', 'C', '!'}; voidhello_thread(void) { for(int i = 0; i<dataMemory.size()*2; i++) { step();wait(delay);} } void step() { std::cout << "time " << sc_core::sc_time_stamp() << ":" << dataMemory[pc % dataMemory.size()] << std::endl; pc++; } sc_core::sc_time delay = sc_core::sc_time(1, sc_core::SC_NS); uint32_t pc = 0; }; intsc_main(int argc,char** argv){HELLOhello("hello"); sc_core::sc_start(); return 0; }
沒有留言:
張貼留言