I am using the Colibri evaluation board 3.2 B with iMX6ULL.In my Application i need to send huge data via SPI within 2 ms. But it is taking around 6 ms via ioctl calls . So i want to use mmap api to directly access the memory in order to achieve the time. I have used the following code(which was from nxp community): ADC using mmap not writing to memory - NXP Community. But when i try to access any memory location through mmap returned virtual address board is hanging at that point it self.
Please provide me the solution where i was wrong?
int main(int argc, char **argv)
{
int fd;
void *mem;
void *aligned_vaddr;
unsigned long aligned_paddr;
uint32_t aligned_size;
if (parse_cmdline(argc, argv)) {
printf("Usage:\n\n"
"Read memory: memtool [-8 | -16 | -32] <phys addr> <count>\n"
"Write memory: memtool [-8 | -16 | -32] <phys addr>=<value>\n\n"
"List SOC module: memtool *. or memtool .\n"
"Read register: memtool UART1.*\n"
" memtool UART1.UMCR\n"
" memtool UART1.UMCR.MDEN\n"
" memtool UART1.-\n"
"Write register: memtool UART.UMCR=0x12\n"
" memtool UART.UMCR.MDEN=0x1\n"
"Default access size is 32-bit.\n\nAddress, count and value are all in hex.\n"
"\nTo support autocompete feature please run below command:\n"
" complete -o nospace -C /unit_tests/memtool memtool\n");
return 1;
}
if (g_is_reg || g_comp) {
parse_module(g_module, g_reg, g_field, g_is_write);
return 0;
}
/* Align address to access size */
g_paddr &= ~(g_size - 1);
aligned_paddr = g_paddr & ~(4096 - 1);
aligned_size = g_paddr - aligned_paddr + (g_count * g_size);
aligned_size = (aligned_size + 4096 - 1) & ~(4096 - 1);
if (g_is_write)
printf("Writing %d-bit value 0x%X to address 0x%08X\n",
g_size * 8, g_value, g_paddr);
else
printf("Reading 0x%X count starting at address 0x%08X\n",
g_count, g_paddr);
if ((fd = open("/dev/mem", O_RDWR | O_SYNC, 0)) < 0)
return 1;
aligned_vaddr =
mmap(NULL, aligned_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
aligned_paddr);
if (aligned_vaddr == NULL) {
printf("Error mapping address\n");
close(fd);
return 1;
}
mem = (void *)((uint32_t) aligned_vaddr + (g_paddr - aligned_paddr));
if (g_is_write) {
write_mem(mem, g_value, g_size);
} else {
read_mem(mem, g_count, g_size);
}
munmap(aligned_vaddr, aligned_size);
close(fd);
if (g_map_vaddr)
munmap((void *)g_map_vaddr, MAP_SIZE);
if (g_fmem)
close(g_fmem);
return 0;
}