?
Solved

how to set a bit of register in linux

Posted on 2010-11-09
18
Medium Priority
?
496 Views
Last Modified: 2012-05-10
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...
0
Comment
Question by:raulapati
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 3
18 Comments
 
LVL 5

Expert Comment

by:Kendor
ID: 34106977
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
 

Author Comment

by:raulapati
ID: 34109636
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
 
LVL 12

Expert Comment

by:HappyCactus
ID: 34109654
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:raulapati
ID: 34109855
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
 
LVL 12

Expert Comment

by:HappyCactus
ID: 34109863
So the register is an i2c DEVICE register ?
 
0
 

Author Comment

by:raulapati
ID: 34109881
spi device register
0
 
LVL 12

Expert Comment

by:HappyCactus
ID: 34109918
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
 
LVL 5

Expert Comment

by:Kendor
ID: 34109924
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
 

Author Comment

by:raulapati
ID: 34135984
i have solved this question
0
 

Author Comment

by:raulapati
ID: 34142537
still i have not solved this problem
0
 

Author Comment

by:raulapati
ID: 34142543
how to set a single bit in a register in linux...
0
 
LVL 12

Expert Comment

by:HappyCactus
ID: 34143215
What is your problem? Please describe carefully the difficulties you have, and eventually post some code.
0
 
LVL 5

Expert Comment

by:Kendor
ID: 34144238
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
 

Author Comment

by:raulapati
ID: 34154409
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
 
LVL 12

Expert Comment

by:HappyCactus
ID: 34154985
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
 

Author Comment

by:raulapati
ID: 34161585
first of all, how i have to intialise WATT_REV_R as a 3rd bit of REVERSE_FLAGS?
0
 
LVL 12

Accepted Solution

by:
HappyCactus earned 375 total points
ID: 34162337
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
 

Author Closing Comment

by:raulapati
ID: 34170847
this solution is some what help ful to solve my technical
issue
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question