Memory fault in32()

hi,

I’m using in32 and out32 function to read or write in register but I get au memory fault, in debug mode it indicate segmentation fault !

just a simple code :

[code]#include <stdlib.h>
#include <stdio.h>
#include <hw/inout.h>
#include <sys/neutrino.h>
#include <stdint.h>
#include <sys/mman.h>

int main(int argc, char *argv[]) {

int data=0;
ThreadCtl( _NTO_TCTL_IO, 0 );
//out32(0x20ac004, 0 );
mmap_device_io( 4,0x20ac004 );
data=in32(0x20ac004 );

printf("data = %x",data);


return EXIT_SUCCESS;

}
[/code]

Are you running as root? To perform the indicated function with ThreadCtl() you need to be root. Other than that your code looks good.

Actually isn’t he supposed to use the return pointer from mmap_device_io like so:

uintptr_t ptr;

ptr = mmap_device_io( 4,0x20ac004 );
data=in32( ptr );

Tim

Ideally yes. On some architecture this might be required. In general, no.

I agree with Tim. This is the correct code for any architecture.

#include <stdlib.h>
#include <stdio.h>
#include <hw/inout.h>
#include <sys/neutrino.h>
#include <stdint.h>
#include <sys/mman.h>

int main(int argc, char *argv[]) {
int data = 0;
uintptr_t hndl;

ThreadCtl( _NTO_TCTL_IO, 0 );
hndl = mmap_device_io( 4, (long long)0x20ac004 );
data = in32( hndl );
printf(“data = %x”,data);
return EXIT_SUCCESS;
]

Thanks evreyone,

using a pointer returned from mmap_device_io and print it fixed the problem.