Memory mapped IO to PCI driver

P

paulgc3

Hello,

I like .NET CF 2.0. I love speed. I need both.

Situation: PCI device on CE 5.0. Memory mapped IO connectivity to
device.

Desires:

o I want to have my driver init routine return an address pointing to
the user mode address of the memory mapped region in the hardware.

o I want to PInvoke into this code to grab that pointer and load it
into an unsafe block in c#.

o I want to manipulate things in the hardware via .NET by using this
unsafe block to change values in the memory region I got from the prior
step.

I think this all works, but I am not peaked on the performance issues.
I belive that I can avoid all the pinvoke business this way (except for
the first one that sets things up) and do fast .NET access to the
hardware.

Can anybody comment on my peculiar approach? I am willing to take the
risks, but I am looking for people who understand the thing I am doing
at a CE internals level who may know reasons this is bad bad bad.

Thanks,

Paul
 
P

paulgc3

I have tested most of this, and it seems that I can easily talk to
memory in win32 land from .net land. So getting to the next step of
talking into the shared memory area the driver provides seems easy
enough. This should avoid the pinvoke penalty, right?

Paul
 
G

Guest

User Mode address? Sounds like you're thinking desktop, not CE. You have a
physical or a virtual address? P/Invoking MmMapIoSpace or
VirtualAlloc/VirtualCopy is probably what you're after.

There's nothing inherently "bad" about what you want to do. I've done it
before, and on many occasions. I have all the "work" done for you.

Here's an article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/jittedcode_cf2.asp

And here's a class:
http://www.opennetcf.org/library/OpenNETCF.IO.PhysicalAddressPointerMembers.html

Simply create the class instance with your address and size, then call
GetUnsafePointer and go to it.
 
P

paulgc3

Chris,

Thanks Much for your help. I had created a custom class that would do
this, and I was also using the OpenNETCF library and didnt realize this
function was in there. I think given what I have seen that I can remove
my custom code and hook in using yours.

I have a question about implementation. My version had a
getunsafepointer type of routine, and that was the only pinvoke. After
getting that pointer, I just happily wrote into the memory using an
offset. I havent seen your source, but I am hoping it works the same
way?

My primary goal is to avoid the pinvoke every call. Does this strategy
accomplish this?

Thanks again,

Paul
 
G

Guest

Yes. GetUnsafePointer returns a pointer to the start of the mapped region.
Once you've done that, you never P/Invoke again. The article I pointed to
discussed this fact, plus some other very important issues (like method call
latency) that you'll want to look at if you're going down this road.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top