130 likes | 146 Vues
Chapter 5. SystemC 1.0. Main Purpose Model RTL Instruments Support diverse data type Execute concurrently by using METHOD s. SystemC 2.0. High-level modeling Communication and synchronization channel interface event. Event.
E N D
SystemC 1.0 • Main Purpose • Model RTL • Instruments • Support diverse data type • Execute concurrently by using METHODs
SystemC 2.0 • High-level modeling • Communication and synchronization • channel • interface • event
Event • Notify – An event can be notified by calling the (non-const) notify() method my_event.notify(); // notify immediately my_event.notify( SC_ZERO_TIME ); // notify next delta cycle my_event.notify( 10, SC_NS ); // notify in 10 ns sc_time t( 10, SC_NS ); my_event.notify( t ); // same • Wait for an event While(true) { Blah blah… Wait (my_event) }
Channel • Contain functionality for communication • Implements one or more interfaces • May not be necessarily a point-to-point connection
Interface • Abstract template • provides a set of method declarations, but provides no method implementations and no data fields • Define how to access the channels • A port that is connected to a channel through an interface sees only those channel methods that are defined by the interface.
Simple FIFO Example • Interface declaration • Inherit from sc_interface • Have not implemntation 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; };
Simple FIFO Example (cont.) • Channel Implementation for write interface 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(); } … … }
Simple FIFO Example (cont.) • Channel Implementation class fifo : public sc_channel, public write_if, public read_if { public: … void read(char &c){ if (num_elements == 0) wait(write_event); c = data[first]; -- num_elements; first = (first + 1) % max; read_event.notify(); } void reset() { num_elements = first = 0; } … }
Simple FIFO Example (cont.) • Module Usage for producer class producer : public sc_module { public: sc_port<write_if> out; … void main() { const char *str = "Visit www.systemc.org and see what SystemC can do for you today!\n"; while (*str) out->write(*str++); } };
Simple FIFO Example (cont.) • Module Usage For Consumer sc_port<read_if> in; void main() { char c; cout << endl << endl; while (true) { in->read(c); cout << c << flush; if (in->num_available() == 1) //cout << "<1>" << flush; cout << "<1>" << endl; if (in->num_available() == 9) //cout << "<9>" << flush; cout << "<9>" << endl; } }
Native Channel of SystemC • sc_signal<T> • sc_fifo<T> • sc_mutux<T> • sc_semaphore<t>
Reference • Function Specification for Systemc 2.0 • src/comminication/