I2C Driver Interface

I2C driver provides kernel mode routines communicating with a PIC microcontroller. It encapsulates PIC's functionality and provides higher level commands which controls PIC's behavior on an I2C bus. Driver functionality is exposed via IRPs (IO request packets). Higher level driver should allocate an IRP, fill it with a code of desired operation and appropriate parameters and call kernel function IoCallDriver in order to execute that operation.

Each operation is identified by its code. The I2C driver implements IRP_MJ_READ, IRP_MJ_WRITE and IRP_MJ_DEVICE_CONTROL major function codes (and several others which purpose is entirely technical).

IRP_MJ_READ/IRP_MJ_WRITE

Operations used to read/write specified amout of data from/to a bus. They can be called in any mode (i.e. master, slave and sniffer mode) except for the write operation in sniffer mode.
  1. master mode read/write

    This call has to follow either StartFirstTransfer or StartNextTransfer operation. After any of these operations the device is waiting for execution of a read or a write operation by a driver. These operations are sending/receiving data per chunks. Each chunk is preceded by its length which is now 8bit unsigned integer but this limitation is not a fundamental one (from the device's point of view). User can read/write data of an arbitrary length and these are then send per chunks, however, this process is transparent for a caller. For details of how communication is going on the device see the PIC state chart.

  2. sniffer mode read

    When a device is switched to the sniffer mode it waits until a frame starts. Then it sniffs bits (one by one according to clocks generated on a bus) and stores them into internal 9bit buffer (8 bits for data, 1 bit for an acknowledgement). When a byte (including an ack) is read the sniffer holds I2C bus clocks low in order to get enough time to send sniffed data to a driver. Data are sent in two octets – the first one contains data themselves the second one contains an acknowledgement bit and possibly some more information. Hence the sniffer slows down a communication on the I2C bus approximately to a half of the original one but this should be a problem only in time critical applications. If that was a case some sofisticated buffering would be neccessary (but that would inevitably cause a delay of data displayed by a sniffing software).

IRP_MJ_DEVICE_CONTROL

Functionality exposed by a driver via device IO control includes the following:

Source files

Driver.c, Driver.h driver body (DriverEntry, dispatching routine etc.) and auxiliary technicalities
Functions.c, Functions.h Implemetation of all major operations (like StartFirstTransfer, SwitchToMasterMode, ...)
I2CErrors.mc, I2CErrors.h Error codes (NTSTATUSes).
I2C.h Interface exposed to higher level drivers or user applications.
Sources A "makefile" for WinXP DDK building utility