Hi all,
Iu2019m trying to write to and read from memory location such that a DMA can access it. I have image file in u201Cmatu201D data structure from OpenCV. First thing I pack the data the data 32bit word to be sent to the DMA and write to the location given by in_buffer after translating it to virtual address using mmap.
As this point I havenu2019t enabled the DMA, I just write to memory location and read it back using the following functions.
copy_mem2dev(src_frame, IMG_BASEADDR);
//startSobel(FILTER_BASEADDR);
copy_dev2mem(sobelFrame,FILTER_OUT_BASEADDR);
Using a trick from the chapter 15, page 443 given here http://lwn.net/Kernel/LDD3/, I restrict the memory given to linux kernel to 510MB using mem=510M at the bootargs of the dts file. And then input image is given at IMG_BASEADDR = 0x1FE00000 (510MB) and FILTER_OUT_BASEADDR=0x1FF00000 (511MB).
When i enable two function above, the application and linux kernel crashes. Any ideas why?
Additionally what is the difference between mamp and ioremap?
Thanks.
The two functions are:
void copy_mem2dev(Mat img, unsigned long in_buffer)
{
tint count=0;
tunsigned long int map_len = FRAME_WIDTH * FRAME_HEIGHT * 4;
tint fd = open("/dev/mem", O_RDWR);
tunsigned char* virtual_addr_in;
tvirtual_addr_in = (unsigned char*)mmap(NULL, map_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)in_buffer);
tif(virtual_addr_in == MAP_FAILED)
t{
ttperror("virtual_addr_in mapping for absolute memory access failed.
");
ttreturn;
t}
tfor (int i=0; i<FRAME_HEIGHT;i++)
t{
ttfor (int j=0; j<FRAME_WIDTH;j++)
tt{
tttVec3b intensity = img.at<Vec3b>(i, j);
tttuchar red = intensity.val[0]; ttuchar green = intensity.val[1]; uchar blue = intensity.val[2];
tttunsigned int value = 0;
tttvalue += red;
tttvalue += green << 8;
tttvalue += blue << 16;
tttREG_WRITE(virtual_addr_in,count,value);
tttcount++;
tt}
t}
tmunmap((void *)virtual_addr_in, map_len);
tclose(fd);
}
void copy_dev2mem(Mat img, unsigned long in_buffer)
{
tint count=0;
tunsigned long int map_len = FRAME_WIDTH * FRAME_HEIGHT * 4;
tint fd = open("/dev/mem", O_RDWR);
tunsigned char* virtual_addr_out;
tvirtual_addr_out = (unsigned char*)mmap(NULL, map_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)in_buffer);
tif(virtual_addr_out == MAP_FAILED)
t{
ttperror("virtual_addr_in mapping for absolute memory access failed.
");
ttreturn;
t}
tfor (int i=0; i<FRAME_HEIGHT;i++)
t{
ttfor (int j=0; j<FRAME_WIDTH;j++)
tt{
tttunsigned int value = 0;
tttvalue = REG_READ(virtual_addr_out,count);
tttVec3b intensity;
tttintensity.val[0] = value & 0xff;
tttintensity.val[1] = ( value >> 8 )& 0xff;
tttintensity.val[2] = ( value >> 16)& 0xff;
tttimg.at<Vec3b>(i, j) = intensity;
tttcount++;
tt}
t}
tmunmap((void *)virtual_addr_out, map_len);
tclose(fd);
}