View topic - Howto return a pointer from io_read-function ?

Howto return a pointer from io_read-function ?

anything that doesn't fit to other groups.

Howto return a pointer from io_read-function ?

Postby tobiZI » Wed Nov 24, 2004 2:52 am

Hello,

I'm rather new to QNX programming and i'm writing a resource manager for a framegrabber board. I have problems with returning a picture to the client.
In the endless while-loop of the main-function of my resource manager, i read from a buffer, which contains the actual picture :

Code: Select all
bitmap=dmabuffer+(readyBuffer->start);

bitmap is declared in the header-file as unsigned char * bitmap;

In the io_read - function, i do the following :
Code: Select all
// write data to the client
  if (nbytes) {
       
       retVal.width = width;
       retVal.height = height;
       retVal.bpp = bpp;
       retVal.bitmap=bitmap;
   
       MsgReply(ctp->rcvid, nbytes, &retVal + off, nbytes);
       // Settup POSIX start atime data
       ocb->attr->flags |= IOFUNC_ATTR_ATIME | IOFUNC_ATTR_DIRTY_TIME;
       // advance the lseek index vy the number of bytes read if not _IO_XTYPE_OFFSET
       if (xtype == _IO_XTYPE_NONE) {
            ocb->offset += nbytes;
       }
       // If we have returned all Data reset offset to 0
       if ( nbytes >= sizeof(picCtrlStruct) ) {
            ocb->offset = 0;
       }
  } else {
    MsgReply(ctp->rcvid,EOK,NULL,0);
  }
  return (_RESMGR_NOREPLY);
} // io_read


Where retVal is of the following struct :
Code: Select all
typedef struct {
      unsigned char * bitmap; /*!< das Bild */
      int height;    /*!< Hoehe des Bildes */
      int width;   /*!< Breite des Bildes */
      int bpp;
} picCtrlStruct;


My problem is, that the values of height, width and bpp are returned correctly, but bitmap doesn't points to the picture. How can i return the picture ?

I hope someone can help me,

Cheers
tobiZI
Active Member
 
Posts: 18
Joined: Wed Nov 24, 2004 2:13 am

Postby mario » Wed Nov 24, 2004 1:58 pm

answered in the newsgroup


Because of virtual addressing pointers cannot be share across processes.

The really nice solution would be for resource manager to support mmap call,
just like linux/unix drivers can do but that is not available in QNX6. Well
apparently it is possible through black magic but that information is not
available.

Solution #1, use IOV structures to return the bitmap as well as the control
structure. The huge amount of data transfer will take a toll on the CPU
though and depending on CPU could make any can of real-time image processing
impossible. This does present the advantage of working over network.

Solution #2, have the client setup a DMA memory region. Send the server the
physical address of the buffer and have the hardware dump data right into
it. Best is to do this only once when the client start. The bitmap field
of the structre could specify the offset in the memory so you could have
multiple images in the DMA memory.

Solution #3, same as #2, the server setup the DMA memory. Add an IOCTL to
let client get the physical address of the memory and map to it. Only do the
memory mapping in the client once.

Solution #4, have the bitmap in your control structure be a physical address
and let the client map/unmap the memory every on every read. Not nice since
mmap/unmap is somewhat costly.


mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby tobiZI » Thu Nov 25, 2004 6:37 am

Ok, thanks, i understand. If i want to use solution 2, how can i setup a dma memory region ?
I think i must do something like

unsigned char *dmabuff;

and send the physical address of dmabuff to the server, but how can i get this physical address ?
And how can i map the physical address, into the virtual memory of the server. I read something about mmap_device_memory() and mmap(). Which one is the right way to do this ?
tobiZI
Active Member
 
Posts: 18
Joined: Wed Nov 24, 2004 2:13 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests