Track 3: ESL and SystemC
The Definitive Guide to SystemC:
The SystemC Language
David C Black, Doulos
Track 3: The Definitive Guide to SystemC
The SystemC Language
Introduction to SystemC
Core Concepts and Syntax
Bus Modeling
Master and slave interfaces
Blocking versus non-blocking
Multiports
Odds and Ends
57
Example Bus Model
Multiple bus masters (modules), shared bus (channel), multiple slaves (channels)
Bus arbitration and memory mapping built into the bus
source0 proc1
Master Master Interfaces
Required
Bus master interface
Provided
clock
Bus
Required
Bus slave interface
Provided
ram0 ram1
Slave Slave
58
Master Interface Definition
source0 proc1
Master Master
id = 0 id = 1
clock
Bus
class master_if : virtual public sc_interface
{
public:
virtual void write(sc_uint<8> address, sc_uint<12> data,
int id) = 0;
virtual void read (sc_uint<8> address, sc_uint<12> &data,
int id) = 0;
};
59
Slave Interface Definition
clock
Bus
ram0 ram1
Slave Slave
class slave_if : virtual public sc_interface
{
public:
virtual void slave_write(sc_uint<8> address, sc_uint<12> data) = 0;
virtual void slave_read (sc_uint<8> address, sc_uint<12> &data) = 0;
virtual void get_map(unsigned int &start, unsigned int &size) = 0;
};
Memory map managed within bus channel 60
60
Master Write and Read
Array of flags
source0 proc1
Master Master request[0] bool
id = 0 id = 1
request[1] bool
Array of events
clock proceed[0] sc_event
Bus
proceed[1] sc_event
Runs in the context of the caller
void Bus::write(sc_uint<8> address, sc_uint<12> data, int id)
{
request[id] = true; // request access to the bus
wait(proceed[id]); // wait for permission
request[id] = false; // clear the flag
slave_port[find_port(address)]->slave_write(address, data);
}
61
61
Blocking and Non-blocking Calls
An Interface Method Call runs in the context of the caller Important!
ASI terminology:
A blocking method may call wait
A blocking method must be called from a thread process
A non-blocking method must not call wait
A non-blocking method may be called from a thread or method process
Naming convention nb_*
62
Bus Controller Process
void Bus::control_bus()
{
int highest;
for (;;)
{
wait(clock->posedge_event());
// Pick out a master that's made a request
highest = -1;
for (int i = 0; i < n_masters; i++)
if (request[i])
highest = i;
// Notify the master with the highest id
if (highest > -1)
proceed[highest].notify();
}
}
63