A data gather program without resource manager

I am write a data gather programm. I want read and write the PCI card just in the phAb with out write the resource manager. With pressing a “start” button,I can read the data from the PCI card.And pressing a “stop” button,I can stop the data transfer.In some web sit,I realized that it is should be created a new thread to do this work.
The question is I don’t know where and how to create the new thread .
Thanks for everyone who give me the hint.

You don’t have to create a thread, you can create a create a photon handler called when receiving interrupt or a pulse.

If you want to create thread look at pthread_* function. Remember the photon library is not thread safe.

thanks mario
but my purpose is when I press the start button,the program read data from hardware.It doesn’t need to receive interrupt or a pulse.The data transfer is controled by the PhAB.
And how to create a photon handler? which chapter I can reference in the QNX document?

Check the section on Parallels Operation in Photon Programmer’s Guide

Mario,
The Photon library may not be thread safe, but it is safe to create a thread in a photon program that doesn’t do any photon calls, which is (I think) what wangxeli wants to do. It’s also worth noting that with QNX, hardware code (usually called a driver) does not have to lie in the kernel. For this reason, the making of a “driver” using the resource manager is optional, and for the convience of creating a reusable interface. If you just want to write one program that accesses the hardware, you clearly don’t need a resource manager.

I just want to write a simpler programme to gather the data from pci card. The hardware always send the data to computer,so that I can decide what time to start the gathering.And simultaneously store the data in file system , display them as image.resource manager or not,which method more simple?
please give me some suggestions.

Well, as I think I implied, it is much simpler (at least the first time around) to just write the code directly without a resource manager. Once you’ve done that, if you want to make it all a little fancier, you can build a resource manager around the hardware code.

thanks maschoen and Mario.
because I have to complete this work in one month,I want just write the code without a resource manager.I’ll write the reource manager in the future.

another question: when I repeatedly use PhDrawPhImage() to draw images,it is seems not refresh the images. Should I use some functions just like PgFlush() so that I can redraw the other image?

any help appreciated.

If you have code like this, do not expect it to work:

while(1)
{
sleep(delay);
PhDrawPhImage(image[i++]…);
}

That’s not at all how Photon works. You have to exit your code before screen updates can occur.
Instead you might use a timer widget, and when it fires, update the image.

Thank you maschoen.very very thank you!! :slight_smile:

I have another quenstion:I use the DMA mode to transfer the data.but the output data is not the one I want to output. And the input data can’t be transfered to the appointed buffer,I don’t know where it is.
I don’t use the mmap() and mem_offset() to map the DMA register space into the process address space.I just use the in() and out() to operate these register directly. is this wrong?
Maybe my description is not clear.but I really don’t know what’s wrong.
please help me !!

It is ok to use in8() and out8() directly to adjust DMA registers directly. I can’t figure out what else you are asking.

Well it depends on the device. If it’s a PCI device then the register could be memory mapped.

I am sorry my english is awful.
yes,It’s a PCI device.I didn’t use the mapp() function because of two reason.
The first, the function of
addr = mmap( 0,
XXXX,
PROT_READ|PROT_WRITE|PROT_NOCACHE,
MAP_PHYS|MAP_ANON,
NOFD,
0 );
mem_offset(addr, NOFD, 1, &offset, 0) ;
doesn’t work on the DMA register.maybe some key point i don’t konw.
The second,in() and out() function can operate the state of these register.just the input and output data is incorrect.

Depending on the device you might have to use MAP_NOX64K, bit it’s rather unlikely if it’s a modern PCIU card.

You description is a bit confusing to me so lets get over what I think you should do.

If the device has IO, map them with mmap_device_io() and use the return value for the in and out functions. If the device has memory mapped registers, map them with mmap_device_mem(). It’s possible the device has both IO and memory mapped sections.

If the device does DMA then you must allocated DMA’able memory with mmap ( as you described in the previous post). Then you must use the physical address returned by mmap/mem_offset and inform the device of this address. The way this is done is device dependant. Can be done with in/out or with memory mapped registers.