<?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; VELOOS</title>
	<atom:link href="http://hutorny.in.ua/category/projects/pic/veloos/feed" rel="self" type="application/rss+xml" />
	<link>http://hutorny.in.ua</link>
	<description>Programming in a small</description>
	<lastBuildDate>Fri, 15 Jan 2010 19:52:10 +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>
	</channel>
</rss>
