I just tried making val an unsigned short and using a length of 2 for the
write. Also tried making it unsigned long and using length 4 for write. Same
error in all cases.
I know I've successfully used dd before with the skip parameter to specify
offset (that was in /dev/kmem but same idea). I would assume dd would do an
lseek, but for all I know it could use mmap too.
--- In "Harold" <> wrote:
>
> In theory, I think, you should be able to write to physical memory by using
> lseek() & write() on /dev/mem, although I have never tried this myself.
>
> Since you get "invalid argument", maybe it does not allow 1-byte writes. Have
> you tried writing 2 or 4 bytes?
>
>
> --- In "frank_kienast" <frank_kienast@> wrote:
> >
> > Maybe I'm doing something stupid here, but it seems like I have to use
> > mmap() to access the LEDs on the TS7200. The following works:
> >
> > #include <sys/types.h>
> > #include <unistd.h>
> > #include <sys/stat.h>
> > #include <sys/mman.h>
> > #include <fcntl.h>
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <unistd.h>
> >
> > #define LED_ADDR 0x80840020
> >
> > extern int errno;
> >
> >
> > int main()
> > {
> > int i;
> > unsigned char *leds;
> > unsigned char val;
> >
> > int fd = open("/dev/mem",O_RDWR|O_SYNC);
> > if(fd < 0)
> > {
> > printf("Can't open /dev/mem\n");
> > return 1;
> > }
> > leds = (unsigned char *) mmap(0, getpagesize(),
> > PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x80840000);
> > if(leds == NULL)
> > {
> > printf("Can't mmap\n");
> > return 1;
> > }
> > else
> > printf("leds=%x\n",leds);
> >
> > for(i = 0; i < 256; i++)
> > {
> > val = i % 4;
> > leds[0x20] = val;
> >
> > sleep(1);
> > }
> >
> > return 0;
> > }
> >
> >
> > But the following gets an error on the write
> > System error: 22 = Invalid argument
> >
> > #include <sys/types.h>
> > #include <unistd.h>
> > #include <sys/stat.h>
> > #include <fcntl.h>
> > #include <stdio.h>
> >
> > #define LED_ADDR 0x80840020
> >
> > extern int errno;
> >
> > int main()
> > {
> > int i;
> > off_t cs;
> > unsigned char val;
> >
> > int fd = open("/dev/mem",O_RDWR|O_SYNC);
> > if(fd < 0)
> > {
> > printf("Can't open /dev/mem\n");
> > return 1;
> > }
> >
> > for(i = 0; i < 256; i++)
> > {
> >
> > cs=lseek(fd,LED_ADDR,SEEK_SET);
> > if(cs != LED_ADDR)
> > {
> > printf("Can't lseek\n");
> > return 1;
> > }
> > val = i % 4;
> > cs=write(fd,&val,1);
> > if(cs != 1)
> > {
> > printf("Write failed: %d\n",errno);
> > return 1;
> > }
> >
> > sleep(1);
> > }
> >
> > return 0;
> > }
> >
> >
> > Shouldn't either method work?
> >
> > Thanks,
> > Frank
> >
>
------------------------------------
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/
|