Skip navigation.
Home
The QNX Community Portal

View topic - Memory fault in32()

Memory fault in32()

For discussion of realtime and/or embedded programming.

Memory fault in32()

Postby djidji » Thu Jul 21, 2016 4:09 pm

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: Select all
#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;
}
djidji
Active Member
 
Posts: 21
Joined: Tue Jun 28, 2016 1:17 pm

Re: Memory fault in32()

Postby maschoen » Thu Jul 21, 2016 6:17 pm

Are you running as root? To perform the indicated function with ThreadCtl() you need to be root. Other than that your code looks good.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: Memory fault in32()

Postby Tim » Fri Jul 22, 2016 3:00 pm

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

Code: Select all
uintptr_t ptr;

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


Tim
Tim
Senior Member
 
Posts: 1388
Joined: Wed Mar 10, 2004 12:28 am

Re: Memory fault in32()

Postby maschoen » Fri Jul 22, 2016 3:33 pm

Ideally yes. On some architecture this might be required. In general, no.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: Memory fault in32()

Postby denkelly » Fri Jul 22, 2016 7:03 pm

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;
]
denkelly
Senior Member
 
Posts: 160
Joined: Sat Aug 02, 2008 3:27 pm

Re: Memory fault in32()

Postby djidji » Mon Jul 25, 2016 12:34 pm

Thanks evreyone,

using a pointer returned from mmap_device_io and print it fixed the problem.
djidji
Active Member
 
Posts: 21
Joined: Tue Jun 28, 2016 1:17 pm


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 2 guests