LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-28-2006, 04:06 PM   #1
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Rep: Reputation: 30
Question register offset?


Hello,

I m trying to make sense of the following code, what does the register offset mean?

/* register offset */
+#define OFS_RCV_BUFFER (0*REG_OFFSET)
+#define OFS_TRANS_HOLD (0*REG_OFFSET)
+#define OFS_SEND_BUFFER (0*REG_OFFSET)
+#define OFS_INTR_ENABLE (1*REG_OFFSET)

Thanks,
Ashlesha.
 
Old 07-28-2006, 04:20 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.

That said - I assume it's a macro that makes that piece of code
more machine independent?


Cheers,
Tink
 
Old 07-28-2006, 06:49 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Well, the definitions are a little strange. It looks to me like a register map. REG_OFFSET is likely defined somewhere to be 4 or 8 (depending on whether the processor is 32- or 64-bit).

In essence it's saying that the values for OFS_RCV_BUFFER, OFS_TRANS_HOLD, and OFS_SEND_BUFFER are all stored in the same register. The next line suggests that OFS_INTR_ENABLE is stored in the next available register. I've seen many hardware designs where the device's control registers occupy a block of memory (memory-mapped that is) and each individual register is addressed by adding the register's offset to the base address of the memory block. Something like this:

Code:
send_buffer = *(volatile unsigned *)(REGISTER_BASE + OFS_SEND_BUFFER); /* Register read */

*(volatile unsigned *)(REGISTER_BASE + OFS_INTR_ENABLE) = 0xFFFFFFF0;  /* Register write */
It's odd to do things that way unless the programmer expects the size of the registers to change (which is what I believe Tinkster was referring to). However, changing the register size has tons of other implications: do the individual fields within the same register change their bit widths, or are the extra bits added simply wasted? If they change, the bit masks need to be updated, etc.

I find it odd, but then again, I haven't seen everything so...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
offset on lm-sensor? bobbens Linux - Hardware 3 01-20-2005 04:34 PM
Download-Offset possible? Cornholio Linux - Software 0 01-10-2005 04:47 AM
monitor offset moschi Linux - Newbie 3 04-18-2004 12:09 PM
Print-out is offset Cichlid Linux - Hardware 1 05-06-2002 05:54 AM
Mouse Offset Problem AgedMan Linux - General 1 12-04-2001 12:08 AM


All times are GMT -5. The time now is 10:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration