xDRV-driver for LPT with interrupt service routine

Driver xDRV.sys is driver developed by Иванов Д. В.(www.pcports.ru) and is capable to work(read write) with any PC port under windows NT, 2000, XP. But main advantage of this driver is that it can catch and handle LPT port interrupts (in this case LPT1 with address 0x378 with IRQ 07).

Program part of xDRV

Lets see how this driver can be put in action. First of all download packed archive with driver and library with functions.

xDRV.sys <13.2kB>

In this package you will find driver xDRV.sys, dynamical library xDRV.dll, statical library xDRV.lib, which may be needed while compiling project with statical connection of dll and header file with function prototype description which can control driver. Let see the functions:

bool xDRV_OpenDriver();

Driver xDRV.sys is dynamically loadable. For loading this driver and initializing this function is used. If driver is loaded successfully, then function returns TRUE otherwise FALSE. This function has to be called one time at the beginning. If function returned FALSE then try to restart computer might be xDRV.sys already has been loaded to the memory and function xDRV_StopDriver() wasn’t used. Driver and library has to be placed in same directory where project files are.

void xDRV_StopDriver();

As it was mentioned – this function is important. It has to be called at the end of program work. If not – driver will stay loaded in to memory and will take over interrupts. And during second load program will throw an error.

void xDRV_Write(unsigned short PortAdr, unsigned char PortValue);

This function is used to write one byte of data(PortValue) to port(PortAdr). For instance in order to make all data-lines high in port you should write: xDRV_Write(0x378, 255) ;

unsigned char xDRV_Read(unsigned short PortAdr);

This function obviously is used for reading byte from port(PortAdr).

void xDRV_InitInterput(void(*FunAdr)(void* p), void* param);

This function is most exiting in this driver. This function is the main reason why this driver was created. Driver in order to be able announce about interrupt it is important to give to interrupt function special function address with strict structure. Then when interrupt occur this function will be called. Function should look like:

void fn_name(void *var_name);

Second xDRV_InitInterput() parameter can be any, which will be passed to special function when it is called.

To make things more clear there are tow there are two ready projects with all driver functions used. One project is written in C/C++ language in Microsoft Visual C++ 6.0 environment (WinAPI) and another MFC ( MICROSOFT FOUNDATION CLASS LIBRARY):

WinAPI Test (xDRV.sys) <53.1kB>

MFC Test (xDRV.sys) <44.9kB>

Hardware part

Now its time to prepare hardware part that xDRV.sys could work properly. Go to Control Panel->System->Hardware->Device Manager->Ports(COM and LPT)->Printer Port(LPT1)->Properties. In tab Port Parameters select “Use any interrupt assigned to the port”.

Then in port header set pin 15 to “0”(STATUS register – ERROR) connecting this pin to ground. Now you can start program that uses xDRV.sys. You can try to write and read from port. But lets see how interrupts work. As we said 15 pin should be connected to ground. Driver registers interrupts from 10th pin of LPT port (ACK). Every time this pin goes LOW the interrupt will be registered.

If ERROR line wasn’t connected to ground, then only one interrupt could be registered, but in DATA and CONTROL register would start chaos which would last for about one minute. The reason of this is native port driver which tries to ping to printer which it thinks should be connected to port. But there is no any printer then this actions is useless. So put 15 pin to ground and don’t bother. Of course we lose one control line, but interrupt ability compensates this.

Source: https://www.pcports.ru

 

One Comment:

  1. Pingback: cheap memory

Leave a Reply