ts-7000
[Top] [All Lists]

[ts-7000] /dev/mem access if not root...

To: ts <>
Subject: [ts-7000] /dev/mem access if not root...
From:
Date: Tue, 15 Feb 2011 17:46:36 -0800
Hello,

I understand that /dev/mem is special.
How special is what I try to understand ;-)

crw-rw-rw- 1 root kmem 1, 1 Jan  1  1970 /dev/mem

The code below still doesn't work probably due to the mmap of /dev/mem.
If I sudo <compiled program> it works.
But under sudo, the environment is reset.
In other words, sudo which <compiled program> doesn't work as expected.
I noticed also that in the sudo environment, the behavior of some binaries are 
slightly different
(mostly due to the environment change or so it seems)

Q: How to access /dev/mem as a regular user?
Q: Do all of my program have to run as root or sudo ?
Thanks,
--
Emmanuel 



int main(int argc, char **argv)
{
   volatile unsigned int *BUFIN;
   unsigned int state;
   unsigned char *start;
   int fd = open("/dev/mem", O_RDWR|O_SYNC);
   int pinoffset;
   int pin_name;  //IN_00 is 0, IN_01 is 1, IN_02 is 2, etc...

   // Check for invalid command line arguments
   if (argc != 2) 
   {
       printf("Usage: %s <pin_name>\n", argv[0]);
       return 1;
   }
   

   // Read buffered input register from mmap (pagesize boundaries required) 
   start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 
           0x600FF000);  // From TS-7350 Manual "Buffered Inputs"
   
   // BUFFERED INPUTS
   BUFIN = (unsigned int *)(start + 0x84);  // Correct for pagesize (4096 byte)
                                            // boundaries.
   // read state of pins
   state = *BUFIN; 
   
   // Gather pin name from the command line argument and check for invalid
   pin_name = strtoul(argv[1], NULL, 0);
   assert(pin_name <=6 && pin_name >=0);
   
   // Pins IN_00 through IN_06 are accessed by bits 7 through 13. 
   pinoffset = pin_name + 7;

   // Print the results   
   printf("Buffered Input Value on IN_0%d: %d\n", pin_name, (state >> 
   (pinoffset)) & 0x1);
   
   return 0;
}



-- 
Emmanuel


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU