Ask a questionAsk a question
 

AnswerSMBus Client/Sensor Class Driver

  • Tuesday, September 29, 2009 3:59 PMChris_H-Kionix Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello all,

    I've been creating custom i2c Linux drivers for our accelerometers and now I'm struggling to make the transition to Windows driver development.  I've read a lot of documentation on Sensor and Location drivers, SMBus client drivers, and the Windows DDK, but I just don't see how everything is supposed to come together.  I'm using the most current release candidate of Windows 7, and I recently received a development kit along with Windows Embedded 2011 Standard pre-release and I should be able to physically add the accelerometer to the hardware platform.  I just have a few newbie questions for you more experienced Windows developers if I may:

    - I've looked at the code for the sample sensor drivers, but they don't seem to include much about the physical communication method.  Is there an example I can look at which uses SMBus in particular to communicate with the sensor device?

    - Is there a way to use Visual Studio or another IDE to make sense of all the various pieces of driver code?  (The sample source is rather disjointed; I'm used to seeing one source file and one header file for a driver...)

    - Browsing the MSDN literature seems to be a great way to pick up information, but at times it seems like too much.  Is there a recommended starter guide in publication that might help me get started with writing this SMBus Client/Sensor Class Driver?

    Any information would be greatly appreciated!

    Thank you,
    Chris H.
    Kionix, Inc.

Answers

  • Wednesday, September 30, 2009 3:40 PMDan PolivyMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Chris,

    Unfortunately we don't have any sample code for what you're looking for, but I can offer some guidance based on some work we've done with ALS and ACPI.  Assuming you can expose your SMBus connected accelerometer via ACPI, this may be the easiest approach.  To do this, you'd have to modify the BIOS ACPI table to expose the custom device, which Windows would then enumerate as a device node.  On this device node, you need to create a KMDF filter which would talk to the ACPI bus driver and get the custom data, which would then be exposed to the user-mode driver (something like the sensor sample driver).  This filter is essentially a bridge between the Microsoft ACPI bus driver and your user-mode sensor driver; it is necessary because the ACPI bus driver will only handle internal IO requests, which cannot be generated from user-mode.  The following resources may be useful to explain these concepts and provide sample code:


    http://download.microsoft.com/download/5/b/9/5b97017b-e28a-4bae-ba48-174cf47d23cd/CPA002_WH06.ppt

     

    http://www.microsoft.com/whdc/system/pnppwr/powermgmt/ACPIDriver_Vista.mspx

    Lastly, you probably want to have the accelerometer be event driver.  To get the events to your user mode driver, we recommend an approach called the "inverted call" method.  This is when the user mode driver will issue an IO request down to to the filter driver, but rather than complete it immediately, the filter will save the request in a WDFQUEUE object.  Then, when the ACPI notify event arrives, you can pull the request off the queue to complete it with the data.

    Hopefully this helps you get oriented in the right direction.

    Dan

All Replies

  • Tuesday, September 29, 2009 4:52 PMWindowsNT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The Sensors sample demonstrates how to export data to the sensor interface, not how to get them from the actual hardware, if any.  Perhaps you have to develop 2 drivers, one to provide the ISensor (like the samples in the WDK) and one to talk with the device via usb or whatever - so you have to learn about USB drivers.

    Make sure you have the latest WDK.



    Michael
  • Tuesday, September 29, 2009 8:02 PMChris_H-Kionix Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thank you Michael,

    I understand that I will need two drivers, one for hardware communication via SMBus, and one to interface with userspace applications via the Sensor API.  Are there any sample drivers dealing with SMBus communication?  I've been reading about them on MSDN, but reading about something and actually seeing the concept implemented in code are completely different.

    The goal of this is to integrate our sensor into an embedded hardware platform without necessitating a stand-alone micro->USB interface (like the JM board).  Is anybody else working on a similar project?  Is there any available documentation that may be more concise than the MSDN library?

    Thank you,
    Chris
  • Tuesday, September 29, 2009 8:10 PMPrasanna PadmanabhanMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Chris,

    By development kit are you referring to the Sensor development kit? If not, you can get that from http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=JMBADGE2008-B&fsrch=1.

    That kit comes with the full sources for its driver which includes communication with the device. That can give you a good idea of how to write your own driver.

    Let us know if you have any other questions.

    Thanks,
    Prasanna
  • Tuesday, September 29, 2009 8:49 PMChris_H-Kionix Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thank you Prasanna,

    I actually have two of the JM Badge boards but they are using USB to communicate with an external microcontroller, which then communicates with the sensors themselves.  I'm not really sure how helpful that source will be but it should be more comprehensive than the samples in the WDK.  I hadn't taken a close look at the files that came with the Badge boards, but I will now; thank you for mentioning it!

    Chris
  • Wednesday, September 30, 2009 3:40 PMDan PolivyMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Chris,

    Unfortunately we don't have any sample code for what you're looking for, but I can offer some guidance based on some work we've done with ALS and ACPI.  Assuming you can expose your SMBus connected accelerometer via ACPI, this may be the easiest approach.  To do this, you'd have to modify the BIOS ACPI table to expose the custom device, which Windows would then enumerate as a device node.  On this device node, you need to create a KMDF filter which would talk to the ACPI bus driver and get the custom data, which would then be exposed to the user-mode driver (something like the sensor sample driver).  This filter is essentially a bridge between the Microsoft ACPI bus driver and your user-mode sensor driver; it is necessary because the ACPI bus driver will only handle internal IO requests, which cannot be generated from user-mode.  The following resources may be useful to explain these concepts and provide sample code:


    http://download.microsoft.com/download/5/b/9/5b97017b-e28a-4bae-ba48-174cf47d23cd/CPA002_WH06.ppt

     

    http://www.microsoft.com/whdc/system/pnppwr/powermgmt/ACPIDriver_Vista.mspx

    Lastly, you probably want to have the accelerometer be event driver.  To get the events to your user mode driver, we recommend an approach called the "inverted call" method.  This is when the user mode driver will issue an IO request down to to the filter driver, but rather than complete it immediately, the filter will save the request in a WDFQUEUE object.  Then, when the ACPI notify event arrives, you can pull the request off the queue to complete it with the data.

    Hopefully this helps you get oriented in the right direction.

    Dan