<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Embedded C - Read/Write Registers' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Embedded C - Read/Write Registers' posted on the 'Embedded C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 04:26:22 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 04:26:22 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Embedded C - Read/Write Registers</title>
      <link>http://www.programmersheaven.com/mb/embedCpp/373283/373283/embedded-c---readwrite-registers/</link>
      <description>I'm looking at example code from Diamond Systems made for their Prometheus PC/104 board, and I'm trying to figure out the proper C functions to read and write registers.  From the sample code's included "manual" :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The example code is written in generic C using outp() and inp() functions. For users with compilers that don’t support these two functions, be sure to define them in the following format:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;#define outp(x, y)  _outp(x, y)
#define inp(x)  _inp(x)&lt;/pre&gt;&lt;br /&gt;
Be sure to define outp and inp to register read/write functions that your compiler does support.&lt;br /&gt;
&lt;br /&gt;
Not really sure how to define outp() and inp() since compiling with those functions not properly declared didn't work.  If anyone has any thoughts I'd greatly appreciate it.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/embedCpp/373283/373283/embedded-c---readwrite-registers/</guid>
      <pubDate>Wed, 09 Jul 2008 11:13:52 -0700</pubDate>
      <category>Embedded C/C++</category>
    </item>
    <item>
      <title>Re: Embedded C - Read/Write Registers</title>
      <link>http://www.programmersheaven.com/mb/embedCpp/373283/373284/re-embedded-c---readwrite-registers/#373284</link>
      <description>Edited your post since the text placed within the code tags made it hard to read.&lt;br /&gt;
&lt;br /&gt;
As for those functions, they are common non-standard C functions. The format is usually like this:&lt;br /&gt;
&lt;br /&gt;
void outp (unsigned char* address, unsigned char data);&lt;br /&gt;
&lt;br /&gt;
unsigned char inp (unsigned char* address);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So those functions are pretty easy to implement on most systems, you just read/write data to an address. Could as well write&lt;br /&gt;
&lt;br /&gt;
*address = data;&lt;br /&gt;
&lt;br /&gt;
The only kind of systems that will moan about that syntax is systems without direct memory access, ie Windows.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/embedCpp/373283/373284/re-embedded-c---readwrite-registers/#373284</guid>
      <pubDate>Wed, 09 Jul 2008 11:35:12 -0700</pubDate>
      <category>Embedded C/C++</category>
    </item>
    <item>
      <title>Re: Embedded C - Read/Write Registers</title>
      <link>http://www.programmersheaven.com/mb/embedCpp/373283/373286/re-embedded-c---readwrite-registers/#373286</link>
      <description>: Edited your post since the text placed within the code tags made it &lt;br /&gt;
: hard to read.&lt;br /&gt;
: &lt;br /&gt;
: As for those functions, they are common non-standard C functions. &lt;br /&gt;
: The format is usually like this:&lt;br /&gt;
: &lt;br /&gt;
: void outp (unsigned char* address, unsigned char data);&lt;br /&gt;
: &lt;br /&gt;
: unsigned char inp (unsigned char* address);&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: So those functions are pretty easy to implement on most systems, you &lt;br /&gt;
: just read/write data to an address. Could as well write&lt;br /&gt;
: &lt;br /&gt;
: *address = data;&lt;br /&gt;
: &lt;br /&gt;
: The only kind of systems that will moan about that syntax is systems &lt;br /&gt;
: without direct memory access, ie Windows.&lt;br /&gt;
&lt;br /&gt;
Thanks for the quick response, and the edit on my post for clarity.&lt;br /&gt;
&lt;br /&gt;
I tried just using the functions within the program, but I get the errors "undefined reference to 'outp'" (or 'inp')  If it helps, this is the sample code they give for it:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;void PROM_AD_Sample()

{

	unsigned char channel;	/* AD channel to be sampled. Range 0-15 */

	unsigned char mode;		/* AD mode for the range, polarity, gain */

	unsigned char LSB;		/* Least Significant Byte. The 8 rightmost bits of 

								the 16 bit A/D code */

	unsigned char MSB;		/* Most Significant Byte. The 8 leftmost bits of

								the 16 bit A/D code */

	short Data;				/* The 16 bit AD sample resulting from the combination of 

								LSB and MSB. Data range (-32768)-32767. Refer to user manual

								on how to calculate voltage */



	outp(base, 0x10);							/* FIFO reset. Write 1 to RSTFIFO bit (bit 4).

													Does not affect any of the other bits */

	outp(base + 2, (channel &amp;lt;&amp;lt; 4) | channel);	/* set A/D channel; Low = High */

	outp(base + 3, mode);						/* set A/D mode which determines the gain */

	while(inp(base + 3) &amp;amp; 0x20)					/* wait for WAIT bit (bit 5) = 0 */

		/*empty while*/;

	outp(base + 0, 0x80); 						/* start A/D conversion; set STRTAD bit (bit 7) to high */

	while(inp(base + 3) &amp;amp; 0x80)  				/* wait for A/D busy bit (bit 7) = 0 */

		/*empty while*/;

	LSB = inp(base + 0);						/* read data LSB */

	MSB = inp(base + 1);						/* read data MSB */

	Data = (MSB &amp;lt;&amp;lt; 8) + LSB;					/* combine LSB + MSB */

}&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Problem is my compiler will not recognize outp() or inp() without some form of definition, and I'm not really sure how to do that, exactly.  Sorry, I'm a little new to programming on this level, as you can probably tell.  I understand the prototypes in that reply, but I get the messages "passing arg 1 of 'outp' makes pointer from integer without a cast" and "undefined reference to 'outp'".&lt;br /&gt;
&lt;br /&gt;
for the record, I'm compiling for BlueCat embedded Linux, using their "Luminosity" dev kit.  I'd use a more friendly compiler if I could, but in compiling specifically for BlueCat it's my only real choice.&lt;br /&gt;
&lt;br /&gt;
Thanks again for the help!</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/embedCpp/373283/373286/re-embedded-c---readwrite-registers/#373286</guid>
      <pubDate>Wed, 09 Jul 2008 12:33:30 -0700</pubDate>
      <category>Embedded C/C++</category>
    </item>
    <item>
      <title>Re: Embedded C - Read/Write Registers</title>
      <link>http://www.programmersheaven.com/mb/embedCpp/373283/373287/re-embedded-c---readwrite-registers/#373287</link>
      <description>That likely means that the system is a 32-bit one. On 32-bit computers, the default int type will be 32 bit, and so will addresses/pointers. If you send char pointers to such functions you will get warnings about no typecasts.&lt;br /&gt;
&lt;br /&gt;
Such systems usually wants 32 bit of data at a time... I don't know your particular system, so I can't tell.&lt;br /&gt;
&lt;br /&gt;
What you need to know to write those functions yourself is roughly the following:&lt;br /&gt;
&lt;br /&gt;
- What is the address bus of the system? (8/16/32/64 bit)&lt;br /&gt;
- Does the system support direct memory access?&lt;br /&gt;
- Does the system require memory alignment, ie do you have to write/read at even addresses?&lt;br /&gt;
&lt;br /&gt;
All of this depends on the CPU really, though the OS could add further restrictions.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/embedCpp/373283/373287/re-embedded-c---readwrite-registers/#373287</guid>
      <pubDate>Wed, 09 Jul 2008 13:33:23 -0700</pubDate>
      <category>Embedded C/C++</category>
    </item>
  </channel>
</rss>