![Elektor EPROM Скачать руководство пользователя страница 21](http://html1.mh-extra.com/html/elektor/eprom/eprom_manual_2386336021.webp)
tion
DeviceIoControl
each time it is called.
You can modify the device name according
to your own desires, as shown in
Listing 3
.
Here you should change ‘EZUSB’ to ‘MYSYS’.
Since both of these names have the same
length, the length declarations ’18’ and ‘14’
need not be changed.
As soon as this driver is loaded by the
operating system, the user-developed pro-
gram can use
CreateFile
to establish a
connection using the name
\\.\Mysys-0.
In
theory, the device driver can manage up to
eight identical devices, which is why the
name ends with a hyphen and a number. This
routine is called for each
DeviceIoControl
instruction that communicates with the USB
device (see
Listing 4
). A Request instruction
for the USB device is handled using
Ezusb_VendorRequest
, but we don’t want to
discuss that in any more detail here.
All instructions that can be executed
using the device driver are handled in the
switch (ioControlCode)
statement
.
Even ver-
sion checking is handled using
DeviceIoCon-
trol
, as can be seen in
Listing 5
. The major,
minor and build numbers are located in the
Version.h
file and can be modified as you see
fit.
The sample Delphi program from the first
part of the series now receives a new type
declaration for the
_VENDOR_REQUEST_IN
record. This type is defined in the file
ezusb-
sys.h
from Cypress (
see
Listing 6). This struc-
ture, as well as other structures for
DeviceIo-
Control
instructions, can be directly incorpo-
rated into applications programmed in C, or
EZUSB.DSW
. Next, check whether it
is actually possible to generate the
project. In the ‘Generate’ menu, sel-
ect ‘Generate ezusb.sys (F7)’. If ever-
ything is in order, ‘0 errors, 0 war-
nings’ will appear in the message
window. If the installation paths
have been changed during the
installation, all paths in the compiler
and linker options must be modified
accordingly. If
the code cannot
be generated without errors or war-
nings, the environment has not been
configured properly.
Under C, it is nearly impossible to
rename an entire project, so we will
just leave it as it is. After everything
is finished, assign your new name
(MYSYS.SYS) to the SYS file.
The individual files
The most important file is
ezusb-
sys.c,
which contains all of the code
for communications between the
Windows USB device drivers and the
application. In this article, we can
only describe certain excerpts from
the Cypress C source code.
The operating system first loads
the SYS file, and then pointers to the
other user-written functions are
assigned to the entry label (
Driver-
Entry
), which is present in every
device driver, to allow the operating
system to directly execute the corre-
sponding instructions. The operating
system generates a new device
using the function
Ezusb_PnPAdd-
Device
, which calls
Ezusb_CreateDe-
viceObject
and generates a virtual
device name (similar to ‘COM1’ or
‘LPT’).
The main task is performed by
the function
Ezusb_ProcessIOCTL
,
which jumps to the Core32.dll func-
MICRO
CONTROLLER
33
11/2002
Elektor Electronics
Table 7
#define Ezusb_IOCTL_INDEX 0x0800
#define IOCTL_Ezusb_VENDOR_REQUEST CTL_CODE(FILE_DEVICE_UNKNOWN,
Ezusb_IOCT5, METHOD_BUFFERED, FILE_ANY_ACCESS)
Table 5
case IOCTL_EZUSB_GET_DRIVER_VERSION:
{ PEZUSB_DRIVER_VERSION version = (PEZUSB_DRIVER_VERSION) ioBuffer;
if (outputBufferLength >= sizeof(EZUSB_DRIVER_VERSION))
{
version->MajorVersion = EZUSB_MAJOR_VERSION
;
version->MinorVersion = EZUSB_MINOR_VERSION
;
version->BuildVersion = EZUSB_BUILD_VERSION
;
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = sizeof(EZUSB_DRIVER_VERSION);
} else
{ Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
}
}
break;
Table 6
typedef struct _VENDOR_REQUEST_IN
{
BYTE bRequest;
WORD wValue;
WORD wIndex;
WORD wLength;
BYTE direction;
BYTE bData;
} VENDOR_REQUEST_IN, *PVENDOR_REQUEST_IN;
Содержание EPROM
Страница 1: ......