Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.


  Search this Thread
Old 11-10-2010, 04:22 AM   #1
Registered: May 2010
Posts: 51

Rep: Reputation: 0
Question how to set a bit in register in linux flat form..

hai to all...

can any body tell me how to acess a bit of 8 bit register in linux flatform..

as in controller point of view we have sbit to set abit of register..but how can i set bit in case of linux..

for example:
unsigned char INTERRUPT;
now i have to set diffetrnt flags to each bit of INTERRUPT..

please help mee.
thanks in advance.....
Old 11-10-2010, 02:32 PM   #2
Senior Member
Registered: Apr 2009
Posts: 1,508

Rep: Reputation: 137Reputation: 137
set_bit : set a bit at the position.
clear_bit: clear a bit at the position.
Old 11-11-2010, 03:25 PM   #3
LQ Newbie
Registered: Aug 2009
Posts: 15

Rep: Reputation: 0
I guess you are talking about the control/status/data registers in devices, rather than the CPU registers, which you need assembly language to access.

to set the n-th bit of x:
x |= 1<<n;
to clear the n-th bit of x:
x &= ~(1<<n);
to toggle the n-th bit of x:
x ^= 1<<n;

If you want to write all bits, just write a number to the register. For example, to accknowledge interrupts, write 0xFF to interrupt register.
Old 11-22-2010, 07:21 PM   #4
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Where is the register which you want to modify? If it is a CPU register, it may not be possible, or meaningful, except from kernel space. If it is a register in a memory-mapped or IO-mapped (x86) peripheral, then you can use the /dev/mem or /dev/port facilities. It may also be on something like a PCI or similar bus, in which case there are probably kernel facilities available to access the register.
The boolean logic to access a particular bit has been demonstrated by earlier posters.

--- rod.


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
[SOLVED] Assistance needed to set up RHEL 64-bit as a YUM Proxy server for 32-bit also. xenner Linux - Newbie 7 10-19-2009 08:50 PM
anyone form BIT,China? urright Member Intro 1 11-09-2007 04:05 PM
Memory bus is 64 bit but data access and register is only 32 bit for i386 lilzz Linux - Newbie 3 09-02-2006 12:35 AM
I want Linux source code for FAT file system in user readable form not in binary form ramya272 Linux - Newbie 5 02-05-2004 07:54 PM
Mandrake 8.2 - can not register boxed set Haldir Linux - Newbie 2 05-07-2002 08:44 PM > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 12:59 AM.

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