<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>struct pointing to RTC in far memory location.</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/16660/struct-pointing-to-rtc-in-far-memory-location</link><description> I have a Real Time Clock (RTC) located at address 0x180000 
 
I would like to create a struct of the RTC registers and map it to 0x180000 where the RTC registers start, located in far xdata memory or (HDATA). 
 
I want to access the RTC such as 
 RTC</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: struct pointing to RTC in far memory location.</title><link>https://community.arm.com/thread/40843?ContentTypeID=1</link><pubDate>Thu, 04 Sep 2003 11:29:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:65657247-7afc-4d44-8311-f76472141183</guid><dc:creator>Jim Leifker</dc:creator><description>&lt;p&gt;This is what I came up with that works, it is accessing the RTC at 0x180000.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
#define RTC_ADDRESS (0x180000ul)

typedef struct RTC_REGS
{
	unsigned char hsec;
	unsigned char sec;
	unsigned char min;
	unsigned char min_alarm;
	unsigned char hour;
	unsigned char hour_alarm;
	unsigned char day;
	unsigned char day_alarm;
	unsigned char date;
	unsigned char month;
	unsigned char year;
	unsigned char cmd;
	unsigned char wd_hsec;
	unsigned char wd_sec;
	unsigned char dummy1;
	unsigned char dummy2;
	unsigned char user[48];
} RTC_regs;

RTC_regs far *RTC_registers = &amp;amp;FVAR(RTC_regs, RTC_ADDRESS);

void RTC_Init( void )
{
		RTC_registers-&amp;gt;hsec = 0;
		RTC_registers-&amp;gt;sec  = 0;
		RTC_registers-&amp;gt;min  = 0;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: struct pointing to RTC in far memory location.</title><link>https://community.arm.com/thread/40841?ContentTypeID=1</link><pubDate>Thu, 04 Sep 2003 11:16:13 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e44716a2-bf53-4f85-9cad-2d0b25ecf6a5</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;I think that would be a reasonable thing to do, yes.  Something like:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
#define RtcAddr  0x180000

typedef struct
    {
    U16 year;
    U8 month;
    U8 day;
    } RtcReg;

#define Rtc  FVAR (RtcReg, RtcAddr)

...

Rtc.month = 8;

&lt;/pre&gt;
&lt;br /&gt;
If you peek at the definition of FVAR, you&amp;#39;ll see that it&amp;#39;s a macro that really just adjusts an address for the Keil tag byte coding scheme, casts it to a pointer to the type given, and dereferences that pointer.  So it&amp;#39;s a way to claim that a variable of a particular type lives at a particular address, without actually declaring a variable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The way I read the manual, you should also be able to use the &lt;b&gt;_at_&lt;/b&gt; extension to declare a variable at the right location:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
RtcReg far Rtc _at_ 0x180000UL;

Rtc.month = 8;
&lt;/pre&gt;
&lt;br /&gt;
But I&amp;#39;ve never done it that way myself.&lt;br /&gt;
&lt;br /&gt;
A variation would be to put the variable in a source file by itself, so that it will wind up in a data segment by itself, and then use the linker to specify the location of that data segment.  A bit more trouble, but it avoids the use of one non-standard extension if portability is a concern.&lt;br /&gt;
&lt;br /&gt;
(The first method is, IMO, the most portable; people tend to forget about the linker configuration files, and there&amp;#39;s no commonality at all between linker control file / directive syntax from one linker to another.  Most projects I&amp;#39;ve worked on use the cast-an-address route to physically locate a variable.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>