Thread and method_2010

663 views

Published on

SystemC : SC_MODULE Using SC_THREAD/SC_METHOD

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
663
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Thread and method_2010

  1. 1. SC_MODULE Using SC_THREAD/SC_METHOD 林敬倫, 蘇文鈺 成大資訊 2010/11
  2. 2. Implementing Modules • SC_MODULE(): – the smallest container of functionality with states, behavior and structure – It may contains • • • • • • • Ports Member channel instance Member data instance Member module instance Constructor Destructor Process member function
  3. 3. SystemC Processes • SC_THREAD: – – – – – similar to software thread It gains control from the system until it returns it to simulator. called only once and return can suspend itself using wait(). Blocked because of blocking operation such as read/write • Sc_method: – – – – – – Simpler and more efficient Run completely and return Cannot suspend internally Called by the simulation kernel repeatedly based on sensitivity. Similar to always@ in Verilog. Implied waits can be implemented by calling SystemC built-in blocking methods such as read and write of sc_fifo.
  4. 4. 2 Ways to Register and Initialize a Process • SC_CTOR: – C++ uses constructor before the process method. – In the constructor, the methods of implementing the process is defined. • SC_HAS_PROCESS: – It is a cpp macro. – It is usually used when one wants to place the constructor in the implementation. – Use arguments to specify the specifications of models. – If you are making an IP, this is the better way to do.
  5. 5. Jobs of SC_CTOR/SC_HAS_PROCESS • • • • • Initialization of its sub-modules Build connections among sub-modules Registering processes to simulation kernel Provide sensitivities Others
  6. 6. A Simple Example • Helloworld的範例程式. – 第一個用SC_CTOR – 第二個用SC_HAS_PROCESS, 這一個請將 constructor寫在.cpp裡面. • 其中包含兩個Module, 一個印Hello, 一個印 World. 前一支用sc_thread, 後一支用 sc_method. • 這是在講concurrency與channel時所使用的 簡單程式, 請參照之後的章節.
  7. 7. SC_CTOR example Main.cpp #include <systemc.h> #include "hello_module.h" #include "method.h" Hello_module.h #include <systemc.h> int sc_main(int argc, char* argv[]) SC_MODULE(hello_module) { { // signal declaration // signal declaration sc_clock clk("clk", 10, SC_NS, 0.5); sc_in_clk clk; // module declaration hello_module module0("hello_word"); method module1("method"); //Constructor SC_CTOR(hello_module) { SC_THREAD(thread_func); sensitive << clk.pos(); } // signal connection module0.clk(clk); module1.clk(clk); // run simulation sc_start(1000, SC_NS); return 0; } // fuction declaration void thread_func(); };
  8. 8. SC_CTOR example Hello_module.cpp #include "hello_module.h" void hello_module::thread_func() { while(1){ wait(); printf(" Word! n"); } } Method.cpp Method.h #include <systemc.h> SC_MODULE(method) { // signal declaration sc_in_clk clk; // fuction declaration void method_func(); //Constructor SC_CTOR(method) { SC_METHOD(method_func); sensitive << clk.pos(); } #include "method.h" void method::method_func() { if(clk){ sc_time_stamp().print(); printf(" Hello! "); } } };
  9. 9. SC_HAS_PROCESS example Main.cpp #include <systemc.h> #include "hello_module.h" #include "method.h" Hello_module.h #include <systemc.h> SC_MODULE(hello_module) int sc_main(int argc, char* argv[]) { { // signal declaration // signal declaration sc_in_clk clk; sc_clock clk("clk", 10, SC_NS, 0.5); // module declaration hello_module module0("hello_word"); method module1("method"); // signal connection module0.clk(clk); module1.clk(clk); // run simulation sc_start(1000, SC_NS); return 0; } // fuction declaration void thread_func(); //Constructor declaration hello_module(sc_module_name); };
  10. 10. SC_HAS_PROCESS example Hello_module.cpp #include "hello_module.h" Method.h #include <systemc.h> //Constructor hello_module::hello_module(sc_module_name nm) : sc_module(nm) { //using SC_HAS_PROCESS replace SC_CTOR SC_HAS_PROCESS(hello_module); SC_THREAD(thread_func); sensitive << clk.pos(); } SC_MODULE(method) { // signal declaration sc_in_clk clk; void hello_module::thread_func() { while(1){ wait(); printf(" Word! n"); } } }; // fuction declaration void method_func(); //Constructor declaration method(sc_module_name);
  11. 11. SC_HAS_PROCESS example Method.cpp #include "method.h" //Constructor method::method(sc_module_name nm) : sc_module(nm) { //using SC_HAS_PROCESS replace SC_CTOR SC_HAS_PROCESS(method); SC_METHOD(method_func); sensitive << clk.pos(); } void method::method_func() { if(clk){ sc_time_stamp().print(); printf(" Hello! "); } }
  12. 12. Summarized Template For System Design with SystemC • pseudo code of templates for: – Sc_main.cpp – Module.h – Module.cpp. • SC_CTOR; • SC_HAS_PROCESS.
  13. 13. Main.cpp #include <systemc.h> #include “module_name.h” int sc_main(){ Port/Signal declarations module declarations modules linked sc_start(); /sc_start(time); return 0; }
  14. 14. Module.h SC_CTOR #ifndef NAME_H #define NAME_H #include "submodule.h" SC_MODULE(NAME) { Port declarations Channel/submodule instances SC_CTOR(NAME) : Initializations { Connectivity Process registrations } Process declarations Helper declarations }; #endif SC_HAS_PROCESS #ifndef NAME_H #define NAME_H #include "submodule.h" SC_MODULE(NAME) { Port declarations Channel/submodule instances // Constructor declaration: NAME(); Process declarations Helper declarations }; #endif
  15. 15. Module.cpp SC_CTOR #include <systemc.h> #include "NAME.h" NAME::Process {implementations } NAME::Helper {implementations } SC_HAS_PROCESS #include <systemc.h> #include "NAME.h" NAME::NAME(sc_module_name nm) : sc_module(nm) , Initializations { Channel allocations Submodule allocations Connectivity SC_HAS_PROCESS(NAME); Process registrations } NAME::Process {implementations } NAME::Helper {implementations }

×