<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>SCLive</title>
	<atom:link href="http://sclive.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sclive.wordpress.com</link>
	<description>A Linux Live Distribution for SystemC</description>
	<pubDate>Fri, 18 Jan 2008 18:18:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SystemC Tutorial: interfaces and channels</title>
		<link>http://sclive.wordpress.com/2008/01/11/systemc-tutorial-interfaces-and-channels-2/</link>
		<comments>http://sclive.wordpress.com/2008/01/11/systemc-tutorial-interfaces-and-channels-2/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 12:22:23 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[SytemC Tutorials]]></category>

		<guid isPermaLink="false">http://sclive.wordpress.com/2008/01/11/systemc-tutorial-interfaces-and-channels-2/</guid>
		<description><![CDATA[
Forewords
Inheritance and multiple inheritances are a pivotal part of interfaces and channels building. Channels in SystemC can be viewed as, a sophisticated form of communication mechanism; Akin to signals or wires in found in other HDLs. However what differentiates SystemC from common HDLs is the ability given to the designer to handcraft his own channels. [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><title></title></p>
<h3 class="western"><font size="4">Forewords</font></h3>
<p class="western">Inheritance and multiple inheritances are a pivotal part of interfaces and channels building. Channels in SystemC can be viewed as, a sophisticated form of communication mechanism; Akin to signals or wires in found in other HDLs. However what differentiates SystemC from common HDLs is the ability given to the designer to handcraft his own channels. Furthermore, the use of interfaces enables the separation of the modules’ implementation from the communication scheme used in between modules; This is an essential part of system level modeling.<br />
In this section we will examine the existing predefined SystemC channels as well as look at the creation of user defined primitive and hierarchical channels.</p>
<h3 class="western"><font size="4">Inheritance and SystemC channels/ Interface loose coupling</font></h3>
<p class="western">For the creation of channels, SystemC borrows from C++ a convenient principle called: “the class interface”. This principle is also known as abstract base classes and is used to define a common interface for related derived classes.<br />
Sometimes in C++, designers want to create a class that will define a set of access methods that should be used by all the classes that will be derived from it; however this class in itself will never be used to create objects. This type of classes is an abstract base class. In SystemC, abstract base classes are used to define all the access methods that a channel should have. Consequently, a channel will be a C++ class derived from an abstract base class and will implement the access methods defined inside its abstract base parent class.</p>
<p class="western">An abstract base class is created in C++ through the definition of one or more pure virtual methods as part of that class. A pure virtual method by definition is a method that will only be implemented inside a derived class from the abstract base class. The semantics for the declaration of a C++ pure virtual method is as follows:</p>
<pre>virtual &lt;return_type&gt; function_name (args&gt;)=0;</pre>
<p class="western">For instance the following line of code declares a method called bustWrite that takes three input arguments and returns an integer type:</p>
<pre>virtual void burstWrite( int destAddress, int numBytes, sc_lv&lt;8&gt; *data ) = 0;</pre>
<p class="western">The keyword ‘virtual’ and the ‘=0’ are the essential parts of this declaration as they indicate to the compiler that ‘burstWrite’ is a pure virtual method and therefore, that the class containing this declaration can never be made into an object.</p>
<p class="western">Once one or a number of abstract base classes (interfaces) have been designed, channels can be implemented by simply inheriting one or more of the base classes and implementing their virtual methods.</p>
<p class="western">Following the creation of channel, instances of that channel can be made as any other C++ object.</p>
<p class="western">&nbsp;</p>
<h3 class="western"><font size="4">Primitive Channels</font></h3>
<p class="western">The SystemC language extension distinguishes between two kinds of channel’s implementation: Primitive channels and non-primitive ones also referred as ‘hierarchical’ channels. Primitive channel as their name imply, have restrictions in regards to their construction. Firstly, any primitive channel is derived from both, its associated interfaces and the predefined SystemC class: sc_prim_channel. In addition, a primitive channel is not allowed to contain SystemC structures for instance threads, methods, other channels et caetera. However, although primitive channel appear limited, they uniquely support the SystemC defined ‘request_update()’ and ‘update()’ access methods.</p>
<p class="western" style="text-indent:1.27cm;">&nbsp;</p>
<p class="western">The SystemC library defines a number of versatile primitive channels namely: sc_buffer&lt;T&gt;, sc_fifo&lt;T&gt;, sc_mutex, sc_semaphore, sc_signal&lt;T&gt;, sc_signal_resolved, sc_signal_rv&lt;W&gt;. Those channels can be used individually or can be combined as part of a ‘non-primitive’ channel to create more complex communication mechanisms. These channels can be declared as follows:</p>
<pre>// A 32×16 bits elements fifo
sc_fifo&lt;sc_lv&lt;16&gt; &gt; inputFifo(32);
// A 16 bits bus
sc_signal&lt;sc_lv&lt;16&gt; &gt; dataBus;
// A 4 tokens semaphore
sc_semaphore gateKeeper(4); </pre>
<p class="western">The predefined SystemC primitive channels rely on a number of access methods to allow users to examine or alter their internal state. As previously highlighted, those methods are defined inside the channel’s interface. For channels used to hold values, the read() and write() methods are provided. Most predefined channels also support the common methods: print(), dump(), trace()and kind(). The print(), dump() and trace() methods are used to display the internal values of a given primitive channel either using the output stream or a trace file in the case of the trace() method. The purpose of the kind() method is used to identify the current primitive channel by providing it’s kind as a string information.</p>
<p class="western">Along with access and display methods, most primitive channels support queries of events. These methods may be used for two purposes: examining if a specific channel has currently had an event as part of an expression; such as an ‘if’ statement or supply information related to the activity/events of a channel as part of a sensitivity list of a SystemC process. The following examples illustrate the different method available for specific channels.</p>
<pre>// A non blocking write on an sc_signal
dataBus.write(”1010111101010101″);
// A blocking write on a variable of type sc_lv
sc_lv&lt;16&gt; busVar = dataBus.read();
while ( inputFifo.num_free() != 0 )
// A blocking write on an sc_fifo
inputFifo.write(dataBus.read());
// A blocking access to an sc_semaphore
gateKeeper.wait();
// A non blocking access to an sc_semaphore
if ( gateKeeper.trywait() != 0 )
cout &lt;&lt; “Got a lock !” &lt;&lt; endl;</pre>
<p class="western">Although SystemC provides us with numerous pre-defined channels, it is also possible to create user defined channels. As mentioned previously, the creation of a channel is achieved through multiple-inheritance. As a rule, a channel inherits from one or more interfaces as well as from either the sc_prim_channel or the sc_channel SystemC class. Sophisticated relationship between channels can be created by multiple inheritances from various interfaces. The following example describes the creation of a simplified version of the SystemC’s semaphore primitive channel.</p>
<pre>
class simple_semaphore_if : virtual public sc_interface {  // Line 1
public:
   // the classical operations: wait(), trywait(),
   // and post(), lock (take) the semaphore,
   // block if not available
   virtual int wait() = 0; // Line 7

   // lock (take) the semaphore, return -1
   // if not available
   virtual int trywait() = 0; // Line 10

   // unlock (give) the semaphore
   virtual int post() = 0; // Line 13

   // get the value of the semphore
   virtual int get_value() const = 0; // Line 16

   protected:
   // constructor
   simple_semaphore_if() { } // Line 21
};

// Creation of the semaphore Channel
class simple_semaphore: public simple_semaphore_if, public sc_prim_channel
{
   public:
   // constructors
   explicit simple_semaphore( int init_value_ );

   // interface methods
   // lock (take) the semaphore, block if
   // not available
   virtual int wait(); // Line 37

   // lock (take) the semaphore, return -1 if
   // not available
   virtual int trywait(); // Line 40

   // unlock (give) the semaphore
   virtual int post(); // Line 43

   // get the value of the semaphore
   virtual int get_value() const // Line 46
   { return m_value; }

   protected:
   // support methods
   bool in_use() const // Line 53
   { return ( m_value &lt;= 0 ); }

   protected:
   int m_value; // Line 58
   sc_event m_free; // Line 58
};

// constructors
simple_semaphore::simple_semaphore( int init_value_ ) :
   sc_prim_channel( sc_gen_unique_name( “semaphore” ) ),
   m_value( init_value_ ) { }</pre>
<pre>
// interface methods
// lock (take) the semaphore, block if
// not available
int simple_semaphore::wait() {
   while( in_use() )  sc_prim_channel::wait( m_free );
   -- m_value;
   return 0;
}

// lock (take) the semaphore, return -1 if
//not available
int simple_semaphore::trywait() {
   if( in_use() ) {
      return -1;
   }
   -- m_value;
   return 0;
}

// unlock (give) the semaphore
int simple_semaphore::post() {
   ++ m_value;
   m_free.notify();
   return 0;
}</pre>
<p class="western">The first part of this example defines the interface for the semaphore’s channel. line 1 declares the interface class named ‘simple_semaphore_if’ and inherits virtually, the sc_interface SystemC predefined class. The virtual inheritance is used here to prevent any problems related to repeated inheritance later-on during the creation of the simple_semaphore channel. The lines 7 to 16 declare pure virtual methods that will be used to access the semaphore channel. Finally the line 21 defines a default constructor for the interface. Following the interface declaration, we find the declaration of the semaphore channel called ‘simple_semaphore’. The class is created through the inheritance of both the simple_semaphore_if interface class and the SystemC sc_prim_channel pre-defined class. The lines 37 to 46 make the previously pure virtual methods defined inside the interface into effective methods inside the channel. A local method is created in line 53 to used to keep track of the current value of the semaphore. Lastly in lines 58 and 59 we find the definitions of internal member variables used by the semaphore channel. The ultimate part of this example implements each individual methods defined inside the semaphore channel.</p>
<h3 class="western"><font size="4">Hierarchical Channel</font></h3>
<p class="western">Up until now we have considered the simplest form of channels: the primary channels. Although primary channels are of great use, one of the main advantages that SystemC has over conventional HDLs, is its ability to create complex communication mechanisms in the form of hierarchical channels.<br />
Hierarchical channels are used as a convenient way to abstract exchanges between communicating objects such as sc_modules. Commonly hierarchical channels are used as transactors, converting high level commands to RTL style signals and vice versa.</p>
<p class="western">Herarchical channel can be considered in a lot of ways as, more sohisticated forms of sc_modules. As such, a hierarchical channel can contain ports, as well as, a hierarchy of sc_modules or other channels. Furthermore, hierarchical channels may contain SystemC processes such as: SC_METHODS or SC_THREAD. However, unlike their sc_modules counterparts, hierarchical channels will also provide methods for implementing the functions defined inside their associated interfaces.</p>
<p class="western">As we mention earlier, a channel is always created from one or multiple existing interfaces. An interface in SystemC is an abstract class derived from the existing SystemC class: sc_interface.</p>
<p class="western">By definition interfaces will only define pure virtual access methods. These methods will eventually have to be implemented in any deriving channels. The following illustrates the creation of a user defined interface called dma_interface with a methods called: burstWrite() and bustRead().</p>
<pre>class dma_interface: virtual public sc_interface {
public:
   virtual void burstWrite(int destAddress, int numBytes, sc_lv&lt;8&gt; *data ) = 0;
   virtual void burstRead(int sourceAddress, int numBytes, sc_lv&lt;8&gt;* data) = 0;
};</pre>
<p class="western">Commonly the inheritance of the pre-defined SystemC class: sc_interface, is done as, public and virtual. The virtual mechanism is used as a safety net, preventing the rise of issues related to repeated inheritance when a channel inherits more that one interface.</p>
<p class="western">After the creation of an interface, numerous channels can be created to provide the required implementation of the interfaces’ methods. The creation of a hierarchical channel differs from a primitive one, only by the type of the inherited pre-defined SystemC class: sc_channel. Along with the sc_channel class, one to any number of interface classes can be inherited. The following code illustrates the creation of a channel called: dma_channel, publicly inheriting form the interface class: dma_interface.</p>
<pre>class dma_channel: public dma_interface, public sc_channel {
public:
   sc_out_rv&lt;16&gt; address_p;
   sc_inout_rv&lt;8&gt; data_p;
   sc_out_resolved rw_p;
   dma_channel(sc_module_name nm): sc_channel(nm)
      ,address_p(”address_p”)
      ,data_p(”data_p”)
      ,rw_p(”rw_p”)
   { }
   virtual void burstWrite( int destAddress, int numBytes, sc_lv&lt;8&gt; *data );
   virtual void burstRead(int sourceAddress, int numBytes, sc_lv&lt;8&gt;* data);
};

void dma_channel::burstWrite( int destAddress, int numBytes, sc_lv&lt;8&gt; *data ) {
   sc_lv&lt;8&gt; *ite = data;
   for (int i=0; i&lt;numBytes; i++) {
      address_p-&gt;write(destAddress++);
      data_p-&gt;write( *(ite++) );
      wait(10, SC_NS);
      cout &lt;&lt; “Write out ” &lt;&lt; data_p-&gt;read() &lt;&lt; endl;
      rw_p-&gt;write(SC_LOGIC_0); // Write pulse
      wait(50, SC_NS);
      rw_p-&gt;write(SC_LOGIC_Z);
      address_p-&gt;write(”ZZZZZZZZZZZZZZZZ”);
      data_p-&gt;write(”ZZZZZZZZ”);
      wait(10, SC_NS);
   }
}</pre>
<pre>
void dma_channel::burstRead(int sourceAddress, int numBytes, sc_lv&lt;8&gt;* data) {
   for (int i=0; i&lt;numBytes; i++) {
      address_p-&gt;write(sourceAddress++);
      wait(10, SC_NS);
      rw_p-&gt;write(SC_LOGIC_1); // Read pulse
      wait(10, SC_NS);
      *(data++) = data_p-&gt;read();
      cout &lt;&lt; “Data read ” &lt;&lt; data_p-&gt;read() &lt;&lt; endl;
      wait(40, SC_NS);
      rw_p-&gt;write(SC_LOGIC_Z);
      address_p-&gt;write(”ZZZZZZZZZZZZZZZZ”);
      data_p-&gt;write(”ZZZZZZZZ”);
      wait(10, SC_NS);
   }
}</pre>
<p class="western">The first part of this code illustrates the creation of the hierarchical channel called dma_channel. This is done through the multiple inheritance of the sc_channel class and the dma_interface class.<br />
Ports are created to illustrate the flexibility of channels. Those port are initialised inside the constructor of that class.<br />
The last part of the dma_channel class declaration restates the existance of the burstWrite() and burstRead() methods found in the parent class: dma_interface.</p>
<p class="western">Lastly the code illustrates the implementation of the two methods burstWrite() and burstRead(). The code itself is of little importance but it demonstrates how high level transactions can be refined into low-level RTL signal activities.</p>
<p class="western">For the pupose of completeness of this example the following code illustrates how can this channel could be used in a verification environment.<br />
This code shows the creation of a simple testbench sending a burstWrite() and a burstRead() request to a slave RTL memory via the dma_channel.</p>
<pre>
class test_bench: public sc_module {
   public:
   sc_port&lt;dma_interface&gt; master_port;

   void stimuli()
   {
      sc_lv&lt;8&gt; data_sent[10] = {20, 21, 22, 23, 24, 25,26,27,28,29};
      sc_lv&lt;8&gt; data_rcv[10] = {0,0,0,0,0,0,0,0,0,0};
      master_port-&gt;burstWrite(100, 10, data_sent);
      wait(100, SC_NS);
      master_port-&gt;burstRead(100, 10, data_rcv);
      for (int i=0; i&lt;10; i++) {
         if (data_sent[i] != data_rcv[i]) {
            cout &lt;&lt; data_sent[i] &lt;&lt; ” ” &lt;&lt; data_rcv[i] &lt;&lt; endl;
            cout &lt;&lt; “data missmatch” &lt;&lt; endl;
         }
      }

   SC_HAS_PROCESS(test_bench);

   test_bench(sc_module_name nm): sc_module(nm) {
      SC_THREAD(stimuli);
   }
};

class rtl_memory: public sc_module {
public:
   sc_in_rv&lt;16&gt; address_p;
   sc_inout_rv&lt;8&gt; data_p;
   sc_in_resolved rw_p;
   sc_lv&lt;8&gt; *mem_arr;
   void run() // sensitive rw_p
   {
      while(true) {
         // read cycle
         if (rw_p-&gt;read() == SC_LOGIC_1) {
            data_p-&gt;write( *( mem_arr+(sc_uint&lt;16&gt;(address_p-&gt;read())) ) );
            // write cycle
         } else if (rw_p-&gt;read() == SC_LOGIC_0) {
            *(mem_arr + (sc_uint&lt;16&gt;(address_p-&gt;read()))) = data_p-&gt;read();
         }
         wait();
      }
   }

   SC_HAS_PROCESS(rtl_memory);
   rtl_memory(sc_module_name nm, int mem_size = 100): sc_module(nm) {
      mem_arr = new sc_lv&lt;8&gt;[mem_size];
      for (int i=0; i&lt; mem_size; i++) {
         mem_arr[i] = sc_lv&lt;8&gt;(0);
      }
   SC_THREAD(run);
      sensitive &lt;&lt; rw_p;
   }

   ~rtl_memory() { delete []mem_arr; } };

// Main program
int sc_main(int argc, char* argv[])
{
   sc_set_time_resolution(1, SC_NS);

   sc_signal_rv&lt;16&gt; address_s;
   sc_signal_rv&lt;8&gt; data_s;
   sc_signal_resolved rw_s;

   test_bench tb(”tb”);
   dma_channel transactor(”transactor”);
   rtl_memory uut(”uut”, 1000);

   tb.master_port(transactor);
   transactor.data_p(data_s);
   transactor.rw_p(rw_s);
   transactor.address_p(address_s);
   uut.address_p(address_s);
   uut.data_p(data_s);
   uut.rw_p(rw_s);

   sc_start();
   return 0;
}</pre>
<h3 class="western"><font size="4">Summary</font></h3>
<p class="western">In this section we covered the existance of two kind of channels in SystemC: primitive, hierarchical. The main differences between those two kinds being: primitive channels cannot contain SystemC structural objects (ports, channels, processes) but can use the update() method to implement non blocking update mechanisims; The hierachical channels however can have structural objects but cannot use the update() method.<br />
I addition we illustrated the creation of both a primitive and hierarchical channel as well as their use in the context of a verification environment.</p>
<p class="western">The code for this tutorial can be found <a href="http://www.openomy.com/download/systemclive/main.cc" title="Interfaces and Channels code" target="_blank">HERE.</a></p>
<p class="western">Et voila !</p>
<p class="western">David Cabanis</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/61/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/61/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=61&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2008/01/11/systemc-tutorial-interfaces-and-channels-2/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
		<item>
		<title>SystemC Tutorial: threads, methods and sc_spawn</title>
		<link>http://sclive.wordpress.com/2008/01/10/systemc-tutorial-threads-methods-and-sc_spawn/</link>
		<comments>http://sclive.wordpress.com/2008/01/10/systemc-tutorial-threads-methods-and-sc_spawn/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 17:44:06 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[SytemC Tutorials]]></category>

		<guid isPermaLink="false">http://sclive.wordpress.com/2008/01/10/systemc-tutorial-threads-methods-and-sc_spawn/</guid>
		<description><![CDATA[Forewords
This tutorial is intended to be a basic introduction to the notions of concurrent processes in SystemC. We will touch on the SystemC ability to dynamically spawn processes.
Processes in SystemC
One of the essential element of the SystemC language is concurrency. This is achieved through what we will call processes. Processes are similar to processes in [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3><font size="4">Forewords</font></h3>
<p>This tutorial is intended to be a basic introduction to the notions of concurrent processes in SystemC. We will touch on the SystemC ability to dynamically spawn processes.</p>
<h3><font size="4">Processes in SystemC</font></h3>
<p>One of the essential element of the SystemC language is concurrency. This is achieved through what we will call processes. Processes are similar to processes in VHDL or always/initial in Verilog. In principle processes are block of sequential code similar to functions. However, unlike functions, processes are not explicitly called by the user. Processes can in effect be seen as always active; For that reason they are considered to be concurrent.<br />
In the SystemC language there are two distinct kinds of processes namely: SC_METHOD and SC_THREAD. These two kind of processes are typically created statically; In other words they are created prior to the execution of the simulation. Alternatively SystemC allows processes to be created dynamically via a dedicated function called: sc_spawn() .</p>
<h3><font size="4">The SC_THREAD process</font></h3>
<p>As a first step we will look at the SystemC SC_THREAD. A thread by definition is a process that will automatically execute itself at the very start of a simulation run and then will suspend itself for the rest of the simulation.<br />
Threads are versatile processes in the sense that they can be halted at any moment and any number of times during their execution. Interestingly, although the thread is mean to be executed only once throughout the simulation, most of times we want to be able to use threads for the whole duration of the simulation. In order to achieve this, we use a simple &#8216;trick&#8217; that consist in creating an infinite loop within a thread. Consequently we prevent the thread from ever reaching its sequential end. The following example illustrates how to create a simple thread used to generate a clock generator.</p>
<pre>void run() {
   while(true) {
      clock_signal.write(SC_LOGIC_0);
      wait(10, SC_NS);
      clock_signal.write(SC_LOGIC_1);
      wait(10, SC_NS);
   }
}</pre>
<p>Three main observations can be made:</p>
<ul>
<li>The funtion &#8216;run&#8217; does not have any input or return parameters. This typical of a SystemC static process such as SC_THREAD or SC_METHOD.</li>
<li>An infinite while loop is used to prevent the function &#8216;run&#8217; from ever reaching its end. This does not have to be used for all SC_THREAD implementations; however it is a common occurrence.</li>
<li> We are using &#8216;wait&#8217; function calls to force a temporary suspension of the function &#8216;run&#8217; and the update of the &#8216;clock_signal&#8217; value. This can only be used by SC_THREAD processes.</li>
</ul>
<p>Up until now we have only created a C++ member function that will be used as a thread. At this time we will need to indicate to the SystemC simulation kernel that this specific member function (in our case &#8216;run&#8217;) should be treated as a concurrent thread and not as a basic C++ member function. This will be done through an operation called processes registration. To put it simply this consists in enumerating how individual functions should be treated. This simple operation is done inside the constructor of a module. The following code will illustrate how this is achieved.</p>
<pre>
sample_module(sc_module_name nm):sc_module(nm) {
   SC_THREAD(run);
}</pre>
<p>In this example we assume the existence of a SystemC called &#8217;sample_module&#8217;. The process registration of the member function &#8216;run&#8217; as an SC_THREAD is done by passing the name of the selected function (run) as an argument of the macro SC_THREAD.</p>
<h3><font size="4">The SC_METHOD process</font></h3>
<p>The SC_METHOD is in many ways similar to the SC_THREAD. However there are two main differences: SC_METHOD will run more than once by design and methods cannot be suspended by a wait statement during their execution. The following code illustrates this.</p>
<pre>
void log() {
   count_signal.write(count_signal.read()+1);
   if (count_signal.read() &gt;= 10) {
      cout &lt;&lt; "Reached max count" &lt;&lt; endl;
      count_signal.write(0);
   }
}</pre>
<p>From this sample we can observe that no wait statements are being used. Additionally there is no need for an infinite &#8216;while&#8217; loop since this is the nature of an SC_METHOD to go back to it&#8217;s beginning when it finishes executing.<br />
However not visible inside the code lies a hidden wait statement. That implicit statement is always located on the very last line of the member function and causes the kernel to suspend the SC_METHOD so that its sensitivity list can be evaluated.</p>
<h3><font size="4">Processes Sensitivity</font></h3>
<p>SystemC support two kind of sensitivity: Dynamic and static. For the purpose of this tutorial we will concern ourselves only with that later. Both SC_THREAD and SC_METHOD may have a sensitivity list although they are not obliged to. In the example of the SC_THREAD covered previously we did not use a static sensitivity list; For the SC_METHOD example we will have to.<br />
As seen before the SystemC requires a kernel registration to identify which member function it needs to treat as a SC_METHOD (no explicit suspension allowed) or an SC_THREAD (suspensions allowed). In the case of the method processes we will use the macro SC_METHOD. The following code illustrates the registration of the &#8216;log&#8217; function as a SC_METHOD.</p>
<pre>
sample_module(sc_module_name nm):sc_module(nm) {
   SC_METHOD(log);
      sensitive &lt;&lt; clock_signal.posedge_event();
}</pre>
<p>As can be observed we now have an additional statement indicating that the macro directly above it is sensitive to positive edges of the signal &#8216;clock_signal&#8217;. That sensitivity list will typically contain event objects as well as ports or channels (signals).<br />
Consequently as soon as a positive edge is detected on the signal &#8216;clock_signal&#8217;, the function &#8216;log&#8217; will be re-executed.</p>
<p>The last point of detail remaining is to indicate to the kernel that this module that we have created will contain concurrent processes. This is done using the macro SC_HAS_PROCESS(moduleName).</p>
<p>The full code for this section on threads, methods and sensitivity list is shown here:</p>
<pre>
class sample_module: public sc_module
{
	public:
	sc_signal clock_signal;
	sc_signal count_signal;
	SC_HAS_PROCESS(sample_module);
	sample_module(sc_module_name nm):sc_module(nm) {
		SC_THREAD(run);
		SC_METHOD(log);
			sensitive &lt;&lt; clock_signal.posedge_event();
	}</pre>
<pre>
	void log() {
		count_signal.write(count_signal.read()+1);
		if (count_signal.read() &gt;= 10) {
			cout &lt;&lt; "Reached max count" &lt;&lt; endl;
			count_signal.write(0);
		}
	}

	void run() {
		while(true) {
			clock_signal.write(SC_LOGIC_0);
			wait(10, SC_NS);
			clock_signal.write(SC_LOGIC_1);
			wait(10, SC_NS);
		}
	}
};</pre>
<h3><font size="4">Dynamic processes</font></h3>
<p>In the first part of this tutorial we have looked at the most common usage of processes in SystemC. Nevertheless there is yet a more sophisticated way of creating processes by spawning functions at will. This method is by far the most flexible and most complete.<br />
The sc_spawn function can be seen as a super-set of the existing SC_THREAD, SC_METHOD macros. It can be used as a straight replacement although the semantics is a bit more involving.<br />
A very basic example of the function sc_spawn is as follows. Assuming that we have an existing <b>member function</b> as such:</p>
<pre>void spawned_th(bool value) {
   cout &lt;&lt; "spawned_th successfuly spawned with value: "
          &lt;&lt; value &lt;&lt; endl;
}</pre>
<p>A call to spawn that function from within an SC_THREAD would be as such:</p>
<pre>sc_spawn( sc_bind(&amp;sample_module::spawned_th, this, true) );</pre>
<p>Without going in too much details, this call relies on an additional function sc_bind that is required to attach an existing function. This is done by passing the address (&amp;) of the required member function as an argument. In addition, we need to indicate that this specific function is not a global function (this is also allowed) but a member function of our module hence the use of &#8216;this&#8217;. Finally the function &#8217;spawned_th&#8217; has one input paramenter &#8216;value&#8217; of type bool therefore we set an actual value (true) inside the &#8217;sc_bind&#8217; call.</p>
<p>A more complete example is as follows:</p>
<pre>class sample_module: public sc_module
{
   public:
   sc_signal clock_signal;
   SC_HAS_PROCESS(sample_module);
   sample_module(sc_module_name nm):sc_module(nm) {
      SC_THREAD(run);
   }

   void spawned_th(bool value) {
      cout &lt;&lt; "spawned_th successfuly spawned with value: "
             &lt;&lt; value &lt;&lt; endl;
   }

   void run() {
      sc_spawn( sc_bind(&amp;sample_module::spawned_th, this, true) );

      while(true) {
         clock_signal.write(SC_LOGIC_0);
         wait(10, SC_NS);
         clock_signal.write(SC_LOGIC_1);
         wait(10, SC_NS);
      }
   }
};</pre>
<p>As stated earlier this example has been kept very simple for the purpose of clarity. Additional features would be the ability to:</p>
<ul>
<li>Specify a return argument for the spawned function</li>
<li>Specify if the argument passed to the function are reference (as opposed to copies) or constant references</li>
<li>Spawn a global function instead of a member function</li>
<li>Being able to specify if the spawned function should be treated as a method or thread(default)</li>
<li>Being able synchronise thread activities by checking their status (idle or running)</li>
</ul>
<p>Most of those options can fairly easily be achieved however they fall outside of the scope of this tutorial. Nevertheless to give you a more complete picture of the &#8217;sc_spawn&#8217; function, we will illustrate the spawning of a global function with return arguments and reference input arguments.</p>
<pre>#define SC_INCLUDE_DYNAMIC_PROCESSES

int global_th(const bool&amp; in_value, int&amp; out_value) {
   cout &lt;&lt; "global_th successfuly spawned with value: "
          &lt;&lt; in_value &lt;&lt; ", " &lt;&lt; out_value &lt;&lt; endl;

   if (in_value) {
      out_value++;
      wait(2, SC_NS);
      return 0;
   }
   wait(5, SC_NS);
   return 1;
}

class sample_module: public sc_module
{
   public:
   sc_signal clock_signal;
   SC_HAS_PROCESS(sample_module);
   sample_module(sc_module_name nm):sc_module(nm) {
      SC_THREAD(run);
   }

   void run() {
      int actual_return_value, actual_int_arg = 9;
      bool actual_bool_arg = true;

      sc_spawn( &amp;actual_return_value, sc_bind(&amp;global_th,
                       sc_cref(actual_bool_arg),
                       sc_ref(actual_int_arg) ) );

      while(true) {
         clock_signal.write(SC_LOGIC_0);
         wait(10, SC_NS);
         clock_signal.write(SC_LOGIC_1);
         wait(10, SC_NS);
      }
   }
};</pre>
<p>This time the &#8217;sc_spawn&#8217; function has an additional argument for the returned value (passed by pointer) in addition the &#8216;this&#8217; argument was removed since we are now dealing with a global function. The &#8217;sc_cref&#8217; and &#8217;sc_ref&#8217; functions were used to indicate that we were dealing with constant reference and reference formal arguments.</p>
<h3><font size="4">Conclusions</font></h3>
<p>This tutorial covered the basic uses of SystemC processes. we announced the rules regarding the suspension of processes and looked at the sensitivity list and kernel registrations. Lastly we covered the use of the sc_spawn function and saw how can generic functions can be parallelised at will.</p>
<p>Et voila!</p>
<p>David Cabanis.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/60/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/60/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=60&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2008/01/10/systemc-tutorial-threads-methods-and-sc_spawn/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
		<item>
		<title>SCLive 2.0 Released</title>
		<link>http://sclive.wordpress.com/2006/10/26/sclive-20-released/</link>
		<comments>http://sclive.wordpress.com/2006/10/26/sclive-20-released/#comments</comments>
		<pubDate>Thu, 26 Oct 2006 18:07:01 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[Releases]]></category>

		<guid isPermaLink="false">http://sclive.wordpress.com/2006/10/26/sclive-20-released/</guid>
		<description><![CDATA[The SystemC Live CD version 2.0 has been released today. It can be downloaded directly from HERE and HERE
This new version features:

SystemC 2.2 beta
SCV 1.0
TLM 1.0
SystemC / C++ tutorial (Esperan)
gcc g++ 3.4.6
gdb 6.3
ddd 3.3.9
gtkwave 1.3.79
vim 7.0
geany 0.7.1
opera 9.02
Beep Media Player 0.9.7
xpdf
xfce4 4.2.3.2
slapt-get 0.9.11b
gslapt 0.3.1.2

The file size is 137MB and can be burnt onto various media [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The SystemC Live CD version 2.0 has been released today. It can be downloaded directly from <a href="http://www.esperan.com/livecd/index.html" target="_blank" title="Esperan SCLive Download Page">HERE</a> and <a href="http://sourceforge.net/project/showfiles.php?group_id=173842&amp;package_id=199161&amp;release_id=458717" title="Sourceforge SCLive Download Page" target="_blank">HERE</a></p>
<p>This new version features:</p>
<ol>
<li>SystemC 2.2 beta</li>
<li>SCV 1.0</li>
<li>TLM 1.0</li>
<li>SystemC / C++ tutorial (Esperan)</li>
<li>gcc g++ 3.4.6</li>
<li>gdb 6.3</li>
<li>ddd 3.3.9</li>
<li>gtkwave 1.3.79</li>
<li>vim 7.0</li>
<li>geany 0.7.1</li>
<li>opera 9.02</li>
<li>Beep Media Player 0.9.7</li>
<li>xpdf</li>
<li>xfce4 4.2.3.2</li>
<li>slapt-get 0.9.11b</li>
<li>gslapt 0.3.1.2</li>
</ol>
<p>The file size is 137MB and can be burnt onto various media such as: Memory stick (USB), Mini CD, CD-R, CD-RW.</p>
<p>You will find SCLive 2.0 to be a more integrated, complete and slicker distribution with tools that will facilitate SystemC development (gdb, ddd, vim)  and user customisations (gslapt, slap-get).</p>
<p>The zip file also contains pre-prepared configuration files to run SCLive 2.0 painlessly inside the VMWare player software.</p>
<p>Have a lot of fun with SCLive and don&#8217;t hesitate to send me your comments (Francais/ English) at: systemclive@googlemail.com</p>
<p>David Cabanis</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/48/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/48/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=48&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2006/10/26/sclive-20-released/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
		<item>
		<title>SystemC Tutorial: Hardware Modeling with C++</title>
		<link>http://sclive.wordpress.com/2006/10/25/systemc-tutorial-hardware-modeling-with-c/</link>
		<comments>http://sclive.wordpress.com/2006/10/25/systemc-tutorial-hardware-modeling-with-c/#comments</comments>
		<pubDate>Wed, 25 Oct 2006 14:26:21 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[SytemC Tutorials]]></category>

		<guid isPermaLink="false">http://sclive.wordpress.com/2006/10/25/systemc-tutorial-hardware-modeling-with-c/</guid>
		<description><![CDATA[      Forewords
C++ implements Object-Orientation on the C language. For most Hardware   Engineers, the principles of Object-Orientation seem fairly remote from the   creation of Hardware components. However ironically, Object-Orientation was   created from design techniques used in Hardware designs. Data abstraction is   the central [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>   <font size="4">   Forewords</font></h3>
<p>C++ implements Object-Orientation on the C language. For most Hardware   Engineers, the principles of Object-Orientation seem fairly remote from the   creation of Hardware components. However ironically, Object-Orientation was   created from design techniques used in Hardware designs. Data abstraction is   the central aspect of Object-Orientation which incidentally, is found in   everyday hardware designs through the use of publicly visible “ports” and   private “internal signals”. Furthermore, the principle of “composition” used   in C++ for creating hierarchical design is almost identical to component   instantiation found in hardware designs. The coming sections will introduce   the basics of C++ by looking at the creation of an hardware component.</p>
<h3>   <font size="4">    The Class</font></h3>
<p>The class in C++ is called an Abstract Data Type (ADT); it defines both data   members and access functions (also called methods). Both data members and   access functions are said to be private by default. In other words, data   members and access functions are not visible from the outside world. This ADT   mechanism is analogous to a package and package body in VHDL. The designer is   responsible for making publicly available the essential set of access   functions for manipulating an ADT. The semantics for a C++ class declaration is as follows:</p>
<blockquote>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">class counter   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">{</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int value;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_reset() { value = 0   ; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_up() {   value++ ; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int do_read() { return   value; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
</blockquote>
<p>In this example we see the declaration of an ADT called: “counter” with a data   member “value” and publicly available access functions: “do_reset”,   “do_count_up” and “do_read”. Although this class declaration is complete;   commonly, a class declaration will also contain specialised functions such as   constructors and a destructor. When constructors are used, they provide   initial values for the ADT’s data members. This mechanism is the only allowed   mean for setting a default value to any data member.<br />
A destructor is used to perform clean-up operations before an instance of the   ADT become out of scope. Pragmatically, the destructor is used for closing   previously opened files or de-allocating dynamically allocated memory.<br />
An example of an ADT with constructors and a destructor is as follows:</p>
<blockquote>
<p class="western" style="margin-bottom:0;page-break-before:always;">   <font face="Courier New, monospace"><font size="2">class counter   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">{</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int value;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_reset() { value = 0   ; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_up() {   value++ ; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int do_read() { return   value; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">counter() {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; &#8220;This a   simple constructor&#8221; &lt;&lt; endl; </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">value = 10;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">counter(int arg):   value(arg) {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; &#8220;This a more   interesting constructor&#8221; &lt;&lt; endl; </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">~counter() { </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; &#8220;Destroying a   counter object&#8221; &lt;&lt; endl;}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
</blockquote>
<p>In our example all access functions are made visible to the outside world   through the use of the “public” keyword. However, not all functions have to be   made public; they can be held hidden from the rest of the world through the   use of the “private” keyword.</p>
<h3>   <font size="4">    The Object</font></h3>
<p>An object is an instance of an ADT. Any number of instances can be made of a   given ADT; each of these instances are initialised individually.<br />
An example of objects instantiation and messages passing is as follows:</p>
<blockquote>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void main() {</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">counter   first_counter;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">counter   second_counter(55);</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">// Message   passing</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">first_counter.do_reset();</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">for (int i=0; i &lt; 10;   i++) { first_counter.do_count_up(); } </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">second_counter.do_count_up();</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">first_counter.do_reset();</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">second_counter.do_reset();</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
</blockquote>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   In this example two instances of the counter ADT are created. The   “first_counter” instance uses the default constructor not requiring any   arguments. The “second_counter” instance uses a more sophisticated constructor   form that passes an argument.</p>
<p class="western" style="margin-bottom:0;">   Messages are send to individual objects via the ‘dot’ notation which is   similar to what is used for “struct” data structures.</p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   The building of more complex objects can be achieved through the composition   mechanism. This mechanism is akin to component instantiation in Hardware   design.</p>
<p class="western" style="margin-bottom:0;">   The following example illustrates the principle of hierarchical design through   composition.</p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<blockquote>
<p class="western" style="margin-bottom:0;page-break-before:always;">   <font face="Courier New, monospace"><font size="2">class modulo_counter   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">{</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">counter   internal_counter;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int   terminal_count;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_reset() {   internal_counter.do_reset(); }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_up() {   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">if (   internal_counter.do_read() &lt; terminal_count ) { </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">internal_counter.do_count_up();   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">} else {   internal_counter.do_reset(); }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">} </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int do_read() { return   internal_counter.do_read(); }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">modulo_counter(int tc):   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">terminal_count(tc),   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">internal_counter(0)   {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; &#8220;A new   modulo_counter instance&#8221; &lt;&lt; endl; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
</blockquote>
<p>In this example a new ADT “modulo_counter” is created form an instance of a   counter ADT called “internal_counter”. An additional data member   “terminal_count” was added to provide the modulo value for this new ADT. The   access function “do_count_up” is customised to take in considerations of the   modulo counter specifications. As it can be observed, most actions are   delegated to the “internal_counter” instance via message passing. It is   interesting to notice how the constructor function is used to initialise both   the “terminal_count” value and the instantiated object “internal_counter”. The   argument “tc” is used to set the value of “terminal_count” and the value “0”   is passed to the constructor of the “internal_counter” object.</p>
<h3>   <font size="4">    Inheritance</font></h3>
<p>Along with composition, C++ provides a sophisticated mechanism for reusing   code called: inheritance. With inheritance designers are able to create new   ADTs from existing ones by accessing all public elements of a parent class   into a child class. This principle can be more appropriate than composition   since it usually requires less effort to achieve the same goal. However   inheritance does not replace composition but complements it. The following   example illustrates the creation of a modulo counter ADT from an existing   counter ADT whilst using inheritance.</p>
<blockquote>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">class modulo_counter :   public counter {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int   terminal_count;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_up()   {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">if ( do_read() &lt;   terminal_count ) { </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">counter::do_count_up();   }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">else { do_reset();   }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">modulo_counter(int tc):   terminal_count(tc), counter(0) {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; &#8220;A new   modulo_counter instance&#8221; &lt;&lt; endl; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
</blockquote>
<p>In this example a new access function called “do_count_up” is created. This   overrides the inherited function from the parent class “counter”. The   remaining public access functions (do_reset, do_read) found in the parent   class are now available to the child class: “modulo_counter”. As it can be   observed the creation of the “modulo_counter” class is greatly simplified   through the use of inheritance. Nevertheless, the “do_read” and   “counter::do_count_up” functions had to be used in the newly created   “do_count_up” function to access the private data members inside the parent   class. Although this is a valid solution, C++ offers a more pragmatic   alternative, consisting in using a protected encapsulation in place of a   private one. Unlike private members, protected members are inherited along   with public ones when a parent class is derived, however, protected data   members remain hidden from the outside world in the same way as private   members do. A new implementation of the counter and modulo_counter class using   protected data members is as follows:</p>
<blockquote>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">class counter   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">{</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">protected:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int value;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_reset() { value = 0   ; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_up() {   value++ ; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int do_read() { return   value; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">counter() {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; &#8220;This a   simple constructor&#8221; &lt;&lt; endl; </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">value = 10;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">counter(int arg):   value(arg) {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; &#8220;This a more   interesting constructor&#8221; &lt;&lt; endl; </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">~counter() { cout &lt;&lt;   &#8220;Destroying a counter object&#8221; </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">&lt;&lt;   endl;}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">class modulo_counter :   public counter {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">protected:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int   terminal_count;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_up()   {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">if ( value &lt;   terminal_count ) { value++; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">else { value = 0;   }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">modulo_counter(int tc):   terminal_count(tc), counter(0) {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; &#8220;A new   modulo_counter instance&#8221; &lt;&lt; endl; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
</blockquote>
<p>In this last example the data member “value” is directly accessed from within   the “modulo_counter” class. The use of the protected encapsulation has   simplified the creation of the derived class by making data members from the   parent class accessible.<br />
The principle of single inheritance can be extended to allow a child class to   be built from multiple parents. This principle is referred as multiple   inheritance. Multiple inheritance enables designers to rapidly create new   sophisticated classes from a multitude of existing ADTs. The use of multiple   inheritance commonly requires careful planning since it can create numerous   undesirable side effects. An example of multiple inheritance is as follows:</p>
<blockquote>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">class reg {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">protected:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int value;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_reset() { value =   0; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int do_read() { return   value; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_write(int arg) {   value = arg; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">reg(): value(0)   {}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">class up_counter: virtual   public reg {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_up() {   value++; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">class down_counter: virtual   public reg {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_down() {   value&#8211;; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">class up_down_counter:   public up_counter, public down_counter { };</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
</blockquote>
<p>In this example the “up_down_counter” ADT is created from two parent classes:   “up_counter” and “down_counter”. The “up_down_counter” does not require any   code since it inherits all of its implementation from its parent classes. It   is important to point out that both the “up_counter” and “down_conter” are   inheriting virtually the register class. The virtual inheritance is used here   to prevent multiple declarations of the “value”, “do_reset”, “do_read”,   “do_write” inside the “up_down_counter” since this ADT inherits those   attributes twice, though both the “up_counter” and “down_counter” inheritance.</p>
<h3>   <font size="4">  Template Class</font></h3>
<p>The template mechanism is used for creating more versatile ADTs. Templates can   be used for variable types or values. An example of a simple template class is   as follows:</p>
<blockquote>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">template&lt;int min, int   max&gt; class barrel_counter {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">private:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int value;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_reset() { value =   min; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">void do_count_up() {   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">if (value&lt; max ) {   value++; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">else {value = min;   }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">} </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int do_read() { return   value; }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">barrel_counter():   value(min) { }</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int main(int argc, char   *argv[])</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">{ </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">barrel_counter&lt;10,   50&gt; first_counter;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">barrel_counter&lt;0, 10&gt;   second_counter;</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">for (int i=0; i &lt; 60;   i++) {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">first_counter.do_count_up();</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">second_counter.do_count_up();</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt;   first_counter.do_read() &lt;&lt; endl;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt;   second_counter.do_read() &lt;&lt; endl;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font size="2"><font face="Courier New, monospace"><span>}   </span></font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">return 0;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
</blockquote>
<p>This counter implementation defines two templates “min” and “max”; these   variables are then used inside the class to define the boundaries of the   barrel counter. This example uses templates to set variable values;   alternatively templates can be used to set a variable type. An example of   templates used for variable types is as follows:</p>
<blockquote>
<p class="western" style="margin-bottom:0;page-break-before:always;">   <font face="Courier New, monospace"><font size="2">template&lt;class T&gt;   class adder {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">private:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">T result;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">public:</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">T add( T a, T b ) {   </font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">result = a + b   ;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font size="2"><font face="Courier New, monospace">return result   ;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">};</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int main(int argc, char   *argv[]) {</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">adder&lt;int&gt;   integer_adder;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">adder&lt;float&gt;   float_adder;</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">int int_result =   integer_adder.add(3, 5);</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">float float_result =   float_adder.add(6.7, 10.2);</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt; int_result   &lt;&lt; endl;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">cout &lt;&lt;float_result   &lt;&lt; endl;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">return 0;</font></font></p>
<p class="western" style="margin-bottom:0;">   <font face="Courier New, monospace"><font size="2">}</font></font></p>
<p class="western" style="margin-bottom:0;">&nbsp;</p>
</blockquote>
<p>This example uses a variable type “T” used throughout the class to provide a   versatile ADT implementation. At a later stage two objects of type adder are   declared however, both adders use different types for its operations.</p>
<h3>   <font size="4">    Summary</font></h3>
<p>As we illustrated in this section, Hardware components can be modeled in C++   and to some extent the mechanisms used are similar to those used in HDLs.   Additionally C++ provides inheritance as a way to complement the composition   mechanism and promotes design reuse.<br />
Nevertheless, C++ does not provide for concurrency which is an essential   aspect of systems modeling. Furthermore, timing and propagation delays cannot   easily expressed in C++. The SystemC library provides additional mechanisms   such as processes and dedicated data types to tackle C++ modeling   deficiencies.</p>
<p>The pdf file and the source files for this tutorial can be found <a href="http://www.esperan.com/tutorial.html#sysc" title="Tutorials page" target="_blank">HERE</a>.</p>
<p>Et Voila !</p>
<p>David Cabanis</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/47/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/47/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=47&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2006/10/25/systemc-tutorial-hardware-modeling-with-c/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
		<item>
		<title>SystemC Tutorial: ports</title>
		<link>http://sclive.wordpress.com/2006/10/20/systemc-tutorial-ports/</link>
		<comments>http://sclive.wordpress.com/2006/10/20/systemc-tutorial-ports/#comments</comments>
		<pubDate>Fri, 20 Oct 2006 15:40:19 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[SytemC Tutorials]]></category>

		<guid isPermaLink="false">http://sclive.wordpress.com/2006/10/20/systemc-tutorial-ports/</guid>
		<description><![CDATA[
   Forewords
These tutorials do not try to teach you everything about SystemC in large chapters taken from the language reference manual (LRM). Instead they focus on the most important aspects of the language, basic and advanced covering them in tutorials designed to take around ten minutes each.
   Ports
A Port is an [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="snap_preview">
<h3>   <font size="4">Forewords</font></h3>
<p>These tutorials do not try to teach you everything about SystemC in large chapters taken from the language reference manual (LRM). Instead they focus on the most important aspects of the language, basic and advanced covering them in tutorials designed to take around ten minutes each.</p>
<h3>   <font size="4">Ports</font></h3>
<p>A Port is an essential element of any SystemC model. Ports are used by modules as a gateway to and from the outside world. In a simplistic way, one can consider a port like the pin of a hardware component.<br />
In HDLs such as VHDL or Verilog, ports are very much like the pins metaphor; In the case of SystemC ports have a substantially more generalized purpose and as a result they are far more sophisticated and useful than their HDLs counterparts.</p>
<p>A simple SystemC port declaration would look like the following code:</p>
<blockquote><p><span style="font-family:Courier New;">sc_in&lt;bool&gt; my_input;</span></p></blockquote>
<p>As can be observed the semantic is kept to a minimum level of complexity; The port has a name <span style="font-style:italic;">my_input</span> and in this particular instance, it is of input mode since we used the <span style="font-style:italic;">sc_<span style="font-weight:bold;">in</span>&lt;&gt;</span> port type (or port mode if you prefer). The last observation that we can make from this simple line of code is the use of the <span style="font-style:italic;"><span class="misspell">bool</span></span> data type inside the <span style="font-style:italic;">&lt;&gt; </span>of the <span style="font-style:italic;">sc_in</span> port type. This data type refers to the kind of data that will be exchanged on that port. In other words we are expecting to receive <span class="misspell">boolean</span> values on the <span style="font-style:italic;">my_input</span> port.</p>
<p>As you would expect, numerous predefined port types exist in SystemC; Such as: <span style="font-style:italic;">sc_in&lt;Type&gt;, sc_out&lt;Type&gt;, sc_inout&lt;Type&gt;</span>, etc. All of those ports are almost identical to their HDL equivalents in VHDL or Verilog; they have a name, a type and a mode (in, out, etc). As a mater of fact, these kinds of ports are commonly used in RTL SystemC. However, as we indicated earlier, SystemC ports are much more than just RTL like ports; This is because SystemC ports not only have a name and a type but most importantly they define the <span style="font-weight:bold;">access mechanisms</span> that should be used on them. Pragmatically the access mechanisms are just a list of allowed messages that can be used on them. If we consider the <span style="font-style:italic;">sc_in&lt;bool&gt;</span> port of the previous example, SystemC defines that one can use the <span style="font-style:italic;">read()</span> message on it. Not surprisingly, an <span style="font-style:italic;">sc_out&lt;&gt; </span>port would allow the use of the <span style="font-style:italic;">write()</span> message. The following code illustrates the use of an sc_in&lt;bool&gt; and an sc_out&lt;bool&gt; ports.</p>
<blockquote><p><span style="font-family:Courier New;">// More code not shown here</span></p>
<p><span style="font-family:Courier New;">   sc_in&lt;bool&gt;  my_input;<br />
sc_out&lt;bool&gt; my_output;</span></p>
<p><span style="font-family:Courier New;">// More code not shown here</span></p>
<p><span style="font-family:Courier New;"> void do_run() {<br />
if (my_input.read() == true) {<br />
my_output.write(false);<br />
} else {<br />
my_output.write(true);<br />
}<br />
}<br />
};</span></p>
<p><span style="font-family:Courier New;">// More code not shown here</span><br />
<span style="font-family:Courier New;"></span> <span style="font-family:Courier New;"></span></p></blockquote>
<p><span style="font-family:Courier New;"></span><br />
For the sake of simplicity the creators of the SystemC language have provided operators that can be used instead of the <span style="font-style:italic;">read()</span> and <span style="font-style:italic;">write()</span> messages. Consequently the following code is also acceptable:<br />
<span style="font-family:Courier New;"></span></p>
<blockquote><p><span style="font-family:Courier New;">// More code not shown…</span></p>
<p><span style="font-family:Courier New;">   void do_run() {<br />
if (my_input == true) {<br />
my_output = false;<br />
} else {<br />
my_output = true;<br />
}<br />
}</span></p>
<p><span style="font-family:Courier New;">// More code not shown…</span><br />
<span style="font-family:Courier New;"></span></p></blockquote>
<p>The list of access messages allowed on specific ports has already been defined for the existing SystemC ports. However SystemC allows the user to define his/her very own set of messages for his/her very own ports. For instance one could imagine the existence of a high-level port used on a CPU model that could receive messages such as: <span style="font-style:italic;">dma_request()</span> or <span style="font-style:italic;">interrupt_request()</span> form the outside world.<br />
The creation of user defined ports goes beyond the scope of this tutorial and can only be covered when you will have gained an understanding of the notion of SystemC interfaces.</p>
<h3>   <font><font size="4">Ports and Modules<br />
</font></font></h3>
<p>Up until now we only considered ports in isolation. Prosaically ports are parts of modules and are used to pass data of some form in and out of the modules. <span class="misspell">SystemC</span> ports are by definition object instances of predefined classes (<span style="font-style:italic;">sc_in&lt;&gt;</span>, <span style="font-style:italic;">sc_out&lt;&gt;</span>, etc.) . As a result they can be accessed from within any member function defined inside the module. For instance the following code would be a valid way of using ports:</p>
<blockquote><p><span style="font-family:Courier New;">class portsTutorial: public sc_module {<br />
public:<br />
sc_in&lt;bool&gt;  my_input;<br />
sc_out&lt;bool&gt; my_output;</span></p>
<p><span style="font-family:Courier New;">SC_HAS_PROCESS(portsTutorial);</span></p>
<p><span style="font-family:Courier New;">portsTutorial(sc_module_name nm): sc_module(nm) {<br />
SC_METHOD(do_run);<br />
sensitive &lt;&lt; my_input;<br />
}</span></p>
<p><span style="font-family:Courier New;">protected:<br />
void do_run() {<br />
if (my_input.read() == true) {<br />
my_output.write(false);<br />
} else {<br />
my_output.write(true);<br />
}<br />
}<br />
};</span></p></blockquote>
<h3>   <font size="4">Ports and Signals</font></h3>
<p>Ports and signals have a special relationship since ports will connect to other ports via signals (also known as channels). More importantly, ports and signals share a common language. All the messages that can be used on a port should also be available on the signals (channels) connected to that port. As a result specific ports can only be connected to compatible signals; for instance an sc_in&lt;&gt; or an sc_out&lt;&gt; port can be connected to an sc_signal&lt;&gt; however and sc_fifo_in&lt;&gt; or an sc_fifo_out&lt;&gt; port can only be connected to an sc_fifo&lt;&gt; kind of channel. The following code illustrates the use of ports with signals:</p>
<blockquote><p><span style="font-family:Courier New;">// Top level</span><br />
<span style="font-family:Courier New;">class top: public sc_module { </span><br />
<span style="font-family:Courier New;">public:</span><br />
<span style="font-family:Courier New;">   sc_signal&lt;bool&gt; sig_1, sig_2;</span><br />
<span style="font-family:Courier New;"></span><br />
<span style="font-family:Courier New;">  portsTutorial uut;</span><br />
<span style="font-family:Courier New;"></span><br />
<span style="font-family:Courier New;">   top(sc_module_name nm): sc_module(nm), uut(”<span class="misspell">uut</span>“) {</span><span style="font-family:Courier New;"></span><br />
<span style="font-family:Courier New;">      uut.my_input(sig_1);</span><br />
<span style="font-family:Courier New;">      uut.my_output(sig_2);</span><br />
<span style="font-family:Courier New;">   }</span><br />
<span style="font-family:Courier New;">};</span><br />
<span style="font-family:Courier New;"></span></p></blockquote>
<p><span style="font-family:Courier New;"><br />
</span></p>
<p style="font-family:Verdana;">As can be observed the connection of a port and a signal is a simple operation. Nevertheless this semantics may look surprising since a usual object-oriented message is of the form: <span style="font-weight:bold;">object_name.message(parameters)</span> . In this case, uut.my_input(sig_1) is composed of two objects: <span class="misspell">uut</span> which is the component’s name and my_input which is the port’s name and finally sig_1 is a parameter. In other words we have: <span style="font-weight:bold;">object_name.object_name(parameter)</span> but no message call on the object. The reason is a simple one; the creators of SystemC used an overloading trick to make ports/signals connections appear simpler. In fact if you wanted to be a object-orientation purist you could write the following code to the same effect:</p>
<blockquote>
<p style="font-family:Courier New;">top(sc_module_name <span class="misspell">nm</span>): sc_module(nm), <span class="misspell">uut</span>(”<span class="misspell">uut</span>“) {<br />
uut.my_input.bind(sig_1);<br />
uut.my_output.bind(sig_2);<br />
}</p></blockquote>
<p><span style="font-family:Verdana;">The bind() message is effectively what is being used to connect a port to a signal (channel) although in the previous example it was hidden through an overloading trick.<br />
Lastly, there is yet anther way to connect your ports to your signals this is done using positional mapping where the signals are mapped to the ports by position. An example of positional mapping is as follows:</span></p>
<blockquote><p><span style="font-family:Courier New;">top(sc_module_name <span class="misspell">nm</span>): sc_module(nm), <span class="misspell">uut</span>(”<span class="misspell">uut</span>“) {</span><br />
<span style="font-family:Courier New;">     uut(sig_1, sig_2);</span><br />
<span style="font-family:Courier New;">}</span><br />
<span style="font-family:Courier New;"></span></p></blockquote>
<p>This style is certainly the most succinct way of connecting a component to a set of signals however it is usually seen as a more error prone way since the signals can easily be miss-ordered.</p>
<h3>   <font size="4">Summary</font></h3>
<p>This tutorial covered the basic uses of ports in a SystemC model. Ports are part of modules and are used to connect modules together via signals (channels). In this tutorial wefocused on the predefined SystemC ports however, most commonly the user creates it’s own port kind defining it’s own set of messages that can be exchanged on those ports. The subject of user defined port we be covered in an other tutorial.</p>
<p>The pdf file and the source files for this tutorial can be found <a href="http://www.esperan.com/tutorial.html#sysc" title="Tutorials page" target="_blank">HERE</a>.</p>
<p>David Cabanis.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/41/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/41/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=41&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2006/10/20/systemc-tutorial-ports/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
		<item>
		<title>SystemC Tutorial: modules</title>
		<link>http://sclive.wordpress.com/2006/09/08/systemc-tutorial-modules/</link>
		<comments>http://sclive.wordpress.com/2006/09/08/systemc-tutorial-modules/#comments</comments>
		<pubDate>Fri, 08 Sep 2006 15:42:49 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[SytemC Tutorials]]></category>

		<guid isPermaLink="false">http://sclive.wordpress.com/2006/09/08/systemc-tutorial-modules/</guid>
		<description><![CDATA[Forewords
These tutorials do not try to teach you everything about SystemC in large chapters taken from the language reference manual (LRM). Instead they focus on the most important aspects of the language, basic and advanced covering them in tutorials designed to take around ten minutes each.
Modules
A module is a C++ class - it encapsulates a [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3><font size="4">Forewords</font></h3>
<p>These tutorials do not try to teach you everything about SystemC in large chapters taken from the language reference manual (LRM). Instead they focus on the most important aspects of the language, basic and advanced covering them in tutorials designed to take around ten minutes each.</p>
<h3><font size="4">Modules</font></h3>
<p>A module is a C++ class - it encapsulates a hardware or software description. SystemC defines that any module has to be derived from the existing class sc_module. SystemC modules are analogous to Verilog modules or VHDL entity/architecture pairs, as they represent the basic building block of a hierarchical system. By definition, modules communicate with other modules through channels and via ports. Typically a module will contain numerous concurrent processes used to implement their required behaviour.</p>
<p>The following code illustrates the creation of the simplest of modules:</p>
<blockquote><p><span style="font-family:Courier New;">1 // module tutorial</span><br />
<span style="font-family:Courier New;">2 SC_MODULE(module_test) {</span><br />
<span style="font-family:Courier New;">3   SC_CTOR(module_test) {</span><br />
<span style="font-family:Courier New;">4       cout &lt;&lt; &#8220;This is my first module&#8221; &lt;&lt; endl;</span><br />
<span style="font-family:Courier New;">5   }</span><br />
<span style="font-family:Courier New;">6 };</span><br />
<span style="font-family:Courier New;"></span></p></blockquote>
<p><span style="font-family:Courier New;"><br />
<span style="font-family:Verdana;">As can be observed two predefined macros have been used namely: SC_MODULE and SC_CTOR. As a result, the SystemC code resembles other hardware description languages such as Verilog.<br />
Although using predefined macros is seen as convenient by someone coming to SystemC from an HDL background, this would look totally alien to someone comming from a software programming background. Additionally, using this simplistic coding style hides the true nature of SystemC, that is C++.<br />
As a result a we will rewrite the previous code using a more C++ oriented style:</span></span></p>
<blockquote><p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">1 class module_test: public sc_module {</span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">2 public:</span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">3   module_test(sc_module_name nm): sc_module(nm)</span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">4   {</span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">5       cout &lt;&lt; &#8220;This is my first module&#8221; &lt;&lt; endl;</span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">6   }</span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">7 };</span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"></span></span></span></p></blockquote>
<p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><br />
<span style="font-family:Verdana;">This latest version requires a few clarifications to understand some of the subtleties of SystemC.<br />
First, the creation of a SystemC module requires the inheritance of a specialized class called sc_module.  This class defines common features found in any module such as their names. As you would expect the sc_module class feature some more complex elements that are beyond the scope of this tutorial.<br />
The second observation that we can make is the existance of the function: module_test. This function is known in C++ as a constructor and is typically used to perform variables initialization. The other important role of the C++ constructor is to make sure that all the parents used by the current class have been initialized too. In the case of a SystemC module it&#8217;s parent class is always the sc_module class. As a result the constructor module_test has to initialise the class sc_module. Thankfully, the only part of the sc_module class that needs to be initialized is it&#8217;s name of type: sc_module_name. Therefore the following code: </span></span></span></span><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">module_test(sc_module_name nm) <span style="font-family:Verdana;">defines a parameter for the constructor function called nm of type sc_module_name and then uses that parameter to initialize the parent class by passing it to the constructor of the sc_module class with this semantic: </span></span></span></span><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">sc_module(nm)<span style="font-family:Verdana;">.</span></span></span></span></p>
<h3><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;">Module Instances</span></span></span></span></h3>
<h3><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"></span></span></span></span></h3>
<p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;">A module by itself isn&#8217;t of much use until we start creating instances of it. To create an instance of a module we use a semantics very similar to existing HDLs like Verilog:</span></span></span></span></p>
<blockquote><p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">module_test module_test_1(&#8221;module_test_1&#8243;);</span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"></span></span></span></span></span></p></blockquote>
<p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><br />
<span style="font-family:Verdana;">Where, module_test is the type of the instance, module_test_1 is the logical name of the instance and &#8220;module_test_1&#8243; is the name (string) passed to the constructor of the module_test class. This name according to the previous discussion is of type sc_module_name. As can be observed, the sc_module_name data type is very similar to a string data type.<br />
To put this module instance in context, the following code will illustrate how a module can be instantiated inside the main function of a SystemC program (sc_main):</span></span></span></span></span></span></p>
<blockquote><p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">1 // Main program</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">2 int sc_main(int argc, char* argv[])</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">3 {</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">4   module_test module_test_1(&#8221;module_test_1&#8243;);</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">5   sc_start();</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">6   return (0);</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">7 }</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"></span></span></span></span></span></span></p></blockquote>
<p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><br />
The result from the following code would be:</span></span></span></span></span></span></p>
<blockquote><p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"> <span style="font-family:Courier New;">SystemC 2.2.05jun06_beta &#8212; Sep  9 2006 10:21:39</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">        Copyright (c) 1996-2006 by all Contributors</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">                    ALL RIGHTS RESERVED</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">This is my first module</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"></span></span></span></span></span></span></span></p></blockquote>
<p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><br />
A variation on the way that we create a module instance is by declaring a pointer to a module instead of a module. This method is commonly used to allocate the memory resources on the mass storage instead of the precious RAM. The following code illustrate this:</span></span></span></span></span></span></p>
<blockquote><p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">1 // Main program</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">2 int sc_main(int argc, char* argv[])</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">3 {</span><span style="font-family:Courier New;"></span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">4   module_test *module_test_1 =<br />
5      new module_test(&#8221;module_test_1&#8243;);</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">6   sc_start();</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">7   delete module_test_1;</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">8   return (0);</span></span></span></span></span></span></span><br />
9  <span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;">}</span></span></span></span></span></span></span><br />
<span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"></span></span></span></span></span></span></p></blockquote>
<p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;">In this example we used the <span style="font-style:italic;">new </span>instruction to allocate memory for a module_test instance and we assign the address of the memory location onto the pointer module_test.</span></span></span></span></span></span></p>
<h3><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"> Summary</span></span></span></span></span></span></h3>
<h3><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"></span></span></span></span></span></span></h3>
<p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"> This tutorial covered the use of SystemC&#8217;s modules. A module is a C++ class derived from an existing class: sc_module; consequenlty all SystemC modules require initialization to provide their parent class (sc_module) an expected name of type (sc_module_name).<br />
This tutorial also covered module instantiations, as demonstrated, instantiating a module is a simple afair all that is required is a logical name and a string.</span></span></span></span></span></span></p>
<p>The pdf file for this document and c++ code can be find <a href="http://www.esperan.com/tutorial.html#sysc" title="modules tutorial files" target="_blank">HERE</a>.</p>
<p>et Voila !</p>
<p>David Cabanis</p>
<p><span style="font-family:Courier New;"><span style="font-family:Verdana;"><span style="font-family:Courier New;"><span style="font-family:Verdana;"></span></span></span></span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/40/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/40/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=40&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2006/09/08/systemc-tutorial-modules/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
		<item>
		<title>SciTE Editor Module for SCLive</title>
		<link>http://sclive.wordpress.com/2006/08/10/scite-editor-module-for-sclive/</link>
		<comments>http://sclive.wordpress.com/2006/08/10/scite-editor-module-for-sclive/#comments</comments>
		<pubDate>Thu, 10 Aug 2006 17:36:25 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[Contributed Addon Modules]]></category>

		<guid isPermaLink="false">https://sclive.wordpress.com/2006/08/10/scite-editor-module-for-sclive/</guid>
		<description><![CDATA[Introduction
This module will allow you to use the much loved editor SciTE inside of SCLive. It’s a 1 Mb module.
Details
The module once installed will copy its content inside the directory: /usr/local/bin To use it, simply type on a console: SciTE 
Note: You may get some warning messages when the program is loading, this is expected [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><b>Introduction</b></p>
<p class="entry">This module will allow you to use the much loved editor SciTE inside of SCLive. It’s a 1 Mb module.</p>
<p><b>Details</b></p>
<p>The module once installed will copy its content inside the directory: /usr/local/bin To use it, simply type on a console: <b>SciTE </b></p>
<p>Note: You may get some warning messages when the program is loading, this is expected and you should not worry about them.<br />
<b>Downloading </b></p>
<p>The module can be downloaded <a href="http://www.openomy.com/download/systemclive/SciTE_1_66_stable.mo" title="SciTE module" target="_blank">HERE</a>.</p>
<p><b>Installing</b></p>
<p>The easiest way to install the module is to download it from within SCLive then type:</p>
<p><b>uselivemod ~/Desktop/</b><i>&lt;modulename.mo&gt;</i></p>
<p>Note: As I am sure you realize ~/Desktop is the default location for the downloaded files from firefox.</p>
<p>Alternatively you can add the module inside the /modules directory of your SCLive ISO file and burn a new ISO file.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=29&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2006/08/10/scite-editor-module-for-sclive/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
		<item>
		<title>VHDL Simulator Module for SCLive</title>
		<link>http://sclive.wordpress.com/2006/08/07/vhdl-simulator-module-for-sclive/</link>
		<comments>http://sclive.wordpress.com/2006/08/07/vhdl-simulator-module-for-sclive/#comments</comments>
		<pubDate>Mon, 07 Aug 2006 17:32:43 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[Contributed Addon Modules]]></category>

		<guid isPermaLink="false">https://sclive.wordpress.com/2006/08/07/vhdl-simulator-module-for-sclive/</guid>
		<description><![CDATA[Introduction
This module will allow you to use ghdl a free VHDL simulator with SCLive. It’s a 4 Mb module.
Details
The module once installed will copy its content inside the directory:  /usr/local/bin To use it, you can follow the ghdl tutorial located HERE.
Downloading 
The module can be downloaded HERE.
Installing
The easiest way to install the module is [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><b>Introduction</b></p>
<p class="entry">This module will allow you to use ghdl a free VHDL simulator with SCLive. It’s a 4 Mb module.</p>
<p><b>Details</b></p>
<p>The module once installed will copy its content inside the directory:  /usr/local/bin To use it, you can follow the ghdl tutorial located <a href="http://ghdl.free.fr/ghdl/A-full-adder.html#A-full-adder" title="GHDL Tutorial" target="_blank">HERE</a>.<br />
<b>Downloading </b></p>
<p>The module can be downloaded <a href="http://www.openomy.com/download/systemclive/ghdlmod.mo" title="GHDL module" target="_blank">HERE</a>.</p>
<p><b>Installing</b></p>
<p>The easiest way to install the module is to download it from within SCLive then type:</p>
<p><b>uselivemod ~/Desktop/</b><i>&lt;modulename.mo&gt;</i></p>
<p>Note: As I am sure you realize ~/Desktop is the default location for the downloaded files from firefox.</p>
<p>Alternatively you can add the module inside the /modules directory of your SCLive ISO file and burn a new ISO file.</p>
<p>Screenshot:</p>
<p><a href="http://sclive.files.wordpress.com/2006/08/ghdl.jpg" class="imagelink" title="ghdl_screenshot"><img src="http://sclive.files.wordpress.com/2006/08/ghdl.thumbnail.jpg" alt="ghdl_screenshot" /></a></p>
<p>Et voila!</p>
<p>David Cabanis.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=27&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2006/08/07/vhdl-simulator-module-for-sclive/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>

		<media:content url="http://sclive.files.wordpress.com/2006/08/ghdl.thumbnail.jpg" medium="image">
			<media:title type="html">ghdl_screenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>SystemC SCV Module for SCLive</title>
		<link>http://sclive.wordpress.com/2006/07/31/systemc-scv-module-for-sclive/</link>
		<comments>http://sclive.wordpress.com/2006/07/31/systemc-scv-module-for-sclive/#comments</comments>
		<pubDate>Mon, 31 Jul 2006 17:47:12 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[Contributed Addon Modules]]></category>

		<guid isPermaLink="false">https://sclive.wordpress.com/2006/07/31/systemc-scv-module-for-sclive/</guid>
		<description><![CDATA[Introduction
This module will allow you to use the SystemC Verification Library with SCLive. It’s a 4 Mb module.
Details
The module once installed will copy its content inside the directory:  /usr/local/systemc/systemc-2.1.v1
To use it, navigate to the examples directory inside the systemc-2.1.v1 directory and try the exemples inside the scv directory ( use make ).
Downloading 
The module can [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="entry"><b>Introduction</b></p>
<p>This module will allow you to use the SystemC Verification Library with SCLive. It’s a 4 Mb module.</p>
<p><b>Details</b></p>
<p>The module once installed will copy its content inside the directory:  /usr/local/systemc/systemc-2.1.v1<br />
To use it, navigate to the examples directory inside the systemc-2.1.v1 directory and try the exemples inside the scv directory ( use make ).</p>
<p><b>Downloading </b></p>
<p>The module can be downloaded <a href="http://www.openomy.com/download/systemclive/scv-10p2.mo" title="SCV module" target="_blank">HERE</a>.</p>
<p><b>Installing</b></p>
<p>The easiest way to install the module is to download it from within SCLive then type:</p>
<p><b>uselivemod ~/Desktop/</b><i>&lt;modulename.mo&gt;</i></p>
<p>Note: As I am sure you realize ~/Desktop is the default location for the downloaded files from firefox.</p>
<p>Alternatively you can add the module inside the /modules directory of your SCLive ISO file and burn a new ISO file.</p>
<p>Et voila!</p>
<p>David Cabanis.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=26&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2006/07/31/systemc-scv-module-for-sclive/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
		<item>
		<title>vim Module for SCLive</title>
		<link>http://sclive.wordpress.com/2006/07/28/vim-module-for-sclive/</link>
		<comments>http://sclive.wordpress.com/2006/07/28/vim-module-for-sclive/#comments</comments>
		<pubDate>Fri, 28 Jul 2006 16:14:37 +0000</pubDate>
		<dc:creator>sclive</dc:creator>
		
		<category><![CDATA[Contributed Addon Modules]]></category>

		<guid isPermaLink="false">https://sclive.wordpress.com/2006/07/28/vim-module-for-sclive/</guid>
		<description><![CDATA[Introduction
This module will allow you to edit files via the ubiquitous and adored vim program. It’s a 4.5 Mb module and worth every bits of it.
Details
The module once installed will copy its executable inside the /usr/local/bin directory.
To invoke vim, simply type: vim &#60;filename&#62;  as a command inside a terminal window.
Downloading 
The module can be [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="entry"><b>Introduction</b></p>
<p>This module will allow you to edit files via the ubiquitous and adored vim program. It’s a 4.5 Mb module and worth every bits of it.</p>
<p><b>Details</b></p>
<p>The module once installed will copy its executable inside the /usr/local/bin directory.</p>
<p>To invoke vim, simply type: <b>vim </b><i>&lt;filename&gt;</i>  as a command inside a terminal window.</p>
<p><b>Downloading </b></p>
<p>The module can be downloaded <a href="http://www.openomy.com/download/systemclive/Vim_VI_iMproved_7_0_Patch_17.mo" title="vim module" target="_blank">HERE</a>.</p>
<p><b>Installing</b></p>
<p>The easiest way to install the module is to download it from within SCLive then type:</p>
<p><b>uselivemod ~/Desktop/</b><i>&lt;modulename.mo&gt;</i></p>
<p>Note: As I am sure you realize ~/Desktop is the default location for the downloaded files from firefox.</p>
<p>Alternatively you can add the module inside the /modules directory of your SCLive ISO file and burn a new ISO file.</p>
<p>Et voila!</p>
<p>David Cabanis.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sclive.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sclive.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sclive.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sclive.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sclive.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sclive.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sclive.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sclive.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sclive.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sclive.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sclive.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sclive.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sclive.wordpress.com&blog=214105&post=25&subd=sclive&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sclive.wordpress.com/2006/07/28/vim-module-for-sclive/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/sclive-128.jpg" medium="image">
			<media:title type="html">sclive</media:title>
		</media:content>
	</item>
	</channel>
</rss>