PC Review


Reply
Thread Tools Rate Thread

Memory mapped IO to PCI driver

 
 
paulgc3@gmail.com
Guest
Posts: n/a
 
      28th Jun 2006
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

 
Reply With Quote
 
 
 
 
paulgc3@gmail.com
Guest
Posts: n/a
 
      28th Jun 2006
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

 
Reply With Quote
 
Guest
Posts: n/a
 
      28th Jun 2006
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/de...edcode_cf2.asp

And here's a class:
http://www.opennetcf.org/library/Ope...erMembers.html

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


--
Chris Tacke
OpenNETCF Consulting
www.opennetcf.com
--




<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
paulgc3@gmail.com
Guest
Posts: n/a
 
      28th Jun 2006
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

 
Reply With Quote
 
Guest
Posts: n/a
 
      28th Jun 2006
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.


--
Chris Tacke
OpenNETCF Consulting
www.opennetcf.com
--





<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
memory mapped file sunil Microsoft Dot NET Framework 3 19th Nov 2008 09:25 PM
Bug in SD Memory Card driver : driver remains in memory after remo Malignonne Windows Vista Hardware 2 24th Jan 2008 09:52 AM
memory mapped IO: device registers mapped to virtual memory or physical memory? Olumide Computer Hardware 13 9th Feb 2006 11:44 PM
How do I do memory mapped files in .Net ? =?Utf-8?B?eWFyb24=?= Microsoft C# .NET 1 10th Jul 2005 07:22 PM
98 clients and mapped driver Paul Edwards Microsoft Windows 2000 Networking 0 6th Apr 2004 10:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:03 PM.