The Definitive Guide To Systemc: The Systemc Language
The Definitive Guide To Systemc: The Systemc Language
Introduction to SystemC
Overview and background
Central concepts
The SystemC World
Use cases and benefits
2
What is SystemC?
Communicating
processes
3
Features of SystemC
Modules (structure)
Ports (structure)
Processes (computation, concurrency)
Channels (communication)
Interfaces (communication refinement)
Events (time, scheduling, synchronization)
Data types (hardware, fixed point)
Port Interface
Module Module
Process
Channel Process
4
Modules and Channels
Module Module
Architecture of SystemC
User Applications
SystemC
Other Model
Verification TLM Library
Libraries
Library SCV
Primitive Channels
(signal, buffer, fifo, mutex, semaphore)
Core Language
(module, port, process, Data Types
channel, interface, event)
C++ Language
6
Typical Use Case: Virtual Platform
Multiple software stacks
Software Software
Bridge
TLM-2.0
Memory Custom
I/O RAM DMA D/A
interface peripheral
Introduction to SystemC
Core Concepts and Syntax
Data
Modules and connectivity
Processes & Events
Channels and Interfaces
Ports
Bus Modeling
Odds and Ends
14
SystemC Data Types
In namespace sc_dt::
15
17
19
Modules
Module
Module Module
Channel
Ports
Instances
- connection
Channels
Processes
of other
- communication
-to
modules
computation
external
- hierarchy
channels
20
SC_MODULE
#include "systemc.h"
Class SC_MODULE(Mult)
{
sc_in<int> a;
Ports sc_in<int> b;
sc_out<int> f;
void action() { f = a * b; }
Constructor SC_CTOR(Mult)
{
SC_METHOD(action); Process
sensitive << a << b;
}
};
21
SC_MODULE or sc_module?
Equivalent SC_MODULE(Name)
: {
...
};
22
Separate Header File
// mult.h
#include "systemc.h"
// mult.cpp
SC_MODULE(Mult)
#include "mult.h"
{
sc_in<int> a; void Mult::action()
sc_in<int> b; {
f = a * b;
sc_out<int> f; }
void action();
SC_CTOR(Mult)
{
SC_METHOD(action);
Define constructor in .cpp?
sensitive << a << b;
Yes - explained later
}
};
23
Top
testclk
asig
fsig
Mult
Stim Mon
bsig f=a*b
25
Top Level Module
#include "systemc.h"
#include "stim.h"
Header files #include "mult.h"
#include "mon.h"
SC_MODULE(Top)
{
Stim stim1;
Modules Mult uut;
Mon mon1;
...
}
26
Module Instantiation
SC_MODULE(Top)
{
sc_signal<int> asig, bsig, fsig;
sc_clock testclk;
Stim stim1;
Mult uut;
Mon mon1;
Name of data member
SC_CTOR(Top)
: testclk("testclk", 10, SC_NS),
stim1("stim1"),
uut ("uut"),
mon1 ("mon1")
{
...
} String name of instance (constructor argument)
}
27
Port Binding
SC_CTOR(Top)
: testclk("testclk", 10, SC_NS),
stim1("stim1"),
uut("uut"),
mon1("mon1")
{
stim1.a(asig);
stim1.b(bsig);
stim1.clk(testclk);
uut.a(asig);
uut.b(bsig);
uut.f(fsig); Alternative function
mon1.a.bind(asig);
mon1.b.bind(bsig);
mon1.f.bind(fsig);
mon1.clk.bind(testclk);
}
sc_main
#include "systemc.h"
#include "top.h"
Called from main()
int sc_main(int argc, char* argv[])
{
return 0;
}
29
Namespaces
SC_MODULE(Mod)
{
sc_in<bool> clk;
sc_out<int> out;
Summary of Files
systemc.h
#include
top.h
main.cpp
32
Compilation and Simulation
C++ Development
.cpp
SystemC Pre-compiled Environment
.h User's
class libraries headers? Text Editor source
.cpp files
.h
Compiler
Makefile
Linker make
Pre-compiled
library
Executable
prompt> make
prompt> run.x
Debugger
prompt> ddd run.x
33
Kinds of Process
Processes
Must be within a module (not in a function)
A module may contain many processes
34
SC_METHOD Example
SC_THREAD Example
#include "systemc.h"
class Counter: public sc_module
{
public:
sc_in<bool> clock, reset;
sc_out<int> q;
Constructor arguments
Counter(sc_module_name _nm, int _mod)
: sc_module(_nm), count(0) , modulus(_mod)
{
SC_HAS_PROCESS(Counter);
Needed if there's a process
SC_METHOD(do_count);
and not using SC_CTOR
sensitive << clock.pos();
}
private:
void do_count();
int count;
int const modulus;
};
37
Dynamic Sensitivity
SC_CTOR(Module)
{
SC_THREAD(thread);
sensitive << a << b; Static sensitivity list
}
void thread()
{
for (;;)
{
wait(); Wait for event on a or b
...
wait(10, SC_NS); Wait for 10ns
... ignore a or b
wait(e); Wait for event e
...
}
}
38
sc_event and Synchronization
SC_MODULE(Test)
{ Shared variable
int data;
sc_event e;
SC_CTOR(Test)
{ Primitive synchronization object
SC_THREAD(producer);
SC_THREAD(consumer);
}
void producer()
{
wait(1, SC_NS);
for (data = 0; data < 10; data++) {
e.notify();
wait(1, SC_NS); Schedule event immediately
}
}
void consumer()
{ Resume when event occurs
for (;;) {
wait(e);
cout << "Received " << data << endl;
}
}
};
39
sc_time
Simulation time is a 64-bit unsigned integer
Time resolution is programmable - must be power of 10 x fs
Resolution can be set once only, before use and before simulation
Default time resolution is 1 ps
40
sc_clock
sc_time sc_time
0 12 16 22 26 32
Elaboration sc_start()
before_end_of_elaboration()
end_of_elaboration()
start_of_simulation()
sc_stop()
Done
end_of_simulation()
44
Overriding the Callbacks
SC_MODULE(Test)
Called for each {
SC_CTOR(Test) {}
Module
void before_end_of_elaboration(){...}
Primitive channel void end_of_elaboration() {...}
void start_of_simulation() {...}
Port void end_of_simulation() {...}
};
Export
Do nothing by default
45
Advance time
Primitive channels
Implement one or more interfaces
Derived from sc_prim_channel
Have access to the update phase of the scheduler
Examples - sc_signal, sc_signal_resolved, sc_fifo
Hierarchical channels
Implement one or more interfaces
Derived from sc_module
Can instantiate ports, processes and modules
47
48
Interface Method Call
Channel Process
Process
49
Important
#include "systemc"
class queue_if : virtual public sc_core::sc_interface
{
public:
virtual void write(char c) = 0;
virtual char read() = 0;
};
50
Queue Channel Implementation
#include "queue_if.h"
class Queue : public queue_if, public sc_core::sc_object
{
public:
Queue(char* nm, int _sz)
: sc_core::sc_object(nm), sz(_sz)
{ data = new char[sz]; w = r = n = 0; }
private:
char* data;
int sz, w, r, n;
};
51
Understanding Ports
Port Required interface Provided interface
Module
Channel
Process
void do_writes();
SC_CTOR(Producer)
{
SC_THREAD(do_writes);
}
};
queue_write_if queue_read_if
Producer Consumer
Channel
53
#include <systemc>
#include "producer.h"
using namespace sc_core;
void Producer::do_writes()
{
std::string txt = "Hallo World.";
for (int i = 0; i < txt.size(); i++)
{
wait(SC_ZERO_TIME);
out->write(txt[i]);
}
}
54
Why Ports?
Producer Consumer
Channel
55
Exports
Module
Port Export Export Port
Producer Consumer
write() read()
Queue
Channel
Producer Consumer
write() read()
Queue
56