Chris Cant - Writing Windows WDM Device Drivers

Здесь есть возможность читать онлайн «Chris Cant - Writing Windows WDM Device Drivers» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Lawrence, Kansas 66046, ISBN: , Издательство: R & D Books, Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Writing Windows WDM Device Drivers: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Writing Windows WDM Device Drivers»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Writing Windows WDM Device Drivers — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Writing Windows WDM Device Drivers», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Most of the commands are fairly self-explanatory. They are best explained using examples in the context of a sample application, WdmIoTest, that outputs data to the LPT printer parallel port.

Table 15.2 WdmIo and PhdIo commands

Command Input parameters Output Description
PHDIO_OR reg, Value Read register, OR with value, and write back. Use to set bit(s)
PHDIO_AND reg, Value Read register, AND with value, and write back. Use to clear bit(s)
PHDIO_XOR reg, Value Read register, XOR with value, and write back. Use to toggle bit(s)
PHDIO_WRITE reg, Value Write value to a register
PHDIO_READ reg Value Read value from a register
PHDIO_DELAY delay Delay for given microseconds. Delay must be 60µs or less
PHDIO_WRITES reg, count, Values, delay Write values to same register with delay (<=60µs)
PHDIO_READS reg, count, delay Values Read values from same register with delay (<=60µs)
PHDIO_IRQ_CONNECT reg, mask, Value Connect to interrupt
PHDIO_TIMEOUT seconds Specify time-out for reads and writes
PHDIO_WRITE_NEXT reg Write next value from write buffer
PHDIO_READ_NEXT reg Store next value in read buffer

LPT Printer Driver Application

The WdmIoTest Win32 application uses the WdmIo driver to output a couple of lines of text to a printer on the old Centronics LPT1 parallel printer port. The source and executable for this program are in the book software WdmIo\Exe directory. However, you will not be able to run this program until you have installed the WdmIo driver and configured your system correctly, as described later.

Parallel Ports

A parallel port responds at three addresses in I/O space in an x86 PC. It also generates an interrupt (when enabled) on one interrupt line. The LPT1 port traditionally lives at I/O space addresses 0x378 to 0x37A and generates ISA interrupt IRQ7.

A basic parallel port has the three registers as listed in Table 15.3. Signals with #at the end of their name use negative logic. For example, if the Status BUSY# bit is read as zero (low), the printer is busy.

The printer is ready to accept data if the Status BUSY# and ONLINE bits are high.

To write data to the printer, write the byte to the Data port. Wait 1µs for the data lines to settle. Set the Control port STROBE output high for at least 0.5µs. The printer signals that it is busy as BUSY# is read as low. When it is ready for another byte, it pulses ACK# low briefly and BUSY# goes high again.

The ACK# pulse signals the parallel port electronics to interrupt the processor (provided ENABLE_INT is high). I have no clear documentation to say what is exactly supposed to happen now. One source says that bit 2 of the Status register is set low to indicate that it has caused the interrupt. However, the two printers that I tried did not set this bit low. It seems that you just have to assume that if the right interrupt arrives (e.g., IRQ7), the correct parallel port caused the interrupt. It seems that reading the Status register clears the interrupt.

A printer may sometimes also pulse ACK# low and so generate an interrupt at other times, such as when it has finished initializing itself, when it is switched off, when it goes off-line, or when it runs out of paper. A dedicated parallel port driver might well take special action for these circumstances. The code here just needs to ensure that the WdmIo driver reads the Status port to clear the interrupt.

As you may be aware, more sophisticated versions of the parallel port are available. For example, when configured in the appropriate mode, a parallel port can input information via the Data port. In addition, some non-standard devices can be connected to a basic parallel port. These might allow input of 4-bits at a time using the Status port. Dongles are hardware devices that are used to verify that some software is licensed to run on a computer. They are designed to respond when their manufacturer's software talks to them in some special way. At all other times, they are designed to pass all parallel port signals to the printer and vice versa.

Table 15.3 Parallel port registers

Offset Access Register
0 Read/Write Data
1 Read only Status
Bit 3 ONLINE
Bit 5 OUT_OF_PAPER
Bit 6 ACK#
Bit 7 BUSY#
2 Read/Write Control
Bit 0 STROBE
Bit 2 INIT#
Bit 3 SELECT
Bit 4 ENABLE_INT
Bit 6 1
Bit 7 1
WdmIoTest

The WdmIoTest application uses the WdmIo driver to write a brief message to the printer. It outputs information to the console screen to indicate its progress as it performs the following steps. Steps 2-8 all involve DeviceIoControl or WriteFile calls to the WdmIo driver.

1. Open a handle to the WdmIo device. The GetDeviceViaInterface routine is used as before to open a handle to the first device with a WDMIO_GUID device interface.

2. Disable the interrupts and connect to an interrupt.

3. Initialize the printer.

4. Send commands for writing each byte.

5. Read the status every second until the printer is ready. Time-out after 20 seconds.

6. Write a message to the printer.

7. Get the write results.

8. Disable the interrupt.

9. Close the handle.

PHDIoTest

PHDIoTest does exactly the same job as WdmIoTest, except that it obtains a handle to the PHDIo device in a different way. It calls CreateFile directly, passing the required resources in the filename, as follows.

HANDLE hPhdIo = CreateFile("\\\\.\\PHDIo\\isa\\io378,3\\irq7\\override", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

Table 15.4 shows the different resource specifiers that may be used as a part of the PHDIo filename. The first specifier must be \isa. The other specifiers can be in any order. An I/O port specifier must be given. Use the \override specifier with caution and never use it in a commercial release. All letters in the filename must be in lower case.

Table 15.4 PHDIo filename resource elements

Element Required Description
\isa Mandatory Initial string: Isa bus
\io, Mandatory I/O ports and in hex
\irq Optional IRQ in decimal
\override Optional Use these resources even if they cannot be allocated
Issuing Commands

Listing 15.1 shows the commands that initialize the printer. It also shows how DeviceIoControl is called with the IOCTL_PHDIO_RUN_CMDS IOCTL code to run these commands.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Writing Windows WDM Device Drivers»

Представляем Вашему вниманию похожие книги на «Writing Windows WDM Device Drivers» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Writing Windows WDM Device Drivers»

Обсуждение, отзывы о книге «Writing Windows WDM Device Drivers» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x