Documente Academic
Documente Profesional
Documente Cultură
Zhonghai Lu
KTH Royal Institute of Technology
C++ Basics
SystemC
Introduction
and Get
Started
Modules
and
Processes
Concurrency
and Time
Channels
and
Interfaces
Transaction
Level
Modeling
SystemC
Data Types
and
Debugging
SystemC
Summary
Aim
Content
Concept
for communication
Channel categories
Primitive channels
Hierarchical channels
An example
CPU
ASIC
Abstract Bus
MEM
Arbiter
I/O
Primitive
channels
Examples
sc_signal<>, sc_signal_resolved<>
sc_buffer<>
sc_fifo<>
sc_mutex, sc_semaphore
To
Primitive channel
Event
Port
sc_signal<T>
sc_buffer<T>
change in value
write()
sc_fifo<T>
write() or read()
sc_fifo_in, sc_fifo_out
sc_mutex
sc_semaphore
Primitive channel
Event
Port
sc_signal<T>
sc_buffer<T>
change in value
write()
sc_fifo<T>
write() or read()
sc_fifo_in, sc_fifo_out
sc_mutex
sc_semaphore
sc_fifo
Template class
Interface methods
sc_fifo<T> fifo(fifo, 5)
10
SC_MODULE (Producer) {
sc_fifo_out<int> fifo_out;
.
fifo_out.write(data);
.
};
Top
SC_MODULE (Consumer) {
sc_fifo_in<int> fifo_in;
.
fifo_in.read(data);
Specialized port
.
};
. operator
sc_fifo
Producer
Consumer
SC_MODULE (Top) {
Producer p;
Consumer c;
sc_fifo<int> fifo;
SC_CTOR(Top): p(p), c(c), fifo(fifo,5){
p.fifo_out(fifo);
c.fifo_in(fifo);
.
};
KTH IL2452 System Design Languages
Step1:
11
Example: Queue
class queue_write_if : virtual public sc_interface {
public: virtual void write (int c) = 0;};
class queue_read_if : virtual public sc_interface {
public: virtual int read () = 0;};
class queue_if : public queue_write_if, public queue_read_if { };
KTH IL2452 System Design Languages
12
#include queue_if.h
private:
int* data;
int size, w, r, n;
};
13
Class sc_object is
the base class for
all objects in the
module hierarchy.
sc_module
+kind
get_child_objects
w: write pointer
r: read pointer
n: number of data
in the queue
sc_object
+name
+kind
get_child_objects
get_parent_objects
sc_prim_channel
+kind
sc_port_base
sc_process*
+kind
+kind
+get_child_objects
14
#include queue_if.h
void Queue :: write(int c) {
if (n < size) {
n++;
data[w++] = c;
if (w == size) w = 0;
}
};
int Queue::read(){
int c = 0;
if (n > 0) {
n--;
c = data[r++];
if (r == size) r = 0;
}
return c;
}
15
We
write a module to
test the functionality
of the channel.
16
Interface type
The max. number of channels to which the port may be bound
(0 means no limit, default is 1).
Port binding policy (optional) with respect to unbounded ports.
sc_port<my_interface, N, policy> if1, if2, ;
17
Process
channel
sc_port<sif> port;
port->method();
Inherit sc_module if
hierarchical channel
The port is declared with interface sif, so a process may call the method method()
through the port.
Note that the port is typed using the name of the interface, not the channel. Thus, any
channel that implements the interface sif may be bound to the port.
KTH IL2452 System Design Languages
18
queue_write_if queue_read_if
Top
Producer
Consumer
queue
SC_MODULE(Producer){
public:
sc_port<queue_write_if> out;
void write_chan();
SC_CTOR(Producer){
SC_THREAD(write_chan); }
};
Top
Producer
Consumer
out
queue
SC_MODULE(Top){
Queue queue;
Producer producer;
Consumer consumer;
SC_CTROR(Top):queue(queue, 5){
producer.out(queue);
consumer.in(queue);
}
in
Channel instance
Module instance
};
KTH IL2452 System Design Languages
20
Besides
21
Different
22
1.
2.
3.
4.
23
Define
24
The
#ifndef STACK.H
#define STACK.H
#include <systemc>
#include stack.h
class stack : pubic sc_module, public stack_read_if, stack_write_if {
private:
char data[100];
int top; //top of the stack
public:
stack(sc_module_nm nm) : sc_module(nm), top(0){ }
bool nb_write(char c) {
if (top<100) { data[top++] = c; return true;}
return false; }
void reset(){ top = 0;}
bool nb_read(char& c){
if (top > 0) { c = data[--top]; return true;}
return false;}
};
#endif
KTH IL2452 System Design Languages
25
#ifndef PRODUCER.H
#define PRODUCER.H
#include <systemc>
#include stack_if.h
class producer : pubic sc_module {
public:
sc_port<stack_write_if> out; //declare a port that interfaces to the stack
sc_in<bool> clock;
void write_stack(){
int i=0; char* TestString=Hello world;
while true {
wait(); //wait for clock edge
if (out->nb_write(TestString[i]) //write to the stack via the port calling nb_write() method
cout << Write stack << TestString[i] << at << sc_time_stamp() <<endl;
i=(i+1)%32;}}
SC_CTOR(producer){
SC_THREAD(write_stack);
sensitive << clock.pos(); }
#endif
KTH IL2452 System Design Languages
26
#include systemc.h
#include producer.h
#include consumer.h
#include stack.h
int sc_main(int argc, char* argv[]){
sc_clock ClkFast(ClkFast, 100, SC_NS);
sc_clock ClkSlow(ClkSlow, 50, SC_NS);
stack Stack1(Stack 1);
producer P1(Producer 1);
P1.out(Stack1);
P1.clock(ClkFast);
consumer C1(Consumer 1);
C1.in(Stack1);
C1.clock(ClkSlow);
sc_start(5000, SC_NS);
return 0;
}
Processes
27
28
Interfaces
Channels
Ports
Abstract class
Channels
Homework:
Try the example of creating own channel Queue.
KTH IL2452 System Design Languages
29
TLM
30
www.systemc.org,
www.accelera.org
www.doulos.com
SystemC:
31