how to set a bit of register in linux

as we have sbit command to set a bit of registers in controllers ...how can i set the bit of a16-bit register in linux...
raulapatiAsked:
Who is Participating?
 
HappyCactusCommented:
First, read the REVERSE_FLAG register.
Then set the 3rd bit with the "bitwise or" operator, i.e.

revfag = revflag | (1 << 2)  

Or, as equivalent

revflag |= 0x04
This sets the bit. To clear the bit, you must use the "bitwise and" and the "bit inversion" operators:

revflag = revflag & ~(1 << 2)

or

revflag &= ~0x04

or

revflag &= 0xFB
 
Finally write back the REVERSE_FLAG register.

Please READ the documents I posted you before.
0
 
KendorCommented:
you might be looking for something like:

`setpci -v -H1 -s 0:0.0 x=y`


 * `-H1` lets setpci to have direct hardware access (intel configuration mode)
 * `-s 0:0.0` means Bus (0:) Slot (.0) and function (.0) (check out setpci(8))
 * `x=y` writes value (y) in register (x)

0
 
raulapatiAuthor Commented:
no no sir that was not my doubt...

if i take
unsigned char INVERSE_FLAGS;
 now i have to set each bit of INVERSE_FLAGS...
like first bit as some Negative flag
       second bit as zero flag...

as in microcontroller we can do it by  sbit Negative=INVERSE_FLAGS^0;


how can i do the same in linux..
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
HappyCactusCommented:
What kind of register is it? a cpu register? An I/O memory mapped register? an i/o on a device connected via i2c?
0
 
raulapatiAuthor Commented:
it is a general register...

actually my intention is ,in my project in which i have to read adc (ADE7758) there are some flags which are to be set.so i have to intialise them in avariable which is of byte width....
0
 
HappyCactusCommented:
So the register is an i2c DEVICE register ?
 
0
 
raulapatiAuthor Commented:
spi device register
0
 
HappyCactusCommented:
Follow the protocol as specified in the ade7758 datasheet (page 60)

first you must write the comm. register to specify the register you want to read/write.
Then you must write/read the length required.
For example, to read the AWATTHR register, write the value 0x01, write 0x00, read the first byte (MSB) of the register, write 0x00, read the second byte (LSB).
To write the OPMODE register, write 0x83 (0x13 is the address, 0x80 the write command), then write the byte.

All you the details you need are written in the datasheet.
0
 
KendorCommented:
ah ok -
so have you checked out: http://www.kernel.org/doc/htmldocs/device-drivers/

namely you are looking for the SPI functions, right?
you find them here: http://www.kernel.org/doc/htmldocs/device-drivers/ch09.html
more specific you can set up your device using this structure: http://www.kernel.org/doc/htmldocs/device-drivers/re747.html
where you have all the bits/flags to set

is this what you are looking for?
(as far as I understand you are trying to access your ADc over SPI from a Linux)
0
 
raulapatiAuthor Commented:
i have solved this question
0
 
raulapatiAuthor Commented:
still i have not solved this problem
0
 
raulapatiAuthor Commented:
how to set a single bit in a register in linux...
0
 
HappyCactusCommented:
What is your problem? Please describe carefully the difficulties you have, and eventually post some code.
0
 
KendorCommented:
raulapati -
you see that it is not easy for you to help you on your problem as you do not provide us with any information. post some code, clear problems, error messages, detailed infrmation on your setup etc... otherwise this is leading nowhere...
0
 
raulapatiAuthor Commented:
in ade7758 datasheets page no.68 describes about interrupt register.
here i have to compare the status of each and every bit of that registers and do some manupulations by the status of that registers so i want to set these values to a general register by taking unsigned char variable.so i have to set each and every bit of that register(0x18)to a general char variable..and proceed by comparing each bit...the same task can be done in microcontroller flatform by initialising as below:;;

bdata unsigned char REVERSE_FLAGS;

bdata unsigned char REVERSE;



sbit WATT_REV_R=REVERSE_FLAGS^2;

sbit WATT_REV_Y=REVERSE_FLAGS^1;

sbit WATT_REV_B=REVERSE_FLAGS^0;



sbit VAR_REV_R=REVERSE^5;

sbit VAR_REV_Y=REVERSE^4;

sbit VAR_REV_B=REVERSE^3;
unsigned char bdata INTERRUPT_STATUS_REG1;

unsigned char bdata INTERRUPT_STATUS_REG2;

unsigned char bdata INTERRUPT_STATUS_REG3;



sbit AEHF       = INTERRUPT_STATUS_REG1^0;

sbit REHF       = INTERRUPT_STATUS_REG1^1;

sbit VAEHF      = INTERRUPT_STATUS_REG1^2;

sbit SAGA       = INTERRUPT_STATUS_REG1^3;

sbit SAGB       = INTERRUPT_STATUS_REG1^4;

sbit SAGC       = INTERRUPT_STATUS_REG1^5;

sbit ZXTOA      = INTERRUPT_STATUS_REG1^6;

sbit ZXTOB      = INTERRUPT_STATUS_REG1^7;

sbit ZXTOC      = INTERRUPT_STATUS_REG2^0;

sbit ZXA        = INTERRUPT_STATUS_REG2^1;

sbit ZXB        = INTERRUPT_STATUS_REG2^2;

sbit ZXC        = INTERRUPT_STATUS_REG2^3;

sbit LENERGY    = INTERRUPT_STATUS_REG2^4;

sbit PKV        = INTERRUPT_STATUS_REG2^6;

so how can i perform the same task in linux?

means how to initialise each bit of a char variable..?



internally by comparing i have to do some task as below...

else if((VAR_REV_R==1)&&(WATT_REV_R==1))

      {//iflag_r

      if(energy2[0]>(0x8000))

      totreacteng_lag[0]=totreacteng_lag[0]+(((65535-energy2[0])+1)/1000.0)*kvarh_mf[0]*energy_mf;

      }//iflag_r

etc....

so please give mee any idea...
0
 
HappyCactusCommented:
If WATT_REV_R is the bit 2 (3rd bit) of REVERSE_FLAGS, you can test it as

if ( ( REVERSE_FLAGS & (1 << 2) ) != 0 )

If you aren't familiar with the bitwise operators in C, please look at this: [1] or [2]


[1] http://www.cs.umd.edu/class/spring2003/cmsc311/Notes/BitOp/bitwise.html
[2] http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/CONCEPT/bitwise.html

0
 
raulapatiAuthor Commented:
first of all, how i have to intialise WATT_REV_R as a 3rd bit of REVERSE_FLAGS?
0
 
raulapatiAuthor Commented:
this solution is some what help ful to solve my technical
issue
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.