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/
|