PORTS Forum

Ports and Interfaces => USB => Topic started by: kimjensen on February 06, 2014, 09:12:39 pm

Title: Custom HID driver in kernel mode for latency measurement
Post by: kimjensen on February 06, 2014, 09:12:39 pm
Hello
I'm using the CY3684 evaluation board from Cypress. I have been running the many HID examples they have for the fx2hid.
Now I'm in the need of writing a WDK custom HID driver in kernel mode. The purpose is to be able to measure latency. The idea  is to send a USB package from the CY3684 board (e.g. using the fx2hid.zip provided by Jan) and then loop that USB package back to the board in the custom kernel mode driver. It seems fairly simple but no luck as of yet and
i can not find anything on the subject any where and which is why I'm writing here. Is it possible for any one to provide a guide line to a WDK kernel sample driver to use, and where to look to perform the USB package loop-back ? (Have looked at firefly sample from Microsoft, seems very complex for my purpose)

Best Regards,
KIm.
Title: Re: Custom HID driver in kernel mode for latency measurement
Post by: Jan Axelson on February 07, 2014, 09:26:37 am
Firefly is a HID filter driver so I'll assume that is what you are looking for. If so, I would say that building and running that example is a good starting point though from the Q&A it looks like you've tried this without success.

A protocol analyzer might be another way to get the latency data you are looking for.

Also see:

http://msdn.microsoft.com/en-us/library/windows/hardware/hh454832%28v=vs.85%29.aspx
Title: Re: Custom HID driver in kernel mode for latency measurement
Post by: kimjensen on February 07, 2014, 08:28:47 pm
Hi Jan,
Thanks for the reply. Yes I did look at the firefly sample but no luck as it is written specific for a Microsoft optic mouse with the  purpose to turn on/off the led in the mouse. It seems difficult to change and use with a HID example running on a CY3684 board from Cypress...

Instead I looked at this http://code.msdn.microsoft.com/windowshardware/kmdffx2-e785110a  This sample is based on the CY3681 board from Cypress, but it has become obsolete, so instead I have the board CY3684 which Cypress claims is compatible. My idea is therefor to load a USB bulk example on the board and change the kmdffx2 sample kernel driver for that purpose (seems easier than to change above filter driver). Also this sample contains some vendor commands to set a 7 segment display and a led bar (which I can user later, after my latency tests). These vendor commands are just not for above CY3684 board but for this  http://www.osronline.com/hardware/OSRFX2_32.pdf which is some kind of a learning kit. But it is based on the CY3681...Confused, me too.....
Well back to the kmdffx2 sample and bulk transfer. I can load a bulk loop back sample on the CY3684 board that should work with the kmdffx2 sample as far, as I can see. Looking into the kmdffx2 in the file bulkrwr.c I think OsrFxEvtIoRead() function is called when the bulk device has sent data to the host, and I think, I then from this function can call OsrFxEvtIoWrite() (longer down in same file) directly and perform the loopback I need to do for the kernel driver latency test. I will do the measurement on the CY3684 board by flipping an I/O pin high when a USB package is sent to host, and flip it back low when I receive the USB package reply. Then use a oscilloscope to measure the high width of the I/O pin should give me the latency. This is step 1, there are more to the story later....

I don't know, if you know about above kmdffx2 sample, but if you do, maybe you or someone else can tell me if it is a viable way to go, or if there is an easier road.

Best Regards,
Kim
Title: Re: Custom HID driver in kernel mode for latency measurement
Post by: Jan Axelson on February 08, 2014, 09:54:42 am
If you are measuring the latency of the driver, that value can vary with the driver code.

Other factors that can affect latency are the OS and OS version, PC hardware, host controller, and other bus traffic.

Why do you need this information/what will you do with it? 
Title: Re: Custom HID driver in kernel mode for latency measurement
Post by: kimjensen on February 08, 2014, 10:46:29 am
The purpose is to move vendor/protocol specific stuff from user mode/Application layer to kernel mode. It is for a new innovative product (under NDA, so I can not yet tell much about the details, sorry) where a lot of performance demanding APP's can run at the same time in windows which potentially causes latency in he USB communication (From APP -> USB device) but the latency has to stay as low, as at all possible. The idea is therefor to loop-back the USB data in kernel mode while loading the windows pc with stressing application's, and observe that it has less influence on the latency, than if executed in user mode/application. Later on there will be a study to figure out what is actually to be moved to the kernel driver, so it still comply with the kernel driver model, and what is intended to do there. Maybe what need to be done is not acceptable to do in Kernel mode and need to happen in the device.....Never the less this is why I need the information.
Title: Re: Custom HID driver in kernel mode for latency measurement
Post by: Jan Axelson on February 09, 2014, 10:05:19 am
If you want a defined maximum latency, use interrupt transfers, not bulk.

The host controller will reserve bandwidth according to the endpoint's requested maximum latency.

The host driver and device firmware are responsible for providing data to send in time for the host driver to send or retrieve the data.

The kmdffx2 seems like a good place to start.

Title: Re: Custom HID driver in kernel mode for latency measurement
Post by: kimjensen on February 10, 2014, 05:20:53 pm
Thanks for the advice Jan. I will do some hands on work based on the kmdffx2 sample and post it here if I find out anything interesting!