Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DMA to access High Speed Serial Port

I use serialport component in c# and it works well! But the question is how can it be faster to handle high speed (e.g. 2 Mbps) data transfers.

As I have researched about this, I have found that memory can be accessed directly (using DMA like this link ). Can anybody tell me how can I define and use it in my application?

like image 508
Mohammad Gohari Avatar asked Dec 24 '22 18:12

Mohammad Gohari


2 Answers

No, the [c#] tag puts this a million miles out of reach. The code snippet on that web page is not real, it is just a "pattern". It does things you cannot do in C#, like handling interrupts, obtaining the physical memory address of buffers, directly programming the device registers. On the kind of machines that can execute C# code, not counting the Micro Framework, this can only be done by device drivers.

It would be the kind of code that could run on a micro-controller, the kind of processor that doesn't run with a protected-mode operating system. Even then it is stretch, it invokes DMA by unstated magic, never actually starting the transfer on a transmit for example. No sign of a DMA controller either, required to arbitrate bus access between devices. It is fake code.

When you use real hardware you always get a device driver with it that takes care of talking to the device. If the device actually supports DMA, very unusual, then the device driver programmer would not avoid using it. The SerialPort class you use in a C# program uses the operating system api, one that's universal for any kind of serial port device. It passes your I/O requests to the device driver to get the job done.

The interface between the operating system api and the device driver is covered by IOCTLs. This MSDN page documents the ones for Windows. There's a pretty close match between the IOCTLs and the api, the api layer is pretty thin. When you take a closer look, it will be obvious that none of them have anything to do with DMA. They can't, it is strictly a driver implementation detail.

like image 180
Hans Passant Avatar answered Dec 27 '22 09:12

Hans Passant


I believe you don't need to make serial access any faster, and instead tune your c# application to handle the data transfer faster. Run a profiler of your choice and measure what percentage of time is spent in serialport component's methods. I predict that will be quite low, meaning any efforts towards making serialport faster will be spent in vain.

like image 27
Codeguard Avatar answered Dec 27 '22 08:12

Codeguard