<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Linux Fast Parallel Port Control using Allegro</title>
		<link>http://www.allegro.cc/forums/view/444640</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 04 Jan 2005 09:17:47 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here is some parallel port routines that I am using to control some hardware that is attached to my parallel port. The writes seem to work, don&#39;t know about the reads yet.  The main problem is that the reads and the writes seem to take way too long to execute.</p><p>Any suggestions on if the linux code is correct or on speeding up the parallel port routines? Thanks.</p><p>#include &quot;allegro.h&quot;<br />#include &quot;sys/io.h&quot;<br />#include &quot;sys/time.h&quot;<br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;unistd.h&gt;</p><p>// Parallel Port<br />#define DATA	0x378<br />#define STATUS 	DATA + 1<br />#define CONTROL	DATA + 2</p><p>struct timespec ts;</p><p>int Main(){<br />...<br />ts.tv_sec = 0;<br />ts.tv_nsec = 500;<br />...<br />   open_parallel_port();<br />   initialize_port_signals();</p><p>   //Write to Parallel Port<br />   outb(0x55, DATA);	<br />   toggle_init();<br />   outb(0x00, DATA);<br />   toggle_strobe();<br />   <br />   usleep(500000);		// Delay 0.5 seconds<br />...<br /> <br />   //Read from Parallel Port<br />   outb(0xAA, DATA);	<br />   toggle_init();<br />   outb(0xd2 ^0x0b, CONTROL);<br />   PP_DATA = inb(DATA);<br />   toggle_strobe();</p><p>   close_parallel_port();<br />   return 0;</p><p>}</p><p>END_OF_MAIN();</p><p>toggle_strobe(){<br />    nanosleep(&amp;ts, NULL);<br />    outb(0xda ^ 0x0b, CONTROL);   <br />    nanosleep(&amp;ts, NULL);<br />    outb(0xdb ^ 0x0b, CONTROL); <br />    nanosleep(&amp;ts, NULL);<br />}<br />END_OF_FUNCTION(toggle_strobe);</p><p>toggle_init(){<br />    outb(0xdf ^ 0x0b, CONTROL);<br />    nanosleep(&amp;ts, NULL);<br />    outb(0xdb ^ 0x0b, CONTROL); <br />    nanosleep(&amp;ts, NULL);<br />}<br />END_OF_FUNCTION(toggle_init);</p><p>initialize_port_signals(){<br />    outb(0xdb ^ 0x0b, CONTROL); <br />    nanosleep(&amp;ts, NULL);<br />}<br />END_OF_FUNCTION(initialize_port_signals);</p><p>open_parallel_port(){<br />   if (ioperm (DATA,3,TURN_ON))	<br />      fprintf(stderr, &quot;Couldn&#39;t open the port at %x\n&quot;, DATA), exit(1);</p><p>   printf(&quot;data: %x\n&quot;, inb(DATA));<br />   printf(&quot;status: %x\n&quot;, inb(STATUS));<br />   printf(&quot;control: %x\n&quot;, inb(CONTROL));</p><p>   usleep(1000);<br />   return 0;<br />}<br />END_OF_FUNCTION(open_parallel_port);</p><p>close_parallel_port(){<br />   printf(&quot;data: %x\n&quot;, inb(DATA));<br />   printf(&quot;status: %x\n&quot;, inb(STATUS));<br />   printf(&quot;control: %x\n&quot;, inb(CONTROL));</p><p>   if (ioperm (DATA,3,TURN_OFF))<br />      fprintf(stderr, &quot;Couldn&#39;t close the port at %x\n&quot;, DATA), exit(1); </p><p>   return 0;<br />}<br />END_OF_FUNCTION(close_parallel_port);
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Randall Dodson)</author>
		<pubDate>Thu, 30 Dec 2004 21:58:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>you know how to time things, what bit takes too long ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (A J)</author>
		<pubDate>Sun, 02 Jan 2005 07:01:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have decided to use parapin.c and parapin.h routines for parallel port control. Theses routines seem to work pretty well.</p><p>But, the &quot;nanosleep(&amp;ts, NULL);&quot; which I have set to delay 500nsec takes several milliseconds to execute for some reason?</p><p>Does anybody know, using linux, how to delay 500nsec +/- 100nsec?</p><p>Thanks for your help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Randall Dodson)</author>
		<pubDate>Mon, 03 Jan 2005 05:25:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Does anybody know, using linux, how to delay 500nsec +/- 100nsec?</p></div></div><p>
