<?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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eugene Hutorny &#187; PIC</title>
	<atom:link href="http://hutorny.in.ua/category/projects/pic/feed" rel="self" type="application/rss+xml" />
	<link>http://hutorny.in.ua</link>
	<description>Programming in a small</description>
	<lastBuildDate>Tue, 16 Mar 2010 07:25:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MIHA675 &#8211; Multi Input Hall Automaton</title>
		<link>http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton</link>
		<comments>http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton#comments</comments>
		<pubDate>Thu, 07 Dec 2006 15:59:25 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[PIC]]></category>
		<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton</guid>
		<description><![CDATA[Previous examples illustrated VELOOS  programming aspects. This post provides an example of using object oriented  paradigm for designing VELOOS application. Unlike the previous examples which  were purely programming exercises, this example is dedicated to a utilitarian  home appliance application and provides a &#34;reference design&#34; for  VELOOS applications.

Example3 &#8211; Designing MIHA [...]]]></description>
			<content:encoded><![CDATA[<p>Previous examples illustrated VELOOS  programming aspects. This post provides an example of using object oriented  paradigm for designing VELOOS application. Unlike the previous examples which  were purely programming exercises, this example is dedicated to a utilitarian  home appliance application and provides a &quot;reference design&quot; for  VELOOS applications.</p>
<p><span id="more-87"></span></p>
<h2>Example3 &ndash; Designing MIHA &ndash;  Multi Input Hall Automaton</h2>
<p></p>
<h3>Introduction</h3>
<p>There are two common approaches for light  switching in halls and staircases &ndash; off-timers and intermediate switching  schemes (please excuse me if terminology is wrong). Off timers turn light on when user pushes a button and turn off when specified time elapsed. Intermediate  switching schemes toggle lights when user toggles any switch (of two). Each  approach has its own advantages and disadvantages, however, both approaches  require special switches, which could be an undesired constraint for interior  design. See, for example, <a href="http://www.o2m8.com/modules.php?name=News&amp;file=article&amp;sid=32">Intermediate lighting switch</a>,&nbsp;<a href="http://www.tlc-direct.co.uk/Manufacturers/Contactum_Distribution/CMD_Controls_3/index.html">Stair case timer</a>,&nbsp;<a href="http://www.amidata.es/componentes-electronicos-es/circuitos-electricos/424356720-STAIRCASE-TIMER.html">Multifunction staircase timer</a></p>
<h3>Requirements (user&#8217;s needs)</h3>
<p>Implement a light-control appliance that:</p>
<ul>
<li>combines off-timer and  intermediate switchers</li>
<li>provides support for at least 3  switches</li>
<li>supports regular light switches  as well as push-buttons</li>
<li>provides settable 0.5-10 min  timer range with a simple user interface for entering value</li>
</ul>
<h3>MIHA Design Description</h3>
<p><u>Key Design Decisions:</u></p>
<ul>
<li>Implement the appliance (named  MIHA) as a VELOOS application running on a PIC microcontroller</li>
<li>Store application  configuration in EEPROM during device programming</li>
<li>Use potentiometer for  specifying timeout</li>
</ul>
<p><u>Architecture</u><br />
  MIHA consists of the following units (see  architecture diagram on Figure 1):</p>
<table border="1" cellspacing="0" cellpadding="0" style="border:solid gray .5pt;border-collapse:collapse;">
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">
      Multi-input Switch Debouncer </td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Reads and debounces switches, sends a    message on switch state changing. <br />
      Featuring triple port read with majority    logic and software implementation of RC-integration and Schmidt trigger.</td>
</tr>
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Hall Light Automaton</td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Implements automaton logic, provides    supports for switches/push-buttons, send &#8216;alt&#8217; message to actuator and &#8216;off&#8217;    message to the delay block</td>
</tr>
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Delay Time Input</td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Reads potentiometer value and sends the    value read to the delay block<br />
      Featuring support for multiple channels.    ADC access is arbitrated via time quantization</td>
</tr>
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Message Delay Block</td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Provides delay for the &#8216;off&#8217; message.</td>
</tr>
<tr>
<td width="196" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Discrete Actuator</td>
<td width="463" valign="top" style="border:solid gray .5pt;padding:0cm 4pt 0cm 4pt;">Turns on or off an output pin depending    on the message received</td>
</tr>
</table>
<table>
<tr>
<td rowspan="2">
<p><u>Mapping Architecture to Implementation.</u><br />
  Mapping from architectural units to  implementation units is straightforward &ndash; all MIHA units are directly mapped to  operating system objects, inter-unit communications are mapped to messaging. <br />
  All MIHA objects are configurable with  EEPROM data. To make design flexible, object configuration embeds acceptor  handle. The latter two decisions establish a generality which is captured as  two abstract classes:<br />
  PDO &ndash; a configurable Process Data Object<br />
  PDD &ndash; a dynamically bound PDO<br />
  (See class diagram on Figure 2)</p>
</td>
<td rowspan="2">&nbsp;</td>
<td height=57><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA-Architecture.png" target=_blank rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA-Architecture.thumbnail.png" alt="MIHA Architecture" height=57 border="0" id="MIHAArchitecture"/></a><br />Figure 1.</td>
</tr>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA-ClassDiagram.png" target=_blank rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA-ClassDiagram.thumbnail.png" alt="MIHA Class Diagram" name="image89" height=80 border="0" id="image89" /></a><br />Figure 2.</td>
</tr>
</table>
<h3>Moduling</h3>
<p>Major advantage provided by VELOOS is  ability to design and implement loosely coupled objects. The following practice  can be applied to get full advantage of loose coupling: </p>
<ul>
<li>A unit should be made up of (at  least) two files: (1) .inc containing interface and (2) .asm &ndash; implementation</li>
<li>Each unit should implement one  class or a hierarchy of closely related classes.</li>
<li>A unit should not instantiate  objects of reenterable or configurable classes. Instead it should publish class  name in the interface.</li>
<li>A unit may instantiate object  of a non-reenterable class. In this case it should publish object name and  encapsulate class name.</li>
</ul>
<h3>Sharing RAM among objects</h3>
<p>Decoupling objects via messaging mechanism  provides a very explicit and straightforward watershed for scoping variables &ndash; everything  that should survive between two messages is a part of object state and should  be allocated in udata section, everything that may be discarded after handling  the message is a temporary variable and can be allocated in udata_ovr section.</p>
<h3>Using Timer for Resource Access Arbitration</h3>
<p>Class Potentiometer Parameter Input (PPI)  implements time-quantified approach for sharing ADC among several instances &ndash; time  is sliced on N quants, each instance may access hardware only if TIME mod N  equals to channel number. To simplify computing TIME mod N, N can be chosen as  power of 2. In this example N = 16.</p>
<table>
<tr>
<td rowspan="4">
<h3>Multi-input Debouncer</h3>
<p>On timer event Debouncer  polls the port three times in a row and applies majority logic to determine current  switch state. This approach eliminates sporadic spikes than may be present in a  noisy environment. For each assigned pin it maintains a counter. This counter  is incremented whenever pin level is high and decremented if low. Counter is  maintained in range 0..16, e.g. when it reaches the boundary it is not changed.  When counter reaches upper threshold (12) logical output state is changed to 1  and to 0 when it reaches lower threshold. This is a software model of an RC-integration  connected to a Schmidt trigger.<br />Few samples of  switch bouncing are shown on figures on right. The switches are regular light switches  manufactured by VIKO.</p>
<h3>Hardware Schematic</h3>
<p>MIHA schematic is shown on Figure 6. Relay, loaded on PIC12, should have actuating current up to 25 mA. Resistors R1-R4 are used for pull-up and can be roughly 1 kOhm. In an environment with strong EMI their can be reduced to avoid pickup.</p>
<h3>Package Content</h3>
<p>The package includes three projects to build this application for three different devices &ndash; PIC12F675, PIC16F690, PIC18F248. It is licensed to public under the <a href="http://www.opensource.org/licenses/osl-3.0.php">Open Software   License<br />
</a><a id=p94 href="http://hutorny.in.ua/wp-content/uploads/2006/12/miha.v.1.0.zip">Download MIHA Sources v.1.0</a></p>
</td>
<td rowspan="4">&nbsp;</td>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/ON-Bouncing.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/ON-Bouncing.thumbnail.png" alt=ON-Bouncing.png height=39 border="0" id="image91" /></a><br />Figure 3.</td>
</tr>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/OFF-Bouncing.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/OFF-Bouncing.thumbnail.png" alt=OFF-Bouncing.png height=39 border="0" id="image92" /></a><br />Figure 4.</td>
</tr>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/Debounced.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/Debounced.thumbnail.png" alt=Debounced.png height=47 border="0" id="image93" /></a><br />Figure 5.</td>
</tr>
<tr>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA675.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/12/MIHA675.thumbnail.png" alt="MIHA Hardware Schematics" height=92 border="0" id="image90" /></a><br />Figure 6.</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VELOOS Example 3</title>
		<link>http://hutorny.in.ua/projects/pic/veloos/veloos-example-3</link>
		<comments>http://hutorny.in.ua/projects/pic/veloos/veloos-example-3#comments</comments>
		<pubDate>Wed, 06 Dec 2006 21:38:00 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/veloos/veloos-example-3</guid>
		<description><![CDATA[This example for PIC12F675 implements set of &#8220;actuators&#8221; and &#8220;generators&#8221; controlled via USART. Actuators produce one 300 ms pulse when it receives command &#8216;ON&#8217; and three 100 ms pulses delimited with 100 ms spaces (pauses) on command &#8216;OFF&#8217;. Generators, when turned on, produce pulses and spaces of the specified duration (1..255). 

Actuators and Generators are [...]]]></description>
			<content:encoded><![CDATA[<p>This example for PIC12F675 implements set of &#8220;actuators&#8221; and &#8220;generators&#8221; controlled via USART. Actuators produce one 300 ms pulse when it receives command &#8216;ON&#8217; and three 100 ms pulses delimited with 100 ms spaces (pauses) on command &#8216;OFF&#8217;. Generators, when turned on, produce pulses and spaces of the specified duration (1..255). </p>
<p><span id="more-84"></span></p>
<p>Actuators and Generators are implemented as instances of Actuator and Generator classes. Yet another class in this example   protocol driver   parses the incoming via software USART commands and forwards it to a corresponding object. Command format is: <strong>command</strong>[<strong>data</strong>,[<strong>data</strong>]]; COM port settings: 2400, 8bit no parity, 1 stop bits.<br />
USART is implemented in software and uses INT0 and TMR1 interrupts for timing bits.<br />
Command language consist of 8 commands (H..O)</p>
<ul>
<li>H,I,J   control an actuator, </li>
<li>K,L   control a generator, </li>
<li>N   all actuators do OFF, susped all generators</li>
<li>O   all actuators do ON, resume all generators.</li>
</ul>
<p>H,I,J commands accepts &#8216;0&#8242; and &#8216;1&#8242; as a parameter to execute OFF or ON command  respectively. K,L commands should be supplied with pulse and pause duration</p>
<p>For example:</p>
<ul>
<li>H0   Actuator 1 do OFF</li>
<li>LUA   Turn on generator 1 with 85 ms pulse and 65 ms space</li>
</ul>
<p><a id=p86 href="http://hutorny.in.ua/wp-content/uploads/2006/12/Example3.zip">Example 3 Sources</a></p>
<p>Hardware Scematics. Connect loads to GP0,GP1,GP4,GP5 (not shown on the schematic)</p>
<p><img id="image85" alt="Example 3 Hardware Schematics" src="http://hutorny.in.ua/wp-content/uploads/2006/12/Example3.png" /></p>
<p>Simulation Results</p>
<p><img id="image95" alt="Simulation Results" src="http://hutorny.in.ua/wp-content/uploads/2006/12/SIM-Example3.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/veloos/veloos-example-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VELOOS 1.0 released</title>
		<link>http://hutorny.in.ua/projects/pic/veloos/veloos-10-released</link>
		<comments>http://hutorny.in.ua/projects/pic/veloos/veloos-10-released#comments</comments>
		<pubDate>Mon, 20 Nov 2006 18:02:45 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/veloos/veloos-10-released</guid>
		<description><![CDATA[VELOOS is an object-oriented message-triggered cooperative operating system for 8-bit Microchip microcontrollers licensed to public under the Open Software License
Release 1.0 includes VELOOS kernel and two timer drivers (TMR0 and TMR2 based). It has been tested on the following devices: PIC12F675, PIC16F690, PIC18F248.
Download VELOOS v.1.0

Supporting other 14-bit core and 16-bit core devices
By design, VELOOS allocates [...]]]></description>
			<content:encoded><![CDATA[<p>VELOOS is an object-oriented message-triggered cooperative operating system for 8-bit Microchip microcontrollers licensed to public under the <a href="http://www.opensource.org/licenses/osl-3.0.php">Open Software License</a><br />
Release 1.0 includes VELOOS kernel and two timer drivers (TMR0 and TMR2 based). It has been tested on the following devices: PIC12F675, PIC16F690, PIC18F248.</p>
<p><a id=p83 href="http://hutorny.in.ua/wp-content/uploads/2006/11/veloos_v1_0.zip">Download VELOOS v.1.0</a></p>
<p><span id="more-82"></span></p>
<h3>Supporting other 14-bit core and 16-bit core devices</h3>
<p>By design, VELOOS allocates its message at the end of available banked (e.g. not shared) memory. Unfortunately, standard .inc does not include constants defining memory limits, therefore pic.inc refines &#8220;device model&#8221; and this refinement block has to be provided for each device to be used for a VELOOS application.</p>
<p>
<code><br />
&nbsp;ifdef __16F690<br />
&nbsp;&nbsp;include         "p16f690.inc"<br />
&nbsp;&nbsp;include         "pic16.inc"<br />
&nbsp;&nbsp;_pic&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= _pic16F690<br />
&nbsp;&nbsp;_pic_maxram&nbsp;&nbsp;&nbsp;&nbsp;= 016Fh       ; with shared bank excluded<br />
&nbsp;&nbsp;_pic_maxrom&nbsp;&nbsp;&nbsp;&nbsp;= 0FFFh<br />
&nbsp;&nbsp;_pic_maxeeprom&nbsp;= 0FFh<br />
&nbsp;endif<br />
</code></p>
<p>With this refinement, VELOOS is expected to work for any 16-bit core devices (PIC18), and any 14-bit core (most of PIC14 and some of PIC12). Perhaps, it may also work on 12-bit core (PIC10 and some of PIC12). However, since there are no interrupts, timer drivers can not be used. Also, these devices have severe memory constraints, which make use of OS unreasonable.</p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/veloos/veloos-10-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VELOOS Example 2</title>
		<link>http://hutorny.in.ua/projects/pic/veloos/veloos-example-2</link>
		<comments>http://hutorny.in.ua/projects/pic/veloos/veloos-example-2#comments</comments>
		<pubDate>Wed, 15 Nov 2006 15:30:06 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/veloos/veloos-example-2</guid>
		<description><![CDATA[This post continues series of examples and describes how VELOOS can be used for implementing time-triggered applications.

Example2 &#8211; Heartbeat Driven PDO



Design&#160;idea:
Enhance previous example with a timer and two PDOs processing timer messages. Use EEPROM to keep instance-specific data.


Value:
Gives a simple example of implementing (1) time-triggered PDOs, (2) reenterable classes. Implements a class which may be [...]]]></description>
			<content:encoded><![CDATA[<p>This post continues series of examples and describes how VELOOS can be used for implementing time-triggered applications.</p>
<p><span id="more-78"></span></p>
<h2>Example2 &#8211; Heartbeat Driven PDO</h2>
<p></p>
<table id="Table1" style="BORDER-COLLAPSE: collapse" cellSpacing="2" cellPadding="2" border="0">
<tr>
<td vAlign="top" align="right" width="111"><b>Design&nbsp;idea:</b></td>
<td vAlign="top" width="576">Enhance previous example with a timer and two PDOs processing timer messages. Use EEPROM to keep instance-specific data.</td>
</tr>
<tr>
<td vAlign="top" align="right" width="111"><b>Value:</b></td>
<td vAlign="top" width="576">Gives a simple example of implementing (1) time-triggered PDOs, (2) reenterable classes. Implements a class which may be used for debug purposes to watch system &quot;heartbeat&quot;. </td>
</tr>
</table>
<h3>Design Description</h3>
<p>This sample application implements two PDO each triggering port pin with a certain period: first PDO is on 1 sec period, second &#8211; on 1 ms. Since behavioral pattern of these PDO are the same, they were implemented as instances of the same class.</p>
<h3>Deploying VELOOS Timer Driver</h3>
<p>Timer Driver is a non-reenterable encapsulated PDO with an interrupt handler and internal counters for millisecond and seconds. To deploy a timer driver to VELOOS application, the project should include file vtm0.asm (Timer0 based) or vtm2.asm (Timer2 based). Timer constants are calculated automatically based on <code>_osc_clock</code>. Timer driver configures hardware timer for 1 ms interrupts. When a timer interrupts occurs, Interrupt Handler sends a broadcast message. Timer PDO counts 1ms messages and on every 1000-th broadcasts a 1s message. Both 1 ms and 1 s messages include current time value.</p>
<p>In a pseudo language messages can be declared as the following (acceptor field is not shown):</p>
<table border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse;border:none;">
<tr>
<td width="358" valign="top" style="border:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;"><code>struct VTMR_cMsgTimer1ms {&nbsp;<br />&nbsp;    byte&nbsp;&nbsp;&nbsp; msg_id;<br />
&nbsp;    word&nbsp;&nbsp;&nbsp; millisec; }<br /></code></td>
<td width="359" valign="top" style="border:solid windowtext 1.0pt;border-left:none;padding:0cm 5.4pt 0cm 5.4pt;"><code>&nbsp;struct VTMR_cMsgTimer1s {<br />
&nbsp;&nbsp;    byte&nbsp;&nbsp;&nbsp; msg_id;<br />
&nbsp;&nbsp;    word&nbsp;&nbsp;&nbsp; seconds; }</code></td>
</tr>
</table>
<p></p>
<h3>Handling Timer Messages</h3>
<p>Timer messages are regular VELOOS messages.  To handle a timer message, PDO should first recognize the message and then, if necessary, examine time delivered with the message and take appropriate action:</p>
<p><code style="text-align:left">MyHandler&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; FSR points to message ID field</span><br />
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">VTMR_cMsgIDTimer1ms</span></b><br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  INDF, W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; if message.msg_id &lt;&gt; VTMR_cMsgIDTimer1ms</span><br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; return</span><br />
&nbsp;&nbsp;&nbsp; incf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  FSR, F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; make FSR pointing to LSB of message data</span><br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  INDF, W<br />
&nbsp;&nbsp;&nbsp; andlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  0F0h<br />
&nbsp;&nbsp;&nbsp; xorlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  007h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; on 7-th msec of every 16 msec</span><br />
&nbsp;&nbsp;&nbsp; skpnz<br />
&nbsp;&nbsp;&nbsp; return<br />
&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; do something</span><br />
  </code>
</p>
<h3>Targeting Reenterability</h3>
<p>To make a class reenterable, it should not be build-time-bound to any resource. This sample class achieves reenterability by using <i>This</i> as a pointer to EEPROM data with configuration (message ID, port mask) assigned to a particular class instance. In run-time PDO reads data from EEPROM on per need basis (e.g. does not cache in in registers). Since message ID is also stored in EEPROM, message handler first reads message ID from EEPROM and then message is processed:</p>
<p><code style="text-align:left">TmrHandler<br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">This</span></b>, W<br />
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;EE_read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">;  W = EEPROM[This]; //(== msgid)</span><br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  INDF, W<br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return<br /></code></p>
<p>With this design, class should be properly instantiated, e.g. object data should point to the configuration location in EEPROM. This can be achieved with use of a label, placed in EEPROM section:</p>
<p><code style="text-align:left">DEEPROM code<br />
On1mSecData&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; Configuration name</span><br />
&nbsp;&nbsp; de&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">VTMR_cMsgIDTimer1ms</span></b>, .1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="COLOR: green">; Configuration data</span><br />
<b><span style="COLOR: #333399">VOS_Objects</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; Object registry begins</span><br />
On1mSec&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; Object name (not necessary for this example)</span><br />
&nbsp;&nbsp; <b><span style="COLOR: #333399">VOS_mPersistentObject</span></b> MyTimer, On1mSecData <span style="COLOR: green">; Instance on MyTimer constructed with</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: green">;object data pointing  to configuration</span></code></p>
<h3>Building the project</h3>
<p>All classes and objects for this example (except Timer) are declared, implemented and instantiated in one file: main.asm. Although this is not a recommended practice, this example, for simplicity, gives it this way. Moduling aspects will be discussed in a subsequent example.</p>
<p>A package with sources for this example can be downloaded <a href="http://hutorny.in.ua/wp-content/uploads/2006/11/VELOOS-Example2.zip">on this link</a>. It includes the following files:</p>
<table id="Table3" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" border="1">
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>Example2.mcp</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">MP LAB project file</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>main.asm</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Example2 application sources</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>pic.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Processor-specific primitives, macros and includes</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>pic16.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">PIC16/PIC12 specific primitives</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos.asm</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS kernel</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS public interface</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos_cfg.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS configuration file</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vtm2.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Timer public interface</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vtm2_m.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Timer auxiliary macros</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vtm2.asm</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Timer implementation</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>16f690.lkr</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS specific linker script</td>
</tr>
</table>
<p><a href="http://hutorny.in.ua/wp-content/uploads/2006/11/VELOOS-Example2.zip">Download sources</a></p>
<table>
<tr>
<td rowspan="2">
<h3>Running the application</h3>
<p>This application was loaded to PIC16F690 on &quot;Low  Pin Count Demo Board&quot; supplied with PICkit&trade; 2. Activity of 1s driven object can be visually monitored with a led. Activities of other objects (1ms  and self-triggering) can be monitored aurally, for example  by connecting a  headset, or with a scope. Signals from RC2 and RC3 were captured with  Simplescope and their traces are shown on Figure 1 and Figure 2. As results  show, in the first run 1 ms period was actually shorter&nbsp; &#8211; 970 us instead of 1000. Therefore, for the  next run internal oscillator has been tuned with -4 value. Traces indicate that  1 ms period varies 1000-1080 ms &ndash; this is an expected effect of message  queuing.</p>
</td>
<td>&nbsp;</td>
<td width=90 align="center"><a target=_blank href="http://hutorny.in.ua/wp-content/uploads/2006/11/Example2-Timing.png" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/11/Example2-Timing.thumbnail.png" alt="Timing of sampled signals" name="image80" height=37 border="0" id="image80" /></a><br />
  Figure 1</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><a target=_blank href="http://hutorny.in.ua/wp-content/uploads/2006/11/Example2-Timing2.png" rel="thumbnail"><img id="image81" height=37 alt="Timing of sampled signals (adjusted)" src="http://hutorny.in.ua/wp-content/uploads/2006/11/Example2-Timing2.thumbnail.png" /></a><br />
      <span align="center">Figure 2</span></td>
</tr>
</table>
<h3>Application Source</h3>
<p><code style="text-align:left">&nbsp;<br /><span style="COLOR: green">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; License:&nbsp;&nbsp; Licensed to public under the Open Software License</span><br /><span style="COLOR: green">;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.opensource.org/licenses/osl-3.0.php"><span style="COLOR: green; TEXT-DECORATION: none; text-underline: none">http://www.opensource.org/licenses/osl-3.0.php</span></a><br />&nbsp;include "pic.inc"<br />&nbsp;include "vos.inc"<br />&nbsp;<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;__CONFIG&nbsp;_WDT_ON&nbsp;&amp;&nbsp;_INTRC_OSC_NOCLKOUT&nbsp;&amp;&nbsp;_CP_OFF&nbsp;&amp;&nbsp;_PWRTE_ON &amp;&nbsp;_MCLRE_ON&nbsp;&amp;&nbsp;_FCMEN_OFF&nbsp;&amp;&nbsp;_BOR_OFF&nbsp;&amp;&nbsp;_IESO_OFF<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
&nbsp;constant mask&nbsp;&nbsp;= 02h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; mask to be used for driving port (RA1)</span><br />
&nbsp;constant msgid = 040h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; message ID</span><br />
&nbsp;constant mask1ms&nbsp;= 04h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; mask to be used for driving port on 1 msec event (RC2)</span><br />
&nbsp;constant mask1s&nbsp;&nbsp;= 08h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; mask to be used for driving led  (RC3) &nbsp;</span><br />
  <b><span style="COLOR:#333399">VOS_Classes</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Class definitions begin</span><br />
  MyClass <b><span style="COLOR: #333399">VOS_mClass</span></b> MyHandler,&nbsp;MyInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; MyClass implementes MyHandler and MyInit methods</span><br />
  MyTimer <b><span style="COLOR: #333399">VOS_mClass</span></b> TmrHandler, TmrInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; MyTimer implementes TmrHandler, TmrInit</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Class definitions end with beginning of the next code section</span><br />
  <b><span style="COLOR:#333399">VOS_Objects</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Object registry begins</span><br />
MyObject<br />
&nbsp; <b><span style="COLOR:#333399">VOS_mPersistentObject</span></b>&nbsp;MyClass,&nbsp;mask&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style="COLOR: green">; Instance of MyClass constructed with object data == mask</span><br />
On1mSec<br /> <br />
&nbsp; <b><span style="COLOR:#333399">VOS_mPersistentObject</span></b> MyTimer,On1mSecData<span style="COLOR: green">; Instance on MyTimer constructed with object data pointing</span><br /> <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; to EERPOM location</span><br />
On1Sec<br />
&nbsp;  <b><span style="COLOR:#333399">VOS_mPersistentObject</span></b> MyTimer,On1SecData  <span style="COLOR: green">; Another instance on MyTimer</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Object registry ends with beginning of the code next section</span><br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
  <br />
  DEEPROM code<br />
On1mSecData     <br />
&nbsp; de      <b><span style="COLOR:#333399">VTMR_cMsgIDTimer1ms</span></b>, mask1ms<br />
On1SecData<br />
&nbsp; de      <b><span style="COLOR:#333399">VTMR_cMsgIDTimer1s</span></b>, mask1s<br />
  <span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
  &nbsp;&nbsp;&nbsp; code  <br />
MyInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; This was loaded with object data</span><br />
&nbsp;&nbsp;&nbsp; comf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><span style="COLOR:#333399">This</span></b>,&nbsp;W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; W := ~mask</span><br />
  <br />
  &nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp; TRISA<br />&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRISA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Prepare port for output</span><br />&nbsp;&nbsp;&nbsp; <b><span style="COLOR:#333399">VOS_mPostMessage</span></b>&nbsp;MyObject,&nbsp;msgid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; post message to itself</span><br />
&nbsp;&nbsp;&nbsp; return<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />&nbsp;<br />
MyHandler&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; FSR points to message ID field, This is loaded with object data</span><br />&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msgid<br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDF,&nbsp;W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; if message.msg_id &lt;&gt; msgid</span><br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; return</span><br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="COLOR: #333399">This</span></b>,&nbsp;W<br />&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; PORTA<br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTA,&nbsp;F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Toggle port</span><br />
&nbsp;&nbsp;&nbsp; <b><span style="COLOR: #333399">VOS_mPostMessage </span></b>MyObject,&nbsp;msgid&nbsp;&nbsp; &nbsp; &nbsp; <span style="COLOR: green">; post message to itself</span><br />
&nbsp;&nbsp;&nbsp; return<br /><span style="COLOR: green">;------------------------------------------------------------------------------</span></p>
<p>EE_read<br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  EEADR<br />
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EEADR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; EEADDR = This</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  EECON1<br />
&nbsp;&nbsp;&nbsp; bsf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EECON1,&nbsp;RD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; EE Read</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  EEDATA<br />
&nbsp;&nbsp;&nbsp; movfw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EEDATA <br />
&nbsp;&nbsp;&nbsp; return<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
TmrHandler<br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">This</span></b>, W<br />
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EE_read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; W = EEPROM[This] == msgid</span><br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  INDF, W<br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return<br />
&nbsp;&nbsp;&nbsp; incf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">This</span></b>, W<br />
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EE_read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; W = EEPROM[This+1] == mask</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  PORTC<br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  PORTC, F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; Toggle   PORT</span><br />
&nbsp;&nbsp;&nbsp; return&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span></p>
<p>TmrInit<br />
&nbsp;&nbsp;&nbsp; incf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b><span style="COLOR: #333399">This</span></b>, W<br />
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  EE_read&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:green; ">; W =  EEPROM[This+1] == mask</span><br />
&nbsp;&nbsp;&nbsp; xorlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  0FFh&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; W = ~mask</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;  TRISC<br />
&nbsp;&nbsp;&nbsp; andwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  TRISC, F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green; ">; Prepare port for output according to mask</span><br />
&nbsp;&nbsp;&nbsp; return<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
<b><span style="COLOR: #333399">VOS_BootHandlers</span></b> code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; starts a section for the application boot handler</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; ANSEL<br />
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANSEL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<span style="COLOR: green">; Turn all pints to digital</span><br />
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANSELH<br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; OSCCON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Set Fosc = 8Mhz</span><br />
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (.7 &lt;&lt; IRCF0)<br />
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OSCCON<br />
&nbsp;&nbsp;&nbsp; banksel     &nbsp;&nbsp;&nbsp; OSCTUNE     <br />
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; -.4<br />
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; OSCTUNE <br />
&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; !!! NO RETURN ALLOWED !!!</span><br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
&nbsp;end<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/veloos/veloos-example-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VELOOS Example 1</title>
		<link>http://hutorny.in.ua/projects/pic/veloos/veloos-example-1</link>
		<comments>http://hutorny.in.ua/projects/pic/veloos/veloos-example-1#comments</comments>
		<pubDate>Fri, 10 Nov 2006 14:17:15 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/veloos/veloos-example-1</guid>
		<description><![CDATA[The previous post gave a brief introduction to VELOOS design idea. VELOOS assumes that an application is decomposed on PDOs (Process Data Objects). This post describes by example features provided by VELOOS for implementing PDO.

Self-triggering PDO



Design&#160;idea:
Implement a PDO sending a message to itself. On every message received toggle a pin.


Value:
Provides a simple example of PDO [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://hutorny.in.ua/projects/pic/very-low-overhead-operating-system">previous post</a> gave a brief introduction to VELOOS design idea. VELOOS assumes that an application is decomposed on PDOs (Process Data Objects). This post describes by example features provided by VELOOS for implementing PDO.</p>
<p><span id="more-75"></span></p>
<h2>Self-triggering PDO</h2>
<p></p>
<table id="Table1" style="BORDER-COLLAPSE: collapse" cellSpacing="2" cellPadding="2" border="0">
<tr>
<td vAlign="top" align="right" width="111"><b>Design&nbsp;idea:</b></td>
<td vAlign="top" width="576">Implement a PDO sending a message to itself. On every message received toggle a pin.</td>
</tr>
<tr>
<td vAlign="top" align="right" width="111"><b>Value:</b></td>
<td vAlign="top" width="576">Provides a simple example of PDO implementation.<br />Implements a metric for measuring/estimating system throughput.</td>
</tr>
</table>
<p>Implementing a PDO for VELOOS requires three steps:</p>
<ul>
<li>Declaring a class</li>
<li>Implementing message handler and initializer</li>
<li>Instantiating an object</li>
</ul>
<h3>Declaring a class</h3>
<p>Class declaration sections starts with <i>VOS_Classes</i> macro and ends with beginning of any other section. As with regular MP ASM sections, there is no explicit &#8217;section end&#8217; therefore it is important to properly delimit class declaration sections. A source file may have only one class declaration sections (MP ASM constraints).</p>
<p>Within class declaration section, a class is declared <i>VOS_mClass</i> macro. The macro should be preceded with a class name &#8211; a valid MP ASM label. This macro generates the class&#8217;s dispatch table. It accepts two labels as parameters: message handler and initialization handler. These labels should be known in this module (e.g. defined in the same module or imported with extern directive).</p>
<p><code style="text-align:left"><br />
<b><span style="COLOR: #333399">VOS_Classes</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Class definitions begin</span><br />
MyClass <b><span style="COLOR: #333399">VOS_mClass</span></b> MyHandler,&nbsp;MyInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">;&nbsp;MyClass implementes MyHandler and MyInit methods</span><br />&nbsp;<br />
&nbsp;&nbsp;&nbsp; code<br />
MyInit<br />
&nbsp;&nbsp;&nbsp; ...<br />
&nbsp;&nbsp;&nbsp; return<br />
&nbsp;<br />
MyHandler<br />
&nbsp;&nbsp;&nbsp; ...<br />
&nbsp;&nbsp;&nbsp; return<br />
</code></p>
<h3>Instantiating an object</h3>
<p>Object instantiation section begins with <i>VOS_Objects</i> macro and ends with beginning of any other section. It accepts two parameters &#8211; class name and object data. Object data can be any 8-bit value. System does not make any assumption on it, it just loads this value to system variable <i>This</i>. Class name must be a label of a previously declared class. It should be known in this module.</p>
<p><code style="text-align:left"><br />
&nbsp;<br />
<b><span style="COLOR: #333399">VOS_Objects</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Object registry begins</span><br />
MyObject<br />&nbsp;<b><span style="COLOR: #333399">VOS_mPersistentObject</span></b> MyClass,&nbsp;0&nbsp;&nbsp;<span style="COLOR: green">;&nbsp;Instance of MyClass constructed with object data == 0</span><br />
&nbsp;<br />
</code></p>
<p>Objects can be instantiated in the same unit where class implemented or in a different unit. In latter case, class name should be exported with <i>global</i>directive.</p>
<h3>Note on Class Reenterability</h3>
<p>A reenterable class allows instantiating several objects. From the system point of view all classes are reenterable. Whether a particular class is reenterable or no depends on its design and implementation and it is up to developer to make such decision. To make a class reenterable, all resources it uses must be allocated by means of object data. PDO implemented in this example is not<br />
reenterable.</p>
<h3>Implementing a message handler</h3>
<p>Message handler is a subroutine, called by the OS when it finds a message addressed to this object or a broadcast message. On handler entrance <i>This</i> is loaded with object data and FSR is pointing to the message ID, so that the handler may compare INDF to a (set of) message ID(s) known to PDO. A PDO should process only know messages and ignore all others. Once the message is recognized, PDO may increment FSR and access message data (if necessary). In this example message has no custom data.</p>
<h3>Implementing an initializer</h3>
<p>Initializer is a subroutine, called by the OS on start-up (power up and reset events). On its entrance <i>This</i> is loaded with object data. Initializer is called for every instantiated object, therefore Initializer should prepare all registers or periphery used by this particular instance. If there is a need of some initialization code executed for all instances PDO should implement a boot handler.</p>
<h3>Sending a message</h3>
<p>VELOOS provides few macros for sending messages. Each of those macro &#8220;allocates&#8221; space for a new message, places acceptor handle, message ID, sender handle (in the last location). When it completes, FSR is pointing to custom data location,<br />
so that PDO may put message data if necessary.</p>
<table id="Table2" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" border="1">
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" align="center" width="154"><b>Macro</b></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" align="center" width="269"><b>Parameters</b></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" align="center" width="294"><b>Description</b></td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="154"><b><code><span style="COLOR: #333399">VOS_mPostMessage</span></code></b></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="269"><code>obj_to</code>&nbsp;- accepter handle<br />
<code>msg_id</code>&nbsp;- message ID</td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="294">Posts a message to a statically defined object. Both message ID and acceptor are defined at build time</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="154"><b><code><span style="COLOR: #333399">VOS_mBroadcastMsg</span></code></b></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="269"><code>msg_id</code>&nbsp;- message ID</td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="294">Posts a broadcast message. Message ID defined at build<br />
time</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="154"><b><code><span style="COLOR: #333399">VOS_mPostMsgIndir</span></code></b></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="269"><code>obj_ptr</code>&nbsp;  file containing accepter handle<br />
<code>msg_id</code>&nbsp;  message ID</td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="294">Posts a message to an object using handle stored in a file, e.g. Acceptor is defined at run time while message ID at build time</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="154"><b><code><span style="COLOR:#333399">VOS_mPostMsgDyn</span></code></b></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="269"><code>obj_ptr</code>&nbsp;  file containing accepter handle<br />
<code>msg_file</code>&nbsp;  file containing message ID</td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="294">Posts a message to an object using handle stored in a file and message ID stored in another file. Both acceptor and message ID are defined at run time</td>
</tr>
</table>
<p>In this example only one form is used:</p>
<p><code style="text-align:left">&nbsp;&nbsp;&nbsp; <b><span style="COLOR: #333399">VOS_mPostMessage</span></b> MyObject,&nbsp;2&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; post message to MyObject</span><br />
&nbsp;<br /></code></p>
<h3>Implementing a boot handler</h3>
<p>Boot handler is a fragment of code executed by the system on start-up. It is not related with any class or object. A boot handler is implemented by placing code to <i>VOS_BootHandlers</i> section. Since an asm file may have only one occurrence of a section name there could be only one boot handler in a source asm file. However, application that consists of many files may have many boot handlers. Order of execution is not known and not fixed, therefore the code should not relay on any particular order. When boot handler is executed objects are not initialized</p>
<p><code style="text-align:left"><br />
&nbsp;<br />
<b><span style="COLOR: #333399">VOS_BootHandlers</span></b> code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; starts a section for the application boot handler</span><br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; ANSEL<br />
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANSEL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">;&nbsp;Turn all pints to digital</span><br />
<br />
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANSELH<br />
&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;<br />
OSCCON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Set Fosc = 8Mhz</span><br />
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (.7 &lt;&lt; IRCF0)<br />
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OSCCON<br />
&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; !!! NO RETURN ALLOWED !!!</span><br />
</code></p>
<h3>Building the project</h3>
<p>A VELOOS project, to be properly built, should include VELOOS kernel (<code>vos.asm</code>) and VELOOS specific instructions in the linker script for the target device. Unfortunately, MP LAB does not support multiple lkr files (it just takes the first one) therefore changes have to be made in a copy of a standard .lkr file distributed with MP LAB.</p>
<p>VELOOS can be configured (fine tuned) at build time. All configurable parameters are given in a separate inc file.</p>
<p>A package with sources for this example can be downloaded on <a href="http://hutorny.in.ua/wp-content/uploads/2006/11/VELOOS-Example1.zip">this link</a>. It includes the following files:</p>
<table id="Table3" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" border="1">
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>Example1.mcp</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">MP LAP project file</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>main.asm</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Example1 application sources</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>pic.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">Processor-specific primitives, macros and includes</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>pic16.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">PIC16/PIC12 specific primitives</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos.asm</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS kernel</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS public interface</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>vos_cfg.inc</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS configuration file</td>
</tr>
<tr>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: windowtext 1pt solid; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="177"><code>16f690.lkr</code></td>
<td style="BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: windowtext 1pt solid" vAlign="top" width="540">VELOOS specific linker script</td>
</tr>
</table>
<p><a id=p77 href="http://hutorny.in.ua/wp-content/uploads/2006/11/VELOOS-Example1.zip">Download Example1 Sources</a></p>
<table>
<tr>
<td>
<h3>Simulation results</h3>
<p>Figure 1 shows Logic Analyzer trace (20000&nbsp;IC&nbsp;=&nbsp;10 ms). As it can be easily counted, this example processes 13 messages per millisecond with turnaround in about 150 IC. Any load on CPU will decrease this number (which will be illustrated in the next example). 150 IC per message can be considered as messaging overhead and should be accounted when designing time-critical applications.</p>
</td>
<td>&nbsp;</td>
<td><a target=_blank href="http://hutorny.in.ua/wp-content/uploads/2006/11/SIM-RA1-Trace.png" rel="thumbnail"><img id="image76" height=60 alt="Example1. Logic Analyzer Trace" src="http://hutorny.in.ua/wp-content/uploads/2006/11/SIM-RA1-Trace.thumbnail.png" /></a><br /><span align="center">Figure 1</span></td>
</tr>
</table>
<h3>Application Source</h3>
<p><code style="text-align:left"><br />
  &nbsp;<br /><span style="COLOR: green">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; License:&nbsp;&nbsp; Licensed to public under the Open Software License</span><br /><span style="COLOR: green">;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.opensource.org/licenses/osl-3.0.php"><span style="COLOR: green; TEXT-DECORATION: none; text-underline: none">http://www.opensource.org/licenses/osl-3.0.php</span></a><br />&nbsp;include "pic.inc"<br />&nbsp;include "vos.inc"<br />&nbsp;<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />&nbsp;__CONFIG&nbsp;_WDT_ON&nbsp;&amp;&nbsp;_INTRC_OSC_NOCLKOUT&nbsp;&amp;&nbsp;_CP_OFF&nbsp;&amp;&nbsp;_PWRTE_ON &amp;&nbsp;_MCLRE_ON&nbsp;&amp;&nbsp;_FCMEN_OFF&nbsp;&amp;&nbsp;_BOR_OFF&nbsp;&amp;&nbsp;_IESO_OFF<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
&nbsp;<br />
&nbsp;constant mask = .2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; mask to be used for driving port (RA1)</span><br />
&nbsp;constant msgid = 040h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; message ID</span><br />
  <br />
  &nbsp;<br />
  <b><span style="COLOR:#333399">VOS_Classes</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Class definitions begin</span><br />
  MyClass <b><span style="COLOR: #333399">VOS_mClass</span></b> MyHandler,&nbsp;MyInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; MyClass implementes MyHandler and MyInit methods</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Class definitions end with beginning of the next code section</span><br />
  <b><span style="COLOR:#333399">VOS_Objects</span></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Object registry begins</span><br />
MyObject<br />
&nbsp; <b><span style="COLOR:#333399">VOS_mPersistentObject</span></b>&nbsp;MyClass,&nbsp;mask&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style="COLOR: green">; Instance of MyClass constructed with object data == mask</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Object registry ends with beginning of the code next section</span><br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />
  <br />&nbsp;&nbsp;&nbsp; code<br />
MyInit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; This was loaded with object data</span><br />
&nbsp;&nbsp;&nbsp; comf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><span style="COLOR:#333399">This</span></b>,&nbsp;W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; W := ~mask</span><br />
  <br />&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; TRISA<br />&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRISA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Prepare port for output</span><br />&nbsp;&nbsp;&nbsp; <b><span style="COLOR:#333399">VOS_mPostMessage</span></b>&nbsp;MyObject,&nbsp;msgid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; post message to itself</span><br />
&nbsp;&nbsp;&nbsp; return<br />
<span style="COLOR: green">;------------------------------------------------------------------------------</span><br />&nbsp;<br />
MyHandler&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; FSR points to message ID field, This is loaded with object data</span><br />&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msgid<br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDF,&nbsp;W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; if message.msg_id &lt;&gt; msgid</span><br />
&nbsp;&nbsp;&nbsp; skpz<br />
&nbsp;&nbsp;&nbsp; return&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; return</span><br />
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="COLOR: #333399">This</span></b>,&nbsp;W<br />&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; PORTA<br />
&nbsp;&nbsp;&nbsp; xorwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTA,&nbsp;F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Toggle port</span><br />
&nbsp;&nbsp;&nbsp; <b><span style="COLOR: #333399">VOS_mPostMessage</span></b>MyObject,&nbsp;msgid&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; <span style="COLOR: green">; post message to itself</span><br />
&nbsp;&nbsp;&nbsp; return<br /><span style="COLOR: green">;------------------------------------------------------------------------------</span><br />&nbsp;<br />
<b><span style="COLOR: #333399">VOS_BootHandlers</span></b> code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; starts a section for the application boot handler</span><br />&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp; ANSEL<br />&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ANSEL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;<span style="COLOR: green">; Turn all pints to digital</span><br />&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ANSELH<br />&nbsp;&nbsp;&nbsp; banksel&nbsp;&nbsp;&nbsp;&nbsp;OSCCON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="COLOR: green">; Set Fosc = 8Mhz</span><br />&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (.7 &lt;&lt; IRCF0)<br />&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OSCCON<br />&nbsp;&nbsp;&nbsp; <span style="COLOR: green">; !!! NO RETURN ALLOWED !!!</span><br /><span style="COLOR: green">;------------------------------------------------------------------------------</span><br />&nbsp;<br />&nbsp;end<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/veloos/veloos-example-1/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Very Low Overhead Operating System</title>
		<link>http://hutorny.in.ua/projects/pic/very-low-overhead-operating-system</link>
		<comments>http://hutorny.in.ua/projects/pic/very-low-overhead-operating-system#comments</comments>
		<pubDate>Mon, 30 Oct 2006 00:47:14 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[PIC]]></category>
		<category><![CDATA[VELOOS]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/uncategorized/very-low-overhead-operating-system</guid>
		<description><![CDATA[VELOOS&#160;-&#160;Very&#160;Low&#160;Overhead&#160;Operating&#160;System
VELOOS is a message-triggered cooperative operating system designed to run in places were a large vehicles can not run. Its implementation for PIC12F takes less than 200 instructions and 20 data registers1. With addition of a timer driver, it becomes a time-triggered RTOS.


Preface
What is a real-time operating system in context of an MCU? First, it [...]]]></description>
			<content:encoded><![CDATA[<p>VELOOS&nbsp;-&nbsp;<b>Ve</b>ry&nbsp;<b>L</b>ow&nbsp;<b>O</b>verhead&nbsp;<b>O</b>perating&nbsp;<b>S</b>ystem</p>
<p>VELOOS is a message-triggered cooperative operating system designed to run in places were a large vehicles can not run. Its implementation for PIC12F takes less than 200 instructions and 20 data registers<a title="" href="#_ftn1" name=_ftnref1><sup><span style="FONT-SIZE: smaller">1</span></sup></a>. With addition of a timer driver, it becomes a time-triggered RTOS.</p>
<p><span id="more-74"></span></p>
<link rel="stylesheet" type="text/css" href="http://hutorny.in.ua/common/std.css" media="all"/>
<h2>Preface</h2>
<p>What is a real-time operating system in context of an MCU? First, it is an abstraction intended to share MCU resources among application components. Whatever abstraction is used in RTOS, it drives the application design &#8211; e.g. if a RTOS operates in terms of tasks, an application developer is obeyed to program application as a set of tasks. <br />
Secondly &#8211; it is a set of services which an application developer may/should use to make application operable and achieve the application goals. Most common abstraction for RTOS is a multitasking. Multitasking has several advantages, which make it very appealing, however it also has disadvantages which are even more noticeable in context of an MCU applications.</p>
<h3>Disadvantages of multitasking</h3>
<p>1. It is costly (high resource consuming)</p>
<p>Task switching requires saving and restoring task context, which includes stack, some system registers and some hardware SFR&#8217;s (such as status).</p>
<p>2. Inter-task communications even more costly</p>
<p>Tasks abstractions were designed for executing rather isolated and limited in time routines. Task communication and synchronization requires use of other abstractions, such as semaphores, pipes, etc. These<br />
communications/synchronizations features are usually accessible as functions and they are not trivial in implementation and use.</p>
<p>3. It is not well suitable for event driven applications</p>
<p>Many of MCU applications are event-driven &#8211; a particular application routine is executed on e response of an external event. When implementing such application with a multitasking, developer should map application requirements to available abstractions &#8211; e.g. decompose the application onto tasks. For an event-driven application this mapping is not trivial and creates unnecessary complications.</p>
<p>4. It is redundant</p>
<p>Multitasking assumes decomposing application on isolated or loosely coupled set of tasks which, due to nature of MCU applications, are implemented as infinite loops &#8211; every task implements an infinite loop. Memory allocated to a task usually is not used in other tasks, even if the task is in idle mode.</p>
<h2>Alternate RTOS abstraction</h2>
<p>Messaging is an alternate abstraction, which fits better for event-driven applications. With this abstraction an application is decomposed to set of process data objects (PDO) which receive and send messages in a response to other messages or external events, such as port change, periphery interrupts or timer.</p>
<p>Messaging provides a simple mechanism for both sharing CPU time and communicating among PDO&#8217;s. Despite messaging is also not a perfect abstraction, it requires fewer resources and needs implementation of very few and very simple abstractions &#8211; message, message queue, send message, and message handlers. All other abstractions and mechanism can be built with (on top of) these four and this is how VELOOS is designed and implemented.</p>
<h2>VELOOS description</h2>
<p>VELOOS design is based on few rather simple design decisions for establishing message processing. </p>
<h3>Terminology</h3>
<p>(It also reflects major design decisions)</p>
<table id=Table1 style="BORDER-COLLAPSE: collapse;" cellSpacing=0 cellPadding=0 border=0>
<tr>
<td vAlign=top width=140>
      <b><u>Message</u></b></td>
<td vAlign=top width=451>
A fixed-size set of sequential general-purpose registers. Message embeds accepter address, message ID and applications data. By default, message is 4 bytes long with 2 bytes available for custom data.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Message Queue</u></b></td>
<td vAlign=top width=451>
A circular buffer of fixed configurable size.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Send Message,<br />Post Message</u></b></td>
<td vAlign=top width=451>
A routine that accepts object handle and message ID, places them into the message area and returns indirect access register pointing to custom data locations. Messages are sent in asynchronous mode &#8211; sender does not wait until accepter processes the message.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Message Handler</u></b></td>
<td vAlign=top width=451>
A routine provided by application developer for processing messages. This routine is invoked by the system when it encounters a message addressed to the object.</td>
</tr>
<tr>
<td vAlign=top width=140>
      &nbsp;</td>
<td vAlign=top width=451>&nbsp;</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Addressing Modes</u></b></td>
<td vAlign=top width=451>
Messages can be addressed to a specific object (direct addressing) or to all registered objects (broadcast addressing). The latter one is indicated by use of a reserved object address &#8211; FF</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Broadcast Message</u></b></td>
<td vAlign=top width=451>
Message sent to all instantiated objects</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Object Address,<br />Handle</u></b></td>
<td vAlign=top width=451>
An 8-bit value uniquely identifying an object. In VELOOS, handle is a synonym of Object Address. VELOOS makes up handle values from lower octet of object entry address.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Object Entry</u></b></td>
<td vAlign=top width=451>
Pair {class&nbsp;pointer,&nbsp;object&nbsp;data} placed in the object registration section.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Object Instantiation</u></b></td>
<td vAlign=top width=451>
Predefined and required way of registering objects in the OS. It creates registration entry in the system and provides value for the object handle. Currently VELOOS implements only build-time object instantiation.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Object Initializer</u></b></td>
<td vAlign=top width=451>
An application routine provided by the application developer for initialization of registers and periphery used by a particular PDO instance. It is called on system startup.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Object Data</u></b></td>
<td vAlign=top width=451>
Any 8-bit value provided by the application developer and suitable for distinguishing among object instances. The system makes no assumption on object data value, it just loads it to system variable <b>This</b>.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Class</u></b></td>
<td vAlign=top width=451>
Set of entries/routines required for instantiating and operating an object &#8211; e.g. handler and initializer.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Class Entry</u></b></td>
<td vAlign=top width=451>
Pair of jumpers {goto&nbsp;handler,&nbsp;goto&nbsp;initializer} used for dispatching the system calls to an object</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Class Pointer</u></b></td>
<td vAlign=top width=451>
Lower octet of class entry address</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Class Definition</u></b></td>
<td vAlign=top width=451>
Predefined and required way of registering classes in the OS. It creates class entry in the system and provides value for the class pointer</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>VELOOS driver</u></b></td>
<td vAlign=top width=451>
Software that provides access to a shared resource and/or handles interrupts. A driver may consist of an object and an interrupt handler (IH)- a fragment of interrupt service routine.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Boot Handler</u></b></td>
<td vAlign=top width=451>
Fragment of application startup routine, provided by a PDO or driver for initializing of resources not associated with a particular PDO.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Interrupt Handler</u></b></td>
<td vAlign=top width=451>
Fragment of ISR provided by the application or a driver for handling concrete interrupt. Custom ISR are ordered and linked accordingly to (logical) priority assigned to it. VELOOS provides the prolog and epilog handlers, which provide context saving and restoring.</td>
</tr>
</table>
</p>
<h3>Principle of Operations</h3>
</p>
<table style="BORDER-COLLAPSE: collapse;" cellSpacing=0 cellPadding=0 border=0 ID="Table2">
<tr>
<td vAlign=top width=140>
      <b><u>System Startup</u></b></td>
<td vAlign=top width=451>
On reset, system executes internal startup routines, and application boot handler. Then system enumerates trough object registry and for each entry calls object initializer.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Interrupt Handling</u></b></td>
<td vAlign=top width=451>
On an interrupt, the prolog handler saves all critical SFRs in temporary registers. Then control is transferred to a next interrupt handler. IH check the interrupt source and if the source is proper, handles the interrupt. As a result of handling an interrupt, IH may post a message. If the source improper, IH skips its body. After all IH were executed, control is transferred to the epilog handler, which restores the context and exits the interrupt.</td>
</tr>
<tr>
<td vAlign=top width=140>&nbsp;</td>
<td vAlign=top width=451>&nbsp;</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Operating Mode</u></b></td>
<td vAlign=top width=451>
VELOOS points to the next message in the queue, retrieves accepter address from the message. If it is a broadcast message, system enters broadcast state. Otherwise, it enters Call Handler State.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Call Handler State</u></b></td>
<td vAlign=top width=451>
System loads the accepter&#8217;s class pointer to system variable <b>This_class</b> and object data to system variable <b>This</b> and calls the message handler. The message handler is expected to complete execution in a predefined timeframe. If it does not, system enters into timeout state. During processing a message, PDO may post message(s) to other objects, including message(s) to itself and broadcast messages. When the message queue is empty, system enters Idle state.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Broadcast State</u></b></td>
<td vAlign=top width=451>
VELOOS enumerates trough object registry and for each entry it calls corresponding handler.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Idle State (optional)</u></b></td>
<td vAlign=top width=451>
VELOOS maintains posts Idle message and calls handler for the next object. If the message queue is not empty after this call, system leaves idle state. VELOOS maintains a dedicated &#8216;next idle object&#8217; pointer, which is incremented after each handler is call for the idle message. This ensures that every PDO gets idle message.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Timeout State</u></b></td>
<td vAlign=top width=451>
If a PDO fails to handle message in the given timeframe, VELOOS will abort handler routine and proceed with the next message in the queue. VELOOS provides two optional mechanisms for controlling execution time &#8211; the hardware watchdog timer (WDT) and software WDT based on a timer driver. Both mechanisms may work simultaneously.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Message Queue Overflow</u></b></td>
<td vAlign=top width=451>
When the message queue is overflowed, system sets Queue Overflow flag and overwrites an existing message &#8211; the first in the queue.</td>
</tr>
<tr>
<td vAlign=top width=140>&nbsp;</td>
<td vAlign=top width=451>&nbsp;</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Time Triggering</u></b></td>
<td vAlign=top width=451>
Time triggering is implemented with a heartbeat broadcast message sent by a timer driver with fixed periodicity (1 ms by default). VELOOS timer drivers also have option for additional 1 sec heartbeat.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Time Intervals</u></b></td>
<td vAlign=top width=451>
VELOOS does not provide an explicit mechanism for controlling time intervals between object activations. PDOs are expected to watch for proper time interval via heartbeat, using either time value provided with the heartbeat message or using countdown approach.</td>
</tr>
<tr>
<td vAlign=top width=140>&nbsp;</td>
<td vAlign=top width=451>&nbsp;</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>VELOOS drivers</u></b></td>
<td vAlign=top width=451>
Currently VELOOS provides two drivers: TMR0 based timer driver and TMR2/CCP based timer driver.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Persistent Storage</u></b></td>
<td vAlign=top width=451>
VELOOS provides two options for storing object registry &#8211; ROM and EEPROM. Class registry is stored in ROM.</td>
</tr>
<tr>
<td vAlign=top width=140>
      <b><u>Call Back</u></b></td>
<td vAlign=top width=451>
Callback is a message sent back from the accepter to the sender. System places sender&#8217;s handle as the last byte in the message and if the PDO does not override it, the accepter may use this handle to send a message back.</td>
</tr>
</table>
</p>
<h2>VELOOS implementation</h2>
</p>
<p>VELOOS is designed and implemented in MP ASM language. Its primitives are implemented as ASM routines or macro.</p>
<h3>VELOOS requirements</h3>
</p>
<table style="BORDER-COLLAPSE: collapse;" cellSpacing=0 cellPadding=0 width=593 border=1 ID="Table3">
<tr>
<td vAlign=top width=253>
      <span style= "TEXT-ALIGN: right">PIC family</span><br />
      <span style= "TEXT-ALIGN: left">Feature</span></td>
<td vAlign=top width=113 align=center>
      <b><span style= "FONT-SIZE: larger">PIC12F675</span></b><br />
      program/data</td>
<td vAlign=top width=113 align=center>
      <b><span style="FONT-SIZE: larger">PIC16F690</span></b><br />
      program/data</td>
<td vAlign=top width=113>
<p style="TEXT-ALIGN: center" align=center><b><span style="FONT-SIZE: larger">PIC18F</span></b><br />
      program/data</p>
</td>
</tr>
<tr>
<td vAlign=top width=253>Bare operating system</td>
<td vAlign=top width=113 align=center>195/20</td>
<td vAlign=top width=113 align=center>220/20</td>
<td vAlign=top width=113 align=center>210/20</td>
</tr>
<tr>
<td vAlign=top width=253>Heartbeat Timer (1ms, 1s)</td>
<td vAlign=top width=113 align=center>75/7</td>
<td vAlign=top width=113 align=center>85/7</td>
<td vAlign=top width=113 align=center>70/7</td>
</tr>
<tr>
<td vAlign=top width=253>A definition of class (per class)</td>
<td vAlign=top width=113 align=center>2/0</td>
<td vAlign=top width=113 align=center>2/0</td>
<td vAlign=top width=113 align=center>2/0</td>
</tr>
<tr>
<td vAlign=top width=253>An object instance (per object)</td>
<td vAlign=top width=113 align=center>2/0</td>
<td vAlign=top width=113 align=center>2/0</td>
<td vAlign=top width=113 align=center>2/0</td>
</tr>
</table>
<p>&nbsp;</p>
<h2>Possible extensions</h2>
</p>
<h3>Simple Networking with VELOOS</h3>
<p>Messaging approach used by VELOOS allows implementing simple distributed computing in a simple and transparent way. First of all networking would need a network driver (a VELOOS class) that implements physical communication between MCU&#8217;s. This driver should be able to (1) filer incoming messages, (2) pack and send filtered messages via communication channel, (3) unpack messages coming from the communication channel and (4) post them to local message queue. Then, for every remote object application should instantiate a local proxy object (as an instance of network driver class). With this approach, an application can be easily distributed among several execution nodes (MCUs).</p>
<h3>Various object lifetime</h3>
<p>Currently the system implements only one lifetime scope for PDO. It is possible to extend this implementation for static objects (stored in ROM), persistent objects (stored in EEPROM), and dynamic objects (created in run-time and stored in RAM). </p>
<h3>Exception handling</h3>
<p>Currently the system has two exceptional situations (Handler&nbsp;Timed&nbsp;Out and Message&nbsp;Queue&nbsp;Overflowed) and provides no ability for changing behavior on these exceptions. VELOOS can be extended with exception handler support, by, for example, providing third jumper to the class entries, which would be called by the system when an exception occurs.</p>
<h3>Class and Object Directory</h3>
<p>Currently the system does not provide a mechanism for retrieving a list of classes and objects registered in the system. This feature can be implemented by class entry with additional jumper, which would return<br />
class/object identification data in for, for example, human-readable class/object names.</p>
<h2>Related Posts</h2>
<p><a href="http://hutorny.in.ua/projects/pic/veloos/veloos-example-1">VELOOS Example1 &#8211; Self-triggering PDO</a></p>
<p><a href="http://hutorny.in.ua/projects/pic/veloos/veloos-example-2">VELOOS Example2 &#8211; Heartbeat Driven PDO</a></p>
<p><a href="http://hutorny.in.ua/projects/pic/veloos/veloos-example-3">VELOOS Example3 &#8211; USART Controlled actuators and Generators</a></p>
<p><a href="http://hutorny.in.ua/projects/pic/miha675-multi-input-hall-automaton">MIHA675 &#8211; a sample VELOOS application</a></p>
<p><a href="http://hutorny.in.ua/veloos/">All VELOOS related</a></p>
<p><a href="http://hutorny.in.ua/wp-content/uploads/2006/11/veloos_v1_0.zip">Download VELOOS v.1.0</a></p>
<h2>Future Posts</h2>
<p>VELOOS sample application (planned)</p>
<p>VELOOS reference (planned)</p>
<div style="mso-element: footnote-list"><br clear=all/></p>
<hr align=left width="33%" SIZE=1/>
<div id=ftn1 style="mso-element: footnote">
<p class=MsoFootnoteText><a title="" style="mso-footnote-id: ftn1" href="#_ftnref1" name=_ftn1><sup><span style="FONT-SIZE: smaller">[1]</span></sup></a> Minimal configuration with broadcasting and message queue for 2 messages</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/very-low-overhead-operating-system/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple sampler as a &#8220;COM2&#8243; plugin</title>
		<link>http://hutorny.in.ua/projects/pic/sisam/simple-sampler-com2-plugin</link>
		<comments>http://hutorny.in.ua/projects/pic/sisam/simple-sampler-com2-plugin#comments</comments>
		<pubDate>Thu, 10 Aug 2006 17:38:18 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[SISAM]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/sisam/simple-sampler-com2-plugin</guid>
		<description><![CDATA[This post presents an alternate implementation of SISAM hardware &#8211; a &#8220;COM2&#8243; plug-in. It is designed for plugging in ahead of a bracket DB9 cable, usually used for accommodating a second serial port. This implementation uses a different MCU &#8211; PIC16F88, which allows the application to utilize 30% more RAM for the sampling buffer.

Capabilities
SISAM 88 [...]]]></description>
			<content:encoded><![CDATA[<p>This post presents an alternate implementation of SISAM hardware &#8211; a &#8220;COM2&#8243; plug-in. It is designed for plugging in ahead of a bracket DB9 cable, usually used for accommodating a second serial port. This implementation uses a different MCU &#8211; PIC16F88, which allows the application to utilize 30% more RAM for the sampling buffer.</p>
<p><span id="more-56"></span></p>
<h2>Capabilities</h2>
<p>SISAM 88 &#8211; provides the same set of <a href="http://hutorny.in.ua/projects/pic/sisam/sisam-overview#Capabilities">capabilities as SISAM 690</a> (differences are <u>underlined</u>/<del>strikethrough</del>):</p>
<ul>
<li><strong>S</strong>  &#8211; Sampling single logical channel &#8211; <u>RB2</u> <del>RB5</del> up to 500 ksps (kilo sample per sec)</li>
<li><strong>X</strong>   &#8211; Sampling dual logical channels <u>RB2, RB1</u> <del>RB5, RB4</del> up to 200 ksps per each channel</li>
<li><strong>J</strong>   &#8211; Limited buffered sampling sole channel @ 5 Msps (<u>2560</u> <del>1920</del> samples via internal buffer)</li>
<li><strong>M</strong>   &#8211; Measuring pulse timing on <u>RB3</u> <del>RC5</del> up to 12 kHz average,</li>
<li><strong>o</strong>   &#8211; drive (trigger) <u>four</u>&nbsp;<del>five</del> output pins right before (0.8us) sampling starts</li>
<li><strong>O</strong>   &#8211; drive (trigger) <u>four</u>&nbsp;<del>five</del> output pins immediately and/or in a sequence (20 us per data byte)</li>
</ul>
<p>In addition to mentioned above, SISAM can be used as a variable frequency generator (VFG). With the current firmware &#8211; as a side effect of <strong>S</strong> command (a separate command is planned for upcoming firmware updates)</p>
<h2>System requirements</h2>
<ul>
<li>High-speed serial port (such as <a href="http://leo.yuriev.ru/serialxp.exe">SerialXP</a>)</li>
<li>Triple power supply (+5VDC, +12VDC, -12VDC)</li>
</ul>
<h2>Schematics</h2>
<p>SISAM88 hardware schematic is given on Figure 1. It includes</p>
<ul>
<li>MCU PIC16F88 (U1)</li>
<li>20MHz crystal (X1)</li>
<li>RS232 level converter, build up on SN75150 line driver (U2), current-limiting resistors R1-R3, R6, a Zener diode D1 that prevents RA5/VPP from being pulled up to +12V.</li>
<li>Current-limiting resistors R4, R5 on input </li>
<li>Four connectors J1-J4.</li>
</ul>
<p>J2 is an angled 10 pin male IDC header identical to a COM2 connector on the motherboard.  J1 is an angled female IDC header mating with the COM2 connector. J3 is an angled 4 pins header mating with Mini-Molex power connector (FDD power). J4 is a 6 pins header compatible with your ICSP programmer (for example PICkit2).</p>
<p>
<div align="center"><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/SISAM88v1.1.png" target=_blank rel="thumbnail"><img id="image57" height=66 alt="SISAM v1.1/88" src="http://hutorny.in.ua/wp-content/uploads/2006/08/SISAM88v1.1.thumbnail.png" /></a></div>
</p>
<p>
<div align="center">Figure 1. SISAM 88 Hardware Schematics</div>
</p>
<p>Actuator outputs are connected to RA0-RA3.<br />
Wire RB4-RB5 delivers clock from EUSART to SSP. RB4 also serves as VFG output.</p>
<h2>External connectors</h2>
<p>Power &#8211; it is an altered FDD power connector. 12V ground header is pulled out of it and another header inserted instead. This header is wired to -12VDC.</p>
<table width="120" border="1" cellpadding="0" cellspacing="0" class="StdTable" style="border-collapse:collapse;border:none;">
<tr>
<th>Pin #</th>
<th>Description</th>
</tr>
<tr>
<td align ="center">1</td>
<td align ="center">+5V</td>
</tr>
<tr>
<td align ="center">2</td>
<td align ="center">-12V</td>
</tr>
<tr>
<td align ="center">3</td>
<td align ="center">GND</td>
</tr>
<tr>
<td align ="center">4</td>
<td align ="center">+12V</td>
</tr>
</table>
<p>Bracket DB9 &#8211; it is a standard COM2 bracket cable. In this design it is used as an input/output connector for connecting probes. Pin 5 on this connector is still used for ground to make it compatible with RS232 cables that may have it connected to the chassis. It make safe connecting a regular RS232 cable.</p>
<table width="480" border="1" cellpadding="0" cellspacing="0" class="StdTable" style="border-collapse:collapse;border:none;">
<tr>
<th>Pin #</th>
<th>Name</th>
<th>Direction</th>
<th>Description</th>
</tr>
<tr>
<td>1</td>
<td>CH1</td>
<td align ="center">In</td>
<td>CH1 sampler input</td>
</tr>
<tr>
<td>2</td>
<td>CH0</td>
<td align ="center">In</td>
<td>CH0 sampler input</td>
</tr>
<tr>
<td>3</td>
<td>GND</td>
<td align ="center">-</td>
<td>Signal ground</td>
</tr>
<tr>
<td>4</td>
<td>VFG</td>
<td align ="center">Out</td>
<td>VFG output</td>
</tr>
<tr>
<td>5</td>
<td>GND</td>
<td align ="center">-</td>
<td>Actuator ground</td>
</tr>
<tr>
<td>6</td>
<td>A3</td>
<td align ="center">Out</td>
<td>Actuator line 3</td>
</tr>
<tr>
<td>7</td>
<td>A2</td>
<td align ="center">Out</td>
<td>Actuator line 2</td>
</tr>
<tr>
<td>8</td>
<td>A1</td>
<td align ="center">Out</td>
<td>Actuator line 1</td>
</tr>
<tr>
<td>9</td>
<td>A0</td>
<td align ="center">Out</td>
<td>Actuator line 0</td>
</tr>
</table>
<p></p>
<h2>Firmware</h2>
<p><a id=p63 href="http://hutorny.in.ua/wp-content/uploads/2006/08/SISAM88v1.1.zip">SISAM v1.1/88 Firmware</a> is available for download.</p>
<p>Revision 1.1 includes the following changes<br />
1. Fixed defect with improper speed estimation for command r02;X0;</p>
<h2>Board</h2>
<p>Figure 2 shows the board layout (Scale 1:2). Discrete parts, which are not shown on this layout, are surface mount on the soldering side. PCB layout is not yet ready.</p>
<p>The board has some space reserved for the future upgrades.</p>
<p>
<div align="center"><img id="image58" height=277 width=372 alt="SISAM Board Layout" src="http://hutorny.in.ua/wp-content/uploads/2006/08/SISAM88v1.1board.png" /></div>
</p>
<p>
<div align="center">Figure 2. SISAM COM2 plug-in board</div>
</p>
<h2>ICSP</h2>
<p>PIC can be programmed in circuit; however, the device should be disconnected from power supply.</p>
<h2>Pictures</h2>
<p>
<table width="100%">
<tr>
<td width="25%"><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/DB9bracket.jpg" target=_blank rel="thumbnail"><img id="image59" height=96 alt="DB9 bracket" src="http://hutorny.in.ua/wp-content/uploads/2006/08/DB9bracket.thumbnail.jpg" /></a></td>
<td width="25%"><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/SISAM88-1m.jpg" target=_blank rel="thumbnail"><img id="image60" height=96 alt="SISAM board" src="http://hutorny.in.ua/wp-content/uploads/2006/08/SISAM88-1m.thumbnail.jpg" /></a></td>
<td width="25%"><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/SISAM88-2m.jpg" target=_blank rel="thumbnail"><img id="image61" height=96 alt="SISAM connected" src="http://hutorny.in.ua/wp-content/uploads/2006/08/SISAM88-2m.thumbnail.jpg" /></a></td>
<td width="25%"><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/COM2-plugin.jpg" target=_blank rel="thumbnail"><img id="image62" height=96 alt="SISAM in place" src="http://hutorny.in.ua/wp-content/uploads/2006/08/COM2-plugin.thumbnail.jpg" /></a></td>
</tr>
<tr>
<td>DB9 bracket</td>
<td>SISAM 88 board</td>
<td>Cables connected</td>
<td>SISAM in place</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Notice altered FDD power connector</td>
<td>&nbsp;</td>
</tr>
</table>
<p>See also: More about <a href="http://hutorny.in.ua/SISAM">SISAM</a>; <a href="http://hutorny.in.ua/projects/simplescope">Simplescope</a>; <a href="http://hutorny.in.ua/projects/w32/overclocking-com-port">Overclocking COM port</a>; <a href="http://hutorny.in.ua/downloads">Downloads</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/sisam/simple-sampler-com2-plugin/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speed tickets on RS232 Level Converters</title>
		<link>http://hutorny.in.ua/projects/tested-high-speed-rs232-level-converter</link>
		<comments>http://hutorny.in.ua/projects/tested-high-speed-rs232-level-converter#comments</comments>
		<pubDate>Wed, 02 Aug 2006 02:41:39 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[PIC]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[SISAM]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/tested-high-speed-rs232-level-converter</guid>
		<description><![CDATA[As practice has shown, simple level converter with -12V supply derived from DTR/RTS is not capable to work on high speed. Therefore I have made several tests on speed with the original PNP-based design and a RS232 line driver SN75150 and publish test results in this post. Test summary is given in Table 1.





Overview

Experiments were [...]]]></description>
			<content:encoded><![CDATA[<p>As practice has shown, simple level converter with -12V supply derived from DTR/RTS is not capable to work on high speed. Therefore I have made several tests on speed with the original PNP-based design and a RS232 line driver SN75150 and publish test results in this post. Test summary is given in <a href="#Table1">Table 1</a>.</p>
<p><span id="more-49"></span></p>
<style type="text/css">
<!--
.style1 {color: #666666}
.subs {
	font-size: smaller;
}
-->
</style>
<h2>
<p>Overview</p>
</h2>
<h3>Experiments were made with four RS232 Level Converter designs:</h3>
<ol>
<li>PNP Transistor, parasitic -12V</li>
<li>PNP Transistor + JFET current source, parasitic -12V</li>
<li>PNP Transistor, external -5V supply</li>
<li>SN75150 &#8211; Dual RS232 Line Driver</li>
</ol>
<h3>Test environment:</h3>
<ul>
<li>TTL output generated by SISAM in diagnostic mode </li>
<li>Converter loaded with 1.5m shielded cable (C?‰?100-300pF) + PC USART (Winbond)</li>
</ul>
<h3>Data verification methods:</h3>
<ul>
<li>watching and reporting framing error condition and</li>
<li>comparing received data to expected</li>
</ul>
<h3>Test tools:</h3>
<ul>
<li><a id=p51 href="http://hutorny.in.ua/wp-content/uploads/2006/08/SITEST.zip">SITEST</a> ??“ sends commands to SISAM and forwards data to stdout</li>
<li><a id=p50 href="http://hutorny.in.ua/wp-content/uploads/2006/08/LOOFI.zip">LOOFI</a> ??“ reads data from stdin and verifies the stream against the master pattern, made of the first <em>count</em> characters.</li>
</ul>
<p>Command lines for tests are the following</p>
<p><code><strong>SITEST</strong> /port=COM1 /count=640000 U03; > c:\temp\U03.txt<br />
<strong>LOOFI </strong>/count=224 /file=c:\temp\U03.txt</code></p>
<p>SITEST sends U03 command to SISAM. This command turns SISAM in diagnostic mode and SISAM sends sequences of characters 0&#215;20 to 0xFF using baudrate, specified in the command (U00 ??“ 115.2K, U03 ??“ 921.6K). SITEST saves data to file and aborts execution if a framing error is detected. Then LOOFI is used to verify data. </p>
<table>
<tr>
<td colspan="2">
<h2>1. Hardware loop test</h2>
<p>In this test RX and TX wires were connected on the free cable end and test data were send with a terminal application. Test has passed 460.8K and has failed on 921.6K ??“ wrong data received. </p>
</td>
</tr>
<tr>
<td>
<h2>2. PNP parasitic -12V</h2>
<p>Test has passed 230.4K and has failed on 460.8K with farming error. Oscilloscope has shown that falling edge is too sloping. I have tried to lower R1 and R2 and test has failed. I also tried to shorten the cable from 1.5 m to 0.3m and it did not make results any better. </p>
</td>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/RS232T2.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/08/RS232T2.thumbnail.png" alt="RS232 Test 2" name="image52" height=84 border="0" id="image52" /></a></td>
</tr>
<tr>
<td>
<h2>3. PNP+JFET parasitic -12V</h2>
<p>As a variation of previous design, I have replaced R2 with a 10mA current source made on BF245A. This did not make results any better. My explanation to this ??“ parasitic power is not a good power supply to drive even small capacitive load at that high speed.</p>
</td>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/RS232T3.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/08/RS232T3.thumbnail.png" alt="RS232 Test 3" height=85 border="0" id="image53" /></a></td>
</tr>
<tr>
<td>
<h2>4. PNP external -5V</h2>
<p>In this test the circuit was powered with??“5V external power supply. R1 and R2 were varied from 1K to 100 Ohm. The best results were achieved with speed R2=360 and R1=10K &#8211; Test has passed 460.8K and has failed on 921.6K with framing error.<br />
These resistor values cannot be used with parasitic power, because transistor&#8217;s collector current (Ic?‰?30 mA) is higher than can be derived from a single COM port line. </p>
</td>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/RS232T4.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/08/RS232T4.thumbnail.png" alt="RS232 Test 4" height=59 border="0" id="image54" /></a></td>
</tr>
<tr>
<td colspan="2">
<h2>5. PNP+JFET external -5V</h2>
<p>This design I did not try because it needs another type of JFET with I<span class="subs">DSS</span> current 30mA and I did not have it handy. </p>
</td>
</tr>
<tr>
<td>
<h2>6. SN75150</h2>
<p>SN75150 is a dual supply dual RS232 line driver. Despite SN75150 datasheet states maximal baud rate 120K, it works on 921.6K and the test has passed 921.6K.</p>
<p>I tried to power it with +5V and -12V parasitic power and it did not work at all.</p>
</td>
<td><a href="http://hutorny.in.ua/wp-content/uploads/2006/08/RS232T5.png" target="_blank" rel="thumbnail"><img src="http://hutorny.in.ua/wp-content/uploads/2006/08/RS232T5.thumbnail.png" alt="RS232 Test 5" height=44 border="0" id="image55" /></a></td>
</tr>
</table>
<table>
<h2>7. Summary on tests</h2>
<p>Table 1<a name="Table1" id="Table1"></a></p>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="0" class="StdTable" style="border-collapse:collapse;border:none;">
<tr>
<th>Test</th>
<th>Max baud rate</th>
</tr>
<tr>
<td>Hardware loop</td>
<td align="right">460.8K</td>
</tr>
<tr>
<td>PNP parasitic -12V</td>
<td align="right">230.4K</td>
</tr>
<tr>
<td>PNP parasitic -12V, 0.3m cable</td>
<td align="right">230.4K</td>
</tr>
<tr>
<td>PNP+JFET parasitic -12V</td>
<td align="right">230.4K</td>
</tr>
<tr>
<td>PNP external -5V</td>
<td align="right">460.8K</td>
</tr>
<tr>
<td>PNP+JFET external -5V</td>
<td><span class="style1">N/T</span></td>
</tr>
<tr>
<td>SN75150</td>
<td align="right">921.6K</td>
</tr>
<tr>
<td>SN75C3232</td>
<td class="style1">N/T</td>
</tr>
<tr>
<td>MAX3232</td>
<td class="style1">N/T</td>
</tr>
<tr>
<td>MAX232</td>
<td><span class="style1">N/T</span></td>
</tr>
</table>
<p><span class="style1">N/T</span> &#8211; Not tested</p>
<h2>6. Notes on driver selection</h2>
<p>In this chapter I provide my motivation for driver selection. </p>
<p>I have looked for drivers in <a href="http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sszt009b&amp;fileType=pdf">TI Interface Selection Guide</a>. None of 1000 kbps drivers were available from local dealers (besides those drivers are not cheap). Therefore I decided to take a 120K driver and &#8216;overclock&#8217; it. Considering that the current level is important for driving capacitive load, I limited my selection to dual supply chips. With these constraints I picked the smallest PDIP chip available locally and it happens to be SN75150. Its advantages: small footprint, very little overhead, level compatibility with PNP-based design, low price. Disadvantages ??“ necessity of dual power supply.</p>
<p>If dual power supply is not acceptable, you may try other drivers (such as <a href="http://focus.ti.com/docs/prod/folders/print/sn75c3232.html">SN75C3232</a>, MAX3232, MAX232). I would appreciate if you share your results with me.</p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/tested-high-speed-rs232-level-converter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple Environment for Automated Testing</title>
		<link>http://hutorny.in.ua/projects/pic/simple-environment-automated-testing-embedded-applications</link>
		<comments>http://hutorny.in.ua/projects/pic/simple-environment-automated-testing-embedded-applications#comments</comments>
		<pubDate>Mon, 17 Jul 2006 00:19:28 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[PIC]]></category>
		<category><![CDATA[SISAM]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/simple-environment-automated-testing-embedded-applications</guid>
		<description><![CDATA[This post describes how SISAM can be used to  build a simple environment for automated testing of embedded applications.

Overview
For developing applications with a long life  cycle it is very important to ensure that a new release contributes no regression  comparing to the previous release. This may become a challenge when an  [...]]]></description>
			<content:encoded><![CDATA[<p>This post describes how SISAM can be used to  build a simple environment for automated testing of embedded applications.</p>
<p><span id="more-46"></span></p>
<h2>Overview</h2>
<p>For developing applications with a long life  cycle it is very important to ensure that a new release contributes no regression  comparing to the previous release. This may become a challenge when an  application provides number of capabilities, operates in number of modes or  implements number of states. A common approach for addressing this challenge is  to establish an automated test environment.</p>
<p>Figure 1 shows a typical automated test  environment. It consists of</p>
<table>
<tr>
<td>
<ul>
<li>Batch Controller &ndash; a (software) component for running tests in a batch and aggregating overall batch  result</li>
<li>Test Tool &ndash; a component  that executes single tests and produce test outputs </li>
<li>Comparator &ndash; a component  that compares test outputs against masters and reports discrepancies</li>
<li>Test Cases Repository &ndash; a  storage of test batches, test cases, test input data and masters </li>
<li>Test Log Repository &ndash; a  storage of test output data and test discrepancies </li>
</ul>
</td>
<td>&nbsp;</td>
<td valign="top"><a href="http://hutorny.in.ua/wp-content/uploads/2006/07/TypicalTestEnvironment.png" target="_blank" rel="thumbnail"><img id="image47" height=85 alt="Typical Test Evironment" src="http://hutorny.in.ua/wp-content/uploads/2006/07/TypicalTestEnvironment.thumbnail.png" /></a><br />Figure 1</td>
</tr>
</table>
<p>Typical sequence of events for automated  testing:</p>
<ul>
<li>Actor uses Batch  Controller to start a specific test batch</li>
<li>Batch Controller reads  test cases that constitutes the batch </li>
<li>Batch Controller calls  Test Tool for executing a test case from the batch</li>
<li>Test Tool reads input  test data for the specified test case, applies stimuli to the Testable  Application, captures, preprocesses and records application responses</li>
<li>Batch Controller, upon  completion of a test case (all test cases), calls Comparator to compare a test  output to a corresponding test master.</li>
<li>Comparator compares test  output and master, writes discrepancies (if any) and signals success/failure</li>
<li>Batch Controller, upon  completion of all test cases, aggregates test results and signals a batch  result (success/failure) to the Actor.</li>
</ul>
<h2>A simple test environment</h2>
<p>A simple environment for automated testing  can be implemented as the following</p>
<table width="500" border="1" cellpadding="0" cellspacing="0" class="StdTable" style="border-collapse:collapse;border:none;">
<tr>
<th scope="col">Component</th>
<th scope="col">Implemented as</th>
</tr>
<tr>
<td>Batch Controller</td>
<td>A script for shell/command interpreter</td>
</tr>
<tr>
<td>Test Case</td>
<td>A script for shell/command interpreter</td>
</tr>
<tr>
<td>Test Batch</td>
<td>A group of scripts/a folder</td>
</tr>
<tr>
<td>Test Data</td>
<td>A data files or command line parameters</td>
</tr>
<tr>
<td>Test Output</td>
<td>A data file</td>
</tr>
<tr>
<td>Master</td>
<td>A data file</td>
</tr>
<tr>
<td>Comparator</td>
<td>File content comparator</td>
</tr>
<tr>
<td>Discrepancies</td>
<td>File content differences</td>
</tr>
<tr>
<td>Test Tool</td>
<td>Simple Sampler based tool</td>
</tr>
</table>
<p></p>
<h2>Test Tool</h2>
<p>To use this simplest automated test  environment for testing embedded applications, the Test Tool should be a  command-line utility, capable to apply stimuli to the testable application and  capture the application response to a file.</p>
<h3>SISAM &amp; SITEST</h3>
<table>
<tr>
<td>
<p>SISAM is PIC-based application capable to  accept commands via RS232, actuate pins according to the command, acquire data  from one or two channels and send acquired data via RS232.</p>
<p>SITEST is a command line interface to SISAM.  It accepts a sequence of characters from the command line, sends these commands  to SISAM and writes data to standard output. These features make SISAM a good  candidate for simple testing environment.</p>
<p>Figure 2 shows architecture diagram for a test tool build on SISAM and SITEST.</p>
</td>
<td>&nbsp;</td>
<td valign="middle"><a href="http://hutorny.in.ua/wp-content/uploads/2006/07/SISAM&amp;SITEST.png" target="_blank" rel="thumbnail"><img id="image48" height=96 alt="SISAM &amp; SITEST in a test tool" src="http://hutorny.in.ua/wp-content/uploads/2006/07/SISAM&amp;SITEST.thumbnail.png" /></a><br />Figure 2</td>
</tr>
</table>
<h3>Filters</h3>
<p>Due to nature of embedded applications  acquired data may vary from run to run even for valid runs. This variability is  very application specific; it may make impossible output-to-master comparison,  and thus may easily bury the idea of automated testing. To address this issue,  acquired data should be filtered and coarsened to the level at which all valid  runs would produce identical outputs while invalid runs would still have some  difference in the output data. Such a filter should be a command line utility  that reads from standard input and writes to standard output. Of course,  writing a filter requires additional efforts, however, from authors&#8217;  experience, implementing a simple filter does not require any significant  efforts.</p>
<h3>Function Generators</h3>
<p>SISAM is only capable to provide static  stimuli for a period of data acquisition. Therefore, if the test conditions  require some alternating stimuli applied in parallel with data acquisition, a  &quot;function generator&quot; can be used in conjunction with SISAM. A  &quot;function generator&quot; is an embedded application that accepts a static  input (function ID) and generates a variable function on output.</p>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/simple-environment-automated-testing-embedded-applications/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SISAM Protocol</title>
		<link>http://hutorny.in.ua/projects/pic/sisam/sisam-protocol</link>
		<comments>http://hutorny.in.ua/projects/pic/sisam/sisam-protocol#comments</comments>
		<pubDate>Fri, 14 Jul 2006 23:50:13 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[SISAM]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/projects/pic/sisam/sisam-protocol</guid>
		<description><![CDATA[
SISAM uses RTS/CTS flow control for reading  command and DTR flow control for sending acquired data. This means that PC  should set RTS before sending commands and watch for CTS (e.g. use CTS sensitivity option). When PIC goes into data acquisition mode, it sends an ASCII string starting  with Y4-MODE:  followed [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css"><!-- .style2 {color: #800080; font-weight: bold; } --></style>
<p>SISAM uses RTS/CTS flow control for reading  command and DTR flow control for sending acquired data. This means that PC  should set RTS before sending commands and watch for CTS (e.g. use CTS sensitivity option). When PIC goes into data acquisition mode, it sends an ASCII string starting  with <strong><code>Y4-MODE:</code></strong>  followed with new  mode description. This description can be directly used with <strong><code>mode</code></strong> command or with <strong><code>BuildCommDCB</code></strong> function.</p>
<p><span id="more-44"></span></p>
<p>PC should change the COM port mode as directed.  Since the mode description contains rts=off dtr=on, DTR will be set SPACE signaling  that PC is ready to receive acquired data.</p>
<p>PC stops Data acquisition by setting DTR to  MARK and restoring 115200 baud rate.</p>
<p>If during data acquisition PIC encounters an  error, it signals a BREAK, e.g. holds RX in SPACE until PC sets DTR to MARK. PIC  does not leave error state until PC holds RTS MARK, therefore, to recover from  error state, PC should restore baud rate 115200, set RTS to SPACE and read  error message.</p>
<p>When data acquisition is performed with  sync flag and PC needs to break waiting, it should alter TX line. If CTS  sensitivity option is applied to COM port, <strong><code>WriteFile</code></strong> to the port will not succeed, <strong><code>SetCommBreak</code></strong> should be used instead. After this PIC will enter a error sate which should be  cleared as stated above.</p>
<h2>Initial state</h2>
<ul>
<p>PC opens port for normal operation: <code>baud=115200 parity=N data=8 stop=1 octs=on dtr=off rts=of</code></p>
</ul>
<h2>Sending a command to SISAM</h2>
<table>
<tr>
<td>
<p class="style2">PIC is in IDLE state</p>
<ul>
<p>1. PC sets RTS=SPACE<br />
    2. PIC confirms by setting CTS=SPACE<br />
    3. PC sends commnd(s)<br />
    4. PIC sets CTS=MARK<br />
    5. PC continues transmission<br />
    6. PC completes transmission<br />
    7. PC sets RTS=MARK<br />
    8. 2 ms timeout<br />
    9. On either of (7) or (8) PIC accepts command<br />
    10. PIC sends new COM port mode<br />
    11. PC changes COM port mode<br />
    12. PC signals START by setting DTR=SPACE</p>
</ul>
<p class="style2">PIC is in WAIT state</p>
<ul>
<p>13. PIC sends data</p>
</ul>
<p class="style2">PIC is in ACQUIRE state</p>
<ul>
<p>14. PC signals STOP by setting DTR=MARK<br />
    15. PIC stops transmission<br />
    16. PC restores COM port mode </p>
</ul>
<p class="style2">PIC is in IDLE state</p>
</td>
<td width="100">&nbsp;</td>
<td valign="top"><a href="http://hutorny.in.ua/wp-content/uploads/2006/07/SISAM%20protocol%20I.png" target="_blank"><br />
<img id="image45" height=96 alt="SISAM Send Command Diagram" src="http://hutorny.in.ua/wp-content/uploads/2006/07/SISAM%20protocol%20I.thumbnail.png" /></a></td>
</tr>
</table>
<h2>Output stream format</h2>
<p>PIC sends acquired data as described below</p>
<table>
<tr>
<td valign="top">S,J:</td>
<td>Sampled bits are packed into octets (bytes) in LSB order (less significant bit first) and sent to the output stream</td>
</tr>
<tr>
<td valign="top">X:</td>
<td>Sampled bits are packed into LSB bytes and sent to the stream by turns, channel 0 comes first</td>
</tr>
<tr>
<td valign="top">M:</td>
<td>Time between signal alternations is measured in ticks and sent as <code>WORD </code>(16 bit unsigned integer with LSB bit ordering). Zero has special meaning ??“ no alternation occurred in <code>0xFFFF</code> ticks.</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/projects/pic/sisam/sisam-protocol/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
