Link to home
Start Free TrialLog in
Avatar of raulapati
raulapati

asked on

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...
Avatar of Kendor
Kendor
Flag of Switzerland image

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)

Avatar of raulapati
raulapati

ASKER

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..
What kind of register is it? a cpu register? An I/O memory mapped register? an i/o on a device connected via i2c?
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....
So the register is an i2c DEVICE register ?
 
spi device register
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.
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)
i have solved this question
still i have not solved this problem
how to set a single bit in a register in linux...
What is your problem? Please describe carefully the difficulties you have, and eventually post some code.
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...
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...
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

first of all, how i have to intialise WATT_REV_R as a 3rd bit of REVERSE_FLAGS?
ASKER CERTIFIED SOLUTION
Avatar of HappyCactus
HappyCactus
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this solution is some what help ful to solve my technical
issue