Hi All,
I get below error, what is the solution?
/dev/mem opened.
Memory mapped at address 0xb6f6c[ 2194.194754] Unhandled fault: external abort on non-linefetch (0x1018) at 0xb6f6c000
000.
Bus error
code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/mman.h>
#define DCAN0_REG_BASE 0x481CC000
#define DCAN0_CTRL_REG_OFFSET 0
#define MAP_SIZE 8192UL
#define MAP_MASK (MAP_SIZE - 1)
int main(int argc, char **argv) {
int fd;
void *map_base, *virt_addr;
volatile unsigned long read_result;
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) {
printf("/dev/mem could not be opened.\n");
exit(1);
} else {
printf("/dev/mem opened.\n");
}
fflush(stdout);
/* Map one page */
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, DCAN0_REG_BASE);
if(map_base == (void *) -1) {
printf("Memory map failed.\n");
} else {
printf("Memory mapped at address %p.\n", map_base);
}
fflush(stdout);
virt_addr = map_base ;
/* acess remapped region here */
/* read dcan0 ctrl reg */
read_result = *((volatile unsigned long *) virt_addr);
printf("DCAN0 CTRL = 0x%x\n", read_result);
if(munmap(map_base, MAP_SIZE) == -1) {
printf("Memory unmap failed.\n");
}
close(fd);
}
Regards,
Gangadhar