SystemC_4-1.ppt
Download
Report
Transcript SystemC_4-1.ppt
Reactivity, Ports, and Signals
in SystemC
Part of
HW/SW Codesign of Embedded
Systems Course (CE 40-226)
Winter-Spring 2001
Codesign of Embedded Systems
1
Today programme
Concept of Reactivity
Reactivity facilities in SystemC
Ports and Signals in SystemC
Resolved Logic Vectors
Winter-Spring 2001
Codesign of Embedded Systems
2
Reactivity, Ports, and Signals
in SystemC
Reactivity Modeling
in
SystemC
Winter-Spring 2001
Codesign of Embedded Systems
3
Concept of Reactivity
Property of Reaction to external events
Inherent in HW => There MUST be some way to
model it in any HDL
Many SW or HW-SW systems are reactive as well:
Any control systems (Chemical process control, ABS, …)
Client-Server systems (Database Engines, …)
Winter-Spring 2001
Codesign of Embedded Systems
4
Concept of Reactivity (cont’d)
Things to consider
Events to react to
Type of event (Clock edge, Signal change, some
condition on signals or ports, …)
Style of reaction
Waiting style
Suspend process until an event comes or some condition
holds (i.e. Blocking wait)
Watching style
Winter-Spring 2001
Do not suspend. But always WATCH if some condition
holds. Then, react accordingly: e.g. Jump to a certain
routine, or point of a routine. (Non-blocking wait)
Codesign of Embedded Systems
5
Reactivity Facilities
in SystemC
Events to react to
Sensitivity lists in SC_METHOD, SC_THREAD. And
clock edge in SC_CTHREAD.
Sensitivity to any event on a signal: sensitive data
member of SC_MODULE
Sensitivity to positive edge of a signal: sensitive_pos
data member of SC_MODULE
Sensitivity to negative edge of a signal: sensitive_neg
data member of SC_MODULE
Special case of infinite loop processes
(SC_THREAD, SC_CTHREAD)
Loop re-initialization, Wait for Signal condition
Winter-Spring 2001
Codesign of Embedded Systems
6
Reactivity Facilities
in SystemC (cont’d)
Style of reaction
Waiting style
wait()
wait_until(<signal condition>)
Both SC_THREAD and SC_CTHREAD
Only SC_CTHREAD
Watching style
Global watching: Always done. Cannot be disabled.
Local watching: Done in certain parts of a process. Can
be disabled and re-enabled (statically)
Winter-Spring 2001
Codesign of Embedded Systems
7
Global Watching Example
SC_MODULE(data_gen) {
sc_in_clk clk;
sc_inout<int> data;
sc_in<bool> reset;
void gen_data();
SC_CTOR(data_gen){
SC_CTHREAD(gen_data,
clk.pos());
watching(reset.delayed());
}
};
Winter-Spring 2001
void gen_data() {
if (reset == true)
data = 0;
}
while (true) {
data = data +
wait();
data = data +
wait();
data = data +
wait();
}
}
Codesign of Embedded Systems
{
1;
2;
4;
8
Global Watching in General
void data_gen::gen_data () {
// variable declarations
// watching code
if (reset == true) {
data = 0;
}
// infinite loop
while (true) {
// Normal process function
}
}
Winter-Spring 2001
Codesign of Embedded Systems
9
Local Watching in General
W_BEGIN
// put the watching declarations here
watching(...);
watching(...);
W_DO
// This is where the process functionality goes
...
W_ESCAPE
// This is where the handlers for the watched events
// go
if (..) {
…
}
W_END
Winter-Spring 2001
Codesign of Embedded Systems
10
Local Watching Example
void bus::xfer() {
while (true) {
// wait for a new address to
// appear
wait_until(
newaddr.delayed() == true);
// got a new address so
//process it
taddr = addr;
datardy = false;
// cannot accept new address
// now
data8 = taddr.range(7,0);
start = true; // new addr
// for memory controller
wait();
// wait 1 clock between data
// transfers
Winter-Spring 2001
data8 = taddr.range(15,8);
start = false;
wait();
data8 = taddr.range(23,16);
wait();
data8 = taddr.range(31,24);
wait();
// now wait for ready signal
// from memory
// controller
wait_until(ready.delayed()
== true);
W_BEGIN
watching(reset.delayed());
// Active value of reset
// will trigger watching
Codesign of Embedded Systems
11
Local Watching Example
(cont’d)
W_DO
// the rest of this block is
// as before
// now transfer memory data
// to databus
tdata.range(7,0) =
data8.read();
wait();
tdata.range(15,8) =
data8.read();
wait();
tdata.range(23,16) =
data8.read();
wait();
tdata.range(31,24) =
data8.read();
data = tdata;
Winter-Spring 2001
datardy = true; // data is
// ready, new addresses ok
W_ESCAPE
if (reset) {
datardy = false;
}
W_END
}
}
Codesign of Embedded Systems
12
HW Design Using
SystemC
Ports and Signals
Winter-Spring 2001
Codesign of Embedded Systems
13
Ports and Signals Outline
Port and Signal Usage
Port Declaration
Signal Declaration
Valid Interconnections
Special Objects: Clocks
Winter-Spring 2001
Codesign of Embedded Systems
14
Port and Signal Usage
Port
Module’s Interface to external world
Signal
Connect Modules’ ports together
Convey values between ports (and hence modules)
Module1
Winter-Spring 2001
Signal
Module2
Codesign of Embedded Systems
15
Port Declaration
Things to declare
Port Mode
Port Type
Port Name
Declaration Syntax
Port_mode<Port_type> Port_name [, Port name, …];
Winter-Spring 2001
Codesign of Embedded Systems
16
Port Declaration
Things to declare
Port Mode
Input:
sc_in
Output:
sc_out
Bi-directional(inout): sc_inout
Winter-Spring 2001
Codesign of Embedded Systems
17
Port Declaration
Things to declare
Port Mode
Input:
sc_in
Output:
sc_out
Bi-directional(inout): sc_inout
Port type
C++ built-in type, SystemC types, and User defined types
Scalar, and Array ports
Special case: Resolved Logic Vector
Winter-Spring 2001
Codesign of Embedded Systems
18
Port Declaration
Things to declare
Port Mode and Type
Port Type
Input:
sc_in
Output:
sc_out
Bi-directional(inout): sc_inout
C++ built-in type, SystemC types, and User defined types
Scalar, and Array ports
Special case: Resolved Logic Vector
Port Name
Any valid C++ identifier
Winter-Spring 2001
Codesign of Embedded Systems
19
Port Types
C++ built-in types
M1
long, int, char, short, float, double
SystemC types
sc_int<n>, sc_uint<n>, sc_bigint<n>, sc_biguint<n>, sc_bit,
sc_logic, sc_bv<n>, sc_lv<n>, sc_fixed, sc_ufixed, sc_fix,
sc_ufix
User defined types
sc_in<int> i
Scalar Types
struct, class, typedef, enum
Array types
Declares an array of ports
sc_in<int> i[10]
Each port must be individually
bound, assigned, read, and written
Winter-Spring 2001
Codesign of Embedded Systems
M1
20
Port Types (cont’d)
Special case: Resolved Logic Vectors
Usage
Multi-driver ports (e.g. Buses)
Resolution function:
z and 0 0
z and 1 1
0 and 1 x
x and (1 or 0 or x or z) x
Declaration syntax
sc_in_rv<n> port_name [, port_name, …];
sc_out_rv<n> port_name [, port_name, …];
sc_inout_rv<n> port_name [, port_name, …];
Winter-Spring 2001
Codesign of Embedded Systems
21
Signal Declaration
Things to declare
Signal type
Signal name
The same as port types
Special case: Resolved vector signals
Any valid C++ identifier
Declaration syntax
sc_signal<signal_type> sig_name [, sig_name, …];
Winter-Spring 2001
Codesign of Embedded Systems
22
Signal Types
The same as port types
Scalar
Array Signals
Special Case: Resolved Logic Vectors
Declaration syntax
sc_signal_rv<n> sig_name [,sig_name, …];
Winter-Spring 2001
Codesign of Embedded Systems
23
Valid Interconnections
Signals required
M1
M2
Higher-Level Module
Undocumented:
Exceptions at least
include:
positional mapping
M1
Direct Connection
No Signal required
Winter-Spring 2001
Codesign of Embedded Systems
24
Valid Interconnections (cont’d)
Port reading and writing
Reading a port = taking value of the signal bound
to the port
Writing a port = writing new value to the signal
bound to the port, but AFTER the writing process
has exited or been suspended
Signal binding
Each port to a single signal
Repetitive bindings of a port FIRST binding will remain
effective
Winter-Spring 2001
Codesign of Embedded Systems
25
Special Objects: Clocks
Clocks generate timing signals to synchronize
simulation events
No clock-signal is declared
Instead, and sc_clock object is instantiated
Declaration syntax
sc_clock clk_name(“clk_name”, clk_period=1,
clk_duty_cycle=0.5,
first_edge_time=0,
first_edge_type=true);
Winter-Spring 2001
Codesign of Embedded Systems
26
Special Objects: Clocks
(cont’d)
Multiple clocks are allowed
Different frequencies
Different phase relations
Declaration point
Typically generated at top-level module and
passed down to lower-level modules
The clock object or its signal (i.e.
clock_object.signal() ) can be passed down
SC_CTHREAD modules need the clock object itself
sc_in_clk clk_object_name;
Winter-Spring 2001
Codesign of Embedded Systems
27
Special Objects: Clocks
(cont’d)
sc_clock clock("Clock", 20, 0.2, 3, false);
Winter-Spring 2001
Codesign of Embedded Systems
28
What we learned today
Reactivity
Concept
SystemC facilities to model reactivity
wait, wait_until
global watching, local watching
Ports, Signals, and Clocks in SystemC
Winter-Spring 2001
Codesign of Embedded Systems
29
Complementary notes:
Assignments and Project
Today is due date for Assignment 5
Take Assignment 6
Due date: Sat. Ordibehesht 15th
Today is due date for Page-of-References of
your project
Winter-Spring 2001
Codesign of Embedded Systems
30
Complementary notes:
Extra classes
“HW Synthesis Techniques Seminar” by S. Safari
Date-Time: TODAY, 13 O’clock
Place: Kwarizmi Hall, CE Dept.
Winter-Spring 2001
Codesign of Embedded Systems
31