LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 03: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, 03:20 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 05:49 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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



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 03:34 PM
Download-Offset possible? Cornholio Linux - Software 0 01-10-2005 03:47 AM
monitor offset moschi Linux - Newbie 3 04-18-2004 11:09 AM
Print-out is offset Cichlid Linux - Hardware 1 05-06-2002 04:54 AM
Mouse Offset Problem AgedMan Linux - General 1 12-03-2001 11:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:03 AM.

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
Open Source Consulting | Domain Registration