I&#39;m not sure you can do that reliably. The nanosleep manpage says
</p><div class="quote_container"><div class="title">the manpage said:</div><div class="quote"><p>
BUGS<br />       The current implementation of nanosleep is  based  on  the<br />       normal  kernel  timer mechanism, which has a resolution of<br />       1/HZ s (i.e, 10 ms on Linux/i386 and 1 ms on Linux/Alpha).<br />       Therefore, nanosleep pauses always for at least the speci­<br />       fied time, however it can take up to  10  ms  longer  than<br />       specified  until  the  process becomes runnable again. For<br />       the same reason, the value returned in case of a delivered<br />       signal  in  *rem  is  usually  rounded  to the next larger<br />       multiple of 1/HZ s.</p><p>       As some applications  require  much  more  precise  pauses<br />       (e.g.,  in  order to control some time-critical hardware),<br />       nanosleep is also capable of short high-precision  pauses.<br />       If  the process is scheduled under a real-time policy like<br />       SCHED_FIFO or SCHED_RR, then pauses of up to 2 ms will  be<br />       performed as busy waits with microsecond precision.
</p></div></div><p>
I think other functions that try to do the same thing would have similar limitations and problems.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 03 Jan 2005 05:44:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for pointing out the bug when using &quot;nanosleep&quot;.</p><p>I will now attempt to use the scheduling functions that you mentioned.</p><p>Has anyone done any &quot;hard&quot; real time loops using linux? Here&#39;s what I want to do:</p><p>while(1){<br />   //slot1 stuff - This slot takes 0.25msec to execute<br />   reset_timer();<br />   do_slot1_stuff();<br />   wait_for_timer_to_expire();</p><p>   //slot2 stuff - This slot takes 0.25msec to execute<br />   reset_timer();<br />   do_slot2_stuff();<br />   wait_for_timer_to_expire();</p><p>   //and so on with each slot consuming 0.25msec of time<br />}</p><p>Maybe I need to learn how to use the hardware timers on the Processor Board.  Has anyone done this?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Randall Dodson)</author>
		<pubDate>Mon, 03 Jan 2005 09:33:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>maybe you need to realize that a multi-threaded environment means you have <b>NO</b> way of guaranteeing your thread is on the CPU when you want it.<br /><b>NO</b> amount of tickering with weird methods will help this.</p><p>best effort, and that is ALL it will be (whilst using a multi-threaded OS), is you create a REAL_TIME or TIME_CRITICAL thread and you completely hog the CPU and do NOT use any OS rest() / yield() functions.<br />this will render the rest of the system useless whilst you have the CPU.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (A J)</author>
		<pubDate>Mon, 03 Jan 2005 12:07:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for the advise.</p><p>On my project, the complete CPU will be dedicated to executing my program.</p><p>I will be checking into the REAL_TIME or TIME_CRITICAL threads.</p><p>My goal is to have 16 processing slots that continuous repeat, with each slot lasting 0.25ms. A processing loop takes 4ms. During each slot, parallel port reads and writes are occuring, allegro graphics screens are showing and sound clips are playing.</p><p>Any additional advise is welcomed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Randall Dodson)</author>
		<pubDate>Mon, 03 Jan 2005 19:53:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Any additional advise is welcomed.</p></div></div><p>

if you are still considering real-time, time critical, on-the-msec accuracy, you are dreamin!</p><p>you want to do time critical, graphics, and audio..  you must have next to zero clue about how your CPU/OS works.</p><p>stop coding, go read about how your multi-tasking OS works.<br />the research will improve your coding, and set your ideas back in reality.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (A J)</author>
		<pubDate>Tue, 04 Jan 2005 09:17:47 +0000</pubDate>
	</item>
</rss>
