SystemC Presentation 2
SystemC Presentation 2
Part II
Suryaprasad
Florida Atlantic University
Presentation Outline
Structural Modelization
Modules
Channels
Ports
Interfaces
Module
A
Block I
Block
C
Module
top
Block B
Block
D
Block
A
Block
B
Module
B
Block I
Block
E
Block B
Block
F
Process,Threads
sc_module
Ports
sc_port
Channels
sc_channel
Interfaces
sc_interface
4
Module Anatomy
SC_MODULE(my_module) {
/* Port Instances
*/
/* Channel Instances */
/* Module Instances
*/
*/
SC_CTOR(my_module)
{
CONSTRUCTOR
/* Module Netlist
*/
/* Process Registration */
}
/* All allowed C++ constructs */
};
Graphical Notations
a Module
a Port
an Interface
Primitive channel
Binding of an abstract
Interface to a Port
Block 1
channel
Block 2
Communication Modeling
Producer/Consumer Example
PORTS
CHANNEL
Consumer
INTERFACE
MODULES
Producer/Consumer - Example
MODULES
TOP
Producer
Consumer
Producer/Consumer Example
TOP Module
class TOP : public sc_module
public:
fifo *fifo_inst;
producer *prod_inst;
consumer *cons_inst;
Producer/Consumer Example
Producer Module
class producer : public sc_module {
public:
sc_port<write_if> out; //Producer has a port with write interface
SC_HAS_PROCESS(producer);
producer(sc_module_name name) : sc_module(name)
{
Constructor
SC_THREAD(main_action);
}
void main_action()
{
const char *str =
Hello How are you! see what SystemC can do for you today!\n";
while (*str)
out->write(*str++);
}
};
10
Producer/Consumer Example
Consumer Module
class consumer : public sc_module {
public:
sc_port<read_if> in; // Consumer has a port with read interface
SC_HAS_PROCESS(consumer);
consumer(sc_module_name name) : sc_module(name)
{
Constructor
SC_THREAD(main_action);
}
void main_action( ) {
char c;
while (true)
{
in->read(c);
cout << c << flush;
if (in->num_available() == 1) cout << "<1>" << flush;
if (in->num_available() == 9) cout << "<9>" << flush;
} /*End of While loop */
}/*End of main_action */
};
11
Producer/Consumer Example
Channel
class fifo : public sc_channel, public write_if, public read_if
{
public:
fifo(sc_module_name name) : sc_channel(name), num_elements(0), first(0)
{
}
void write(char c) {
if (num_elements == max)
wait(read_event);
data[(first + num_elements) % max] = c;
++ num_elements;
write_event.notify();
Definition/Implementa
tion of WRITE
interface
}
12
Producer/Consumer Example
Channel
Definition/Impl
ementation of
READ
interface
private:
enum e { max = 10 };
char data[max];
int num_elements, first;
sc_event write_event,
read_event;
};
13
Interface
class write_if : virtual public sc_interface
{
public:
virtual void write(char) = 0;
virtual void reset() = 0;
};
class read_if : virtual public sc_interface
{
public:
virtual void read(char &) = 0;
virtual int num_available() = 0;
};
14
Output Snapshot
15
Interfaces
16
Interfaces
my_module
in_out_port
read(T &)
write(T,U)
write_if
my_interface.h
17
Channels
channel
Block2
PORTS
19
PORTS
PORTS
Port Binding:
Named Form: Order doesnt matter
ADDER adder1(adder1);
A
adder1.a(in1);
adder1.b(in2);
B
adder1.sum(sum);
adder1.c(carry_out);
ADDER
SC_MODULE(ADDER)
{
Sum
sc_in<sc_bit> a;
sc_in<sc_bit> b;
sc_out<sc_bit> c;
sc_out<sc_bit> sum;
};
21
PORTS
ADDER
SC_MODULE(ADDER)
{
Sum
sc_in<sc_bit> a;
sc_in<sc_bit> b;
sc_out<sc_bit> c;
sc_out<sc_bit> sum;
};
22
Modules
SC_MODULE(Producer) { };
Class Producer: public sc_module {
};
23
Modules
Module Instantiation
25
SC_CTOR(top) {
s1 = new smodule1(s1") ;
s1->sport1(sig1) ;
}
}
top.h
SC_MODULE(top) {
smodule1 s1 ;
SC_CTOR(top) :
s1(s1){
Initialize s1 member
s1.sport1(sig1) ;
}
}
26
Processes
SC_METHOD
SC_THREAD
SC_CTHREAD
27
SC_METHOD
void
void my_method1()
my_method1() ;;
SC_CTOR(my_module)
SC_CTOR(my_module)
{{
SC_METHOD(my_method1);
SC_METHOD(my_method1);
sensitive
sensitive <<
<< my_port1;
my_port1;
}}
void my_module::my_method1() {
// Code of my_method1
} ;
28
SC_THREAD
void my_module::my_thread2() {
// Initialization of my_thread2
SC_CTOR(my_module)
SC_CTOR(my_module)
{{
while (true) {
SC_THREAD(my_thread1);
SC_THREAD(my_thread1);
SC_THREAD(my_thread2);
SC_THREAD(my_thread2);
sensitive
sensitive <<
<< my_port1;
my_port1;
}}
// Code of my_thread2
wait();
}
} ;
SC_CTHREAD
void
void my_cthread1()
my_cthread1() ;;
void my_module::my_cthread1() {
// Initialization of my_cthread1
SC_CTOR(my_module)
SC_CTOR(my_module)
{{
while (true) {
// Code of my_cthread1
SC_CTHREAD(my_cthread1,clk.pos());
SC_CTHREAD(my_cthread1,clk.pos());
wait();
}}
}
} ;
SC_METHOD
SC_THREAD
SC_CTHREAD
SC_CTOR(<module_name>)
SC_CTOR(<module_name>)
wait();
Sensitive only to
a clock
Can be suspended
And reactivated
wait();
{{
SC_METHOD(<sc_method_name>)
SC_METHOD(<sc_method_name>)
sensitive
sensitive <<
<< <port1>
<port1> <<
<< <port2>
<port2> ;;
SC_THREAD(<sc_thread_name>);
SC_THREAD(<sc_thread_name>);
SC_THREAD(<sc_thread_name>);
SC_THREAD(<sc_thread_name>);
sensitive
sensitive <<
<< <port1>
<port1> <<
<< <port2>
<port2> ;;
SC_CTHREAD(<sc_cthread_name>,<clk_name>.pos());
SC_CTHREAD(<sc_cthread_name>,<clk_name>.pos());
}}
31
THANK YOU
32