You should test that both the open() and mmap() calls return sensible values,
not -1 for error.
You can check with dmesg to see where it is crashing.
--- In salva g <> wrote:
>
>
> Hi I'm working with this code in order to control relay switch, (the
> TS-Relay8 Board) on a TS7800,
>
> #include <netinet/in.h>
> #include <arpa/inet.h>
> #include <unistd.h>
> #include <time.h>
> #include <ctype.h>
> #include <sys/mman.h>
> #include <fcntl.h>
>
> #define RELAYBASE 0xEE000140
>
> int main()
> {
> volatile unsigned int *PBDR;
> unsigned char state;
> unsigned char *start;
> int fd = open("/dev/mem", O_RDWR|O_SYNC);
> start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd,
> RELAYBASE);
> PBDR = (unsigned int *)(start + 0x02);
> state = *PBDR;
> printf("Result: %x\n",state);
> return 0;
> }
>
> Can be compiled, but return Segmentation Faults when it runs. Instead, with
> the shell I can do peek16 0xEE000142 with no problem.
> Any ideas please?
>
> _________________________________________________________________
> Infórmate, mantente en contacto y encuéntralo todo, a la vez. Con la nueva
> Toolbar de MSN nunca has tenido tantas ventajas en tan poco espacio.
> http://toolbar.es.msn.com/
>
------------------------------------
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/
|